@galacticcouncil/sdk 6.2.0 → 7.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 +99 -41
- package/build/index.cjs +2 -2
- package/build/index.mjs +2 -2
- package/build/types/{client → api}/PolkadotApi.d.ts +3 -0
- package/build/types/api/index.d.ts +2 -3
- package/build/types/api/types.d.ts +8 -0
- package/build/types/client/AssetClient.d.ts +2 -2
- package/build/types/client/BalanceClient.d.ts +1 -1
- package/build/types/client/FarmClient.d.ts +1 -1
- package/build/types/client/index.d.ts +0 -1
- package/build/types/consts.d.ts +6 -7
- package/build/types/errors.d.ts +1 -1
- package/build/types/{pool/aave/AaveAbi.d.ts → evm/abi/Aave.d.ts} +48 -0
- package/build/types/evm/abi/Erc20.d.ts +150 -0
- package/build/types/evm/abi/index.d.ts +1 -0
- package/build/types/evm/chain.d.ts +2 -0
- package/build/types/evm/client.d.ts +11 -0
- package/build/types/evm/const.d.ts +4 -0
- package/build/types/evm/index.d.ts +4 -0
- package/build/types/index.d.ts +7 -4
- package/build/types/pool/CachingPoolService.d.ts +2 -2
- package/build/types/pool/PoolClient.d.ts +2 -1
- package/build/types/pool/PoolFactory.d.ts +1 -1
- package/build/types/pool/PoolService.d.ts +10 -14
- package/build/types/pool/aave/AavePool.d.ts +3 -3
- package/build/types/pool/aave/AavePoolClient.d.ts +1 -1
- package/build/types/pool/index.d.ts +1 -1
- package/build/types/pool/lbp/LbpPool.d.ts +3 -3
- package/build/types/pool/lbp/LbpPoolClient.d.ts +1 -1
- package/build/types/pool/omni/OmniPool.d.ts +3 -3
- package/build/types/pool/omni/OmniPoolClient.d.ts +1 -1
- package/build/types/pool/stable/StableSwap.d.ts +3 -3
- package/build/types/pool/stable/StableSwapClient.d.ts +1 -1
- package/build/types/pool/types.d.ts +81 -0
- package/build/types/pool/xyk/XykPool.d.ts +3 -3
- package/build/types/pool/xyk/XykPoolClient.d.ts +1 -1
- package/build/types/{api → sor}/Router.d.ts +2 -1
- package/build/types/{api → sor}/TradeRouter.d.ts +3 -1
- package/build/types/sor/TradeUtils.d.ts +25 -0
- package/build/types/sor/index.d.ts +4 -0
- package/build/types/{route → sor/route}/graph.d.ts +1 -1
- package/build/types/{route → sor/route}/suggester.d.ts +1 -1
- package/build/types/sor/types.d.ts +34 -0
- package/build/types/types.d.ts +8 -127
- package/build/types/utils/erc20.d.ts +3 -3
- package/build/types/utils/h160.d.ts +11 -0
- package/build/types/utils/mapper.d.ts +1 -1
- package/build/types/utils/math.d.ts +8 -0
- package/package.json +1 -1
- package/build/types/api/WalletCtx.d.ts +0 -20
- package/build/types/pool/PoolUtils.d.ts +0 -12
- package/build/types/{route → sor/route}/bfs.d.ts +0 -0
- package/build/types/{route → sor/route}/index.d.ts +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
export declare const ERC20_ABI: readonly [{
|
|
2
|
+
readonly anonymous: false;
|
|
3
|
+
readonly inputs: readonly [{
|
|
4
|
+
readonly indexed: true;
|
|
5
|
+
readonly internalType: "address";
|
|
6
|
+
readonly name: "owner";
|
|
7
|
+
readonly type: "address";
|
|
8
|
+
}, {
|
|
9
|
+
readonly indexed: true;
|
|
10
|
+
readonly internalType: "address";
|
|
11
|
+
readonly name: "spender";
|
|
12
|
+
readonly type: "address";
|
|
13
|
+
}, {
|
|
14
|
+
readonly indexed: false;
|
|
15
|
+
readonly internalType: "uint256";
|
|
16
|
+
readonly name: "value";
|
|
17
|
+
readonly type: "uint256";
|
|
18
|
+
}];
|
|
19
|
+
readonly name: "Approval";
|
|
20
|
+
readonly type: "event";
|
|
21
|
+
}, {
|
|
22
|
+
readonly anonymous: false;
|
|
23
|
+
readonly inputs: readonly [{
|
|
24
|
+
readonly indexed: true;
|
|
25
|
+
readonly internalType: "address";
|
|
26
|
+
readonly name: "from";
|
|
27
|
+
readonly type: "address";
|
|
28
|
+
}, {
|
|
29
|
+
readonly indexed: true;
|
|
30
|
+
readonly internalType: "address";
|
|
31
|
+
readonly name: "to";
|
|
32
|
+
readonly type: "address";
|
|
33
|
+
}, {
|
|
34
|
+
readonly indexed: false;
|
|
35
|
+
readonly internalType: "uint256";
|
|
36
|
+
readonly name: "value";
|
|
37
|
+
readonly type: "uint256";
|
|
38
|
+
}];
|
|
39
|
+
readonly name: "Transfer";
|
|
40
|
+
readonly type: "event";
|
|
41
|
+
}, {
|
|
42
|
+
readonly inputs: readonly [{
|
|
43
|
+
readonly internalType: "address";
|
|
44
|
+
readonly name: "owner";
|
|
45
|
+
readonly type: "address";
|
|
46
|
+
}, {
|
|
47
|
+
readonly internalType: "address";
|
|
48
|
+
readonly name: "spender";
|
|
49
|
+
readonly type: "address";
|
|
50
|
+
}];
|
|
51
|
+
readonly name: "allowance";
|
|
52
|
+
readonly outputs: readonly [{
|
|
53
|
+
readonly internalType: "uint256";
|
|
54
|
+
readonly name: "";
|
|
55
|
+
readonly type: "uint256";
|
|
56
|
+
}];
|
|
57
|
+
readonly stateMutability: "view";
|
|
58
|
+
readonly type: "function";
|
|
59
|
+
}, {
|
|
60
|
+
readonly inputs: readonly [{
|
|
61
|
+
readonly internalType: "address";
|
|
62
|
+
readonly name: "spender";
|
|
63
|
+
readonly type: "address";
|
|
64
|
+
}, {
|
|
65
|
+
readonly internalType: "uint256";
|
|
66
|
+
readonly name: "amount";
|
|
67
|
+
readonly type: "uint256";
|
|
68
|
+
}];
|
|
69
|
+
readonly name: "approve";
|
|
70
|
+
readonly outputs: readonly [{
|
|
71
|
+
readonly internalType: "bool";
|
|
72
|
+
readonly name: "";
|
|
73
|
+
readonly type: "bool";
|
|
74
|
+
}];
|
|
75
|
+
readonly stateMutability: "nonpayable";
|
|
76
|
+
readonly type: "function";
|
|
77
|
+
}, {
|
|
78
|
+
readonly inputs: readonly [{
|
|
79
|
+
readonly internalType: "address";
|
|
80
|
+
readonly name: "account";
|
|
81
|
+
readonly type: "address";
|
|
82
|
+
}];
|
|
83
|
+
readonly name: "balanceOf";
|
|
84
|
+
readonly outputs: readonly [{
|
|
85
|
+
readonly internalType: "uint256";
|
|
86
|
+
readonly name: "";
|
|
87
|
+
readonly type: "uint256";
|
|
88
|
+
}];
|
|
89
|
+
readonly stateMutability: "view";
|
|
90
|
+
readonly type: "function";
|
|
91
|
+
}, {
|
|
92
|
+
readonly inputs: readonly [];
|
|
93
|
+
readonly name: "decimals";
|
|
94
|
+
readonly outputs: readonly [{
|
|
95
|
+
readonly name: "";
|
|
96
|
+
readonly type: "uint8";
|
|
97
|
+
}];
|
|
98
|
+
readonly stateMutability: "view";
|
|
99
|
+
readonly type: "function";
|
|
100
|
+
}, {
|
|
101
|
+
readonly inputs: readonly [];
|
|
102
|
+
readonly name: "totalSupply";
|
|
103
|
+
readonly outputs: readonly [{
|
|
104
|
+
readonly internalType: "uint256";
|
|
105
|
+
readonly name: "";
|
|
106
|
+
readonly type: "uint256";
|
|
107
|
+
}];
|
|
108
|
+
readonly stateMutability: "view";
|
|
109
|
+
readonly type: "function";
|
|
110
|
+
}, {
|
|
111
|
+
readonly inputs: readonly [{
|
|
112
|
+
readonly internalType: "address";
|
|
113
|
+
readonly name: "to";
|
|
114
|
+
readonly type: "address";
|
|
115
|
+
}, {
|
|
116
|
+
readonly internalType: "uint256";
|
|
117
|
+
readonly name: "amount";
|
|
118
|
+
readonly type: "uint256";
|
|
119
|
+
}];
|
|
120
|
+
readonly name: "transfer";
|
|
121
|
+
readonly outputs: readonly [{
|
|
122
|
+
readonly internalType: "bool";
|
|
123
|
+
readonly name: "";
|
|
124
|
+
readonly type: "bool";
|
|
125
|
+
}];
|
|
126
|
+
readonly stateMutability: "nonpayable";
|
|
127
|
+
readonly type: "function";
|
|
128
|
+
}, {
|
|
129
|
+
readonly inputs: readonly [{
|
|
130
|
+
readonly internalType: "address";
|
|
131
|
+
readonly name: "from";
|
|
132
|
+
readonly type: "address";
|
|
133
|
+
}, {
|
|
134
|
+
readonly internalType: "address";
|
|
135
|
+
readonly name: "to";
|
|
136
|
+
readonly type: "address";
|
|
137
|
+
}, {
|
|
138
|
+
readonly internalType: "uint256";
|
|
139
|
+
readonly name: "amount";
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
}];
|
|
142
|
+
readonly name: "transferFrom";
|
|
143
|
+
readonly outputs: readonly [{
|
|
144
|
+
readonly internalType: "bool";
|
|
145
|
+
readonly name: "";
|
|
146
|
+
readonly type: "bool";
|
|
147
|
+
}];
|
|
148
|
+
readonly stateMutability: "nonpayable";
|
|
149
|
+
readonly type: "function";
|
|
150
|
+
}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Aave';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Chain, PublicClient, WalletClient } from 'viem';
|
|
2
|
+
export declare class EvmClient {
|
|
3
|
+
readonly chain: Chain;
|
|
4
|
+
constructor(chain?: Chain);
|
|
5
|
+
get chainId(): number;
|
|
6
|
+
get chainCurrency(): string;
|
|
7
|
+
get chainDecimals(): number;
|
|
8
|
+
getProvider(): PublicClient;
|
|
9
|
+
getWsProvider(): PublicClient;
|
|
10
|
+
getSigner(address: string): WalletClient;
|
|
11
|
+
}
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './pool';
|
|
1
|
+
export * from './consts';
|
|
3
2
|
export * from './client';
|
|
4
|
-
export * from './types';
|
|
5
3
|
export * from './errors';
|
|
6
|
-
export * from './
|
|
4
|
+
export * from './evm';
|
|
5
|
+
export * from './pool';
|
|
6
|
+
export * from './sor';
|
|
7
|
+
export * from './types';
|
|
7
8
|
export * from './utils/bignumber';
|
|
9
|
+
export * from './utils/erc20';
|
|
10
|
+
export * from './utils/h160';
|
|
8
11
|
export * from './utils/math';
|
|
9
12
|
export * from './utils/json';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PoolService } from './PoolService';
|
|
2
|
-
import { Pool, PoolFees, PoolPair } from '../types';
|
|
3
1
|
import { ApiPromise } from '@polkadot/api';
|
|
2
|
+
import { Pool, PoolFees, PoolPair } from './types';
|
|
3
|
+
import { PoolService } from './PoolService';
|
|
4
4
|
export declare class CachingPoolService extends PoolService {
|
|
5
5
|
private feeCache;
|
|
6
6
|
private disconnectSubscribeNewHeads;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ApiPromise } from '@polkadot/api';
|
|
2
2
|
import { UnsubscribePromise } from '@polkadot/api-base/types';
|
|
3
3
|
import { BalanceClient } from '../client';
|
|
4
|
-
import { Asset
|
|
4
|
+
import { Asset } from '../types';
|
|
5
|
+
import { PoolBase, PoolFees, PoolPair, PoolType } from './types';
|
|
5
6
|
export declare abstract class PoolClient extends BalanceClient {
|
|
6
7
|
protected pools: PoolBase[];
|
|
7
8
|
protected subs: UnsubscribePromise[];
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
2
|
+
import { PolkadotApiClient } from '../api';
|
|
3
|
+
import { AssetClient } from '../client';
|
|
4
|
+
import { Asset, ExternalAsset } from '../types';
|
|
5
|
+
import { AavePoolClient } from './aave';
|
|
6
|
+
import { LbpPoolClient } from './lbp';
|
|
7
|
+
import { OmniPoolClient } from './omni';
|
|
8
|
+
import { XykPoolClient } from './xyk';
|
|
9
|
+
import { StableSwapClient } from './stable';
|
|
10
|
+
import { IPoolService, Pool, PoolBase, PoolFees, PoolPair, PoolType } from './types';
|
|
10
11
|
import { PoolClient } from './PoolClient';
|
|
11
12
|
export declare class PoolService extends PolkadotApiClient implements IPoolService {
|
|
12
13
|
protected readonly api: ApiPromise;
|
|
@@ -24,11 +25,6 @@ export declare class PoolService extends PolkadotApiClient implements IPoolServi
|
|
|
24
25
|
get isRegistrySynced(): boolean;
|
|
25
26
|
syncRegistry(external?: ExternalAsset[]): Promise<void>;
|
|
26
27
|
getPools(includeOnly: PoolType[]): Promise<PoolBase[]>;
|
|
27
|
-
|
|
28
|
+
destroy(): void;
|
|
28
29
|
getPoolFees(poolPair: PoolPair, pool: Pool): Promise<PoolFees>;
|
|
29
|
-
private isDirectOmnipoolTrade;
|
|
30
|
-
private dryRun;
|
|
31
|
-
buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
|
|
32
|
-
buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
|
|
33
|
-
buildSellAllTx(assetIn: string, assetOut: string, minAmountOut: BigNumber, route: Hop[]): Transaction;
|
|
34
30
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
2
|
import { BigNumber } from '../../utils/bignumber';
|
|
3
3
|
export declare class AavePool implements Pool {
|
|
4
4
|
type: PoolType;
|
|
@@ -11,8 +11,8 @@ export declare class AavePool implements Pool {
|
|
|
11
11
|
constructor(address: string, tokens: PoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number);
|
|
12
12
|
validatePair(_tokenIn: string, _tokenOut: string): boolean;
|
|
13
13
|
parsePair(tokenIn: string, tokenOut: string): PoolPair;
|
|
14
|
-
validateAndBuy(poolPair: PoolPair, amountOut: BigNumber, _fees: PoolFees):
|
|
15
|
-
validateAndSell(poolPair: PoolPair, amountIn: BigNumber, _fees: PoolFees):
|
|
14
|
+
validateAndBuy(poolPair: PoolPair, amountOut: BigNumber, _fees: PoolFees): BuyCtx;
|
|
15
|
+
validateAndSell(poolPair: PoolPair, amountIn: BigNumber, _fees: PoolFees): SellCtx;
|
|
16
16
|
calculateInGivenOut(_poolPair: PoolPair, amountOut: BigNumber): BigNumber;
|
|
17
17
|
calculateOutGivenIn(_poolPair: PoolPair, amountIn: BigNumber): BigNumber;
|
|
18
18
|
spotPriceInGivenOut(poolPair: PoolPair): BigNumber;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsubscribePromise } from '@polkadot/api-base/types';
|
|
2
|
-
import { PoolBase, PoolType, PoolFees, PoolPair } from '
|
|
2
|
+
import { PoolBase, PoolType, PoolFees, PoolPair } from '../types';
|
|
3
3
|
import { PoolClient } from '../PoolClient';
|
|
4
4
|
export declare class AavePoolClient extends PoolClient {
|
|
5
5
|
isSupported(): boolean;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { CachingPoolService } from './CachingPoolService';
|
|
2
2
|
export { PoolFactory } from './PoolFactory';
|
|
3
3
|
export { PoolService } from './PoolService';
|
|
4
|
-
export * from './PoolUtils';
|
|
5
4
|
export * from './aave';
|
|
6
5
|
export * from './xyk';
|
|
7
6
|
export * from './omni';
|
|
8
7
|
export * from './lbp';
|
|
9
8
|
export * from './stable';
|
|
9
|
+
export * from './types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFee, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
2
|
import { BigNumber } from '../../utils/bignumber';
|
|
3
3
|
export type WeightedPoolPair = PoolPair & {
|
|
4
4
|
weightIn: BigNumber;
|
|
@@ -34,14 +34,14 @@ export declare class LbpPool implements Pool {
|
|
|
34
34
|
* a) Accumulated asset is bought (out) from the pool for distributed asset (in) - User(Buyer) bears the fee
|
|
35
35
|
* b) Distributed asset is bought (out) from the pool for accumualted asset (in) - Pool bears the fee
|
|
36
36
|
*/
|
|
37
|
-
validateAndBuy(poolPair: WeightedPoolPair, amountOut: BigNumber, fees: LbpPoolFees):
|
|
37
|
+
validateAndBuy(poolPair: WeightedPoolPair, amountOut: BigNumber, fees: LbpPoolFees): BuyCtx;
|
|
38
38
|
/**
|
|
39
39
|
* Validate sell transfer
|
|
40
40
|
*
|
|
41
41
|
* a) Accumulated asset is sold (in) to the pool for distributed asset (out) - Pool bears the fee
|
|
42
42
|
* b) Distributed asset is sold (in) to the pool for accumualted asset (out) - User(Seller) bears the fee
|
|
43
43
|
*/
|
|
44
|
-
validateAndSell(poolPair: WeightedPoolPair, amountIn: BigNumber, fees: LbpPoolFees):
|
|
44
|
+
validateAndSell(poolPair: WeightedPoolPair, amountIn: BigNumber, fees: LbpPoolFees): SellCtx;
|
|
45
45
|
calculateInGivenOut(poolPair: WeightedPoolPair, amountOut: BigNumber): BigNumber;
|
|
46
46
|
calculateOutGivenIn(poolPair: WeightedPoolPair, amountIn: BigNumber): BigNumber;
|
|
47
47
|
spotPriceInGivenOut(poolPair: WeightedPoolPair): BigNumber;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsubscribePromise } from '@polkadot/api-base/types';
|
|
2
|
-
import { PoolBase, PoolFees, PoolPair, PoolType } from '
|
|
2
|
+
import { PoolBase, PoolFees, PoolPair, PoolType } from '../types';
|
|
3
3
|
import { PoolClient } from '../PoolClient';
|
|
4
4
|
export declare class LbpPoolClient extends PoolClient {
|
|
5
5
|
private readonly MAX_FINAL_WEIGHT;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFee, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
2
|
import { BigNumber } from '../../utils/bignumber';
|
|
3
3
|
export type OmniPoolPair = PoolPair & {
|
|
4
4
|
hubReservesIn: BigNumber;
|
|
@@ -33,8 +33,8 @@ export declare class OmniPool implements Pool {
|
|
|
33
33
|
constructor(address: string, tokens: OmniPoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number, hubAssetId: string);
|
|
34
34
|
validatePair(_tokenIn: string, tokenOut: string): boolean;
|
|
35
35
|
parsePair(tokenIn: string, tokenOut: string): OmniPoolPair;
|
|
36
|
-
validateAndBuy(poolPair: OmniPoolPair, amountOut: BigNumber, fees: OmniPoolFees):
|
|
37
|
-
validateAndSell(poolPair: OmniPoolPair, amountIn: BigNumber, fees: OmniPoolFees):
|
|
36
|
+
validateAndBuy(poolPair: OmniPoolPair, amountOut: BigNumber, fees: OmniPoolFees): BuyCtx;
|
|
37
|
+
validateAndSell(poolPair: OmniPoolPair, amountIn: BigNumber, fees: OmniPoolFees): SellCtx;
|
|
38
38
|
calculateInGivenOut(poolPair: OmniPoolPair, amountOut: BigNumber, fees?: OmniPoolFees): BigNumber;
|
|
39
39
|
calculateLrnaInGivenOut(poolPair: OmniPoolPair, amountOut: BigNumber, fees?: OmniPoolFees): BigNumber;
|
|
40
40
|
calculateOutGivenIn(poolPair: OmniPoolPair, amountIn: BigNumber, fees?: OmniPoolFees): BigNumber;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsubscribePromise } from '@polkadot/api-base/types';
|
|
2
|
-
import { PoolBase, PoolType, PoolFees, PoolPair } from '
|
|
2
|
+
import { PoolBase, PoolType, PoolFees, PoolPair } from '../types';
|
|
3
3
|
import { PoolClient } from '../PoolClient';
|
|
4
4
|
export declare class OmniPoolClient extends PoolClient {
|
|
5
5
|
isSupported(): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFee, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
2
|
import { BigNumber } from '../../utils/bignumber';
|
|
3
3
|
export type StableSwapPair = PoolPair & {
|
|
4
4
|
tradeableIn: number;
|
|
@@ -32,8 +32,8 @@ export declare class StableSwap implements Pool {
|
|
|
32
32
|
constructor(address: string, tokens: PoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number, amplification: string, id: string, fee: PoolFee, totalIssuance: string, pegs: string[][], pegsFee: PoolFee);
|
|
33
33
|
validatePair(_tokenIn: string, _tokenOut: string): boolean;
|
|
34
34
|
parsePair(tokenIn: string, tokenOut: string): StableSwapPair;
|
|
35
|
-
validateAndBuy(poolPair: StableSwapPair, amountOut: BigNumber, fees: StableSwapFees):
|
|
36
|
-
validateAndSell(poolPair: StableSwapPair, amountIn: BigNumber, fees: StableSwapFees):
|
|
35
|
+
validateAndBuy(poolPair: StableSwapPair, amountOut: BigNumber, fees: StableSwapFees): BuyCtx;
|
|
36
|
+
validateAndSell(poolPair: StableSwapPair, amountIn: BigNumber, fees: StableSwapFees): SellCtx;
|
|
37
37
|
private calculateIn;
|
|
38
38
|
private calculateAddOneAsset;
|
|
39
39
|
private calculateSharesForAmount;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsubscribePromise } from '@polkadot/api-base/types';
|
|
2
|
-
import { PoolBase, PoolType, PoolFees, PoolPair } from '
|
|
2
|
+
import { PoolBase, PoolType, PoolFees, PoolPair } from '../types';
|
|
3
3
|
import { PoolClient } from '../PoolClient';
|
|
4
4
|
export declare const AMOUNT_MAX = 340282366920938463463374607431768211455n;
|
|
5
5
|
export declare class StableSwapClient extends PoolClient {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Asset } from '../types';
|
|
2
|
+
import type { BigNumber } from '../utils/bignumber';
|
|
3
|
+
export declare enum PoolType {
|
|
4
|
+
Aave = "Aave",
|
|
5
|
+
LBP = "Lbp",
|
|
6
|
+
Omni = "Omnipool",
|
|
7
|
+
Stable = "Stableswap",
|
|
8
|
+
XYK = "Xyk"
|
|
9
|
+
}
|
|
10
|
+
export declare enum PoolError {
|
|
11
|
+
UnknownError = "UnknownError",
|
|
12
|
+
InsufficientTradingAmount = "InsufficientTradingAmount",
|
|
13
|
+
MaxInRatioExceeded = "MaxInRatioExceeded",
|
|
14
|
+
MaxOutRatioExceeded = "MaxOutRatioExceeded",
|
|
15
|
+
TradeNotAllowed = "TradeNotAllowed"
|
|
16
|
+
}
|
|
17
|
+
export interface PoolPair {
|
|
18
|
+
assetIn: string;
|
|
19
|
+
assetOut: string;
|
|
20
|
+
decimalsIn: number;
|
|
21
|
+
decimalsOut: number;
|
|
22
|
+
balanceIn: BigNumber;
|
|
23
|
+
balanceOut: BigNumber;
|
|
24
|
+
assetInED: BigNumber;
|
|
25
|
+
assetOutED: BigNumber;
|
|
26
|
+
}
|
|
27
|
+
export type PoolBase = {
|
|
28
|
+
address: string;
|
|
29
|
+
id?: string;
|
|
30
|
+
type: PoolType;
|
|
31
|
+
tokens: PoolToken[];
|
|
32
|
+
maxInRatio: number;
|
|
33
|
+
maxOutRatio: number;
|
|
34
|
+
minTradingLimit: number;
|
|
35
|
+
};
|
|
36
|
+
export interface PoolToken extends Asset {
|
|
37
|
+
id: string;
|
|
38
|
+
balance: string;
|
|
39
|
+
tradeable?: number;
|
|
40
|
+
}
|
|
41
|
+
export type PoolLimits = Pick<PoolBase, 'maxInRatio' | 'maxOutRatio' | 'minTradingLimit'>;
|
|
42
|
+
export type PoolFee = [numerator: number, denominator: number];
|
|
43
|
+
export type PoolFees = {
|
|
44
|
+
min?: PoolFee;
|
|
45
|
+
max?: PoolFee;
|
|
46
|
+
};
|
|
47
|
+
export type PoolSell = {
|
|
48
|
+
calculatedOut: BigNumber;
|
|
49
|
+
};
|
|
50
|
+
export type PoolBuy = {
|
|
51
|
+
calculatedIn: BigNumber;
|
|
52
|
+
};
|
|
53
|
+
export type PoolSwap = {
|
|
54
|
+
amountIn: BigNumber;
|
|
55
|
+
amountOut: BigNumber;
|
|
56
|
+
feePct: number;
|
|
57
|
+
errors: PoolError[];
|
|
58
|
+
};
|
|
59
|
+
export type SellCtx = PoolSwap & PoolSell;
|
|
60
|
+
export type BuyCtx = PoolSwap & PoolBuy;
|
|
61
|
+
export interface Pool extends PoolBase {
|
|
62
|
+
validatePair(tokenIn: string, tokenOut: string): boolean;
|
|
63
|
+
parsePair(tokenIn: string, tokenOut: string): PoolPair;
|
|
64
|
+
validateAndBuy(poolPair: PoolPair, amountOut: BigNumber, dynamicFees: PoolFees | null): BuyCtx;
|
|
65
|
+
validateAndSell(poolPair: PoolPair, amountOut: BigNumber, dynamicFees: PoolFees | null): SellCtx;
|
|
66
|
+
calculateInGivenOut(poolPair: PoolPair, amountOut: BigNumber): BigNumber;
|
|
67
|
+
calculateOutGivenIn(poolPair: PoolPair, amountIn: BigNumber): BigNumber;
|
|
68
|
+
spotPriceInGivenOut(poolPair: PoolPair): BigNumber;
|
|
69
|
+
spotPriceOutGivenIn(poolPair: PoolPair): BigNumber;
|
|
70
|
+
}
|
|
71
|
+
export interface IPoolService {
|
|
72
|
+
getPools(includeOnly?: PoolType[]): Promise<PoolBase[]>;
|
|
73
|
+
getPoolFees(poolPair: PoolPair, pool: Pool): Promise<PoolFees>;
|
|
74
|
+
}
|
|
75
|
+
export type Hop = {
|
|
76
|
+
pool: PoolType;
|
|
77
|
+
poolAddress: string;
|
|
78
|
+
poolId?: string;
|
|
79
|
+
assetIn: string;
|
|
80
|
+
assetOut: string;
|
|
81
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFee, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
2
|
import { BigNumber } from '../../utils/bignumber';
|
|
3
3
|
export type XykPoolFees = PoolFees & {
|
|
4
4
|
exchangeFee: PoolFee;
|
|
@@ -14,8 +14,8 @@ export declare class XykPool implements Pool {
|
|
|
14
14
|
constructor(address: string, tokens: PoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number);
|
|
15
15
|
validatePair(_tokenIn: string, _tokenOut: string): boolean;
|
|
16
16
|
parsePair(tokenIn: string, tokenOut: string): PoolPair;
|
|
17
|
-
validateAndBuy(poolPair: PoolPair, amountOut: BigNumber, fees: XykPoolFees):
|
|
18
|
-
validateAndSell(poolPair: PoolPair, amountIn: BigNumber, fees: XykPoolFees):
|
|
17
|
+
validateAndBuy(poolPair: PoolPair, amountOut: BigNumber, fees: XykPoolFees): BuyCtx;
|
|
18
|
+
validateAndSell(poolPair: PoolPair, amountIn: BigNumber, fees: XykPoolFees): SellCtx;
|
|
19
19
|
calculateInGivenOut(poolPair: PoolPair, amountOut: BigNumber): BigNumber;
|
|
20
20
|
calculateOutGivenIn(poolPair: PoolPair, amountIn: BigNumber): BigNumber;
|
|
21
21
|
spotPriceInGivenOut(poolPair: PoolPair): BigNumber;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsubscribePromise } from '@polkadot/api-base/types';
|
|
2
|
-
import { PoolBase, PoolType, PoolFees, PoolPair } from '
|
|
2
|
+
import { PoolBase, PoolType, PoolFees, PoolPair } from '../types';
|
|
3
3
|
import { PoolClient } from '../PoolClient';
|
|
4
4
|
export declare class XykPoolClient extends PoolClient {
|
|
5
5
|
isSupported(): boolean;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Router } from './Router';
|
|
2
|
-
import {
|
|
2
|
+
import { Hop } from '../pool';
|
|
3
|
+
import { Amount } from '../types';
|
|
3
4
|
import { BigNumber } from '../utils/bignumber';
|
|
5
|
+
import { Trade } from './types';
|
|
4
6
|
export declare class TradeRouter extends Router {
|
|
5
7
|
/**
|
|
6
8
|
* Check whether trade is direct or not
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ApiPromise } from '@polkadot/api';
|
|
2
|
+
import { PolkadotApiClient, Transaction } from '../api';
|
|
3
|
+
import { PoolType } from '../pool';
|
|
4
|
+
import { Swap, Trade } from './types';
|
|
5
|
+
export declare class TradeUtils extends PolkadotApiClient {
|
|
6
|
+
private balanceClient;
|
|
7
|
+
private evmClient;
|
|
8
|
+
constructor(api: ApiPromise);
|
|
9
|
+
buildBuyTx(trade: Trade, slippagePct?: number): Transaction;
|
|
10
|
+
buildSellTx(trade: Trade, slippagePct?: number): Transaction;
|
|
11
|
+
buildSellAllTx(trade: Trade, slippagePct?: number): Transaction;
|
|
12
|
+
buildWithdrawAndSellReserveTx(beneficiary: string, trade: Trade, slippagePct?: number): Promise<Transaction>;
|
|
13
|
+
buildRoute(swaps: Swap[]): ({
|
|
14
|
+
pool: {
|
|
15
|
+
Stableswap: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
assetIn: string;
|
|
18
|
+
assetOut: string;
|
|
19
|
+
} | {
|
|
20
|
+
pool: PoolType.Aave | PoolType.LBP | PoolType.Omni | PoolType.XYK;
|
|
21
|
+
assetIn: string;
|
|
22
|
+
assetOut: string;
|
|
23
|
+
})[];
|
|
24
|
+
isDirectOmnipoolTrade(swaps: Swap[]): boolean;
|
|
25
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Hop, PoolBuy, PoolError, PoolSell } from '../pool';
|
|
2
|
+
import type { BigNumber } from '../utils/bignumber';
|
|
3
|
+
export interface Humanizer {
|
|
4
|
+
toHuman(): any;
|
|
5
|
+
}
|
|
6
|
+
export type Swap = Hop & Humanizer & {
|
|
7
|
+
assetInDecimals: number;
|
|
8
|
+
assetOutDecimals: number;
|
|
9
|
+
amountIn: BigNumber;
|
|
10
|
+
amountOut: BigNumber;
|
|
11
|
+
spotPrice: BigNumber;
|
|
12
|
+
tradeFeePct: number;
|
|
13
|
+
tradeFeeRange?: [number, number];
|
|
14
|
+
priceImpactPct: number;
|
|
15
|
+
errors: PoolError[];
|
|
16
|
+
isSupply(): boolean;
|
|
17
|
+
isWithdraw(): boolean;
|
|
18
|
+
};
|
|
19
|
+
export type SellSwap = Swap & PoolSell;
|
|
20
|
+
export type BuySwap = Swap & PoolBuy;
|
|
21
|
+
export declare enum TradeType {
|
|
22
|
+
Buy = "Buy",
|
|
23
|
+
Sell = "Sell"
|
|
24
|
+
}
|
|
25
|
+
export interface Trade extends Humanizer {
|
|
26
|
+
type: TradeType;
|
|
27
|
+
amountIn: BigNumber;
|
|
28
|
+
amountOut: BigNumber;
|
|
29
|
+
spotPrice: BigNumber;
|
|
30
|
+
tradeFee: BigNumber;
|
|
31
|
+
tradeFeePct: number;
|
|
32
|
+
priceImpactPct: number;
|
|
33
|
+
swaps: Swap[];
|
|
34
|
+
}
|