@galacticcouncil/sdk 0.7.7 → 0.8.0-beta.2

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.
@@ -1,4 +1,4 @@
1
- import { IPoolService, PoolBase, Hop, Pool, PoolAsset, PoolType } from '../types';
1
+ import { IPoolService, PoolBase, Hop, Pool, PoolToken, PoolType } from '../types';
2
2
  export type RouterOptions = {
3
3
  includeOnly?: PoolType[];
4
4
  };
@@ -21,16 +21,16 @@ export declare class Router {
21
21
  /**
22
22
  * Return list of all available assets from substrate based pools
23
23
  *
24
- * @returns {PoolAsset[]} List of all available assets
24
+ * @returns {PoolToken[]} List of all available assets
25
25
  */
26
- getAllAssets(): Promise<PoolAsset[]>;
26
+ getAllAssets(): Promise<PoolToken[]>;
27
27
  /**
28
28
  * Calculate and return list of all assets, given token can be trade with
29
29
  *
30
30
  * @param {string} asset - Storage key of asset
31
31
  * @returns {PoolAsset[]} List of all available assets, given token can be trade with
32
32
  */
33
- getAssetPairs(asset: string): Promise<PoolAsset[]>;
33
+ getAssetPairs(asset: string): Promise<PoolToken[]>;
34
34
  /**
35
35
  * Calculate and return all possible paths for best swap assetIn>assetOut
36
36
  *
@@ -45,7 +45,7 @@ export declare class Router {
45
45
  * @param pools - pools
46
46
  * @returns Map of all available assets
47
47
  */
48
- protected getAssets(pools: PoolBase[]): Promise<Map<string, PoolAsset>>;
48
+ protected getAssets(pools: PoolBase[]): Promise<Map<string, PoolToken>>;
49
49
  /**
50
50
  * Calculate and return all possible paths for best swap assetIn>assetOut
51
51
  *
@@ -64,7 +64,7 @@ export declare class Router {
64
64
  * @returns Pool assets & map
65
65
  */
66
66
  protected validateTokenPair(assetIn: string, assetOut: string, pools: PoolBase[]): Promise<{
67
- assets: Map<string, PoolAsset>;
67
+ assets: Map<string, PoolToken>;
68
68
  poolsMap: Map<string, Pool>;
69
69
  }>;
70
70
  /**
@@ -74,7 +74,7 @@ export declare class Router {
74
74
  * @returns Pool assets & map
75
75
  */
76
76
  protected validateToken(token: string, pools: PoolBase[]): Promise<{
77
- assets: Map<string, PoolAsset>;
77
+ assets: Map<string, PoolToken>;
78
78
  poolsMap: Map<string, Pool>;
79
79
  }>;
80
80
  /**
@@ -1,16 +1,18 @@
1
+ import type { PalletAssetRegistryAssetMetadata, PalletStableswapPoolInfo } from '@polkadot/types/lookup';
1
2
  import { ApiPromise } from '@polkadot/api';
2
- import { AssetDetail, AssetMetadata } from '../types';
3
+ import { AssetMetadata } from '../types';
3
4
  import { PolkadotApiClient } from './PolkadotApi';
5
+ import { ITuple } from '@polkadot/types-codec/types';
6
+ import { u32, u64 } from '@polkadot/types-codec';
4
7
  export declare class AssetClient extends PolkadotApiClient {
8
+ private SUPPORTED_TYPES;
5
9
  constructor(api: ApiPromise);
6
- private tryBonds;
7
- private tryShares;
10
+ safeSharesQuery(): Promise<Map<string, PalletStableswapPoolInfo>>;
11
+ safeBondsQuery(): Promise<Map<string, ITuple<[u32, u64]>>>;
12
+ metadataQuery(): Promise<Map<string, PalletAssetRegistryAssetMetadata>>;
8
13
  private getTokenMetadata;
9
14
  private getBondMetadata;
10
15
  private getShareMetadata;
11
- getAssetMetadata(tokenKey: string): Promise<AssetMetadata>;
12
- private getTokenDetail;
13
- private getBondDetail;
14
- private getShareDetail;
15
- getAssetDetail(tokenKey: string): Promise<AssetDetail>;
16
+ getOnChainMetadata(): Promise<AssetMetadata[]>;
17
+ private isSupportedType;
16
18
  }
@@ -1,11 +1,14 @@
1
1
  import { ApiPromise } from '@polkadot/api';
2
+ import { UnsubscribePromise } from '@polkadot/api-base/types';
2
3
  import { BigNumber } from '../utils/bignumber';
3
- import { Amount } from '../types';
4
- import { AssetClient } from './AssetClient';
5
- export declare class BalanceClient extends AssetClient {
4
+ import { PolkadotApiClient } from './PolkadotApi';
5
+ export declare class BalanceClient extends PolkadotApiClient {
6
6
  constructor(api: ApiPromise);
7
- getAccountBalance(accountId: string, tokenKey: string): Promise<Amount>;
8
- getSystemAccountBalance(accountId: string): Promise<BigNumber>;
9
- getTokenAccountBalance(accountId: string, tokenKey: string): Promise<BigNumber>;
7
+ getBalance(accountId: string, tokenKey: string): Promise<BigNumber>;
8
+ getSystemBalance(accountId: string): Promise<BigNumber>;
9
+ getTokenBalance(accountId: string, tokenKey: string): Promise<BigNumber>;
10
+ subscribeBalance(address: string, tokens: string[], onChange: (token: string, balance: BigNumber) => void): UnsubscribePromise;
11
+ subscribeTokenBalance(address: string, tokens: string[], onChange: (token: string, balance: BigNumber) => void): UnsubscribePromise;
12
+ subscribeSystemBalance(address: string, onChange: (token: string, balance: BigNumber) => void): UnsubscribePromise;
10
13
  private calculateFreeBalance;
11
14
  }
@@ -6,3 +6,4 @@ export declare const HYDRADX_PARACHAIN_ID = 2034;
6
6
  export declare const HYDRADX_SS58_PREFIX = 63;
7
7
  export declare const BASILISK_PARACHAIN_ID = 2090;
8
8
  export declare const DENOMINATOR = 1000;
9
+ export declare const HYDRADX_OMNIPOOL_ADDRESS: string;
@@ -1,14 +1,23 @@
1
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 { PoolBase, PoolFees, PoolToken } from '../types';
2
+ import { UnsubscribePromise, VoidFn } from '@polkadot/api-base/types';
3
+ import { PoolBase, PoolFees, PoolType } from '../types';
5
4
  import { BalanceClient } from '../client';
6
5
  export declare abstract class PoolClient extends BalanceClient {
6
+ protected pools: PoolBase[];
7
+ protected subs: VoidFn[];
8
+ private poolsLoaded;
7
9
  constructor(api: ApiPromise);
8
- abstract getPools(): Promise<PoolBase[]>;
10
+ protected abstract loadPools(): Promise<PoolBase[]>;
11
+ abstract getPoolType(): PoolType;
9
12
  abstract getPoolFees(feeAsset: string, address: string): Promise<PoolFees>;
10
- protected getStorageKey(asset: [StorageKey<AnyTuple>, Codec], index: number): string;
11
- protected getStorageEntryArray(asset: [StorageKey<AnyTuple>, Codec]): string[];
12
- protected getPoolTokens(poolAddress: string, assetKeys: string[]): Promise<PoolToken[]>;
13
- protected syncPoolTokens(poolAddress: string, poolTokens: PoolToken[]): Promise<PoolToken[]>;
13
+ protected abstract subscribePoolChange(pool: PoolBase): UnsubscribePromise;
14
+ getPools(): Promise<PoolBase[]>;
15
+ subscribe(): Promise<VoidFn[]>;
16
+ unsubscribe(): void;
17
+ private hasShareAsset;
18
+ private tokenSubs;
19
+ private shareSubs;
20
+ private systemSubs;
21
+ private updateBalanceCallback;
22
+ private updateBalanceLog;
14
23
  }
@@ -2,17 +2,23 @@ import { LbpPoolClient } from './lbp/LbpPoolClient';
2
2
  import { OmniPoolClient } from './omni/OmniPoolClient';
3
3
  import { XykPoolClient } from './xyk/XykPoolClient';
4
4
  import { StableSwapClient } from './stable/StableSwapClient';
5
- import { Hop, PoolBase, IPoolService, PoolType, Transaction, PoolFees, Pool } from '../types';
5
+ import { AssetClient } from '../client';
6
+ import { Hop, PoolBase, IPoolService, PoolType, Transaction, PoolFees, Pool, AssetMetadata } from '../types';
6
7
  import { BigNumber } from '../utils/bignumber';
7
8
  import { ApiPromise } from '@polkadot/api';
8
9
  export declare class PoolService implements IPoolService {
9
10
  protected readonly api: ApiPromise;
11
+ protected readonly assetClient: AssetClient;
10
12
  protected readonly xykClient: XykPoolClient;
11
13
  protected readonly omniClient: OmniPoolClient;
12
14
  protected readonly lbpClient: LbpPoolClient;
13
15
  protected readonly stableClient: StableSwapClient;
16
+ protected metadata: AssetMetadata[];
17
+ protected metadataLoaded: boolean;
14
18
  constructor(api: ApiPromise);
15
19
  getPools(includeOnly: PoolType[]): Promise<PoolBase[]>;
20
+ unsubscribe(): void;
21
+ private withMetadata;
16
22
  getPoolFees(feeAsset: string, pool: Pool): Promise<PoolFees>;
17
23
  private isDirectOmnipoolTrade;
18
24
  buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
@@ -1,18 +1,16 @@
1
- import { PoolBase, PoolFees } from '../../types';
1
+ import { UnsubscribePromise } from '@polkadot/api-base/types';
2
+ import { PoolBase, PoolFees, PoolType } from '../../types';
2
3
  import { PoolClient } from '../PoolClient';
3
4
  export declare class LbpPoolClient extends PoolClient {
4
5
  private readonly MAX_FINAL_WEIGHT;
5
6
  private poolsData;
6
- private pools;
7
- private _poolsLoaded;
8
- getPools(): Promise<PoolBase[]>;
9
- private loadPools;
10
- private syncPools;
11
- getRelayChainBlock(): Promise<number>;
7
+ loadPools(): Promise<PoolBase[]>;
8
+ getPoolFees(_feeAsset: string, address: string): Promise<PoolFees>;
9
+ getPoolType(): PoolType;
10
+ subscribePoolChange(pool: PoolBase): UnsubscribePromise;
11
+ private getPoolDelta;
12
12
  private isActivePool;
13
- private getLinearWeight;
14
13
  private isRepayFeeApplied;
15
- getPoolFees(_feeAsset: string, address: string): Promise<PoolFees>;
16
14
  private getRepayFee;
17
15
  private getPoolLimits;
18
16
  }
@@ -11,7 +11,6 @@ export type OmniPoolPair = PoolPair & {
11
11
  export type OmniPoolToken = PoolToken & {
12
12
  hubReserves: BigNumber;
13
13
  shares: BigNumber;
14
- tradeable: number;
15
14
  };
16
15
  export type OmniPoolFees = PoolFees & {
17
16
  assetFee: PoolFee;
@@ -1,13 +1,12 @@
1
- import { PoolBase, PoolFees } from '../../types';
1
+ import { UnsubscribePromise } from '@polkadot/api-base/types';
2
+ import { PoolBase, PoolType, PoolFees } from '../../types';
2
3
  import { PoolClient } from '../PoolClient';
3
4
  export declare class OmniPoolClient extends PoolClient {
4
- private pools;
5
- private _poolLoaded;
6
- getPools(): Promise<PoolBase[]>;
7
- private loadPool;
8
- private syncPool;
9
- private getPoolTokenState;
5
+ loadPools(): Promise<PoolBase[]>;
10
6
  getPoolFees(feeAsset: string, _address: string): Promise<PoolFees>;
7
+ getPoolType(): PoolType;
8
+ subscribePoolChange(pool: PoolBase): UnsubscribePromise;
9
+ private updateTokenState;
11
10
  private getAssetFee;
12
11
  private getProtocolFee;
13
12
  private getPoolId;
@@ -4,9 +4,6 @@ export type StableSwapPair = PoolPair & {
4
4
  tradeableIn: number;
5
5
  tradeableOut: number;
6
6
  };
7
- export type StableSwapToken = PoolToken & {
8
- tradeable: number;
9
- };
10
7
  export type StableSwapFees = PoolFees & {
11
8
  fee: PoolFee;
12
9
  };
@@ -19,7 +16,7 @@ export type StableSwapBase = PoolBase & {
19
16
  export declare class StableSwap implements Pool {
20
17
  type: PoolType;
21
18
  address: string;
22
- tokens: StableSwapToken[];
19
+ tokens: PoolToken[];
23
20
  maxInRatio: number;
24
21
  maxOutRatio: number;
25
22
  minTradingLimit: number;
@@ -28,7 +25,7 @@ export declare class StableSwap implements Pool {
28
25
  fee: PoolFee;
29
26
  totalIssuance: string;
30
27
  static fromPool(pool: StableSwapBase): StableSwap;
31
- constructor(address: string, tokens: StableSwapToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number, amplification: string, id: string, fee: PoolFee, totalIssuance: string);
28
+ constructor(address: string, tokens: PoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number, amplification: string, id: string, fee: PoolFee, totalIssuance: string);
32
29
  validatePair(_tokenIn: string, _tokenOut: string): boolean;
33
30
  parsePair(tokenIn: string, tokenOut: string): StableSwapPair;
34
31
  validateAndBuy(poolPair: StableSwapPair, amountOut: BigNumber, fees: StableSwapFees): BuyTransfer;
@@ -1,19 +1,14 @@
1
- import { PoolBase, PoolFees } from '../../types';
1
+ import { UnsubscribePromise } from '@polkadot/api-base/types';
2
+ import { PoolBase, PoolType, PoolFees } from '../../types';
2
3
  import { PoolClient } from '../PoolClient';
3
4
  export declare class StableSwapClient extends PoolClient {
4
- private poolsData;
5
- private pools;
6
- private _poolsLoaded;
7
- getPools(): Promise<PoolBase[]>;
8
- private loadPools;
9
- private syncPools;
10
- private syncTokens;
11
- private getPoolTokenState;
12
- getParaChainBlock(): Promise<number>;
13
- private getTotalIssueance;
14
- private getAmplification;
15
- private getPoolAddress;
16
- private getOmniPoolAddress;
5
+ private stablePools;
6
+ loadPools(): Promise<PoolBase[]>;
17
7
  getPoolFees(_feeAsset: string, address: string): Promise<PoolFees>;
8
+ getPoolType(): PoolType;
9
+ subscribePoolChange(pool: PoolBase): UnsubscribePromise;
10
+ private getPoolDelta;
11
+ private getPoolTokens;
12
+ private getPoolAddress;
18
13
  private getPoolLimits;
19
14
  }
@@ -1,12 +1,11 @@
1
- import { PoolBase, PoolFees } from '../../types';
1
+ import { UnsubscribePromise } from '@polkadot/api-base/types';
2
+ import { PoolBase, PoolType, PoolFees } from '../../types';
2
3
  import { PoolClient } from '../PoolClient';
3
4
  export declare class XykPoolClient extends PoolClient {
4
- private pools;
5
- private _poolsLoaded;
6
- getPools(): Promise<PoolBase[]>;
7
- private loadPools;
8
- private syncPools;
5
+ loadPools(): Promise<PoolBase[]>;
9
6
  getPoolFees(_feeAsset: string, _address: string): Promise<PoolFees>;
7
+ getPoolType(): PoolType;
8
+ protected subscribePoolChange(pool: PoolBase): UnsubscribePromise;
10
9
  private getExchangeFee;
11
10
  private getPoolLimits;
12
11
  }
@@ -1,10 +1,4 @@
1
1
  import { BigNumber } from './utils/bignumber';
2
- export type PoolAsset = {
3
- id: string;
4
- symbol: string;
5
- icon: string;
6
- meta?: Record<string, string>;
7
- };
8
2
  export declare enum PoolType {
9
3
  XYK = "Xyk",
10
4
  LBP = "Lbp",
@@ -35,16 +29,17 @@ export type PoolBase = {
35
29
  maxOutRatio: number;
36
30
  minTradingLimit: number;
37
31
  };
32
+ export interface PoolToken extends AssetMetadata {
33
+ id: string;
34
+ balance: string;
35
+ tradeable?: number;
36
+ }
38
37
  export type PoolLimits = Pick<PoolBase, 'maxInRatio' | 'maxOutRatio' | 'minTradingLimit'>;
39
38
  export type PoolFee = [numerator: number, denominator: number];
40
39
  export type PoolFees = {
41
40
  min?: PoolFee;
42
41
  max?: PoolFee;
43
42
  };
44
- export type PoolToken = PoolAsset & {
45
- balance: string;
46
- decimals: number;
47
- };
48
43
  export type PoolSell = {
49
44
  calculatedOut: BigNumber;
50
45
  };
@@ -129,13 +124,12 @@ export interface AssetBalance {
129
124
  available: BigNumber;
130
125
  }
131
126
  export interface AssetMetadata {
132
- symbol: string;
127
+ id: string;
133
128
  decimals: number;
134
- icon: string;
135
- meta?: Record<string, string>;
136
- }
137
- export interface AssetDetail {
138
129
  name: string;
130
+ symbol: string;
131
+ icon: string;
139
132
  assetType: string;
140
133
  existentialDeposit: string;
134
+ meta?: Record<string, string>;
141
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/sdk",
3
- "version": "0.7.7",
3
+ "version": "0.8.0-beta.2",
4
4
  "description": "Galactic off-chain routing & optimization of orders across pools for best price execution",
5
5
  "author": "GalacticCouncil",
6
6
  "repository": {