@galacticcouncil/sdk-next 0.6.0-pr192-1d1a581 → 0.6.0-pr193-4adb9c7
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/build/index.cjs +1 -1
- package/build/index.mjs +1 -1
- package/build/types/client/BalanceClient.d.ts +11 -10
- package/build/types/client/LiquidityMiningClient.d.ts +75 -0
- package/build/types/client/claimSimulator.d.ts +196 -0
- package/build/types/client/index.d.ts +1 -0
- package/build/types/factory.d.ts +4 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/pool/PoolContextProvider.d.ts +3 -2
- package/build/types/pool/types.d.ts +5 -1
- package/build/types/sor/Router.d.ts +12 -6
- package/build/types/sor/TradeRouter.d.ts +62 -33
- package/build/types/sor/route/bfs.d.ts +11 -2
- package/build/types/sor/route/index.d.ts +1 -1
- package/build/types/sor/route/suggester.d.ts +21 -12
- package/build/types/staking/StakingApi.d.ts +46 -0
- package/build/types/staking/StakingClient.d.ts +120 -0
- package/build/types/staking/index.d.ts +2 -0
- package/build/types/types.d.ts +9 -2
- package/build/types/utils/format.d.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { TypedApi } from 'polkadot-api';
|
|
2
|
+
import { MultiCurrencyContainer, OmnipoolWarehouseLMDepositYieldFarmEntry } from './LiquidityMiningClient';
|
|
3
|
+
import { hydration } from '@galacticcouncil/descriptors';
|
|
4
|
+
import Big from 'big.js';
|
|
5
|
+
type Api = TypedApi<typeof hydration>;
|
|
6
|
+
type NotUndefined<T> = T extends undefined ? never : T;
|
|
7
|
+
type GlobalFarm = NotUndefined<Awaited<ReturnType<Api['query']['XYKWarehouseLM']['GlobalFarm']['getValue'] | Api['query']['OmnipoolWarehouseLM']['GlobalFarm']['getValue']>>>;
|
|
8
|
+
type YieldFarm = NotUndefined<Awaited<ReturnType<Api['query']['XYKWarehouseLM']['YieldFarm']['getValue'] | Api['query']['OmnipoolWarehouseLM']['YieldFarm']['getValue']>>>;
|
|
9
|
+
export declare class OmnipoolLiquidityMiningClaimSim {
|
|
10
|
+
protected get_account: (sub: number) => string;
|
|
11
|
+
protected multiCurrency: MultiCurrencyContainer;
|
|
12
|
+
protected getAsset: (id: number) => Promise<{
|
|
13
|
+
existential_deposit: bigint;
|
|
14
|
+
} | undefined>;
|
|
15
|
+
constructor(get_account: (sub: number) => string, multiCurrency: MultiCurrencyContainer, getAsset: (id: number) => Promise<{
|
|
16
|
+
existential_deposit: bigint;
|
|
17
|
+
} | undefined>);
|
|
18
|
+
calculate_rewards_from_pot(global_farm: GlobalFarm, yield_farm: YieldFarm, stake_in_global_farm: Big): {
|
|
19
|
+
reward: Big.Big;
|
|
20
|
+
mutatedYieldFarm: {
|
|
21
|
+
id: number;
|
|
22
|
+
updated_at: number;
|
|
23
|
+
accumulated_rpz: bigint;
|
|
24
|
+
state: import("polkadot-api").Enum<{
|
|
25
|
+
Active: undefined;
|
|
26
|
+
Stopped: undefined;
|
|
27
|
+
Terminated: undefined;
|
|
28
|
+
}>;
|
|
29
|
+
total_shares: bigint;
|
|
30
|
+
total_valued_shares: bigint;
|
|
31
|
+
accumulated_rpvs: bigint;
|
|
32
|
+
loyalty_curve: {
|
|
33
|
+
initial_reward_percentage: bigint;
|
|
34
|
+
scale_coef: number;
|
|
35
|
+
} | undefined;
|
|
36
|
+
multiplier: bigint;
|
|
37
|
+
entries_count: bigint;
|
|
38
|
+
left_to_distribute: bigint;
|
|
39
|
+
total_stopped: number;
|
|
40
|
+
};
|
|
41
|
+
mutatedGlobalFarm: {
|
|
42
|
+
id: number;
|
|
43
|
+
owner: import("polkadot-api").SS58String;
|
|
44
|
+
updated_at: number;
|
|
45
|
+
total_shares_z: bigint;
|
|
46
|
+
accumulated_rpz: bigint;
|
|
47
|
+
reward_currency: number;
|
|
48
|
+
pending_rewards: bigint;
|
|
49
|
+
accumulated_paid_rewards: bigint;
|
|
50
|
+
yield_per_period: bigint;
|
|
51
|
+
planned_yielding_periods: number;
|
|
52
|
+
blocks_per_period: number;
|
|
53
|
+
incentivized_asset: number;
|
|
54
|
+
max_reward_per_period: bigint;
|
|
55
|
+
min_deposit: bigint;
|
|
56
|
+
live_yield_farms_count: number;
|
|
57
|
+
total_yield_farms_count: number;
|
|
58
|
+
price_adjustment: bigint;
|
|
59
|
+
state: import("polkadot-api").Enum<{
|
|
60
|
+
Active: undefined;
|
|
61
|
+
Stopped: undefined;
|
|
62
|
+
Terminated: undefined;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
sync_global_farm(global_farm: GlobalFarm, current_period: number, oraclePrice: bigint): Promise<{
|
|
67
|
+
global_farm: {
|
|
68
|
+
updated_at: number;
|
|
69
|
+
id: number;
|
|
70
|
+
owner: import("polkadot-api").SS58String;
|
|
71
|
+
total_shares_z: bigint;
|
|
72
|
+
accumulated_rpz: bigint;
|
|
73
|
+
reward_currency: number;
|
|
74
|
+
pending_rewards: bigint;
|
|
75
|
+
accumulated_paid_rewards: bigint;
|
|
76
|
+
yield_per_period: bigint;
|
|
77
|
+
planned_yielding_periods: number;
|
|
78
|
+
blocks_per_period: number;
|
|
79
|
+
incentivized_asset: number;
|
|
80
|
+
max_reward_per_period: bigint;
|
|
81
|
+
min_deposit: bigint;
|
|
82
|
+
live_yield_farms_count: number;
|
|
83
|
+
total_yield_farms_count: number;
|
|
84
|
+
price_adjustment: bigint;
|
|
85
|
+
state: import("polkadot-api").Enum<{
|
|
86
|
+
Active: undefined;
|
|
87
|
+
Stopped: undefined;
|
|
88
|
+
Terminated: undefined;
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
91
|
+
reward?: undefined;
|
|
92
|
+
} | {
|
|
93
|
+
reward: Big.Big;
|
|
94
|
+
global_farm: {
|
|
95
|
+
id: number;
|
|
96
|
+
owner: import("polkadot-api").SS58String;
|
|
97
|
+
updated_at: number;
|
|
98
|
+
total_shares_z: bigint;
|
|
99
|
+
accumulated_rpz: bigint;
|
|
100
|
+
reward_currency: number;
|
|
101
|
+
pending_rewards: bigint;
|
|
102
|
+
accumulated_paid_rewards: bigint;
|
|
103
|
+
yield_per_period: bigint;
|
|
104
|
+
planned_yielding_periods: number;
|
|
105
|
+
blocks_per_period: number;
|
|
106
|
+
incentivized_asset: number;
|
|
107
|
+
max_reward_per_period: bigint;
|
|
108
|
+
min_deposit: bigint;
|
|
109
|
+
live_yield_farms_count: number;
|
|
110
|
+
total_yield_farms_count: number;
|
|
111
|
+
price_adjustment: bigint;
|
|
112
|
+
state: import("polkadot-api").Enum<{
|
|
113
|
+
Active: undefined;
|
|
114
|
+
Stopped: undefined;
|
|
115
|
+
Terminated: undefined;
|
|
116
|
+
}>;
|
|
117
|
+
};
|
|
118
|
+
} | undefined>;
|
|
119
|
+
sync_yield_farm(yield_farm: YieldFarm, global_farm: GlobalFarm, current_period: number): {
|
|
120
|
+
yield_farm: {
|
|
121
|
+
accumulated_rpz: bigint;
|
|
122
|
+
updated_at: number;
|
|
123
|
+
id: number;
|
|
124
|
+
state: import("polkadot-api").Enum<{
|
|
125
|
+
Active: undefined;
|
|
126
|
+
Stopped: undefined;
|
|
127
|
+
Terminated: undefined;
|
|
128
|
+
}>;
|
|
129
|
+
total_shares: bigint;
|
|
130
|
+
total_valued_shares: bigint;
|
|
131
|
+
accumulated_rpvs: bigint;
|
|
132
|
+
loyalty_curve: {
|
|
133
|
+
initial_reward_percentage: bigint;
|
|
134
|
+
scale_coef: number;
|
|
135
|
+
} | undefined;
|
|
136
|
+
multiplier: bigint;
|
|
137
|
+
entries_count: bigint;
|
|
138
|
+
left_to_distribute: bigint;
|
|
139
|
+
total_stopped: number;
|
|
140
|
+
};
|
|
141
|
+
global_farm?: undefined;
|
|
142
|
+
} | {
|
|
143
|
+
yield_farm: {
|
|
144
|
+
id: number;
|
|
145
|
+
updated_at: number;
|
|
146
|
+
accumulated_rpz: bigint;
|
|
147
|
+
state: import("polkadot-api").Enum<{
|
|
148
|
+
Active: undefined;
|
|
149
|
+
Stopped: undefined;
|
|
150
|
+
Terminated: undefined;
|
|
151
|
+
}>;
|
|
152
|
+
total_shares: bigint;
|
|
153
|
+
total_valued_shares: bigint;
|
|
154
|
+
accumulated_rpvs: bigint;
|
|
155
|
+
loyalty_curve: {
|
|
156
|
+
initial_reward_percentage: bigint;
|
|
157
|
+
scale_coef: number;
|
|
158
|
+
} | undefined;
|
|
159
|
+
multiplier: bigint;
|
|
160
|
+
entries_count: bigint;
|
|
161
|
+
left_to_distribute: bigint;
|
|
162
|
+
total_stopped: number;
|
|
163
|
+
};
|
|
164
|
+
global_farm: {
|
|
165
|
+
id: number;
|
|
166
|
+
owner: import("polkadot-api").SS58String;
|
|
167
|
+
updated_at: number;
|
|
168
|
+
total_shares_z: bigint;
|
|
169
|
+
accumulated_rpz: bigint;
|
|
170
|
+
reward_currency: number;
|
|
171
|
+
pending_rewards: bigint;
|
|
172
|
+
accumulated_paid_rewards: bigint;
|
|
173
|
+
yield_per_period: bigint;
|
|
174
|
+
planned_yielding_periods: number;
|
|
175
|
+
blocks_per_period: number;
|
|
176
|
+
incentivized_asset: number;
|
|
177
|
+
max_reward_per_period: bigint;
|
|
178
|
+
min_deposit: bigint;
|
|
179
|
+
live_yield_farms_count: number;
|
|
180
|
+
total_yield_farms_count: number;
|
|
181
|
+
price_adjustment: bigint;
|
|
182
|
+
state: import("polkadot-api").Enum<{
|
|
183
|
+
Active: undefined;
|
|
184
|
+
Stopped: undefined;
|
|
185
|
+
Terminated: undefined;
|
|
186
|
+
}>;
|
|
187
|
+
};
|
|
188
|
+
} | undefined;
|
|
189
|
+
get_loyalty_multiplier(periods: Big, loyaltyCurve: YieldFarm['loyalty_curve']): string;
|
|
190
|
+
claim_rewards(global_farm: GlobalFarm, yield_farm: YieldFarm, farmEntry: OmnipoolWarehouseLMDepositYieldFarmEntry, relaychainBlockNumber: number, oraclePrice: bigint): Promise<{
|
|
191
|
+
reward: Big.Big;
|
|
192
|
+
maxReward: Big.Big;
|
|
193
|
+
assetId: number;
|
|
194
|
+
} | null>;
|
|
195
|
+
}
|
|
196
|
+
export {};
|
package/build/types/factory.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { PolkadotClient } from 'polkadot-api';
|
|
2
2
|
import { AaveUtils } from './aave';
|
|
3
|
-
import { AssetClient, BalanceClient } from './client';
|
|
3
|
+
import { AssetClient, BalanceClient, LiquidityMining } from './client';
|
|
4
4
|
import { EvmClient } from './evm';
|
|
5
5
|
import { PoolContextProvider } from './pool';
|
|
6
6
|
import { TradeRouter, TradeScheduler } from './sor';
|
|
7
7
|
import { TxBuilderFactory } from './tx';
|
|
8
|
+
import { StakingApi } from './staking';
|
|
8
9
|
export type SdkCtx = {
|
|
9
10
|
api: {
|
|
10
11
|
aave: AaveUtils;
|
|
11
12
|
router: TradeRouter;
|
|
12
13
|
scheduler: TradeScheduler;
|
|
14
|
+
staking: StakingApi;
|
|
13
15
|
};
|
|
14
16
|
client: {
|
|
15
17
|
asset: AssetClient;
|
|
16
18
|
balance: BalanceClient;
|
|
17
19
|
evm: EvmClient;
|
|
20
|
+
mining: LiquidityMining;
|
|
18
21
|
};
|
|
19
22
|
ctx: {
|
|
20
23
|
pool: PoolContextProvider;
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PolkadotClient } from 'polkadot-api';
|
|
2
2
|
import { Papi } from '../api';
|
|
3
|
-
import { IPoolCtxProvider, PoolBase, PoolFees, PoolTokenOverride } from './types';
|
|
3
|
+
import { IPoolCtxProvider, PoolBase, PoolFees, PoolFilter, PoolTokenOverride } from './types';
|
|
4
4
|
export declare class PoolContextProvider extends Papi implements IPoolCtxProvider {
|
|
5
5
|
private readonly lbpClient;
|
|
6
6
|
private readonly omniClient;
|
|
@@ -25,6 +25,7 @@ export declare class PoolContextProvider extends Papi implements IPoolCtxProvide
|
|
|
25
25
|
withAave(): this;
|
|
26
26
|
withXyk(override?: PoolTokenOverride[]): this;
|
|
27
27
|
destroy(): void;
|
|
28
|
-
getPools(): Promise<PoolBase[]>;
|
|
28
|
+
getPools(filter?: PoolFilter): Promise<PoolBase[]>;
|
|
29
|
+
private getFilteredPools;
|
|
29
30
|
getPoolFees(pool: PoolBase, feeAsset: number): Promise<PoolFees>;
|
|
30
31
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { AssetType } from '../types';
|
|
2
|
+
export type PoolFilter = {
|
|
3
|
+
useOnly?: PoolType[];
|
|
4
|
+
exclude?: PoolType[];
|
|
5
|
+
};
|
|
2
6
|
export declare enum PoolType {
|
|
3
7
|
Aave = "Aave",
|
|
4
8
|
LBP = "LBP",
|
|
@@ -72,7 +76,7 @@ export interface Pool extends PoolBase {
|
|
|
72
76
|
spotPriceOutGivenIn(poolPair: PoolPair): bigint;
|
|
73
77
|
}
|
|
74
78
|
export interface IPoolCtxProvider {
|
|
75
|
-
getPools(): Promise<PoolBase[]>;
|
|
79
|
+
getPools(filter?: PoolFilter): Promise<PoolBase[]>;
|
|
76
80
|
getPoolFees(pool: PoolBase, feeAsset: number): Promise<PoolFees>;
|
|
77
81
|
}
|
|
78
82
|
export type Hop = {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Hop, IPoolCtxProvider, Pool, PoolBase,
|
|
2
|
-
export type RouterOptions =
|
|
3
|
-
useOnly: PoolType[];
|
|
4
|
-
};
|
|
1
|
+
import { Hop, IPoolCtxProvider, Pool, PoolBase, PoolFilter } from '../pool';
|
|
2
|
+
export type RouterOptions = PoolFilter;
|
|
5
3
|
export declare class Router {
|
|
6
4
|
private readonly routeSuggester;
|
|
5
|
+
private readonly routeProposals;
|
|
7
6
|
private readonly routerOptions;
|
|
8
7
|
protected readonly ctx: IPoolCtxProvider;
|
|
9
|
-
private readonly defaultRouterOptions;
|
|
10
8
|
constructor(ctx: IPoolCtxProvider, routerOptions?: RouterOptions);
|
|
9
|
+
protected buildRouteKey(assetIn: number, assetOut: number, pools: PoolBase[]): string;
|
|
11
10
|
/**
|
|
12
11
|
* List trading pools
|
|
13
12
|
*/
|
|
@@ -23,6 +22,12 @@ export declare class Router {
|
|
|
23
22
|
* List tradeable assets
|
|
24
23
|
*/
|
|
25
24
|
getTradeableAssets(): Promise<number[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Return list of all routeble assets from substrate based pools
|
|
27
|
+
*
|
|
28
|
+
* @returns {number[]} List of all routeable asset ids
|
|
29
|
+
*/
|
|
30
|
+
getRouteableAssets(toAsset: number): Promise<number[]>;
|
|
26
31
|
/**
|
|
27
32
|
* Ckeck if asset pair is valid
|
|
28
33
|
*
|
|
@@ -44,7 +49,8 @@ export declare class Router {
|
|
|
44
49
|
* @param {number} assetOut - assetOut id
|
|
45
50
|
* @param {PoolBase[]} pools - trading pools
|
|
46
51
|
*/
|
|
47
|
-
protected getPaths(assetIn: number, assetOut: number
|
|
52
|
+
protected getPaths(assetIn: number, assetOut: number, pools: PoolBase[]): Hop[][];
|
|
53
|
+
private getProposals;
|
|
48
54
|
/**
|
|
49
55
|
* Check if path is valid -> all edges are valid asset pairs
|
|
50
56
|
*
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { Router } from './Router';
|
|
1
|
+
import { Router, RouterOptions } from './Router';
|
|
2
2
|
import { Trade } from './types';
|
|
3
|
-
import { Hop } from '../pool';
|
|
3
|
+
import { Hop, IPoolCtxProvider } from '../pool';
|
|
4
4
|
import { Amount } from '../types';
|
|
5
5
|
export declare class TradeRouter extends Router {
|
|
6
|
+
private readonly mlr;
|
|
7
|
+
private poolsSnapshot?;
|
|
8
|
+
constructor(ctx: IPoolCtxProvider, routerOptions?: RouterOptions);
|
|
9
|
+
private buildCtxSync;
|
|
10
|
+
private withCtx;
|
|
6
11
|
/**
|
|
7
12
|
* Check whether trade is direct or not
|
|
8
13
|
*
|
|
@@ -50,15 +55,23 @@ export declare class TradeRouter extends Router {
|
|
|
50
55
|
*/
|
|
51
56
|
private getSellSpot;
|
|
52
57
|
/**
|
|
53
|
-
* Calculate and return sell trade for assetIn>assetOut
|
|
58
|
+
* Calculate and return sell trade for assetIn > assetOut pair
|
|
54
59
|
*
|
|
55
|
-
* @param {number} assetIn -
|
|
56
|
-
* @param {number} assetOut -
|
|
57
|
-
* @param {bigint} amountIn - amount of assetIn to sell for assetOut
|
|
60
|
+
* @param {number} assetIn - asset in
|
|
61
|
+
* @param {number} assetOut - asset out
|
|
62
|
+
* @param {bigint | string} amountIn - amount of assetIn to sell for assetOut
|
|
58
63
|
* @param {Hop[]} route - explicit route to use for trade
|
|
59
|
-
* @returns sell trade of given
|
|
64
|
+
* @returns sell trade of given asset pair
|
|
60
65
|
*/
|
|
61
66
|
getSell(assetIn: number, assetOut: number, amountIn: bigint | string, route?: Hop[]): Promise<Trade>;
|
|
67
|
+
/**
|
|
68
|
+
* Build sell trade
|
|
69
|
+
*
|
|
70
|
+
* @param poolsMap - pools map
|
|
71
|
+
* @param route - sell route
|
|
72
|
+
* @returns - sell trade
|
|
73
|
+
*/
|
|
74
|
+
private buildSell;
|
|
62
75
|
/**
|
|
63
76
|
* Calculate the amount out for best possible trade if fees are zero
|
|
64
77
|
*
|
|
@@ -68,6 +81,19 @@ export declare class TradeRouter extends Router {
|
|
|
68
81
|
* @returns the amount out for best possible trade if fees are zero
|
|
69
82
|
*/
|
|
70
83
|
private calculateDelta0Y;
|
|
84
|
+
/**
|
|
85
|
+
* Calculate and cache the most liquid route
|
|
86
|
+
*
|
|
87
|
+
* To avoid routing through the pools with low liquidity, 0.1% from the
|
|
88
|
+
* most liquid pool asset is used as reference value to determine the
|
|
89
|
+
* sweet spot.
|
|
90
|
+
*
|
|
91
|
+
* @param {number} assetIn - asset in
|
|
92
|
+
* @param {number} assetOut - asset out
|
|
93
|
+
* @param {Ctx} ctx - route ctx
|
|
94
|
+
* @return most liquid route of given asset pair
|
|
95
|
+
*/
|
|
96
|
+
private calculateMostLiquidRoute;
|
|
71
97
|
/**
|
|
72
98
|
* Calculate and return sell swaps for given path
|
|
73
99
|
* - final amount of previous swap is entry to next one
|
|
@@ -79,40 +105,35 @@ export declare class TradeRouter extends Router {
|
|
|
79
105
|
*/
|
|
80
106
|
private toSellSwaps;
|
|
81
107
|
/**
|
|
82
|
-
*
|
|
108
|
+
* Returns the most liquid route
|
|
83
109
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* @param {number} assetIn - assetIn id
|
|
89
|
-
* @param {number} assetOut - assetout id
|
|
90
|
-
* @return Most liquid route of given token pair
|
|
110
|
+
* @param {number} assetIn - asset in
|
|
111
|
+
* @param {number} assetOut - asset out
|
|
112
|
+
* @return most liquid route of given asset pair
|
|
91
113
|
*/
|
|
92
114
|
getMostLiquidRoute(assetIn: number, assetOut: number): Promise<Hop[]>;
|
|
93
115
|
/**
|
|
94
|
-
* Calculate and return best spot price for
|
|
116
|
+
* Calculate and return best possible spot price for assetIn > assetOut pair
|
|
95
117
|
*
|
|
96
|
-
* @param {number} assetIn -
|
|
97
|
-
* @param {number} assetOut -
|
|
98
|
-
* @return best possible spot price of given asset pair, or undefined
|
|
99
|
-
* if given pair swap is not supported
|
|
118
|
+
* @param {number} assetIn - asset in
|
|
119
|
+
* @param {number} assetOut - asset out
|
|
120
|
+
* @return best possible spot price of given asset pair, or undefined if trade not supported
|
|
100
121
|
*/
|
|
101
122
|
getSpotPrice(assetIn: number, assetOut: number): Promise<Amount>;
|
|
102
123
|
/**
|
|
103
|
-
* Find
|
|
124
|
+
* Find best buy route without errors, if there is none return first one found
|
|
104
125
|
*
|
|
105
|
-
* @param
|
|
106
|
-
* @returns best buy
|
|
126
|
+
* @param swaps - buy routes
|
|
127
|
+
* @returns best buy route if exist, otherwise first one found
|
|
107
128
|
*/
|
|
108
129
|
private findBestBuyRoute;
|
|
109
130
|
/**
|
|
110
|
-
* Calculate and return best possible buy trade for assetIn>assetOut
|
|
131
|
+
* Calculate and return best possible buy trade for assetIn > assetOut pair
|
|
111
132
|
*
|
|
112
|
-
* @param {number} assetIn -
|
|
113
|
-
* @param {number} assetOut -
|
|
114
|
-
* @param {bigint} amountOut - amount of
|
|
115
|
-
* @returns best possible buy trade of given
|
|
133
|
+
* @param {number} assetIn - asset in
|
|
134
|
+
* @param {number} assetOut - asset out
|
|
135
|
+
* @param {bigint | string} amountOut - amount of assetOut to buy for assetIn
|
|
136
|
+
* @returns best possible buy trade of given asset pair
|
|
116
137
|
*/
|
|
117
138
|
getBestBuy(assetIn: number, assetOut: number, amountOut: bigint | string): Promise<Trade>;
|
|
118
139
|
/**
|
|
@@ -123,15 +144,23 @@ export declare class TradeRouter extends Router {
|
|
|
123
144
|
*/
|
|
124
145
|
private getBuySpot;
|
|
125
146
|
/**
|
|
126
|
-
* Calculate and return buy trade for assetIn>assetOut
|
|
147
|
+
* Calculate and return buy trade for assetIn > assetOut pair
|
|
127
148
|
*
|
|
128
|
-
* @param {number} assetIn -
|
|
129
|
-
* @param {number} assetOut -
|
|
130
|
-
* @param {bigint} amountOut - amount of assetOut to buy for assetIn
|
|
149
|
+
* @param {number} assetIn - asset in
|
|
150
|
+
* @param {number} assetOut - asset out
|
|
151
|
+
* @param {bigint | string} amountOut - amount of assetOut to buy for assetIn
|
|
131
152
|
* @param {Hop[]} route - explicit route to use for trade
|
|
132
|
-
* @returns buy trade of given
|
|
153
|
+
* @returns buy trade of given asset pair
|
|
133
154
|
*/
|
|
134
155
|
getBuy(assetIn: number, assetOut: number, amountOut: bigint | string, route?: Hop[]): Promise<Trade>;
|
|
156
|
+
/**
|
|
157
|
+
* Build buy trade
|
|
158
|
+
*
|
|
159
|
+
* @param poolsMap - pools map
|
|
160
|
+
* @param route - buy route
|
|
161
|
+
* @returns - buy trade
|
|
162
|
+
*/
|
|
163
|
+
private buildBuy;
|
|
135
164
|
/**
|
|
136
165
|
* Calculate the amount in for best possible trade if fees are zero
|
|
137
166
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type Path = Node[];
|
|
2
1
|
export type Node = [id: number, from: string];
|
|
2
|
+
export type Path = Node[];
|
|
3
3
|
/**
|
|
4
4
|
* Breadth First Search.
|
|
5
5
|
*
|
|
@@ -25,7 +25,16 @@ export declare class Bfs {
|
|
|
25
25
|
* @param dst - destination node or null if requesting all posible paths from src
|
|
26
26
|
* @returns paths
|
|
27
27
|
*/
|
|
28
|
-
findPaths(g: Map<number, Path>, src: number, dst: number
|
|
28
|
+
findPaths(g: Map<number, Path>, src: number, dst: number): Path[];
|
|
29
|
+
/**
|
|
30
|
+
* Finding shortest paths in graph from given source to destination
|
|
31
|
+
*
|
|
32
|
+
* @param g - routes graph containing nodes & corresponding edges
|
|
33
|
+
* @param src - source node
|
|
34
|
+
* @param dst - destination node or null if requesting all posible paths from src
|
|
35
|
+
* @returns shortest paths
|
|
36
|
+
*/
|
|
37
|
+
findShortestPaths(g: Map<number, Path>, src: number, dst: number | null): Path[];
|
|
29
38
|
/**
|
|
30
39
|
* Build and populate graph
|
|
31
40
|
*
|
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
import { Edge } from './graph';
|
|
2
2
|
import { PoolBase } from '../../pool';
|
|
3
|
+
export type RouteProposal = Edge[];
|
|
3
4
|
export declare class RouteSuggester {
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 2) tokenIn to *(all possible paths are requested)
|
|
6
|
+
* Returns ideal path proposals from `tokenIn` to `tokenOut`
|
|
7
|
+
* based on BFS over trusted, isolated or both pools.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* - Trusted pools = all pools except XYK (isolated)
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* The routing strategy is:
|
|
12
|
+
* - If neither `tokenIn` and `tokenOut` is in a trusted pool:
|
|
13
|
+
* → Run BFS over isolated pools only, searching for all paths.
|
|
14
|
+
* - If both `tokenIn` and `tokenOut` are in trusted pools:
|
|
15
|
+
* → Run BFS over trusted pools only, searching for shortest paths.
|
|
16
|
+
* - Otherwise:
|
|
17
|
+
* → Run BFS over all relevant pools (trusted + isolated).
|
|
13
18
|
*
|
|
14
|
-
*
|
|
19
|
+
* This strategy minimizes search scope while ensuring all viable
|
|
20
|
+
* paths are discovered.
|
|
15
21
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
22
|
+
* NOTE: Filtering of valid swaps and pair execution is handled by the router,
|
|
23
|
+
* not in this step.
|
|
24
|
+
*
|
|
25
|
+
* @param tokenIn - The starting token (asset ID as string)
|
|
26
|
+
* @param tokenOut - The destination token (asset ID as string)
|
|
27
|
+
* @param pools - The list of available pools
|
|
28
|
+
* @returns Array of path proposals (each path is a list of edges)
|
|
20
29
|
*/
|
|
21
|
-
getProposals(tokenIn: number, tokenOut: number
|
|
30
|
+
getProposals(tokenIn: number, tokenOut: number, pools: PoolBase[]): RouteProposal[];
|
|
22
31
|
private parsePaths;
|
|
23
32
|
private toEdge;
|
|
24
33
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { StakingClient } from './StakingClient';
|
|
3
|
+
import { BalanceClient } from 'client';
|
|
4
|
+
export declare const BIG_10: Big.Big;
|
|
5
|
+
export declare const BIG_BILL: Big.Big;
|
|
6
|
+
export declare class StakingApi {
|
|
7
|
+
private readonly client;
|
|
8
|
+
private readonly balanceClient;
|
|
9
|
+
constructor(client: StakingClient, balanceClient: BalanceClient);
|
|
10
|
+
getTransferablePotBalance(): Promise<bigint>;
|
|
11
|
+
getStakingPosition(id: bigint): Promise<{
|
|
12
|
+
stake: bigint | undefined;
|
|
13
|
+
rewardPerStake: bigint | undefined;
|
|
14
|
+
createdAt: number | undefined;
|
|
15
|
+
actionPoints: bigint | undefined;
|
|
16
|
+
accumulatedUnpaidRewards: bigint | undefined;
|
|
17
|
+
accumulatedSlashPoints: bigint | undefined;
|
|
18
|
+
accumulatedLockedRewards: bigint | undefined;
|
|
19
|
+
votes: {
|
|
20
|
+
id: number;
|
|
21
|
+
amount: bigint;
|
|
22
|
+
conviction: string;
|
|
23
|
+
}[];
|
|
24
|
+
}>;
|
|
25
|
+
getStake(address: string): Promise<{
|
|
26
|
+
totalStake: bigint;
|
|
27
|
+
accumulatedRewardPerStake: bigint;
|
|
28
|
+
potReservedBalance: bigint;
|
|
29
|
+
positionId: bigint | undefined;
|
|
30
|
+
stakePosition: {
|
|
31
|
+
stake: bigint | undefined;
|
|
32
|
+
rewardPerStake: bigint | undefined;
|
|
33
|
+
createdAt: number | undefined;
|
|
34
|
+
actionPoints: bigint | undefined;
|
|
35
|
+
accumulatedUnpaidRewards: bigint | undefined;
|
|
36
|
+
accumulatedSlashPoints: bigint | undefined;
|
|
37
|
+
accumulatedLockedRewards: bigint | undefined;
|
|
38
|
+
votes: {
|
|
39
|
+
id: number;
|
|
40
|
+
amount: bigint;
|
|
41
|
+
conviction: string;
|
|
42
|
+
}[];
|
|
43
|
+
} | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
getRewards(account: string, blockNumber: string): Promise<string | undefined>;
|
|
46
|
+
}
|