@1delta/margin-fetcher 0.0.18 → 0.0.19
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/dist/assets/liquidityThresholds.d.ts +10 -0
- package/dist/assets/liquidityThresholds.d.ts.map +1 -1
- package/dist/assets/liquidityThresholds.js +9 -2
- package/dist/flash-liquidity/fetchLiquidity.d.ts +2 -2
- package/dist/flash-liquidity/fetchLiquidity.d.ts.map +1 -1
- package/dist/flash-liquidity/fetchLiquidity.js +85 -54
- package/dist/flash-liquidity/types.d.ts +1 -0
- package/dist/flash-liquidity/types.d.ts.map +1 -1
- package/dist/lending/aave-v3-type/publicCallBuild.d.ts +1 -1
- package/dist/lending/aave-v3-type/publicCallBuild.d.ts.map +1 -1
- package/dist/lending/aave-v3-type/publicCallBuild.js +46 -48
- package/dist/lending/aave-v3-type/publicCallParse.d.ts.map +1 -1
- package/dist/lending/aave-v3-type/publicCallParse.js +8 -2
- package/dist/lending/compound-v3/publicCallParse.d.ts.map +1 -1
- package/dist/lending/compound-v3/publicCallParse.js +8 -3
- package/dist/lending/fetchLender.js +2 -2
- package/dist/lending/morpho/convertPublic.js +1 -1
- package/dist/lending/user-data/types.js +2 -2
- package/dist/lending-pairs/computeLendingPairs.d.ts +10 -1
- package/dist/lending-pairs/computeLendingPairs.d.ts.map +1 -1
- package/dist/lending-pairs/computeLendingPairs.js +26 -22
- package/dist/prices/defillama/index.d.ts.map +1 -1
- package/dist/prices/defillama/index.js +162 -151
- package/dist/prices/index.d.ts +3 -2
- package/dist/prices/index.d.ts.map +1 -1
- package/dist/prices/index.js +3 -2
- package/dist/prices/main-prices/addresses/aaveOracles.d.ts +159 -143
- package/dist/prices/main-prices/addresses/aaveOracles.d.ts.map +1 -1
- package/dist/prices/main-prices/addresses/aaveOracles.js +276 -260
- package/dist/prices/main-prices/addresses/morpho.d.ts.map +1 -1
- package/dist/prices/main-prices/addresses/morpho.js +114 -0
- package/dist/prices/main-prices/fetchOracleData.d.ts.map +1 -1
- package/dist/prices/main-prices/fetchOracleData.js +21 -9
- package/dist/prices/pendle/fetchPendlePrices.d.ts +7 -0
- package/dist/prices/pendle/fetchPendlePrices.d.ts.map +1 -0
- package/dist/prices/pendle/fetchPendlePrices.js +148 -0
- package/dist/prices/pendle/index.d.ts +2 -0
- package/dist/prices/pendle/index.d.ts.map +1 -0
- package/dist/prices/pendle/index.js +1 -0
- package/dist/types/apiReturnType.d.ts +2 -0
- package/dist/types/apiReturnType.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +10 -16
- package/dist/yields/index.d.ts.map +1 -1
- package/dist/yields/index.js +46 -33
- package/package.json +3 -6
- package/src/assets/liquidityThresholds.ts +22 -3
- package/src/flash-liquidity/fetchLiquidity.ts +298 -261
- package/src/flash-liquidity/types.ts +1 -0
- package/src/lending/aave-v3-type/publicCallBuild.ts +74 -68
- package/src/lending/aave-v3-type/publicCallParse.ts +8 -2
- package/src/lending/compound-v3/publicCallParse.ts +10 -3
- package/src/lending/fetchLender.ts +2 -2
- package/src/lending/morpho/convertPublic.ts +1 -1
- package/src/lending/user-data/types.ts +2 -2
- package/src/lending-pairs/computeLendingPairs.ts +423 -410
- package/src/prices/defillama/index.ts +233 -227
- package/src/prices/index.ts +3 -2
- package/src/prices/main-prices/addresses/aaveOracles.ts +292 -277
- package/src/prices/main-prices/addresses/morpho.ts +114 -0
- package/src/prices/main-prices/fetchOracleData.ts +29 -22
- package/src/prices/pendle/fetchPendlePrices.ts +208 -0
- package/src/prices/pendle/index.ts +1 -0
- package/src/types/apiReturnType.ts +42 -39
- package/src/utils/index.ts +11 -18
- package/src/yields/index.ts +205 -179
- package/test/flashLiquidity.test.ts +40 -0
- package/test/lenderData.test.ts +18 -13254
- package/test/mainPrices.test.ts +24 -19
- package/test/morphoPrice.test.ts +1 -1
- package/test/userDataAave.test.ts +73 -0
|
@@ -1,5 +1,119 @@
|
|
|
1
1
|
import { Chain } from '@1delta/asset-registry';
|
|
2
2
|
export const MrophoOracles = {
|
|
3
|
+
[Chain.ARBITRUM_ONE]: [
|
|
4
|
+
{
|
|
5
|
+
oracle: '0x8e02a9b9Cc29d783b2fCB71C3a72651B591cae31',
|
|
6
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
7
|
+
collateralAsset: '0x5979d7b546e38e414f7e9822514be443a4800529',
|
|
8
|
+
loanAssetDecimals: 6,
|
|
9
|
+
collateralAssetDecimals: 18,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
oracle: '0x3855b7833C7Cb22aDCAB28505D838A2015eA8457',
|
|
13
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
14
|
+
collateralAsset: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f',
|
|
15
|
+
loanAssetDecimals: 18,
|
|
16
|
+
collateralAssetDecimals: 8,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
oracle: '0x88193FcB705d29724A40Bb818eCAA47dD5F014d9',
|
|
20
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
21
|
+
collateralAsset: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f',
|
|
22
|
+
loanAssetDecimals: 6,
|
|
23
|
+
collateralAssetDecimals: 8,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
oracle: '0x9041D09213607A0E85190719e60d11125583612D',
|
|
27
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
28
|
+
collateralAsset: '0x5979d7b546e38e414f7e9822514be443a4800529',
|
|
29
|
+
loanAssetDecimals: 18,
|
|
30
|
+
collateralAssetDecimals: 18,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
oracle: '0x8e02a9b9Cc29d783b2fCB71C3a72651B591cae31',
|
|
34
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
35
|
+
collateralAsset: '0x5979d7b546e38e414f7e9822514be443a4800529',
|
|
36
|
+
loanAssetDecimals: 6,
|
|
37
|
+
collateralAssetDecimals: 18,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
oracle: '0x52CC7c3b27bb61D0a83785B5344acC919F8f7124',
|
|
41
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
42
|
+
collateralAsset: '0xddb46999f8891663a8f2828d25298f70416d7610',
|
|
43
|
+
loanAssetDecimals: 6,
|
|
44
|
+
collateralAssetDecimals: 18,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
oracle: '0xEDcAE878827fc68B9bC9c700CA17c20F811b1612',
|
|
48
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
49
|
+
collateralAsset: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f',
|
|
50
|
+
loanAssetDecimals: 6,
|
|
51
|
+
collateralAssetDecimals: 8,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
oracle: '0x4E49d73434a78866d217BE0B542CA868495CBc77',
|
|
55
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
56
|
+
collateralAsset: '0x35751007a407ca6feffe80b3cb397736d2cf4dbe',
|
|
57
|
+
loanAssetDecimals: 6,
|
|
58
|
+
collateralAssetDecimals: 18,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
oracle: '0x282FEB10549fde52bD61A6979424Ddf18A4971A2',
|
|
62
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
63
|
+
collateralAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
64
|
+
loanAssetDecimals: 6,
|
|
65
|
+
collateralAssetDecimals: 18,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
oracle: '0x282FEB10549fde52bD61A6979424Ddf18A4971A2',
|
|
69
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
70
|
+
collateralAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
71
|
+
loanAssetDecimals: 6,
|
|
72
|
+
collateralAssetDecimals: 18,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
oracle: '0x4E49d73434a78866d217BE0B542CA868495CBc77',
|
|
76
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
77
|
+
collateralAsset: '0x35751007a407ca6feffe80b3cb397736d2cf4dbe',
|
|
78
|
+
loanAssetDecimals: 6,
|
|
79
|
+
collateralAssetDecimals: 18,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
oracle: '0x52CC7c3b27bb61D0a83785B5344acC919F8f7124',
|
|
83
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
84
|
+
collateralAsset: '0xddb46999f8891663a8f2828d25298f70416d7610',
|
|
85
|
+
loanAssetDecimals: 6,
|
|
86
|
+
collateralAssetDecimals: 18,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
oracle: '0xa23175b3066672F4C5e07c6Fd21913efEA74e6EF',
|
|
90
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
91
|
+
collateralAsset: '0xec70dcb4a1efa46b8f2d97c310c9c4790ba5ffa8',
|
|
92
|
+
loanAssetDecimals: 18,
|
|
93
|
+
collateralAssetDecimals: 18,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
oracle: '0xE468929f1E6F065926c9C88E1E4Fd2a20005275e',
|
|
97
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
98
|
+
collateralAsset: '0x2416092f143378750bb29b79ed961ab195cceea5',
|
|
99
|
+
loanAssetDecimals: 18,
|
|
100
|
+
collateralAssetDecimals: 18,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
oracle: '0xAC55d7601C7108A9CFE3D1E0224984204089154F',
|
|
104
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
105
|
+
collateralAsset: '0x4186bfc76e2e237523cbc30fd220fe055156b41f',
|
|
106
|
+
loanAssetDecimals: 18,
|
|
107
|
+
collateralAssetDecimals: 18,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
oracle: '0xF287a5725E9e78B55cA3aEd614ce9bD8Ea6d5583',
|
|
111
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
112
|
+
collateralAsset: '0x35751007a407ca6feffe80b3cb397736d2cf4dbe',
|
|
113
|
+
loanAssetDecimals: 18,
|
|
114
|
+
collateralAssetDecimals: 18,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
3
117
|
[Chain.BASE]: [
|
|
4
118
|
{
|
|
5
119
|
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchOracleData.d.ts","sourceRoot":"","sources":["../../../src/prices/main-prices/fetchOracleData.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetchOracleData.d.ts","sourceRoot":"","sources":["../../../src/prices/main-prices/fetchOracleData.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAKlD,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,EAAE,cAAY,KAAG,MAY7D,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,OAAO,MAAM,EACb,eAAe,MAAM,EACrB,SAAS,MAAM,KACd,MAYF,CAAA;AAOD,UAAU,UAAU;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CACtB;AAID;;GAEG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,MAAM,EAAE,EAClB,cAAc,oBAAoB,KACjC,OAAO,CAAC,UAAU,CAiJpB,CAAA"}
|
|
@@ -9,6 +9,7 @@ import { formatEther, formatUnits } from 'viem';
|
|
|
9
9
|
import { getAaveAssets } from '../../assets';
|
|
10
10
|
import { chainlinkOracles, getChainLinkKeys, ChainlinkAggregatorIndexes, } from './addresses/chainlink';
|
|
11
11
|
import { fetchDefillamaData } from '../defillama';
|
|
12
|
+
import { fetchPendlePrices } from '../pendle';
|
|
12
13
|
import { multicallViemAbiArray } from '../../utils/multicall';
|
|
13
14
|
import { AAVE_STYLE_ORACLES } from './addresses/aaveOracles';
|
|
14
15
|
import { AAVES_PER_CHAIN } from '../../utils';
|
|
@@ -127,6 +128,7 @@ export const fetchMainPrices = async (chainIds, getEvmClient) => {
|
|
|
127
128
|
});
|
|
128
129
|
});
|
|
129
130
|
promises.push(fetchDefillamaData());
|
|
131
|
+
promises.push(fetchPendlePrices());
|
|
130
132
|
const result = await Promise.all(promises);
|
|
131
133
|
let data = {};
|
|
132
134
|
result.forEach((r) => {
|
|
@@ -272,13 +274,15 @@ function lowDecimalOracle(chainId, fork) {
|
|
|
272
274
|
const parseAaveResults = (chainId, data, queries) => {
|
|
273
275
|
let prices = {};
|
|
274
276
|
data.forEach((d, i) => {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
ASSET_META[chainId]
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
277
|
+
if (d !== '0x') {
|
|
278
|
+
const details = queries[i];
|
|
279
|
+
details.assets.forEach((a, j) => {
|
|
280
|
+
const oracleId = ASSET_META[chainId][a]?.assetGroup ??
|
|
281
|
+
ASSET_META[chainId]?.[a]?.symbol ??
|
|
282
|
+
chainId + '-' + a;
|
|
283
|
+
prices[oracleId] = formatAavePrice(d[j].toString(), lowDecimalOracle(chainId, details.fork));
|
|
284
|
+
});
|
|
285
|
+
}
|
|
282
286
|
});
|
|
283
287
|
return prices;
|
|
284
288
|
};
|
|
@@ -291,9 +295,17 @@ const parseMorphoResults = (chainId, data, queries, donePrices = {}) => {
|
|
|
291
295
|
const debtPrice = donePrices[oracleId];
|
|
292
296
|
const oracleIdCollateral = ASSET_META[chainId][collateralAsset]?.assetGroup ??
|
|
293
297
|
chainId + '-' + collateralAsset;
|
|
298
|
+
const collateralPrice = donePrices[oracleIdCollateral];
|
|
299
|
+
const priceDebtToCollateral = formatMorphoPrice(d.toString(), loanAssetDecimals, collateralAssetDecimals);
|
|
294
300
|
if (debtPrice) {
|
|
295
|
-
|
|
296
|
-
|
|
301
|
+
if (!prices[oracleIdCollateral])
|
|
302
|
+
prices[oracleIdCollateral] = priceDebtToCollateral * debtPrice;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
if (collateralPrice) {
|
|
306
|
+
if (!prices[oracleId])
|
|
307
|
+
prices[oracleId] = collateralPrice / priceDebtToCollateral;
|
|
308
|
+
}
|
|
297
309
|
}
|
|
298
310
|
});
|
|
299
311
|
return prices;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchPendlePrices.d.ts","sourceRoot":"","sources":["../../../src/prices/pendle/fetchPendlePrices.ts"],"names":[],"mappings":"AAsKA;;GAEG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC;IACjD,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CAC1B,CAAC,CAoCD"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const PENDLE_API_BASE = 'https://api-v2.pendle.finance/core';
|
|
2
|
+
const MARKETS_ENDPOINT = (chainId) => `${PENDLE_API_BASE}/v1/${chainId}/markets/active`;
|
|
3
|
+
const PRICES_ENDPOINT = (chainId, type = 'SY') => `${PENDLE_API_BASE}/v1/${chainId}/assets/prices?&type=${type}`;
|
|
4
|
+
const SUPPORTED_CHAINS = [
|
|
5
|
+
// '1', Disabled for now
|
|
6
|
+
'42161',
|
|
7
|
+
'10',
|
|
8
|
+
'56',
|
|
9
|
+
'8453',
|
|
10
|
+
'5000',
|
|
11
|
+
'146',
|
|
12
|
+
'80094',
|
|
13
|
+
];
|
|
14
|
+
let marketsCache = null;
|
|
15
|
+
let marketsCacheTimestamp = 0;
|
|
16
|
+
const MARKETS_CACHE_TTL = 5 * 60 * 1000; // 5mins
|
|
17
|
+
/**
|
|
18
|
+
* Fetch Pendle markets data for a specific chain
|
|
19
|
+
*/
|
|
20
|
+
async function fetchMarketsForChain(chainId) {
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(MARKETS_ENDPOINT(chainId));
|
|
23
|
+
const data = (await response.json());
|
|
24
|
+
return data.markets || [];
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error(`Error fetching markets for chain ${chainId}:`, error);
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fetch and cache Pendle markets data for all supported chains
|
|
33
|
+
*/
|
|
34
|
+
async function fetchPendleMarkets() {
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
if (marketsCache && now - marketsCacheTimestamp < MARKETS_CACHE_TTL) {
|
|
37
|
+
return marketsCache;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const allMarkets = [];
|
|
41
|
+
const promises = [];
|
|
42
|
+
for (const chainId of SUPPORTED_CHAINS) {
|
|
43
|
+
const chainMarkets = fetchMarketsForChain(chainId);
|
|
44
|
+
promises.push(chainMarkets);
|
|
45
|
+
}
|
|
46
|
+
const results = await Promise.all(promises);
|
|
47
|
+
allMarkets.push(...results.flat());
|
|
48
|
+
const result = { markets: allMarkets };
|
|
49
|
+
marketsCache = result;
|
|
50
|
+
marketsCacheTimestamp = now;
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Error fetching Pendle markets:', error);
|
|
55
|
+
// return cached data (if any, even if expired, it is better than nothing I guess)
|
|
56
|
+
return marketsCache || { markets: [] };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Fetch prices for a specific chain and token type
|
|
61
|
+
*/
|
|
62
|
+
async function fetchPendlePricesForChain(chainId, type = 'all') {
|
|
63
|
+
try {
|
|
64
|
+
// Fetch prices for different token types (PT, YT, SY, PENDLE_LP)
|
|
65
|
+
const types = type === 'all' ? ['PT', 'YT', 'SY', 'PENDLE_LP'] : [type];
|
|
66
|
+
let allPrices = {};
|
|
67
|
+
try {
|
|
68
|
+
const response = await fetch(PRICES_ENDPOINT(chainId, types.join(',')));
|
|
69
|
+
const data = (await response.json());
|
|
70
|
+
allPrices = data.prices;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error(`Error fetching prices for chain ${chainId}:`, error);
|
|
74
|
+
}
|
|
75
|
+
return allPrices;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(`Error fetching Pendle prices for chain ${chainId}:`, error);
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Extract relevant token addresses from markets data
|
|
84
|
+
* Note: Seperating the chainId from address is not really required since we do the same when we return results
|
|
85
|
+
* but it allows to extend the file later and use individual addresses (maybe), or we can simplify this
|
|
86
|
+
*/
|
|
87
|
+
function extractTokenAddressesFromMarkets(markets) {
|
|
88
|
+
const tokensByChain = {};
|
|
89
|
+
markets.forEach((market) => {
|
|
90
|
+
const chain = market.pt?.split('-')[0];
|
|
91
|
+
if (chain && !tokensByChain[chain]) {
|
|
92
|
+
tokensByChain[chain] = { pt: [], yt: [], sy: [] };
|
|
93
|
+
}
|
|
94
|
+
// Add token addresses to their respective chains
|
|
95
|
+
if (market.pt && chain) {
|
|
96
|
+
const address = market.pt.split('-')[1];
|
|
97
|
+
if (address && !tokensByChain[chain].pt.includes(address)) {
|
|
98
|
+
tokensByChain[chain].pt.push(address);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (market.yt && chain) {
|
|
102
|
+
const address = market.yt.split('-')[1];
|
|
103
|
+
if (address && !tokensByChain[chain].yt.includes(address)) {
|
|
104
|
+
tokensByChain[chain].yt.push(address);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (market.sy && chain) {
|
|
108
|
+
const address = market.sy.split('-')[1];
|
|
109
|
+
if (address && !tokensByChain[chain].sy.includes(address)) {
|
|
110
|
+
tokensByChain[chain].sy.push(address);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return tokensByChain;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Main function to fetch Pendle prices
|
|
118
|
+
*/
|
|
119
|
+
export async function fetchPendlePrices() {
|
|
120
|
+
try {
|
|
121
|
+
const marketsResponse = await fetchPendleMarkets();
|
|
122
|
+
if (!marketsResponse.markets.length) {
|
|
123
|
+
// console.warn('No Pendle markets found')
|
|
124
|
+
return {};
|
|
125
|
+
}
|
|
126
|
+
const tokensByChain = extractTokenAddressesFromMarkets(marketsResponse.markets);
|
|
127
|
+
const allPrices = {};
|
|
128
|
+
for (const chainId of SUPPORTED_CHAINS) {
|
|
129
|
+
if (tokensByChain[chainId]) {
|
|
130
|
+
// console.log(`Fetching Pendle prices for chain ${chainId}`)
|
|
131
|
+
const chainPrices = await fetchPendlePricesForChain(chainId, 'YT'); // only fetch YT prices
|
|
132
|
+
// create a chainId-address key for each token price
|
|
133
|
+
Object.entries(chainPrices).forEach(([address, price]) => {
|
|
134
|
+
if (price !== 0) {
|
|
135
|
+
const prefixedAddress = `${chainId}-${address}`;
|
|
136
|
+
allPrices[prefixedAddress] = price;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// console.log(`Fetched ${Object.keys(allPrices).length} Pendle token prices`)
|
|
142
|
+
return allPrices;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.error('Error in fetchPendlePrices:', error);
|
|
146
|
+
return {};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/prices/pendle/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fetchPendlePrices';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GenericCurrency } from '../lending';
|
|
1
2
|
export interface BaseYields {
|
|
2
3
|
variableBorrowRate: number;
|
|
3
4
|
stableBorrowRate: number;
|
|
@@ -29,6 +30,7 @@ interface EMode {
|
|
|
29
30
|
export interface PoolData {
|
|
30
31
|
poolId: string;
|
|
31
32
|
underlying: string;
|
|
33
|
+
asset: GenericCurrency;
|
|
32
34
|
totalDeposits: string;
|
|
33
35
|
totalDebtStable: string;
|
|
34
36
|
totalDebt: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiReturnType.d.ts","sourceRoot":"","sources":["../../src/types/apiReturnType.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IAEzB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,gBAAgB,EAAE,MAAM,CAAA;IAExB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAA;AAE3D,MAAM,WAAW,YAAa,SAAQ,UAAU;IAE9C,YAAY,EAAE,MAAM,CAAA;IAGpB,OAAO,CAAC,EAAE,UAAU,CAAA;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"apiReturnType.d.ts","sourceRoot":"","sources":["../../src/types/apiReturnType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,WAAW,UAAU;IAEzB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,gBAAgB,EAAE,MAAM,CAAA;IAExB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAA;AAE3D,MAAM,WAAW,YAAa,SAAQ,UAAU;IAE9C,YAAY,EAAE,MAAM,CAAA;IAGpB,OAAO,CAAC,EAAE,UAAU,CAAA;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,sBAAsB,EAAE,MAAM,CAAA;IAC9B,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,UAAU,UAAU;IAClB,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAA;CAChC;AAED,UAAU,KAAK;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,sBAAsB,EAAE,MAAM,CAAA;IAC9B,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,eAAe,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,gBAAgB,EAAE,MAAM,CAAA;IACxB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;IACpB,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,EAAE,UAAU,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,UAAU,CAAA;IAClB,gBAAgB,EAAE,OAAO,CAAA;IACzB,gBAAgB,EAAE,OAAO,CAAA;IACzB,SAAS,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,CAAC,OAAO,EAAE,MAAM,GAAG;QACjB,IAAI,EAAE;YACJ,CAAC,MAAM,EAAE,MAAM,GAAG;gBAChB,IAAI,EAAE;oBACJ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAA;iBAC3B,CAAA;gBACD,MAAM,EAAE;oBAAE,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAA;iBAAE,CAAA;gBACnC,OAAO,EAAE,MAAM,CAAA;aAChB,CAAA;SACF,CAAA;QACD,WAAW,EAAE,MAAM,CAAA;KACpB,CAAA;CACF,CAAA"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -3,12 +3,10 @@ export declare function isCompoundV3(lender: string): boolean;
|
|
|
3
3
|
export declare function isCompoundV3Type(lender: string): boolean;
|
|
4
4
|
export declare function isInit(lender: string): lender is Lender.INIT;
|
|
5
5
|
export declare function isMorphoType(lender: string): boolean;
|
|
6
|
-
export declare const AAVE_V3_2_PROTOCOLS: Lender[];
|
|
7
6
|
export declare function isAaveV3Type(lender: string): boolean;
|
|
8
|
-
export declare function isAaveV3Original(lender: string): boolean;
|
|
9
7
|
export declare function isAaveV2Type(lender: string): boolean;
|
|
10
8
|
export declare function isYLDR(lender: string): lender is Lender.YLDR;
|
|
11
|
-
export declare function isAaveV32Type(lender:
|
|
9
|
+
export declare function isAaveV32Type(lender: string): boolean;
|
|
12
10
|
export declare function isAaveType(lender: string): boolean;
|
|
13
11
|
export declare function isSwaylend(lender: string): boolean;
|
|
14
12
|
export declare const getLendersForChain: (c: string) => string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EAKP,MAAM,wBAAwB,CAAA;AAO/B,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,WAAgD;AAE3F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,WAAgD;AAE/F,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,yBAAmC;AAExE,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,WAE1C;AAID,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,WAE1C;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,WAE1C;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,yBAEpC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,WAE3C;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,WAExC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,WAExC;AAED,eAAO,MAAM,kBAAkB,GAAI,GAAG,MAAM,aA4B3C,CAAA;AAED,sCAAsC;AACtC,eAAO,MAAM,uBAAuB,GAAI,YAAY,MAAM,EAAE,EAAE,eAAe,MAAM,EAAE,KAAG,MAAM,EAS7F,CAAA;AAaD,mCAAmC;AACnC,eAAO,MAAM,eAAe;;CAAqB,CAAA;AAEjD,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,MAEpD,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,GAAG,MAAM,GAAG,SAAS,EACpC,wBAAgC,KAC/B,MAAM,EAOR,CAAA;AAGD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,WAE3C"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
import { AAVE_FORK_POOL_DATA, AAVE_STYLE_RESERVE_ASSETS, AAVE_V2_LENDERS, AAVE_V3_LENDERS, COMPOUND_BASE_TOKENS, COMPOUND_STYLE_RESERVE_ASSETS, INIT_STYLE_RESERVE_ASSETS, Lender, SWAYLEND_RESERVE_ASSETS, INIT_CONFIG_DATA, MORPHO_BLUE_POOL_DATA, } from "@1delta/asset-registry";
|
|
1
|
+
import { AAVE_FORK_POOL_DATA, AAVE_STYLE_RESERVE_ASSETS, AAVE_V2_LENDERS, AAVE_V3_LENDERS, COMPOUND_BASE_TOKENS, COMPOUND_STYLE_RESERVE_ASSETS, INIT_STYLE_RESERVE_ASSETS, Lender, SWAYLEND_RESERVE_ASSETS, INIT_CONFIG_DATA, MORPHO_BLUE_POOL_DATA, AAVE_V32_LENDERS, } from "@1delta/asset-registry";
|
|
2
2
|
import { uniq } from "lodash";
|
|
3
3
|
import { COMPOSERS } from "./constants";
|
|
4
|
-
|
|
4
|
+
import { zeroAddress } from "viem";
|
|
5
5
|
const COMPOUND_V3_KEY = "COMPOUND_V3";
|
|
6
|
-
export function isCompoundV3(lender) { return lender
|
|
7
|
-
export function isCompoundV3Type(lender) { return lender
|
|
6
|
+
export function isCompoundV3(lender) { return lender?.startsWith(COMPOUND_V3_KEY); }
|
|
7
|
+
export function isCompoundV3Type(lender) { return lender?.startsWith(COMPOUND_V3_KEY); }
|
|
8
8
|
export function isInit(lender) { return lender === Lender.INIT; }
|
|
9
9
|
export function isMorphoType(lender) {
|
|
10
|
-
return
|
|
11
|
-
Lender.MORPHO_BLUE
|
|
12
|
-
].includes(lender);
|
|
10
|
+
return lender?.startsWith("MORPHO_BLUE");
|
|
13
11
|
}
|
|
14
12
|
const SWAYLEND_KEY = "SWAYLEND";
|
|
15
|
-
export const AAVE_V3_2_PROTOCOLS = [Lender.AAVE_V3, Lender.AAVE_V3_ETHER_FI, Lender.AAVE_V3_PRIME];
|
|
16
13
|
export function isAaveV3Type(lender) {
|
|
17
14
|
return AAVE_V3_LENDERS.includes(lender);
|
|
18
15
|
}
|
|
19
|
-
export function isAaveV3Original(lender) {
|
|
20
|
-
return lender.startsWith(AAVE_V3_KEY);
|
|
21
|
-
}
|
|
22
16
|
export function isAaveV2Type(lender) {
|
|
23
17
|
return AAVE_V2_LENDERS.includes(lender);
|
|
24
18
|
}
|
|
@@ -26,13 +20,13 @@ export function isYLDR(lender) {
|
|
|
26
20
|
return lender === Lender.YLDR;
|
|
27
21
|
}
|
|
28
22
|
export function isAaveV32Type(lender) {
|
|
29
|
-
return
|
|
23
|
+
return AAVE_V32_LENDERS.includes(lender);
|
|
30
24
|
}
|
|
31
25
|
export function isAaveType(lender) {
|
|
32
26
|
return [...AAVE_V3_LENDERS, ...AAVE_V2_LENDERS].includes(lender);
|
|
33
27
|
}
|
|
34
28
|
export function isSwaylend(lender) {
|
|
35
|
-
return lender
|
|
29
|
+
return lender?.startsWith(SWAYLEND_KEY);
|
|
36
30
|
}
|
|
37
31
|
export const getLendersForChain = (c) => {
|
|
38
32
|
let lenders = [];
|
|
@@ -70,7 +64,7 @@ export const filterLendersByProtocol = (allLenders, protocolList) => {
|
|
|
70
64
|
}
|
|
71
65
|
const hasMorpho = protocolList.includes(Lender.MORPHO_BLUE);
|
|
72
66
|
// Filter lenders based on protocol list
|
|
73
|
-
return allLenders.filter((lender) => protocolList.includes(lender) || (hasMorpho && lender
|
|
67
|
+
return allLenders.filter((lender) => protocolList.includes(lender) || (hasMorpho && lender?.startsWith("MORPHO_BLUE")));
|
|
74
68
|
};
|
|
75
69
|
const getAavesForChain = () => {
|
|
76
70
|
let lenders = {};
|
|
@@ -86,7 +80,7 @@ const getAavesForChain = () => {
|
|
|
86
80
|
/** All aave protocols per chain */
|
|
87
81
|
export const AAVES_PER_CHAIN = getAavesForChain();
|
|
88
82
|
export const getComposerAddress = (chainId) => {
|
|
89
|
-
return COMPOSERS[chainId];
|
|
83
|
+
return COMPOSERS[chainId] ?? zeroAddress;
|
|
90
84
|
};
|
|
91
85
|
export const getLenderAssets = (chainId, lendingProtocol = Lender.AAVE_V3) => {
|
|
92
86
|
if (!chainId)
|
|
@@ -102,5 +96,5 @@ export const getLenderAssets = (chainId, lendingProtocol = Lender.AAVE_V3) => {
|
|
|
102
96
|
return [];
|
|
103
97
|
};
|
|
104
98
|
export function isMultiMarket(lender) {
|
|
105
|
-
return lender
|
|
99
|
+
return lender?.startsWith("MORPHO_BLUE");
|
|
106
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/yields/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/yields/index.ts"],"names":[],"mappings":"AAwCA,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,qBAAqB,EAAE,GAAG,CAAA;IAC1B,oBAAoB,EAAE,GAAG,CAAA;CAC1B;AAED,MAAM,WAAW,sBAAsB;IACrC,eAAe,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;IACxD,aAAa,EAAE;QACb,CAAC,OAAO,EAAE,MAAM,GAAG;YACjB,CAAC,MAAM,EAAE,MAAM,GAAG;gBAAE,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAA;aAAE,CAAA;SACzD,CAAA;KACF,CAAA;CACF;AAcD,eAAO,MAAM,kBAAkB,uCAoK9B,CAAA"}
|