@galacticcouncil/sdk 0.0.1-beta.12 → 0.0.1-beta.14
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/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/types/api/tradeRouter.d.ts +22 -4
- package/dist/types/client/{capi.d.ts → cApi.d.ts} +0 -0
- package/dist/types/client/polkadotApi.d.ts +1 -0
- package/dist/types/pool/lbp/lbpPolkadotApiClient.d.ts +5 -0
- package/dist/types/pool/polkadotApiPoolService.d.ts +8 -4
- package/dist/types/pool/xyk/xykPolkadotApiClient.d.ts +4 -0
- package/dist/types/types.d.ts +3 -1
- package/dist/types/utils/math.d.ts +20 -0
- package/package.json +1 -1
- package/dist/types/client/polkadot.d.ts +0 -14
- package/dist/types/client/types.d.ts +0 -7
- package/dist/types/pool/polkadotPoolService.d.ts +0 -7
- package/dist/types/pool/xyk/xykPolkadotClient.d.ts +0 -8
|
@@ -27,13 +27,22 @@ export declare class TradeRouter extends Router {
|
|
|
27
27
|
* @returns Best possible sell trade of given token pair
|
|
28
28
|
*/
|
|
29
29
|
getBestSell(assetIn: string, assetOut: string, amountIn: BigNumber | string | number): Promise<Trade>;
|
|
30
|
+
/**
|
|
31
|
+
* Calculate the amount out for best possible trade if fees are zero
|
|
32
|
+
*
|
|
33
|
+
* @param amountIn - Amount of assetIn to sell for assetOut
|
|
34
|
+
* @param bestRoute - Best possible trade route (sell)
|
|
35
|
+
* @param poolsMap - Pools map
|
|
36
|
+
* @returns the amount out for best possible trade if fees are zero
|
|
37
|
+
*/
|
|
38
|
+
private calculateDelta0Y;
|
|
30
39
|
/**
|
|
31
40
|
* Calculate and return sell swaps for given path
|
|
32
41
|
* - final amount of previous swap is entry to next one
|
|
33
42
|
*
|
|
34
43
|
* @param amountIn - Amount of assetIn to sell for assetOut
|
|
35
|
-
* @param path -
|
|
36
|
-
* @param poolsMap -
|
|
44
|
+
* @param path - Current path
|
|
45
|
+
* @param poolsMap - Pools map
|
|
37
46
|
* @returns Sell swaps for given path with corresponding pool pairs
|
|
38
47
|
*/
|
|
39
48
|
private toSellSwaps;
|
|
@@ -46,14 +55,23 @@ export declare class TradeRouter extends Router {
|
|
|
46
55
|
* @returns Best possible buy trade of given token pair
|
|
47
56
|
*/
|
|
48
57
|
getBestBuy(assetIn: string, assetOut: string, amountOut: BigNumber | string | number): Promise<Trade>;
|
|
58
|
+
/**
|
|
59
|
+
* Calculate the amount in for best possible trade if fees are zero
|
|
60
|
+
*
|
|
61
|
+
* @param amountOut - Amount of assetOut to buy for assetIn
|
|
62
|
+
* @param bestRoute - Best possible trade route (buy)
|
|
63
|
+
* @param poolsMap - Pools map
|
|
64
|
+
* @returns the amount in for best possible trade if fees are zero
|
|
65
|
+
*/
|
|
66
|
+
private calculateDelta0X;
|
|
49
67
|
/**
|
|
50
68
|
* Calculate and return buy swaps for given path
|
|
51
69
|
* - final amount of previous swap is entry to next one
|
|
52
70
|
* - calculation is done backwards (swaps in reversed order)
|
|
53
71
|
*
|
|
54
72
|
* @param amountOut - Amount of assetOut to buy for assetIn
|
|
55
|
-
* @param path -
|
|
56
|
-
* @param poolsMap -
|
|
73
|
+
* @param path - Current path
|
|
74
|
+
* @param poolsMap - Pools map
|
|
57
75
|
* @returns Buy swaps for given path
|
|
58
76
|
*/
|
|
59
77
|
private toBuySwaps;
|
|
File without changes
|
|
@@ -10,6 +10,7 @@ export declare class PolkadotApiClient {
|
|
|
10
10
|
getStorageKey(asset: [StorageKey<AnyTuple>, Codec], index: number): string;
|
|
11
11
|
getStorageEntryArray(asset: [StorageKey<AnyTuple>, Codec]): string[];
|
|
12
12
|
getPoolTokens(poolAddress: string, assetKeys: string[]): Promise<PoolToken[]>;
|
|
13
|
+
syncPoolTokens(poolAddress: string, poolTokens: PoolToken[]): Promise<PoolToken[]>;
|
|
13
14
|
getAssetMetadata(tokenKey: string): Promise<AssetMetadata>;
|
|
14
15
|
getAccountBalance(accountId: string, tokenKey: string): Promise<string>;
|
|
15
16
|
getSystemAccountBalance(accountId: string): Promise<string>;
|
|
@@ -12,7 +12,12 @@ interface LbpPoolData {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class LbpPolkadotApiClient extends PolkadotApiClient {
|
|
14
14
|
private readonly MAX_FINAL_WEIGHT;
|
|
15
|
+
private poolsData;
|
|
16
|
+
private pools;
|
|
17
|
+
private _poolsLoaded;
|
|
15
18
|
getPools(): Promise<PoolBase[]>;
|
|
19
|
+
loadPools(): Promise<PoolBase[]>;
|
|
20
|
+
syncPools(): Promise<PoolBase[]>;
|
|
16
21
|
getLinearWeight(poolEntry: LbpPoolData): Promise<string>;
|
|
17
22
|
getRepayFee(): PoolFee;
|
|
18
23
|
isRepayFeeApplied(assetKey: string, poolEntry: LbpPoolData): Promise<boolean>;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { Hop, PoolBase, PoolService, Transaction } from '../types';
|
|
2
|
-
import {
|
|
1
|
+
import { Hop, PoolBase, PoolService, PoolType, Transaction } from '../types';
|
|
2
|
+
import { XykPolkadotApiClient } from './xyk/xykPolkadotApiClient';
|
|
3
|
+
import { LbpPolkadotApiClient } from './lbp/lbpPolkadotApiClient';
|
|
3
4
|
import { BigNumber } from '../utils/bignumber';
|
|
5
|
+
import { ApiPromise } from '@polkadot/api';
|
|
4
6
|
export declare class PolkadotApiPoolService implements PoolService {
|
|
5
|
-
|
|
7
|
+
protected readonly api: ApiPromise;
|
|
8
|
+
protected readonly xykClient: XykPolkadotApiClient;
|
|
9
|
+
protected readonly lbpClient: LbpPolkadotApiClient;
|
|
6
10
|
constructor(api: ApiPromise);
|
|
7
|
-
getPools(): Promise<PoolBase[]>;
|
|
11
|
+
getPools(includeOnly: PoolType[]): Promise<PoolBase[]>;
|
|
8
12
|
buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
|
|
9
13
|
buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
|
|
10
14
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { PolkadotApiClient } from '../../client';
|
|
2
2
|
import { PoolBase, PoolFee } from '../../types';
|
|
3
3
|
export declare class XykPolkadotApiClient extends PolkadotApiClient {
|
|
4
|
+
private pools;
|
|
5
|
+
private _poolsLoaded;
|
|
4
6
|
getPools(): Promise<PoolBase[]>;
|
|
7
|
+
loadPools(): Promise<PoolBase[]>;
|
|
8
|
+
syncPools(): Promise<PoolBase[]>;
|
|
5
9
|
getTradeFee(): PoolFee;
|
|
6
10
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export interface Pool extends PoolBase {
|
|
|
64
64
|
calculateTradeFee(amount: BigNumber): BigNumber;
|
|
65
65
|
}
|
|
66
66
|
export interface PoolService {
|
|
67
|
-
getPools(): Promise<PoolBase[]>;
|
|
67
|
+
getPools(includeOnly?: PoolType[]): Promise<PoolBase[]>;
|
|
68
68
|
buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
|
|
69
69
|
buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
|
|
70
70
|
}
|
|
@@ -99,6 +99,8 @@ export interface Trade extends Humanizer {
|
|
|
99
99
|
amountIn: BigNumber;
|
|
100
100
|
amountOut: BigNumber;
|
|
101
101
|
spotPrice: BigNumber;
|
|
102
|
+
tradeFee: BigNumber;
|
|
103
|
+
tradeFeePct: number;
|
|
102
104
|
priceImpactPct: number;
|
|
103
105
|
swaps: Swap[];
|
|
104
106
|
toTx(tradeLimit: BigNumber): Transaction;
|
|
@@ -11,3 +11,23 @@ import { BigNumber } from './bignumber';
|
|
|
11
11
|
* @returns Price impact percentage
|
|
12
12
|
*/
|
|
13
13
|
export declare function calculatePriceImpact(amount: BigNumber, decimals: number, spotPrice: BigNumber, calculatedAmount: BigNumber): BigNumber;
|
|
14
|
+
/**
|
|
15
|
+
* The total fee paid for a ‘sell’ transaction
|
|
16
|
+
* Suppose the trader is selling X for Y
|
|
17
|
+
*
|
|
18
|
+
* fee = 1 - (deltaY / delta0Y)
|
|
19
|
+
*
|
|
20
|
+
* @param delta0Y - the amount out if fees are zero
|
|
21
|
+
* @param deltaY - the amount out if the existing nonzero fees are included in the calculation
|
|
22
|
+
*/
|
|
23
|
+
export declare function calculateSellFee(delta0Y: BigNumber, deltaY: BigNumber): BigNumber;
|
|
24
|
+
/**
|
|
25
|
+
* The total fee paid for a buy transaction
|
|
26
|
+
* Suppose the trader is buying Y using X
|
|
27
|
+
*
|
|
28
|
+
* fee = (deltaX / delta0X) - 1
|
|
29
|
+
*
|
|
30
|
+
* @param delta0X - the amount in if fees are zero
|
|
31
|
+
* @param deltaX - the amount in, inclusive of fees
|
|
32
|
+
*/
|
|
33
|
+
export declare function calculateBuyFee(delta0X: BigNumber, deltaX: BigNumber): BigNumber;
|
package/package.json
CHANGED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import type { StorageKey } from '@polkadot/types';
|
|
3
|
-
import type { AnyTuple, Codec } from '@polkadot/types/types';
|
|
4
|
-
import type { AssetMetadata } from '@polkadot/types/interfaces';
|
|
5
|
-
import '@polkadot/api-augment';
|
|
6
|
-
export declare class PolkadotClient {
|
|
7
|
-
protected readonly api: ApiPromise;
|
|
8
|
-
constructor(api: ApiPromise);
|
|
9
|
-
getStorageKey(asset: [StorageKey<AnyTuple>, Codec], index: number): string;
|
|
10
|
-
getStorageEntryArray(asset: [StorageKey<AnyTuple>, Codec]): string[];
|
|
11
|
-
getAssetMetadata(tokenKey: string): Promise<AssetMetadata>;
|
|
12
|
-
getSystemAccountBalance(accountId: string): Promise<string>;
|
|
13
|
-
getTokenAccountBalance(accountId: string, tokenKey: string): Promise<string>;
|
|
14
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { PolkadotClient } from '../../client';
|
|
2
|
-
import { PoolBase, PoolToken } from '../../types';
|
|
3
|
-
export declare class XykPolkadotClient extends PolkadotClient {
|
|
4
|
-
getPools(): Promise<PoolBase[]>;
|
|
5
|
-
getPoolTokens(poolAddress: string, assetKeys: string[]): Promise<PoolToken[]>;
|
|
6
|
-
getBalance(poolAddress: string, assetKey: string): Promise<string>;
|
|
7
|
-
getTradeFee(): string;
|
|
8
|
-
}
|