impermax-sdk 1.0.2 → 1.0.3

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 (108) hide show
  1. package/package.json +1 -1
  2. package/lib/esm/abis/ImpermaxABI.d.ts +0 -2
  3. package/lib/esm/abis/ImpermaxABI.js +0 -3
  4. package/lib/esm/abis/contracts/ClaimAggregator.json +0 -2015
  5. package/lib/esm/abis/contracts/IBorrowable.json +0 -13207
  6. package/lib/esm/abis/contracts/IClaimable.json +0 -406
  7. package/lib/esm/abis/contracts/ICollateral.json +0 -8952
  8. package/lib/esm/abis/contracts/IERC20.json +0 -2376
  9. package/lib/esm/abis/contracts/IFactory.json +0 -3660
  10. package/lib/esm/abis/contracts/IFarmingPool.json +0 -3584
  11. package/lib/esm/abis/contracts/IMerkleDistributor.json +0 -1134
  12. package/lib/esm/abis/contracts/IRouter02.json +0 -7283
  13. package/lib/esm/abis/contracts/ISimpleUniswapOracle.json +0 -1469
  14. package/lib/esm/abis/contracts/IStakedLPToken.json +0 -7309
  15. package/lib/esm/abis/contracts/IStakingRewards.json +0 -1036
  16. package/lib/esm/abis/contracts/IUniswapV2Factory.json +0 -1690
  17. package/lib/esm/abis/contracts/IUniswapV2Pair.json +0 -6761
  18. package/lib/esm/abis/contracts/ImpermaxChef.json +0 -20945
  19. package/lib/esm/config/amms.d.ts +0 -25
  20. package/lib/esm/config/amms.js +0 -196
  21. package/lib/esm/config/contracts/claim-aggregators.d.ts +0 -2
  22. package/lib/esm/config/contracts/claim-aggregators.js +0 -18
  23. package/lib/esm/config/contracts/impermax-chef.d.ts +0 -2
  24. package/lib/esm/config/contracts/impermax-chef.js +0 -18
  25. package/lib/esm/config/contracts/imxes.d.ts +0 -2
  26. package/lib/esm/config/contracts/imxes.js +0 -18
  27. package/lib/esm/config/contracts/merkle-distributors.d.ts +0 -4
  28. package/lib/esm/config/contracts/merkle-distributors.js +0 -13
  29. package/lib/esm/config/contracts/routers.d.ts +0 -2
  30. package/lib/esm/config/contracts/routers.js +0 -38
  31. package/lib/esm/config/contracts/simple-uniswap-oracles.d.ts +0 -2
  32. package/lib/esm/config/contracts/simple-uniswap-oracles.js +0 -35
  33. package/lib/esm/config/contracts/weths.d.ts +0 -2
  34. package/lib/esm/config/contracts/weths.js +0 -19
  35. package/lib/esm/config/debank-ids.d.ts +0 -2
  36. package/lib/esm/config/debank-ids.js +0 -17
  37. package/lib/esm/config/endpoints/merkle-distributors.d.ts +0 -4
  38. package/lib/esm/config/endpoints/merkle-distributors.js +0 -13
  39. package/lib/esm/config/eth.d.ts +0 -3
  40. package/lib/esm/config/eth.js +0 -32
  41. package/lib/esm/config/factories.d.ts +0 -6
  42. package/lib/esm/config/factories.js +0 -24
  43. package/lib/esm/config/farms.d.ts +0 -59
  44. package/lib/esm/config/farms.js +0 -114
  45. package/lib/esm/config/general.d.ts +0 -3
  46. package/lib/esm/config/general.js +0 -8
  47. package/lib/esm/config/subgraphs.d.ts +0 -5
  48. package/lib/esm/config/subgraphs.js +0 -68
  49. package/lib/esm/config/types.d.ts +0 -67
  50. package/lib/esm/config/types.js +0 -54
  51. package/lib/esm/impermax-router/Account.d.ts +0 -31
  52. package/lib/esm/impermax-router/Account.js +0 -154
  53. package/lib/esm/impermax-router/AccountBorrowable.d.ts +0 -22
  54. package/lib/esm/impermax-router/AccountBorrowable.js +0 -141
  55. package/lib/esm/impermax-router/AccountCollateral.d.ts +0 -11
  56. package/lib/esm/impermax-router/AccountCollateral.js +0 -63
  57. package/lib/esm/impermax-router/AccountLendingPool.d.ts +0 -57
  58. package/lib/esm/impermax-router/AccountLendingPool.js +0 -266
  59. package/lib/esm/impermax-router/AccountPoolToken.d.ts +0 -29
  60. package/lib/esm/impermax-router/AccountPoolToken.js +0 -89
  61. package/lib/esm/impermax-router/Borrowable.d.ts +0 -27
  62. package/lib/esm/impermax-router/Borrowable.js +0 -128
  63. package/lib/esm/impermax-router/Collateral.d.ts +0 -9
  64. package/lib/esm/impermax-router/Collateral.js +0 -45
  65. package/lib/esm/impermax-router/ContractsHelper.d.ts +0 -28
  66. package/lib/esm/impermax-router/ContractsHelper.js +0 -50
  67. package/lib/esm/impermax-router/ImpermaxFactory.d.ts +0 -15
  68. package/lib/esm/impermax-router/ImpermaxFactory.js +0 -42
  69. package/lib/esm/impermax-router/Interactions.d.ts +0 -16
  70. package/lib/esm/impermax-router/Interactions.js +0 -105
  71. package/lib/esm/impermax-router/InteractionsLendingPool.d.ts +0 -43
  72. package/lib/esm/impermax-router/InteractionsLendingPool.js +0 -124
  73. package/lib/esm/impermax-router/InteractionsPoolToken.d.ts +0 -23
  74. package/lib/esm/impermax-router/InteractionsPoolToken.js +0 -194
  75. package/lib/esm/impermax-router/LendingPool.d.ts +0 -69
  76. package/lib/esm/impermax-router/LendingPool.js +0 -291
  77. package/lib/esm/impermax-router/PoolToken.d.ts +0 -36
  78. package/lib/esm/impermax-router/PoolToken.js +0 -140
  79. package/lib/esm/impermax-router/index.d.ts +0 -20
  80. package/lib/esm/impermax-router/index.js +0 -34
  81. package/lib/esm/impermax-router/interfaces.d.ts +0 -218
  82. package/lib/esm/impermax-router/interfaces.js +0 -15
  83. package/lib/esm/index.d.ts +0 -3
  84. package/lib/esm/index.js +0 -10
  85. package/lib/esm/subgraph/Account.d.ts +0 -18
  86. package/lib/esm/subgraph/Account.js +0 -111
  87. package/lib/esm/subgraph/AccountLendingPool.d.ts +0 -19
  88. package/lib/esm/subgraph/AccountLendingPool.js +0 -71
  89. package/lib/esm/subgraph/AccountPoolToken.d.ts +0 -14
  90. package/lib/esm/subgraph/AccountPoolToken.js +0 -75
  91. package/lib/esm/subgraph/LendingPool.d.ts +0 -38
  92. package/lib/esm/subgraph/LendingPool.js +0 -204
  93. package/lib/esm/subgraph/PoolToken.d.ts +0 -64
  94. package/lib/esm/subgraph/PoolToken.js +0 -462
  95. package/lib/esm/subgraph/PriceHelper.d.ts +0 -21
  96. package/lib/esm/subgraph/PriceHelper.js +0 -166
  97. package/lib/esm/subgraph/SolidexHelper.d.ts +0 -16
  98. package/lib/esm/subgraph/SolidexHelper.js +0 -58
  99. package/lib/esm/subgraph/index.d.ts +0 -73
  100. package/lib/esm/subgraph/index.js +0 -185
  101. package/lib/esm/subgraph/initializer.d.ts +0 -34
  102. package/lib/esm/subgraph/initializer.js +0 -517
  103. package/lib/esm/subgraph/query.d.ts +0 -10
  104. package/lib/esm/subgraph/query.js +0 -229
  105. package/lib/esm/utils/ether-utils.d.ts +0 -5
  106. package/lib/esm/utils/ether-utils.js +0 -26
  107. package/lib/esm/utils/index.d.ts +0 -3
  108. package/lib/esm/utils/index.js +0 -16
@@ -1,462 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const utils_1 = require("../utils");
13
- const types_1 = require("../config/types");
14
- const eth_1 = require("../config/eth");
15
- const imxes_1 = require("../config/contracts/imxes");
16
- const weths_1 = require("../config/contracts/weths");
17
- class PoolToken {
18
- constructor(lendingPool, poolTokenType) {
19
- this.lendingPool = lendingPool;
20
- this.poolTokenType = poolTokenType;
21
- }
22
- // Subgraph calls
23
- getPoolTokenData() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const lendingPoolData = yield this.lendingPool.getLendingPoolData();
26
- return lendingPoolData[this.poolTokenType];
27
- });
28
- }
29
- // Helpers
30
- getPoolTokenParam(param) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const poolTokenData = yield this.getPoolTokenData();
33
- return poolTokenData[param];
34
- });
35
- }
36
- getPoolTokenParamFloat(param) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- return parseFloat(yield this.getPoolTokenParam(param));
39
- });
40
- }
41
- getUnderlyingParam(param) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const poolTokenData = yield this.getPoolTokenData();
44
- return poolTokenData.underlying[param];
45
- });
46
- }
47
- // Name
48
- getName() {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- if (this.poolTokenType == types_1.PoolTokenType.Collateral) {
51
- const nameA = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableA].getName();
52
- const nameB = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableB].getName();
53
- return nameA + '-' + nameB + ' LP';
54
- }
55
- const underlying = yield this.getUnderlyingAddress();
56
- if (underlying.toLowerCase() === weths_1.WETH[this.lendingPool.subgraph.network].toLowerCase())
57
- return eth_1.ETH_NAME[this.lendingPool.subgraph.network];
58
- if (underlying.toLowerCase() === "0xa3fa99a148fa48d14ed51d610c367c61876997f1")
59
- return "MIMATIC";
60
- if (underlying.toLowerCase() === "0x2e9a6df78e42a30712c10a9dc4b1c8656f8f2879")
61
- return "Maker";
62
- return this.getUnderlyingParam("name");
63
- });
64
- }
65
- // Symbol
66
- getSymbol() {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- if (this.poolTokenType == types_1.PoolTokenType.Collateral) {
69
- const symbolA = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableA].getSymbol();
70
- const symbolB = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableB].getSymbol();
71
- return symbolA + '-' + symbolB;
72
- }
73
- const underlying = yield this.getUnderlyingAddress();
74
- if (underlying.toLowerCase() === weths_1.WETH[this.lendingPool.subgraph.network].toLowerCase())
75
- return eth_1.ETH_SYMBOL[this.lendingPool.subgraph.network];
76
- if (underlying.toLowerCase() === "0xa3fa99a148fa48d14ed51d610c367c61876997f1")
77
- return "MAI";
78
- if (underlying.toLowerCase() === "0x2e9a6df78e42a30712c10a9dc4b1c8656f8f2879")
79
- return "MKR";
80
- if (underlying.toLowerCase() === "0xc165d941481e68696f43ee6e99bfb2b23e0e3114")
81
- return "OXDv1";
82
- if (underlying.toLowerCase() === "0xc5a9848b9d145965d821aaec8fa32aaee026492d")
83
- return "OXDv2";
84
- if (underlying.toLowerCase() === "0x6ae7dfc73e0dde2aa99ac063dcf7e8a63265108c")
85
- return "JPYCv1";
86
- if (underlying.toLowerCase() === "0x431d5dff03120afa4bdf332c61a6e1766ef37bdb")
87
- return "JPYCv2";
88
- return this.getUnderlyingParam("symbol");
89
- });
90
- }
91
- // Decimals
92
- getDecimals() {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- if (this.poolTokenType == types_1.PoolTokenType.Collateral)
95
- return 18;
96
- return parseInt(yield this.getUnderlyingParam("decimals"));
97
- });
98
- }
99
- // ExchangeRate
100
- getExchangeRate() {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- return this.getPoolTokenParamFloat("exchangeRate");
103
- });
104
- }
105
- // Underlying Address
106
- getUnderlyingAddress() {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- if (this.poolTokenType == types_1.PoolTokenType.Collateral)
109
- return this.lendingPool.pairAddress;
110
- return this.getUnderlyingParam("id");
111
- });
112
- }
113
- // Total balance
114
- getTotalBalance() {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- return this.getPoolTokenParamFloat("totalBalance");
117
- });
118
- }
119
- getTotalBalanceUSD() {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- const totalBalance = yield this.getTotalBalance();
122
- const tokenPrice = yield this.getTokenPriceFast();
123
- return totalBalance * tokenPrice;
124
- });
125
- }
126
- // Reserve Factor
127
- getReserveFactor() {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- return this.getPoolTokenParamFloat("reserveFactor");
130
- });
131
- }
132
- // Kink Borrow Rate
133
- getKinkBorrowRate() {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- return this.getPoolTokenParamFloat("kinkBorrowRate");
136
- });
137
- }
138
- // Kink Utilization Rate
139
- getKinkUtilizationRate() {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- return this.getPoolTokenParamFloat("kinkUtilizationRate");
142
- });
143
- }
144
- // Borrow Index
145
- getBorrowIndex() {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- return this.getPoolTokenParamFloat("borrowIndex");
148
- });
149
- }
150
- // Accrue Timestamp
151
- getAccrualTimestamp() {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- return this.getPoolTokenParamFloat("accrualTimestamp");
154
- });
155
- }
156
- // Total borrows
157
- getTotalBorrows() {
158
- return __awaiter(this, void 0, void 0, function* () {
159
- return this.getPoolTokenParamFloat("totalBorrows");
160
- });
161
- }
162
- getCurrentTotalBorrows() {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- const storedAmount = yield this.getTotalBorrows();
165
- const accrualTimestamp = yield this.getAccrualTimestamp();
166
- const borrowRate = yield this.getBorrowRate();
167
- return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * borrowRate);
168
- });
169
- }
170
- getTotalBorrowsUSD() {
171
- return __awaiter(this, void 0, void 0, function* () {
172
- const totalBorrows = yield this.getCurrentTotalBorrows();
173
- const tokenPrice = yield this.getTokenPriceFast();
174
- return totalBorrows * tokenPrice;
175
- });
176
- }
177
- // Borrow rate
178
- getBorrowRate() {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- return this.getPoolTokenParamFloat("borrowRate");
181
- });
182
- }
183
- getBorrowAPR() {
184
- return __awaiter(this, void 0, void 0, function* () {
185
- const borrowRate = yield this.getBorrowRate();
186
- return (0, utils_1.toAPR)(borrowRate);
187
- });
188
- }
189
- getNextBorrowRate(borrowAmount) {
190
- return __awaiter(this, void 0, void 0, function* () {
191
- const totalBorrows = yield this.getTotalBorrows();
192
- const supply = yield this.getSupply();
193
- const UR = (borrowAmount + totalBorrows) / supply;
194
- const kinkBR = yield this.getKinkBorrowRate();
195
- const kinkUR = yield this.getKinkUtilizationRate();
196
- if (UR < kinkUR)
197
- return UR / kinkUR * kinkBR;
198
- const kinkMultiplier = this.lendingPool.getKinkMultiplier();
199
- return ((UR - kinkUR) / (1 - kinkUR) * (kinkMultiplier - 1) + 1) * kinkBR;
200
- });
201
- }
202
- getNextBorrowAPR(borrowAmount) {
203
- return __awaiter(this, void 0, void 0, function* () {
204
- const borrowRate = yield this.getNextBorrowRate(borrowAmount);
205
- return (0, utils_1.toAPR)(borrowRate);
206
- });
207
- }
208
- // Supply
209
- getSupply() {
210
- return __awaiter(this, void 0, void 0, function* () {
211
- const totalBalance = yield this.getTotalBalance();
212
- const totalBorrows = yield this.getTotalBorrows();
213
- return totalBalance + totalBorrows;
214
- });
215
- }
216
- getCurrentSupply() {
217
- return __awaiter(this, void 0, void 0, function* () {
218
- const storedAmount = yield this.getSupply();
219
- const accrualTimestamp = yield this.getAccrualTimestamp();
220
- const supplyRate = yield this.getSupplyRate();
221
- return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * supplyRate);
222
- });
223
- }
224
- getSupplyUSD() {
225
- return __awaiter(this, void 0, void 0, function* () {
226
- const supply = yield this.getCurrentSupply();
227
- const tokenPrice = yield this.getTokenPriceFast();
228
- return supply * tokenPrice;
229
- });
230
- }
231
- // Utilization Rate
232
- getUtilizationRate() {
233
- return __awaiter(this, void 0, void 0, function* () {
234
- const supply = yield this.getSupply();
235
- if (supply == 0)
236
- return 0;
237
- const totalBalance = yield this.getTotalBorrows();
238
- return totalBalance / supply;
239
- });
240
- }
241
- // Supply Rate
242
- getSupplyRate() {
243
- return __awaiter(this, void 0, void 0, function* () {
244
- const borrowRate = yield this.getBorrowRate();
245
- const utilizationRate = yield this.getUtilizationRate();
246
- const reserveFactor = yield this.getReserveFactor();
247
- return borrowRate * utilizationRate * (1 - reserveFactor);
248
- });
249
- }
250
- getSupplyAPR() {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- const supplyRate = yield this.getSupplyRate();
253
- return (0, utils_1.toAPR)(supplyRate);
254
- });
255
- }
256
- getNextSupplyRate(supplyAmount) {
257
- return __awaiter(this, void 0, void 0, function* () {
258
- const totalBorrows = yield this.getTotalBorrows();
259
- const supply = yield this.getSupply();
260
- const UR = totalBorrows / (supply + supplyAmount);
261
- const kinkBR = yield this.getKinkBorrowRate();
262
- const kinkUR = yield this.getKinkUtilizationRate();
263
- const reserveFactor = yield this.getReserveFactor();
264
- if (UR < kinkUR)
265
- return UR / kinkUR * kinkBR * UR * (1 - reserveFactor);
266
- const kinkMultiplier = this.lendingPool.getKinkMultiplier();
267
- return ((UR - kinkUR) / (1 - kinkUR) * (kinkMultiplier - 1) + 1) * kinkBR * UR * (1 - reserveFactor);
268
- });
269
- }
270
- getNextSupplyAPR(supplyAmount) {
271
- return __awaiter(this, void 0, void 0, function* () {
272
- const supplyRate = yield this.getNextSupplyRate(supplyAmount);
273
- return (0, utils_1.toAPR)(supplyRate);
274
- });
275
- }
276
- // Reward Speed
277
- getFarmingRewardsRate() {
278
- return __awaiter(this, void 0, void 0, function* () {
279
- const poolTokenData = yield this.getPoolTokenData();
280
- const rewards = poolTokenData.rewards;
281
- if (rewards && rewards.length > 0)
282
- return rewards;
283
- const FINISH_DELAY = 3600 * 24;
284
- const farmingPoolData = poolTokenData.farmingPool;
285
- if (farmingPoolData === null)
286
- return [];
287
- const segmentLength = parseInt(farmingPoolData.segmentLength);
288
- const epochAmount = parseFloat(farmingPoolData.epochAmount);
289
- const epochBegin = parseInt(farmingPoolData.epochBegin);
290
- const epochEnd = epochBegin + segmentLength;
291
- const timestamp = (new Date()).getTime() / 1000;
292
- if (timestamp - FINISH_DELAY > epochEnd) {
293
- // How to manage better this case? Maybe check shares on distributor
294
- return [];
295
- }
296
- return [{
297
- rewardToken: imxes_1.IMX[this.lendingPool.subgraph.network],
298
- rewardRate: epochAmount / segmentLength
299
- }];
300
- });
301
- }
302
- // Farming
303
- getFarmingRewards() {
304
- return __awaiter(this, void 0, void 0, function* () {
305
- return this.getNextFarmingRewards(0);
306
- });
307
- }
308
- getNextFarmingRewards(borrowAmount) {
309
- return __awaiter(this, void 0, void 0, function* () {
310
- const farmingRewards = yield this.getFarmingRewardsRate();
311
- const currentBorrowedUSD = yield this.getTotalBorrowsUSD();
312
- const tokenPrice = yield this.getTokenPriceFast();
313
- const additionalBorrowsUSD = borrowAmount * tokenPrice;
314
- const totalBorrowedUSD = currentBorrowedUSD + additionalBorrowsUSD;
315
- if (totalBorrowedUSD === 0)
316
- return [];
317
- const rewards = [];
318
- for (const reward of farmingRewards) {
319
- const rewardPrice = yield this.lendingPool.subgraph.priceHelper.getDebankTokenPrice(reward.rewardToken);
320
- rewards.push({
321
- APR: (0, utils_1.toAPR)((rewardPrice * reward.rewardRate) / totalBorrowedUSD),
322
- symbol: reward.rewardToken == "0x98878b06940ae243284ca214f92bb71a2b032b8a" ? "WMOVR" :
323
- reward.rewardToken == "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270" ? "WMATIC" :
324
- "IMX",
325
- });
326
- }
327
- return rewards;
328
- });
329
- }
330
- getFarmingAPR() {
331
- return __awaiter(this, void 0, void 0, function* () {
332
- return this.getNextFarmingAPR(0);
333
- });
334
- }
335
- getNextFarmingAPR(borrowAmount) {
336
- return __awaiter(this, void 0, void 0, function* () {
337
- const rewards = yield this.getNextFarmingRewards(borrowAmount);
338
- let APR = 0;
339
- for (const reward of rewards) {
340
- APR += reward.APR;
341
- }
342
- return APR;
343
- });
344
- }
345
- // Past Data
346
- getPoolTokenDataPast24h() {
347
- return __awaiter(this, void 0, void 0, function* () {
348
- const lendingPoolDataPast = yield this.lendingPool.getLendingPoolDataPast24h();
349
- if (!lendingPoolDataPast)
350
- return undefined;
351
- return lendingPoolDataPast[this.poolTokenType];
352
- });
353
- }
354
- getPoolTokenDataPast7d() {
355
- return __awaiter(this, void 0, void 0, function* () {
356
- const lendingPoolDataPast = yield this.lendingPool.getLendingPoolDataPast7d();
357
- if (!lendingPoolDataPast)
358
- return undefined;
359
- return lendingPoolDataPast[this.poolTokenType];
360
- });
361
- }
362
- // Average Borrow APR
363
- getAverageBorrowAPR(poolTokenDataPast, fallback) {
364
- return __awaiter(this, void 0, void 0, function* () {
365
- if (poolTokenDataPast) {
366
- const accrualTimestampPast = parseFloat(poolTokenDataPast.accrualTimestamp);
367
- const borrowIndexPast = parseFloat(poolTokenDataPast.borrowIndex);
368
- const accrualTimestampNow = yield this.getAccrualTimestamp();
369
- const borrowIndexNow = yield this.getBorrowIndex();
370
- if (accrualTimestampNow > accrualTimestampPast) {
371
- const borrowRate = (borrowIndexNow / borrowIndexPast - 1) / (accrualTimestampNow - accrualTimestampPast);
372
- return borrowRate * 3600 * 24 * 365;
373
- }
374
- }
375
- return fallback;
376
- });
377
- }
378
- getAverage24hBorrowAPR() {
379
- return __awaiter(this, void 0, void 0, function* () {
380
- const poolTokenDataPast = yield this.getPoolTokenDataPast24h();
381
- return this.getAverageBorrowAPR(poolTokenDataPast, this.getBorrowAPR());
382
- });
383
- }
384
- getAverage7dBorrowAPR() {
385
- return __awaiter(this, void 0, void 0, function* () {
386
- const poolTokenDataPast = yield this.getPoolTokenDataPast7d();
387
- return this.getAverageBorrowAPR(poolTokenDataPast, this.getAverage24hBorrowAPR());
388
- });
389
- }
390
- // Average Supply APR
391
- getAverageSupplyAPR(poolTokenDataPast, fallback) {
392
- return __awaiter(this, void 0, void 0, function* () {
393
- if (poolTokenDataPast) {
394
- const accrualTimestampPast = parseFloat(poolTokenDataPast.accrualTimestamp);
395
- const exchangeRatePast = parseFloat(poolTokenDataPast.exchangeRate);
396
- const accrualTimestampNow = yield this.getAccrualTimestamp();
397
- const exchangeRateNow = yield this.getExchangeRate();
398
- if (accrualTimestampNow > accrualTimestampPast) {
399
- const supplyRate = (exchangeRateNow / exchangeRatePast - 1) / (accrualTimestampNow - accrualTimestampPast);
400
- return supplyRate * 3600 * 24 * 365;
401
- }
402
- }
403
- return fallback;
404
- });
405
- }
406
- getAverage24hSupplyAPR() {
407
- return __awaiter(this, void 0, void 0, function* () {
408
- const poolTokenDataPast = yield this.getPoolTokenDataPast24h();
409
- return this.getAverageSupplyAPR(poolTokenDataPast, this.getSupplyAPR());
410
- });
411
- }
412
- getAverage7dSupplyAPR() {
413
- return __awaiter(this, void 0, void 0, function* () {
414
- const poolTokenDataPast = yield this.getPoolTokenDataPast7d();
415
- return this.getAverageSupplyAPR(poolTokenDataPast, this.getAverage24hSupplyAPR());
416
- });
417
- }
418
- // Calculate collateral price -> returns the price of the collateral, not necessarily of the underlying LP
419
- calculateCollateralPrice(reserve0, reserve1, totalSupply, price0, price1) {
420
- if (totalSupply === 0) {
421
- console.error("Warning: totalSupply is 0");
422
- return 0;
423
- }
424
- const reserve0USD = reserve0 * price0;
425
- const reserve1USD = reserve1 * price1;
426
- // adjust reserves taking the latest price passed as parameters
427
- const adjustedReserveUSD = Math.sqrt(reserve0USD * reserve1USD) * 2;
428
- return adjustedReserveUSD / totalSupply;
429
- }
430
- // Token price getters
431
- getTokenPriceFast(fallback = true) {
432
- return __awaiter(this, void 0, void 0, function* () {
433
- let tokenPrice = 0;
434
- if (this.poolTokenType != types_1.PoolTokenType.Collateral) {
435
- //const poolTokenData = await this.getPoolTokenData() as BorrowableData;
436
- //tokenPrice = parseFloat(poolTokenData.underlying.derivedUSD);
437
- let tokenAddress = yield this.getUnderlyingAddress();
438
- let tokenPrices = yield this.lendingPool.subgraph.priceHelper.getSubgraphTokenPrice();
439
- tokenPrice = tokenPrices[tokenAddress];
440
- }
441
- else {
442
- tokenPrice = yield this.lendingPool.getCollateralPrice(false);
443
- }
444
- if (tokenPrice > 0)
445
- return tokenPrice;
446
- if (fallback) {
447
- return this.getTokenPriceAccurate();
448
- }
449
- return 0;
450
- });
451
- }
452
- getTokenPriceAccurate() {
453
- return __awaiter(this, void 0, void 0, function* () {
454
- if (this.poolTokenType === types_1.PoolTokenType.Collateral) {
455
- return this.lendingPool.getCollateralPrice(false);
456
- }
457
- let tokenAddress = yield this.getUnderlyingAddress();
458
- return this.lendingPool.subgraph.priceHelper.getDebankTokenPrice(tokenAddress);
459
- });
460
- }
461
- }
462
- exports.default = PoolToken;
@@ -1,21 +0,0 @@
1
- import Subgraph from "./index";
2
- import { Address } from '../config/types';
3
- export default class PriceHelper {
4
- subgraph: Subgraph;
5
- subgraphTokenPrice: Promise<{
6
- [key in Address]?: number;
7
- }>;
8
- debankTokenPrice: {
9
- [key in Address]?: Promise<number>;
10
- };
11
- constructor(subgraph: Subgraph);
12
- cleanCache(): void;
13
- private initializeSubgraphTokenPrice;
14
- getSubgraphTokenPrice(): Promise<{
15
- [key in Address]: number;
16
- }>;
17
- private getCoingeckoTokenPrice;
18
- private initializeDebankTokenPrice;
19
- getDebankTokenPrice(tokenAddress: Address): Promise<number>;
20
- getImxPrice(): Promise<number>;
21
- }
@@ -1,166 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const debank_ids_1 = require("../config/debank-ids");
13
- const imxes_1 = require("../config/contracts/imxes");
14
- // coingecko has priority over debank for initialized tokens
15
- const coingecko_ids = {
16
- // Arbitrum
17
- "0xb348b87b23d5977e2948e6f36ca07e1ec94d7328": "swapfish",
18
- "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f": "wrapped-bitcoin",
19
- };
20
- class PriceHelper {
21
- constructor(subgraph) {
22
- this.subgraph = subgraph;
23
- this.debankTokenPrice = {};
24
- }
25
- cleanCache() {
26
- this.subgraphTokenPrice = null;
27
- this.debankTokenPrice = {};
28
- }
29
- // First source of token price: Subgraph (less accurate, faster)
30
- initializeSubgraphTokenPrice() {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const lendingPoolsData = yield this.subgraph.getLendingPoolsData();
33
- const subgraphTokenPrice = {};
34
- for (const factory of Object.keys(lendingPoolsData)) {
35
- for (const id of Object.keys(lendingPoolsData[factory])) {
36
- const lendingPool = lendingPoolsData[factory][id];
37
- subgraphTokenPrice[lendingPool.borrowable0.underlying.id] = parseFloat(lendingPool.borrowable0.underlying.derivedUSD);
38
- subgraphTokenPrice[lendingPool.borrowable1.underlying.id] = parseFloat(lendingPool.borrowable1.underlying.derivedUSD);
39
- for (const reward of lendingPool.pair.rewards) {
40
- subgraphTokenPrice[reward.rewardsToken.id] = parseFloat(reward.rewardsToken.derivedUSD);
41
- }
42
- }
43
- }
44
- //fix for IMX
45
- subgraphTokenPrice["0x9c67ee39e3c4954396b9142010653f17257dd39c"] = 0;
46
- subgraphTokenPrice["0x7b35ce522cb72e4077baeb96cb923a5529764a00"] = 0;
47
- subgraphTokenPrice["0xea6887e4a9cda1b77e70129e5fba830cdb5cddef"] = 0;
48
- subgraphTokenPrice["0x60bb3d364b765c497c8ce50ae0ae3f0882c5bd05"] = 0;
49
- subgraphTokenPrice["0x900f1ec5819fa087d368877cd03b265bf1802667"] = 0;
50
- subgraphTokenPrice["0xea38f1ccf77bf43f352636241b05dd8f6f5f52b2"] = 0;
51
- return subgraphTokenPrice;
52
- });
53
- }
54
- getSubgraphTokenPrice() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- if (!this.subgraphTokenPrice)
57
- this.subgraphTokenPrice = this.initializeSubgraphTokenPrice();
58
- return this.subgraphTokenPrice;
59
- });
60
- }
61
- // Second source of token price: Debank (more accurate, slower)
62
- getCoingeckoTokenPrice(tokenAddress) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- try {
65
- const tokenId = coingecko_ids[tokenAddress];
66
- const response = yield fetch("https://api.coingecko.com/api/v3/simple/price?ids=" + tokenId + "&vs_currencies=usd");
67
- if (response.status != 200)
68
- return 0;
69
- const data = yield response.json();
70
- if (!data)
71
- return 0;
72
- return data[tokenId].usd ? data[tokenId].usd : 0;
73
- }
74
- catch (_a) {
75
- return 0;
76
- }
77
- });
78
- }
79
- initializeDebankTokenPrice(tokenAddress) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- if (Object.keys(coingecko_ids).includes(tokenAddress.toLowerCase())) {
82
- const result = this.getCoingeckoTokenPrice(tokenAddress.toLowerCase());
83
- if (result)
84
- return result;
85
- }
86
- try {
87
- const response = yield fetch("https://openapi.debank.com/v1/token?chain_id=" + debank_ids_1.DEBANK_IDS[this.subgraph.network] + "&id=" + tokenAddress);
88
- /*const response = await fetch(
89
- "https://pro-openapi.debank.com/v1/token?chain_id=" + debank_chain_ids[this.subgraph.network] + "&id=" + tokenAddress,
90
- {headers: {"AccessKey": "0ac0fba6aeb0905b4c9a1c5cfd9d48d74fbc60e0"}}
91
- );*/
92
- if (response.status != 200)
93
- return 0;
94
- const data = yield response.json();
95
- if (!data)
96
- return 0;
97
- return data.price ? data.price : 0;
98
- }
99
- catch (_a) {
100
- return 0;
101
- }
102
- });
103
- }
104
- getDebankTokenPrice(tokenAddress) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- if (tokenAddress.toLowerCase() === '0xb348b87b23d5977e2948e6f36ca07e1ec94d7328') { // fix for FISH
107
- //return 0.07;
108
- }
109
- if (tokenAddress.toLowerCase() === '0xf28164a485b0b2c90639e47b0f377b4a438a16b1') { // fix for dQuick
110
- return (yield this.getDebankTokenPrice('0x831753dd7087cac61ab5644b308642cc1c33dc13')) * 1.68;
111
- }
112
- if (tokenAddress.toLowerCase() === '0x63468133ed352e602beb61dd254d6060ad2fe419') { // fix for sTHO
113
- return (yield this.getDebankTokenPrice('0xae4aa155d2987b454c29450ef4f862cf00907b61')) * 1.1;
114
- }
115
- if (tokenAddress.toLowerCase() === '0xfcef8a994209d6916eb2c86cdd2afd60aa6f54b1') { // fix for fBEETS
116
- return (yield this.getDebankTokenPrice('0xf24bcf4d1e507740041c9cfd2dddb29585adce1e')) * 0.93;
117
- }
118
- if (tokenAddress.toLowerCase() === '0x5979d7b546e38e414f7e9822514be443a4800529') { // TEMPORARY fix for WSTETH
119
- return (yield this.getDebankTokenPrice('0x82af49447d8a07e3bd95bd0d56f35241523fbab1')) / 0.92;
120
- }
121
- if (tokenAddress.toLowerCase() === '0x3f56e0c36d275367b8c502090edf38289b3dea0d') { // TEMPORARY fix for MAI
122
- return 1;
123
- }
124
- if ([
125
- "0x9c67ee39e3c4954396b9142010653f17257dd39c",
126
- "0x7b35ce522cb72e4077baeb96cb923a5529764a00",
127
- "0xea6887e4a9cda1b77e70129e5fba830cdb5cddef",
128
- "0x60bb3d364b765c497c8ce50ae0ae3f0882c5bd05",
129
- "0x900f1ec5819fa087d368877cd03b265bf1802667",
130
- "0xea38f1ccf77bf43f352636241b05dd8f6f5f52b2",
131
- ].includes(tokenAddress.toLowerCase())) { // fix for IMX
132
- return 0;
133
- }
134
- if (tokenAddress.toLowerCase() === '0xda0053f0befcbcac208a3f867bb243716734d809') { // TEMPORARY fix for oxSOLID
135
- return (yield this.getDebankTokenPrice('0x888ef71766ca594ded1f0fa3ae64ed2941740a20')) * 0.88;
136
- }
137
- if (tokenAddress.toLowerCase() === '0x431d5dff03120afa4bdf332c61a6e1766ef37bdb') { // TEMPORARY fix for JPYCv2
138
- return (yield this.getDebankTokenPrice('0x6ae7dfc73e0dde2aa99ac063dcf7e8a63265108c'));
139
- }
140
- if (!this.debankTokenPrice[tokenAddress])
141
- this.debankTokenPrice[tokenAddress] = this.initializeDebankTokenPrice(tokenAddress);
142
- const tokenPrice = yield this.debankTokenPrice[tokenAddress];
143
- if (tokenPrice === 0) {
144
- // try fallback on subgraph
145
- const subgraphTokenPrice = yield this.getSubgraphTokenPrice();
146
- return subgraphTokenPrice[tokenAddress] ? subgraphTokenPrice[tokenAddress] : 0;
147
- }
148
- return tokenPrice;
149
- });
150
- }
151
- getImxPrice() {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- const imx = imxes_1.IMX[this.subgraph.network];
154
- if (!imx)
155
- return 0;
156
- const imxPrice = yield this.getDebankTokenPrice(imx);
157
- if (imxPrice != 0)
158
- return imxPrice;
159
- const subgraphTokenPrice = yield this.getSubgraphTokenPrice();
160
- if (subgraphTokenPrice[imx])
161
- return subgraphTokenPrice[imx];
162
- return 0;
163
- });
164
- }
165
- }
166
- exports.default = PriceHelper;
@@ -1,16 +0,0 @@
1
- import Subgraph from "./index";
2
- import { Address } from "../config/types";
3
- export type SolidexLPDetails = {
4
- [key in Address]: Array<{
5
- APR: number;
6
- symbol: string;
7
- }>;
8
- };
9
- export default class SolidexHelper {
10
- subgraph: Subgraph;
11
- solidexLPDetails: Promise<SolidexLPDetails>;
12
- constructor(subgraph: Subgraph);
13
- cleanCache(): void;
14
- private initializeSolidexLPDetails;
15
- getSolidexLPDetails(): Promise<SolidexLPDetails>;
16
- }