-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch supported contracts from orderbook while creating orders
- Loading branch information
Showing
18 changed files
with
194 additions
and
702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"singleQuote": false, | ||
"tabWidth": 4 | ||
"singleQuote": true, | ||
"tabWidth": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
{ | ||
"private": true, | ||
"name": "yarn_workspace_sandbox", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"echo": "yarn workspaces foreach --include \"packages/*\" run echo", | ||
"build": "yarn workspaces foreach -Atp --include \"packages/*\" run build", | ||
"start:docs": "yarn workspace docs start", | ||
"dev": "yarn workspaces foreach -Api -j unlimited --include \"packages/*\" run dev ", | ||
"patch:affected": "yarn workspaces foreach -p --topological --include \"packages/*\" --since=$0 run patch", | ||
"publish:affected": "yarn workspaces foreach -p --include \"packages/*\" --since=main npm publish" | ||
}, | ||
"workspaces": [ | ||
"packages/*", | ||
"docs" | ||
], | ||
"devDependencies": { | ||
"@types/chrome": "^0.0.268", | ||
"@types/node": "^20.11.30", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.2", | ||
"vite": "^5.1.6", | ||
"vite-plugin-dts": "^3.7.3" | ||
} | ||
"private": true, | ||
"name": "yarn_workspace_sandbox", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"echo": "yarn workspaces foreach --include \"packages/*\" run echo", | ||
"build": "yarn workspaces foreach -Atp --include \"packages/*\" run build", | ||
"start:docs": "yarn workspace docs start", | ||
"test": "vitest run", | ||
"dev": "yarn workspaces foreach -Api -j unlimited --include \"packages/*\" run dev ", | ||
"patch:affected": "yarn workspaces foreach -p --topological --include \"packages/*\" --since=$0 run patch", | ||
"publish:affected": "yarn workspaces foreach -p --include \"packages/*\" --since=main npm publish" | ||
}, | ||
"workspaces": [ | ||
"packages/*", | ||
"docs" | ||
], | ||
"devDependencies": { | ||
"@types/chrome": "^0.0.268", | ||
"@types/node": "^20.11.30", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.2", | ||
"vite": "^5.1.6", | ||
"vite-plugin-dts": "^3.7.3", | ||
"vitest": "^1.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { Assets, Chains, Orderbook } from '@gardenfi/orderbook'; | ||
import { JsonRpcProvider, Wallet } from 'ethers'; | ||
import { | ||
BitcoinNetwork, | ||
BitcoinProvider, | ||
BitcoinWallet, | ||
EVMWallet, | ||
} from '@catalogfi/wallets'; | ||
import { GardenJS } from './garden'; | ||
|
||
describe('Garden JS', async () => { | ||
// these tests expect a local bitcoin node, ethereum node | ||
// and the orderbook backend to be running using merry | ||
|
||
const provider = new JsonRpcProvider('http://localhost:8545'); | ||
const pk = Wallet.createRandom().privateKey; | ||
const signer = new Wallet(pk, provider); | ||
|
||
const bitcoinProvider = new BitcoinProvider( | ||
BitcoinNetwork.Regtest, | ||
'http://localhost:30000' | ||
); | ||
|
||
const bitcoinWallet = BitcoinWallet.createRandom(bitcoinProvider); | ||
|
||
const orderbook = await Orderbook.init({ | ||
url: 'http://localhost:8080', | ||
signer, | ||
}); | ||
|
||
const wallets = { | ||
[Chains.bitcoin_regtest]: bitcoinWallet, | ||
[Chains.ethereum_localnet]: new EVMWallet(signer), | ||
}; | ||
|
||
const garden = new GardenJS(orderbook, wallets); | ||
|
||
it('should be able to create order', async () => { | ||
const orderId = await garden.swap( | ||
Assets.bitcoin_regtest.BTC, | ||
Assets.ethereum_localnet.WBTC, | ||
100000, | ||
90000 | ||
); | ||
|
||
const order = await orderbook.getOrder(orderId); | ||
expect(order).toBeDefined(); | ||
expect(order.maker).toEqual( | ||
(await signer.getAddress()).toLocaleLowerCase() | ||
); | ||
expect(order.orderPair).toContain(Chains.bitcoin_regtest); | ||
expect(order.orderPair).toContain(Chains.ethereum_localnet); | ||
|
||
const contracts = await orderbook.getSupportedContracts(); | ||
expect(order.orderPair).toContain(contracts[Chains.ethereum_localnet]); | ||
}); | ||
}); |
Oops, something went wrong.