@galacticcouncil/sdk 0.0.1-beta.1 → 0.0.1-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -31
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +7 -0
- package/dist/types/api/index.d.ts +1 -0
- package/dist/types/api/router.d.ts +18 -46
- package/dist/types/api/tradeRouter.d.ts +44 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/pool/xyk/{math/bundler.d.ts → xykMath.d.ts} +0 -0
- package/dist/types/pool/xyk/xykPolkadotClient.d.ts +1 -1
- package/dist/types/pool/xyk/xykPool.d.ts +1 -1
- package/dist/types/{suggester → route}/bfs.d.ts +0 -0
- package/dist/types/{suggester → route}/graph.d.ts +0 -0
- package/dist/types/{suggester → route}/index.d.ts +0 -0
- package/dist/types/{suggester → route}/suggester.d.ts +0 -0
- package/dist/types/types.d.ts +34 -8
- package/dist/types/utils/math.d.ts +14 -2
- package/package.json +5 -5
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -20
- package/.nvmrc +0 -1
- package/.prettierrc.json +0 -12
- package/.vscode/settings.json +0 -15
- package/dist/cjs/hydra_dx_wasm_bg-ZX7K4FM7.wasm +0 -0
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/hydra_dx_wasm_bg-ZX7K4FM7.wasm +0 -0
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +0 -7
- package/dist/types/api/trader.d.ts +0 -0
- package/dist/types/pool/xyk/math/nodejs.d.ts +0 -9
- package/esbuild.mjs +0 -36
- package/jest.config.mjs +0 -16
- package/src/api/index.ts +0 -1
- package/src/api/router.ts +0 -359
- package/src/api/trader.ts +0 -0
- package/src/client/capi.ts +0 -0
- package/src/client/index.ts +0 -1
- package/src/client/polkadot.ts +0 -47
- package/src/client/types.ts +0 -8
- package/src/index.ts +0 -4
- package/src/pool/index.ts +0 -3
- package/src/pool/polkadotPoolService.ts +0 -19
- package/src/pool/poolFactory.ts +0 -14
- package/src/pool/xyk/math/bundler.ts +0 -19
- package/src/pool/xyk/math/nodejs.ts +0 -19
- package/src/pool/xyk/xykPolkadotClient.ts +0 -58
- package/src/pool/xyk/xykPool.ts +0 -82
- package/src/suggester/bfs.ts +0 -106
- package/src/suggester/graph.ts +0 -31
- package/src/suggester/index.ts +0 -3
- package/src/suggester/suggester.ts +0 -66
- package/src/types.ts +0 -61
- package/src/utils/bignumber.ts +0 -25
- package/src/utils/math.ts +0 -24
- package/src/utils/queue.ts +0 -26
- package/src/utils/stack.ts +0 -31
- package/src/utils/traversal/bfs.ts +0 -74
- package/test/api/router.spec.ts +0 -87
- package/test/data/xykPool.ts +0 -21
- package/test/data/xykPools.ts +0 -61
- package/test/lib/mockXykPoolService.ts +0 -8
- package/test/pool/xyk/xykPool.spec.ts +0 -26
- package/test/script/examples/router/getAllAssets.ts +0 -14
- package/test/script/examples/router/getAllPaths.ts +0 -14
- package/test/script/examples/router/getAssetPairs.ts +0 -14
- package/test/script/examples/router/getBestBuyPrice.ts +0 -19
- package/test/script/examples/router/getBestSellPrice.ts +0 -19
- package/test/script/executor.ts +0 -45
- package/test/suggester/bfs.spec.ts +0 -34
- package/test/suggester/graph.spec.ts +0 -30
- package/test/suggester/suggester.spec.ts +0 -25
- package/test/utils/traversal/bfs.spec.ts +0 -28
- package/tsconfig.json +0 -14
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import { PolkadotExecutor } from '../../executor';
|
|
3
|
-
import { PolkadotPoolService } from '../../../../src/pool';
|
|
4
|
-
import { Router } from '../../../../src/api';
|
|
5
|
-
|
|
6
|
-
class GetAssetPairsExample extends PolkadotExecutor {
|
|
7
|
-
async script(api: ApiPromise): Promise<any> {
|
|
8
|
-
const poolService = new PolkadotPoolService(api);
|
|
9
|
-
const router = new Router(poolService);
|
|
10
|
-
return router.getAssetPairs('1');
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
new GetAssetPairsExample('wss://rpc.basilisk.cloud', 'Get asset pairs').run();
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import { PolkadotExecutor } from '../../executor';
|
|
3
|
-
import { PolkadotPoolService } from '../../../../src/pool';
|
|
4
|
-
import { Router } from '../../../../src/api';
|
|
5
|
-
import { bnum, scale } from '../../../../src/utils/bignumber';
|
|
6
|
-
|
|
7
|
-
class GetBestBuyPriceExample extends PolkadotExecutor {
|
|
8
|
-
async script(api: ApiPromise): Promise<any> {
|
|
9
|
-
const poolService = new PolkadotPoolService(api);
|
|
10
|
-
const router = new Router(poolService);
|
|
11
|
-
return router.getBestBuyPrice('1', '2', scale(bnum('10'), 12));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
new GetBestBuyPriceExample(
|
|
16
|
-
'wss://rpc.basilisk.cloud',
|
|
17
|
-
'Get best buy price',
|
|
18
|
-
true
|
|
19
|
-
).run();
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import { PolkadotExecutor } from '../../executor';
|
|
3
|
-
import { PolkadotPoolService } from '../../../../src/pool';
|
|
4
|
-
import { Router } from '../../../../src/api';
|
|
5
|
-
import { bnum, scale } from '../../../../src/utils/bignumber';
|
|
6
|
-
|
|
7
|
-
class GetBestSellPriceExample extends PolkadotExecutor {
|
|
8
|
-
async script(api: ApiPromise): Promise<any> {
|
|
9
|
-
const poolService = new PolkadotPoolService(api);
|
|
10
|
-
const router = new Router(poolService);
|
|
11
|
-
return router.getBestSellPrice('1', '2', scale(bnum('1'), 12));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
new GetBestSellPriceExample(
|
|
16
|
-
'wss://rpc.basilisk.cloud',
|
|
17
|
-
'Get best sell price',
|
|
18
|
-
true
|
|
19
|
-
).run();
|
package/test/script/executor.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
2
|
-
|
|
3
|
-
export abstract class PolkadotExecutor {
|
|
4
|
-
protected readonly apiUrl: string;
|
|
5
|
-
protected readonly desc: string;
|
|
6
|
-
protected readonly pretty: boolean;
|
|
7
|
-
|
|
8
|
-
constructor(apiUrl: string, desc: string, pretty?: boolean) {
|
|
9
|
-
this.apiUrl = apiUrl;
|
|
10
|
-
this.desc = desc;
|
|
11
|
-
this.pretty = pretty || false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async run() {
|
|
15
|
-
try {
|
|
16
|
-
const provider = new WsProvider(this.apiUrl);
|
|
17
|
-
const api = new ApiPromise({
|
|
18
|
-
provider: provider,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
api
|
|
22
|
-
.on('connected', () => console.log('API connected'))
|
|
23
|
-
.on('disconnected', () => console.log('API disconnected'))
|
|
24
|
-
.on('error', () => console.log('API error'))
|
|
25
|
-
.on('ready', () => {
|
|
26
|
-
console.log('API ready');
|
|
27
|
-
console.log('Running script...');
|
|
28
|
-
console.log(this.desc);
|
|
29
|
-
this.script(api)
|
|
30
|
-
.then((output: any) => {
|
|
31
|
-
if (this.pretty) {
|
|
32
|
-
console.log(output ? JSON.stringify(output, null, 2) : '');
|
|
33
|
-
} else {
|
|
34
|
-
console.log(output);
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
.finally(() => api.disconnect());
|
|
38
|
-
});
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.log(error);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
abstract script(api: ApiPromise): Promise<any>;
|
|
45
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Bfs, Path } from '../../src/suggester';
|
|
2
|
-
|
|
3
|
-
describe('Suggester Breadth First Search algorithm', () => {
|
|
4
|
-
const g: Path[] = [];
|
|
5
|
-
const size = 4;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
for (let j = 0; j < size; j++) {
|
|
9
|
-
g.push([]);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
g[0].push([2, 'bXjT2D2cuxUuP2JzddMxYusg4cKo3wENje5Xdk3jbNwtRvStq']);
|
|
13
|
-
g[0].push([1, 'bXn6KCrv8k2JV7B2c5jzLttBDqL4BurPCTcLa3NQk5SWDVXCJ']);
|
|
14
|
-
g[1].push([2, 'bXi1mHNp4jSRUNXuX3sY1fjCF9Um2EezkpzkFmQuLHaChdPM3']);
|
|
15
|
-
g[1].push([0, 'bXn6KCrv8k2JV7B2c5jzLttBDqL4BurPCTcLa3NQk5SWDVXCJ']);
|
|
16
|
-
g[2].push([0, 'bXjT2D2cuxUuP2JzddMxYusg4cKo3wENje5Xdk3jbNwtRvStq']);
|
|
17
|
-
g[2].push([1, 'bXi1mHNp4jSRUNXuX3sY1fjCF9Um2EezkpzkFmQuLHaChdPM3']);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('Should find all possible paths from node 1 to node 2 with edge type', () => {
|
|
21
|
-
const result = new Bfs().findPaths(g, 1, 2);
|
|
22
|
-
expect(result).toStrictEqual([
|
|
23
|
-
[
|
|
24
|
-
[1, ''],
|
|
25
|
-
[2, 'bXi1mHNp4jSRUNXuX3sY1fjCF9Um2EezkpzkFmQuLHaChdPM3'],
|
|
26
|
-
],
|
|
27
|
-
[
|
|
28
|
-
[1, ''],
|
|
29
|
-
[0, 'bXn6KCrv8k2JV7B2c5jzLttBDqL4BurPCTcLa3NQk5SWDVXCJ'],
|
|
30
|
-
[2, 'bXjT2D2cuxUuP2JzddMxYusg4cKo3wENje5Xdk3jbNwtRvStq'],
|
|
31
|
-
],
|
|
32
|
-
]);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { getNodesAndEdges } from '../../src/suggester';
|
|
2
|
-
import { PoolBase } from '../../src/types';
|
|
3
|
-
import { xykPools } from '../data/xykPools';
|
|
4
|
-
|
|
5
|
-
describe('Suggester graph utility', () => {
|
|
6
|
-
let pools: PoolBase[];
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
pools = xykPools;
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('Should be map of nodes & bidirectional edges', () => {
|
|
13
|
-
expect(pools).toBeDefined();
|
|
14
|
-
const result = getNodesAndEdges(pools);
|
|
15
|
-
expect(result).toStrictEqual({
|
|
16
|
-
'0': [
|
|
17
|
-
['bXjT2D2cuxUuP2JzddMxYusg4cKo3wENje5Xdk3jbNwtRvStq', '0', '2'],
|
|
18
|
-
['bXn6KCrv8k2JV7B2c5jzLttBDqL4BurPCTcLa3NQk5SWDVXCJ', '0', '1'],
|
|
19
|
-
],
|
|
20
|
-
'1': [
|
|
21
|
-
['bXi1mHNp4jSRUNXuX3sY1fjCF9Um2EezkpzkFmQuLHaChdPM3', '1', '2'],
|
|
22
|
-
['bXn6KCrv8k2JV7B2c5jzLttBDqL4BurPCTcLa3NQk5SWDVXCJ', '1', '0'],
|
|
23
|
-
],
|
|
24
|
-
'2': [
|
|
25
|
-
['bXjT2D2cuxUuP2JzddMxYusg4cKo3wENje5Xdk3jbNwtRvStq', '2', '0'],
|
|
26
|
-
['bXi1mHNp4jSRUNXuX3sY1fjCF9Um2EezkpzkFmQuLHaChdPM3', '2', '1'],
|
|
27
|
-
],
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { RouteSuggester } from '../../src/suggester';
|
|
2
|
-
import { PoolBase } from '../../src/types';
|
|
3
|
-
import { xykPools } from '../data/xykPools';
|
|
4
|
-
|
|
5
|
-
describe('Suggester proposals', () => {
|
|
6
|
-
let pools: PoolBase[];
|
|
7
|
-
let suggester: RouteSuggester;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
pools = xykPools;
|
|
11
|
-
suggester = new RouteSuggester();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('Should return suggested hops from token 1 to 2 for given XYK pool', () => {
|
|
15
|
-
expect(pools).toBeDefined();
|
|
16
|
-
const result = suggester.getProposals('1', '2', pools);
|
|
17
|
-
expect(result).toStrictEqual([
|
|
18
|
-
[['bXi1mHNp4jSRUNXuX3sY1fjCF9Um2EezkpzkFmQuLHaChdPM3', '1', '2']],
|
|
19
|
-
[
|
|
20
|
-
['bXn6KCrv8k2JV7B2c5jzLttBDqL4BurPCTcLa3NQk5SWDVXCJ', '1', '0'],
|
|
21
|
-
['bXjT2D2cuxUuP2JzddMxYusg4cKo3wENje5Xdk3jbNwtRvStq', '0', '2'],
|
|
22
|
-
],
|
|
23
|
-
]);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Bfs } from '../../../src/utils/traversal/bfs';
|
|
2
|
-
|
|
3
|
-
describe('Breadth First Search', () => {
|
|
4
|
-
const g: number[][] = [];
|
|
5
|
-
const size = 4;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
for (let j = 0; j < size; j++) {
|
|
9
|
-
g.push([]);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
g[0].push(3);
|
|
13
|
-
g[0].push(1);
|
|
14
|
-
g[0].push(2);
|
|
15
|
-
g[1].push(3);
|
|
16
|
-
g[2].push(0);
|
|
17
|
-
g[2].push(1);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('Should find all possible routes from 2 to 3', () => {
|
|
21
|
-
const result = new Bfs().findPaths(g, 2, 3);
|
|
22
|
-
expect(result).toStrictEqual([
|
|
23
|
-
[2, 0, 3],
|
|
24
|
-
[2, 1, 3],
|
|
25
|
-
[2, 0, 1, 3],
|
|
26
|
-
]);
|
|
27
|
-
});
|
|
28
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"declaration": true,
|
|
4
|
-
"target": "es2021",
|
|
5
|
-
"module": "esnext",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"lib": ["esnext", "dom", "dom.iterable"],
|
|
8
|
-
"strict": true,
|
|
9
|
-
"noImplicitAny": false,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"outDir": "./out"
|
|
12
|
-
},
|
|
13
|
-
"include": ["src/**/*.ts"]
|
|
14
|
-
}
|