@galacticcouncil/sdk-next 0.10.0-pr207-436c730 → 0.10.1

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.
@@ -0,0 +1,124 @@
1
+ export declare const GHO_TOKEN_ABI: readonly [{
2
+ readonly inputs: readonly [{
3
+ readonly internalType: "address";
4
+ readonly name: "facilitator";
5
+ readonly type: "address";
6
+ }];
7
+ readonly name: "getFacilitator";
8
+ readonly outputs: readonly [{
9
+ readonly type: "tuple";
10
+ readonly components: readonly [{
11
+ readonly name: "addr";
12
+ readonly type: "address";
13
+ }, {
14
+ readonly name: "label";
15
+ readonly type: "bytes32";
16
+ }, {
17
+ readonly name: "bucketCapacity";
18
+ readonly type: "uint128";
19
+ }, {
20
+ readonly name: "bucketLevel";
21
+ readonly type: "uint128";
22
+ }];
23
+ }];
24
+ readonly stateMutability: "view";
25
+ readonly type: "function";
26
+ }, {
27
+ readonly inputs: readonly [{
28
+ readonly internalType: "address";
29
+ readonly name: "facilitator";
30
+ readonly type: "address";
31
+ }];
32
+ readonly name: "getFacilitatorBucket";
33
+ readonly outputs: readonly [{
34
+ readonly internalType: "uint256";
35
+ readonly name: "";
36
+ readonly type: "uint256";
37
+ }, {
38
+ readonly internalType: "uint256";
39
+ readonly name: "";
40
+ readonly type: "uint256";
41
+ }];
42
+ readonly stateMutability: "view";
43
+ readonly type: "function";
44
+ }, {
45
+ readonly inputs: readonly [];
46
+ readonly name: "getFacilitatorsList";
47
+ readonly outputs: readonly [{
48
+ readonly internalType: "address[]";
49
+ readonly name: "";
50
+ readonly type: "address[]";
51
+ }];
52
+ readonly stateMutability: "view";
53
+ readonly type: "function";
54
+ }, {
55
+ readonly anonymous: false;
56
+ readonly inputs: readonly [{
57
+ readonly indexed: true;
58
+ readonly internalType: "address";
59
+ readonly name: "facilitatorAddress";
60
+ readonly type: "address";
61
+ }, {
62
+ readonly indexed: true;
63
+ readonly internalType: "bytes32";
64
+ readonly name: "label";
65
+ readonly type: "bytes32";
66
+ }, {
67
+ readonly indexed: false;
68
+ readonly internalType: "uint256";
69
+ readonly name: "bucketCapacity";
70
+ readonly type: "uint256";
71
+ }];
72
+ readonly name: "FacilitatorAdded";
73
+ readonly type: "event";
74
+ }, {
75
+ readonly anonymous: false;
76
+ readonly inputs: readonly [{
77
+ readonly indexed: true;
78
+ readonly internalType: "address";
79
+ readonly name: "facilitatorAddress";
80
+ readonly type: "address";
81
+ }, {
82
+ readonly indexed: false;
83
+ readonly internalType: "uint256";
84
+ readonly name: "oldCapacity";
85
+ readonly type: "uint256";
86
+ }, {
87
+ readonly indexed: false;
88
+ readonly internalType: "uint256";
89
+ readonly name: "newCapacity";
90
+ readonly type: "uint256";
91
+ }];
92
+ readonly name: "FacilitatorBucketCapacityUpdated";
93
+ readonly type: "event";
94
+ }, {
95
+ readonly anonymous: false;
96
+ readonly inputs: readonly [{
97
+ readonly indexed: true;
98
+ readonly internalType: "address";
99
+ readonly name: "facilitatorAddress";
100
+ readonly type: "address";
101
+ }, {
102
+ readonly indexed: false;
103
+ readonly internalType: "uint256";
104
+ readonly name: "oldLevel";
105
+ readonly type: "uint256";
106
+ }, {
107
+ readonly indexed: false;
108
+ readonly internalType: "uint256";
109
+ readonly name: "newLevel";
110
+ readonly type: "uint256";
111
+ }];
112
+ readonly name: "FacilitatorBucketLevelUpdated";
113
+ readonly type: "event";
114
+ }, {
115
+ readonly anonymous: false;
116
+ readonly inputs: readonly [{
117
+ readonly indexed: true;
118
+ readonly internalType: "address";
119
+ readonly name: "facilitatorAddress";
120
+ readonly type: "address";
121
+ }];
122
+ readonly name: "FacilitatorRemoved";
123
+ readonly type: "event";
124
+ }];
@@ -0,0 +1,2 @@
1
+ export { GhoTokenClient } from './GhoTokenClient';
2
+ export { GHO_TOKEN_ABI } from './abi';
@@ -22,8 +22,8 @@ export declare abstract class PoolClient<T extends PoolBase> extends BalanceClie
22
22
  getSubscriber(): Observable<T[]>;
23
23
  private subscribeStore;
24
24
  protected subscribeBalances(): Subscription;
25
- private hasSystemAsset;
26
- private hasErc20Asset;
25
+ protected hasSystemAsset(pool: T): boolean;
26
+ protected hasErc20Asset(pool: PoolBase): boolean;
27
27
  private hasValidAssets;
28
28
  private updateBalances;
29
29
  }
@@ -2,6 +2,7 @@ import { PolkadotClient } from 'polkadot-api';
2
2
  import { Papi } from '../api';
3
3
  import { EvmClient } from '../evm';
4
4
  import { AavePoolClient } from './aave';
5
+ import { HsmPoolClient } from './hsm';
5
6
  import { LbpPoolClient } from './lbp';
6
7
  import { OmniPoolClient } from './omni';
7
8
  import { XykPoolClient } from './xyk';
@@ -12,6 +13,7 @@ export declare class PoolContextProvider extends Papi implements IPoolCtxProvide
12
13
  readonly aave: AavePoolClient;
13
14
  readonly omnipool: OmniPoolClient;
14
15
  readonly stableswap: StableSwapClient;
16
+ readonly hsm: HsmPoolClient;
15
17
  readonly xyk: XykPoolClient;
16
18
  readonly lbp: LbpPoolClient;
17
19
  private readonly active;
@@ -20,17 +22,19 @@ export declare class PoolContextProvider extends Papi implements IPoolCtxProvide
20
22
  private aaveSub;
21
23
  private omniSub;
22
24
  private stableSub;
25
+ private hsmSub;
23
26
  private xykSub;
24
27
  private lbpSub;
25
28
  private isReady;
26
29
  private isDestroyed;
27
30
  constructor(client: PolkadotClient, evm: EvmClient);
28
31
  private subscribe;
32
+ withAave(): this;
29
33
  withOmnipool(): this;
30
34
  withStableswap(): this;
31
- withLbp(): this;
32
- withAave(): this;
35
+ withHsm(): this;
33
36
  withXyk(override?: PoolTokenOverride[]): this;
37
+ withLbp(): this;
34
38
  destroy(): void;
35
39
  getPools(): Promise<PoolBase[]>;
36
40
  getPoolFees(poolPair: PoolPair, pool: Pool): Promise<PoolFees>;
@@ -11,7 +11,7 @@ export declare class AavePool implements Pool {
11
11
  maxOutRatio: bigint;
12
12
  minTradingLimit: bigint;
13
13
  static fromPool(pool: PoolBase): AavePool;
14
- constructor(address: string, tokens: AavePoolToken[], maxInRation: bigint, maxOutRatio: bigint, minTradeLimit: bigint);
14
+ constructor(pool: PoolBase);
15
15
  validatePair(_tokenIn: number, _tokenOut: number): boolean;
16
16
  parsePair(tokenIn: number, tokenOut: number): PoolPair;
17
17
  validateAndBuy(poolPair: PoolPair, amountOut: bigint, _fees: PoolFees): BuyCtx;
@@ -0,0 +1,21 @@
1
+ export declare class HsmMath {
2
+ static calculateCollateralInGivenHollarOut(amountOut: string, collateralPeg: string, purchaseFee: string): string;
3
+ static calculateCollateralOutGivenHollarIn(amountIn: string, executionPrice: string, buybackFee: string): string;
4
+ static calculateHollarOutGivenCollateralIn(amountIn: string, collateralPeg: string, purchaseFee: string): string;
5
+ static calculateHollarInGivenCollateralOut(amountOut: string, executionPrice: string, buybackFee: string): string;
6
+ /**
7
+ * I_i = (H_i - peg_i * R_i) / 2
8
+ *
9
+ * If hollar reserve is less than pegged collateral, we're considering zero imbalance
10
+ * as we only care about positive imbalance (excess Hollar in the pool
11
+ *
12
+ * @param hollarReserve
13
+ * @param collateralPeg
14
+ * @param collateralReserve
15
+ * @returns pool imbalance or 0 if hollar reserve is less than pegged collateral
16
+ */
17
+ static calculateImbalance(hollarReserve: string, collateralPeg: string, collateralReserve: string): string;
18
+ static calculateBuybackLimit(imbalance: string, buybackRate: string): string;
19
+ static calculateBuybackPriceWithFee(executionPriceNum: string, executionPriceDen: string, buyBackFee: string): string;
20
+ static calculateMaxPrice(collateralPeg: string, coeficient: string): string;
21
+ }
@@ -0,0 +1,51 @@
1
+ import { BuyCtx, PoolError, PoolFee, PoolPair, SellCtx } from '../types';
2
+ import { StableSwap, StableSwapBase, StableSwapPair } from '../stable';
3
+ export type HsmPoolBase = StableSwapBase & {
4
+ hsmAddress: string;
5
+ hsmMintCapacity: bigint;
6
+ hollarId: number;
7
+ hollarH160: string;
8
+ collateralId: number;
9
+ collateralBalance: bigint;
10
+ maxBuyPriceCoefficient: bigint;
11
+ maxInHolding: bigint;
12
+ purchaseFee: PoolFee;
13
+ buyBackFee: PoolFee;
14
+ buyBackRate: PoolFee;
15
+ };
16
+ export declare class HsmPool extends StableSwap {
17
+ hsmAddress: string;
18
+ hsmMintCapacity: bigint;
19
+ hollarId: number;
20
+ hollarH160: string;
21
+ collateralId: number;
22
+ collateralBalance: bigint;
23
+ maxBuyPriceCoefficient: bigint;
24
+ maxInHolding: bigint;
25
+ purchaseFee: PoolFee;
26
+ buyBackFee: PoolFee;
27
+ buyBackRate: PoolFee;
28
+ static fromPool(pool: HsmPoolBase): HsmPool;
29
+ constructor(pool: HsmPoolBase);
30
+ validatePair(_tokenIn: number, _tokenOut: number): boolean;
31
+ parsePair(tokenIn: number, tokenOut: number): StableSwapPair;
32
+ validateTradeHollarIn(poolPair: PoolPair, amountIn: bigint, amountOut: bigint, errors: PoolError[]): PoolError[];
33
+ validateTradeHollarOut(amountIn: bigint, amountOut: bigint, errors: PoolError[]): PoolError[];
34
+ validateTradeConstraints(poolPair: PoolPair, amountIn: bigint, amountOut: bigint): PoolError[];
35
+ validateAndBuy(poolPair: PoolPair, amountOut: bigint): BuyCtx;
36
+ validateAndSell(poolPair: PoolPair, amountIn: bigint): SellCtx;
37
+ private calculateHollarInGivenCollateralOut;
38
+ private calculateCollateralInGivenHollarOut;
39
+ calculateInGivenOut(poolPair: PoolPair, amountOut: bigint): bigint;
40
+ private calculateCollateralOutGivenHollarIn;
41
+ private calculateHollarOutGivenCollateralIn;
42
+ calculateOutGivenIn(poolPair: PoolPair, amountIn: bigint): bigint;
43
+ private calculateImbalance;
44
+ private calculateBuybackLimit;
45
+ private calculateBuyPrice;
46
+ private calculateMaxPrice;
47
+ spotPriceInGivenOut(poolPair: PoolPair): bigint;
48
+ spotPriceOutGivenIn(poolPair: PoolPair): bigint;
49
+ private getCollateralPeg;
50
+ private isDefaultPeg;
51
+ }
@@ -0,0 +1,24 @@
1
+ import { PolkadotClient } from 'polkadot-api';
2
+ import { Subscription } from 'rxjs';
3
+ import { PoolClient } from '../PoolClient';
4
+ import { StableSwapClient } from '../stable';
5
+ import { PoolFees, PoolType } from '../types';
6
+ import { EvmClient } from '../../evm';
7
+ import { HsmPoolBase } from './HsmPool';
8
+ export declare class HsmPoolClient extends PoolClient<HsmPoolBase> {
9
+ private ghoClient;
10
+ private stableClient;
11
+ constructor(client: PolkadotClient, evm: EvmClient, stableClient: StableSwapClient);
12
+ getPoolType(): PoolType;
13
+ private getPoolId;
14
+ private getFacilitatorAddress;
15
+ private getHollarAddress;
16
+ private getPoolAddress;
17
+ isSupported(): Promise<boolean>;
18
+ loadPools(): Promise<HsmPoolBase[]>;
19
+ getPoolFees(): Promise<PoolFees>;
20
+ private parseEvmLog;
21
+ private subscribeEvmLog;
22
+ protected subscribeBalances(): Subscription;
23
+ protected subscribeUpdates(): Subscription;
24
+ }
@@ -0,0 +1,3 @@
1
+ export * from './HsmMath';
2
+ export * from './HsmPool';
3
+ export * from './HsmPoolClient';
@@ -0,0 +1,7 @@
1
+ import { HydrationEvents } from '@galacticcouncil/descriptors';
2
+ export type TEvmPayload = HydrationEvents['EVM']['Log'];
3
+ export type TEvmEvent = {
4
+ eventName: string;
5
+ facilitator: string;
6
+ key: string;
7
+ };
@@ -1,8 +1,9 @@
1
1
  export { PoolFactory } from './PoolFactory';
2
2
  export { PoolContextProvider } from './PoolContextProvider';
3
3
  export * as aave from './aave';
4
- export * as xyk from './xyk';
5
4
  export * as omni from './omni';
6
- export * as lbp from './lbp';
7
5
  export * as stable from './stable';
6
+ export * as hsm from './hsm';
7
+ export * as xyk from './xyk';
8
+ export * as lbp from './lbp';
8
9
  export * from './types';
@@ -24,7 +24,7 @@ export declare class LbpPool implements Pool {
24
24
  fee: PoolFee;
25
25
  repayFeeApply: boolean;
26
26
  static fromPool(pool: LbpPoolBase): LbpPool;
27
- constructor(address: string, tokens: WeightedPoolToken[], maxInRatio: bigint, maxOutRatio: bigint, minTradingLimit: bigint, fee: PoolFee, repayFeeApply: boolean);
27
+ constructor(pool: LbpPoolBase);
28
28
  validatePair(_tokenIn: number, _tokenOut: number): boolean;
29
29
  parsePair(tokenIn: number, tokenOut: number): WeightedPoolPair;
30
30
  /**
@@ -29,7 +29,7 @@ export declare class OmniPool implements Pool {
29
29
  minTradingLimit: bigint;
30
30
  hubAssetId: number;
31
31
  static fromPool(pool: OmniPoolBase): OmniPool;
32
- constructor(address: string, tokens: OmniPoolToken[], maxInRation: bigint, maxOutRatio: bigint, minTradeLimit: bigint, hubAssetId: number);
32
+ constructor(pool: OmniPoolBase);
33
33
  validatePair(_tokenIn: number, tokenOut: number): boolean;
34
34
  parsePair(tokenIn: number, tokenOut: number): OmniPoolPair;
35
35
  validateAndBuy(poolPair: OmniPoolPair, amountOut: bigint, fees: OmniPoolFees): BuyCtx;
@@ -28,7 +28,7 @@ export declare class StableSwap implements Pool {
28
28
  totalIssuance: bigint;
29
29
  pegs: string[][];
30
30
  static fromPool(pool: StableSwapBase): StableSwap;
31
- constructor(address: string, tokens: PoolToken[], maxInRation: bigint, maxOutRatio: bigint, minTradeLimit: bigint, amplification: bigint, isRampPeriod: boolean, id: number, fee: PoolFee, totalIssuance: bigint, pegs: PoolPegs);
31
+ constructor(pool: StableSwapBase);
32
32
  validatePair(_tokenIn: number, _tokenOut: number): boolean;
33
33
  parsePair(tokenIn: number, tokenOut: number): StableSwapPair;
34
34
  validateAndBuy(poolPair: StableSwapPair, amountOut: bigint, fees: StableSwapFees): BuyCtx;
@@ -8,14 +8,20 @@ export declare enum PoolType {
8
8
  LBP = "LBP",
9
9
  Omni = "Omnipool",
10
10
  Stable = "Stableswap",
11
- XYK = "XYK"
11
+ XYK = "XYK",
12
+ HSM = "HSM"
12
13
  }
13
14
  export declare enum PoolError {
15
+ UnknownError = "UnknownError",
16
+ FacilitatorCapacityExceeded = "FacilitatorCapacityExceeded",
14
17
  InsufficientTradingAmount = "InsufficientTradingAmount",
18
+ InsufficientCollateral = "InsufficientCollateral",
19
+ MaxHoldingExceeded = "MaxHoldingExceeded",
15
20
  MaxInRatioExceeded = "MaxInRatioExceeded",
16
21
  MaxOutRatioExceeded = "MaxOutRatioExceeded",
17
22
  TradeNotAllowed = "TradeNotAllowed",
18
- UnknownError = "UnknownError"
23
+ MaxBuyBackExceeded = "MaxBuyBackExceeded",
24
+ MaxBuyPriceExceeded = "MaxBuyPriceExceeded"
19
25
  }
20
26
  export interface PoolPair {
21
27
  assetIn: number;
@@ -10,7 +10,7 @@ export declare class XykPool implements Pool {
10
10
  maxOutRatio: bigint;
11
11
  minTradingLimit: bigint;
12
12
  static fromPool(pool: PoolBase): XykPool;
13
- constructor(address: string, tokens: PoolToken[], maxInRation: bigint, maxOutRatio: bigint, minTradeLimit: bigint);
13
+ constructor(pool: PoolBase);
14
14
  validatePair(_tokenIn: number, _tokenOut: number): boolean;
15
15
  parsePair(tokenIn: number, tokenOut: number): PoolPair;
16
16
  validateAndBuy(poolPair: PoolPair, amountOut: bigint, fees: XykPoolFees): BuyCtx;
@@ -6,6 +6,7 @@ export declare class Router {
6
6
  private filter;
7
7
  constructor(ctx: IPoolCtxProvider);
8
8
  withFilter(filter?: PoolFilter): Promise<void>;
9
+ protected onFilterChanged(): void;
9
10
  protected buildRouteKey(assetIn: number, assetOut: number, pools: PoolBase[]): string;
10
11
  /**
11
12
  * Filter pools given the following contraints:
@@ -4,8 +4,8 @@ import { Hop, IPoolCtxProvider } from '../pool';
4
4
  import { Amount } from '../types';
5
5
  export declare class TradeRouter extends Router {
6
6
  private readonly mlr;
7
- private poolsSnapshot?;
8
7
  constructor(ctx: IPoolCtxProvider);
8
+ protected onFilterChanged(): void;
9
9
  private buildCtxSync;
10
10
  private withCtx;
11
11
  /**
@@ -42,11 +42,23 @@ export declare class StakingApi {
42
42
  };
43
43
  getRewards(account: string, activeReferendaIds: Array<string>, blockNumber: string): Promise<{
44
44
  rewards: string;
45
+ payablePercentage: string;
46
+ extraPayablePercentage: string | undefined;
47
+ constants: {
48
+ a: string;
49
+ b: string;
50
+ };
45
51
  maxRewards?: undefined;
46
52
  allocatedRewardsPercentage?: undefined;
47
53
  } | {
48
54
  rewards: string;
49
55
  maxRewards: string;
50
56
  allocatedRewardsPercentage: number;
57
+ payablePercentage: string;
58
+ extraPayablePercentage: string | undefined;
59
+ constants: {
60
+ a: string;
61
+ b: string;
62
+ };
51
63
  } | undefined>;
52
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/sdk-next",
3
- "version": "0.10.0-pr207-436c730",
3
+ "version": "0.10.1",
4
4
  "description": "Galactic next gen sdk (papi)",
5
5
  "author": "GalacticCouncil",
6
6
  "repository": {
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@galacticcouncil/descriptors": "^1.4.0",
39
+ "@galacticcouncil/math-hsm": "^1.1.0",
39
40
  "@galacticcouncil/math-lbp": "^1.2.0",
40
41
  "@galacticcouncil/math-liquidity-mining": "^1.2.0",
41
42
  "@galacticcouncil/math-omnipool": "^1.3.0",