@galacticcouncil/sdk-next 0.0.0
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 +223 -0
- package/build/index.cjs +1 -0
- package/build/index.mjs +1 -0
- package/build/types/api/Papi.d.ts +385 -0
- package/build/types/api/client.d.ts +2 -0
- package/build/types/api/index.d.ts +2 -0
- package/build/types/client/AssetClient.d.ts +24 -0
- package/build/types/client/BalanceClient.d.ts +17 -0
- package/build/types/client/index.d.ts +2 -0
- package/build/types/consts.d.ts +8 -0
- package/build/types/errors.d.ts +10 -0
- package/build/types/index.d.ts +8 -0
- package/build/types/pool/PoolClient.d.ts +25 -0
- package/build/types/pool/PoolContextProvider.d.ts +30 -0
- package/build/types/pool/PoolFactory.d.ts +4 -0
- package/build/types/pool/aave/AaveAbi.d.ts +126 -0
- package/build/types/pool/aave/AavePool.d.ts +24 -0
- package/build/types/pool/aave/AavePoolClient.d.ts +14 -0
- package/build/types/pool/aave/index.d.ts +2 -0
- package/build/types/pool/index.d.ts +8 -0
- package/build/types/pool/lbp/LbpMath.d.ts +7 -0
- package/build/types/pool/lbp/LbpPool.d.ts +49 -0
- package/build/types/pool/lbp/LbpPoolClient.d.ts +18 -0
- package/build/types/pool/lbp/index.d.ts +3 -0
- package/build/types/pool/omni/OmniMath.d.ts +19 -0
- package/build/types/pool/omni/OmniPool.d.ts +45 -0
- package/build/types/pool/omni/OmniPoolClient.d.ts +13 -0
- package/build/types/pool/omni/index.d.ts +3 -0
- package/build/types/pool/stable/StableMath.d.ts +14 -0
- package/build/types/pool/stable/StableSwap.d.ts +46 -0
- package/build/types/pool/stable/StableSwapClient.d.ts +16 -0
- package/build/types/pool/stable/index.d.ts +3 -0
- package/build/types/pool/types.d.ts +84 -0
- package/build/types/pool/xyk/XykMath.d.ts +12 -0
- package/build/types/pool/xyk/XykPool.d.ts +23 -0
- package/build/types/pool/xyk/XykPoolClient.d.ts +12 -0
- package/build/types/pool/xyk/index.d.ts +3 -0
- package/build/types/sor/Router.d.ts +66 -0
- package/build/types/sor/TradeRouter.d.ts +155 -0
- package/build/types/sor/TradeUtils.d.ts +12 -0
- package/build/types/sor/index.d.ts +4 -0
- package/build/types/sor/route/bfs.d.ts +37 -0
- package/build/types/sor/route/graph.d.ts +12 -0
- package/build/types/sor/route/index.d.ts +3 -0
- package/build/types/sor/route/suggester.d.ts +24 -0
- package/build/types/sor/types.d.ts +31 -0
- package/build/types/types.d.ts +40 -0
- package/build/types/utils/Queue.d.ts +13 -0
- package/build/types/utils/Stack.d.ts +15 -0
- package/build/types/utils/big.d.ts +3 -0
- package/build/types/utils/erc20.d.ts +5 -0
- package/build/types/utils/evm.d.ts +3 -0
- package/build/types/utils/format.d.ts +4 -0
- package/build/types/utils/index.d.ts +7 -0
- package/build/types/utils/json.d.ts +3 -0
- package/build/types/utils/math.d.ts +62 -0
- package/build/types/utils/traversal/bfs.d.ts +27 -0
- package/build/types/utils/xc.d.ts +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Router } from './Router';
|
|
2
|
+
import { Trade } from './types';
|
|
3
|
+
import { Hop } from '../pool';
|
|
4
|
+
import { Amount } from '../types';
|
|
5
|
+
export declare class TradeRouter extends Router {
|
|
6
|
+
/**
|
|
7
|
+
* Check whether trade is direct or not
|
|
8
|
+
*
|
|
9
|
+
* @param {Swap[]} swaps - trade route swaps
|
|
10
|
+
* @returns true if direct trade, otherwise false
|
|
11
|
+
*/
|
|
12
|
+
private isDirectTrade;
|
|
13
|
+
/**
|
|
14
|
+
* Find the best sell swap without errors
|
|
15
|
+
*
|
|
16
|
+
* @param {SellSwap[]} swaps - all possible sell routes
|
|
17
|
+
* @returns best sell swap if exist, otherwise first one found
|
|
18
|
+
*/
|
|
19
|
+
private findBestSellRoute;
|
|
20
|
+
/**
|
|
21
|
+
* Route fee range [min,max] in case pool is using dynamic fees
|
|
22
|
+
*
|
|
23
|
+
* @param {Swap[]} swaps - trade routes
|
|
24
|
+
* @returns min & max fee range if swapping through the pool with
|
|
25
|
+
* dynamic fees support
|
|
26
|
+
*/
|
|
27
|
+
private getRouteFeeRange;
|
|
28
|
+
/**
|
|
29
|
+
* Pool fee range [min,max] in case pool is using dynamic fees
|
|
30
|
+
*
|
|
31
|
+
* @param {PoolFees} fees - pool fees
|
|
32
|
+
* @returns min & max fee range if swapping through the pool with
|
|
33
|
+
* dynamic fees support
|
|
34
|
+
*/
|
|
35
|
+
private getPoolFeeRange;
|
|
36
|
+
/**
|
|
37
|
+
* Calculate and return best possible sell trade for assetIn>assetOut
|
|
38
|
+
*
|
|
39
|
+
* @param {number} assetIn - assetIn id
|
|
40
|
+
* @param {number} assetOut - assetOut id
|
|
41
|
+
* @param {bigint} amountIn - amount of assetIn to sell for assetOut
|
|
42
|
+
* @returns best possible sell trade of given token pair
|
|
43
|
+
*/
|
|
44
|
+
getBestSell(assetIn: number, assetOut: number, amountIn: bigint | string): Promise<Trade>;
|
|
45
|
+
/**
|
|
46
|
+
* Calculate and return sell spot price for assetIn>assetOut
|
|
47
|
+
*
|
|
48
|
+
* @param route - best possible trade route (sell)
|
|
49
|
+
* @returns sell spot price
|
|
50
|
+
*/
|
|
51
|
+
private getSellSpot;
|
|
52
|
+
/**
|
|
53
|
+
* Calculate and return sell trade for assetIn>assetOut
|
|
54
|
+
*
|
|
55
|
+
* @param {number} assetIn - assetIn id
|
|
56
|
+
* @param {number} assetOut - assetOut id
|
|
57
|
+
* @param {bigint} amountIn - amount of assetIn to sell for assetOut
|
|
58
|
+
* @param {Hop[]} route - explicit route to use for trade
|
|
59
|
+
* @returns sell trade of given token pair
|
|
60
|
+
*/
|
|
61
|
+
getSell(assetIn: number, assetOut: number, amountIn: bigint | string, route?: Hop[]): Promise<Trade>;
|
|
62
|
+
/**
|
|
63
|
+
* Calculate the amount out for best possible trade if fees are zero
|
|
64
|
+
*
|
|
65
|
+
* @param amountIn - amount of assetIn to sell for assetOut
|
|
66
|
+
* @param route - best possible trade route (sell)
|
|
67
|
+
* @param poolsMap - pools map
|
|
68
|
+
* @returns the amount out for best possible trade if fees are zero
|
|
69
|
+
*/
|
|
70
|
+
private calculateDelta0Y;
|
|
71
|
+
/**
|
|
72
|
+
* Calculate and return sell swaps for given path
|
|
73
|
+
* - final amount of previous swap is entry to next one
|
|
74
|
+
*
|
|
75
|
+
* @param amountIn - amount of assetIn to sell for assetOut
|
|
76
|
+
* @param path - current path
|
|
77
|
+
* @param poolsMap - pools map
|
|
78
|
+
* @returns sell swaps for given path
|
|
79
|
+
*/
|
|
80
|
+
private toSellSwaps;
|
|
81
|
+
/**
|
|
82
|
+
* Calculate and return most liquid route for tokenIn>tokenOut
|
|
83
|
+
*
|
|
84
|
+
* To avoid routing through the pools with low liquidity, 0.1% from the
|
|
85
|
+
* most liquid pool asset is used as reference value to determine the
|
|
86
|
+
* sweet spot.
|
|
87
|
+
*
|
|
88
|
+
* @param {number} assetIn - assetIn id
|
|
89
|
+
* @param {number} assetOut - assetout id
|
|
90
|
+
* @return Most liquid route of given token pair
|
|
91
|
+
*/
|
|
92
|
+
getMostLiquidRoute(assetIn: number, assetOut: number): Promise<Hop[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Calculate and return best spot price for tokenIn>tokenOut
|
|
95
|
+
*
|
|
96
|
+
* @param {number} assetIn - assetIn id
|
|
97
|
+
* @param {number} assetOut - assetOut id
|
|
98
|
+
* @return best possible spot price of given asset pair, or undefined
|
|
99
|
+
* if given pair swap is not supported
|
|
100
|
+
*/
|
|
101
|
+
getSpotPrice(assetIn: number, assetOut: number): Promise<Amount>;
|
|
102
|
+
/**
|
|
103
|
+
* Find the best buy swap without errors, if there is none return first one found
|
|
104
|
+
*
|
|
105
|
+
* @param {BuySwap[]} swaps - all possible buy routes
|
|
106
|
+
* @returns best buy swap if exist, otherwise first one found
|
|
107
|
+
*/
|
|
108
|
+
private findBestBuyRoute;
|
|
109
|
+
/**
|
|
110
|
+
* Calculate and return best possible buy trade for assetIn>assetOut
|
|
111
|
+
*
|
|
112
|
+
* @param {number} assetIn - assetIn id
|
|
113
|
+
* @param {number} assetOut - assetOut id
|
|
114
|
+
* @param {bigint} amountOut - amount of tokenOut to buy for tokenIn
|
|
115
|
+
* @returns best possible buy trade of given token pair
|
|
116
|
+
*/
|
|
117
|
+
getBestBuy(assetIn: number, assetOut: number, amountOut: bigint | string): Promise<Trade>;
|
|
118
|
+
/**
|
|
119
|
+
* Calculate and return buy spot price for assetIn>assetOut
|
|
120
|
+
*
|
|
121
|
+
* @param route - best possible trade route (buy)
|
|
122
|
+
* @returns buy spot price
|
|
123
|
+
*/
|
|
124
|
+
private getBuySpot;
|
|
125
|
+
/**
|
|
126
|
+
* Calculate and return buy trade for assetIn>assetOut
|
|
127
|
+
*
|
|
128
|
+
* @param {number} assetIn - assetIn id
|
|
129
|
+
* @param {number} assetOut - assetOut id
|
|
130
|
+
* @param {bigint} amountOut - amount of assetOut to buy for assetIn
|
|
131
|
+
* @param {Hop[]} route - explicit route to use for trade
|
|
132
|
+
* @returns buy trade of given token pair
|
|
133
|
+
*/
|
|
134
|
+
getBuy(assetIn: number, assetOut: number, amountOut: bigint | string, route?: Hop[]): Promise<Trade>;
|
|
135
|
+
/**
|
|
136
|
+
* Calculate the amount in for best possible trade if fees are zero
|
|
137
|
+
*
|
|
138
|
+
* @param amountOut - amount of assetOut to buy for assetIn
|
|
139
|
+
* @param bestRoute - best possible trade route (buy)
|
|
140
|
+
* @param poolsMap - pools map
|
|
141
|
+
* @returns the amount in for best possible trade if fees are zero
|
|
142
|
+
*/
|
|
143
|
+
private calculateDelta0X;
|
|
144
|
+
/**
|
|
145
|
+
* Calculate and return buy swaps for given path
|
|
146
|
+
* - final amount of previous swap is entry to next one
|
|
147
|
+
* - calculation is done backwards (swaps in reversed order)
|
|
148
|
+
*
|
|
149
|
+
* @param amountOut - amount of assetOut to buy for assetIn
|
|
150
|
+
* @param path - current path
|
|
151
|
+
* @param poolsMap - pools map
|
|
152
|
+
* @returns buy swaps for given path
|
|
153
|
+
*/
|
|
154
|
+
private toBuySwaps;
|
|
155
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Binary, PolkadotClient } from 'polkadot-api';
|
|
2
|
+
import { Papi } from '../api';
|
|
3
|
+
import { Trade } from './types';
|
|
4
|
+
export declare class TradeUtils extends Papi {
|
|
5
|
+
constructor(client: PolkadotClient);
|
|
6
|
+
private isDirectOmnipoolTrade;
|
|
7
|
+
private tradeCheck;
|
|
8
|
+
buildBuyTx(trade: Trade, slippagePct?: number): Promise<Binary>;
|
|
9
|
+
buildSellTx(trade: Trade, slippagePct?: number): Promise<Binary>;
|
|
10
|
+
buildSellAllTx(trade: Trade, slippagePct?: number): Promise<Binary>;
|
|
11
|
+
private buildRoute;
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type Path = Node[];
|
|
2
|
+
export type Node = [id: number, from: string];
|
|
3
|
+
/**
|
|
4
|
+
* Breadth First Search.
|
|
5
|
+
*
|
|
6
|
+
* - uses Queue to find the shortest path
|
|
7
|
+
* - slower than DFS (Depth First Search)
|
|
8
|
+
* - better when dst is closer to src
|
|
9
|
+
* - complexity O(N+E) where N are nodes and E are edges
|
|
10
|
+
*/
|
|
11
|
+
export declare class Bfs {
|
|
12
|
+
/**
|
|
13
|
+
* Check if current node is present in path or traversal within the same pool was already done
|
|
14
|
+
*
|
|
15
|
+
* @param x - current node
|
|
16
|
+
* @param path - path
|
|
17
|
+
* @returns true if node in path, otherwise false
|
|
18
|
+
*/
|
|
19
|
+
isNotVisited(x: Node, path: Path): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Finding paths in graph from given source to destination
|
|
22
|
+
*
|
|
23
|
+
* @param g - routes graph containing nodes & corresponding edges
|
|
24
|
+
* @param src - source node
|
|
25
|
+
* @param dst - destination node or null if requesting all posible paths from src
|
|
26
|
+
* @returns paths
|
|
27
|
+
*/
|
|
28
|
+
findPaths(g: Map<number, Path>, src: number, dst: number | null): Path[];
|
|
29
|
+
/**
|
|
30
|
+
* Build and populate graph
|
|
31
|
+
*
|
|
32
|
+
* @param nodes - list of pool assets
|
|
33
|
+
* @param edges - list of all edges [id, from, to] between assets
|
|
34
|
+
* @returns - traversal graph
|
|
35
|
+
*/
|
|
36
|
+
buildAndPopulateGraph(nodes: string[], edges: [string, number, number][]): Map<number, Path>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PoolBase } from '../../pool';
|
|
2
|
+
export type Edge = [address: string, from: number, to: number];
|
|
3
|
+
export type NodeEdges = {
|
|
4
|
+
[node: string]: Edge[];
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Calculate nodes & edges from substrate pools
|
|
8
|
+
*
|
|
9
|
+
* @param pools - given substrate pools
|
|
10
|
+
* @returns nodes & corresponding edges
|
|
11
|
+
*/
|
|
12
|
+
export declare function getNodesAndEdges(pools: PoolBase[]): NodeEdges;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Edge } from './graph';
|
|
2
|
+
import { PoolBase } from '../../pool';
|
|
3
|
+
export declare class RouteSuggester {
|
|
4
|
+
/**
|
|
5
|
+
* Proposals are ideal paths from
|
|
6
|
+
* 1) tokenIn to tokenOut
|
|
7
|
+
* 2) tokenIn to *(all possible paths are requested)
|
|
8
|
+
*
|
|
9
|
+
* calculated from all permutations of tokens of given pools.
|
|
10
|
+
*
|
|
11
|
+
* E.g. permutation of pool A={1,3} is 2, such as {1,3}, {3,1} where 1 are 3
|
|
12
|
+
* are pool assets(tokens)
|
|
13
|
+
*
|
|
14
|
+
* Filtering of valid paths and corresponding asset pairs is done by router itself!!!
|
|
15
|
+
*
|
|
16
|
+
* @param tokenIn - tokenIn
|
|
17
|
+
* @param tokenOut - tokenOut or null if all possible paths from tokenIn are requested
|
|
18
|
+
* @param pools - substrate based pools
|
|
19
|
+
* @returns all possible path proposals
|
|
20
|
+
*/
|
|
21
|
+
getProposals(tokenIn: number, tokenOut: number | null, pools: PoolBase[]): Edge[][];
|
|
22
|
+
private parsePaths;
|
|
23
|
+
private toEdge;
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Hop, PoolBuy, PoolError, PoolSell } from '../pool';
|
|
2
|
+
export interface Humanizer {
|
|
3
|
+
toHuman(): any;
|
|
4
|
+
}
|
|
5
|
+
export type Swap = Hop & Humanizer & {
|
|
6
|
+
assetInDecimals: number;
|
|
7
|
+
assetOutDecimals: number;
|
|
8
|
+
amountIn: bigint;
|
|
9
|
+
amountOut: bigint;
|
|
10
|
+
spotPrice: bigint;
|
|
11
|
+
tradeFeePct: number;
|
|
12
|
+
tradeFeeRange?: [number, number];
|
|
13
|
+
priceImpactPct: number;
|
|
14
|
+
errors: PoolError[];
|
|
15
|
+
};
|
|
16
|
+
export type SellSwap = Swap & PoolSell;
|
|
17
|
+
export type BuySwap = Swap & PoolBuy;
|
|
18
|
+
export declare enum TradeType {
|
|
19
|
+
Buy = "Buy",
|
|
20
|
+
Sell = "Sell"
|
|
21
|
+
}
|
|
22
|
+
export interface Trade extends Humanizer {
|
|
23
|
+
type: TradeType;
|
|
24
|
+
amountIn: bigint;
|
|
25
|
+
amountOut: bigint;
|
|
26
|
+
spotPrice: bigint;
|
|
27
|
+
tradeFee: bigint;
|
|
28
|
+
tradeFeePct: number;
|
|
29
|
+
priceImpactPct: number;
|
|
30
|
+
swaps: Swap[];
|
|
31
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { XcmV3Junctions } from '@galacticcouncil/descriptors';
|
|
2
|
+
export type Amount = {
|
|
3
|
+
amount: bigint;
|
|
4
|
+
decimals: number;
|
|
5
|
+
};
|
|
6
|
+
export interface AssetAmount {
|
|
7
|
+
id: number;
|
|
8
|
+
amount: bigint;
|
|
9
|
+
}
|
|
10
|
+
export interface AssetMetadata {
|
|
11
|
+
decimals: number;
|
|
12
|
+
symbol: string;
|
|
13
|
+
}
|
|
14
|
+
export type AssetType = 'StableSwap' | 'Bond' | 'Token' | 'External' | 'Erc20';
|
|
15
|
+
export interface Asset extends AssetMetadata {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
icon: string;
|
|
19
|
+
type: AssetType;
|
|
20
|
+
existentialDeposit: bigint;
|
|
21
|
+
isSufficient: boolean;
|
|
22
|
+
location?: XcmV3Multilocation;
|
|
23
|
+
meta?: Record<string, string>;
|
|
24
|
+
isWhiteListed?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface Bond extends Asset {
|
|
27
|
+
underlyingAssetId: number;
|
|
28
|
+
maturity: number;
|
|
29
|
+
}
|
|
30
|
+
export interface ExternalAsset extends AssetMetadata {
|
|
31
|
+
id: string;
|
|
32
|
+
origin: number;
|
|
33
|
+
name: string;
|
|
34
|
+
internalId: number;
|
|
35
|
+
isWhiteListed?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export type XcmV3Multilocation = {
|
|
38
|
+
parents: number;
|
|
39
|
+
interior: XcmV3Junctions;
|
|
40
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IQueue<T> {
|
|
2
|
+
enqueue(item: T): void;
|
|
3
|
+
dequeue(): T | undefined;
|
|
4
|
+
size(): number;
|
|
5
|
+
}
|
|
6
|
+
export declare class Queue<T> implements IQueue<T> {
|
|
7
|
+
private capacity;
|
|
8
|
+
private storage;
|
|
9
|
+
constructor(capacity?: number);
|
|
10
|
+
enqueue(item: T): void;
|
|
11
|
+
dequeue(): T | undefined;
|
|
12
|
+
size(): number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface IStack<T> {
|
|
2
|
+
push(item: T): void;
|
|
3
|
+
pop(): T | undefined;
|
|
4
|
+
peek(): T | undefined;
|
|
5
|
+
size(): number;
|
|
6
|
+
}
|
|
7
|
+
export declare class Stack<T> implements IStack<T> {
|
|
8
|
+
private capacity;
|
|
9
|
+
private storage;
|
|
10
|
+
constructor(capacity?: number);
|
|
11
|
+
push(item: T): void;
|
|
12
|
+
pop(): T | undefined;
|
|
13
|
+
peek(): T | undefined;
|
|
14
|
+
size(): number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Percentage Difference Formula
|
|
3
|
+
*
|
|
4
|
+
* (|๐1โ๐2| / [(๐1+๐2)/2]) ร 100
|
|
5
|
+
*
|
|
6
|
+
* This formula calculates the percentage difference by comparing
|
|
7
|
+
* the absolute difference between the two values with their <b>average</b>.
|
|
8
|
+
*
|
|
9
|
+
* Usage: It's used when you want to find the percentage difference between
|
|
10
|
+
* two quantities where both quantities are significant.
|
|
11
|
+
*
|
|
12
|
+
* @param v1 - 1st value
|
|
13
|
+
* @param v2 - 2nd value
|
|
14
|
+
* @returns Difference between two values in relation to their average
|
|
15
|
+
*/
|
|
16
|
+
export declare function calculateDiffToAvg(v1: bigint, v2: bigint): number;
|
|
17
|
+
/**
|
|
18
|
+
* Percentage Difference Formula (Relative Change)
|
|
19
|
+
*
|
|
20
|
+
* ((Vfin-Vref) / Vref) * 100
|
|
21
|
+
*
|
|
22
|
+
* This formula calculates the percentage difference by comparing
|
|
23
|
+
* the absolute difference between the two values with the <b>reference value</b>.
|
|
24
|
+
*
|
|
25
|
+
* Usage: This formula isn't suitable for finding percentage differences
|
|
26
|
+
* when the values being compared are not reference and final values of the
|
|
27
|
+
* same quantity.
|
|
28
|
+
*
|
|
29
|
+
* @param vFin - final value
|
|
30
|
+
* @param vRef - reference value
|
|
31
|
+
* @returns Difference between a final value and a reference value in relation to the reference value
|
|
32
|
+
*/
|
|
33
|
+
export declare function calculateDiffToRef(vFin: bigint, vRef: bigint): number;
|
|
34
|
+
/**
|
|
35
|
+
* The total fee paid for a โsellโ transaction
|
|
36
|
+
* Suppose the trader is selling X for Y
|
|
37
|
+
*
|
|
38
|
+
* fee = 1 - (deltaY / delta0Y)
|
|
39
|
+
*
|
|
40
|
+
* @param delta0Y - the amount out if fees are zero
|
|
41
|
+
* @param deltaY - the amount out if the existing nonzero fees are included in the calculation
|
|
42
|
+
*/
|
|
43
|
+
export declare function calculateSellFee(delta0Y: bigint, deltaY: bigint): number;
|
|
44
|
+
/**
|
|
45
|
+
* The total fee paid for a โbuyโ transaction
|
|
46
|
+
* Suppose the trader is buying Y using X
|
|
47
|
+
*
|
|
48
|
+
* fee = (deltaX / delta0X) - 1
|
|
49
|
+
*
|
|
50
|
+
* @param delta0X - the amount in if fees are zero
|
|
51
|
+
* @param deltaX - the amount in, inclusive of fees
|
|
52
|
+
*/
|
|
53
|
+
export declare function calculateBuyFee(delta0X: bigint, deltaX: bigint): number;
|
|
54
|
+
/**
|
|
55
|
+
* Get % fraction from native value
|
|
56
|
+
*
|
|
57
|
+
* @param value - native amount
|
|
58
|
+
* @param pct - percentage value
|
|
59
|
+
* @param dp - safe decimals margin (2dp = 0.01%)
|
|
60
|
+
* @returns fraction of given amount
|
|
61
|
+
*/
|
|
62
|
+
export declare function getFraction(value: bigint, pct: number, dp?: number): bigint;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Breadth First Search.
|
|
3
|
+
*
|
|
4
|
+
* - uses Queue to find the shortest path
|
|
5
|
+
* - slower than DFS (Depth First Search)
|
|
6
|
+
* - better when dst is closer to src
|
|
7
|
+
* - complexity O(N+E) where N are nodes and E are edges
|
|
8
|
+
*/
|
|
9
|
+
export declare class Bfs {
|
|
10
|
+
/**
|
|
11
|
+
* Check if current node is already present in path
|
|
12
|
+
*
|
|
13
|
+
* @param x - current node
|
|
14
|
+
* @param path - path
|
|
15
|
+
* @returns true if node in path, otherwise false
|
|
16
|
+
*/
|
|
17
|
+
isNotVisited(x: number, path: number[]): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Finding paths in graph from given source to destination
|
|
20
|
+
*
|
|
21
|
+
* @param g - routes graph containing nodes & corresponding edges
|
|
22
|
+
* @param src - source node
|
|
23
|
+
* @param dst - destination node
|
|
24
|
+
* @returns paths
|
|
25
|
+
*/
|
|
26
|
+
findPaths(g: number[][], src: number, dst: number): number[][];
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function convertToId(xcAddress: string): number;
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@galacticcouncil/sdk-next",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Galactic next gen sdk (papi)",
|
|
5
|
+
"author": "GalacticCouncil",
|
|
6
|
+
"repository": {
|
|
7
|
+
"directory": "packages/sdk-next",
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/galacticcouncil/sdk.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"hydration",
|
|
13
|
+
"api",
|
|
14
|
+
"router",
|
|
15
|
+
"sdk"
|
|
16
|
+
],
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/galacticcouncil/sdk/issues"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"build"
|
|
22
|
+
],
|
|
23
|
+
"main": "./build/index.cjs",
|
|
24
|
+
"module": "./build/index.mjs",
|
|
25
|
+
"types": "./build/types/index.d.ts",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "npm run clean && node ./esbuild.dist.mjs",
|
|
28
|
+
"build:watch": "node ./esbuild.dev.mjs",
|
|
29
|
+
"postbuild": "tsc --emitDeclarationOnly --outDir build/types/",
|
|
30
|
+
"clean": "rimraf build",
|
|
31
|
+
"link": "npm ln",
|
|
32
|
+
"test": "NODE_NO_WARNINGS=1 jest"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/big.js": "^6.2.2"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@galacticcouncil/descriptors": "^1.1.1",
|
|
39
|
+
"@galacticcouncil/math-lbp": "^1.0.0",
|
|
40
|
+
"@galacticcouncil/math-liquidity-mining": "^1.0.0",
|
|
41
|
+
"@galacticcouncil/math-omnipool": "^1.1.0",
|
|
42
|
+
"@galacticcouncil/math-stableswap": "^2.0.0",
|
|
43
|
+
"@galacticcouncil/math-xyk": "^1.0.0",
|
|
44
|
+
"@noble/hashes": "^1.6.1",
|
|
45
|
+
"@thi.ng/cache": "^2.1.35",
|
|
46
|
+
"@thi.ng/memoize": "^4.0.2",
|
|
47
|
+
"big.js": "^6.2.1"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"polkadot-api": "^1.11.1",
|
|
51
|
+
"viem": "^2.23.7"
|
|
52
|
+
}
|
|
53
|
+
}
|