@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.
Files changed (53) hide show
  1. package/README.md +99 -41
  2. package/build/index.cjs +2 -2
  3. package/build/index.mjs +2 -2
  4. package/build/types/{client → api}/PolkadotApi.d.ts +3 -0
  5. package/build/types/api/index.d.ts +2 -3
  6. package/build/types/api/types.d.ts +8 -0
  7. package/build/types/client/AssetClient.d.ts +2 -2
  8. package/build/types/client/BalanceClient.d.ts +1 -1
  9. package/build/types/client/FarmClient.d.ts +1 -1
  10. package/build/types/client/index.d.ts +0 -1
  11. package/build/types/consts.d.ts +6 -7
  12. package/build/types/errors.d.ts +1 -1
  13. package/build/types/{pool/aave/AaveAbi.d.ts → evm/abi/Aave.d.ts} +48 -0
  14. package/build/types/evm/abi/Erc20.d.ts +150 -0
  15. package/build/types/evm/abi/index.d.ts +1 -0
  16. package/build/types/evm/chain.d.ts +2 -0
  17. package/build/types/evm/client.d.ts +11 -0
  18. package/build/types/evm/const.d.ts +4 -0
  19. package/build/types/evm/index.d.ts +4 -0
  20. package/build/types/index.d.ts +7 -4
  21. package/build/types/pool/CachingPoolService.d.ts +2 -2
  22. package/build/types/pool/PoolClient.d.ts +2 -1
  23. package/build/types/pool/PoolFactory.d.ts +1 -1
  24. package/build/types/pool/PoolService.d.ts +10 -14
  25. package/build/types/pool/aave/AavePool.d.ts +3 -3
  26. package/build/types/pool/aave/AavePoolClient.d.ts +1 -1
  27. package/build/types/pool/index.d.ts +1 -1
  28. package/build/types/pool/lbp/LbpPool.d.ts +3 -3
  29. package/build/types/pool/lbp/LbpPoolClient.d.ts +1 -1
  30. package/build/types/pool/omni/OmniPool.d.ts +3 -3
  31. package/build/types/pool/omni/OmniPoolClient.d.ts +1 -1
  32. package/build/types/pool/stable/StableSwap.d.ts +3 -3
  33. package/build/types/pool/stable/StableSwapClient.d.ts +1 -1
  34. package/build/types/pool/types.d.ts +81 -0
  35. package/build/types/pool/xyk/XykPool.d.ts +3 -3
  36. package/build/types/pool/xyk/XykPoolClient.d.ts +1 -1
  37. package/build/types/{api → sor}/Router.d.ts +2 -1
  38. package/build/types/{api → sor}/TradeRouter.d.ts +3 -1
  39. package/build/types/sor/TradeUtils.d.ts +25 -0
  40. package/build/types/sor/index.d.ts +4 -0
  41. package/build/types/{route → sor/route}/graph.d.ts +1 -1
  42. package/build/types/{route → sor/route}/suggester.d.ts +1 -1
  43. package/build/types/sor/types.d.ts +34 -0
  44. package/build/types/types.d.ts +8 -127
  45. package/build/types/utils/erc20.d.ts +3 -3
  46. package/build/types/utils/h160.d.ts +11 -0
  47. package/build/types/utils/mapper.d.ts +1 -1
  48. package/build/types/utils/math.d.ts +8 -0
  49. package/package.json +1 -1
  50. package/build/types/api/WalletCtx.d.ts +0 -20
  51. package/build/types/pool/PoolUtils.d.ts +0 -12
  52. package/build/types/{route → sor/route}/bfs.d.ts +0 -0
  53. package/build/types/{route → sor/route}/index.d.ts +1 -1
@@ -1,123 +1,4 @@
1
- import { BigNumber } from './utils/bignumber';
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
- UnknownError = "UnknownError",
11
- InsufficientTradingAmount = "InsufficientTradingAmount",
12
- MaxInRatioExceeded = "MaxInRatioExceeded",
13
- MaxOutRatioExceeded = "MaxOutRatioExceeded",
14
- TradeNotAllowed = "TradeNotAllowed"
15
- }
16
- export interface PoolPair {
17
- assetIn: string;
18
- assetOut: string;
19
- decimalsIn: number;
20
- decimalsOut: number;
21
- balanceIn: BigNumber;
22
- balanceOut: BigNumber;
23
- assetInED: BigNumber;
24
- assetOutED: BigNumber;
25
- }
26
- export type PoolBase = {
27
- address: string;
28
- id?: string;
29
- type: PoolType;
30
- tokens: PoolToken[];
31
- maxInRatio: number;
32
- maxOutRatio: number;
33
- minTradingLimit: number;
34
- };
35
- export interface PoolToken extends Asset {
36
- id: string;
37
- balance: string;
38
- tradeable?: number;
39
- }
40
- export type PoolLimits = Pick<PoolBase, 'maxInRatio' | 'maxOutRatio' | 'minTradingLimit'>;
41
- export type PoolFee = [numerator: number, denominator: number];
42
- export type PoolFees = {
43
- min?: PoolFee;
44
- max?: PoolFee;
45
- };
46
- export type PoolSell = {
47
- calculatedOut: BigNumber;
48
- };
49
- export type PoolBuy = {
50
- calculatedIn: BigNumber;
51
- };
52
- export type Transfer = {
53
- amountIn: BigNumber;
54
- amountOut: BigNumber;
55
- feePct: number;
56
- errors: PoolError[];
57
- };
58
- export type SellTransfer = Transfer & PoolSell;
59
- export type BuyTransfer = Transfer & PoolBuy;
60
- export interface Pool extends PoolBase {
61
- validatePair(tokenIn: string, tokenOut: string): boolean;
62
- parsePair(tokenIn: string, tokenOut: string): PoolPair;
63
- validateAndBuy(poolPair: PoolPair, amountOut: BigNumber, dynamicFees: PoolFees | null): BuyTransfer;
64
- validateAndSell(poolPair: PoolPair, amountOut: BigNumber, dynamicFees: PoolFees | null): SellTransfer;
65
- calculateInGivenOut(poolPair: PoolPair, amountOut: BigNumber): BigNumber;
66
- calculateOutGivenIn(poolPair: PoolPair, amountIn: BigNumber): BigNumber;
67
- spotPriceInGivenOut(poolPair: PoolPair): BigNumber;
68
- spotPriceOutGivenIn(poolPair: PoolPair): BigNumber;
69
- }
70
- export interface IPoolService {
71
- getPools(includeOnly?: PoolType[]): Promise<PoolBase[]>;
72
- getPoolFees(poolPair: PoolPair, pool: Pool): Promise<PoolFees>;
73
- buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
74
- buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
75
- buildSellAllTx(assetIn: string, assetOut: string, minAmountOut: BigNumber, route: Hop[]): Transaction;
76
- }
77
- export interface Transaction {
78
- hex: string;
79
- name?: string;
80
- get<T>(): T;
81
- dryRun<R>(account: string): Promise<R>;
82
- }
83
- export type Hop = {
84
- pool: PoolType;
85
- poolAddress: string;
86
- poolId?: string;
87
- assetIn: string;
88
- assetOut: string;
89
- };
90
- export type Swap = Hop & Humanizer & {
91
- assetInDecimals: number;
92
- assetOutDecimals: number;
93
- amountIn: BigNumber;
94
- amountOut: BigNumber;
95
- spotPrice: BigNumber;
96
- tradeFeePct: number;
97
- tradeFeeRange?: [number, number];
98
- priceImpactPct: number;
99
- errors: PoolError[];
100
- };
101
- export type SellSwap = Swap & PoolSell;
102
- export type BuySwap = Swap & PoolBuy;
103
- export declare enum TradeType {
104
- Buy = "Buy",
105
- Sell = "Sell"
106
- }
107
- export interface Trade extends Humanizer {
108
- type: TradeType;
109
- amountIn: BigNumber;
110
- amountOut: BigNumber;
111
- spotPrice: BigNumber;
112
- tradeFee: BigNumber;
113
- tradeFeePct: number;
114
- priceImpactPct: number;
115
- swaps: Swap[];
116
- toTx(tradeLimit: BigNumber, tradeAll?: boolean): Transaction;
117
- }
118
- export interface Humanizer {
119
- toHuman(): any;
120
- }
1
+ import type { BigNumber } from './utils/bignumber';
121
2
  export type Amount = {
122
3
  amount: BigNumber;
123
4
  decimals: number;
@@ -133,13 +14,6 @@ export interface Asset extends AssetMetadata {
133
14
  meta?: Record<string, string>;
134
15
  isWhiteListed?: boolean;
135
16
  }
136
- export interface ExternalAsset extends AssetMetadata {
137
- id: string;
138
- origin: number;
139
- name: string;
140
- internalId: string;
141
- isWhiteListed?: boolean;
142
- }
143
17
  export interface AssetMetadata {
144
18
  decimals: number;
145
19
  symbol: string;
@@ -148,3 +22,10 @@ export interface Bond extends Asset {
148
22
  underlyingAssetId: string;
149
23
  maturity: number;
150
24
  }
25
+ export interface ExternalAsset extends AssetMetadata {
26
+ id: string;
27
+ origin: number;
28
+ name: string;
29
+ internalId: string;
30
+ isWhiteListed?: boolean;
31
+ }
@@ -1,5 +1,5 @@
1
- export declare class ERC20Mapping {
2
- static encodeEvmAddress(assetId: string): string;
3
- static decodeEvmAddress(evmAddress: string): number | null;
1
+ export declare class ERC20 {
2
+ static fromAssetId(assetId: string): string;
3
+ static toAssetId(address: string): number | null;
4
4
  static isAssetAddress(address: string): boolean;
5
5
  }
@@ -0,0 +1,11 @@
1
+ import { Buffer } from 'buffer';
2
+ export declare function isEvmAccount(address: string): boolean;
3
+ export declare function isEvmAddress(address: string): boolean;
4
+ export declare function isSs58Address(address: string): boolean;
5
+ export declare class H160 {
6
+ static prefixBytes: Buffer<ArrayBuffer>;
7
+ static toAccount: (address: string) => string;
8
+ static fromAccount: (address: string) => string;
9
+ static fromSS58: (address: string) => `0x${string}`;
10
+ static fromAny: (address: string) => string;
11
+ }
@@ -1,4 +1,4 @@
1
- import { PoolFee } from '../types';
1
+ import { PoolFee } from '../pool';
2
2
  import { BigNumber } from './bignumber';
3
3
  export declare function toHuman(amount: BigNumber, decimals: number): string;
4
4
  export declare function toPct(fee: PoolFee): number;
@@ -52,3 +52,11 @@ export declare function calculateSellFee(delta0Y: BigNumber, deltaY: BigNumber):
52
52
  * @param deltaX - the amount in, inclusive of fees
53
53
  */
54
54
  export declare function calculateBuyFee(delta0X: BigNumber, deltaX: BigNumber): BigNumber;
55
+ /**
56
+ * Get % fraction from amount
57
+ *
58
+ * @param value - amount
59
+ * @param pct - percentage value
60
+ * @returns fraction of given amount
61
+ */
62
+ export declare function getFraction(value: BigNumber, pct: number): BigNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/sdk",
3
- "version": "6.2.0",
3
+ "version": "7.0.0",
4
4
  "description": "Galactic off-chain routing & optimization of orders across pools for best price execution",
5
5
  "author": "GalacticCouncil",
6
6
  "repository": {
@@ -1,20 +0,0 @@
1
- import { ApiPromise } from '@polkadot/api';
2
- import { VoidFn } from '@polkadot/api-base/types';
3
- import { AssetClient, BalanceClient } from '../client';
4
- import { BigNumber } from '../utils/bignumber';
5
- export declare class WalletCtx extends BalanceClient {
6
- protected readonly assetClient: AssetClient;
7
- protected ctx: Map<string, BigNumber>;
8
- protected subs: VoidFn[];
9
- private assets;
10
- private memBalances;
11
- constructor(api: ApiPromise);
12
- getBalancesMem(account: string): Promise<Map<string, BigNumber>>;
13
- private getBalances;
14
- unsubscribe(): void;
15
- private getAccountBalanceData;
16
- private subscribeTokensAccountBalance;
17
- private subscribeErc20AccountBalance;
18
- private subscribeSystemAccountBalance;
19
- private updateCtxCallback;
20
- }
@@ -1,12 +0,0 @@
1
- import { Hop, PoolType } from '../types';
2
- export declare function buildRoute(route: Hop[]): ({
3
- pool: {
4
- Stableswap: string | undefined;
5
- };
6
- assetIn: string;
7
- assetOut: string;
8
- } | {
9
- pool: PoolType.Aave | PoolType.LBP | PoolType.Omni | PoolType.XYK;
10
- assetIn: string;
11
- assetOut: string;
12
- })[];
File without changes
@@ -1,3 +1,3 @@
1
- export { RouteSuggester } from './suggester';
2
1
  export { Bfs, Path } from './bfs';
3
2
  export { Edge, getNodesAndEdges } from './graph';
3
+ export { RouteSuggester } from './suggester';