@galacticcouncil/sdk 0.5.0-beta.0 → 0.5.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 +1 -0
- package/dist/index.esm.js +4 -17
- package/dist/index.js +4 -3
- package/dist/types/api/TradeRouter.d.ts +14 -0
- package/dist/types/errors.d.ts +3 -0
- package/dist/types/pool/CachingPoolService.d.ts +10 -0
- package/dist/types/pool/PoolClient.d.ts +3 -1
- package/dist/types/pool/PoolService.d.ts +2 -2
- package/dist/types/pool/index.d.ts +1 -0
- package/dist/types/pool/lbp/LbpPool.d.ts +5 -4
- package/dist/types/pool/lbp/LbpPoolClient.d.ts +6 -17
- package/dist/types/pool/omni/OmniPool.d.ts +3 -4
- package/dist/types/pool/omni/OmniPoolClient.d.ts +6 -8
- package/dist/types/pool/xyk/XykPool.d.ts +3 -4
- package/dist/types/pool/xyk/XykPoolClient.d.ts +4 -4
- package/dist/types/types.d.ts +6 -3
- package/package.json +5 -2
|
@@ -16,6 +16,20 @@ export declare class TradeRouter extends Router {
|
|
|
16
16
|
* @returns best sell swap if exist, otherwise first one found
|
|
17
17
|
*/
|
|
18
18
|
private findBestSellRoute;
|
|
19
|
+
/**
|
|
20
|
+
* Return route fee range [min,max] in case pool is using dynamic fees
|
|
21
|
+
*
|
|
22
|
+
* @param swaps - Trade routes
|
|
23
|
+
* @returns min & max fee range if swap through the pool with dynamic fees support
|
|
24
|
+
*/
|
|
25
|
+
private getRouteFeeRange;
|
|
26
|
+
/**
|
|
27
|
+
* Return pool fee range [min,max] in case pool is using dynamic fees
|
|
28
|
+
*
|
|
29
|
+
* @param fees - Pool fees
|
|
30
|
+
* @returns min & max fee range if swap through the pool with dynamic fees support
|
|
31
|
+
*/
|
|
32
|
+
private getPoolFeeRange;
|
|
19
33
|
/**
|
|
20
34
|
* Calculate and return best possible sell trade for assetIn>assetOut
|
|
21
35
|
*
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PoolService } from './PoolService';
|
|
2
|
+
import { PoolFees, Pool } from '../types';
|
|
3
|
+
import { ApiPromise } from '@polkadot/api';
|
|
4
|
+
export declare class CachingPoolService extends PoolService {
|
|
5
|
+
private feeCache;
|
|
6
|
+
private disconnectSubscribeNewHeads;
|
|
7
|
+
constructor(api: ApiPromise);
|
|
8
|
+
getPoolFees(feeAsset: string, pool: Pool): Promise<PoolFees>;
|
|
9
|
+
destroy(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { ApiPromise } from '@polkadot/api';
|
|
2
2
|
import type { StorageKey } from '@polkadot/types';
|
|
3
3
|
import type { AnyTuple, Codec } from '@polkadot/types/types';
|
|
4
|
-
import type { PoolToken } from '../types';
|
|
4
|
+
import type { PoolBase, PoolFees, PoolToken } from '../types';
|
|
5
5
|
import { BalanceClient } from '../client';
|
|
6
6
|
export declare abstract class PoolClient extends BalanceClient {
|
|
7
7
|
constructor(api: ApiPromise);
|
|
8
|
+
abstract getPools(): Promise<PoolBase[]>;
|
|
9
|
+
abstract getPoolFees(feeAsset: string, address: string): Promise<PoolFees>;
|
|
8
10
|
protected getStorageKey(asset: [StorageKey<AnyTuple>, Codec], index: number): string;
|
|
9
11
|
protected getStorageEntryArray(asset: [StorageKey<AnyTuple>, Codec]): string[];
|
|
10
12
|
protected getPoolTokens(poolAddress: string, assetKeys: string[]): Promise<PoolToken[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LbpPoolClient } from './lbp/LbpPoolClient';
|
|
2
2
|
import { OmniPoolClient } from './omni/OmniPoolClient';
|
|
3
3
|
import { XykPoolClient } from './xyk/XykPoolClient';
|
|
4
|
-
import { Hop, PoolBase, IPoolService, PoolType, Transaction, PoolFees } from '../types';
|
|
4
|
+
import { Hop, PoolBase, IPoolService, PoolType, Transaction, PoolFees, Pool } from '../types';
|
|
5
5
|
import { BigNumber } from '../utils/bignumber';
|
|
6
6
|
import { ApiPromise } from '@polkadot/api';
|
|
7
7
|
export declare class PoolService implements IPoolService {
|
|
@@ -11,7 +11,7 @@ export declare class PoolService implements IPoolService {
|
|
|
11
11
|
protected readonly lbpClient: LbpPoolClient;
|
|
12
12
|
constructor(api: ApiPromise);
|
|
13
13
|
getPools(includeOnly: PoolType[]): Promise<PoolBase[]>;
|
|
14
|
-
|
|
14
|
+
getPoolFees(feeAsset: string, pool: Pool): Promise<PoolFees>;
|
|
15
15
|
private isDirectOmnipoolTrade;
|
|
16
16
|
buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
|
|
17
17
|
buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
|
|
@@ -12,6 +12,7 @@ export type LbpPoolFees = PoolFees & {
|
|
|
12
12
|
repayFee: PoolFee;
|
|
13
13
|
};
|
|
14
14
|
export type LbpPoolBase = PoolBase & {
|
|
15
|
+
fee: PoolFee;
|
|
15
16
|
repayFeeApply: boolean;
|
|
16
17
|
};
|
|
17
18
|
export declare class LbpPool implements Pool {
|
|
@@ -21,10 +22,10 @@ export declare class LbpPool implements Pool {
|
|
|
21
22
|
maxInRatio: number;
|
|
22
23
|
maxOutRatio: number;
|
|
23
24
|
minTradingLimit: number;
|
|
24
|
-
|
|
25
|
+
fee: PoolFee;
|
|
25
26
|
repayFeeApply: boolean;
|
|
26
27
|
static fromPool(pool: LbpPoolBase): LbpPool;
|
|
27
|
-
constructor(address: string, tokens: WeightedPoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number,
|
|
28
|
+
constructor(address: string, tokens: WeightedPoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number, fee: PoolFee, repayFeeApply: boolean);
|
|
28
29
|
validatePair(_tokenIn: string, _tokenOut: string): boolean;
|
|
29
30
|
parsePair(tokenIn: string, tokenOut: string): WeightedPoolPair;
|
|
30
31
|
/**
|
|
@@ -33,14 +34,14 @@ export declare class LbpPool implements Pool {
|
|
|
33
34
|
* a) Accumulated asset is bought (out) from the pool for distributed asset (in) - User(Buyer) bears the fee
|
|
34
35
|
* b) Distributed asset is bought (out) from the pool for accumualted asset (in) - Pool bears the fee
|
|
35
36
|
*/
|
|
36
|
-
validateAndBuy(poolPair: WeightedPoolPair, amountOut: BigNumber,
|
|
37
|
+
validateAndBuy(poolPair: WeightedPoolPair, amountOut: BigNumber, fees: LbpPoolFees): BuyTransfer;
|
|
37
38
|
/**
|
|
38
39
|
* Validate sell transfer
|
|
39
40
|
*
|
|
40
41
|
* a) Accumulated asset is sold (in) to the pool for distributed asset (out) - Pool bears the fee
|
|
41
42
|
* b) Distributed asset is sold (in) to the pool for accumualted asset (out) - User(Seller) bears the fee
|
|
42
43
|
*/
|
|
43
|
-
validateAndSell(poolPair: WeightedPoolPair, amountIn: BigNumber,
|
|
44
|
+
validateAndSell(poolPair: WeightedPoolPair, amountIn: BigNumber, fees: LbpPoolFees): SellTransfer;
|
|
44
45
|
calculateInGivenOut(poolPair: WeightedPoolPair, amountOut: BigNumber): BigNumber;
|
|
45
46
|
calculateOutGivenIn(poolPair: WeightedPoolPair, amountIn: BigNumber): BigNumber;
|
|
46
47
|
spotPriceInGivenOut(poolPair: WeightedPoolPair): BigNumber;
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import { PoolBase,
|
|
1
|
+
import { PoolBase, PoolFees } from '../../types';
|
|
2
2
|
import { PoolClient } from '../PoolClient';
|
|
3
|
-
interface LbpPoolData {
|
|
4
|
-
readonly assets: string[];
|
|
5
|
-
readonly feeCollector: string;
|
|
6
|
-
readonly fee: number[];
|
|
7
|
-
readonly repayTarget: string;
|
|
8
|
-
readonly initialWeight: number;
|
|
9
|
-
readonly finalWeight: number;
|
|
10
|
-
readonly start: number;
|
|
11
|
-
readonly end: number;
|
|
12
|
-
}
|
|
13
3
|
export declare class LbpPoolClient extends PoolClient {
|
|
14
4
|
private readonly MAX_FINAL_WEIGHT;
|
|
15
5
|
private poolsData;
|
|
@@ -18,10 +8,9 @@ export declare class LbpPoolClient extends PoolClient {
|
|
|
18
8
|
getPools(): Promise<PoolBase[]>;
|
|
19
9
|
private loadPools;
|
|
20
10
|
private syncPools;
|
|
21
|
-
getLinearWeight
|
|
22
|
-
isRepayFeeApplied
|
|
23
|
-
getPoolFees(
|
|
24
|
-
getRepayFee
|
|
25
|
-
getPoolLimits
|
|
11
|
+
private getLinearWeight;
|
|
12
|
+
private isRepayFeeApplied;
|
|
13
|
+
getPoolFees(_feeAsset: string, address: string): Promise<PoolFees>;
|
|
14
|
+
private getRepayFee;
|
|
15
|
+
private getPoolLimits;
|
|
26
16
|
}
|
|
27
|
-
export {};
|
|
@@ -24,14 +24,13 @@ export declare class OmniPool implements Pool {
|
|
|
24
24
|
maxInRatio: number;
|
|
25
25
|
maxOutRatio: number;
|
|
26
26
|
minTradingLimit: number;
|
|
27
|
-
fees: OmniPoolFees;
|
|
28
27
|
hubAssetId: string;
|
|
29
28
|
static fromPool(pool: OmniPoolBase): OmniPool;
|
|
30
|
-
constructor(address: string, tokens: OmniPoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number,
|
|
29
|
+
constructor(address: string, tokens: OmniPoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number, hubAssetId: string);
|
|
31
30
|
validatePair(_tokenIn: string, tokenOut: string): boolean;
|
|
32
31
|
parsePair(tokenIn: string, tokenOut: string): OmniPoolPair;
|
|
33
|
-
validateAndBuy(poolPair: OmniPoolPair, amountOut: BigNumber,
|
|
34
|
-
validateAndSell(poolPair: OmniPoolPair, amountIn: BigNumber,
|
|
32
|
+
validateAndBuy(poolPair: OmniPoolPair, amountOut: BigNumber, fees: OmniPoolFees): BuyTransfer;
|
|
33
|
+
validateAndSell(poolPair: OmniPoolPair, amountIn: BigNumber, fees: OmniPoolFees): SellTransfer;
|
|
35
34
|
calculateInGivenOut(poolPair: OmniPoolPair, amountOut: BigNumber, fees?: OmniPoolFees): BigNumber;
|
|
36
35
|
calculateLrnaInGivenOut(poolPair: OmniPoolPair, amountOut: BigNumber, fees?: OmniPoolFees): BigNumber;
|
|
37
36
|
calculateOutGivenIn(poolPair: OmniPoolPair, amountIn: BigNumber, fees?: OmniPoolFees): BigNumber;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PoolBase,
|
|
2
|
-
import { OmniPoolFees } from './OmniPool';
|
|
1
|
+
import { PoolBase, PoolFees } from '../../types';
|
|
3
2
|
import { PoolClient } from '../PoolClient';
|
|
4
3
|
export declare class OmniPoolClient extends PoolClient {
|
|
5
4
|
private pools;
|
|
@@ -8,10 +7,9 @@ export declare class OmniPoolClient extends PoolClient {
|
|
|
8
7
|
private loadPool;
|
|
9
8
|
private syncPool;
|
|
10
9
|
private getPoolTokenState;
|
|
11
|
-
getPoolFees(): PoolFees
|
|
12
|
-
getAssetFee
|
|
13
|
-
getProtocolFee
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
getPoolLimits(): PoolLimits;
|
|
10
|
+
getPoolFees(feeAsset: string, _address: string): Promise<PoolFees>;
|
|
11
|
+
private getAssetFee;
|
|
12
|
+
private getProtocolFee;
|
|
13
|
+
private getPoolId;
|
|
14
|
+
private getPoolLimits;
|
|
17
15
|
}
|
|
@@ -10,13 +10,12 @@ export declare class XykPool implements Pool {
|
|
|
10
10
|
maxInRatio: number;
|
|
11
11
|
maxOutRatio: number;
|
|
12
12
|
minTradingLimit: number;
|
|
13
|
-
fees: XykPoolFees;
|
|
14
13
|
static fromPool(pool: PoolBase): XykPool;
|
|
15
|
-
constructor(address: string, tokens: PoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number
|
|
14
|
+
constructor(address: string, tokens: PoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number);
|
|
16
15
|
validatePair(_tokenIn: string, _tokenOut: string): boolean;
|
|
17
16
|
parsePair(tokenIn: string, tokenOut: string): PoolPair;
|
|
18
|
-
validateAndBuy(poolPair: PoolPair, amountOut: BigNumber,
|
|
19
|
-
validateAndSell(poolPair: PoolPair, amountIn: BigNumber,
|
|
17
|
+
validateAndBuy(poolPair: PoolPair, amountOut: BigNumber, fees: XykPoolFees): BuyTransfer;
|
|
18
|
+
validateAndSell(poolPair: PoolPair, amountIn: BigNumber, fees: XykPoolFees): SellTransfer;
|
|
20
19
|
calculateInGivenOut(poolPair: PoolPair, amountOut: BigNumber): BigNumber;
|
|
21
20
|
calculateOutGivenIn(poolPair: PoolPair, amountIn: BigNumber): BigNumber;
|
|
22
21
|
spotPriceInGivenOut(poolPair: PoolPair): BigNumber;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PoolBase,
|
|
1
|
+
import { PoolBase, PoolFees } from '../../types';
|
|
2
2
|
import { PoolClient } from '../PoolClient';
|
|
3
3
|
export declare class XykPoolClient extends PoolClient {
|
|
4
4
|
private pools;
|
|
@@ -6,7 +6,7 @@ export declare class XykPoolClient extends PoolClient {
|
|
|
6
6
|
getPools(): Promise<PoolBase[]>;
|
|
7
7
|
private loadPools;
|
|
8
8
|
private syncPools;
|
|
9
|
-
getPoolFees(): PoolFees
|
|
10
|
-
getExchangeFee
|
|
11
|
-
getPoolLimits
|
|
9
|
+
getPoolFees(_feeAsset: string, _address: string): Promise<PoolFees>;
|
|
10
|
+
private getExchangeFee;
|
|
11
|
+
private getPoolLimits;
|
|
12
12
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -26,14 +26,16 @@ export type PoolBase = {
|
|
|
26
26
|
address: string;
|
|
27
27
|
type: PoolType;
|
|
28
28
|
tokens: PoolToken[];
|
|
29
|
-
fees: PoolFees;
|
|
30
29
|
maxInRatio: number;
|
|
31
30
|
maxOutRatio: number;
|
|
32
31
|
minTradingLimit: number;
|
|
33
32
|
};
|
|
34
33
|
export type PoolLimits = Pick<PoolBase, 'maxInRatio' | 'maxOutRatio' | 'minTradingLimit'>;
|
|
35
34
|
export type PoolFee = [numerator: number, denominator: number];
|
|
36
|
-
export type PoolFees = {
|
|
35
|
+
export type PoolFees = {
|
|
36
|
+
min?: PoolFee;
|
|
37
|
+
max?: PoolFee;
|
|
38
|
+
};
|
|
37
39
|
export type PoolToken = PoolAsset & {
|
|
38
40
|
balance: string;
|
|
39
41
|
decimals: number;
|
|
@@ -64,7 +66,7 @@ export interface Pool extends PoolBase {
|
|
|
64
66
|
}
|
|
65
67
|
export interface IPoolService {
|
|
66
68
|
getPools(includeOnly?: PoolType[]): Promise<PoolBase[]>;
|
|
67
|
-
|
|
69
|
+
getPoolFees(feeAsset: string, pool: Pool): Promise<PoolFees>;
|
|
68
70
|
buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
|
|
69
71
|
buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
|
|
70
72
|
}
|
|
@@ -86,6 +88,7 @@ export type Swap = Hop & Humanizer & {
|
|
|
86
88
|
amountOut: BigNumber;
|
|
87
89
|
spotPrice: BigNumber;
|
|
88
90
|
tradeFeePct: number;
|
|
91
|
+
tradeFeeRange?: [number, number];
|
|
89
92
|
priceImpactPct: number;
|
|
90
93
|
errors: PoolError[];
|
|
91
94
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@galacticcouncil/sdk",
|
|
3
|
-
"version": "0.5.0
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Galactic SDK",
|
|
6
6
|
"author": "Pavol Noha <palo@hydradx.io>",
|
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "node ./esbuild.mjs && tsc --emitDeclarationOnly --outDir dist/types/",
|
|
12
12
|
"cleanup": "rimraf out && rimraf dist",
|
|
13
|
+
"release": "standard-version --tag-prefix=''",
|
|
13
14
|
"test": "jest",
|
|
14
15
|
"test:coverage": "jest --coverage",
|
|
15
16
|
"pckg:build": "npm run cleanup && npm run build",
|
|
16
|
-
"pckg:
|
|
17
|
+
"pckg:beta": "npm run pckg:build && npm publish --tag beta",
|
|
18
|
+
"pckg:release": "npm run pckg:build && npm release",
|
|
17
19
|
"pckg:publish": "git push --follow-tags origin master && npm publish",
|
|
18
20
|
"xcmgr:sync": "node ./xcmgr.sync.mjs"
|
|
19
21
|
},
|
|
@@ -41,6 +43,7 @@
|
|
|
41
43
|
"@galacticcouncil/math-lbp": "^0.1.3",
|
|
42
44
|
"@galacticcouncil/math-omnipool": "^0.1.3",
|
|
43
45
|
"@galacticcouncil/math-xyk": "^0.1.3",
|
|
46
|
+
"@thi.ng/cache": "^2.1.35",
|
|
44
47
|
"bignumber.js": "^9.1.0",
|
|
45
48
|
"lodash.clonedeep": "^4.5.0"
|
|
46
49
|
},
|