@1delta/margin-fetcher 0.0.14 → 0.0.16
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/lending/aave-v3-type/publicCallParse.d.ts +4 -4
- package/dist/lending/aave-v3-type/publicCallParse.d.ts.map +1 -1
- package/dist/lending/aave-v3-type/publicCallParse.js +68 -44
- package/dist/lending/fetchLender.d.ts.map +1 -1
- package/dist/lending/user-data/morpho/userCallParse.d.ts +2 -2
- package/dist/lending/user-data/morpho/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/morpho/userCallParse.js +92 -26
- package/dist/prices/main-prices/fetchOracleData.d.ts.map +1 -1
- package/dist/prices/main-prices/fetchOracleData.js +8 -3
- package/dist/types/providers.d.ts +1 -1
- package/dist/types/providers.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/lending/aave-v3-type/publicCallParse.ts +312 -110
- package/src/lending/fetchLender.ts +1 -0
- package/src/lending/user-data/morpho/userCallParse.ts +138 -55
- package/src/prices/main-prices/fetchOracleData.ts +11 -7
- package/src/types/providers.ts +4 -3
- package/test/userDataMorpho.test.ts +1 -0
|
@@ -1,39 +1,62 @@
|
|
|
1
|
-
|
|
2
1
|
import {
|
|
3
2
|
AaveV3GeneralPublicResponse,
|
|
4
3
|
AaveV3GetreserveConfigDataIndexes,
|
|
5
4
|
AaveV3GetReservesIndexes,
|
|
6
5
|
YLDRTypeGetReserveConfigurationData,
|
|
7
|
-
YLDRTypeGetReserveDataIndexes
|
|
8
|
-
} from
|
|
9
|
-
import { AAVE_V3_EMODES } from
|
|
10
|
-
import { AdditionalYields } from
|
|
11
|
-
import { BPS, formatAaveRawApyToApr, parseRawAmount } from
|
|
12
|
-
import { Lender } from
|
|
13
|
-
import {
|
|
14
|
-
|
|
6
|
+
YLDRTypeGetReserveDataIndexes,
|
|
7
|
+
} from './types'
|
|
8
|
+
import { AAVE_V3_EMODES } from './publicCallBuild'
|
|
9
|
+
import { AdditionalYields } from '../../types'
|
|
10
|
+
import { BPS, formatAaveRawApyToApr, parseRawAmount } from '../../utils/parsing'
|
|
11
|
+
import { Lender } from '@1delta/asset-registry'
|
|
12
|
+
import {
|
|
13
|
+
getAaveAssets,
|
|
14
|
+
getAssetMeta,
|
|
15
|
+
LENDER_MODE_NO_MODE,
|
|
16
|
+
toGenericPriceKey,
|
|
17
|
+
toOracleKey,
|
|
18
|
+
} from '../../assets'
|
|
19
|
+
import { GenericTokenList } from '../types'
|
|
15
20
|
|
|
16
21
|
export const getAaveV3ReservesDataConverter = (
|
|
17
22
|
lender: Lender,
|
|
18
23
|
chainId: string,
|
|
19
24
|
prices: { [asset: string]: number },
|
|
20
25
|
additionalYields: AdditionalYields,
|
|
21
|
-
tokenList: GenericTokenList = {}
|
|
26
|
+
tokenList: GenericTokenList = {},
|
|
22
27
|
): [(data: any[]) => AaveV3GeneralPublicResponse | undefined, number] => {
|
|
23
|
-
if (lender.
|
|
28
|
+
if (lender.startsWith('AAVE_V3'))
|
|
29
|
+
return parseAave32(
|
|
30
|
+
chainId,
|
|
31
|
+
lender,
|
|
32
|
+
prices,
|
|
33
|
+
additionalYields,
|
|
34
|
+
tokenList,
|
|
35
|
+
) as any
|
|
24
36
|
switch (lender) {
|
|
25
37
|
/** AAVE V3 style with rewards from state */
|
|
26
|
-
case Lender.YLDR:
|
|
38
|
+
case Lender.YLDR:
|
|
39
|
+
return parseYLDRCall(
|
|
40
|
+
chainId,
|
|
41
|
+
lender,
|
|
42
|
+
additionalYields,
|
|
43
|
+
prices,
|
|
44
|
+
tokenList,
|
|
45
|
+
) as any
|
|
27
46
|
default: {
|
|
28
47
|
const assetsToQuery = getAaveAssets(chainId, lender)
|
|
29
|
-
const expectedNumberOfCalls =
|
|
48
|
+
const expectedNumberOfCalls =
|
|
49
|
+
assetsToQuery.length * 6 + AAVE_V3_EMODES.length + 1
|
|
30
50
|
|
|
31
51
|
return [
|
|
32
52
|
(data: any[]) => {
|
|
33
53
|
if (data.length !== expectedNumberOfCalls) {
|
|
34
54
|
return undefined
|
|
35
55
|
}
|
|
36
|
-
const emodeDataResult = data.slice(
|
|
56
|
+
const emodeDataResult = data.slice(
|
|
57
|
+
assetsToQuery.length * 6,
|
|
58
|
+
assetsToQuery.length * 6 + AAVE_V3_EMODES.length,
|
|
59
|
+
)
|
|
37
60
|
const resultReserves: any = {}
|
|
38
61
|
const decimalsCeiling = data[expectedNumberOfCalls - 1]
|
|
39
62
|
|
|
@@ -46,7 +69,7 @@ export const getAaveV3ReservesDataConverter = (
|
|
|
46
69
|
label: rawCfg.label,
|
|
47
70
|
borrowCollateralFactor: rawCfg.ltv / BPS,
|
|
48
71
|
collateralFactor: rawCfg.liquidationThreshold / BPS,
|
|
49
|
-
borrowFactor: 1
|
|
72
|
+
borrowFactor: 1,
|
|
50
73
|
}
|
|
51
74
|
})
|
|
52
75
|
|
|
@@ -61,16 +84,38 @@ export const getAaveV3ReservesDataConverter = (
|
|
|
61
84
|
const debtCeiling = data[i * 6 + 4]
|
|
62
85
|
const reserveEMode = data[i * 6 + 5]
|
|
63
86
|
|
|
64
|
-
const assetMeta = tokenList[asset] ?? {
|
|
87
|
+
const assetMeta = tokenList[asset] ?? {
|
|
88
|
+
...getAssetMeta(chainId, asset),
|
|
89
|
+
address: asset,
|
|
90
|
+
}
|
|
65
91
|
|
|
66
92
|
const decimals = assetMeta?.decimals ?? 18
|
|
67
93
|
|
|
68
|
-
const totalDeposits = parseRawAmount(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
94
|
+
const totalDeposits = parseRawAmount(
|
|
95
|
+
reserveData?.[AaveV3GetReservesIndexes.totalAToken]?.toString(),
|
|
96
|
+
decimals,
|
|
97
|
+
)
|
|
98
|
+
const totalDebtStable = parseRawAmount(
|
|
99
|
+
reserveData?.[
|
|
100
|
+
AaveV3GetReservesIndexes.totalStableDebt
|
|
101
|
+
]?.toString(),
|
|
102
|
+
decimals,
|
|
103
|
+
)
|
|
104
|
+
const totalDebt = parseRawAmount(
|
|
105
|
+
reserveData?.[
|
|
106
|
+
AaveV3GetReservesIndexes.totalVariableDebt
|
|
107
|
+
]?.toString(),
|
|
108
|
+
decimals,
|
|
109
|
+
)
|
|
110
|
+
const liquidity =
|
|
111
|
+
Number(totalDeposits) -
|
|
112
|
+
Number(totalDebt) -
|
|
113
|
+
Number(totalDebtStable)
|
|
114
|
+
const price =
|
|
115
|
+
prices[
|
|
116
|
+
toOracleKey(assetMeta?.assetGroup) ??
|
|
117
|
+
toGenericPriceKey(asset, chainId)
|
|
118
|
+
]
|
|
74
119
|
|
|
75
120
|
resultReserves[asset] = {
|
|
76
121
|
poolId: asset,
|
|
@@ -87,38 +132,78 @@ export const getAaveV3ReservesDataConverter = (
|
|
|
87
132
|
totalDebtUSD: Number(totalDebt) * price,
|
|
88
133
|
totalLiquidityUSD: liquidity * price,
|
|
89
134
|
// rates
|
|
90
|
-
depositRate: formatAaveRawApyToApr(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
135
|
+
depositRate: formatAaveRawApyToApr(
|
|
136
|
+
reserveData?.[
|
|
137
|
+
AaveV3GetReservesIndexes.liquidityRate
|
|
138
|
+
]?.toString(),
|
|
139
|
+
),
|
|
140
|
+
variableBorrowRate: formatAaveRawApyToApr(
|
|
141
|
+
reserveData?.[
|
|
142
|
+
AaveV3GetReservesIndexes.variableBorrowRate
|
|
143
|
+
]?.toString(),
|
|
144
|
+
),
|
|
145
|
+
stableBorrowRate: formatAaveRawApyToApr(
|
|
146
|
+
reserveData?.[
|
|
147
|
+
AaveV3GetReservesIndexes.stableBorrowRate
|
|
148
|
+
]?.toString(),
|
|
149
|
+
),
|
|
150
|
+
stakingYield:
|
|
151
|
+
additionalYields.intrinsicYields[
|
|
152
|
+
toOracleKey(assetMeta?.assetGroup)
|
|
153
|
+
] ?? 0,
|
|
94
154
|
// rewards
|
|
95
155
|
rewards: {},
|
|
96
156
|
}
|
|
97
157
|
const eModeCategory = Number(reserveEMode?.toString())
|
|
98
158
|
resultReserves[asset] = {
|
|
99
159
|
...resultReserves[asset],
|
|
100
|
-
decimals: Number(
|
|
160
|
+
decimals: Number(
|
|
161
|
+
configData?.[AaveV3GetreserveConfigDataIndexes.decimals],
|
|
162
|
+
),
|
|
101
163
|
|
|
102
164
|
config: {
|
|
103
|
-
...populateEModes(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
165
|
+
...populateEModes(
|
|
166
|
+
Number(configData?.[AaveV3GetreserveConfigDataIndexes.ltv]) /
|
|
167
|
+
BPS,
|
|
168
|
+
Number(
|
|
169
|
+
configData?.[
|
|
170
|
+
AaveV3GetreserveConfigDataIndexes.liquidationThreshold
|
|
171
|
+
],
|
|
172
|
+
) / BPS,
|
|
173
|
+
),
|
|
174
|
+
...(eModeCategory !== 0
|
|
175
|
+
? {
|
|
176
|
+
[eModeCategory]: {
|
|
177
|
+
category: eModeCategory,
|
|
178
|
+
label: eModeConfigs[eModeCategory]?.label ?? 'Default',
|
|
179
|
+
borrowCollateralFactor:
|
|
180
|
+
eModeConfigs[eModeCategory]?.borrowCollateralFactor ??
|
|
181
|
+
0,
|
|
182
|
+
collateralFactor:
|
|
183
|
+
eModeConfigs[eModeCategory]?.collateralFactor ?? 0,
|
|
184
|
+
borrowFactor: 1,
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
: {}),
|
|
114
188
|
},
|
|
115
189
|
|
|
116
190
|
// flags
|
|
117
|
-
collateralActive:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
191
|
+
collateralActive:
|
|
192
|
+
configData?.[
|
|
193
|
+
AaveV3GetreserveConfigDataIndexes.usageAsCollateralEnabled
|
|
194
|
+
],
|
|
195
|
+
borrowingEnabled:
|
|
196
|
+
configData?.[
|
|
197
|
+
AaveV3GetreserveConfigDataIndexes.borrowingEnabled
|
|
198
|
+
],
|
|
199
|
+
hasStable:
|
|
200
|
+
configData?.[
|
|
201
|
+
AaveV3GetreserveConfigDataIndexes.stableBorrowRateEnabled
|
|
202
|
+
],
|
|
203
|
+
isActive:
|
|
204
|
+
configData?.[AaveV3GetreserveConfigDataIndexes.isActive],
|
|
205
|
+
isFrozen:
|
|
206
|
+
configData?.[AaveV3GetreserveConfigDataIndexes.isFrozen],
|
|
122
207
|
|
|
123
208
|
// eMode
|
|
124
209
|
eMode: eModeConfigs[eModeCategory],
|
|
@@ -126,13 +211,16 @@ export const getAaveV3ReservesDataConverter = (
|
|
|
126
211
|
// caps
|
|
127
212
|
borrowCap: Number(reserveCaps[0]?.toString()),
|
|
128
213
|
supplyCap: Number(reserveCaps[1]?.toString()),
|
|
129
|
-
debtCeiling: parseRawAmount(
|
|
214
|
+
debtCeiling: parseRawAmount(
|
|
215
|
+
debtCeiling[i]?.toString(),
|
|
216
|
+
Number(decimalsCeiling?.toString()),
|
|
217
|
+
),
|
|
130
218
|
}
|
|
131
219
|
}
|
|
132
220
|
return {
|
|
133
221
|
data: resultReserves,
|
|
134
222
|
chainId,
|
|
135
|
-
eModes: eModeConfigs
|
|
223
|
+
eModes: eModeConfigs,
|
|
136
224
|
}
|
|
137
225
|
},
|
|
138
226
|
expectedNumberOfCalls,
|
|
@@ -141,31 +229,37 @@ export const getAaveV3ReservesDataConverter = (
|
|
|
141
229
|
}
|
|
142
230
|
}
|
|
143
231
|
|
|
144
|
-
const populateEModes = (
|
|
232
|
+
const populateEModes = (
|
|
233
|
+
borrowCollateralFactor: number,
|
|
234
|
+
collateralFactor: number,
|
|
235
|
+
) => {
|
|
145
236
|
let data: any = {}
|
|
146
|
-
AAVE_V3_EMODES.forEach(e => {
|
|
237
|
+
AAVE_V3_EMODES.forEach((e) => {
|
|
147
238
|
data[e] = {
|
|
148
239
|
category: e,
|
|
149
240
|
borrowCollateralFactor,
|
|
150
241
|
collateralFactor,
|
|
151
|
-
borrowFactor: 1
|
|
242
|
+
borrowFactor: 1,
|
|
152
243
|
}
|
|
153
244
|
})
|
|
154
245
|
return data
|
|
155
246
|
}
|
|
156
247
|
|
|
157
|
-
|
|
158
248
|
/** Replica of aave's bitmap checker */
|
|
159
249
|
function isReserveEnabledOnBitmap(
|
|
160
250
|
bitmap: bigint,
|
|
161
|
-
reserveIndex: number
|
|
251
|
+
reserveIndex: number,
|
|
162
252
|
): boolean {
|
|
163
|
-
return ((bitmap >> BigInt(reserveIndex)) & 1n) !== 0n
|
|
253
|
+
return ((bitmap >> BigInt(reserveIndex)) & 1n) !== 0n
|
|
164
254
|
}
|
|
165
255
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
256
|
+
export function parseYLDRCall(
|
|
257
|
+
chainId: string,
|
|
258
|
+
lender: Lender,
|
|
259
|
+
additionalYields: any,
|
|
260
|
+
prices: any,
|
|
261
|
+
tokenList: any,
|
|
262
|
+
): [(data: any[]) => any | undefined, number] {
|
|
169
263
|
const assetsToQuery = getAaveAssets(chainId, lender)
|
|
170
264
|
|
|
171
265
|
const expectedNumberOfCalls = assetsToQuery.length * 2
|
|
@@ -182,14 +276,27 @@ export function parseYLDRCall(chainId: string, lender: Lender, additionalYields:
|
|
|
182
276
|
const reserveData = data[i * 2]
|
|
183
277
|
const configData = data[i * 2 + 1]
|
|
184
278
|
|
|
185
|
-
const assetMeta = tokenList[asset] ?? {
|
|
279
|
+
const assetMeta = tokenList[asset] ?? {
|
|
280
|
+
...getAssetMeta(chainId, asset),
|
|
281
|
+
address: asset,
|
|
282
|
+
}
|
|
186
283
|
const decimals = assetMeta?.decimals ?? 18
|
|
187
284
|
|
|
188
|
-
const totalVariableDebt = parseRawAmount(
|
|
189
|
-
|
|
285
|
+
const totalVariableDebt = parseRawAmount(
|
|
286
|
+
reserveData?.[
|
|
287
|
+
YLDRTypeGetReserveDataIndexes.totalVariableDebt
|
|
288
|
+
]?.toString(),
|
|
289
|
+
decimals,
|
|
290
|
+
)
|
|
291
|
+
const totalAToken = parseRawAmount(
|
|
292
|
+
reserveData?.[YLDRTypeGetReserveDataIndexes.totalYToken]?.toString(),
|
|
293
|
+
decimals,
|
|
294
|
+
)
|
|
190
295
|
const liquidity = Number(totalAToken) - Number(totalVariableDebt)
|
|
191
296
|
|
|
192
|
-
const oracleKey =
|
|
297
|
+
const oracleKey =
|
|
298
|
+
toOracleKey(assetMeta?.assetGroup) ??
|
|
299
|
+
toGenericPriceKey(asset, chainId)
|
|
193
300
|
const price = prices[oracleKey] ?? 1
|
|
194
301
|
|
|
195
302
|
const totalDepositsUSD = Number(totalAToken) * price
|
|
@@ -210,27 +317,56 @@ export function parseYLDRCall(chainId: string, lender: Lender, additionalYields:
|
|
|
210
317
|
totalDebtUSD,
|
|
211
318
|
totalLiquidityUSD: liquidity * price,
|
|
212
319
|
// rates
|
|
213
|
-
depositRate: formatAaveRawApyToApr(
|
|
214
|
-
|
|
320
|
+
depositRate: formatAaveRawApyToApr(
|
|
321
|
+
reserveData?.[
|
|
322
|
+
YLDRTypeGetReserveDataIndexes.liquidityRate
|
|
323
|
+
]?.toString(),
|
|
324
|
+
),
|
|
325
|
+
variableBorrowRate: formatAaveRawApyToApr(
|
|
326
|
+
reserveData?.[
|
|
327
|
+
YLDRTypeGetReserveDataIndexes.variableBorrowRate
|
|
328
|
+
]?.toString(),
|
|
329
|
+
),
|
|
215
330
|
stableBorrowRate: 0,
|
|
216
331
|
stakingYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
217
332
|
|
|
218
333
|
// rewards
|
|
219
334
|
rewards: {},
|
|
220
|
-
decimals: Number(
|
|
335
|
+
decimals: Number(
|
|
336
|
+
configData?.[YLDRTypeGetReserveConfigurationData.decimals],
|
|
337
|
+
),
|
|
221
338
|
config: {
|
|
222
339
|
[LENDER_MODE_NO_MODE]: {
|
|
223
340
|
category: LENDER_MODE_NO_MODE,
|
|
224
341
|
// collateral factors
|
|
225
|
-
borrowCollateralFactor:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
342
|
+
borrowCollateralFactor:
|
|
343
|
+
Number(
|
|
344
|
+
configData?.[
|
|
345
|
+
YLDRTypeGetReserveConfigurationData.ltv
|
|
346
|
+
]?.toString(),
|
|
347
|
+
) / BPS,
|
|
348
|
+
collateralFactor:
|
|
349
|
+
Number(
|
|
350
|
+
configData?.[
|
|
351
|
+
YLDRTypeGetReserveConfigurationData.liquidationThreshold
|
|
352
|
+
]?.toString(),
|
|
353
|
+
) / BPS,
|
|
354
|
+
borrowFactor: 1,
|
|
355
|
+
},
|
|
229
356
|
},
|
|
230
|
-
liquidationBonus:
|
|
357
|
+
liquidationBonus:
|
|
358
|
+
Number(
|
|
359
|
+
configData?.[
|
|
360
|
+
YLDRTypeGetReserveConfigurationData.liquidationBonus
|
|
361
|
+
]?.toString(),
|
|
362
|
+
) / BPS,
|
|
231
363
|
// flags
|
|
232
|
-
collateralActive:
|
|
233
|
-
|
|
364
|
+
collateralActive:
|
|
365
|
+
configData?.[
|
|
366
|
+
YLDRTypeGetReserveConfigurationData.usageAsCollateralEnabled
|
|
367
|
+
],
|
|
368
|
+
borrowingEnabled:
|
|
369
|
+
configData?.[YLDRTypeGetReserveConfigurationData.borrowingEnabled],
|
|
234
370
|
hasStable: false,
|
|
235
371
|
isActive: configData?.[YLDRTypeGetReserveConfigurationData.isActive],
|
|
236
372
|
isFrozen: configData?.[YLDRTypeGetReserveConfigurationData.isFrozen],
|
|
@@ -240,24 +376,33 @@ export function parseYLDRCall(chainId: string, lender: Lender, additionalYields:
|
|
|
240
376
|
return {
|
|
241
377
|
data: resultReserves,
|
|
242
378
|
chainId,
|
|
243
|
-
eModes: {}
|
|
379
|
+
eModes: {},
|
|
244
380
|
}
|
|
245
381
|
},
|
|
246
382
|
expectedNumberOfCalls,
|
|
247
383
|
]
|
|
248
384
|
}
|
|
249
385
|
|
|
250
|
-
|
|
251
|
-
|
|
386
|
+
function parseAave32(
|
|
387
|
+
chainId: string,
|
|
388
|
+
lender: string,
|
|
389
|
+
prices: any,
|
|
390
|
+
additionalYields: any,
|
|
391
|
+
tokenList: any,
|
|
392
|
+
) {
|
|
252
393
|
const assetsToQuery = getAaveAssets(chainId, lender)
|
|
253
|
-
const expectedNumberOfCalls =
|
|
394
|
+
const expectedNumberOfCalls =
|
|
395
|
+
assetsToQuery.length * 5 + AAVE_V3_EMODES.length * 3 + 2
|
|
254
396
|
|
|
255
397
|
return [
|
|
256
398
|
(data: any[]) => {
|
|
257
399
|
if (data.length !== expectedNumberOfCalls) {
|
|
258
400
|
return undefined
|
|
259
401
|
}
|
|
260
|
-
const emodeDataResult = data.slice(
|
|
402
|
+
const emodeDataResult = data.slice(
|
|
403
|
+
assetsToQuery.length * 5,
|
|
404
|
+
assetsToQuery.length * 5 + AAVE_V3_EMODES.length * 3,
|
|
405
|
+
)
|
|
261
406
|
const resultReserves: any = {}
|
|
262
407
|
|
|
263
408
|
const reservesList = data[expectedNumberOfCalls - 2]
|
|
@@ -274,14 +419,15 @@ function parseAave32(chainId: string, lender: string, prices: any, additionalYie
|
|
|
274
419
|
label: rawCfg.label,
|
|
275
420
|
borrowCollateralFactor: rawCfg.ltv / BPS,
|
|
276
421
|
collateralFactor: rawCfg.liquidationThreshold / BPS,
|
|
277
|
-
borrowFactor: 1
|
|
422
|
+
borrowFactor: 1,
|
|
278
423
|
}
|
|
279
424
|
debtBitmap[mode] = emodeDataResult[3 * index + 1]
|
|
280
425
|
collateralBitmap[mode] = emodeDataResult[3 * index + 2]
|
|
281
426
|
})
|
|
282
|
-
|
|
283
427
|
// we get the reserves list to obtain the index per reserve
|
|
284
|
-
const lowerReservesList = (reservesList as string[])
|
|
428
|
+
const lowerReservesList = (reservesList as string[])?.map((a) =>
|
|
429
|
+
a.toLowerCase(),
|
|
430
|
+
)
|
|
285
431
|
|
|
286
432
|
for (let i = 0; i < assetsToQuery.length; i++) {
|
|
287
433
|
const asset = assetsToQuery[i]
|
|
@@ -293,14 +439,29 @@ function parseAave32(chainId: string, lender: string, prices: any, additionalYie
|
|
|
293
439
|
const reserveCaps = data[i * 5 + 3]
|
|
294
440
|
const debtCeiling = data[i * 5 + 4]
|
|
295
441
|
|
|
296
|
-
const assetMeta = tokenList[asset] ?? {
|
|
442
|
+
const assetMeta = tokenList[asset] ?? {
|
|
443
|
+
...getAssetMeta(chainId, asset),
|
|
444
|
+
address: asset,
|
|
445
|
+
}
|
|
297
446
|
|
|
298
447
|
const decimals = assetMeta?.decimals ?? 18
|
|
299
|
-
const totalDeposits = parseRawAmount(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
448
|
+
const totalDeposits = parseRawAmount(
|
|
449
|
+
reserveData?.[AaveV3GetReservesIndexes.totalAToken]?.toString(),
|
|
450
|
+
decimals,
|
|
451
|
+
)
|
|
452
|
+
const totalDebtStable = parseRawAmount(
|
|
453
|
+
reserveData?.[AaveV3GetReservesIndexes.totalStableDebt]?.toString(),
|
|
454
|
+
decimals,
|
|
455
|
+
)
|
|
456
|
+
const totalDebt = parseRawAmount(
|
|
457
|
+
reserveData?.[AaveV3GetReservesIndexes.totalVariableDebt]?.toString(),
|
|
458
|
+
decimals,
|
|
459
|
+
)
|
|
460
|
+
const liquidity =
|
|
461
|
+
Number(totalDeposits) - Number(totalDebt) - Number(totalDebtStable)
|
|
462
|
+
const price =
|
|
463
|
+
prices[toOracleKey(assetMeta?.assetGroup!)] ??
|
|
464
|
+
toGenericPriceKey(asset, chainId)
|
|
304
465
|
|
|
305
466
|
resultReserves[asset] = {
|
|
306
467
|
poolId: asset,
|
|
@@ -317,44 +478,82 @@ function parseAave32(chainId: string, lender: string, prices: any, additionalYie
|
|
|
317
478
|
totalDebtUSD: Number(totalDebt) * price,
|
|
318
479
|
totalLiquidityUSD: liquidity * price,
|
|
319
480
|
// rates
|
|
320
|
-
depositRate: formatAaveRawApyToApr(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
481
|
+
depositRate: formatAaveRawApyToApr(
|
|
482
|
+
reserveData?.[AaveV3GetReservesIndexes.liquidityRate]?.toString(),
|
|
483
|
+
),
|
|
484
|
+
variableBorrowRate: formatAaveRawApyToApr(
|
|
485
|
+
reserveData?.[
|
|
486
|
+
AaveV3GetReservesIndexes.variableBorrowRate
|
|
487
|
+
]?.toString(),
|
|
488
|
+
),
|
|
489
|
+
stableBorrowRate: formatAaveRawApyToApr(
|
|
490
|
+
reserveData?.[
|
|
491
|
+
AaveV3GetReservesIndexes.stableBorrowRate
|
|
492
|
+
]?.toString(),
|
|
493
|
+
),
|
|
494
|
+
|
|
495
|
+
stakingYield:
|
|
496
|
+
additionalYields.intrinsicYields[
|
|
497
|
+
toOracleKey(assetMeta?.assetGroup)
|
|
498
|
+
] ?? 0,
|
|
325
499
|
// rewards
|
|
326
500
|
rewards: {},
|
|
327
501
|
}
|
|
328
|
-
const activeEmodes = AAVE_V3_EMODES.map(mode =>
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
502
|
+
const activeEmodes = AAVE_V3_EMODES.map((mode) =>
|
|
503
|
+
isReserveEnabledOnBitmap(
|
|
504
|
+
debtBitmap[mode],
|
|
505
|
+
lowerReservesList.indexOf(asset),
|
|
506
|
+
) ||
|
|
507
|
+
isReserveEnabledOnBitmap(
|
|
508
|
+
collateralBitmap[mode],
|
|
509
|
+
lowerReservesList.indexOf(asset),
|
|
510
|
+
)
|
|
511
|
+
? mode
|
|
512
|
+
: -1,
|
|
513
|
+
).filter((m) => m !== undefined && m > 0)
|
|
334
514
|
const eModeCategory = activeEmodes.length === 0 ? 0 : activeEmodes[0] // Number(emodeResult[index].toString())
|
|
335
515
|
|
|
336
516
|
resultReserves[asset] = {
|
|
337
517
|
...resultReserves[asset],
|
|
338
|
-
decimals: Number(
|
|
518
|
+
decimals: Number(
|
|
519
|
+
configData?.[AaveV3GetreserveConfigDataIndexes.decimals],
|
|
520
|
+
),
|
|
339
521
|
|
|
340
522
|
config: {
|
|
341
|
-
...populateEModes(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
523
|
+
...populateEModes(
|
|
524
|
+
Number(configData?.[AaveV3GetreserveConfigDataIndexes.ltv]) / BPS,
|
|
525
|
+
Number(
|
|
526
|
+
configData?.[
|
|
527
|
+
AaveV3GetreserveConfigDataIndexes.liquidationThreshold
|
|
528
|
+
],
|
|
529
|
+
) / BPS,
|
|
530
|
+
),
|
|
531
|
+
...(eModeCategory !== 0
|
|
532
|
+
? {
|
|
533
|
+
[eModeCategory]: {
|
|
534
|
+
category: eModeCategory,
|
|
535
|
+
label: eModeConfigs[eModeCategory]?.label ?? 'Default',
|
|
536
|
+
borrowCollateralFactor:
|
|
537
|
+
eModeConfigs[eModeCategory]?.borrowCollateralFactor ?? 0,
|
|
538
|
+
collateralFactor:
|
|
539
|
+
eModeConfigs[eModeCategory]?.collateralFactor ?? 0,
|
|
540
|
+
borrowFactor: 1,
|
|
541
|
+
},
|
|
542
|
+
}
|
|
543
|
+
: {}),
|
|
352
544
|
},
|
|
353
545
|
|
|
354
546
|
// flags
|
|
355
|
-
collateralActive:
|
|
356
|
-
|
|
357
|
-
|
|
547
|
+
collateralActive:
|
|
548
|
+
configData?.[
|
|
549
|
+
AaveV3GetreserveConfigDataIndexes.usageAsCollateralEnabled
|
|
550
|
+
],
|
|
551
|
+
borrowingEnabled:
|
|
552
|
+
configData?.[AaveV3GetreserveConfigDataIndexes.borrowingEnabled],
|
|
553
|
+
hasStable:
|
|
554
|
+
configData?.[
|
|
555
|
+
AaveV3GetreserveConfigDataIndexes.stableBorrowRateEnabled
|
|
556
|
+
],
|
|
358
557
|
isActive: configData?.[AaveV3GetreserveConfigDataIndexes.isActive],
|
|
359
558
|
isFrozen: configData?.[AaveV3GetreserveConfigDataIndexes.isFrozen],
|
|
360
559
|
|
|
@@ -364,13 +563,16 @@ function parseAave32(chainId: string, lender: string, prices: any, additionalYie
|
|
|
364
563
|
// caps
|
|
365
564
|
borrowCap: Number(reserveCaps[0]?.toString()),
|
|
366
565
|
supplyCap: Number(reserveCaps[1]?.toString()),
|
|
367
|
-
debtCeiling: parseRawAmount(
|
|
566
|
+
debtCeiling: parseRawAmount(
|
|
567
|
+
debtCeiling[i]?.toString(),
|
|
568
|
+
Number(decimalsCeiling?.toString()),
|
|
569
|
+
),
|
|
368
570
|
}
|
|
369
571
|
}
|
|
370
572
|
return {
|
|
371
573
|
data: resultReserves,
|
|
372
574
|
chainId,
|
|
373
|
-
eModes: eModeConfigs
|
|
575
|
+
eModes: eModeConfigs,
|
|
374
576
|
}
|
|
375
577
|
},
|
|
376
578
|
expectedNumberOfCalls,
|