@galacticcouncil/sdk 0.6.5 → 0.7.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.
@@ -3,11 +3,14 @@ import { AssetDetail, AssetMetadata } from '../types';
3
3
  import { PolkadotApiClient } from './PolkadotApi';
4
4
  export declare class AssetClient extends PolkadotApiClient {
5
5
  constructor(api: ApiPromise);
6
- getAssetMetadata(tokenKey: string): Promise<AssetMetadata>;
6
+ private tryBonds;
7
+ private tryShares;
7
8
  private getTokenMetadata;
8
9
  private getBondMetadata;
9
10
  private getShareMetadata;
10
- getAssetDetail(tokenKey: string): Promise<AssetDetail>;
11
+ getAssetMetadata(tokenKey: string): Promise<AssetMetadata>;
11
12
  private getTokenDetail;
12
13
  private getBondDetail;
14
+ private getShareDetail;
15
+ getAssetDetail(tokenKey: string): Promise<AssetDetail>;
13
16
  }
@@ -1,6 +1,7 @@
1
1
  import { LbpPoolClient } from './lbp/LbpPoolClient';
2
2
  import { OmniPoolClient } from './omni/OmniPoolClient';
3
3
  import { XykPoolClient } from './xyk/XykPoolClient';
4
+ import { StableSwapClient } from './stable/StableSwapClient';
4
5
  import { Hop, PoolBase, IPoolService, PoolType, Transaction, PoolFees, Pool } from '../types';
5
6
  import { BigNumber } from '../utils/bignumber';
6
7
  import { ApiPromise } from '@polkadot/api';
@@ -9,10 +10,12 @@ export declare class PoolService implements IPoolService {
9
10
  protected readonly xykClient: XykPoolClient;
10
11
  protected readonly omniClient: OmniPoolClient;
11
12
  protected readonly lbpClient: LbpPoolClient;
13
+ protected readonly stableClient: StableSwapClient;
12
14
  constructor(api: ApiPromise);
13
15
  getPools(includeOnly: PoolType[]): Promise<PoolBase[]>;
14
16
  getPoolFees(feeAsset: string, pool: Pool): Promise<PoolFees>;
15
17
  private isDirectOmnipoolTrade;
16
18
  buildBuyTx(assetIn: string, assetOut: string, amountOut: BigNumber, maxAmountIn: BigNumber, route: Hop[]): Transaction;
17
19
  buildSellTx(assetIn: string, assetOut: string, amountIn: BigNumber, minAmountOut: BigNumber, route: Hop[]): Transaction;
20
+ private buildRoute;
18
21
  }
@@ -0,0 +1,11 @@
1
+ export declare class StableMath {
2
+ static getPoolAddress(assetId: number): Uint8Array;
3
+ static calculateAmplification(initialAmp: string, finalAmp: string, initialBlock: string, finalBlock: string, currentBlock: string): string;
4
+ static calculateInGivenOut(reserves: string, assetIn: number, assetOut: number, amountOut: string, amplification: string, fee: string): string;
5
+ static calculateAddOneAsset(reserves: string, shares: string, assetIn: number, amplification: string, shareIssuance: string, fee: string): string;
6
+ static calculateSharesForAmount(reserves: string, assetIn: number, amount: string, amplification: string, shareIssuance: string, fee: string): string;
7
+ static calculateOutGivenIn(reserves: string, assetIn: number, assetOut: number, amountIn: string, amplification: string, fee: string): string;
8
+ static calculateLiquidityOutOneAsset(reserves: string, shares: string, assetOut: number, amplification: string, shareIssuance: string, withdrawFee: string): string;
9
+ static calculateShares(reserves: string, assets: string, amplification: string, shareIssuance: string, fee: string): string;
10
+ static calculatePoolTradeFee(amount: string, feeNumerator: number, feeDenominator: number): string;
11
+ }
@@ -1,4 +1,42 @@
1
- import { PoolFee, PoolFees } from '../../types';
1
+ import { BuyTransfer, Pool, PoolBase, PoolFee, PoolFees, PoolPair, PoolToken, PoolType, SellTransfer } from '../../types';
2
+ import { BigNumber } from '../../utils/bignumber';
2
3
  export type StableSwapFees = PoolFees & {
3
4
  fee: PoolFee;
4
5
  };
6
+ export type StableSwapBase = PoolBase & {
7
+ amplification: string;
8
+ id: string;
9
+ fee: PoolFee;
10
+ totalIssuance: string;
11
+ };
12
+ export declare class StableSwap implements Pool {
13
+ type: PoolType;
14
+ address: string;
15
+ tokens: PoolToken[];
16
+ maxInRatio: number;
17
+ maxOutRatio: number;
18
+ minTradingLimit: number;
19
+ amplification: string;
20
+ id: string;
21
+ fee: PoolFee;
22
+ totalIssuance: string;
23
+ static fromPool(pool: StableSwapBase): StableSwap;
24
+ constructor(address: string, tokens: PoolToken[], maxInRation: number, maxOutRatio: number, minTradeLimit: number, amplification: string, id: string, fee: PoolFee, totalIssuance: string);
25
+ validatePair(_tokenIn: string, _tokenOut: string): boolean;
26
+ parsePair(tokenIn: string, tokenOut: string): PoolPair;
27
+ validateAndBuy(poolPair: PoolPair, amountOut: BigNumber, fees: StableSwapFees): BuyTransfer;
28
+ validateAndSell(poolPair: PoolPair, amountIn: BigNumber, fees: StableSwapFees): SellTransfer;
29
+ private calculateIn;
30
+ private calculateAddOneAsset;
31
+ private calculateSharesForAmount;
32
+ calculateInGivenOut(poolPair: PoolPair, amountOut: BigNumber, fees?: StableSwapFees): BigNumber;
33
+ spotPriceInGivenOut(poolPair: PoolPair): BigNumber;
34
+ private calculateOut;
35
+ private calculateWithdrawOneAsset;
36
+ private calculateShares;
37
+ calculateOutGivenIn(poolPair: PoolPair, amountIn: BigNumber, fees?: StableSwapFees): BigNumber;
38
+ spotPriceOutGivenIn(poolPair: PoolPair): BigNumber;
39
+ calculateTradeFee(amount: BigNumber, fees: StableSwapFees): BigNumber;
40
+ private getReserves;
41
+ private getAssets;
42
+ }
@@ -1,11 +1,16 @@
1
1
  import { PoolBase, PoolFees } from '../../types';
2
2
  import { PoolClient } from '../PoolClient';
3
3
  export declare class StableSwapClient extends PoolClient {
4
+ private poolsData;
4
5
  private pools;
5
6
  private _poolsLoaded;
6
7
  getPools(): Promise<PoolBase[]>;
7
8
  private loadPools;
8
9
  private syncPools;
9
- getPoolFees(_feeAsset: string, _address: string): Promise<PoolFees>;
10
+ getParaChainBlock(): Promise<number>;
11
+ private getTotalIssueance;
12
+ private getAmplification;
13
+ getPoolAddress(poolId: string): string;
14
+ getPoolFees(_feeAsset: string, address: string): Promise<PoolFees>;
10
15
  private getPoolLimits;
11
16
  }
@@ -2,7 +2,7 @@ import { BigNumber } from './utils/bignumber';
2
2
  export type PoolAsset = {
3
3
  id: string;
4
4
  symbol: string;
5
- origin: string;
5
+ icon: string;
6
6
  };
7
7
  export declare enum PoolType {
8
8
  XYK = "Xyk",
@@ -26,6 +26,7 @@ export interface PoolPair {
26
26
  }
27
27
  export type PoolBase = {
28
28
  address: string;
29
+ id?: string;
29
30
  type: PoolType;
30
31
  tokens: PoolToken[];
31
32
  maxInRatio: number;
@@ -79,7 +80,8 @@ export interface Transaction {
79
80
  }
80
81
  export type Hop = {
81
82
  pool: PoolType;
82
- poolId: string;
83
+ poolAddress: string;
84
+ poolId?: string;
83
85
  assetIn: string;
84
86
  assetOut: string;
85
87
  };
@@ -127,7 +129,7 @@ export interface AssetBalance {
127
129
  export interface AssetMetadata {
128
130
  symbol: string;
129
131
  decimals: number;
130
- origin: string;
132
+ icon: string;
131
133
  }
132
134
  export interface AssetDetail {
133
135
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/sdk",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "description": "Galactic off-chain routing & optimization of orders across pools for best price execution",
5
5
  "author": "GalacticCouncil",
6
6
  "repository": {
@@ -37,6 +37,7 @@
37
37
  "dependencies": {
38
38
  "@galacticcouncil/math-lbp": "^0.2.1",
39
39
  "@galacticcouncil/math-omnipool": "^0.2.0",
40
+ "@galacticcouncil/math-stableswap": "^0.2.1",
40
41
  "@galacticcouncil/math-xyk": "^0.2.0",
41
42
  "@thi.ng/cache": "^2.1.35",
42
43
  "bignumber.js": "^9.1.0",