@galacticcouncil/sdk 0.0.8 → 0.2.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.
@@ -1,17 +1,17 @@
1
- import { PoolService, PoolBase, Hop, Pool, PoolAsset, PoolType } from '../types';
1
+ import { IPoolService, PoolBase, Hop, Pool, PoolAsset, PoolType } from '../types';
2
2
  export type RouterOptions = {
3
3
  includeOnly?: PoolType[];
4
4
  };
5
5
  export declare class Router {
6
6
  private readonly routeSuggester;
7
7
  private readonly routerOptions;
8
- protected readonly poolService: PoolService;
8
+ protected readonly poolService: IPoolService;
9
9
  private readonly defaultRouterOptions;
10
10
  /**
11
11
  * @param poolService - Fetch pool data from substrate based pools
12
12
  * @param routerOptions - Optional router options
13
13
  */
14
- constructor(poolService: PoolService, routerOptions?: RouterOptions);
14
+ constructor(poolService: IPoolService, routerOptions?: RouterOptions);
15
15
  /**
16
16
  * Return all pools
17
17
  *
@@ -49,9 +49,9 @@ export declare class TradeRouter extends Router {
49
49
  *
50
50
  * @param {string} assetIn - Storage key of tokenIn
51
51
  * @param {string} assetOut - Storage key of tokenOut
52
- * @return Best possible spot price of given token pair
52
+ * @return Best possible spot price of given token pair, or undefined if given pair trade not supported
53
53
  */
54
- getBestSpotPrice(assetIn: string, assetOut: string): Promise<Amount>;
54
+ getBestSpotPrice(assetIn: string, assetOut: string): Promise<Amount | undefined>;
55
55
  /**
56
56
  * Find best buy swap without errors, if there is none return first one found
57
57
  *
@@ -0,0 +1,8 @@
1
+ import { ApiPromise } from '@polkadot/api';
2
+ import { AssetDetail, AssetMetadata } from '../types';
3
+ import { PolkadotApiClient } from './PolkadotApi';
4
+ export declare class AssetApiClient extends PolkadotApiClient {
5
+ constructor(api: ApiPromise);
6
+ getAssetMetadata(tokenKey: string): Promise<AssetMetadata>;
7
+ getAssetDetail(tokenKey: string): Promise<AssetDetail>;
8
+ }
@@ -0,0 +1,11 @@
1
+ import { ApiPromise } from '@polkadot/api';
2
+ import { BigNumber } from '../utils/bignumber';
3
+ import { Amount } from '../types';
4
+ import { AssetApiClient } from './AssetApiClient';
5
+ export declare class BalanceApiClient extends AssetApiClient {
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>;
10
+ private calculateFreeBalance;
11
+ }
@@ -1,18 +1,8 @@
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 { AssetMetadata } from '@polkadot/types/interfaces';
5
- import type { PoolToken } from '../types';
6
2
  import '@polkadot/api-augment';
7
- export declare class PolkadotApiClient {
3
+ export declare abstract class PolkadotApiClient {
8
4
  protected readonly api: ApiPromise;
9
5
  constructor(api: ApiPromise);
10
- getStorageKey(asset: [StorageKey<AnyTuple>, Codec], index: number): string;
11
- getStorageEntryArray(asset: [StorageKey<AnyTuple>, Codec]): string[];
12
- getPoolTokens(poolAddress: string, assetKeys: string[]): Promise<PoolToken[]>;
13
- syncPoolTokens(poolAddress: string, poolTokens: PoolToken[]): Promise<PoolToken[]>;
14
- getAssetMetadata(tokenKey: string): Promise<AssetMetadata>;
15
- getAccountBalance(accountId: string, tokenKey: string): Promise<string>;
16
- getSystemAccountBalance(accountId: string): Promise<string>;
17
- getTokenAccountBalance(accountId: string, tokenKey: string): Promise<string>;
6
+ get chainDecimals(): number;
7
+ get chainToken(): string;
18
8
  }
@@ -1 +1,3 @@
1
1
  export { PolkadotApiClient } from './PolkadotApi';
2
+ export { AssetApiClient } from './AssetApiClient';
3
+ export { BalanceApiClient } from './BalanceApiClient';
@@ -0,0 +1,12 @@
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 { PoolToken } from '../types';
5
+ import { BalanceApiClient } from '../client';
6
+ export declare abstract class PoolApiClient extends BalanceApiClient {
7
+ constructor(api: ApiPromise);
8
+ protected getStorageKey(asset: [StorageKey<AnyTuple>, Codec], index: number): string;
9
+ protected getStorageEntryArray(asset: [StorageKey<AnyTuple>, Codec]): string[];
10
+ protected getPoolTokens(poolAddress: string, assetKeys: string[]): Promise<PoolToken[]>;
11
+ protected syncPoolTokens(poolAddress: string, poolTokens: PoolToken[]): Promise<PoolToken[]>;
12
+ }
@@ -0,0 +1,17 @@
1
+ import { LbpPoolApiClient } from './lbp/LbpPoolApiClient';
2
+ import { OmniPoolApiClient } from './omni/OmniPoolApiClient';
3
+ import { XykPoolApiClient } from './xyk/XykPoolApiClient';
4
+ import { Hop, PoolBase, IPoolService, PoolType, Transaction } from '../types';
5
+ import { BigNumber } from '../utils/bignumber';
6
+ import { ApiPromise } from '@polkadot/api';
7
+ export declare class PoolService implements IPoolService {
8
+ protected readonly api: ApiPromise;
9
+ protected readonly xykClient: XykPoolApiClient;
10
+ protected readonly omniClient: OmniPoolApiClient;
11
+ protected readonly lbpClient: LbpPoolApiClient;
12
+ constructor(api: ApiPromise);
13
+ getPools(includeOnly: PoolType[]): Promise<PoolBase[]>;
14
+ private isOmnipoolTx;
15
+ buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
16
+ buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
17
+ }
@@ -1,4 +1,4 @@
1
- export { PolkadotApiPoolService } from './PolkadotApiPoolService';
1
+ export { PoolService } from './PoolService';
2
2
  export { PoolFactory } from './PoolFactory';
3
3
  export { XykPool } from './xyk/XykPool';
4
4
  export { XykMath } from './xyk/XykMath';
@@ -1,5 +1,5 @@
1
- import { PolkadotApiClient } from '../../client';
2
1
  import { PoolBase, PoolFee, PoolLimits } from '../../types';
2
+ import { PoolApiClient } from '../PoolApiClient';
3
3
  interface LbpPoolData {
4
4
  readonly assets: string[];
5
5
  readonly feeCollector: string;
@@ -10,14 +10,14 @@ interface LbpPoolData {
10
10
  readonly start: number;
11
11
  readonly end: number;
12
12
  }
13
- export declare class LbpPolkadotApiClient extends PolkadotApiClient {
13
+ export declare class LbpPoolApiClient extends PoolApiClient {
14
14
  private readonly MAX_FINAL_WEIGHT;
15
15
  private poolsData;
16
16
  private pools;
17
17
  private _poolsLoaded;
18
18
  getPools(): Promise<PoolBase[]>;
19
- loadPools(): Promise<PoolBase[]>;
20
- syncPools(): Promise<PoolBase[]>;
19
+ private loadPools;
20
+ private syncPools;
21
21
  getLinearWeight(poolEntry: LbpPoolData): Promise<string>;
22
22
  isRepayFeeApplied(assetKey: string, poolEntry: LbpPoolData): Promise<boolean>;
23
23
  getRepayFee(): PoolFee;
@@ -7,8 +7,8 @@ export declare class OmniMath {
7
7
  static calculateOutGivenLrnaIn(assetOutBalance: string, assetOutHubReserve: string, assetOutShares: string, amountOut: string, assetFee: string): string;
8
8
  static calculatePoolTradeFee(amount: string, feeNumerator: number, feeDenominator: number): string;
9
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): string;
11
- static calculateLiquidityLRNAOut(assetReserve: string, assetHubReserve: string, assetShares: string, positionAmount: string, positionShares: string, positionPrice: string, sharesToRemove: 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
12
  static calculateCapDifference(assetReserve: string, assetHubReserve: string, assetCap: string, totalHubReserve: string): string;
13
13
  static verifyAssetCap(assetReserve: string, assetCap: string, hubAdded: string, totalHubReserve: string): boolean;
14
14
  static calculateLimitHubIn(assetReserve: string, assetHubReserve: string, assetShares: string, amountIn: string): string;
@@ -1,13 +1,11 @@
1
- import { ApiPromise } from '@polkadot/api';
2
- import { PolkadotApiClient } from '../../client';
3
1
  import { PoolBase, PoolFee, PoolLimits } from '../../types';
4
- export declare class OmniPolkadotApiClient extends PolkadotApiClient {
2
+ import { PoolApiClient } from '../PoolApiClient';
3
+ export declare class OmniPoolApiClient extends PoolApiClient {
5
4
  private pools;
6
5
  private _poolLoaded;
7
- constructor(api: ApiPromise);
8
6
  getPools(): Promise<PoolBase[]>;
9
- loadPool(): Promise<PoolBase>;
10
- syncPool(): Promise<PoolBase>;
7
+ private loadPool;
8
+ private syncPool;
11
9
  private getPoolTokenState;
12
10
  getTradeFee(): PoolFee;
13
11
  getAssetFee(): PoolFee;
@@ -1,11 +1,11 @@
1
- import { PolkadotApiClient } from '../../client';
2
1
  import { PoolBase, PoolFee, PoolLimits } from '../../types';
3
- export declare class XykPolkadotApiClient extends PolkadotApiClient {
2
+ import { PoolApiClient } from '../PoolApiClient';
3
+ export declare class XykPoolApiClient extends PoolApiClient {
4
4
  private pools;
5
5
  private _poolsLoaded;
6
6
  getPools(): Promise<PoolBase[]>;
7
- loadPools(): Promise<PoolBase[]>;
8
- syncPools(): Promise<PoolBase[]>;
7
+ private loadPools;
8
+ private syncPools;
9
9
  getTradeFee(): PoolFee;
10
10
  getPoolLimits(): PoolLimits;
11
11
  }
@@ -62,7 +62,7 @@ export interface Pool extends PoolBase {
62
62
  spotPriceOutGivenIn(poolPair: PoolPair): BigNumber;
63
63
  calculateTradeFee(amount: BigNumber): BigNumber;
64
64
  }
65
- export interface PoolService {
65
+ export interface IPoolService {
66
66
  getPools(includeOnly?: PoolType[]): Promise<PoolBase[]>;
67
67
  buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
68
68
  buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
@@ -118,3 +118,12 @@ export interface AssetBalance {
118
118
  reserved: BigNumber;
119
119
  available: BigNumber;
120
120
  }
121
+ export interface AssetMetadata {
122
+ symbol: string;
123
+ decimals: number;
124
+ }
125
+ export interface AssetDetail {
126
+ name: string;
127
+ existentialDeposit: string;
128
+ locked: boolean;
129
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/sdk",
3
- "version": "0.0.8",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "description": "Galactic SDK",
6
6
  "author": "Pavol Noha <palo@hydradx.io>",
@@ -36,14 +36,14 @@
36
36
  "typescript": "^4.7.4"
37
37
  },
38
38
  "dependencies": {
39
- "@galacticcouncil/math-lbp": "^0.0.7",
40
- "@galacticcouncil/math-omnipool": "^0.0.7",
41
- "@galacticcouncil/math-xyk": "^0.0.7",
39
+ "@galacticcouncil/math-lbp": "^0.1.3",
40
+ "@galacticcouncil/math-omnipool": "^0.1.3",
41
+ "@galacticcouncil/math-xyk": "^0.1.3",
42
42
  "bignumber.js": "^9.1.0",
43
43
  "lodash.clonedeep": "^4.5.0"
44
44
  },
45
45
  "peerDependencies": {
46
- "@polkadot/api": "^9.9.1",
46
+ "@polkadot/api": "^9.14.2",
47
47
  "capi": "^0.1.0-beta.12",
48
48
  "ethers": "^6.0.5"
49
49
  }
@@ -1,17 +0,0 @@
1
- import { Hop, PoolBase, PoolService, PoolType, Transaction } from '../types';
2
- import { XykPolkadotApiClient } from './xyk/XykPolkadotApiClient';
3
- import { LbpPolkadotApiClient } from './lbp/LbpPolkadotApiClient';
4
- import { OmniPolkadotApiClient } from './omni/OmniPolkadotApiClient';
5
- import { BigNumber } from '../utils/bignumber';
6
- import { ApiPromise } from '@polkadot/api';
7
- export declare class PolkadotApiPoolService implements PoolService {
8
- protected readonly api: ApiPromise;
9
- protected readonly xykClient: XykPolkadotApiClient;
10
- protected readonly omniClient: OmniPolkadotApiClient;
11
- protected readonly lbpClient: LbpPolkadotApiClient;
12
- constructor(api: ApiPromise);
13
- getPools(includeOnly: PoolType[]): Promise<PoolBase[]>;
14
- isOmnipoolTx(route: Hop[]): boolean;
15
- buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
16
- buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
17
- }