@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,24 @@
|
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
|
+
import { XcmV3Multilocation } from '../../types';
|
|
3
|
+
export type AavePoolToken = PoolToken & {
|
|
4
|
+
location: XcmV3Multilocation;
|
|
5
|
+
};
|
|
6
|
+
export declare class AavePool implements Pool {
|
|
7
|
+
type: PoolType;
|
|
8
|
+
address: string;
|
|
9
|
+
tokens: AavePoolToken[];
|
|
10
|
+
maxInRatio: bigint;
|
|
11
|
+
maxOutRatio: bigint;
|
|
12
|
+
minTradingLimit: bigint;
|
|
13
|
+
static fromPool(pool: PoolBase): AavePool;
|
|
14
|
+
constructor(address: string, tokens: AavePoolToken[], maxInRation: bigint, maxOutRatio: bigint, minTradeLimit: bigint);
|
|
15
|
+
validatePair(_tokenIn: number, _tokenOut: number): boolean;
|
|
16
|
+
parsePair(tokenIn: number, tokenOut: number): PoolPair;
|
|
17
|
+
validateAndBuy(poolPair: PoolPair, amountOut: bigint, _fees: PoolFees): BuyCtx;
|
|
18
|
+
validateAndSell(poolPair: PoolPair, amountIn: bigint, _fees: PoolFees): SellCtx;
|
|
19
|
+
calculateInGivenOut(_poolPair: PoolPair, amountOut: bigint): bigint;
|
|
20
|
+
calculateOutGivenIn(_poolPair: PoolPair, amountIn: bigint): bigint;
|
|
21
|
+
spotPriceInGivenOut(poolPair: PoolPair): bigint;
|
|
22
|
+
spotPriceOutGivenIn(poolPair: PoolPair): bigint;
|
|
23
|
+
calculateTradeFee(_amount: bigint, _fees: PoolFees): bigint;
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { PoolBase, PoolFees, PoolType } from '../types';
|
|
3
|
+
import { PoolClient } from '../PoolClient';
|
|
4
|
+
export declare class AavePoolClient extends PoolClient<PoolBase> {
|
|
5
|
+
loadPools(): Promise<PoolBase[]>;
|
|
6
|
+
private getPoolDelta;
|
|
7
|
+
private getPoolId;
|
|
8
|
+
private getPoolLimits;
|
|
9
|
+
getPoolFees(_pool: PoolBase, _feeAsset: number): Promise<PoolFees>;
|
|
10
|
+
getPoolType(): PoolType;
|
|
11
|
+
isSupported(): Promise<boolean>;
|
|
12
|
+
subscribePoolChange(pool: PoolBase): Observable<PoolBase>;
|
|
13
|
+
private getReserveH160Id;
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { PoolFactory } from './PoolFactory';
|
|
2
|
+
export { PoolContextProvider } from './PoolContextProvider';
|
|
3
|
+
export * as aave from './aave';
|
|
4
|
+
export * as xyk from './xyk';
|
|
5
|
+
export * as omni from './omni';
|
|
6
|
+
export * as lbp from './lbp';
|
|
7
|
+
export * as stable from './stable';
|
|
8
|
+
export * from './types';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class LbpMath {
|
|
2
|
+
static getSpotPrice(balanceA: string, balanceB: string, weightA: string, weightB: string, amount: string): string;
|
|
3
|
+
static calculateInGivenOut(balanceIn: string, balanceOut: string, weightIn: string, weightOut: string, amountOut: string): string;
|
|
4
|
+
static calculateOutGivenIn(balanceIn: string, balanceOut: string, weightIn: string, weightOut: string, amountIn: string): string;
|
|
5
|
+
static calculateLinearWeights(start: string, end: string, initialWeight: string, finalWeight: string, at: string): string;
|
|
6
|
+
static calculatePoolTradeFee(amount: string, feeNumerator: number, feeDenominator: number): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFee, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
|
+
export type WeightedPoolPair = PoolPair & {
|
|
3
|
+
weightIn: bigint;
|
|
4
|
+
weightOut: bigint;
|
|
5
|
+
};
|
|
6
|
+
export type WeightedPoolToken = PoolToken & {
|
|
7
|
+
weight: bigint;
|
|
8
|
+
};
|
|
9
|
+
export type LbpPoolFees = PoolFees & {
|
|
10
|
+
exchangeFee: PoolFee;
|
|
11
|
+
repayFee: PoolFee;
|
|
12
|
+
};
|
|
13
|
+
export type LbpPoolBase = PoolBase & {
|
|
14
|
+
fee: PoolFee;
|
|
15
|
+
repayFeeApply: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare class LbpPool implements Pool {
|
|
18
|
+
type: PoolType;
|
|
19
|
+
address: string;
|
|
20
|
+
tokens: WeightedPoolToken[];
|
|
21
|
+
maxInRatio: bigint;
|
|
22
|
+
maxOutRatio: bigint;
|
|
23
|
+
minTradingLimit: bigint;
|
|
24
|
+
fee: PoolFee;
|
|
25
|
+
repayFeeApply: boolean;
|
|
26
|
+
static fromPool(pool: LbpPoolBase): LbpPool;
|
|
27
|
+
constructor(address: string, tokens: WeightedPoolToken[], maxInRatio: bigint, maxOutRatio: bigint, minTradingLimit: bigint, fee: PoolFee, repayFeeApply: boolean);
|
|
28
|
+
validatePair(_tokenIn: number, _tokenOut: number): boolean;
|
|
29
|
+
parsePair(tokenIn: number, tokenOut: number): WeightedPoolPair;
|
|
30
|
+
/**
|
|
31
|
+
* Validate buy transfer
|
|
32
|
+
*
|
|
33
|
+
* a) Accumulated asset is bought (out) from the pool for distributed asset (in) - User(Buyer) bears the fee
|
|
34
|
+
* b) Distributed asset is bought (out) from the pool for accumualted asset (in) - Pool bears the fee
|
|
35
|
+
*/
|
|
36
|
+
validateAndBuy(poolPair: WeightedPoolPair, amountOut: bigint, fees: LbpPoolFees): BuyCtx;
|
|
37
|
+
/**
|
|
38
|
+
* Validate sell transfer
|
|
39
|
+
*
|
|
40
|
+
* a) Accumulated asset is sold (in) to the pool for distributed asset (out) - Pool bears the fee
|
|
41
|
+
* b) Distributed asset is sold (in) to the pool for accumualted asset (out) - User(Seller) bears the fee
|
|
42
|
+
*/
|
|
43
|
+
validateAndSell(poolPair: WeightedPoolPair, amountIn: bigint, fees: LbpPoolFees): SellCtx;
|
|
44
|
+
calculateInGivenOut(poolPair: WeightedPoolPair, amountOut: bigint): bigint;
|
|
45
|
+
calculateOutGivenIn(poolPair: WeightedPoolPair, amountIn: bigint): bigint;
|
|
46
|
+
spotPriceInGivenOut(poolPair: WeightedPoolPair): bigint;
|
|
47
|
+
spotPriceOutGivenIn(poolPair: WeightedPoolPair): bigint;
|
|
48
|
+
calculateTradeFee(amount: bigint, fees: LbpPoolFees): bigint;
|
|
49
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Observable } from 'rxjs';
|
|
2
|
+
import { PoolType, PoolFees } from '../types';
|
|
3
|
+
import { PoolClient } from '../PoolClient';
|
|
4
|
+
import { LbpPoolBase } from './LbpPool';
|
|
5
|
+
export declare class LbpPoolClient extends PoolClient<LbpPoolBase> {
|
|
6
|
+
private readonly MAX_FINAL_WEIGHT;
|
|
7
|
+
private poolsData;
|
|
8
|
+
protected loadPools(): Promise<LbpPoolBase[]>;
|
|
9
|
+
private getPoolDelta;
|
|
10
|
+
private isActivePool;
|
|
11
|
+
private isRepayFeeApplied;
|
|
12
|
+
private getRepayFee;
|
|
13
|
+
private getPoolLimits;
|
|
14
|
+
getPoolFees(pool: LbpPoolBase): Promise<PoolFees>;
|
|
15
|
+
getPoolType(): PoolType;
|
|
16
|
+
isSupported(): Promise<boolean>;
|
|
17
|
+
subscribePoolChange(pool: LbpPoolBase): Observable<LbpPoolBase>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class OmniMath {
|
|
2
|
+
static calculateSpotPrice(assetInBalance: string, assetInHubReserve: string, assetOutBalance: string, assetOutHubReserve: string): string;
|
|
3
|
+
static calculateLrnaSpotPrice(assetBalance: string, assetHubReserve: string): string;
|
|
4
|
+
static calculateInGivenOut(assetInBalance: string, assetInHubReserve: string, assetInShares: string, assetOutBalance: string, assetOutHubReserve: string, assetOutShares: string, amountOut: string, assetFee: string, protocolFee: string): string;
|
|
5
|
+
static calculateLrnaInGivenOut(assetOutBalance: string, assetOutHubReserve: string, assetOutShares: string, amountOut: string, assetFee: string): string;
|
|
6
|
+
static calculateOutGivenIn(assetInBalance: string, assetInHubReserve: string, assetInShares: string, assetOutBalance: string, assetOutHubReserve: string, assetOutShares: string, amountIn: string, assetFee: string, protocolFee: string): string;
|
|
7
|
+
static calculateOutGivenLrnaIn(assetOutBalance: string, assetOutHubReserve: string, assetOutShares: string, amountOut: string, assetFee: string): string;
|
|
8
|
+
static calculatePoolTradeFee(amount: string, feeNumerator: number, feeDenominator: number): string;
|
|
9
|
+
static calculateShares(assetReserve: string, assetHubReserve: string, assetShares: string, amountIn: string): string;
|
|
10
|
+
static calculateLiquidityOut(assetReserve: string, assetHubReserve: string, assetShares: string, positionAmount: string, positionShares: string, positionPrice: string, sharesToRemove: string, withdrawalFee: string): string;
|
|
11
|
+
static calculateLiquidityLRNAOut(assetReserve: string, assetHubReserve: string, assetShares: string, positionAmount: string, positionShares: string, positionPrice: string, sharesToRemove: string, withdrawalFee: string): string;
|
|
12
|
+
static calculateCapDifference(assetReserve: string, assetHubReserve: string, assetCap: string, totalHubReserve: string): string;
|
|
13
|
+
static verifyAssetCap(assetReserve: string, assetCap: string, hubAdded: string, totalHubReserve: string): boolean;
|
|
14
|
+
static calculateLimitHubIn(assetReserve: string, assetHubReserve: string, assetShares: string, amountIn: string): string;
|
|
15
|
+
static isSellAllowed(bits: number): boolean;
|
|
16
|
+
static isBuyAllowed(bits: number): boolean;
|
|
17
|
+
static isAddLiquidityAllowed(bits: number): boolean;
|
|
18
|
+
static isRemoveLiquidityAllowed(bits: number): boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFee, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
|
+
export type OmniPoolPair = PoolPair & {
|
|
3
|
+
hubReservesIn: bigint;
|
|
4
|
+
hubReservesOut: bigint;
|
|
5
|
+
sharesIn: bigint;
|
|
6
|
+
sharesOut: bigint;
|
|
7
|
+
tradeableIn: number;
|
|
8
|
+
tradeableOut: number;
|
|
9
|
+
};
|
|
10
|
+
export type OmniPoolToken = PoolToken & {
|
|
11
|
+
cap: bigint;
|
|
12
|
+
hubReserves: bigint;
|
|
13
|
+
protocolShares: bigint;
|
|
14
|
+
shares: bigint;
|
|
15
|
+
};
|
|
16
|
+
export type OmniPoolFees = PoolFees & {
|
|
17
|
+
assetFee: PoolFee;
|
|
18
|
+
protocolFee: PoolFee;
|
|
19
|
+
};
|
|
20
|
+
export type OmniPoolBase = PoolBase & {
|
|
21
|
+
hubAssetId: number;
|
|
22
|
+
};
|
|
23
|
+
export declare class OmniPool implements Pool {
|
|
24
|
+
type: PoolType;
|
|
25
|
+
address: string;
|
|
26
|
+
tokens: OmniPoolToken[];
|
|
27
|
+
maxInRatio: bigint;
|
|
28
|
+
maxOutRatio: bigint;
|
|
29
|
+
minTradingLimit: bigint;
|
|
30
|
+
hubAssetId: number;
|
|
31
|
+
static fromPool(pool: OmniPoolBase): OmniPool;
|
|
32
|
+
constructor(address: string, tokens: OmniPoolToken[], maxInRation: bigint, maxOutRatio: bigint, minTradeLimit: bigint, hubAssetId: number);
|
|
33
|
+
validatePair(_tokenIn: number, tokenOut: number): boolean;
|
|
34
|
+
parsePair(tokenIn: number, tokenOut: number): OmniPoolPair;
|
|
35
|
+
validateAndBuy(poolPair: OmniPoolPair, amountOut: bigint, fees: OmniPoolFees): BuyCtx;
|
|
36
|
+
validateAndSell(poolPair: OmniPoolPair, amountIn: bigint, fees: OmniPoolFees): SellCtx;
|
|
37
|
+
calculateInGivenOut(poolPair: OmniPoolPair, amountOut: bigint, fees?: OmniPoolFees): bigint;
|
|
38
|
+
calculateLrnaInGivenOut(poolPair: OmniPoolPair, amountOut: bigint, fees?: OmniPoolFees): bigint;
|
|
39
|
+
calculateOutGivenIn(poolPair: OmniPoolPair, amountIn: bigint, fees?: OmniPoolFees): bigint;
|
|
40
|
+
calculateOutGivenLrnaIn(poolPair: OmniPoolPair, amountIn: bigint, fees?: OmniPoolFees): bigint;
|
|
41
|
+
spotPriceInGivenOut(poolPair: OmniPoolPair): bigint;
|
|
42
|
+
spotPriceLrnaInGivenOut(poolPair: OmniPoolPair): bigint;
|
|
43
|
+
spotPriceOutGivenIn(poolPair: OmniPoolPair): bigint;
|
|
44
|
+
spotPriceOutGivenLrnaIn(poolPair: OmniPoolPair): bigint;
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Observable } from 'rxjs';
|
|
2
|
+
import { PoolType, PoolFees } from '../types';
|
|
3
|
+
import { PoolClient } from '../PoolClient';
|
|
4
|
+
import { OmniPoolBase } from './OmniPool';
|
|
5
|
+
export declare class OmniPoolClient extends PoolClient<OmniPoolBase> {
|
|
6
|
+
protected loadPools(): Promise<OmniPoolBase[]>;
|
|
7
|
+
private getPoolAddress;
|
|
8
|
+
private getPoolLimits;
|
|
9
|
+
getPoolFees(_pool: OmniPoolBase, feeAsset: number): Promise<PoolFees>;
|
|
10
|
+
getPoolType(): PoolType;
|
|
11
|
+
isSupported(): Promise<boolean>;
|
|
12
|
+
subscribePoolChange(pool: OmniPoolBase): Observable<OmniPoolBase>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class StableMath {
|
|
2
|
+
static getPoolAddress(assetId: number): Uint8Array;
|
|
3
|
+
static defaultPegs(size: number): string[][];
|
|
4
|
+
static calculateAmplification(initialAmp: string, finalAmp: string, initialBlock: string, finalBlock: string, currentBlock: string): string;
|
|
5
|
+
static calculateInGivenOut(reserves: string, assetIn: number, assetOut: number, amountOut: string, amplification: string, fee: string, pegs: string): string;
|
|
6
|
+
static calculateAddOneAsset(reserves: string, shares: string, assetIn: number, amplification: string, shareIssuance: string, fee: string, pegs: string): string;
|
|
7
|
+
static calculateSharesForAmount(reserves: string, assetIn: number, amount: string, amplification: string, shareIssuance: string, fee: string, pegs: string): string;
|
|
8
|
+
static calculateOutGivenIn(reserves: string, assetIn: number, assetOut: number, amountIn: string, amplification: string, fee: string, pegs: string): string;
|
|
9
|
+
static calculateLiquidityOutOneAsset(reserves: string, shares: string, assetOut: number, amplification: string, shareIssuance: string, withdrawFee: string, pegs: string): string;
|
|
10
|
+
static calculateShares(reserves: string, assets: string, amplification: string, shareIssuance: string, fee: string, pegs: string): string;
|
|
11
|
+
static calculateSpotPriceWithFee(poolId: string, reserves: string, amplification: string, assetIn: string, assetOut: string, shareIssuance: string, fee: string, pegs: string): string;
|
|
12
|
+
static calculatePoolTradeFee(amount: string, feeNumerator: number, feeDenominator: number): string;
|
|
13
|
+
static recalculatePegs(currentPegs: string, targetPegs: string, currentBlock: string, maxPegUpdate: string, poolFee: string): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFee, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
|
+
export type StableSwapPair = PoolPair & {
|
|
3
|
+
tradeableIn: number;
|
|
4
|
+
tradeableOut: number;
|
|
5
|
+
};
|
|
6
|
+
export type StableSwapFees = PoolFees & {
|
|
7
|
+
fee: PoolFee;
|
|
8
|
+
};
|
|
9
|
+
export type StableSwapBase = PoolBase & {
|
|
10
|
+
amplification: bigint;
|
|
11
|
+
id: string;
|
|
12
|
+
fee: PoolFee;
|
|
13
|
+
totalIssuance: bigint;
|
|
14
|
+
};
|
|
15
|
+
export declare class StableSwap implements Pool {
|
|
16
|
+
type: PoolType;
|
|
17
|
+
address: string;
|
|
18
|
+
tokens: PoolToken[];
|
|
19
|
+
maxInRatio: bigint;
|
|
20
|
+
maxOutRatio: bigint;
|
|
21
|
+
minTradingLimit: bigint;
|
|
22
|
+
amplification: bigint;
|
|
23
|
+
id: number;
|
|
24
|
+
fee: PoolFee;
|
|
25
|
+
totalIssuance: bigint;
|
|
26
|
+
static fromPool(pool: StableSwapBase): StableSwap;
|
|
27
|
+
constructor(address: string, tokens: PoolToken[], maxInRation: bigint, maxOutRatio: bigint, minTradeLimit: bigint, amplification: bigint, id: number, fee: PoolFee, totalIssuance: bigint);
|
|
28
|
+
validatePair(_tokenIn: number, _tokenOut: number): boolean;
|
|
29
|
+
parsePair(tokenIn: number, tokenOut: number): StableSwapPair;
|
|
30
|
+
validateAndBuy(poolPair: StableSwapPair, amountOut: bigint, fees: StableSwapFees): BuyCtx;
|
|
31
|
+
validateAndSell(poolPair: StableSwapPair, amountIn: bigint, fees: StableSwapFees): SellCtx;
|
|
32
|
+
private calculateIn;
|
|
33
|
+
private calculateAddOneAsset;
|
|
34
|
+
private calculateSharesForAmount;
|
|
35
|
+
calculateInGivenOut(poolPair: PoolPair, amountOut: bigint, fees?: StableSwapFees): bigint;
|
|
36
|
+
spotPriceInGivenOut(poolPair: PoolPair): bigint;
|
|
37
|
+
private calculateOut;
|
|
38
|
+
private calculateWithdrawOneAsset;
|
|
39
|
+
private calculateShares;
|
|
40
|
+
calculateOutGivenIn(poolPair: PoolPair, amountIn: bigint, fees?: StableSwapFees): bigint;
|
|
41
|
+
spotPriceOutGivenIn(poolPair: PoolPair): bigint;
|
|
42
|
+
calculateTradeFee(amount: bigint, fees: StableSwapFees): bigint;
|
|
43
|
+
private getPegs;
|
|
44
|
+
private getReserves;
|
|
45
|
+
private getAssets;
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Observable } from 'rxjs';
|
|
2
|
+
import { PoolType, PoolFees } from '../types';
|
|
3
|
+
import { PoolClient } from '../PoolClient';
|
|
4
|
+
import { StableSwapBase } from './StableSwap';
|
|
5
|
+
export declare class StableSwapClient extends PoolClient<StableSwapBase> {
|
|
6
|
+
private poolsData;
|
|
7
|
+
protected loadPools(): Promise<StableSwapBase[]>;
|
|
8
|
+
private getPoolDelta;
|
|
9
|
+
private getPoolTokens;
|
|
10
|
+
private getPoolAddress;
|
|
11
|
+
private getPoolLimits;
|
|
12
|
+
getPoolFees(pool: StableSwapBase): Promise<PoolFees>;
|
|
13
|
+
getPoolType(): PoolType;
|
|
14
|
+
isSupported(): Promise<boolean>;
|
|
15
|
+
subscribePoolChange(pool: StableSwapBase): Observable<StableSwapBase>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { AssetType } from '../types';
|
|
2
|
+
export declare enum PoolType {
|
|
3
|
+
Aave = "Aave",
|
|
4
|
+
LBP = "LBP",
|
|
5
|
+
Omni = "Omnipool",
|
|
6
|
+
Stable = "Stableswap",
|
|
7
|
+
XYK = "XYK"
|
|
8
|
+
}
|
|
9
|
+
export declare enum PoolError {
|
|
10
|
+
InsufficientTradingAmount = "InsufficientTradingAmount",
|
|
11
|
+
MaxInRatioExceeded = "MaxInRatioExceeded",
|
|
12
|
+
MaxOutRatioExceeded = "MaxOutRatioExceeded",
|
|
13
|
+
TradeNotAllowed = "TradeNotAllowed",
|
|
14
|
+
UnknownError = "UnknownError"
|
|
15
|
+
}
|
|
16
|
+
export interface PoolPair {
|
|
17
|
+
assetIn: number;
|
|
18
|
+
assetOut: number;
|
|
19
|
+
decimalsIn: number;
|
|
20
|
+
decimalsOut: number;
|
|
21
|
+
balanceIn: bigint;
|
|
22
|
+
balanceOut: bigint;
|
|
23
|
+
assetInEd: bigint;
|
|
24
|
+
assetOutEd: bigint;
|
|
25
|
+
}
|
|
26
|
+
export type PoolBase = {
|
|
27
|
+
address: string;
|
|
28
|
+
id?: number;
|
|
29
|
+
type: PoolType;
|
|
30
|
+
tokens: PoolToken[];
|
|
31
|
+
maxInRatio: bigint;
|
|
32
|
+
maxOutRatio: bigint;
|
|
33
|
+
minTradingLimit: bigint;
|
|
34
|
+
};
|
|
35
|
+
export interface PoolToken {
|
|
36
|
+
id: number;
|
|
37
|
+
balance: bigint;
|
|
38
|
+
decimals?: number;
|
|
39
|
+
existentialDeposit: bigint;
|
|
40
|
+
tradeable?: number;
|
|
41
|
+
type: AssetType;
|
|
42
|
+
}
|
|
43
|
+
export type PoolTokenOverride = Pick<PoolToken, 'id' | 'decimals'>;
|
|
44
|
+
export type PoolLimits = Pick<PoolBase, 'maxInRatio' | 'maxOutRatio' | 'minTradingLimit'>;
|
|
45
|
+
export type PoolFee = [numerator: number, denominator: number];
|
|
46
|
+
export type PoolFees = {
|
|
47
|
+
min?: PoolFee;
|
|
48
|
+
max?: PoolFee;
|
|
49
|
+
};
|
|
50
|
+
export type PoolSell = {
|
|
51
|
+
calculatedOut: bigint;
|
|
52
|
+
};
|
|
53
|
+
export type PoolBuy = {
|
|
54
|
+
calculatedIn: bigint;
|
|
55
|
+
};
|
|
56
|
+
export type PoolSwap = {
|
|
57
|
+
amountIn: bigint;
|
|
58
|
+
amountOut: bigint;
|
|
59
|
+
feePct: number;
|
|
60
|
+
errors: PoolError[];
|
|
61
|
+
};
|
|
62
|
+
export type SellCtx = PoolSwap & PoolSell;
|
|
63
|
+
export type BuyCtx = PoolSwap & PoolBuy;
|
|
64
|
+
export interface Pool extends PoolBase {
|
|
65
|
+
validatePair(tokenIn: number, tokenOut: number): boolean;
|
|
66
|
+
parsePair(tokenIn: number, tokenOut: number): PoolPair;
|
|
67
|
+
validateAndBuy(poolPair: PoolPair, amountOut: bigint, dynamicFees: PoolFees | null): BuyCtx;
|
|
68
|
+
validateAndSell(poolPair: PoolPair, amountOut: bigint, dynamicFees: PoolFees | null): SellCtx;
|
|
69
|
+
calculateInGivenOut(poolPair: PoolPair, amountOut: bigint): bigint;
|
|
70
|
+
calculateOutGivenIn(poolPair: PoolPair, amountIn: bigint): bigint;
|
|
71
|
+
spotPriceInGivenOut(poolPair: PoolPair): bigint;
|
|
72
|
+
spotPriceOutGivenIn(poolPair: PoolPair): bigint;
|
|
73
|
+
}
|
|
74
|
+
export interface IPoolCtxProvider {
|
|
75
|
+
getPools(): Promise<PoolBase[]>;
|
|
76
|
+
getPoolFees(pool: PoolBase, feeAsset: number): Promise<PoolFees>;
|
|
77
|
+
}
|
|
78
|
+
export type Hop = {
|
|
79
|
+
pool: PoolType;
|
|
80
|
+
poolAddress: string;
|
|
81
|
+
poolId?: number;
|
|
82
|
+
assetIn: number;
|
|
83
|
+
assetOut: number;
|
|
84
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class XykMath {
|
|
2
|
+
static getSpotPrice(balanceA: string, balanceB: string, amount: string): string;
|
|
3
|
+
static calculateInGivenOut(balanceIn: string, balanceOut: string, amountOut: string): string;
|
|
4
|
+
static calculateOutGivenIn(balanceIn: string, balanceOut: string, amountIn: string): string;
|
|
5
|
+
static calculatePoolTradeFee(amount: string, feeNumerator: number, feeDenominator: number): string;
|
|
6
|
+
static calculateLiquidityIn(reserveA: string, reserveB: string, amountA: string): string;
|
|
7
|
+
static calculateSpotPrice(balanceA: string, balanceB: string): string;
|
|
8
|
+
static calculateSpotPriceWithFee(balanceA: string, balanceB: string, feeNumerator: string, feeDenominator: string): string;
|
|
9
|
+
static calculateShares(reserveA: string, amountA: string, totalShares: string): string;
|
|
10
|
+
static calculateLiquidityOutAssetA(reserveA: string, reserveB: string, shares: string, totalShares: string): string;
|
|
11
|
+
static calculateLiquidityOutAssetB(reserveA: string, reserveB: string, shares: string, totalShares: string): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BuyCtx, Pool, PoolBase, PoolFee, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
|
|
2
|
+
export type XykPoolFees = PoolFees & {
|
|
3
|
+
exchangeFee: PoolFee;
|
|
4
|
+
};
|
|
5
|
+
export declare class XykPool implements Pool {
|
|
6
|
+
type: PoolType;
|
|
7
|
+
address: string;
|
|
8
|
+
tokens: PoolToken[];
|
|
9
|
+
maxInRatio: bigint;
|
|
10
|
+
maxOutRatio: bigint;
|
|
11
|
+
minTradingLimit: bigint;
|
|
12
|
+
static fromPool(pool: PoolBase): XykPool;
|
|
13
|
+
constructor(address: string, tokens: PoolToken[], maxInRation: bigint, maxOutRatio: bigint, minTradeLimit: bigint);
|
|
14
|
+
validatePair(_tokenIn: number, _tokenOut: number): boolean;
|
|
15
|
+
parsePair(tokenIn: number, tokenOut: number): PoolPair;
|
|
16
|
+
validateAndBuy(poolPair: PoolPair, amountOut: bigint, fees: XykPoolFees): BuyCtx;
|
|
17
|
+
validateAndSell(poolPair: PoolPair, amountIn: bigint, fees: XykPoolFees): SellCtx;
|
|
18
|
+
calculateInGivenOut(poolPair: PoolPair, amountOut: bigint): bigint;
|
|
19
|
+
calculateOutGivenIn(poolPair: PoolPair, amountIn: bigint): bigint;
|
|
20
|
+
spotPriceInGivenOut(poolPair: PoolPair): bigint;
|
|
21
|
+
spotPriceOutGivenIn(poolPair: PoolPair): bigint;
|
|
22
|
+
calculateTradeFee(amount: bigint, fees: XykPoolFees): bigint;
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Observable } from 'rxjs';
|
|
2
|
+
import { PoolBase, PoolType, PoolFees } from '../types';
|
|
3
|
+
import { PoolClient } from '../PoolClient';
|
|
4
|
+
export declare class XykPoolClient extends PoolClient<PoolBase> {
|
|
5
|
+
protected loadPools(): Promise<PoolBase[]>;
|
|
6
|
+
private getExchangeFee;
|
|
7
|
+
private getPoolLimits;
|
|
8
|
+
getPoolFees(): Promise<PoolFees>;
|
|
9
|
+
getPoolType(): PoolType;
|
|
10
|
+
isSupported(): Promise<boolean>;
|
|
11
|
+
subscribePoolChange(pool: PoolBase): Observable<PoolBase>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Hop, IPoolCtxProvider, Pool, PoolBase, PoolType } from '../pool';
|
|
2
|
+
export type RouterOptions = {
|
|
3
|
+
useOnly: PoolType[];
|
|
4
|
+
};
|
|
5
|
+
export declare class Router {
|
|
6
|
+
private readonly routeSuggester;
|
|
7
|
+
private readonly routerOptions;
|
|
8
|
+
protected readonly ctx: IPoolCtxProvider;
|
|
9
|
+
private readonly defaultRouterOptions;
|
|
10
|
+
constructor(ctx: IPoolCtxProvider, routerOptions?: RouterOptions);
|
|
11
|
+
/**
|
|
12
|
+
* List trading pools
|
|
13
|
+
*/
|
|
14
|
+
getPools(): Promise<PoolBase[]>;
|
|
15
|
+
/**
|
|
16
|
+
* List all possible trading routes for given pair
|
|
17
|
+
*
|
|
18
|
+
* @param {number} assetIn - assetIn id
|
|
19
|
+
* @param {number} assetOut - assetOut id
|
|
20
|
+
*/
|
|
21
|
+
getRoutes(assetIn: number, assetOut: number): Promise<Hop[][]>;
|
|
22
|
+
/**
|
|
23
|
+
* List tradeable assets
|
|
24
|
+
*/
|
|
25
|
+
getTradeableAssets(): Promise<number[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Ckeck if asset pair is valid
|
|
28
|
+
*
|
|
29
|
+
* @param {number} assetIn - assetIn id
|
|
30
|
+
* @param {number} assetOut - assetOut id
|
|
31
|
+
* @param {PoolBase[]} pools - trading pools
|
|
32
|
+
*/
|
|
33
|
+
protected validateInput(assetIn: number, assetOut: number, pools: PoolBase[]): Map<string, Pool>;
|
|
34
|
+
/**
|
|
35
|
+
* List tradeable assets ASC
|
|
36
|
+
*
|
|
37
|
+
* @param {PoolBase[]} pools - trading pools
|
|
38
|
+
*/
|
|
39
|
+
protected getAssets(pools: PoolBase[]): Set<number>;
|
|
40
|
+
/**
|
|
41
|
+
* List all possible routes between assetIn & assetOut
|
|
42
|
+
*
|
|
43
|
+
* @param {number} assetIn - assetIn id
|
|
44
|
+
* @param {number} assetOut - assetOut id
|
|
45
|
+
* @param {PoolBase[]} pools - trading pools
|
|
46
|
+
*/
|
|
47
|
+
protected getPaths(assetIn: number, assetOut: number | null, pools: PoolBase[]): Hop[][];
|
|
48
|
+
/**
|
|
49
|
+
* Check if path is valid -> all edges are valid asset pairs
|
|
50
|
+
*
|
|
51
|
+
* @param proposedPath - proposed path
|
|
52
|
+
* @param poolsMap - pools map
|
|
53
|
+
* @returns only valid paths
|
|
54
|
+
*/
|
|
55
|
+
private validPath;
|
|
56
|
+
/**
|
|
57
|
+
* Check if edge (asset pair) of corresponding pool is valid
|
|
58
|
+
*
|
|
59
|
+
* @param edge - current edge (asset pair)
|
|
60
|
+
* @param poolsMap - pools map
|
|
61
|
+
* @returns true if edge (asset pair) is valid, otherwise false
|
|
62
|
+
*/
|
|
63
|
+
private validEdge;
|
|
64
|
+
private toPoolsMap;
|
|
65
|
+
private toHops;
|
|
66
|
+
}
|