@galacticcouncil/sdk-next 1.0.0-beta.0 → 1.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 (151) hide show
  1. package/README.md +131 -78
  2. package/build/aave/AaveClient.d.ts +77 -0
  3. package/build/aave/AaveUtils.d.ts +78 -0
  4. package/build/aave/abi/AavePool.d.ts +208 -0
  5. package/build/aave/abi/AavePoolDataProvider.d.ts +384 -0
  6. package/build/aave/abi/index.d.ts +2 -0
  7. package/build/aave/const.d.ts +6 -0
  8. package/build/aave/index.cjs +1 -0
  9. package/build/aave/index.d.ts +4 -0
  10. package/build/aave/index.mjs +1 -0
  11. package/build/aave/types.d.ts +17 -0
  12. package/build/api/Papi.d.ts +10 -0
  13. package/build/api/Watcher.d.ts +11 -0
  14. package/build/api/index.d.ts +3 -0
  15. package/build/api/probe.d.ts +26 -0
  16. package/build/api/provider/index.d.ts +2 -0
  17. package/build/api/provider/smoldot.d.ts +1 -0
  18. package/build/api/provider/websocket.d.ts +4 -0
  19. package/build/{types/client → client}/AssetClient.d.ts +1 -1
  20. package/build/client/BalanceClient.d.ts +20 -0
  21. package/build/client/ChainParams.d.ts +9 -0
  22. package/build/client/index.cjs +1 -0
  23. package/build/{types/client → client}/index.d.ts +1 -0
  24. package/build/client/index.mjs +1 -0
  25. package/build/{types/consts.d.ts → consts.d.ts} +2 -2
  26. package/build/evm/adapter.d.ts +11 -0
  27. package/build/evm/chain.d.ts +2 -0
  28. package/build/evm/client.d.ts +15 -0
  29. package/build/evm/index.cjs +1 -0
  30. package/build/evm/index.d.ts +4 -0
  31. package/build/evm/index.mjs +1 -0
  32. package/build/evm/types.d.ts +7 -0
  33. package/build/factory.d.ts +29 -0
  34. package/build/farm/LiquidityMiningApi.d.ts +29 -0
  35. package/build/farm/LiquidityMiningClient.d.ts +146 -0
  36. package/build/farm/MultiCurrencyContainer.d.ts +8 -0
  37. package/build/farm/RewardClaimSimulator.d.ts +16 -0
  38. package/build/farm/const.d.ts +4 -0
  39. package/build/farm/index.cjs +1 -0
  40. package/build/farm/index.d.ts +3 -0
  41. package/build/farm/index.mjs +1 -0
  42. package/build/farm/types.d.ts +46 -0
  43. package/build/gho/GhoTokenClient.d.ts +6 -0
  44. package/build/gho/abi.d.ts +124 -0
  45. package/build/gho/index.d.ts +2 -0
  46. package/build/index.cjs +1 -1
  47. package/build/{types/index.d.ts → index.d.ts} +6 -0
  48. package/build/index.mjs +1 -1
  49. package/build/oracle/MmOracleClient.d.ts +7 -0
  50. package/build/oracle/abi.d.ts +196 -0
  51. package/build/oracle/index.d.ts +3 -0
  52. package/build/oracle/types.d.ts +5 -0
  53. package/build/pool/PoolClient.d.ts +75 -0
  54. package/build/pool/PoolContextProvider.d.ts +41 -0
  55. package/build/pool/PoolLog.d.ts +11 -0
  56. package/build/pool/PoolStore.d.ts +20 -0
  57. package/build/pool/aave/AaveAbi.d.ts +126 -0
  58. package/build/pool/aave/AavePool.d.ts +24 -0
  59. package/build/pool/aave/AavePoolClient.d.ts +19 -0
  60. package/build/pool/aave/index.d.ts +2 -0
  61. package/build/pool/aave/types.d.ts +13 -0
  62. package/build/pool/hsm/HsmMath.d.ts +21 -0
  63. package/build/pool/hsm/HsmPool.d.ts +63 -0
  64. package/build/pool/hsm/HsmPoolClient.d.ts +26 -0
  65. package/build/pool/hsm/index.d.ts +3 -0
  66. package/build/pool/hsm/types.d.ts +7 -0
  67. package/build/pool/index.cjs +1 -0
  68. package/build/{types/pool → pool}/index.d.ts +4 -2
  69. package/build/pool/index.mjs +1 -0
  70. package/build/{types/pool → pool}/lbp/LbpPool.d.ts +1 -1
  71. package/build/{types/pool → pool}/lbp/LbpPoolClient.d.ts +9 -7
  72. package/build/{types/pool → pool}/omni/OmniMath.d.ts +7 -6
  73. package/build/{types/pool → pool}/omni/OmniPool.d.ts +14 -1
  74. package/build/pool/omni/OmniPoolClient.d.ts +29 -0
  75. package/build/pool/omni/types.d.ts +11 -0
  76. package/build/{types/pool → pool}/stable/StableMath.d.ts +1 -2
  77. package/build/{types/pool → pool}/stable/StableSwap.d.ts +21 -4
  78. package/build/pool/stable/StableSwapClient.d.ts +23 -0
  79. package/build/pool/stable/types.d.ts +15 -0
  80. package/build/{types/pool → pool}/types.d.ts +14 -3
  81. package/build/{types/pool → pool}/xyk/XykPool.d.ts +13 -1
  82. package/build/pool/xyk/XykPoolClient.d.ts +14 -0
  83. package/build/{types/sor → sor}/Router.d.ts +26 -8
  84. package/build/sor/TradeRouteBuilder.d.ts +4 -0
  85. package/build/sor/TradeRouter.d.ts +207 -0
  86. package/build/sor/TradeScheduler.d.ts +111 -0
  87. package/build/sor/const.d.ts +8 -0
  88. package/build/sor/index.cjs +1 -0
  89. package/build/sor/index.d.ts +6 -0
  90. package/build/sor/index.mjs +1 -0
  91. package/build/{types/sor → sor}/route/bfs.d.ts +11 -2
  92. package/build/{types/sor → sor}/route/index.d.ts +1 -1
  93. package/build/sor/route/suggester.d.ts +33 -0
  94. package/build/sor/types.d.ts +68 -0
  95. package/build/staking/StakingApi.d.ts +66 -0
  96. package/build/staking/StakingClient.d.ts +132 -0
  97. package/build/staking/index.cjs +1 -0
  98. package/build/staking/index.d.ts +2 -0
  99. package/build/staking/index.mjs +1 -0
  100. package/build/staking/types.d.ts +16 -0
  101. package/build/staking/utils.d.ts +1 -0
  102. package/build/tx/OrderTxBuilder.d.ts +21 -0
  103. package/build/tx/TradeTxBuilder.d.ts +18 -0
  104. package/build/tx/TxBuilder.d.ts +19 -0
  105. package/build/tx/TxBuilderFactory.d.ts +12 -0
  106. package/build/tx/index.cjs +1 -0
  107. package/build/tx/index.d.ts +2 -0
  108. package/build/tx/index.mjs +1 -0
  109. package/build/tx/types.d.ts +10 -0
  110. package/build/tx/utils.d.ts +5 -0
  111. package/build/{types/types.d.ts → types.d.ts} +9 -2
  112. package/build/utils/QueryBus.d.ts +10 -0
  113. package/build/utils/async.d.ts +1 -0
  114. package/build/utils/calc.d.ts +52 -0
  115. package/build/utils/format.d.ts +11 -0
  116. package/build/utils/index.cjs +1 -0
  117. package/build/{types/utils → utils}/index.d.ts +3 -3
  118. package/build/utils/index.mjs +1 -0
  119. package/build/{types/utils → utils}/math.d.ts +0 -9
  120. package/package.json +70 -15
  121. package/build/types/api/Papi.d.ts +0 -375
  122. package/build/types/api/client.d.ts +0 -2
  123. package/build/types/api/index.d.ts +0 -2
  124. package/build/types/client/BalanceClient.d.ts +0 -17
  125. package/build/types/pool/PoolClient.d.ts +0 -25
  126. package/build/types/pool/PoolContextProvider.d.ts +0 -26
  127. package/build/types/pool/omni/OmniPoolClient.d.ts +0 -13
  128. package/build/types/pool/stable/StableSwapClient.d.ts +0 -16
  129. package/build/types/pool/xyk/XykPoolClient.d.ts +0 -12
  130. package/build/types/sor/TradeRouter.d.ts +0 -155
  131. package/build/types/sor/TradeUtils.d.ts +0 -12
  132. package/build/types/sor/index.d.ts +0 -4
  133. package/build/types/sor/route/suggester.d.ts +0 -24
  134. package/build/types/sor/types.d.ts +0 -31
  135. package/build/types/utils/big.d.ts +0 -3
  136. package/build/types/utils/evm.d.ts +0 -3
  137. package/build/types/utils/format.d.ts +0 -4
  138. package/build/types/utils/xc.d.ts +0 -1
  139. /package/build/{types/errors.d.ts → errors.d.ts} +0 -0
  140. /package/build/{types/pool → pool}/PoolFactory.d.ts +0 -0
  141. /package/build/{types/pool → pool}/lbp/LbpMath.d.ts +0 -0
  142. /package/build/{types/pool → pool}/lbp/index.d.ts +0 -0
  143. /package/build/{types/pool → pool}/omni/index.d.ts +0 -0
  144. /package/build/{types/pool → pool}/stable/index.d.ts +0 -0
  145. /package/build/{types/pool → pool}/xyk/XykMath.d.ts +0 -0
  146. /package/build/{types/pool → pool}/xyk/index.d.ts +0 -0
  147. /package/build/{types/sor → sor}/route/graph.d.ts +0 -0
  148. /package/build/{types/utils → utils}/Queue.d.ts +0 -0
  149. /package/build/{types/utils → utils}/Stack.d.ts +0 -0
  150. /package/build/{types/utils → utils}/json.d.ts +0 -0
  151. /package/build/{types/utils → utils}/traversal/bfs.d.ts +0 -0
@@ -0,0 +1,196 @@
1
+ export declare const AGGREGATOR_V3_ABI: readonly [{
2
+ readonly inputs: readonly [];
3
+ readonly name: "decimals";
4
+ readonly outputs: readonly [{
5
+ readonly internalType: "uint8";
6
+ readonly name: "";
7
+ readonly type: "uint8";
8
+ }];
9
+ readonly stateMutability: "view";
10
+ readonly type: "function";
11
+ }, {
12
+ readonly inputs: readonly [];
13
+ readonly name: "description";
14
+ readonly outputs: readonly [{
15
+ readonly internalType: "string";
16
+ readonly name: "";
17
+ readonly type: "string";
18
+ }];
19
+ readonly stateMutability: "view";
20
+ readonly type: "function";
21
+ }, {
22
+ readonly inputs: readonly [];
23
+ readonly name: "version";
24
+ readonly outputs: readonly [{
25
+ readonly internalType: "uint256";
26
+ readonly name: "";
27
+ readonly type: "uint256";
28
+ }];
29
+ readonly stateMutability: "view";
30
+ readonly type: "function";
31
+ }, {
32
+ readonly inputs: readonly [{
33
+ readonly internalType: "uint80";
34
+ readonly name: "_roundId";
35
+ readonly type: "uint80";
36
+ }];
37
+ readonly name: "getRoundData";
38
+ readonly outputs: readonly [{
39
+ readonly internalType: "uint80";
40
+ readonly name: "roundId";
41
+ readonly type: "uint80";
42
+ }, {
43
+ readonly internalType: "int256";
44
+ readonly name: "answer";
45
+ readonly type: "int256";
46
+ }, {
47
+ readonly internalType: "uint256";
48
+ readonly name: "startedAt";
49
+ readonly type: "uint256";
50
+ }, {
51
+ readonly internalType: "uint256";
52
+ readonly name: "updatedAt";
53
+ readonly type: "uint256";
54
+ }, {
55
+ readonly internalType: "uint80";
56
+ readonly name: "answeredInRound";
57
+ readonly type: "uint80";
58
+ }];
59
+ readonly stateMutability: "view";
60
+ readonly type: "function";
61
+ }, {
62
+ readonly inputs: readonly [];
63
+ readonly name: "latestRoundData";
64
+ readonly outputs: readonly [{
65
+ readonly internalType: "uint80";
66
+ readonly name: "roundId";
67
+ readonly type: "uint80";
68
+ }, {
69
+ readonly internalType: "int256";
70
+ readonly name: "answer";
71
+ readonly type: "int256";
72
+ }, {
73
+ readonly internalType: "uint256";
74
+ readonly name: "startedAt";
75
+ readonly type: "uint256";
76
+ }, {
77
+ readonly internalType: "uint256";
78
+ readonly name: "updatedAt";
79
+ readonly type: "uint256";
80
+ }, {
81
+ readonly internalType: "uint80";
82
+ readonly name: "answeredInRound";
83
+ readonly type: "uint80";
84
+ }];
85
+ readonly stateMutability: "view";
86
+ readonly type: "function";
87
+ }];
88
+ export declare const DIA_ORACLE_ABI: readonly [{
89
+ readonly inputs: readonly [];
90
+ readonly stateMutability: "nonpayable";
91
+ readonly type: "constructor";
92
+ }, {
93
+ readonly anonymous: false;
94
+ readonly inputs: readonly [{
95
+ readonly indexed: false;
96
+ readonly internalType: "string";
97
+ readonly name: "key";
98
+ readonly type: "string";
99
+ }, {
100
+ readonly indexed: false;
101
+ readonly internalType: "uint128";
102
+ readonly name: "value";
103
+ readonly type: "uint128";
104
+ }, {
105
+ readonly indexed: false;
106
+ readonly internalType: "uint128";
107
+ readonly name: "timestamp";
108
+ readonly type: "uint128";
109
+ }];
110
+ readonly name: "OracleUpdate";
111
+ readonly type: "event";
112
+ }, {
113
+ readonly anonymous: false;
114
+ readonly inputs: readonly [{
115
+ readonly indexed: false;
116
+ readonly internalType: "address";
117
+ readonly name: "newUpdater";
118
+ readonly type: "address";
119
+ }];
120
+ readonly name: "UpdaterAddressChange";
121
+ readonly type: "event";
122
+ }, {
123
+ readonly inputs: readonly [{
124
+ readonly internalType: "string";
125
+ readonly name: "key";
126
+ readonly type: "string";
127
+ }];
128
+ readonly name: "getValue";
129
+ readonly outputs: readonly [{
130
+ readonly internalType: "uint128";
131
+ readonly name: "";
132
+ readonly type: "uint128";
133
+ }, {
134
+ readonly internalType: "uint128";
135
+ readonly name: "";
136
+ readonly type: "uint128";
137
+ }];
138
+ readonly stateMutability: "view";
139
+ readonly type: "function";
140
+ }, {
141
+ readonly inputs: readonly [{
142
+ readonly internalType: "string[]";
143
+ readonly name: "keys";
144
+ readonly type: "string[]";
145
+ }, {
146
+ readonly internalType: "uint256[]";
147
+ readonly name: "compressedValues";
148
+ readonly type: "uint256[]";
149
+ }];
150
+ readonly name: "setMultipleValues";
151
+ readonly outputs: readonly [];
152
+ readonly stateMutability: "nonpayable";
153
+ readonly type: "function";
154
+ }, {
155
+ readonly inputs: readonly [{
156
+ readonly internalType: "string";
157
+ readonly name: "key";
158
+ readonly type: "string";
159
+ }, {
160
+ readonly internalType: "uint128";
161
+ readonly name: "value";
162
+ readonly type: "uint128";
163
+ }, {
164
+ readonly internalType: "uint128";
165
+ readonly name: "timestamp";
166
+ readonly type: "uint128";
167
+ }];
168
+ readonly name: "setValue";
169
+ readonly outputs: readonly [];
170
+ readonly stateMutability: "nonpayable";
171
+ readonly type: "function";
172
+ }, {
173
+ readonly inputs: readonly [{
174
+ readonly internalType: "address";
175
+ readonly name: "newOracleUpdaterAddress";
176
+ readonly type: "address";
177
+ }];
178
+ readonly name: "updateOracleUpdaterAddress";
179
+ readonly outputs: readonly [];
180
+ readonly stateMutability: "nonpayable";
181
+ readonly type: "function";
182
+ }, {
183
+ readonly inputs: readonly [{
184
+ readonly internalType: "string";
185
+ readonly name: "";
186
+ readonly type: "string";
187
+ }];
188
+ readonly name: "values";
189
+ readonly outputs: readonly [{
190
+ readonly internalType: "uint256";
191
+ readonly name: "";
192
+ readonly type: "uint256";
193
+ }];
194
+ readonly stateMutability: "view";
195
+ readonly type: "function";
196
+ }];
@@ -0,0 +1,3 @@
1
+ export { MmOracleClient } from './MmOracleClient';
2
+ export * from './abi';
3
+ export * from './types';
@@ -0,0 +1,5 @@
1
+ export type MmOracleEntry = {
2
+ price: bigint;
3
+ decimals: number;
4
+ updatedAt: number;
5
+ };
@@ -0,0 +1,75 @@
1
+ import { PolkadotClient } from 'polkadot-api';
2
+ import { Observable, OperatorFunction, Subscription } from 'rxjs';
3
+ import { Papi } from '../api';
4
+ import { BalanceClient } from '../client';
5
+ import { EvmClient } from '../evm';
6
+ import { PoolBase, PoolFees, PoolPair, PoolType } from './types';
7
+ import { PoolStore } from './PoolStore';
8
+ import { PoolLog } from './PoolLog';
9
+ export declare abstract class PoolClient<T extends PoolBase> extends Papi {
10
+ protected evm: EvmClient;
11
+ protected balance: BalanceClient;
12
+ protected store: PoolStore<T>;
13
+ protected log: PoolLog;
14
+ private shared$?;
15
+ private resync$;
16
+ private resyncAt;
17
+ private resyncPending;
18
+ private mem;
19
+ private memPoolsCache;
20
+ private memPools;
21
+ constructor(client: PolkadotClient, evm: EvmClient);
22
+ abstract isSupported(): Promise<boolean>;
23
+ abstract getPoolFees(pair: PoolPair, address: string): Promise<PoolFees>;
24
+ abstract getPoolType(): PoolType;
25
+ protected abstract loadPools(): Promise<T[]>;
26
+ protected abstract subscribeUpdates(): Subscription;
27
+ private getMemPools;
28
+ getPools(): Promise<T[]>;
29
+ getSubscriber(): Observable<T[]>;
30
+ private subscribeStore;
31
+ protected subscribeBalances(): Subscription;
32
+ protected hasSystemAsset(pool: T): boolean;
33
+ protected hasErc20Asset(pool: PoolBase): boolean;
34
+ private hasValidAssets;
35
+ private updateBalances;
36
+ /**
37
+ * Invalidates the current seed, tears down all active writers,
38
+ * and rebuilds the store from scratch.
39
+ *
40
+ * - Increments `mem` to bust memoized seeds
41
+ * - Emits on `resync$` to restart the active cycle
42
+ * - Rate-limited by default to avoid resync storms
43
+ * - Use `force` for fatal, state-corrupting errors
44
+ *
45
+ * @param force - bypass the resync throttle
46
+ */
47
+ private resync;
48
+ /**
49
+ * Schedules a resync on the next tick.
50
+ *
51
+ * - Ensures the current cycle tears down before resync
52
+ * - Dedup multiple requests occurring in the same tick
53
+ *
54
+ * @param force - forward the force flag to `resync`
55
+ */
56
+ private requestResync;
57
+ /**
58
+ * Starts the connection and block watchdog.
59
+ *
60
+ * - Triggers a resync on offline → online recovery
61
+ * - Triggers a resync on block gap
62
+ * - Errors are swallowed and the watchdog re-subscribes (`repeat`)
63
+ */
64
+ private startWatchdog;
65
+ /**
66
+ * Guards a watcher stream.
67
+ *
68
+ * - Logs any error and treats it as fatal
69
+ * - Schedules a forced resync
70
+ * - Outer re-sync cycle handles recovery
71
+ *
72
+ * @param tag - log prefix of the watcher
73
+ */
74
+ protected watchGuard<T>(tag: string): OperatorFunction<T, T>;
75
+ }
@@ -0,0 +1,41 @@
1
+ import { PolkadotClient } from 'polkadot-api';
2
+ import { Papi } from '../api';
3
+ import { EvmClient } from '../evm';
4
+ import { AavePoolClient } from './aave';
5
+ import { HsmPoolClient } from './hsm';
6
+ import { LbpPoolClient } from './lbp';
7
+ import { OmniPoolClient } from './omni';
8
+ import { XykPoolClient } from './xyk';
9
+ import { StableSwapClient } from './stable';
10
+ import { IPoolCtxProvider, Pool, PoolBase, PoolFees, PoolPair, PoolTokenOverride } from './types';
11
+ export declare class PoolContextProvider extends Papi implements IPoolCtxProvider {
12
+ readonly evm: EvmClient;
13
+ readonly aave: AavePoolClient;
14
+ readonly omnipool: OmniPoolClient;
15
+ readonly stableswap: StableSwapClient;
16
+ readonly hsm: HsmPoolClient;
17
+ readonly xyk: XykPoolClient;
18
+ readonly lbp: LbpPoolClient;
19
+ private readonly active;
20
+ private readonly pools;
21
+ private readonly clients;
22
+ private aaveSub;
23
+ private omniSub;
24
+ private stableSub;
25
+ private hsmSub;
26
+ private xykSub;
27
+ private lbpSub;
28
+ private isReady;
29
+ private isDestroyed;
30
+ constructor(client: PolkadotClient, evm: EvmClient);
31
+ private subscribe;
32
+ withAave(): this;
33
+ withOmnipool(): this;
34
+ withStableswap(): this;
35
+ withHsm(): this;
36
+ withXyk(override?: PoolTokenOverride[]): this;
37
+ withLbp(): this;
38
+ destroy(): void;
39
+ getPools(): Promise<PoolBase[]>;
40
+ getPoolFees(poolPair: PoolPair, pool: Pool): Promise<PoolFees>;
41
+ }
@@ -0,0 +1,11 @@
1
+ import { PoolType } from './types';
2
+ export declare class PoolLog {
3
+ private readonly type;
4
+ constructor(type: PoolType);
5
+ private prefix;
6
+ trace(label: string, ...args: any[]): void;
7
+ debug(label: string, ...args: any[]): void;
8
+ info(label: string, ...args: any[]): void;
9
+ error(label: string, ...args: any[]): void;
10
+ private pad;
11
+ }
@@ -0,0 +1,20 @@
1
+ import { Observable } from 'rxjs';
2
+ import { PoolBase } from './types';
3
+ export declare class PoolStore<T extends PoolBase> {
4
+ private store$;
5
+ private updateQueue;
6
+ private changeset;
7
+ get pools(): readonly T[];
8
+ asObservable(): Observable<T[]>;
9
+ applyChangeset(state: T[]): T[];
10
+ set(next: T[]): void;
11
+ /**
12
+ * Apply a batched mutation to the store.
13
+ *
14
+ * Updates are applied one at a time in call order (internally queued).
15
+ *
16
+ * @param patch - update callback
17
+ */
18
+ update(patch: (state: readonly T[]) => T[] | Promise<T[]>): void;
19
+ destroy(): void;
20
+ }
@@ -0,0 +1,126 @@
1
+ export declare const AAVE_ABI: readonly [{
2
+ readonly anonymous: false;
3
+ readonly inputs: readonly [{
4
+ readonly indexed: true;
5
+ readonly internalType: "address";
6
+ readonly name: "reserve";
7
+ readonly type: "address";
8
+ }, {
9
+ readonly indexed: false;
10
+ readonly internalType: "address";
11
+ readonly name: "user";
12
+ readonly type: "address";
13
+ }, {
14
+ readonly indexed: true;
15
+ readonly internalType: "address";
16
+ readonly name: "onBehalfOf";
17
+ readonly type: "address";
18
+ }, {
19
+ readonly indexed: false;
20
+ readonly internalType: "uint256";
21
+ readonly name: "amount";
22
+ readonly type: "uint256";
23
+ }, {
24
+ readonly indexed: true;
25
+ readonly internalType: "uint16";
26
+ readonly name: "referralCode";
27
+ readonly type: "uint16";
28
+ }];
29
+ readonly name: "Supply";
30
+ readonly type: "event";
31
+ }, {
32
+ readonly anonymous: false;
33
+ readonly inputs: readonly [{
34
+ readonly indexed: true;
35
+ readonly internalType: "address";
36
+ readonly name: "reserve";
37
+ readonly type: "address";
38
+ }, {
39
+ readonly indexed: true;
40
+ readonly internalType: "address";
41
+ readonly name: "user";
42
+ readonly type: "address";
43
+ }, {
44
+ readonly indexed: true;
45
+ readonly internalType: "address";
46
+ readonly name: "to";
47
+ readonly type: "address";
48
+ }, {
49
+ readonly indexed: false;
50
+ readonly internalType: "uint256";
51
+ readonly name: "amount";
52
+ readonly type: "uint256";
53
+ }];
54
+ readonly name: "Withdraw";
55
+ readonly type: "event";
56
+ }, {
57
+ readonly anonymous: false;
58
+ readonly inputs: readonly [{
59
+ readonly indexed: true;
60
+ readonly internalType: "address";
61
+ readonly name: "reserve";
62
+ readonly type: "address";
63
+ }, {
64
+ readonly indexed: false;
65
+ readonly internalType: "address";
66
+ readonly name: "user";
67
+ readonly type: "address";
68
+ }, {
69
+ readonly indexed: true;
70
+ readonly internalType: "address";
71
+ readonly name: "onBehalfOf";
72
+ readonly type: "address";
73
+ }, {
74
+ readonly indexed: false;
75
+ readonly internalType: "uint256";
76
+ readonly name: "amount";
77
+ readonly type: "uint256";
78
+ }, {
79
+ readonly indexed: false;
80
+ readonly internalType: "enum DataTypes.InterestRateMode";
81
+ readonly name: "interestRateMode";
82
+ readonly type: "uint8";
83
+ }, {
84
+ readonly indexed: false;
85
+ readonly internalType: "uint256";
86
+ readonly name: "borrowRate";
87
+ readonly type: "uint256";
88
+ }, {
89
+ readonly indexed: true;
90
+ readonly internalType: "uint16";
91
+ readonly name: "referralCode";
92
+ readonly type: "uint16";
93
+ }];
94
+ readonly name: "Borrow";
95
+ readonly type: "event";
96
+ }, {
97
+ readonly anonymous: false;
98
+ readonly inputs: readonly [{
99
+ readonly indexed: true;
100
+ readonly internalType: "address";
101
+ readonly name: "reserve";
102
+ readonly type: "address";
103
+ }, {
104
+ readonly indexed: true;
105
+ readonly internalType: "address";
106
+ readonly name: "user";
107
+ readonly type: "address";
108
+ }, {
109
+ readonly indexed: true;
110
+ readonly internalType: "address";
111
+ readonly name: "repayer";
112
+ readonly type: "address";
113
+ }, {
114
+ readonly indexed: false;
115
+ readonly internalType: "uint256";
116
+ readonly name: "amount";
117
+ readonly type: "uint256";
118
+ }, {
119
+ readonly indexed: false;
120
+ readonly internalType: "bool";
121
+ readonly name: "useATokens";
122
+ readonly type: "bool";
123
+ }];
124
+ readonly name: "Repay";
125
+ readonly type: "event";
126
+ }];
@@ -0,0 +1,24 @@
1
+ import { BuyCtx, Pool, PoolBase, PoolFees, PoolPair, PoolToken, PoolType, SellCtx } from '../types';
2
+ import { XcmV3Multilocation } from '../../types';
3
+ export type AavePoolToken = PoolToken & {
4
+ location: XcmV3Multilocation;
5
+ };
6
+ export declare class AavePool implements Pool {
7
+ type: PoolType;
8
+ address: string;
9
+ tokens: AavePoolToken[];
10
+ maxInRatio: bigint;
11
+ maxOutRatio: bigint;
12
+ minTradingLimit: bigint;
13
+ static fromPool(pool: PoolBase): AavePool;
14
+ constructor(pool: PoolBase);
15
+ validatePair(_tokenIn: number, _tokenOut: number): boolean;
16
+ parsePair(tokenIn: number, tokenOut: number): PoolPair;
17
+ validateAndBuy(poolPair: PoolPair, amountOut: bigint, _fees: PoolFees): BuyCtx;
18
+ validateAndSell(poolPair: PoolPair, amountIn: bigint, _fees: PoolFees): SellCtx;
19
+ calculateInGivenOut(_poolPair: PoolPair, amountOut: bigint): bigint;
20
+ calculateOutGivenIn(_poolPair: PoolPair, amountIn: bigint): bigint;
21
+ spotPriceInGivenOut(_poolPair: PoolPair): bigint;
22
+ spotPriceOutGivenIn(_poolPair: PoolPair): bigint;
23
+ calculateTradeFee(_amount: bigint, _fees: PoolFees): bigint;
24
+ }
@@ -0,0 +1,19 @@
1
+ import { Subscription } from 'rxjs';
2
+ import { PoolBase, PoolFees, PoolType } from '../types';
3
+ import { PoolClient } from '../PoolClient';
4
+ export declare class AavePoolClient extends PoolClient<PoolBase> {
5
+ getPoolType(): PoolType;
6
+ isSupported(): Promise<boolean>;
7
+ private getPoolId;
8
+ private getPoolLimits;
9
+ loadPools(): Promise<PoolBase[]>;
10
+ private getPoolDelta;
11
+ getPoolFees(): Promise<PoolFees>;
12
+ private getReserveH160Id;
13
+ private parseRouterLog;
14
+ private parseEvmLog;
15
+ private subscribeRouterExecuted;
16
+ private subscribeEvmLog;
17
+ protected subscribeBalances(): Subscription;
18
+ protected subscribeUpdates(): Subscription;
19
+ }
@@ -0,0 +1,2 @@
1
+ export * from './AavePool';
2
+ export * from './AavePoolClient';
@@ -0,0 +1,13 @@
1
+ import { HydrationEvents } from '@galacticcouncil/descriptors';
2
+ export type TEvmPayload = HydrationEvents['EVM']['Log'];
3
+ export type TEvmEvent = {
4
+ eventName: string;
5
+ reserve: string;
6
+ key: string;
7
+ };
8
+ export type TRouterExecutedPayload = HydrationEvents['Router']['Executed'];
9
+ export type TRouterEvent = {
10
+ assetIn: number;
11
+ assetOut: number;
12
+ key: string;
13
+ };
@@ -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,63 @@
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, 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
+ /**
52
+ * Normalize spot to runtime decimals.
53
+ *
54
+ * - if `decimalsIn === decimalsOut`: spot already 18dp
55
+ * - if `decimalsIn > decimalsOut`: spot in 18 - (decimalsIn - decimalsOut)
56
+ * - if `decimalsIn < decimalsOut`: spot in 18 + (decimalsOut - decimalsIn)
57
+ *
58
+ * @param spotRaw - raw spot
59
+ * @param decimalsIn - asset in decimals
60
+ * @param decimalsOut - asset out decimals
61
+ */
62
+ private normalizeSpotPrice;
63
+ }
@@ -0,0 +1,26 @@
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
+ private subscribeCollateralBalance;
23
+ private subscribeStableswapUpdates;
24
+ protected subscribeBalances(): Subscription;
25
+ protected subscribeUpdates(): Subscription;
26
+ }
@@ -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
+ };