@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.
- package/README.md +131 -78
- package/build/aave/AaveClient.d.ts +77 -0
- package/build/aave/AaveUtils.d.ts +78 -0
- package/build/aave/abi/AavePool.d.ts +208 -0
- package/build/aave/abi/AavePoolDataProvider.d.ts +384 -0
- package/build/aave/abi/index.d.ts +2 -0
- package/build/aave/const.d.ts +6 -0
- package/build/aave/index.cjs +1 -0
- package/build/aave/index.d.ts +4 -0
- package/build/aave/index.mjs +1 -0
- package/build/aave/types.d.ts +17 -0
- package/build/api/Papi.d.ts +10 -0
- package/build/api/Watcher.d.ts +11 -0
- package/build/api/index.d.ts +3 -0
- package/build/api/probe.d.ts +26 -0
- package/build/api/provider/index.d.ts +2 -0
- package/build/api/provider/smoldot.d.ts +1 -0
- package/build/api/provider/websocket.d.ts +4 -0
- package/build/{types/client → client}/AssetClient.d.ts +1 -1
- package/build/client/BalanceClient.d.ts +20 -0
- package/build/client/ChainParams.d.ts +9 -0
- package/build/client/index.cjs +1 -0
- package/build/{types/client → client}/index.d.ts +1 -0
- package/build/client/index.mjs +1 -0
- package/build/{types/consts.d.ts → consts.d.ts} +2 -2
- package/build/evm/adapter.d.ts +11 -0
- package/build/evm/chain.d.ts +2 -0
- package/build/evm/client.d.ts +15 -0
- package/build/evm/index.cjs +1 -0
- package/build/evm/index.d.ts +4 -0
- package/build/evm/index.mjs +1 -0
- package/build/evm/types.d.ts +7 -0
- package/build/factory.d.ts +29 -0
- package/build/farm/LiquidityMiningApi.d.ts +29 -0
- package/build/farm/LiquidityMiningClient.d.ts +146 -0
- package/build/farm/MultiCurrencyContainer.d.ts +8 -0
- package/build/farm/RewardClaimSimulator.d.ts +16 -0
- package/build/farm/const.d.ts +4 -0
- package/build/farm/index.cjs +1 -0
- package/build/farm/index.d.ts +3 -0
- package/build/farm/index.mjs +1 -0
- package/build/farm/types.d.ts +46 -0
- package/build/gho/GhoTokenClient.d.ts +6 -0
- package/build/gho/abi.d.ts +124 -0
- package/build/gho/index.d.ts +2 -0
- package/build/index.cjs +1 -1
- package/build/{types/index.d.ts → index.d.ts} +6 -0
- package/build/index.mjs +1 -1
- package/build/oracle/MmOracleClient.d.ts +7 -0
- package/build/oracle/abi.d.ts +196 -0
- package/build/oracle/index.d.ts +3 -0
- package/build/oracle/types.d.ts +5 -0
- package/build/pool/PoolClient.d.ts +75 -0
- package/build/pool/PoolContextProvider.d.ts +41 -0
- package/build/pool/PoolLog.d.ts +11 -0
- package/build/pool/PoolStore.d.ts +20 -0
- package/build/pool/aave/AaveAbi.d.ts +126 -0
- package/build/pool/aave/AavePool.d.ts +24 -0
- package/build/pool/aave/AavePoolClient.d.ts +19 -0
- package/build/pool/aave/index.d.ts +2 -0
- package/build/pool/aave/types.d.ts +13 -0
- package/build/pool/hsm/HsmMath.d.ts +21 -0
- package/build/pool/hsm/HsmPool.d.ts +63 -0
- package/build/pool/hsm/HsmPoolClient.d.ts +26 -0
- package/build/pool/hsm/index.d.ts +3 -0
- package/build/pool/hsm/types.d.ts +7 -0
- package/build/pool/index.cjs +1 -0
- package/build/{types/pool → pool}/index.d.ts +4 -2
- package/build/pool/index.mjs +1 -0
- package/build/{types/pool → pool}/lbp/LbpPool.d.ts +1 -1
- package/build/{types/pool → pool}/lbp/LbpPoolClient.d.ts +9 -7
- package/build/{types/pool → pool}/omni/OmniMath.d.ts +7 -6
- package/build/{types/pool → pool}/omni/OmniPool.d.ts +14 -1
- package/build/pool/omni/OmniPoolClient.d.ts +29 -0
- package/build/pool/omni/types.d.ts +11 -0
- package/build/{types/pool → pool}/stable/StableMath.d.ts +1 -2
- package/build/{types/pool → pool}/stable/StableSwap.d.ts +21 -4
- package/build/pool/stable/StableSwapClient.d.ts +23 -0
- package/build/pool/stable/types.d.ts +15 -0
- package/build/{types/pool → pool}/types.d.ts +14 -3
- package/build/{types/pool → pool}/xyk/XykPool.d.ts +13 -1
- package/build/pool/xyk/XykPoolClient.d.ts +14 -0
- package/build/{types/sor → sor}/Router.d.ts +26 -8
- package/build/sor/TradeRouteBuilder.d.ts +4 -0
- package/build/sor/TradeRouter.d.ts +207 -0
- package/build/sor/TradeScheduler.d.ts +111 -0
- package/build/sor/const.d.ts +8 -0
- package/build/sor/index.cjs +1 -0
- package/build/sor/index.d.ts +6 -0
- package/build/sor/index.mjs +1 -0
- package/build/{types/sor → sor}/route/bfs.d.ts +11 -2
- package/build/{types/sor → sor}/route/index.d.ts +1 -1
- package/build/sor/route/suggester.d.ts +33 -0
- package/build/sor/types.d.ts +68 -0
- package/build/staking/StakingApi.d.ts +66 -0
- package/build/staking/StakingClient.d.ts +132 -0
- package/build/staking/index.cjs +1 -0
- package/build/staking/index.d.ts +2 -0
- package/build/staking/index.mjs +1 -0
- package/build/staking/types.d.ts +16 -0
- package/build/staking/utils.d.ts +1 -0
- package/build/tx/OrderTxBuilder.d.ts +21 -0
- package/build/tx/TradeTxBuilder.d.ts +18 -0
- package/build/tx/TxBuilder.d.ts +19 -0
- package/build/tx/TxBuilderFactory.d.ts +12 -0
- package/build/tx/index.cjs +1 -0
- package/build/tx/index.d.ts +2 -0
- package/build/tx/index.mjs +1 -0
- package/build/tx/types.d.ts +10 -0
- package/build/tx/utils.d.ts +5 -0
- package/build/{types/types.d.ts → types.d.ts} +9 -2
- package/build/utils/QueryBus.d.ts +10 -0
- package/build/utils/async.d.ts +1 -0
- package/build/utils/calc.d.ts +52 -0
- package/build/utils/format.d.ts +11 -0
- package/build/utils/index.cjs +1 -0
- package/build/{types/utils → utils}/index.d.ts +3 -3
- package/build/utils/index.mjs +1 -0
- package/build/{types/utils → utils}/math.d.ts +0 -9
- package/package.json +70 -15
- package/build/types/api/Papi.d.ts +0 -375
- package/build/types/api/client.d.ts +0 -2
- package/build/types/api/index.d.ts +0 -2
- package/build/types/client/BalanceClient.d.ts +0 -17
- package/build/types/pool/PoolClient.d.ts +0 -25
- package/build/types/pool/PoolContextProvider.d.ts +0 -26
- package/build/types/pool/omni/OmniPoolClient.d.ts +0 -13
- package/build/types/pool/stable/StableSwapClient.d.ts +0 -16
- package/build/types/pool/xyk/XykPoolClient.d.ts +0 -12
- package/build/types/sor/TradeRouter.d.ts +0 -155
- package/build/types/sor/TradeUtils.d.ts +0 -12
- package/build/types/sor/index.d.ts +0 -4
- package/build/types/sor/route/suggester.d.ts +0 -24
- package/build/types/sor/types.d.ts +0 -31
- package/build/types/utils/big.d.ts +0 -3
- package/build/types/utils/evm.d.ts +0 -3
- package/build/types/utils/format.d.ts +0 -4
- package/build/types/utils/xc.d.ts +0 -1
- /package/build/{types/errors.d.ts → errors.d.ts} +0 -0
- /package/build/{types/pool → pool}/PoolFactory.d.ts +0 -0
- /package/build/{types/pool → pool}/lbp/LbpMath.d.ts +0 -0
- /package/build/{types/pool → pool}/lbp/index.d.ts +0 -0
- /package/build/{types/pool → pool}/omni/index.d.ts +0 -0
- /package/build/{types/pool → pool}/stable/index.d.ts +0 -0
- /package/build/{types/pool → pool}/xyk/XykMath.d.ts +0 -0
- /package/build/{types/pool → pool}/xyk/index.d.ts +0 -0
- /package/build/{types/sor → sor}/route/graph.d.ts +0 -0
- /package/build/{types/utils → utils}/Queue.d.ts +0 -0
- /package/build/{types/utils → utils}/Stack.d.ts +0 -0
- /package/build/{types/utils → utils}/json.d.ts +0 -0
- /package/build/{types/utils → utils}/traversal/bfs.d.ts +0 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
export declare const AAVE_POOL_DATA_PROVIDER_ABI: readonly [{
|
|
2
|
+
readonly inputs: readonly [{
|
|
3
|
+
readonly internalType: "contract IEACAggregatorProxy";
|
|
4
|
+
readonly name: "_networkBaseTokenPriceInUsdProxyAggregator";
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
}, {
|
|
7
|
+
readonly internalType: "contract IEACAggregatorProxy";
|
|
8
|
+
readonly name: "_marketReferenceCurrencyPriceInUsdProxyAggregator";
|
|
9
|
+
readonly type: "address";
|
|
10
|
+
}];
|
|
11
|
+
readonly stateMutability: "nonpayable";
|
|
12
|
+
readonly type: "constructor";
|
|
13
|
+
}, {
|
|
14
|
+
readonly inputs: readonly [];
|
|
15
|
+
readonly name: "ETH_CURRENCY_UNIT";
|
|
16
|
+
readonly outputs: readonly [{
|
|
17
|
+
readonly internalType: "uint256";
|
|
18
|
+
readonly name: "";
|
|
19
|
+
readonly type: "uint256";
|
|
20
|
+
}];
|
|
21
|
+
readonly stateMutability: "view";
|
|
22
|
+
readonly type: "function";
|
|
23
|
+
}, {
|
|
24
|
+
readonly inputs: readonly [];
|
|
25
|
+
readonly name: "MKR_ADDRESS";
|
|
26
|
+
readonly outputs: readonly [{
|
|
27
|
+
readonly internalType: "address";
|
|
28
|
+
readonly name: "";
|
|
29
|
+
readonly type: "address";
|
|
30
|
+
}];
|
|
31
|
+
readonly stateMutability: "view";
|
|
32
|
+
readonly type: "function";
|
|
33
|
+
}, {
|
|
34
|
+
readonly inputs: readonly [{
|
|
35
|
+
readonly internalType: "bytes32";
|
|
36
|
+
readonly name: "_bytes32";
|
|
37
|
+
readonly type: "bytes32";
|
|
38
|
+
}];
|
|
39
|
+
readonly name: "bytes32ToString";
|
|
40
|
+
readonly outputs: readonly [{
|
|
41
|
+
readonly internalType: "string";
|
|
42
|
+
readonly name: "";
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
}];
|
|
45
|
+
readonly stateMutability: "pure";
|
|
46
|
+
readonly type: "function";
|
|
47
|
+
}, {
|
|
48
|
+
readonly inputs: readonly [{
|
|
49
|
+
readonly internalType: "contract IPoolAddressesProvider";
|
|
50
|
+
readonly name: "provider";
|
|
51
|
+
readonly type: "address";
|
|
52
|
+
}];
|
|
53
|
+
readonly name: "getReservesData";
|
|
54
|
+
readonly outputs: readonly [{
|
|
55
|
+
readonly components: readonly [{
|
|
56
|
+
readonly internalType: "address";
|
|
57
|
+
readonly name: "underlyingAsset";
|
|
58
|
+
readonly type: "address";
|
|
59
|
+
}, {
|
|
60
|
+
readonly internalType: "string";
|
|
61
|
+
readonly name: "name";
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
}, {
|
|
64
|
+
readonly internalType: "string";
|
|
65
|
+
readonly name: "symbol";
|
|
66
|
+
readonly type: "string";
|
|
67
|
+
}, {
|
|
68
|
+
readonly internalType: "uint256";
|
|
69
|
+
readonly name: "decimals";
|
|
70
|
+
readonly type: "uint256";
|
|
71
|
+
}, {
|
|
72
|
+
readonly internalType: "uint256";
|
|
73
|
+
readonly name: "baseLTVasCollateral";
|
|
74
|
+
readonly type: "uint256";
|
|
75
|
+
}, {
|
|
76
|
+
readonly internalType: "uint256";
|
|
77
|
+
readonly name: "reserveLiquidationThreshold";
|
|
78
|
+
readonly type: "uint256";
|
|
79
|
+
}, {
|
|
80
|
+
readonly internalType: "uint256";
|
|
81
|
+
readonly name: "reserveLiquidationBonus";
|
|
82
|
+
readonly type: "uint256";
|
|
83
|
+
}, {
|
|
84
|
+
readonly internalType: "uint256";
|
|
85
|
+
readonly name: "reserveFactor";
|
|
86
|
+
readonly type: "uint256";
|
|
87
|
+
}, {
|
|
88
|
+
readonly internalType: "bool";
|
|
89
|
+
readonly name: "usageAsCollateralEnabled";
|
|
90
|
+
readonly type: "bool";
|
|
91
|
+
}, {
|
|
92
|
+
readonly internalType: "bool";
|
|
93
|
+
readonly name: "borrowingEnabled";
|
|
94
|
+
readonly type: "bool";
|
|
95
|
+
}, {
|
|
96
|
+
readonly internalType: "bool";
|
|
97
|
+
readonly name: "stableBorrowRateEnabled";
|
|
98
|
+
readonly type: "bool";
|
|
99
|
+
}, {
|
|
100
|
+
readonly internalType: "bool";
|
|
101
|
+
readonly name: "isActive";
|
|
102
|
+
readonly type: "bool";
|
|
103
|
+
}, {
|
|
104
|
+
readonly internalType: "bool";
|
|
105
|
+
readonly name: "isFrozen";
|
|
106
|
+
readonly type: "bool";
|
|
107
|
+
}, {
|
|
108
|
+
readonly internalType: "uint128";
|
|
109
|
+
readonly name: "liquidityIndex";
|
|
110
|
+
readonly type: "uint128";
|
|
111
|
+
}, {
|
|
112
|
+
readonly internalType: "uint128";
|
|
113
|
+
readonly name: "variableBorrowIndex";
|
|
114
|
+
readonly type: "uint128";
|
|
115
|
+
}, {
|
|
116
|
+
readonly internalType: "uint128";
|
|
117
|
+
readonly name: "liquidityRate";
|
|
118
|
+
readonly type: "uint128";
|
|
119
|
+
}, {
|
|
120
|
+
readonly internalType: "uint128";
|
|
121
|
+
readonly name: "variableBorrowRate";
|
|
122
|
+
readonly type: "uint128";
|
|
123
|
+
}, {
|
|
124
|
+
readonly internalType: "uint128";
|
|
125
|
+
readonly name: "stableBorrowRate";
|
|
126
|
+
readonly type: "uint128";
|
|
127
|
+
}, {
|
|
128
|
+
readonly internalType: "uint40";
|
|
129
|
+
readonly name: "lastUpdateTimestamp";
|
|
130
|
+
readonly type: "uint40";
|
|
131
|
+
}, {
|
|
132
|
+
readonly internalType: "address";
|
|
133
|
+
readonly name: "aTokenAddress";
|
|
134
|
+
readonly type: "address";
|
|
135
|
+
}, {
|
|
136
|
+
readonly internalType: "address";
|
|
137
|
+
readonly name: "stableDebtTokenAddress";
|
|
138
|
+
readonly type: "address";
|
|
139
|
+
}, {
|
|
140
|
+
readonly internalType: "address";
|
|
141
|
+
readonly name: "variableDebtTokenAddress";
|
|
142
|
+
readonly type: "address";
|
|
143
|
+
}, {
|
|
144
|
+
readonly internalType: "address";
|
|
145
|
+
readonly name: "interestRateStrategyAddress";
|
|
146
|
+
readonly type: "address";
|
|
147
|
+
}, {
|
|
148
|
+
readonly internalType: "uint256";
|
|
149
|
+
readonly name: "availableLiquidity";
|
|
150
|
+
readonly type: "uint256";
|
|
151
|
+
}, {
|
|
152
|
+
readonly internalType: "uint256";
|
|
153
|
+
readonly name: "totalPrincipalStableDebt";
|
|
154
|
+
readonly type: "uint256";
|
|
155
|
+
}, {
|
|
156
|
+
readonly internalType: "uint256";
|
|
157
|
+
readonly name: "averageStableRate";
|
|
158
|
+
readonly type: "uint256";
|
|
159
|
+
}, {
|
|
160
|
+
readonly internalType: "uint256";
|
|
161
|
+
readonly name: "stableDebtLastUpdateTimestamp";
|
|
162
|
+
readonly type: "uint256";
|
|
163
|
+
}, {
|
|
164
|
+
readonly internalType: "uint256";
|
|
165
|
+
readonly name: "totalScaledVariableDebt";
|
|
166
|
+
readonly type: "uint256";
|
|
167
|
+
}, {
|
|
168
|
+
readonly internalType: "uint256";
|
|
169
|
+
readonly name: "priceInMarketReferenceCurrency";
|
|
170
|
+
readonly type: "uint256";
|
|
171
|
+
}, {
|
|
172
|
+
readonly internalType: "address";
|
|
173
|
+
readonly name: "priceOracle";
|
|
174
|
+
readonly type: "address";
|
|
175
|
+
}, {
|
|
176
|
+
readonly internalType: "uint256";
|
|
177
|
+
readonly name: "variableRateSlope1";
|
|
178
|
+
readonly type: "uint256";
|
|
179
|
+
}, {
|
|
180
|
+
readonly internalType: "uint256";
|
|
181
|
+
readonly name: "variableRateSlope2";
|
|
182
|
+
readonly type: "uint256";
|
|
183
|
+
}, {
|
|
184
|
+
readonly internalType: "uint256";
|
|
185
|
+
readonly name: "stableRateSlope1";
|
|
186
|
+
readonly type: "uint256";
|
|
187
|
+
}, {
|
|
188
|
+
readonly internalType: "uint256";
|
|
189
|
+
readonly name: "stableRateSlope2";
|
|
190
|
+
readonly type: "uint256";
|
|
191
|
+
}, {
|
|
192
|
+
readonly internalType: "uint256";
|
|
193
|
+
readonly name: "baseStableBorrowRate";
|
|
194
|
+
readonly type: "uint256";
|
|
195
|
+
}, {
|
|
196
|
+
readonly internalType: "uint256";
|
|
197
|
+
readonly name: "baseVariableBorrowRate";
|
|
198
|
+
readonly type: "uint256";
|
|
199
|
+
}, {
|
|
200
|
+
readonly internalType: "uint256";
|
|
201
|
+
readonly name: "optimalUsageRatio";
|
|
202
|
+
readonly type: "uint256";
|
|
203
|
+
}, {
|
|
204
|
+
readonly internalType: "bool";
|
|
205
|
+
readonly name: "isPaused";
|
|
206
|
+
readonly type: "bool";
|
|
207
|
+
}, {
|
|
208
|
+
readonly internalType: "bool";
|
|
209
|
+
readonly name: "isSiloedBorrowing";
|
|
210
|
+
readonly type: "bool";
|
|
211
|
+
}, {
|
|
212
|
+
readonly internalType: "uint128";
|
|
213
|
+
readonly name: "accruedToTreasury";
|
|
214
|
+
readonly type: "uint128";
|
|
215
|
+
}, {
|
|
216
|
+
readonly internalType: "uint128";
|
|
217
|
+
readonly name: "unbacked";
|
|
218
|
+
readonly type: "uint128";
|
|
219
|
+
}, {
|
|
220
|
+
readonly internalType: "uint128";
|
|
221
|
+
readonly name: "isolationModeTotalDebt";
|
|
222
|
+
readonly type: "uint128";
|
|
223
|
+
}, {
|
|
224
|
+
readonly internalType: "bool";
|
|
225
|
+
readonly name: "flashLoanEnabled";
|
|
226
|
+
readonly type: "bool";
|
|
227
|
+
}, {
|
|
228
|
+
readonly internalType: "uint256";
|
|
229
|
+
readonly name: "debtCeiling";
|
|
230
|
+
readonly type: "uint256";
|
|
231
|
+
}, {
|
|
232
|
+
readonly internalType: "uint256";
|
|
233
|
+
readonly name: "debtCeilingDecimals";
|
|
234
|
+
readonly type: "uint256";
|
|
235
|
+
}, {
|
|
236
|
+
readonly internalType: "uint8";
|
|
237
|
+
readonly name: "eModeCategoryId";
|
|
238
|
+
readonly type: "uint8";
|
|
239
|
+
}, {
|
|
240
|
+
readonly internalType: "uint256";
|
|
241
|
+
readonly name: "borrowCap";
|
|
242
|
+
readonly type: "uint256";
|
|
243
|
+
}, {
|
|
244
|
+
readonly internalType: "uint256";
|
|
245
|
+
readonly name: "supplyCap";
|
|
246
|
+
readonly type: "uint256";
|
|
247
|
+
}, {
|
|
248
|
+
readonly internalType: "uint16";
|
|
249
|
+
readonly name: "eModeLtv";
|
|
250
|
+
readonly type: "uint16";
|
|
251
|
+
}, {
|
|
252
|
+
readonly internalType: "uint16";
|
|
253
|
+
readonly name: "eModeLiquidationThreshold";
|
|
254
|
+
readonly type: "uint16";
|
|
255
|
+
}, {
|
|
256
|
+
readonly internalType: "uint16";
|
|
257
|
+
readonly name: "eModeLiquidationBonus";
|
|
258
|
+
readonly type: "uint16";
|
|
259
|
+
}, {
|
|
260
|
+
readonly internalType: "address";
|
|
261
|
+
readonly name: "eModePriceSource";
|
|
262
|
+
readonly type: "address";
|
|
263
|
+
}, {
|
|
264
|
+
readonly internalType: "string";
|
|
265
|
+
readonly name: "eModeLabel";
|
|
266
|
+
readonly type: "string";
|
|
267
|
+
}, {
|
|
268
|
+
readonly internalType: "bool";
|
|
269
|
+
readonly name: "borrowableInIsolation";
|
|
270
|
+
readonly type: "bool";
|
|
271
|
+
}];
|
|
272
|
+
readonly internalType: "struct IUiPoolDataProviderV3.AggregatedReserveData[]";
|
|
273
|
+
readonly name: "";
|
|
274
|
+
readonly type: "tuple[]";
|
|
275
|
+
}, {
|
|
276
|
+
readonly components: readonly [{
|
|
277
|
+
readonly internalType: "uint256";
|
|
278
|
+
readonly name: "marketReferenceCurrencyUnit";
|
|
279
|
+
readonly type: "uint256";
|
|
280
|
+
}, {
|
|
281
|
+
readonly internalType: "int256";
|
|
282
|
+
readonly name: "marketReferenceCurrencyPriceInUsd";
|
|
283
|
+
readonly type: "int256";
|
|
284
|
+
}, {
|
|
285
|
+
readonly internalType: "int256";
|
|
286
|
+
readonly name: "networkBaseTokenPriceInUsd";
|
|
287
|
+
readonly type: "int256";
|
|
288
|
+
}, {
|
|
289
|
+
readonly internalType: "uint8";
|
|
290
|
+
readonly name: "networkBaseTokenPriceDecimals";
|
|
291
|
+
readonly type: "uint8";
|
|
292
|
+
}];
|
|
293
|
+
readonly internalType: "struct IUiPoolDataProviderV3.BaseCurrencyInfo";
|
|
294
|
+
readonly name: "";
|
|
295
|
+
readonly type: "tuple";
|
|
296
|
+
}];
|
|
297
|
+
readonly stateMutability: "view";
|
|
298
|
+
readonly type: "function";
|
|
299
|
+
}, {
|
|
300
|
+
readonly inputs: readonly [{
|
|
301
|
+
readonly internalType: "contract IPoolAddressesProvider";
|
|
302
|
+
readonly name: "provider";
|
|
303
|
+
readonly type: "address";
|
|
304
|
+
}];
|
|
305
|
+
readonly name: "getReservesList";
|
|
306
|
+
readonly outputs: readonly [{
|
|
307
|
+
readonly internalType: "address[]";
|
|
308
|
+
readonly name: "";
|
|
309
|
+
readonly type: "address[]";
|
|
310
|
+
}];
|
|
311
|
+
readonly stateMutability: "view";
|
|
312
|
+
readonly type: "function";
|
|
313
|
+
}, {
|
|
314
|
+
readonly inputs: readonly [{
|
|
315
|
+
readonly internalType: "contract IPoolAddressesProvider";
|
|
316
|
+
readonly name: "provider";
|
|
317
|
+
readonly type: "address";
|
|
318
|
+
}, {
|
|
319
|
+
readonly internalType: "address";
|
|
320
|
+
readonly name: "user";
|
|
321
|
+
readonly type: "address";
|
|
322
|
+
}];
|
|
323
|
+
readonly name: "getUserReservesData";
|
|
324
|
+
readonly outputs: readonly [{
|
|
325
|
+
readonly components: readonly [{
|
|
326
|
+
readonly internalType: "address";
|
|
327
|
+
readonly name: "underlyingAsset";
|
|
328
|
+
readonly type: "address";
|
|
329
|
+
}, {
|
|
330
|
+
readonly internalType: "uint256";
|
|
331
|
+
readonly name: "scaledATokenBalance";
|
|
332
|
+
readonly type: "uint256";
|
|
333
|
+
}, {
|
|
334
|
+
readonly internalType: "bool";
|
|
335
|
+
readonly name: "usageAsCollateralEnabledOnUser";
|
|
336
|
+
readonly type: "bool";
|
|
337
|
+
}, {
|
|
338
|
+
readonly internalType: "uint256";
|
|
339
|
+
readonly name: "stableBorrowRate";
|
|
340
|
+
readonly type: "uint256";
|
|
341
|
+
}, {
|
|
342
|
+
readonly internalType: "uint256";
|
|
343
|
+
readonly name: "scaledVariableDebt";
|
|
344
|
+
readonly type: "uint256";
|
|
345
|
+
}, {
|
|
346
|
+
readonly internalType: "uint256";
|
|
347
|
+
readonly name: "principalStableDebt";
|
|
348
|
+
readonly type: "uint256";
|
|
349
|
+
}, {
|
|
350
|
+
readonly internalType: "uint256";
|
|
351
|
+
readonly name: "stableBorrowLastUpdateTimestamp";
|
|
352
|
+
readonly type: "uint256";
|
|
353
|
+
}];
|
|
354
|
+
readonly internalType: "struct IUiPoolDataProviderV3.UserReserveData[]";
|
|
355
|
+
readonly name: "";
|
|
356
|
+
readonly type: "tuple[]";
|
|
357
|
+
}, {
|
|
358
|
+
readonly internalType: "uint8";
|
|
359
|
+
readonly name: "";
|
|
360
|
+
readonly type: "uint8";
|
|
361
|
+
}];
|
|
362
|
+
readonly stateMutability: "view";
|
|
363
|
+
readonly type: "function";
|
|
364
|
+
}, {
|
|
365
|
+
readonly inputs: readonly [];
|
|
366
|
+
readonly name: "marketReferenceCurrencyPriceInUsdProxyAggregator";
|
|
367
|
+
readonly outputs: readonly [{
|
|
368
|
+
readonly internalType: "contract IEACAggregatorProxy";
|
|
369
|
+
readonly name: "";
|
|
370
|
+
readonly type: "address";
|
|
371
|
+
}];
|
|
372
|
+
readonly stateMutability: "view";
|
|
373
|
+
readonly type: "function";
|
|
374
|
+
}, {
|
|
375
|
+
readonly inputs: readonly [];
|
|
376
|
+
readonly name: "networkBaseTokenPriceInUsdProxyAggregator";
|
|
377
|
+
readonly outputs: readonly [{
|
|
378
|
+
readonly internalType: "contract IEACAggregatorProxy";
|
|
379
|
+
readonly name: "";
|
|
380
|
+
readonly type: "address";
|
|
381
|
+
}];
|
|
382
|
+
readonly stateMutability: "view";
|
|
383
|
+
readonly type: "function";
|
|
384
|
+
}];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const AAVE_POOL_PROXY = "0x1b02E051683b5cfaC5929C25E84adb26ECf87B38";
|
|
2
|
+
export declare const AAVE_POOL_DATA_PROVIDER = "0x112b087b60C1a166130d59266363C45F8aa99db0";
|
|
3
|
+
export declare const AAVE_LENDING_POOL_ADDRESS = "0xf3Ba4D1b50f78301BDD7EAEa9B67822A15FCA691";
|
|
4
|
+
export declare const AAVE_GAS_LIMIT = 1000000n;
|
|
5
|
+
export declare const AAVE_ROUNDING_THRESHOLD = 5;
|
|
6
|
+
export declare const AAVE_UINT_256_MAX: bigint;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var K=Object.create;var D=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(l,e)=>{for(var t in e)D(l,t,{get:e[t],enumerable:!0})},U=(l,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Q(e))!ee.call(l,n)&&n!==t&&D(l,n,{get:()=>e[n],enumerable:!(r=J(e,n))||r.enumerable});return l};var ne=(l,e,t)=>(t=l!=null?K(Z(l)):{},U(e||!l||!l.__esModule?D(t,"default",{value:l,enumerable:!0}):t,l)),ae=l=>U(D({},"__esModule",{value:!0}),l);var le={};te(le,{AAVE_GAS_LIMIT:()=>re,AAVE_LENDING_POOL_ADDRESS:()=>P,AAVE_POOL_ABI:()=>S,AAVE_POOL_DATA_PROVIDER:()=>B,AAVE_POOL_DATA_PROVIDER_ABI:()=>C,AAVE_POOL_PROXY:()=>M,AAVE_ROUNDING_THRESHOLD:()=>ge,AAVE_UINT_256_MAX:()=>ie,AaveClient:()=>I,AaveUtils:()=>k});module.exports=ae(le);var S=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"reserve",type:"address"},{indexed:!1,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"address",name:"onBehalfOf",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!0,internalType:"uint16",name:"referralCode",type:"uint16"}],name:"Supply",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"reserve",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"Withdraw",type:"event"},{inputs:[{internalType:"address",name:"asset",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address",name:"to",type:"address"}],name:"withdraw",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"reserve",type:"address"},{indexed:!1,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"address",name:"onBehalfOf",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"enum DataTypes.InterestRateMode",name:"interestRateMode",type:"uint8"},{indexed:!1,internalType:"uint256",name:"borrowRate",type:"uint256"},{indexed:!0,internalType:"uint16",name:"referralCode",type:"uint16"}],name:"Borrow",type:"event"},{inputs:[{internalType:"address",name:"asset",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"interestRateMode",type:"uint256"},{internalType:"uint16",name:"referralCode",type:"uint16"},{internalType:"address",name:"onBehalfOf",type:"address"}],name:"borrow",outputs:[],stateMutability:"nonpayable",type:"function"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"reserve",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"address",name:"repayer",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"bool",name:"useATokens",type:"bool"}],name:"Repay",type:"event"},{inputs:[{internalType:"address",name:"user",type:"address"}],name:"getUserAccountData",outputs:[{internalType:"uint256",name:"totalCollateralBase",type:"uint256"},{internalType:"uint256",name:"totalDebtBase",type:"uint256"},{internalType:"uint256",name:"availableBorrowsBase",type:"uint256"},{internalType:"uint256",name:"currentLiquidationThreshold",type:"uint256"},{internalType:"uint256",name:"ltv",type:"uint256"},{internalType:"uint256",name:"healthFactor",type:"uint256"}],stateMutability:"view",type:"function"}];var C=[{inputs:[{internalType:"contract IEACAggregatorProxy",name:"_networkBaseTokenPriceInUsdProxyAggregator",type:"address"},{internalType:"contract IEACAggregatorProxy",name:"_marketReferenceCurrencyPriceInUsdProxyAggregator",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"ETH_CURRENCY_UNIT",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"MKR_ADDRESS",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_bytes32",type:"bytes32"}],name:"bytes32ToString",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"contract IPoolAddressesProvider",name:"provider",type:"address"}],name:"getReservesData",outputs:[{components:[{internalType:"address",name:"underlyingAsset",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"baseLTVasCollateral",type:"uint256"},{internalType:"uint256",name:"reserveLiquidationThreshold",type:"uint256"},{internalType:"uint256",name:"reserveLiquidationBonus",type:"uint256"},{internalType:"uint256",name:"reserveFactor",type:"uint256"},{internalType:"bool",name:"usageAsCollateralEnabled",type:"bool"},{internalType:"bool",name:"borrowingEnabled",type:"bool"},{internalType:"bool",name:"stableBorrowRateEnabled",type:"bool"},{internalType:"bool",name:"isActive",type:"bool"},{internalType:"bool",name:"isFrozen",type:"bool"},{internalType:"uint128",name:"liquidityIndex",type:"uint128"},{internalType:"uint128",name:"variableBorrowIndex",type:"uint128"},{internalType:"uint128",name:"liquidityRate",type:"uint128"},{internalType:"uint128",name:"variableBorrowRate",type:"uint128"},{internalType:"uint128",name:"stableBorrowRate",type:"uint128"},{internalType:"uint40",name:"lastUpdateTimestamp",type:"uint40"},{internalType:"address",name:"aTokenAddress",type:"address"},{internalType:"address",name:"stableDebtTokenAddress",type:"address"},{internalType:"address",name:"variableDebtTokenAddress",type:"address"},{internalType:"address",name:"interestRateStrategyAddress",type:"address"},{internalType:"uint256",name:"availableLiquidity",type:"uint256"},{internalType:"uint256",name:"totalPrincipalStableDebt",type:"uint256"},{internalType:"uint256",name:"averageStableRate",type:"uint256"},{internalType:"uint256",name:"stableDebtLastUpdateTimestamp",type:"uint256"},{internalType:"uint256",name:"totalScaledVariableDebt",type:"uint256"},{internalType:"uint256",name:"priceInMarketReferenceCurrency",type:"uint256"},{internalType:"address",name:"priceOracle",type:"address"},{internalType:"uint256",name:"variableRateSlope1",type:"uint256"},{internalType:"uint256",name:"variableRateSlope2",type:"uint256"},{internalType:"uint256",name:"stableRateSlope1",type:"uint256"},{internalType:"uint256",name:"stableRateSlope2",type:"uint256"},{internalType:"uint256",name:"baseStableBorrowRate",type:"uint256"},{internalType:"uint256",name:"baseVariableBorrowRate",type:"uint256"},{internalType:"uint256",name:"optimalUsageRatio",type:"uint256"},{internalType:"bool",name:"isPaused",type:"bool"},{internalType:"bool",name:"isSiloedBorrowing",type:"bool"},{internalType:"uint128",name:"accruedToTreasury",type:"uint128"},{internalType:"uint128",name:"unbacked",type:"uint128"},{internalType:"uint128",name:"isolationModeTotalDebt",type:"uint128"},{internalType:"bool",name:"flashLoanEnabled",type:"bool"},{internalType:"uint256",name:"debtCeiling",type:"uint256"},{internalType:"uint256",name:"debtCeilingDecimals",type:"uint256"},{internalType:"uint8",name:"eModeCategoryId",type:"uint8"},{internalType:"uint256",name:"borrowCap",type:"uint256"},{internalType:"uint256",name:"supplyCap",type:"uint256"},{internalType:"uint16",name:"eModeLtv",type:"uint16"},{internalType:"uint16",name:"eModeLiquidationThreshold",type:"uint16"},{internalType:"uint16",name:"eModeLiquidationBonus",type:"uint16"},{internalType:"address",name:"eModePriceSource",type:"address"},{internalType:"string",name:"eModeLabel",type:"string"},{internalType:"bool",name:"borrowableInIsolation",type:"bool"}],internalType:"struct IUiPoolDataProviderV3.AggregatedReserveData[]",name:"",type:"tuple[]"},{components:[{internalType:"uint256",name:"marketReferenceCurrencyUnit",type:"uint256"},{internalType:"int256",name:"marketReferenceCurrencyPriceInUsd",type:"int256"},{internalType:"int256",name:"networkBaseTokenPriceInUsd",type:"int256"},{internalType:"uint8",name:"networkBaseTokenPriceDecimals",type:"uint8"}],internalType:"struct IUiPoolDataProviderV3.BaseCurrencyInfo",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IPoolAddressesProvider",name:"provider",type:"address"}],name:"getReservesList",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IPoolAddressesProvider",name:"provider",type:"address"},{internalType:"address",name:"user",type:"address"}],name:"getUserReservesData",outputs:[{components:[{internalType:"address",name:"underlyingAsset",type:"address"},{internalType:"uint256",name:"scaledATokenBalance",type:"uint256"},{internalType:"bool",name:"usageAsCollateralEnabledOnUser",type:"bool"},{internalType:"uint256",name:"stableBorrowRate",type:"uint256"},{internalType:"uint256",name:"scaledVariableDebt",type:"uint256"},{internalType:"uint256",name:"principalStableDebt",type:"uint256"},{internalType:"uint256",name:"stableBorrowLastUpdateTimestamp",type:"uint256"}],internalType:"struct IUiPoolDataProviderV3.UserReserveData[]",name:"",type:"tuple[]"},{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"marketReferenceCurrencyPriceInUsdProxyAggregator",outputs:[{internalType:"contract IEACAggregatorProxy",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"networkBaseTokenPriceInUsdProxyAggregator",outputs:[{internalType:"contract IEACAggregatorProxy",name:"",type:"address"}],stateMutability:"view",type:"function"}];var M="0x1b02E051683b5cfaC5929C25E84adb26ECf87B38",B="0x112b087b60C1a166130d59266363C45F8aa99db0",P="0xf3Ba4D1b50f78301BDD7EAEa9B67822A15FCA691",re=1000000n,ge=5,ie=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var I=class{client;constructor(e){this.client=e.getWsProvider()}async getBlockTimestamp(){let e=await this.client.getBlock();return Number(e.timestamp)}async getReservesData(){return await this.client.readContract({abi:C,address:B,args:[P],functionName:"getReservesData"})}async getUserReservesData(e){return await this.client.readContract({abi:C,address:B,args:[P,e],functionName:"getUserReservesData"})}async getUserAccountData(e){return await this.client.readContract({abi:S,address:M,args:[e],functionName:"getUserAccountData"})}};var s=ne(require("big.js")),f=require("@galacticcouncil/common");var{ERC20:w}=f.erc20,{H160:O}=f.h160,se=1.01,oe=31536000n,F=4,E=-1,_=10n**27n,k=class{client;constructor(e){this.client=new I(e)}async getSummary(e){let t=O.fromAny(e),[r,n,a,i]=await Promise.all([this.client.getReservesData(),this.client.getUserReservesData(t),this.client.getUserAccountData(t),this.client.getBlockTimestamp()]),[o]=r,[p,d]=n,[y,m,u,A,T,g]=a,b=f.big.toDecimal(g,18),h=[];for(let v of p){let R=v.underlyingAsset.toLowerCase(),c=o.find(({underlyingAsset:z})=>z.toLowerCase()===R);if(!c)throw new Error("Missing pool reserve for "+R);let L=v.scaledATokenBalance,x=c.liquidityIndex,q=c.liquidityRate,N=c.availableLiquidity,V=c.priceInMarketReferenceCurrency,W=i+6,H=this.calculateLinearInterest(q,c.lastUpdateTimestamp,W),$=x*H/_,G=L*$/_,Y=Number(d!==0&&d===c.eModeCategoryId?c.eModeLiquidationThreshold:c.reserveLiquidationThreshold)/1e4,X=c.usageAsCollateralEnabled&&v.usageAsCollateralEnabledOnUser&&v.scaledATokenBalance>0n,j=w.toAssetId(R);h.push({aTokenBalance:G,availableLiquidity:N,decimals:Number(c.decimals),isCollateral:X,priceInRef:V,reserveId:j,reserveAsset:R,reserveLiquidationThreshold:Y})}return{healthFactor:Number(b),currentLiquidationThreshold:Number(f.big.toDecimal(A,F)),totalCollateral:y,totalDebt:m,reserves:h}}async hasBorrowPositions(e){let t=O.fromAny(e),r=await this.client.getUserAccountData(t),[n,a]=r;return a>0n}async getHealthFactor(e){let t=O.fromAny(e),r=await this.client.getUserAccountData(t),[n,a,i,o,p,d]=r;return this.calculateHealthFactorFromBalances(a,n,o)}async getHealthFactorAfterWithdraw(e,t,r){let{totalCollateral:n,totalDebt:a,reserves:i,currentLiquidationThreshold:o}=await this.getSummary(e);if(a===0n)return E;let p=w.fromAssetId(t),d=i.find(R=>R.reserveAsset===p);if(!d)throw new Error("Missing reserve ctx for "+p);let{decimals:y,isCollateral:m,priceInRef:u,reserveLiquidationThreshold:A}=d,T=f.big.toBigInt(r,y),g=m?T*u/10n**BigInt(y):0n,b=n-g;if(b<=0n)return 0;let h=(0,s.default)(n.toString()).mul(o).minus((0,s.default)(g.toString()).mul(A)).div(b.toString()),v=(0,s.default)(b.toString()).mul(h).div(a.toString()).toFixed(6,s.default.roundDown);return Number(v)}async getHealthFactorAfterSupply(e,t,r){let{totalCollateral:n,totalDebt:a,reserves:i,currentLiquidationThreshold:o}=await this.getSummary(e);if(a===0n)return E;let p=w.fromAssetId(t),d=i.find(v=>v.reserveAsset===p);if(!d)throw new Error("Missing reserve ctx for "+p);let{decimals:y,priceInRef:m,reserveLiquidationThreshold:u}=d,T=f.big.toBigInt(r,y)*m/10n**BigInt(y),g=n+T;if(g<=0n)return 0;let b=(0,s.default)(n.toString()).mul(o).plus((0,s.default)(T.toString()).mul(u)).div(g.toString()),h=(0,s.default)(g.toString()).mul(b).div(a.toString()).toFixed(6,s.default.roundDown);return Number(h)}async getHealthFactorAfterSwap(e,t,r,n,a){let{totalDebt:i,reserves:o,healthFactor:p}=await this.getSummary(e);if(i===0n)return E;let d=w.fromAssetId(r),y=w.fromAssetId(a),m=o.find(x=>x.reserveAsset===d),u=o.find(x=>x.reserveAsset===y);if(!m)throw new Error(`Missing reserve ctx for ${d}`);if(!u)throw new Error(`Missing reserve ctx for ${u}`);let A=f.big.toBigInt(t,m.decimals),T=f.big.toBigInt(n,u.decimals),g=A*m.priceInRef/10n**BigInt(m.decimals),b=T*u.priceInRef/10n**BigInt(u.decimals),h=m.isCollateral?(0,s.default)(g.toString()).mul(m.reserveLiquidationThreshold):(0,s.default)(0),c=(u.isCollateral?(0,s.default)(b.toString()).mul(u.reserveLiquidationThreshold):(0,s.default)(0)).minus(h).div(i.toString()),L=(0,s.default)(p).plus(c).toFixed(6,s.default.roundDown);return Number(L)}async getMaxWithdraw(e,t){let{totalDebt:r,reserves:n,healthFactor:a}=await this.getSummary(e),i=w.fromAssetId(t),o=n.find(p=>p.reserveAsset===i);if(!o)throw new Error("Missing reserve ctx for "+i);return this.calculateWithdrawMax(o,r,a)}async getMaxWithdrawAll(e){let{totalDebt:t,reserves:r,healthFactor:n}=await this.getSummary(e),a={};for(let i of r){let o=this.calculateWithdrawMax(i,t,n);i.reserveId&&(a[i.reserveId]=o)}return a}calculateWithdrawMax(e,t,r){let{aTokenBalance:n,availableLiquidity:a,decimals:i,priceInRef:o,reserveLiquidationThreshold:p,isCollateral:d}=e,y=n;if(d&&t>0n){let u=r-se;if(u>0){let A=(0,s.default)(u).mul(t.toString()).div(p).toFixed(0,s.default.roundDown),T=(0,s.default)(A).div(o.toString()).mul(10**i).toFixed(0,s.default.roundDown);y=n<BigInt(T)?n:BigInt(T)}else y=0n}return{amount:y<a?y:a,decimals:i}}calculateLinearInterest(e,t,r){let n=r-t;if(n<=0)return _;let a=e*BigInt(n)/oe;return _+a}calculateHealthFactorFromBalances(e,t,r){if(e===0n)return E;let n=t*r/e,a=f.big.toDecimal(n,F);return Number(a)}};0&&(module.exports={AAVE_GAS_LIMIT,AAVE_LENDING_POOL_ADDRESS,AAVE_POOL_ABI,AAVE_POOL_DATA_PROVIDER,AAVE_POOL_DATA_PROVIDER_ABI,AAVE_POOL_PROXY,AAVE_ROUNDING_THRESHOLD,AAVE_UINT_256_MAX,AaveClient,AaveUtils});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import j from"buffer";typeof window<"u"&&(window.Buffer=j.Buffer);var L=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"reserve",type:"address"},{indexed:!1,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"address",name:"onBehalfOf",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!0,internalType:"uint16",name:"referralCode",type:"uint16"}],name:"Supply",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"reserve",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"Withdraw",type:"event"},{inputs:[{internalType:"address",name:"asset",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address",name:"to",type:"address"}],name:"withdraw",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"reserve",type:"address"},{indexed:!1,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"address",name:"onBehalfOf",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"enum DataTypes.InterestRateMode",name:"interestRateMode",type:"uint8"},{indexed:!1,internalType:"uint256",name:"borrowRate",type:"uint256"},{indexed:!0,internalType:"uint16",name:"referralCode",type:"uint16"}],name:"Borrow",type:"event"},{inputs:[{internalType:"address",name:"asset",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"interestRateMode",type:"uint256"},{internalType:"uint16",name:"referralCode",type:"uint16"},{internalType:"address",name:"onBehalfOf",type:"address"}],name:"borrow",outputs:[],stateMutability:"nonpayable",type:"function"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"reserve",type:"address"},{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"address",name:"repayer",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"bool",name:"useATokens",type:"bool"}],name:"Repay",type:"event"},{inputs:[{internalType:"address",name:"user",type:"address"}],name:"getUserAccountData",outputs:[{internalType:"uint256",name:"totalCollateralBase",type:"uint256"},{internalType:"uint256",name:"totalDebtBase",type:"uint256"},{internalType:"uint256",name:"availableBorrowsBase",type:"uint256"},{internalType:"uint256",name:"currentLiquidationThreshold",type:"uint256"},{internalType:"uint256",name:"ltv",type:"uint256"},{internalType:"uint256",name:"healthFactor",type:"uint256"}],stateMutability:"view",type:"function"}];var B=[{inputs:[{internalType:"contract IEACAggregatorProxy",name:"_networkBaseTokenPriceInUsdProxyAggregator",type:"address"},{internalType:"contract IEACAggregatorProxy",name:"_marketReferenceCurrencyPriceInUsdProxyAggregator",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"ETH_CURRENCY_UNIT",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"MKR_ADDRESS",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_bytes32",type:"bytes32"}],name:"bytes32ToString",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"contract IPoolAddressesProvider",name:"provider",type:"address"}],name:"getReservesData",outputs:[{components:[{internalType:"address",name:"underlyingAsset",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"baseLTVasCollateral",type:"uint256"},{internalType:"uint256",name:"reserveLiquidationThreshold",type:"uint256"},{internalType:"uint256",name:"reserveLiquidationBonus",type:"uint256"},{internalType:"uint256",name:"reserveFactor",type:"uint256"},{internalType:"bool",name:"usageAsCollateralEnabled",type:"bool"},{internalType:"bool",name:"borrowingEnabled",type:"bool"},{internalType:"bool",name:"stableBorrowRateEnabled",type:"bool"},{internalType:"bool",name:"isActive",type:"bool"},{internalType:"bool",name:"isFrozen",type:"bool"},{internalType:"uint128",name:"liquidityIndex",type:"uint128"},{internalType:"uint128",name:"variableBorrowIndex",type:"uint128"},{internalType:"uint128",name:"liquidityRate",type:"uint128"},{internalType:"uint128",name:"variableBorrowRate",type:"uint128"},{internalType:"uint128",name:"stableBorrowRate",type:"uint128"},{internalType:"uint40",name:"lastUpdateTimestamp",type:"uint40"},{internalType:"address",name:"aTokenAddress",type:"address"},{internalType:"address",name:"stableDebtTokenAddress",type:"address"},{internalType:"address",name:"variableDebtTokenAddress",type:"address"},{internalType:"address",name:"interestRateStrategyAddress",type:"address"},{internalType:"uint256",name:"availableLiquidity",type:"uint256"},{internalType:"uint256",name:"totalPrincipalStableDebt",type:"uint256"},{internalType:"uint256",name:"averageStableRate",type:"uint256"},{internalType:"uint256",name:"stableDebtLastUpdateTimestamp",type:"uint256"},{internalType:"uint256",name:"totalScaledVariableDebt",type:"uint256"},{internalType:"uint256",name:"priceInMarketReferenceCurrency",type:"uint256"},{internalType:"address",name:"priceOracle",type:"address"},{internalType:"uint256",name:"variableRateSlope1",type:"uint256"},{internalType:"uint256",name:"variableRateSlope2",type:"uint256"},{internalType:"uint256",name:"stableRateSlope1",type:"uint256"},{internalType:"uint256",name:"stableRateSlope2",type:"uint256"},{internalType:"uint256",name:"baseStableBorrowRate",type:"uint256"},{internalType:"uint256",name:"baseVariableBorrowRate",type:"uint256"},{internalType:"uint256",name:"optimalUsageRatio",type:"uint256"},{internalType:"bool",name:"isPaused",type:"bool"},{internalType:"bool",name:"isSiloedBorrowing",type:"bool"},{internalType:"uint128",name:"accruedToTreasury",type:"uint128"},{internalType:"uint128",name:"unbacked",type:"uint128"},{internalType:"uint128",name:"isolationModeTotalDebt",type:"uint128"},{internalType:"bool",name:"flashLoanEnabled",type:"bool"},{internalType:"uint256",name:"debtCeiling",type:"uint256"},{internalType:"uint256",name:"debtCeilingDecimals",type:"uint256"},{internalType:"uint8",name:"eModeCategoryId",type:"uint8"},{internalType:"uint256",name:"borrowCap",type:"uint256"},{internalType:"uint256",name:"supplyCap",type:"uint256"},{internalType:"uint16",name:"eModeLtv",type:"uint16"},{internalType:"uint16",name:"eModeLiquidationThreshold",type:"uint16"},{internalType:"uint16",name:"eModeLiquidationBonus",type:"uint16"},{internalType:"address",name:"eModePriceSource",type:"address"},{internalType:"string",name:"eModeLabel",type:"string"},{internalType:"bool",name:"borrowableInIsolation",type:"bool"}],internalType:"struct IUiPoolDataProviderV3.AggregatedReserveData[]",name:"",type:"tuple[]"},{components:[{internalType:"uint256",name:"marketReferenceCurrencyUnit",type:"uint256"},{internalType:"int256",name:"marketReferenceCurrencyPriceInUsd",type:"int256"},{internalType:"int256",name:"networkBaseTokenPriceInUsd",type:"int256"},{internalType:"uint8",name:"networkBaseTokenPriceDecimals",type:"uint8"}],internalType:"struct IUiPoolDataProviderV3.BaseCurrencyInfo",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IPoolAddressesProvider",name:"provider",type:"address"}],name:"getReservesList",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IPoolAddressesProvider",name:"provider",type:"address"},{internalType:"address",name:"user",type:"address"}],name:"getUserReservesData",outputs:[{components:[{internalType:"address",name:"underlyingAsset",type:"address"},{internalType:"uint256",name:"scaledATokenBalance",type:"uint256"},{internalType:"bool",name:"usageAsCollateralEnabledOnUser",type:"bool"},{internalType:"uint256",name:"stableBorrowRate",type:"uint256"},{internalType:"uint256",name:"scaledVariableDebt",type:"uint256"},{internalType:"uint256",name:"principalStableDebt",type:"uint256"},{internalType:"uint256",name:"stableBorrowLastUpdateTimestamp",type:"uint256"}],internalType:"struct IUiPoolDataProviderV3.UserReserveData[]",name:"",type:"tuple[]"},{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"marketReferenceCurrencyPriceInUsdProxyAggregator",outputs:[{internalType:"contract IEACAggregatorProxy",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"networkBaseTokenPriceInUsdProxyAggregator",outputs:[{internalType:"contract IEACAggregatorProxy",name:"",type:"address"}],stateMutability:"view",type:"function"}];var S="0x1b02E051683b5cfaC5929C25E84adb26ECf87B38",P="0x112b087b60C1a166130d59266363C45F8aa99db0",E="0xf3Ba4D1b50f78301BDD7EAEa9B67822A15FCA691",pe=1000000n,de=5,ye=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var x=class{client;constructor(e){this.client=e.getWsProvider()}async getBlockTimestamp(){let e=await this.client.getBlock();return Number(e.timestamp)}async getReservesData(){return await this.client.readContract({abi:B,address:P,args:[E],functionName:"getReservesData"})}async getUserReservesData(e){return await this.client.readContract({abi:B,address:P,args:[E,e],functionName:"getUserReservesData"})}async getUserAccountData(e){return await this.client.readContract({abi:L,address:S,args:[e],functionName:"getUserAccountData"})}};import s from"big.js";import{big as h,erc20 as z,h160 as K}from"@galacticcouncil/common";var{ERC20:w}=z,{H160:_}=K,J=1.01,Q=31536000n,M=4,I=-1,D=10n**27n,O=class{client;constructor(e){this.client=new x(e)}async getSummary(e){let t=_.fromAny(e),[r,n,a,i]=await Promise.all([this.client.getReservesData(),this.client.getUserReservesData(t),this.client.getUserAccountData(t),this.client.getBlockTimestamp()]),[o]=r,[u,p]=n,[d,y,l,b,c,f]=a,T=h.toDecimal(f,18),v=[];for(let g of u){let A=g.underlyingAsset.toLowerCase(),m=o.find(({underlyingAsset:X})=>X.toLowerCase()===A);if(!m)throw new Error("Missing pool reserve for "+A);let C=g.scaledATokenBalance,R=m.liquidityIndex,U=m.liquidityRate,F=m.availableLiquidity,q=m.priceInMarketReferenceCurrency,N=i+6,V=this.calculateLinearInterest(U,m.lastUpdateTimestamp,N),W=R*V/D,H=C*W/D,$=Number(p!==0&&p===m.eModeCategoryId?m.eModeLiquidationThreshold:m.reserveLiquidationThreshold)/1e4,G=m.usageAsCollateralEnabled&&g.usageAsCollateralEnabledOnUser&&g.scaledATokenBalance>0n,Y=w.toAssetId(A);v.push({aTokenBalance:H,availableLiquidity:F,decimals:Number(m.decimals),isCollateral:G,priceInRef:q,reserveId:Y,reserveAsset:A,reserveLiquidationThreshold:$})}return{healthFactor:Number(T),currentLiquidationThreshold:Number(h.toDecimal(b,M)),totalCollateral:d,totalDebt:y,reserves:v}}async hasBorrowPositions(e){let t=_.fromAny(e),r=await this.client.getUserAccountData(t),[n,a]=r;return a>0n}async getHealthFactor(e){let t=_.fromAny(e),r=await this.client.getUserAccountData(t),[n,a,i,o,u,p]=r;return this.calculateHealthFactorFromBalances(a,n,o)}async getHealthFactorAfterWithdraw(e,t,r){let{totalCollateral:n,totalDebt:a,reserves:i,currentLiquidationThreshold:o}=await this.getSummary(e);if(a===0n)return I;let u=w.fromAssetId(t),p=i.find(A=>A.reserveAsset===u);if(!p)throw new Error("Missing reserve ctx for "+u);let{decimals:d,isCollateral:y,priceInRef:l,reserveLiquidationThreshold:b}=p,c=h.toBigInt(r,d),f=y?c*l/10n**BigInt(d):0n,T=n-f;if(T<=0n)return 0;let v=s(n.toString()).mul(o).minus(s(f.toString()).mul(b)).div(T.toString()),g=s(T.toString()).mul(v).div(a.toString()).toFixed(6,s.roundDown);return Number(g)}async getHealthFactorAfterSupply(e,t,r){let{totalCollateral:n,totalDebt:a,reserves:i,currentLiquidationThreshold:o}=await this.getSummary(e);if(a===0n)return I;let u=w.fromAssetId(t),p=i.find(g=>g.reserveAsset===u);if(!p)throw new Error("Missing reserve ctx for "+u);let{decimals:d,priceInRef:y,reserveLiquidationThreshold:l}=p,c=h.toBigInt(r,d)*y/10n**BigInt(d),f=n+c;if(f<=0n)return 0;let T=s(n.toString()).mul(o).plus(s(c.toString()).mul(l)).div(f.toString()),v=s(f.toString()).mul(T).div(a.toString()).toFixed(6,s.roundDown);return Number(v)}async getHealthFactorAfterSwap(e,t,r,n,a){let{totalDebt:i,reserves:o,healthFactor:u}=await this.getSummary(e);if(i===0n)return I;let p=w.fromAssetId(r),d=w.fromAssetId(a),y=o.find(R=>R.reserveAsset===p),l=o.find(R=>R.reserveAsset===d);if(!y)throw new Error(`Missing reserve ctx for ${p}`);if(!l)throw new Error(`Missing reserve ctx for ${l}`);let b=h.toBigInt(t,y.decimals),c=h.toBigInt(n,l.decimals),f=b*y.priceInRef/10n**BigInt(y.decimals),T=c*l.priceInRef/10n**BigInt(l.decimals),v=y.isCollateral?s(f.toString()).mul(y.reserveLiquidationThreshold):s(0),m=(l.isCollateral?s(T.toString()).mul(l.reserveLiquidationThreshold):s(0)).minus(v).div(i.toString()),C=s(u).plus(m).toFixed(6,s.roundDown);return Number(C)}async getMaxWithdraw(e,t){let{totalDebt:r,reserves:n,healthFactor:a}=await this.getSummary(e),i=w.fromAssetId(t),o=n.find(u=>u.reserveAsset===i);if(!o)throw new Error("Missing reserve ctx for "+i);return this.calculateWithdrawMax(o,r,a)}async getMaxWithdrawAll(e){let{totalDebt:t,reserves:r,healthFactor:n}=await this.getSummary(e),a={};for(let i of r){let o=this.calculateWithdrawMax(i,t,n);i.reserveId&&(a[i.reserveId]=o)}return a}calculateWithdrawMax(e,t,r){let{aTokenBalance:n,availableLiquidity:a,decimals:i,priceInRef:o,reserveLiquidationThreshold:u,isCollateral:p}=e,d=n;if(p&&t>0n){let l=r-J;if(l>0){let b=s(l).mul(t.toString()).div(u).toFixed(0,s.roundDown),c=s(b).div(o.toString()).mul(10**i).toFixed(0,s.roundDown);d=n<BigInt(c)?n:BigInt(c)}else d=0n}return{amount:d<a?d:a,decimals:i}}calculateLinearInterest(e,t,r){let n=r-t;if(n<=0)return D;let a=e*BigInt(n)/Q;return D+a}calculateHealthFactorFromBalances(e,t,r){if(e===0n)return I;let n=t*r/e,a=h.toDecimal(n,M);return Number(a)}};export{pe as AAVE_GAS_LIMIT,E as AAVE_LENDING_POOL_ADDRESS,L as AAVE_POOL_ABI,P as AAVE_POOL_DATA_PROVIDER,B as AAVE_POOL_DATA_PROVIDER_ABI,S as AAVE_POOL_PROXY,de as AAVE_ROUNDING_THRESHOLD,ye as AAVE_UINT_256_MAX,x as AaveClient,O as AaveUtils};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type AaveSummary = {
|
|
2
|
+
healthFactor: number;
|
|
3
|
+
currentLiquidationThreshold: number;
|
|
4
|
+
totalCollateral: bigint;
|
|
5
|
+
totalDebt: bigint;
|
|
6
|
+
reserves: AaveReserveData[];
|
|
7
|
+
};
|
|
8
|
+
export type AaveReserveData = {
|
|
9
|
+
aTokenBalance: bigint;
|
|
10
|
+
availableLiquidity: bigint;
|
|
11
|
+
decimals: number;
|
|
12
|
+
isCollateral: boolean;
|
|
13
|
+
priceInRef: bigint;
|
|
14
|
+
reserveId: number | null;
|
|
15
|
+
reserveAsset: string;
|
|
16
|
+
reserveLiquidationThreshold: number;
|
|
17
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PolkadotClient, TypedApi } from 'polkadot-api';
|
|
2
|
+
import { hydration, hydrationNext } from '@galacticcouncil/descriptors';
|
|
3
|
+
import { Watcher } from './Watcher';
|
|
4
|
+
export declare abstract class Papi {
|
|
5
|
+
readonly client: PolkadotClient;
|
|
6
|
+
readonly api: TypedApi<typeof hydration>;
|
|
7
|
+
readonly apiNext: TypedApi<typeof hydrationNext>;
|
|
8
|
+
readonly watcher: Watcher;
|
|
9
|
+
constructor(client: PolkadotClient);
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PolkadotClient } from 'polkadot-api';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class Watcher {
|
|
4
|
+
private static instance;
|
|
5
|
+
readonly bestBlock$: Observable<number>;
|
|
6
|
+
readonly finalizedBlock$: Observable<import("polkadot-api").BlockInfo>;
|
|
7
|
+
readonly connection$: Observable<"online" | "offline">;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(client: PolkadotClient): Watcher;
|
|
10
|
+
private watched;
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PolkadotClient } from 'polkadot-api';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
type ConnState = 'online' | 'offline';
|
|
4
|
+
type Opts = {
|
|
5
|
+
intervalMs?: number;
|
|
6
|
+
rpcTimeoutMs?: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Periodically probes the node and exposes a derived
|
|
10
|
+
* online/offline state.
|
|
11
|
+
*
|
|
12
|
+
* Behavior:
|
|
13
|
+
* - Runs one probe at a time
|
|
14
|
+
* - Each probe is allowed to run up to `rpcTimeoutMs`
|
|
15
|
+
* - Next probe is scheduled after the previous one completes plus `intervalMs`
|
|
16
|
+
* - Does not emit an initial synthetic state
|
|
17
|
+
* - Emits only on state changes
|
|
18
|
+
*
|
|
19
|
+
* @param client - polkadot client
|
|
20
|
+
* @param opts.intervalMs - time between probes
|
|
21
|
+
* @param opts.rpcTimeoutMs - time to wait before emitting offline
|
|
22
|
+
*
|
|
23
|
+
* @returns observable emitting connection state
|
|
24
|
+
*/
|
|
25
|
+
export declare function connectionProbe$(client: PolkadotClient, { intervalMs, rpcTimeoutMs }?: Opts): Observable<ConnState>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSm(chainSpec: string): Promise<import("polkadot-api").JsonRpcProvider>;
|
|
@@ -18,7 +18,7 @@ export declare class AssetClient extends Papi {
|
|
|
18
18
|
private mapShares;
|
|
19
19
|
private mapExternal;
|
|
20
20
|
private parseMetadata;
|
|
21
|
-
|
|
21
|
+
getSupported(includeInvalid?: boolean, external?: ExternalAsset[]): Promise<Asset[]>;
|
|
22
22
|
private isValidAsset;
|
|
23
23
|
}
|
|
24
24
|
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PolkadotClient } from 'polkadot-api';
|
|
2
|
+
import { type Observable } from 'rxjs';
|
|
3
|
+
import { Papi } from '../api';
|
|
4
|
+
import { AssetBalance, Balance } from '../types';
|
|
5
|
+
export declare class BalanceClient extends Papi {
|
|
6
|
+
private erc20Ids;
|
|
7
|
+
constructor(client: PolkadotClient);
|
|
8
|
+
getBalance(account: string, assetId: number): Promise<Balance>;
|
|
9
|
+
getSystemBalance(account: string): Promise<Balance>;
|
|
10
|
+
getTokenBalance(account: string, assetId: number): Promise<Balance>;
|
|
11
|
+
getErc20Balance(account: string, assetId: number): Promise<Balance>;
|
|
12
|
+
watchBalance(address: string): Observable<AssetBalance[]>;
|
|
13
|
+
watchSystemBalance(address: string): Observable<AssetBalance>;
|
|
14
|
+
watchTokenBalance(address: string, assetId: number): Observable<AssetBalance>;
|
|
15
|
+
watchTokensBalance(address: string): Observable<AssetBalance[]>;
|
|
16
|
+
watchErc20Balance(address: string, includeOnly?: number[]): Observable<AssetBalance[]>;
|
|
17
|
+
private getBalanceData;
|
|
18
|
+
private getBreakdown;
|
|
19
|
+
getDeltas(prev: AssetBalance[], curr: AssetBalance[]): AssetBalance[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PolkadotClient } from 'polkadot-api';
|
|
2
|
+
import { Papi } from '../api';
|
|
3
|
+
export declare class ChainParams extends Papi {
|
|
4
|
+
private _minOrderBudget?;
|
|
5
|
+
private _blockTime?;
|
|
6
|
+
constructor(client: PolkadotClient);
|
|
7
|
+
getBlockTime(): Promise<number>;
|
|
8
|
+
getMinOrderBudget(): Promise<bigint>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var E=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var R=(p,e)=>{for(var t in e)E(p,t,{get:e[t],enumerable:!0})},N=(p,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of I(e))!L.call(p,n)&&n!==t&&E(p,n,{get:()=>e[n],enumerable:!(s=O(e,n))||s.enumerable});return p};var H=p=>N(E({},"__esModule",{value:!0}),p);var Q={};R(Q,{AssetClient:()=>k,BalanceClient:()=>x,ChainParams:()=>_});module.exports=H(Q);var w=require("polkadot-api");var S=require("@galacticcouncil/descriptors");var C=require("@galacticcouncil/common"),B=require("rxjs");var b=require("rxjs"),c=require("rxjs/operators");function v(p,{intervalMs:e=5e3,rpcTimeoutMs:t=1e4}={}){let s=()=>(0,b.defer)(()=>(0,b.from)(p._request("system_health",[]))).pipe((0,c.timeout)({first:t}),(0,c.map)(()=>"online"),(0,c.catchError)(()=>(0,b.of)("offline")));return(0,b.of)({state:"offline",delayMs:0}).pipe((0,c.expand)(a=>(0,b.timer)(a.delayMs).pipe((0,c.switchMap)(s),(0,c.map)(r=>({state:r,delayMs:e})))),(0,c.skip)(1),(0,c.map)(a=>a.state),(0,c.distinctUntilChanged)(),(0,c.shareReplay)({bufferSize:1,refCount:!0}))}var{logger:V}=C.log,P=class p{static instance=null;bestBlock$;finalizedBlock$;connection$;constructor(e){this.bestBlock$=this.watched("watcher(bestBlock)",e.getUnsafeApi().query.System.Number.watchValue({at:"best"}).pipe((0,B.map)(({value:t})=>t))),this.finalizedBlock$=this.watched("watcher(finalizedBlock)",e.finalizedBlock$),this.connection$=this.watched("watcher(connection)",v(e))}static getInstance(e){return this.instance||(this.instance=new p(e)),this.instance}watched(e,t){return t.pipe((0,B.tap)({error:s=>V.error(e,s)}),(0,B.shareReplay)({bufferSize:1,refCount:!0}))}};var h=class{client;api;apiNext;watcher;constructor(e){this.client=e,this.api=this.client.getTypedApi(S.hydration),this.apiNext=this.client.getTypedApi(S.hydrationNext),this.watcher=P.getInstance(this.client)}};var W=require("polkadot-api/ws"),z=require("polkadot-api/logs-provider");var $=require("polkadot-api/sm-provider");var k=class extends h{SUPPORTED_TYPES=["StableSwap","Bond","Token","External","Erc20"];constructor(e){super(e)}async queryShares(){let t=await this.api.query.Stableswap.Pools.getEntries();return new Map(t.map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async queryBonds(){let t=await this.api.query.Bonds.Bonds.getEntries();return new Map(t.map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async queryAssets(){let t=await this.api.query.AssetRegistry.Assets.getEntries();return new Map(t.filter(({value:s})=>{let{asset_type:n}=s;return this.SUPPORTED_TYPES.includes(n.type)}).map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async queryAssetLocations(){let t=await this.api.query.AssetRegistry.AssetLocations.getEntries();return new Map(t.map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async mapToken(e,t,s,n){let{name:a,asset_type:r,is_sufficient:i,existential_deposit:m}=t,{symbol:l,decimals:u}=s.get(e)??{};return{id:e,name:a?w.Binary.toText(a):void 0,symbol:l,decimals:u,icon:l,type:r.type,isSufficient:i,location:n,existentialDeposit:m}}async mapBond(e,t,s,n){let[a,r]=n,{asset_type:i,is_sufficient:m,existential_deposit:l}=t,{symbol:u,decimals:A}=await this.mapToken(a,t,s),f=Number(r),y=new Intl.DateTimeFormat("en-GB"),g=[u,"Bond",y.format(f)].join(" ");return{id:e,name:g,symbol:u+"b",decimals:A,icon:u,type:i.type,isSufficient:m,existentialDeposit:l,underlyingAssetId:a,maturity:f}}async mapShares(e,t,s,n){let{assets:a}=n,{name:r,symbol:i,asset_type:m,is_sufficient:l,existential_deposit:u}=t,A=await Promise.all(a.map(async g=>{let{symbol:M}=await this.mapToken(g,t,s);return[g,M]})),f=Object.fromEntries(A),y=Object.values(f);return{id:e,name:y.join(", "),symbol:i&&w.Binary.toText(i)||r&&w.Binary.toText(r),decimals:18,icon:y.join("/"),type:m.type,isSufficient:l,existentialDeposit:u,meta:f}}async mapExternal(e,t,s,n){let a=await this.mapToken(e,t,new Map,n),r=s?.find(i=>i.internalId===a.id);return r?{...a,decimals:r.decimals,name:r.name,symbol:r.symbol,icon:r.symbol,isWhiteListed:r.isWhiteListed}:a}parseMetadata(e){return new Map(Array.from(e,([t,s])=>[t,{symbol:s.symbol?w.Binary.toText(s.symbol):void 0,decimals:s.decimals}]))}async getSupported(e,t){let[s,n,a,r]=await Promise.all([this.queryAssets(),this.queryAssetLocations(),this.queryShares(),this.queryBonds()]),i=this.parseMetadata(s),m=[];for(let[l,u]of Array.from(s)){let A=n.get(l),{asset_type:f}=u,y;switch(f.type){case"Bond":let g=r.get(l);y=await this.mapBond(l,u,i,g);break;case"StableSwap":let M=a.get(l);y=await this.mapShares(l,u,i,M);break;case"External":y=await this.mapExternal(l,u,t,A);break;default:y=await this.mapToken(l,u,i,A)}m.push(y)}return e?m:m.filter(l=>this.isValidAsset(l))}isValidAsset(e){let t=Math.sign(e.decimals);return!!e.symbol&&(t===0||t===1)}};var D=require("@galacticcouncil/common"),d=require("rxjs"),o=require("rxjs/operators");var{logger:T}=D.log,x=class extends h{erc20Ids=null;constructor(e){super(e)}async getBalance(e,t){return t===0?this.getSystemBalance(e):this.getBalanceData(e,t)}async getSystemBalance(e){let t=this.api.query.System.Account,{data:s}=await t.getValue(e,{at:"best"});return this.getBreakdown(s)}async getTokenBalance(e,t){let n=await this.api.query.Tokens.Accounts.getValue(e,t,{at:"best"});return this.getBreakdown(n)}async getErc20Balance(e,t){return this.getBalanceData(e,t)}watchBalance(e){return(0,d.defer)(()=>{let t=this.watchSystemBalance(e),s=this.watchTokensBalance(e),n=this.watchErc20Balance(e);return(0,d.combineLatest)([t,s,n]).pipe((0,o.connect)(a=>(0,d.concat)(a.pipe((0,o.take)(1)),a.pipe((0,o.skip)(1),(0,o.debounceTime)(250)))))}).pipe((0,o.map)(t=>t.flat()),(0,o.startWith)([]),(0,o.bufferCount)(2,1),(0,o.map)(([t,s],n)=>n===0?s:this.getDeltas(t,s))).pipe((0,o.tap)({subscribe:()=>T.debug("balance: subscribe",e),error:t=>T.error("balance",t)}),(0,o.retry)({delay:1e3}))}watchSystemBalance(e){let t=this.api.query.System.Account;return(0,d.defer)(()=>t.watchValue(e,{at:"best"})).pipe((0,o.map)(({value:s})=>({id:0,balance:this.getBreakdown(s.data)})),(0,o.tap)({error:s=>T.error("balance(system)",s)}))}watchTokenBalance(e,t){let s=this.api.query.Tokens.Accounts;return(0,d.defer)(()=>s.watchValue(e,t,{at:"best"})).pipe((0,o.map)(({value:n})=>({id:t,balance:this.getBreakdown(n)})),(0,o.tap)({error:n=>T.error("balance(token)",n)}))}watchTokensBalance(e){let t=this.api.query.Tokens.Accounts;return(0,d.defer)(()=>t.watchEntries(e,{at:"best"})).pipe((0,o.distinctUntilChanged)((s,n)=>!n.deltas),(0,o.map)(({deltas:s})=>{let n=[];return s?.deleted.forEach(a=>{let[r,i]=a.args;n.push({id:i,balance:this.getBreakdown({free:0n,reserved:0n,frozen:0n})})}),s?.upserted.forEach(a=>{let[r,i]=a.args;n.push({id:i,balance:this.getBreakdown(a.value)})}),n}),(0,o.tap)({error:s=>T.error("balance(tokens)",s)}))}watchErc20Balance(e,t){let s=async()=>{if(this.erc20Ids)return this.erc20Ids;let a=await this.api.query.AssetRegistry.Assets.getEntries({at:"best"});return this.erc20Ids=a.filter(({value:r})=>r.asset_type.type==="Erc20").map(({keyArgs:r})=>{let[i]=r;return i}),this.erc20Ids},n=async a=>(await Promise.all(a.map(async i=>[i,await this.getBalanceData(e,i)]))).map(([i,m])=>({id:i,balance:m}));return(0,d.defer)(()=>(0,d.from)(t?Promise.resolve(t):s()).pipe((0,o.switchMap)(a=>this.watcher.bestBlock$.pipe((0,o.switchMap)(()=>(0,d.from)(n(a))))),(0,o.startWith)([]),(0,o.bufferCount)(2,1),(0,o.map)(([a,r],i)=>i===0?r.filter(m=>m.balance.total>0n):this.getDeltas(a,r)),(0,o.distinctUntilChanged)((a,r)=>r.length===0),(0,o.tap)({error:a=>T.error("balance(erc20)",a)})))}async getBalanceData(e,t){let s=await this.api.apis.CurrenciesApi.account(t,e,{at:"best"});return this.getBreakdown(s)}getBreakdown(e){let t=e.free>=e.frozen?e.free-e.frozen:0n,s=e.free+e.reserved;return{free:e.free,reserved:e.reserved,frozen:e.frozen,total:s,transferable:t}}getDeltas(e,t){let s=(a,r)=>a!==void 0&&r!==void 0&&a.transferable===r.transferable&&a.total===r.total,n=e.reduce((a,r)=>(a.set(r.id,r.balance),a),new Map);return t.filter(a=>!s(a.balance,n.get(a.id)))}};var _=class extends h{_minOrderBudget;_blockTime;constructor(e){super(e)}async getBlockTime(){if(this._blockTime===void 0){let e=await this.api.constants.Aura.SlotDuration();this._blockTime=Number(e)}return this._blockTime}async getMinOrderBudget(){return this._minOrderBudget===void 0&&(this._minOrderBudget=await this.api.constants.DCA.MinBudgetInNativeCurrency()),this._minOrderBudget}};0&&(module.exports={AssetClient,BalanceClient,ChainParams});
|