@1delta/margin-fetcher 0.0.17 → 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/aave-v3-type/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/fetchUserData.d.ts.map +1 -1
- package/dist/lending/user-data/fetchUserData.js +1 -3
- package/dist/lending/user-data/morpho/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/morpho/userCallParse.js +2 -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/aave-v3-type/userCallParse.ts +2 -0
- package/src/lending/user-data/fetchUserData.ts +1 -4
- package/src/lending/user-data/morpho/userCallParse.ts +2 -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/data.ts +47979 -0
- 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
- package/test/userDataAll.test.ts +32 -41
|
@@ -9,6 +9,120 @@ export interface MrophoOracleInfo {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const MrophoOracles: { [c: string]: MrophoOracleInfo[] } = {
|
|
12
|
+
[Chain.ARBITRUM_ONE]: [
|
|
13
|
+
{
|
|
14
|
+
oracle: '0x8e02a9b9Cc29d783b2fCB71C3a72651B591cae31',
|
|
15
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
16
|
+
collateralAsset: '0x5979d7b546e38e414f7e9822514be443a4800529',
|
|
17
|
+
loanAssetDecimals: 6,
|
|
18
|
+
collateralAssetDecimals: 18,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
oracle: '0x3855b7833C7Cb22aDCAB28505D838A2015eA8457',
|
|
22
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
23
|
+
collateralAsset: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f',
|
|
24
|
+
loanAssetDecimals: 18,
|
|
25
|
+
collateralAssetDecimals: 8,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
oracle: '0x88193FcB705d29724A40Bb818eCAA47dD5F014d9',
|
|
29
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
30
|
+
collateralAsset: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f',
|
|
31
|
+
loanAssetDecimals: 6,
|
|
32
|
+
collateralAssetDecimals: 8,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
oracle: '0x9041D09213607A0E85190719e60d11125583612D',
|
|
36
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
37
|
+
collateralAsset: '0x5979d7b546e38e414f7e9822514be443a4800529',
|
|
38
|
+
loanAssetDecimals: 18,
|
|
39
|
+
collateralAssetDecimals: 18,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
oracle: '0x8e02a9b9Cc29d783b2fCB71C3a72651B591cae31',
|
|
43
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
44
|
+
collateralAsset: '0x5979d7b546e38e414f7e9822514be443a4800529',
|
|
45
|
+
loanAssetDecimals: 6,
|
|
46
|
+
collateralAssetDecimals: 18,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
oracle: '0x52CC7c3b27bb61D0a83785B5344acC919F8f7124',
|
|
50
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
51
|
+
collateralAsset: '0xddb46999f8891663a8f2828d25298f70416d7610',
|
|
52
|
+
loanAssetDecimals: 6,
|
|
53
|
+
collateralAssetDecimals: 18,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
oracle: '0xEDcAE878827fc68B9bC9c700CA17c20F811b1612',
|
|
57
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
58
|
+
collateralAsset: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f',
|
|
59
|
+
loanAssetDecimals: 6,
|
|
60
|
+
collateralAssetDecimals: 8,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
oracle: '0x4E49d73434a78866d217BE0B542CA868495CBc77',
|
|
64
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
65
|
+
collateralAsset: '0x35751007a407ca6feffe80b3cb397736d2cf4dbe',
|
|
66
|
+
loanAssetDecimals: 6,
|
|
67
|
+
collateralAssetDecimals: 18,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
oracle: '0x282FEB10549fde52bD61A6979424Ddf18A4971A2',
|
|
71
|
+
loanAsset: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
72
|
+
collateralAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
73
|
+
loanAssetDecimals: 6,
|
|
74
|
+
collateralAssetDecimals: 18,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
oracle: '0x282FEB10549fde52bD61A6979424Ddf18A4971A2',
|
|
78
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
79
|
+
collateralAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
80
|
+
loanAssetDecimals: 6,
|
|
81
|
+
collateralAssetDecimals: 18,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
oracle: '0x4E49d73434a78866d217BE0B542CA868495CBc77',
|
|
85
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
86
|
+
collateralAsset: '0x35751007a407ca6feffe80b3cb397736d2cf4dbe',
|
|
87
|
+
loanAssetDecimals: 6,
|
|
88
|
+
collateralAssetDecimals: 18,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
oracle: '0x52CC7c3b27bb61D0a83785B5344acC919F8f7124',
|
|
92
|
+
loanAsset: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
|
|
93
|
+
collateralAsset: '0xddb46999f8891663a8f2828d25298f70416d7610',
|
|
94
|
+
loanAssetDecimals: 6,
|
|
95
|
+
collateralAssetDecimals: 18,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
oracle: '0xa23175b3066672F4C5e07c6Fd21913efEA74e6EF',
|
|
99
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
100
|
+
collateralAsset: '0xec70dcb4a1efa46b8f2d97c310c9c4790ba5ffa8',
|
|
101
|
+
loanAssetDecimals: 18,
|
|
102
|
+
collateralAssetDecimals: 18,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
oracle: '0xE468929f1E6F065926c9C88E1E4Fd2a20005275e',
|
|
106
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
107
|
+
collateralAsset: '0x2416092f143378750bb29b79ed961ab195cceea5',
|
|
108
|
+
loanAssetDecimals: 18,
|
|
109
|
+
collateralAssetDecimals: 18,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
oracle: '0xAC55d7601C7108A9CFE3D1E0224984204089154F',
|
|
113
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
114
|
+
collateralAsset: '0x4186bfc76e2e237523cbc30fd220fe055156b41f',
|
|
115
|
+
loanAssetDecimals: 18,
|
|
116
|
+
collateralAssetDecimals: 18,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
oracle: '0xF287a5725E9e78B55cA3aEd614ce9bD8Ea6d5583',
|
|
120
|
+
loanAsset: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
121
|
+
collateralAsset: '0x35751007a407ca6feffe80b3cb397736d2cf4dbe',
|
|
122
|
+
loanAssetDecimals: 18,
|
|
123
|
+
collateralAssetDecimals: 18,
|
|
124
|
+
},
|
|
125
|
+
],
|
|
12
126
|
[Chain.BASE]: [
|
|
13
127
|
{
|
|
14
128
|
oracle: '0x663BECd10daE6C4A3Dcd89F1d76c1174199639B9',
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
ChainlinkAggregatorIndexes,
|
|
15
15
|
} from './addresses/chainlink'
|
|
16
16
|
import { fetchDefillamaData } from '../defillama'
|
|
17
|
+
import { fetchPendlePrices } from '../pendle'
|
|
17
18
|
import { multicallViemAbiArray } from '../../utils/multicall'
|
|
18
19
|
import { AAVE_STYLE_ORACLES } from './addresses/aaveOracles'
|
|
19
20
|
import { AAVES_PER_CHAIN } from '../../utils'
|
|
@@ -64,10 +65,6 @@ interface OracleData {
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
type QueryAave = { oracle: string; assets: string[]; fork: string }
|
|
67
|
-
type QueryMorpho = {
|
|
68
|
-
oracle: string
|
|
69
|
-
assets: [string, string, number, number][]
|
|
70
|
-
}
|
|
71
68
|
|
|
72
69
|
/**
|
|
73
70
|
* Fetches Aave and uniswap V2 oracle data
|
|
@@ -212,6 +209,7 @@ export const fetchMainPrices = async (
|
|
|
212
209
|
})
|
|
213
210
|
})
|
|
214
211
|
promises.push(fetchDefillamaData())
|
|
212
|
+
promises.push(fetchPendlePrices())
|
|
215
213
|
const result = await Promise.all(promises)
|
|
216
214
|
let data: any = {}
|
|
217
215
|
result.forEach((r) => {
|
|
@@ -389,17 +387,19 @@ const parseAaveResults = (
|
|
|
389
387
|
let prices: any = {}
|
|
390
388
|
|
|
391
389
|
data.forEach((d, i) => {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
390
|
+
if (d !== '0x') {
|
|
391
|
+
const details = queries[i]
|
|
392
|
+
details.assets.forEach((a, j) => {
|
|
393
|
+
const oracleId =
|
|
394
|
+
ASSET_META[chainId][a]?.assetGroup ??
|
|
395
|
+
ASSET_META[chainId]?.[a]?.symbol ??
|
|
396
|
+
chainId + '-' + a
|
|
397
|
+
prices[oracleId] = formatAavePrice(
|
|
398
|
+
d[j].toString(),
|
|
399
|
+
lowDecimalOracle(chainId, details.fork as any),
|
|
400
|
+
)
|
|
401
|
+
})
|
|
402
|
+
}
|
|
403
403
|
})
|
|
404
404
|
|
|
405
405
|
return prices
|
|
@@ -427,16 +427,23 @@ const parseMorphoResults = (
|
|
|
427
427
|
const oracleIdCollateral =
|
|
428
428
|
ASSET_META[chainId][collateralAsset]?.assetGroup ??
|
|
429
429
|
chainId + '-' + collateralAsset
|
|
430
|
+
const collateralPrice = donePrices[oracleIdCollateral]
|
|
431
|
+
const priceDebtToCollateral = formatMorphoPrice(
|
|
432
|
+
d.toString(),
|
|
433
|
+
loanAssetDecimals,
|
|
434
|
+
collateralAssetDecimals,
|
|
435
|
+
)
|
|
436
|
+
|
|
430
437
|
if (debtPrice) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
438
|
+
if (!prices[oracleIdCollateral])
|
|
439
|
+
prices[oracleIdCollateral] = priceDebtToCollateral * debtPrice
|
|
440
|
+
} else {
|
|
441
|
+
if (collateralPrice) {
|
|
442
|
+
if (!prices[oracleId])
|
|
443
|
+
prices[oracleId] = collateralPrice / priceDebtToCollateral
|
|
444
|
+
}
|
|
437
445
|
}
|
|
438
446
|
})
|
|
439
|
-
|
|
440
447
|
return prices
|
|
441
448
|
}
|
|
442
449
|
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
const PENDLE_API_BASE = 'https://api-v2.pendle.finance/core'
|
|
2
|
+
const MARKETS_ENDPOINT = (chainId: string) =>
|
|
3
|
+
`${PENDLE_API_BASE}/v1/${chainId}/markets/active`
|
|
4
|
+
const PRICES_ENDPOINT = (chainId: string, type: string = 'SY') =>
|
|
5
|
+
`${PENDLE_API_BASE}/v1/${chainId}/assets/prices?&type=${type}`
|
|
6
|
+
|
|
7
|
+
const SUPPORTED_CHAINS = [
|
|
8
|
+
// '1', Disabled for now
|
|
9
|
+
'42161',
|
|
10
|
+
'10',
|
|
11
|
+
'56',
|
|
12
|
+
'8453',
|
|
13
|
+
'5000',
|
|
14
|
+
'146',
|
|
15
|
+
'80094',
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
let marketsCache: PendleMarketResponse | null = null
|
|
19
|
+
let marketsCacheTimestamp: number = 0
|
|
20
|
+
const MARKETS_CACHE_TTL = 5 * 60 * 1000 // 5mins
|
|
21
|
+
|
|
22
|
+
interface PendleMarket {
|
|
23
|
+
name: string
|
|
24
|
+
address: string
|
|
25
|
+
expiry: string
|
|
26
|
+
pt: string
|
|
27
|
+
yt: string
|
|
28
|
+
sy: string
|
|
29
|
+
underlyingAsset: string
|
|
30
|
+
details: any
|
|
31
|
+
isNew: boolean
|
|
32
|
+
isPrime: boolean
|
|
33
|
+
timestamp: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface PendleMarketResponse {
|
|
37
|
+
markets: PendleMarket[]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface PendlePricesResponse {
|
|
41
|
+
prices: { [address: string]: number }
|
|
42
|
+
total: number
|
|
43
|
+
skip: number
|
|
44
|
+
limit: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Fetch Pendle markets data for a specific chain
|
|
49
|
+
*/
|
|
50
|
+
async function fetchMarketsForChain(chainId: string): Promise<PendleMarket[]> {
|
|
51
|
+
try {
|
|
52
|
+
const response = await fetch(MARKETS_ENDPOINT(chainId))
|
|
53
|
+
const data = (await response.json()) as PendleMarketResponse
|
|
54
|
+
return data.markets || []
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(`Error fetching markets for chain ${chainId}:`, error)
|
|
57
|
+
return []
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Fetch and cache Pendle markets data for all supported chains
|
|
63
|
+
*/
|
|
64
|
+
async function fetchPendleMarkets(): Promise<PendleMarketResponse> {
|
|
65
|
+
const now = Date.now()
|
|
66
|
+
|
|
67
|
+
if (marketsCache && now - marketsCacheTimestamp < MARKETS_CACHE_TTL) {
|
|
68
|
+
return marketsCache
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const allMarkets: PendleMarket[] = []
|
|
73
|
+
const promises = []
|
|
74
|
+
|
|
75
|
+
for (const chainId of SUPPORTED_CHAINS) {
|
|
76
|
+
const chainMarkets = fetchMarketsForChain(chainId)
|
|
77
|
+
promises.push(chainMarkets)
|
|
78
|
+
}
|
|
79
|
+
const results = await Promise.all(promises)
|
|
80
|
+
|
|
81
|
+
allMarkets.push(...results.flat())
|
|
82
|
+
|
|
83
|
+
const result: PendleMarketResponse = { markets: allMarkets }
|
|
84
|
+
marketsCache = result
|
|
85
|
+
marketsCacheTimestamp = now
|
|
86
|
+
|
|
87
|
+
return result
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error('Error fetching Pendle markets:', error)
|
|
90
|
+
// return cached data (if any, even if expired, it is better than nothing I guess)
|
|
91
|
+
return marketsCache || { markets: [] }
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Fetch prices for a specific chain and token type
|
|
97
|
+
*/
|
|
98
|
+
async function fetchPendlePricesForChain(
|
|
99
|
+
chainId: string,
|
|
100
|
+
type: string = 'all',
|
|
101
|
+
): Promise<{ [address: string]: number }> {
|
|
102
|
+
try {
|
|
103
|
+
// Fetch prices for different token types (PT, YT, SY, PENDLE_LP)
|
|
104
|
+
const types = type === 'all' ? ['PT', 'YT', 'SY', 'PENDLE_LP'] : [type]
|
|
105
|
+
let allPrices: { [address: string]: number } = {}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const response = await fetch(PRICES_ENDPOINT(chainId, types.join(',')))
|
|
109
|
+
const data = (await response.json()) as PendlePricesResponse
|
|
110
|
+
allPrices = data.prices
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error(`Error fetching prices for chain ${chainId}:`, error)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return allPrices
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error(`Error fetching Pendle prices for chain ${chainId}:`, error)
|
|
118
|
+
return {}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Extract relevant token addresses from markets data
|
|
124
|
+
* Note: Seperating the chainId from address is not really required since we do the same when we return results
|
|
125
|
+
* but it allows to extend the file later and use individual addresses (maybe), or we can simplify this
|
|
126
|
+
*/
|
|
127
|
+
function extractTokenAddressesFromMarkets(markets: PendleMarket[]): {
|
|
128
|
+
[chainId: string]: { pt: string[]; yt: string[]; sy: string[] }
|
|
129
|
+
} {
|
|
130
|
+
const tokensByChain: {
|
|
131
|
+
[chainId: string]: { pt: string[]; yt: string[]; sy: string[] }
|
|
132
|
+
} = {}
|
|
133
|
+
|
|
134
|
+
markets.forEach((market) => {
|
|
135
|
+
const chain = market.pt?.split('-')[0]
|
|
136
|
+
|
|
137
|
+
if (chain && !tokensByChain[chain]) {
|
|
138
|
+
tokensByChain[chain] = { pt: [], yt: [], sy: [] }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Add token addresses to their respective chains
|
|
142
|
+
if (market.pt && chain) {
|
|
143
|
+
const address = market.pt.split('-')[1]
|
|
144
|
+
if (address && !tokensByChain[chain].pt.includes(address)) {
|
|
145
|
+
tokensByChain[chain].pt.push(address)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (market.yt && chain) {
|
|
150
|
+
const address = market.yt.split('-')[1]
|
|
151
|
+
if (address && !tokensByChain[chain].yt.includes(address)) {
|
|
152
|
+
tokensByChain[chain].yt.push(address)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (market.sy && chain) {
|
|
157
|
+
const address = market.sy.split('-')[1]
|
|
158
|
+
if (address && !tokensByChain[chain].sy.includes(address)) {
|
|
159
|
+
tokensByChain[chain].sy.push(address)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
return tokensByChain
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Main function to fetch Pendle prices
|
|
169
|
+
*/
|
|
170
|
+
export async function fetchPendlePrices(): Promise<{
|
|
171
|
+
[address: string]: number
|
|
172
|
+
}> {
|
|
173
|
+
try {
|
|
174
|
+
const marketsResponse = await fetchPendleMarkets()
|
|
175
|
+
|
|
176
|
+
if (!marketsResponse.markets.length) {
|
|
177
|
+
// console.warn('No Pendle markets found')
|
|
178
|
+
return {}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const tokensByChain = extractTokenAddressesFromMarkets(
|
|
182
|
+
marketsResponse.markets,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
const allPrices: { [address: string]: number } = {}
|
|
186
|
+
|
|
187
|
+
for (const chainId of SUPPORTED_CHAINS) {
|
|
188
|
+
if (tokensByChain[chainId]) {
|
|
189
|
+
// console.log(`Fetching Pendle prices for chain ${chainId}`)
|
|
190
|
+
const chainPrices = await fetchPendlePricesForChain(chainId, 'YT') // only fetch YT prices
|
|
191
|
+
|
|
192
|
+
// create a chainId-address key for each token price
|
|
193
|
+
Object.entries(chainPrices).forEach(([address, price]) => {
|
|
194
|
+
if (price !== 0) {
|
|
195
|
+
const prefixedAddress = `${chainId}-${address}`
|
|
196
|
+
allPrices[prefixedAddress] = price
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// console.log(`Fetched ${Object.keys(allPrices).length} Pendle token prices`)
|
|
203
|
+
return allPrices
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.error('Error in fetchPendlePrices:', error)
|
|
206
|
+
return {}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fetchPendlePrices'
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GenericCurrency } from '../lending'
|
|
2
|
+
|
|
1
3
|
export interface BaseYields {
|
|
2
4
|
// borrow interest rates
|
|
3
5
|
variableBorrowRate: number
|
|
@@ -17,51 +19,52 @@ export interface LenderYields extends BaseYields {
|
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export interface ConfigEntry {
|
|
20
|
-
category: number
|
|
21
|
-
borrowCollateralFactor: number
|
|
22
|
-
collateralFactor: number
|
|
23
|
-
borrowFactor: number
|
|
22
|
+
category: number
|
|
23
|
+
borrowCollateralFactor: number
|
|
24
|
+
collateralFactor: number
|
|
25
|
+
borrowFactor: number
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
interface PoolConfig {
|
|
27
|
-
[category: number]: ConfigEntry
|
|
29
|
+
[category: number]: ConfigEntry
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
interface EMode {
|
|
31
|
-
category: number
|
|
32
|
-
label: string
|
|
33
|
-
borrowCollateralFactor: number
|
|
34
|
-
collateralFactor: number
|
|
35
|
-
borrowFactor: number
|
|
33
|
+
category: number
|
|
34
|
+
label: string
|
|
35
|
+
borrowCollateralFactor: number
|
|
36
|
+
collateralFactor: number
|
|
37
|
+
borrowFactor: number
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export interface PoolData {
|
|
39
|
-
poolId: string
|
|
40
|
-
underlying: string
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
41
|
+
poolId: string
|
|
42
|
+
underlying: string
|
|
43
|
+
asset: GenericCurrency
|
|
44
|
+
totalDeposits: string
|
|
45
|
+
totalDebtStable: string
|
|
46
|
+
totalDebt: string
|
|
47
|
+
totalLiquidity: number
|
|
48
|
+
totalDepositsUSD: number
|
|
49
|
+
totalDebtStableUSD: number
|
|
50
|
+
totalDebtUSD: number
|
|
51
|
+
totalLiquidityUSD: number
|
|
52
|
+
depositRate: number
|
|
53
|
+
variableBorrowRate: number
|
|
54
|
+
stableBorrowRate: number
|
|
55
|
+
stakingYield: number
|
|
56
|
+
rewards: RewardsMap
|
|
57
|
+
decimals: number
|
|
58
|
+
config: PoolConfig
|
|
59
|
+
collateralActive: boolean
|
|
60
|
+
borrowingEnabled: boolean
|
|
61
|
+
hasStable: boolean
|
|
62
|
+
isActive: boolean
|
|
63
|
+
isFrozen: boolean
|
|
64
|
+
eMode: EMode
|
|
65
|
+
borrowCap: number
|
|
66
|
+
supplyCap: number
|
|
67
|
+
debtCeiling: string
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
export type LenderData = {
|
|
@@ -70,11 +73,11 @@ export type LenderData = {
|
|
|
70
73
|
[lender: string]: {
|
|
71
74
|
data: {
|
|
72
75
|
[poolId: string]: PoolData
|
|
73
|
-
}
|
|
76
|
+
}
|
|
74
77
|
eModes: { [modeId: number]: EMode }
|
|
75
78
|
chainId: string
|
|
76
79
|
}
|
|
77
|
-
}
|
|
80
|
+
}
|
|
78
81
|
lastFetched: number
|
|
79
82
|
}
|
|
80
|
-
}
|
|
83
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -10,37 +10,30 @@ import {
|
|
|
10
10
|
SWAYLEND_RESERVE_ASSETS,
|
|
11
11
|
INIT_CONFIG_DATA,
|
|
12
12
|
MORPHO_BLUE_POOL_DATA,
|
|
13
|
+
AAVE_V32_LENDERS,
|
|
13
14
|
} from "@1delta/asset-registry"
|
|
14
15
|
import { uniq } from "lodash"
|
|
15
16
|
import { COMPOSERS } from "./constants"
|
|
17
|
+
import { zeroAddress } from "viem"
|
|
16
18
|
|
|
17
|
-
const AAVE_V3_KEY = "AAVE_V3"
|
|
18
19
|
const COMPOUND_V3_KEY = "COMPOUND_V3"
|
|
19
20
|
|
|
20
|
-
export function isCompoundV3(lender: string) { return lender
|
|
21
|
+
export function isCompoundV3(lender: string) { return lender?.startsWith(COMPOUND_V3_KEY) }
|
|
21
22
|
|
|
22
|
-
export function isCompoundV3Type(lender: string) { return lender
|
|
23
|
+
export function isCompoundV3Type(lender: string) { return lender?.startsWith(COMPOUND_V3_KEY) }
|
|
23
24
|
|
|
24
25
|
export function isInit(lender: string) { return lender === Lender.INIT }
|
|
25
26
|
|
|
26
27
|
export function isMorphoType(lender: string) {
|
|
27
|
-
return
|
|
28
|
-
Lender.MORPHO_BLUE
|
|
29
|
-
].includes(lender as any)
|
|
28
|
+
return lender?.startsWith("MORPHO_BLUE")
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
const SWAYLEND_KEY = "SWAYLEND"
|
|
33
32
|
|
|
34
|
-
export const AAVE_V3_2_PROTOCOLS = [Lender.AAVE_V3, Lender.AAVE_V3_ETHER_FI, Lender.AAVE_V3_PRIME]
|
|
35
|
-
|
|
36
33
|
export function isAaveV3Type(lender: string) {
|
|
37
34
|
return AAVE_V3_LENDERS.includes(lender as any)
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
export function isAaveV3Original(lender: string) {
|
|
41
|
-
return lender.startsWith(AAVE_V3_KEY)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
37
|
export function isAaveV2Type(lender: string) {
|
|
45
38
|
return AAVE_V2_LENDERS.includes(lender as any)
|
|
46
39
|
}
|
|
@@ -49,8 +42,8 @@ export function isYLDR(lender: string) {
|
|
|
49
42
|
return lender === Lender.YLDR
|
|
50
43
|
}
|
|
51
44
|
|
|
52
|
-
export function isAaveV32Type(lender:
|
|
53
|
-
return
|
|
45
|
+
export function isAaveV32Type(lender: string) {
|
|
46
|
+
return AAVE_V32_LENDERS.includes(lender as any)
|
|
54
47
|
}
|
|
55
48
|
|
|
56
49
|
export function isAaveType(lender: string) {
|
|
@@ -58,7 +51,7 @@ export function isAaveType(lender: string) {
|
|
|
58
51
|
}
|
|
59
52
|
|
|
60
53
|
export function isSwaylend(lender: string) {
|
|
61
|
-
return lender
|
|
54
|
+
return lender?.startsWith(SWAYLEND_KEY)
|
|
62
55
|
}
|
|
63
56
|
|
|
64
57
|
export const getLendersForChain = (c: string) => {
|
|
@@ -100,7 +93,7 @@ export const filterLendersByProtocol = (allLenders: string[], protocolList?: str
|
|
|
100
93
|
|
|
101
94
|
const hasMorpho = protocolList.includes(Lender.MORPHO_BLUE)
|
|
102
95
|
// Filter lenders based on protocol list
|
|
103
|
-
return allLenders.filter((lender) => protocolList.includes(lender) || (hasMorpho && lender
|
|
96
|
+
return allLenders.filter((lender) => protocolList.includes(lender) || (hasMorpho && lender?.startsWith("MORPHO_BLUE")))
|
|
104
97
|
}
|
|
105
98
|
|
|
106
99
|
const getAavesForChain = () => {
|
|
@@ -118,7 +111,7 @@ const getAavesForChain = () => {
|
|
|
118
111
|
export const AAVES_PER_CHAIN = getAavesForChain()
|
|
119
112
|
|
|
120
113
|
export const getComposerAddress = (chainId: string): string => {
|
|
121
|
-
return COMPOSERS[chainId as keyof typeof COMPOSERS]
|
|
114
|
+
return COMPOSERS[chainId as keyof typeof COMPOSERS] ?? zeroAddress
|
|
122
115
|
}
|
|
123
116
|
|
|
124
117
|
export const getLenderAssets = (
|
|
@@ -135,5 +128,5 @@ export const getLenderAssets = (
|
|
|
135
128
|
|
|
136
129
|
|
|
137
130
|
export function isMultiMarket(lender: string) {
|
|
138
|
-
return lender
|
|
131
|
+
return lender?.startsWith("MORPHO_BLUE")
|
|
139
132
|
}
|