Skip to content

Commit

Permalink
fetch supported contracts from orderbook while creating orders
Browse files Browse the repository at this point in the history
  • Loading branch information
Revantark committed Jun 25, 2024
1 parent 9186d57 commit eda62be
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 702 deletions.
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"singleQuote": false,
"tabWidth": 4
"singleQuote": true,
"tabWidth": 2
}
52 changes: 27 additions & 25 deletions package.json
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"
}
}
4 changes: 3 additions & 1 deletion packages/core/src/lib/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const CatalogErrors = {
WALLET_NOT_FOUND: (from: boolean): string =>
`${from ? 'from' : 'to'} wallet not found`,
`${
from ? 'from' : 'to'
} asset wallet not found; please pass the wallet associated with the chain of the asset swapping`,

CHAIN_WALLET_NOT_FOUND: (blockchain: 'EVM' | 'Bitcoin'): string =>
`no ${blockchain} wallet found`,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/lib/garden.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ describe("Catalog", () => {
async () => {
const bitcoinWallet = BitcoinWallet.fromPrivateKey(
bitcoinPk,
AddressType.p2wpkh,
"m/84'/0'/0'/0/0",
bitcoinProvider
);

Expand Down
58 changes: 58 additions & 0 deletions packages/core/src/lib/garden.v1.spec.ts
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]);
});
});
Loading

0 comments on commit eda62be

Please sign in to comment.