impermax-sdk 1.2.151 → 1.2.153
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/lib/config/amms.js +5 -1
- package/lib/config/contracts/claim-aggregators.js +1 -0
- package/lib/config/contracts/impermax-chef.js +1 -0
- package/lib/config/contracts/impermax-config-manager.js +1 -0
- package/lib/config/contracts/impermax-factories.js +3 -0
- package/lib/config/contracts/imxes.js +1 -0
- package/lib/config/contracts/lending-vault-watcher.js +1 -0
- package/lib/config/contracts/merkle-distributors.js +3 -0
- package/lib/config/contracts/routers.js +4 -0
- package/lib/config/contracts/simple-uniswap-oracles.js +1 -0
- package/lib/config/contracts/weths.js +2 -1
- package/lib/config/debank-ids.js +1 -0
- package/lib/config/endpoints/merkle-distributors.js +3 -0
- package/lib/config/eth.js +2 -0
- package/lib/config/farms.js +2 -1
- package/lib/config/private-api.d.ts +4 -0
- package/lib/config/private-api.js +7 -0
- package/lib/config/subgraphs.d.ts +1 -0
- package/lib/config/subgraphs.js +6 -2
- package/lib/config/types.d.ts +2 -1
- package/lib/config/types.js +1 -0
- package/lib/offchain/lendingPool/offchainBorrowable.js +3 -3
- package/lib/offchain/lendingPool/offchainLendingPool.js +1 -1
- package/lib/offchain/offchain.d.ts +13 -3
- package/lib/offchain/offchain.js +55 -2
- package/lib/offchain/offchainAPRHelper.js +1 -3
- package/lib/offchain/offchainLendingVault.js +1 -1
- package/lib/offchain/offchainPriceHelperV2.d.ts +27 -0
- package/lib/offchain/offchainPriceHelperV2.js +75 -0
- package/package.json +1 -1
package/lib/config/amms.js
CHANGED
|
@@ -224,7 +224,8 @@ exports.AMM_FACTORY = {
|
|
|
224
224
|
[Amms.nile]: '0xcbdf792456367a91708c0036e0678ecfb1f09654',
|
|
225
225
|
[Amms.nileStable]: '0xb037874de77e7b4505261301d2f3ce2fb9036ca7',
|
|
226
226
|
[Amms.etherex]: '0xc0b920f6f1d6122b8187c031554dc8194f644592'
|
|
227
|
-
}
|
|
227
|
+
},
|
|
228
|
+
[types_1.Networks.HyperEVM]: {}
|
|
228
229
|
};
|
|
229
230
|
function getAmmByFactory(network, address) {
|
|
230
231
|
if (!address)
|
|
@@ -300,6 +301,7 @@ exports.AMM_SUBGRAPH_URLS = {
|
|
|
300
301
|
[types_1.Networks.Optimism]: {},
|
|
301
302
|
[types_1.Networks.Sonic]: {},
|
|
302
303
|
[types_1.Networks.Linea]: {},
|
|
304
|
+
[types_1.Networks.HyperEVM]: {}
|
|
303
305
|
};
|
|
304
306
|
exports.ADD_LIQUIDITY_URLS = {
|
|
305
307
|
[types_1.Networks.Ropsten]: {
|
|
@@ -401,6 +403,7 @@ exports.ADD_LIQUIDITY_URLS = {
|
|
|
401
403
|
[Amms.nileStable]: 'https://www.nile.build/manage/v1/',
|
|
402
404
|
[Amms.etherex]: 'https://www.etherex.finance/liquidity'
|
|
403
405
|
},
|
|
406
|
+
[types_1.Networks.HyperEVM]: {}
|
|
404
407
|
};
|
|
405
408
|
exports.AMM_LP_FEE = {
|
|
406
409
|
[types_1.Networks.Ropsten]: {
|
|
@@ -501,4 +504,5 @@ exports.AMM_LP_FEE = {
|
|
|
501
504
|
[Amms.nileStable]: 0,
|
|
502
505
|
[Amms.etherex]: 0
|
|
503
506
|
},
|
|
507
|
+
[types_1.Networks.HyperEVM]: {}
|
|
504
508
|
};
|
|
@@ -25,4 +25,5 @@ exports.IMPERMAX_CONFIG_MANAGER = {
|
|
|
25
25
|
[types_1.Networks.Real]: '0x274C36c461C02B39a110A0801EbB218eC076B79B',
|
|
26
26
|
[types_1.Networks.Sonic]: '0x1A3e33E38D2e70D43f65772f63c5B3f52073b37E',
|
|
27
27
|
[types_1.Networks.Linea]: '0x3A65E736b534B3A3703Eb081b93118852Bf1796a',
|
|
28
|
+
[types_1.Networks.HyperEVM]: '0x0c84eaf5203b0699fc950733336b6379f1429418'
|
|
28
29
|
};
|
|
@@ -75,6 +75,9 @@ exports.IMPERMAX_FACTORY = {
|
|
|
75
75
|
[types_1.Factory.SOLV2]: '0x7A9212D34DD283e952f8f15f084832e9b48ee746',
|
|
76
76
|
[types_1.Factory.SOL_STABLE]: '0x0D5433FEe91fb2DB9dd6A74267Dd900EC2130675'
|
|
77
77
|
},
|
|
78
|
+
[types_1.Networks.HyperEVM]: {
|
|
79
|
+
[types_1.Factory.SOLV2]: '0xdc2037d10f3a10f02b8cf8d3e373c0924b300f7d'
|
|
80
|
+
}
|
|
78
81
|
};
|
|
79
82
|
function getFactoryByAddress(network, address) {
|
|
80
83
|
if (!address)
|
|
@@ -25,6 +25,7 @@ exports.MERKLE_DISTRIBUTOR_IBEX = {
|
|
|
25
25
|
[types_1.Networks.Real]: '',
|
|
26
26
|
[types_1.Networks.Sonic]: '',
|
|
27
27
|
[types_1.Networks.Linea]: '',
|
|
28
|
+
[types_1.Networks.HyperEVM]: ''
|
|
28
29
|
};
|
|
29
30
|
exports.MERKLE_DISTRIBUTOR_IBEX_2 = {
|
|
30
31
|
[types_1.Networks.Polygon]: '0x1c813cDd6dAecE2CB83C52F0798504e42816E9C5',
|
|
@@ -49,6 +50,7 @@ exports.MERKLE_DISTRIBUTOR_IBEX_2 = {
|
|
|
49
50
|
[types_1.Networks.Real]: '',
|
|
50
51
|
[types_1.Networks.Sonic]: '',
|
|
51
52
|
[types_1.Networks.Linea]: '',
|
|
53
|
+
[types_1.Networks.HyperEVM]: '',
|
|
52
54
|
};
|
|
53
55
|
exports.MERKLE_DISTRIBUTOR_ETH = {
|
|
54
56
|
[types_1.Networks.Polygon]: '0x7ce2f634f0698ecdca051ef1dc4be96ef3d05a62',
|
|
@@ -73,4 +75,5 @@ exports.MERKLE_DISTRIBUTOR_ETH = {
|
|
|
73
75
|
[types_1.Networks.Real]: '',
|
|
74
76
|
[types_1.Networks.Sonic]: '',
|
|
75
77
|
[types_1.Networks.Linea]: '',
|
|
78
|
+
[types_1.Networks.HyperEVM]: '',
|
|
76
79
|
};
|
|
@@ -79,6 +79,9 @@ exports.ROUTER = {
|
|
|
79
79
|
[types_1.Factory.SOLV2]: '0xEB81da0cAC9D3efc4bf3270080936C6a5758926f',
|
|
80
80
|
[types_1.Factory.SOL_STABLE]: '0xC8BBC42B546d25c411b9BD42cDDDa12c00B468bc',
|
|
81
81
|
},
|
|
82
|
+
[types_1.Networks.HyperEVM]: {
|
|
83
|
+
[types_1.Factory.SOLV2]: '0xfe1cbfa345de7a08cf5c7aa8b2781756f1c5b496'
|
|
84
|
+
}
|
|
82
85
|
};
|
|
83
86
|
exports.DEFAULT_ROUTER = {
|
|
84
87
|
[types_1.Networks.Ropsten]: '0xbFf4acF789297A8507Eb7493AE18EB2C3A3A9632',
|
|
@@ -103,4 +106,5 @@ exports.DEFAULT_ROUTER = {
|
|
|
103
106
|
[types_1.Networks.Optimism]: '0xb5657FA5ba87CaD11b9150c319069625d423aaD4',
|
|
104
107
|
[types_1.Networks.Sonic]: '0xcBdf792456367a91708C0036E0678eCFB1f09654',
|
|
105
108
|
[types_1.Networks.Linea]: '0xEB81da0cAC9D3efc4bf3270080936C6a5758926f',
|
|
109
|
+
[types_1.Networks.HyperEVM]: '0xfe1cbfa345de7a08cf5c7aa8b2781756f1c5b496'
|
|
106
110
|
};
|
|
@@ -25,5 +25,6 @@ exports.WETH = {
|
|
|
25
25
|
[types_1.Networks.Optimism]: '0x4200000000000000000000000000000000000006',
|
|
26
26
|
[types_1.Networks.Real]: '0x90c6E93849E06EC7478ba24522329d14A5954Df4',
|
|
27
27
|
[types_1.Networks.Sonic]: '0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38',
|
|
28
|
-
[types_1.Networks.Linea]: '0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f',
|
|
28
|
+
[types_1.Networks.Linea]: '0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f',
|
|
29
|
+
[types_1.Networks.HyperEVM]: '0x5555555555555555555555555555555555555555' // whype
|
|
29
30
|
};
|
package/lib/config/debank-ids.js
CHANGED
|
@@ -25,6 +25,7 @@ exports.MERKLE_URL_IBEX = {
|
|
|
25
25
|
[types_1.Networks.Real]: '',
|
|
26
26
|
[types_1.Networks.Sonic]: '',
|
|
27
27
|
[types_1.Networks.Linea]: '',
|
|
28
|
+
[types_1.Networks.HyperEVM]: ''
|
|
28
29
|
};
|
|
29
30
|
exports.MERKLE_URL_IBEX_2 = {
|
|
30
31
|
[types_1.Networks.Polygon]: 'https://misty-rice-9880.impermax.workers.dev',
|
|
@@ -49,6 +50,7 @@ exports.MERKLE_URL_IBEX_2 = {
|
|
|
49
50
|
[types_1.Networks.Real]: '',
|
|
50
51
|
[types_1.Networks.Sonic]: '',
|
|
51
52
|
[types_1.Networks.Linea]: '',
|
|
53
|
+
[types_1.Networks.HyperEVM]: ''
|
|
52
54
|
};
|
|
53
55
|
exports.MERKLE_URL_ETH = {
|
|
54
56
|
[types_1.Networks.Polygon]: 'https://damp-hill-13d0.impermax.workers.dev',
|
|
@@ -73,4 +75,5 @@ exports.MERKLE_URL_ETH = {
|
|
|
73
75
|
[types_1.Networks.Real]: '',
|
|
74
76
|
[types_1.Networks.Sonic]: '',
|
|
75
77
|
[types_1.Networks.Linea]: '',
|
|
78
|
+
[types_1.Networks.HyperEVM]: ''
|
|
76
79
|
};
|
package/lib/config/eth.js
CHANGED
|
@@ -25,6 +25,7 @@ exports.ETH_NAME = {
|
|
|
25
25
|
[types_1.Networks.Real]: 'Ethereum',
|
|
26
26
|
[types_1.Networks.Sonic]: 'S',
|
|
27
27
|
[types_1.Networks.Linea]: 'Ethereum',
|
|
28
|
+
[types_1.Networks.HyperEVM]: 'Hyperliquid',
|
|
28
29
|
};
|
|
29
30
|
exports.ETH_SYMBOL = {
|
|
30
31
|
[types_1.Networks.Ropsten]: 'ETH',
|
|
@@ -49,4 +50,5 @@ exports.ETH_SYMBOL = {
|
|
|
49
50
|
[types_1.Networks.Real]: 'reETH',
|
|
50
51
|
[types_1.Networks.Sonic]: 'S',
|
|
51
52
|
[types_1.Networks.Linea]: 'ETH',
|
|
53
|
+
[types_1.Networks.HyperEVM]: 'HYPE',
|
|
52
54
|
};
|
package/lib/config/farms.js
CHANGED
|
@@ -217,7 +217,8 @@ exports.STAKED_LP_FACTORY = {
|
|
|
217
217
|
[types_1.Networks.Linea]: {
|
|
218
218
|
[Farms.nileStable]: '0xB037874dE77E7b4505261301d2F3CE2fb9036cA7',
|
|
219
219
|
[Farms.etherex]: '0xc0b920f6f1d6122b8187c031554dc8194f644592'
|
|
220
|
-
}
|
|
220
|
+
},
|
|
221
|
+
[types_1.Networks.HyperEVM]: {}
|
|
221
222
|
};
|
|
222
223
|
function getFarmByStakedLPFactory(network, address) {
|
|
223
224
|
if (!address)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PRICE_AGGREGATOR_API_URL = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Single endpoint for all factory subgraph token prices
|
|
6
|
+
*/
|
|
7
|
+
exports.PRICE_AGGREGATOR_API_URL = "https://price-aggregator-production.up.railway.app/api/tokens";
|
package/lib/config/subgraphs.js
CHANGED
|
@@ -6,7 +6,6 @@ const types_1 = require("./types");
|
|
|
6
6
|
// - FactoryV2: Sonic/Base/Optimism
|
|
7
7
|
// - FactoryV3: Arbitrum/Base
|
|
8
8
|
// - LendingVaults: Polygon/Arbitrum/Blast/Sonic/Base/Scroll
|
|
9
|
-
// @ts-ignore
|
|
10
9
|
exports.IMPERMAX_SUBGRAPH_URL = {
|
|
11
10
|
[types_1.Networks.Ropsten]: {},
|
|
12
11
|
[types_1.Networks.Mainnet]: {
|
|
@@ -152,7 +151,8 @@ exports.IMPERMAX_SUBGRAPH_URL = {
|
|
|
152
151
|
[types_1.Factory.SOL_STABLE]: [
|
|
153
152
|
'https://gateway.thegraph.com/api/e9bbf185bbf657f7ea313387cdf0e5ce/subgraphs/id/Ah5k6hzS9YicNHWuA4Uts9MQQQGbPLDtwD8tYjKaX8Ls',
|
|
154
153
|
]
|
|
155
|
-
}
|
|
154
|
+
},
|
|
155
|
+
[types_1.Networks.HyperEVM]: {}
|
|
156
156
|
};
|
|
157
157
|
exports.IMPERMAX_CHEF_SUBGRAPH_URL = {
|
|
158
158
|
[types_1.Networks.Ropsten]: '',
|
|
@@ -178,6 +178,7 @@ exports.IMPERMAX_CHEF_SUBGRAPH_URL = {
|
|
|
178
178
|
[types_1.Networks.Real]: '',
|
|
179
179
|
[types_1.Networks.Sonic]: '',
|
|
180
180
|
[types_1.Networks.Linea]: '',
|
|
181
|
+
[types_1.Networks.HyperEVM]: ''
|
|
181
182
|
};
|
|
182
183
|
exports.LENDING_VAULT_SUBGRAPH_URL = {
|
|
183
184
|
[types_1.Networks.Ropsten]: '',
|
|
@@ -202,6 +203,7 @@ exports.LENDING_VAULT_SUBGRAPH_URL = {
|
|
|
202
203
|
[types_1.Networks.Scroll]: 'https://gateway.thegraph.com/api/e9bbf185bbf657f7ea313387cdf0e5ce/subgraphs/id/BaPMX2ubiRZ4ujqTFmWyrk72fPo6yFLQ7A5Z4BLXCTFU',
|
|
203
204
|
[types_1.Networks.Sonic]: 'https://gateway.thegraph.com/api/e9bbf185bbf657f7ea313387cdf0e5ce/subgraphs/id/AHj91C4xwYSfyHAnZiMa1pC4ZwRtzqG3QGVyJchEsJAC',
|
|
204
205
|
[types_1.Networks.Linea]: '',
|
|
206
|
+
[types_1.Networks.HyperEVM]: ''
|
|
205
207
|
};
|
|
206
208
|
exports.BLOCKS_SUBGRAPH_URL = {
|
|
207
209
|
[types_1.Networks.Ropsten]: '',
|
|
@@ -226,6 +228,7 @@ exports.BLOCKS_SUBGRAPH_URL = {
|
|
|
226
228
|
[types_1.Networks.Optimism]: '',
|
|
227
229
|
[types_1.Networks.Sonic]: '',
|
|
228
230
|
[types_1.Networks.Linea]: '',
|
|
231
|
+
[types_1.Networks.HyperEVM]: ''
|
|
229
232
|
};
|
|
230
233
|
exports.XIMX_SUBGRAPH_URL = "https://api.thegraph.com/subgraphs/name/impermax-finance/imx-staking";
|
|
231
234
|
exports.CONFIG_MANAGER_SUBGRAPH_URL = {
|
|
@@ -250,6 +253,7 @@ exports.CONFIG_MANAGER_SUBGRAPH_URL = {
|
|
|
250
253
|
[types_1.Networks.Real]: 'https://api.goldsky.com/api/public/project_cm2d5q4l4w31601vz4swb3vmi/subgraphs/impermax-config-manager-real/1.0/gn',
|
|
251
254
|
[types_1.Networks.Sonic]: 'https://gateway.thegraph.com/api/e9bbf185bbf657f7ea313387cdf0e5ce/subgraphs/id/DqzQAecRNGsoRgwVre16Fha9XTPFf9QBo8iZxubysy2x',
|
|
252
255
|
[types_1.Networks.Linea]: 'https://gateway.thegraph.com/api/e9bbf185bbf657f7ea313387cdf0e5ce/subgraphs/id/CKu5kt4M1p2ELhn7cef9ZjE9igMH2icv3mzBepEdNPRz',
|
|
256
|
+
[types_1.Networks.HyperEVM]: ''
|
|
253
257
|
};
|
|
254
258
|
exports.WHITELIST_SUBGRAPH_URL = {
|
|
255
259
|
[types_1.Networks.Ropsten]: '',
|
package/lib/config/types.d.ts
CHANGED
package/lib/config/types.js
CHANGED
|
@@ -238,7 +238,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
|
|
|
238
238
|
return [];
|
|
239
239
|
const rewards = [];
|
|
240
240
|
for (const reward of farmingRewards) {
|
|
241
|
-
const rewardPrice = await this.getOffchain().getPriceHelper().
|
|
241
|
+
const rewardPrice = await this.getOffchain().getPriceHelper().getTokenPrice(reward.rewardToken);
|
|
242
242
|
rewards.push({
|
|
243
243
|
APR: (0, utils_1.toAPR)((rewardPrice * reward.rewardRate) / totalBorrowedUSD),
|
|
244
244
|
symbol: reward.rewardToken == "0x98878b06940ae243284ca214f92bb71a2b032b8a" ? "WMOVR" :
|
|
@@ -326,7 +326,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
|
|
|
326
326
|
// Token price getters
|
|
327
327
|
async getTokenPriceFast(fallback = true) {
|
|
328
328
|
let tokenAddress = await this.getUnderlyingAddress();
|
|
329
|
-
let tokenPrices = await this.getOffchain().getPriceHelper().getSubgraphTokensPrice();
|
|
329
|
+
let tokenPrices = await this.getOffchain().getPriceHelper().offchainPriceHelperV1.getSubgraphTokensPrice();
|
|
330
330
|
let tokenPrice = tokenPrices[tokenAddress];
|
|
331
331
|
if (tokenPrice !== undefined && tokenPrice > 0)
|
|
332
332
|
return tokenPrice;
|
|
@@ -334,7 +334,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
|
|
|
334
334
|
}
|
|
335
335
|
async getTokenPriceAccurate() {
|
|
336
336
|
let tokenAddress = await this.getUnderlyingAddress();
|
|
337
|
-
return this.getOffchain().getPriceHelper().
|
|
337
|
+
return this.getOffchain().getPriceHelper().getTokenPrice(tokenAddress);
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
exports.default = OffchainBorrowable;
|
|
@@ -92,7 +92,7 @@ class OffchainLendingPool {
|
|
|
92
92
|
let rewardRate = parseFloat(reward.rewardRate);
|
|
93
93
|
if (farm == farms_1.Farms.traderJoeV4)
|
|
94
94
|
rewardRate = rewardRate * 0.45;
|
|
95
|
-
const rewardPrice = await this.offchain.getPriceHelper().
|
|
95
|
+
const rewardPrice = await this.offchain.getPriceHelper().getTokenPrice(reward.rewardsToken.id);
|
|
96
96
|
rewards.push({
|
|
97
97
|
APR: (0, utils_1.toAPR)((rewardPrice * rewardRate) / (stakedTotalSupply * underlyingLPPrice) * multiplier),
|
|
98
98
|
symbol: reward.rewardsToken.symbol,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as initializer from "./offchainInitializer";
|
|
2
2
|
import OffchainLendingPool from "./lendingPool";
|
|
3
|
-
import
|
|
3
|
+
import OffchainPriceHelperV2 from "./offchainPriceHelperV2";
|
|
4
4
|
import OffchainAPRHelper from "./offchainAPRHelper";
|
|
5
5
|
import OffchainSolidexHelper from "./offchainSolidexHelper";
|
|
6
6
|
import OffchainAccount from "./account";
|
|
@@ -15,6 +15,14 @@ export interface OffchainCfg {
|
|
|
15
15
|
chainId: number;
|
|
16
16
|
whitelistedPairs?: FactoryIndex<Address[]>;
|
|
17
17
|
}
|
|
18
|
+
type TokenData = {
|
|
19
|
+
token: `${Networks}:${Address}`;
|
|
20
|
+
id: Address;
|
|
21
|
+
symbol: string;
|
|
22
|
+
name: string;
|
|
23
|
+
decimals: number;
|
|
24
|
+
chainId: number;
|
|
25
|
+
};
|
|
18
26
|
export default class Offchain {
|
|
19
27
|
readonly network: Networks;
|
|
20
28
|
readonly chainId: number;
|
|
@@ -22,7 +30,7 @@ export default class Offchain {
|
|
|
22
30
|
protected lendingPools: LendingPoolIndex<OffchainLendingPool>;
|
|
23
31
|
protected lendingVaults: AddressIndex<OffchainLendingVault>;
|
|
24
32
|
protected accounts: AddressIndex<OffchainAccount>;
|
|
25
|
-
protected priceHelper:
|
|
33
|
+
protected priceHelper: OffchainPriceHelperV2;
|
|
26
34
|
protected aprHelper: OffchainAPRHelper;
|
|
27
35
|
protected solidexHelper: OffchainSolidexHelper;
|
|
28
36
|
protected configManager: OffchainConfigManager;
|
|
@@ -43,7 +51,7 @@ export default class Offchain {
|
|
|
43
51
|
getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool>;
|
|
44
52
|
getLendingVault(vaultAddress: Address): Promise<OffchainLendingVault>;
|
|
45
53
|
getAccount(accountAddress: Address): OffchainAccount;
|
|
46
|
-
getPriceHelper: () =>
|
|
54
|
+
getPriceHelper: () => OffchainPriceHelperV2;
|
|
47
55
|
getSolidexHelper: () => OffchainSolidexHelper;
|
|
48
56
|
getConfigManager: () => OffchainConfigManager;
|
|
49
57
|
getAPRHelper: () => OffchainAPRHelper;
|
|
@@ -110,4 +118,6 @@ export default class Offchain {
|
|
|
110
118
|
getXIMXAPY(): Promise<number>;
|
|
111
119
|
getProtocolChart(): Promise<LlamaTvlChart>;
|
|
112
120
|
getProtocolChainChart(chain: Networks): Promise<LlamaTvlChart>;
|
|
121
|
+
getNetworkTokens(): Promise<TokenData[]>;
|
|
113
122
|
}
|
|
123
|
+
export {};
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const initializer = __importStar(require("./offchainInitializer"));
|
|
30
|
-
const
|
|
30
|
+
const offchainPriceHelperV2_1 = __importDefault(require("./offchainPriceHelperV2"));
|
|
31
31
|
const offchainAPRHelper_1 = __importDefault(require("./offchainAPRHelper"));
|
|
32
32
|
const offchainSolidexHelper_1 = __importDefault(require("./offchainSolidexHelper"));
|
|
33
33
|
const account_1 = __importDefault(require("./account"));
|
|
@@ -83,7 +83,7 @@ class Offchain {
|
|
|
83
83
|
this.network = cfg.network;
|
|
84
84
|
this.chainId = cfg.chainId;
|
|
85
85
|
this.whitelistedPairs = cfg.whitelistedPairs ? cfg.whitelistedPairs : {};
|
|
86
|
-
this.priceHelper = new
|
|
86
|
+
this.priceHelper = new offchainPriceHelperV2_1.default(this);
|
|
87
87
|
this.solidexHelper = new offchainSolidexHelper_1.default(this);
|
|
88
88
|
this.configManager = new configManager_1.default(this);
|
|
89
89
|
this.aprHelper = new offchainAPRHelper_1.default(this);
|
|
@@ -210,5 +210,58 @@ class Offchain {
|
|
|
210
210
|
const chainTvlCharts = await this.getAPRHelper().getChainTvlChart(chain);
|
|
211
211
|
return chainTvlCharts;
|
|
212
212
|
}
|
|
213
|
+
async getNetworkTokens() {
|
|
214
|
+
const tokenMap = new Map();
|
|
215
|
+
const lendingPoolsData = await this.getLendingPoolsData();
|
|
216
|
+
const chainId = this.chainId;
|
|
217
|
+
// Go through each factory
|
|
218
|
+
const factoryPromises = Object.entries(lendingPoolsData).map(async ([factory, pools]) => {
|
|
219
|
+
// Go through each pool in the factory
|
|
220
|
+
const poolPromises = Object.keys(pools).map(async (poolId) => {
|
|
221
|
+
try {
|
|
222
|
+
const lendingPool = await this.getLendingPool(factory, poolId);
|
|
223
|
+
if (!lendingPool)
|
|
224
|
+
return [];
|
|
225
|
+
// Get underlyings
|
|
226
|
+
const tokenPromises = [lendingPool.getBorrowableA(), lendingPool.getBorrowableB()].map(async (borrowable) => {
|
|
227
|
+
try {
|
|
228
|
+
const [address, symbol, name, decimals] = await Promise.all([
|
|
229
|
+
borrowable.getUnderlyingAddress(),
|
|
230
|
+
borrowable.getSymbol(),
|
|
231
|
+
borrowable.getName(),
|
|
232
|
+
borrowable.getDecimals(),
|
|
233
|
+
]);
|
|
234
|
+
if (!address)
|
|
235
|
+
return null;
|
|
236
|
+
return {
|
|
237
|
+
token: `${this.network}:${address}`,
|
|
238
|
+
id: address,
|
|
239
|
+
symbol,
|
|
240
|
+
name,
|
|
241
|
+
decimals,
|
|
242
|
+
chainId,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
console.error(`Error getting token details for borrowable in pool ${poolId}:`, error);
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
const tokens = await Promise.all(tokenPromises);
|
|
251
|
+
return tokens.filter((token) => token !== null);
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
console.error(`Error processing pool ${poolId} in factory ${factory} on ${this.network}:`, error);
|
|
255
|
+
return [];
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
const poolResults = await Promise.all(poolPromises);
|
|
259
|
+
return poolResults.flat();
|
|
260
|
+
});
|
|
261
|
+
const factoryResults = await Promise.all(factoryPromises);
|
|
262
|
+
const networkTokens = factoryResults.flat();
|
|
263
|
+
networkTokens.forEach(tokenData => tokenMap.set(tokenData.token, tokenData));
|
|
264
|
+
return networkTokens;
|
|
265
|
+
}
|
|
213
266
|
}
|
|
214
267
|
exports.default = Offchain;
|
|
@@ -25,6 +25,7 @@ const LlamaChains = {
|
|
|
25
25
|
[types_1.Networks.Blast]: "blast",
|
|
26
26
|
[types_1.Networks.Sonic]: "sonic",
|
|
27
27
|
[types_1.Networks.Linea]: "linea",
|
|
28
|
+
[types_1.Networks.HyperEVM]: "hyperliquid",
|
|
28
29
|
};
|
|
29
30
|
// Class to get the APR from DefiLlama directly, only makes 1 call to api and caches all pools
|
|
30
31
|
class OffchainAPRHelper {
|
|
@@ -275,10 +276,7 @@ class OffchainAPRHelper {
|
|
|
275
276
|
const etherexPools = await this.getEtherexPools();
|
|
276
277
|
// `initializeShadowPools` keys by pool address
|
|
277
278
|
// Convert to decimals to match `getUniswapAPR` and `getStakingAPR`
|
|
278
|
-
console.log(etherexPools[pool.toLowerCase()]);
|
|
279
|
-
console.log(etherexPools);
|
|
280
279
|
const apy = etherexPools[pool.toLowerCase()]?.lpApr / 100;
|
|
281
|
-
console.log("APY: ", apy);
|
|
282
280
|
return apy || 0;
|
|
283
281
|
}
|
|
284
282
|
async getLlamaTvlAndBorrows(chain) {
|
|
@@ -71,7 +71,7 @@ class OffchainLendingVault extends offchainPoolToken_1.default {
|
|
|
71
71
|
}
|
|
72
72
|
async getTokenPriceAccurate() {
|
|
73
73
|
let tokenAddress = await this.getUnderlyingAddress();
|
|
74
|
-
return this.getOffchain().getPriceHelper().
|
|
74
|
+
return this.getOffchain().getPriceHelper().getTokenPrice(tokenAddress);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
exports.default = OffchainLendingVault;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Address } from "../config/types";
|
|
2
|
+
import Offchain from "./offchain";
|
|
3
|
+
import OffchainPriceHelperV1 from "./offchainPriceHelper";
|
|
4
|
+
export default class OffchainPriceHelper {
|
|
5
|
+
private apiTokens;
|
|
6
|
+
private apiTokensInitialized;
|
|
7
|
+
offchainPriceHelperV1: OffchainPriceHelperV1;
|
|
8
|
+
offchain: Offchain;
|
|
9
|
+
constructor(offchain: Offchain);
|
|
10
|
+
cleanCache(): void;
|
|
11
|
+
/**
|
|
12
|
+
* NOTE: Used as a fallback at the moment while we deprecate the old price helper
|
|
13
|
+
*/
|
|
14
|
+
private getTokenPriceOld;
|
|
15
|
+
/**
|
|
16
|
+
* Initializes token prices from the API
|
|
17
|
+
*/
|
|
18
|
+
private initializeTokenPrices;
|
|
19
|
+
/**
|
|
20
|
+
* Gets all tokens data from the API
|
|
21
|
+
*/
|
|
22
|
+
private getTokenPrices;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the price of a token from the API, initializes all tokens
|
|
25
|
+
*/
|
|
26
|
+
getTokenPrice(tokenAddress: Address): Promise<number>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const private_api_1 = require("../config/private-api");
|
|
7
|
+
const offchainPriceHelper_1 = __importDefault(require("./offchainPriceHelper"));
|
|
8
|
+
class OffchainPriceHelper {
|
|
9
|
+
constructor(offchain) {
|
|
10
|
+
// Multichain private api
|
|
11
|
+
this.apiTokens = null;
|
|
12
|
+
this.apiTokensInitialized = null;
|
|
13
|
+
this.offchain = offchain;
|
|
14
|
+
this.offchainPriceHelperV1 = new offchainPriceHelper_1.default(offchain);
|
|
15
|
+
this.apiTokensInitialized = this.initializeTokenPrices();
|
|
16
|
+
}
|
|
17
|
+
cleanCache() {
|
|
18
|
+
this.apiTokens = null;
|
|
19
|
+
this.apiTokensInitialized = null;
|
|
20
|
+
this.offchainPriceHelperV1.cleanCache();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* NOTE: Used as a fallback at the moment while we deprecate the old price helper
|
|
24
|
+
*/
|
|
25
|
+
async getTokenPriceOld(tokenAddress) {
|
|
26
|
+
// Initializes v1 prices once if necessary
|
|
27
|
+
const price = await this.offchainPriceHelperV1.getDebankTokenPrice(tokenAddress);
|
|
28
|
+
return price;
|
|
29
|
+
}
|
|
30
|
+
/* -----------------------------------------------------------------------
|
|
31
|
+
* 1. Price aggreagator API (railway)
|
|
32
|
+
* ----------------------------------------------------------------------*/
|
|
33
|
+
/**
|
|
34
|
+
* Initializes token prices from the API
|
|
35
|
+
*/
|
|
36
|
+
async initializeTokenPrices() {
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetch(private_api_1.PRICE_AGGREGATOR_API_URL);
|
|
39
|
+
if (!response.ok)
|
|
40
|
+
throw new Error(`API response error: ${response.status}`);
|
|
41
|
+
this.apiTokens = await response.json();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error("Error fetching token prices:", error);
|
|
45
|
+
this.apiTokens = null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets all tokens data from the API
|
|
50
|
+
*/
|
|
51
|
+
async getTokenPrices() {
|
|
52
|
+
if (!this.apiTokensInitialized)
|
|
53
|
+
this.apiTokensInitialized = this.initializeTokenPrices();
|
|
54
|
+
await this.apiTokensInitialized;
|
|
55
|
+
return this.apiTokens;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets the price of a token from the API, initializes all tokens
|
|
59
|
+
*/
|
|
60
|
+
async getTokenPrice(tokenAddress) {
|
|
61
|
+
// Initialize tokens if necessary
|
|
62
|
+
const apiData = await this.getTokenPrices();
|
|
63
|
+
// Our price aggregator stores tokens as `chainId-tokenAddress`
|
|
64
|
+
// in case diff tokens have same address on diff networks
|
|
65
|
+
const key = `${this.offchain.chainId}-${tokenAddress.toLowerCase()}`;
|
|
66
|
+
this.offchain.chainId;
|
|
67
|
+
// First try get token price from our price-aggregator
|
|
68
|
+
const priceUsd = apiData?.tokens[key]?.priceUsd;
|
|
69
|
+
if (priceUsd)
|
|
70
|
+
return parseFloat(priceUsd);
|
|
71
|
+
// Fallback to price old
|
|
72
|
+
return this.getTokenPriceOld(tokenAddress);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.default = OffchainPriceHelper;
|