@1delta/margin-fetcher 0.0.37 → 0.0.38
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-v2-type/publicCallParse.d.ts +4 -4
- package/dist/lending/aave-v2-type/publicCallParse.d.ts.map +1 -1
- package/dist/lending/aave-v2-type/publicCallParse.js +60 -32
- package/dist/lending/addresses/meridian.d.ts +3 -0
- package/dist/lending/addresses/meridian.d.ts.map +1 -1
- package/dist/lending/addresses/meridian.js +4 -1
- package/dist/prices/defillama/index.d.ts.map +1 -1
- package/dist/prices/defillama/index.js +14 -2
- package/dist/prices/main-prices/fetchOracleData.js +2 -0
- package/package.json +1 -1
- package/src/lending/aave-v2-type/publicCallParse.ts +334 -92
- package/src/lending/addresses/meridian.ts +4 -1
- package/src/prices/defillama/index.ts +16 -2
- package/src/prices/main-prices/fetchOracleData.ts +1 -0
- package/test/flashLiquidity.test.ts +2 -2
- package/test/lenderData.test.ts +2 -2
- package/test/mainPrices.test.ts +4 -3
- package/test/userDataAaveTelos.test.ts +85 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Lender } from
|
|
2
|
-
import { AaveV2GeneralPublicResponse } from
|
|
3
|
-
import { AdditionalYields } from
|
|
4
|
-
import { GenericTokenList } from
|
|
1
|
+
import { Lender } from '@1delta/lender-registry';
|
|
2
|
+
import { AaveV2GeneralPublicResponse } from './types';
|
|
3
|
+
import { AdditionalYields } from '../../types';
|
|
4
|
+
import { GenericTokenList } from '../types';
|
|
5
5
|
export declare const getAaveV2ReservesDataConverter: (lender: Lender, chainId: string, prices: {
|
|
6
6
|
[asset: string]: number;
|
|
7
7
|
}, additionalYields: AdditionalYields, tokenList?: GenericTokenList) => [(data: any[]) => AaveV2GeneralPublicResponse | undefined, number];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicCallParse.d.ts","sourceRoot":"","sources":["../../../src/lending/aave-v2-type/publicCallParse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publicCallParse.d.ts","sourceRoot":"","sources":["../../../src/lending/aave-v2-type/publicCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAahD,OAAO,EACL,2BAA2B,EAI5B,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAG3C,eAAO,MAAM,8BAA8B,GACzC,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,QAAQ;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACnC,kBAAkB,gBAAgB,EAClC,YAAW,gBAAqB,KAC/B,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,2BAA2B,GAAG,SAAS,EAAE,MAAM,CAqgBnE,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Lender } from
|
|
2
|
-
import { getAaveAssets, LENDER_MODE_NO_MODE, toGenericPriceKey, toOracleKey } from
|
|
3
|
-
import { BPS, convertRateToApr, formatAaveRawApyToApr, parseRawAmount } from
|
|
4
|
-
import { AaveV2TypeGetReserveConfigurationData, AaveV2TypeGetReserveDataIndexes, AaveV2TypeIncentivesControllerPoolInfoIndexes } from
|
|
1
|
+
import { Lender } from '@1delta/lender-registry';
|
|
2
|
+
import { getAaveAssets, LENDER_MODE_NO_MODE, toGenericPriceKey, toOracleKey, } from '../../assets';
|
|
3
|
+
import { BPS, convertRateToApr, formatAaveRawApyToApr, parseRawAmount, } from '../../utils/parsing';
|
|
4
|
+
import { AaveV2TypeGetReserveConfigurationData, AaveV2TypeGetReserveDataIndexes, AaveV2TypeIncentivesControllerPoolInfoIndexes, } from './types';
|
|
5
|
+
import { Chain } from '@1delta/chain-registry';
|
|
5
6
|
export const getAaveV2ReservesDataConverter = (lender, chainId, prices, additionalYields, tokenList = {}) => {
|
|
6
7
|
switch (lender) {
|
|
7
8
|
case Lender.AURELIUS: {
|
|
@@ -26,8 +27,11 @@ export const getAaveV2ReservesDataConverter = (lender, chainId, prices, addition
|
|
|
26
27
|
const totalStableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalStableDebt]?.toString(), decimals);
|
|
27
28
|
const totalVariableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalVariableDebt]?.toString(), decimals);
|
|
28
29
|
const liquidity = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.availableLiquidity]?.toString(), decimals);
|
|
29
|
-
const totalAToken = Number(liquidity) +
|
|
30
|
-
|
|
30
|
+
const totalAToken = Number(liquidity) +
|
|
31
|
+
Number(totalStableDebt) +
|
|
32
|
+
Number(totalVariableDebt);
|
|
33
|
+
const oracleKey = toOracleKey(assetMeta?.assetGroup) ??
|
|
34
|
+
toGenericPriceKey(asset, chainId);
|
|
31
35
|
const price = prices[oracleKey] ?? 1;
|
|
32
36
|
const totalDepositsUSD = totalAToken * price;
|
|
33
37
|
const totalDebtUSD = Number(totalVariableDebt) * price;
|
|
@@ -53,14 +57,24 @@ export const getAaveV2ReservesDataConverter = (lender, chainId, prices, addition
|
|
|
53
57
|
// rewards
|
|
54
58
|
rewards: {
|
|
55
59
|
WMNT: {
|
|
56
|
-
depositRate: convertRateToApr(parseRawAmount(emission0PerSecondCollateral)) /
|
|
57
|
-
|
|
60
|
+
depositRate: (convertRateToApr(parseRawAmount(emission0PerSecondCollateral)) /
|
|
61
|
+
totalDepositsUSD) *
|
|
62
|
+
prices['WMNT'],
|
|
63
|
+
variableBorrowRate: (convertRateToApr(parseRawAmount(emission0PerSecondDebt)) /
|
|
64
|
+
totalDebtUSD) *
|
|
65
|
+
prices['WMNT'],
|
|
58
66
|
stableBorrowRate: 0,
|
|
59
67
|
},
|
|
60
68
|
// oAU allows for a 50% discount to pruchase AU, hence the price is the price of AU divided by 2
|
|
61
69
|
OAU: {
|
|
62
|
-
depositRate: convertRateToApr(parseRawAmount(emission1PerSecondCollateral)) /
|
|
63
|
-
|
|
70
|
+
depositRate: ((convertRateToApr(parseRawAmount(emission1PerSecondCollateral)) /
|
|
71
|
+
totalDepositsUSD) *
|
|
72
|
+
(prices['AU'] ?? 0)) /
|
|
73
|
+
2,
|
|
74
|
+
variableBorrowRate: ((convertRateToApr(parseRawAmount(emission1PerSecondDebt)) /
|
|
75
|
+
totalDebtUSD) *
|
|
76
|
+
(prices['AU'] ?? 0)) /
|
|
77
|
+
2,
|
|
64
78
|
stableBorrowRate: 0,
|
|
65
79
|
},
|
|
66
80
|
},
|
|
@@ -70,9 +84,10 @@ export const getAaveV2ReservesDataConverter = (lender, chainId, prices, addition
|
|
|
70
84
|
category: LENDER_MODE_NO_MODE,
|
|
71
85
|
// collateral factors
|
|
72
86
|
borrowCollateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData.ltv].toString()) / BPS,
|
|
73
|
-
collateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
collateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData
|
|
88
|
+
.liquidationThreshold].toString()) / BPS,
|
|
89
|
+
borrowFactor: 1,
|
|
90
|
+
},
|
|
76
91
|
},
|
|
77
92
|
liquidationBonus: Number(configData?.[AaveV2TypeGetReserveConfigurationData.liquidationBonus].toString()) / BPS,
|
|
78
93
|
// flags
|
|
@@ -102,22 +117,29 @@ export const getAaveV2ReservesDataConverter = (lender, chainId, prices, addition
|
|
|
102
117
|
const rewardsPerSecond = Number(parseRawAmount(data[expectedNumberOfCalls - 2].toString(), 18));
|
|
103
118
|
const totalAllocPoint = Number(data[expectedNumberOfCalls - 1].toString());
|
|
104
119
|
const resultReserves = {};
|
|
105
|
-
const lendPrice = prices[
|
|
120
|
+
const lendPrice = prices['LEND'];
|
|
106
121
|
for (let i = 0; i < assetsToQuery.length; i++) {
|
|
107
122
|
const asset = assetsToQuery[i];
|
|
108
123
|
const reserveData = data[i * 4];
|
|
109
124
|
const configData = data[i * 4 + 1];
|
|
110
125
|
const collateralRewardIndex = i * 4 + 2;
|
|
111
126
|
const borrowRewardIndex = i * 4 + 3;
|
|
112
|
-
const collateralRewards = Number(data?.[collateralRewardIndex]?.[AaveV2TypeIncentivesControllerPoolInfoIndexes.allocPoint].toString()) /
|
|
113
|
-
|
|
127
|
+
const collateralRewards = (Number(data?.[collateralRewardIndex]?.[AaveV2TypeIncentivesControllerPoolInfoIndexes.allocPoint].toString()) /
|
|
128
|
+
totalAllocPoint) *
|
|
129
|
+
rewardsPerSecond;
|
|
130
|
+
const borrowRewards = (Number(data?.[borrowRewardIndex]?.[AaveV2TypeIncentivesControllerPoolInfoIndexes.allocPoint].toString()) /
|
|
131
|
+
totalAllocPoint) *
|
|
132
|
+
rewardsPerSecond;
|
|
114
133
|
const assetMeta = tokenList[asset];
|
|
115
134
|
const decimals = assetMeta?.decimals ?? 18;
|
|
116
135
|
const totalStableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalStableDebt]?.toString(), decimals);
|
|
117
136
|
const totalVariableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalVariableDebt]?.toString(), decimals);
|
|
118
137
|
const liquidity = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.availableLiquidity]?.toString(), decimals);
|
|
119
|
-
const totalAToken = Number(liquidity) +
|
|
120
|
-
|
|
138
|
+
const totalAToken = Number(liquidity) +
|
|
139
|
+
Number(totalStableDebt) +
|
|
140
|
+
Number(totalVariableDebt);
|
|
141
|
+
const oracleKey = toOracleKey(assetMeta?.assetGroup) ??
|
|
142
|
+
toGenericPriceKey(asset, chainId);
|
|
121
143
|
const price = prices?.[oracleKey] ?? 1;
|
|
122
144
|
const totalDepositsUSD = totalAToken * price;
|
|
123
145
|
const totalDebtUSD = Number(totalVariableDebt) * price;
|
|
@@ -143,7 +165,8 @@ export const getAaveV2ReservesDataConverter = (lender, chainId, prices, addition
|
|
|
143
165
|
// rewards
|
|
144
166
|
rewards: {
|
|
145
167
|
LEND: {
|
|
146
|
-
depositRate: convertRateToApr(collateralRewards / totalDepositsUSD) *
|
|
168
|
+
depositRate: convertRateToApr(collateralRewards / totalDepositsUSD) *
|
|
169
|
+
lendPrice,
|
|
147
170
|
variableBorrowRate: convertRateToApr(totalDebtUSD > 0 ? borrowRewards / totalDebtUSD : 0) * lendPrice,
|
|
148
171
|
stableBorrowRate: 0,
|
|
149
172
|
},
|
|
@@ -154,9 +177,10 @@ export const getAaveV2ReservesDataConverter = (lender, chainId, prices, addition
|
|
|
154
177
|
category: LENDER_MODE_NO_MODE,
|
|
155
178
|
// collateral factors
|
|
156
179
|
borrowCollateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData.ltv].toString()) / BPS,
|
|
157
|
-
collateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData
|
|
158
|
-
|
|
159
|
-
|
|
180
|
+
collateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData
|
|
181
|
+
.liquidationThreshold].toString()) / BPS,
|
|
182
|
+
borrowFactor: 1,
|
|
183
|
+
},
|
|
160
184
|
},
|
|
161
185
|
liquidationBonus: Number(configData?.[AaveV2TypeGetReserveConfigurationData.liquidationBonus].toString()) / BPS,
|
|
162
186
|
// flags
|
|
@@ -195,7 +219,8 @@ export const getAaveV2ReservesDataConverter = (lender, chainId, prices, addition
|
|
|
195
219
|
const totalVariableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalVariableDebt]?.toString(), decimals);
|
|
196
220
|
const liquidity = Number(parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.availableLiquidity]?.toString(), decimals));
|
|
197
221
|
const totalAToken = liquidity + Number(totalStableDebt) + Number(totalVariableDebt);
|
|
198
|
-
const oracleKey = toOracleKey(assetMeta?.assetGroup) ??
|
|
222
|
+
const oracleKey = toOracleKey(assetMeta?.assetGroup) ??
|
|
223
|
+
toGenericPriceKey(asset, chainId);
|
|
199
224
|
const price = prices[oracleKey] ?? 1;
|
|
200
225
|
const totalDepositsUSD = Number(totalAToken) * price;
|
|
201
226
|
const totalDebtUSD = Number(totalVariableDebt) * price;
|
|
@@ -219,22 +244,25 @@ export const getAaveV2ReservesDataConverter = (lender, chainId, prices, addition
|
|
|
219
244
|
stableBorrowRate: formatAaveRawApyToApr(reserveData?.[AaveV2TypeGetReserveDataIndexes.stableBorrowRate]?.toString()),
|
|
220
245
|
stakingYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
221
246
|
// rewards
|
|
222
|
-
rewards: lender === Lender.MERIDIAN
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
247
|
+
rewards: lender === Lender.MERIDIAN && chainId === Chain.TAIKO_ALETHIA
|
|
248
|
+
? {
|
|
249
|
+
TAIKO: {
|
|
250
|
+
depositRate: additionalYields.lenderRewards[Lender.MERIDIAN]?.[asset]?.deposit ?? 0,
|
|
251
|
+
variableBorrowRate: additionalYields.lenderRewards[Lender.MERIDIAN]?.[asset]?.borrow ?? 0,
|
|
252
|
+
stableBorrowRate: 0,
|
|
253
|
+
},
|
|
227
254
|
}
|
|
228
|
-
|
|
255
|
+
: {},
|
|
229
256
|
decimals: Number(configData?.[AaveV2TypeGetReserveConfigurationData.decimals]),
|
|
230
257
|
config: {
|
|
231
258
|
[LENDER_MODE_NO_MODE]: {
|
|
232
259
|
category: LENDER_MODE_NO_MODE,
|
|
233
260
|
// collateral factors
|
|
234
261
|
borrowCollateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData.ltv].toString()) / BPS,
|
|
235
|
-
collateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData
|
|
236
|
-
|
|
237
|
-
|
|
262
|
+
collateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData
|
|
263
|
+
.liquidationThreshold].toString()) / BPS,
|
|
264
|
+
borrowFactor: 1,
|
|
265
|
+
},
|
|
238
266
|
},
|
|
239
267
|
liquidationBonus: Number(configData?.[AaveV2TypeGetReserveConfigurationData.liquidationBonus].toString()) / BPS,
|
|
240
268
|
// flags
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meridian.d.ts","sourceRoot":"","sources":["../../../src/lending/addresses/meridian.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB
|
|
1
|
+
{"version":3,"file":"meridian.d.ts","sourceRoot":"","sources":["../../../src/lending/addresses/meridian.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;CAajC,CAAA"}
|
|
@@ -4,7 +4,10 @@ export const addressesMeridianCore = {
|
|
|
4
4
|
[Chain.TAIKO_ALETHIA]: '0xd79417be2cE02fc22F2E520869b1DfC02a677751',
|
|
5
5
|
},
|
|
6
6
|
IncentivesController: {
|
|
7
|
-
[Chain.TAIKO_ALETHIA]: '0xb3020EbFD800B488B64E92A8717E826cBf0d63E2'
|
|
7
|
+
[Chain.TAIKO_ALETHIA]: '0xb3020EbFD800B488B64E92A8717E826cBf0d63E2',
|
|
8
|
+
[Chain.TELOS_EVM_MAINNET]: '0x406F044A5aBF071db08E4482c3487331Cf284ADc',
|
|
9
|
+
[Chain.FUSE_MAINNET]: '0xd2Fa60C6fab6EdF77E78A0908066d04a5F5EB1E0',
|
|
10
|
+
[Chain.METER_MAINNET]: '0xBAE27c0F27A7bff3f391A19E0dE2d241E2497a09',
|
|
8
11
|
},
|
|
9
12
|
MultiFeeDistribution: {
|
|
10
13
|
[Chain.TAIKO_ALETHIA]: '0xb0e103e2A80489Ba697D882EEd0Ba552389Ca31E'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/prices/defillama/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/prices/defillama/index.ts"],"names":[],"mappings":"AAgSA,wBAAsB,kBAAkB,iBA6CvC;AAED,wBAAsB,sBAAsB,iBAiD3C"}
|
|
@@ -125,6 +125,10 @@ const prefixBera = 'berachain:';
|
|
|
125
125
|
const WBERA = '0x6969696969696969696969696969696969696969';
|
|
126
126
|
const prefixCronos = 'cronos:';
|
|
127
127
|
const WCRO = '0x5c7f8a570d578ed84e63fdfa7b1ee72deae1ae23';
|
|
128
|
+
const prefixTelos = 'telos:';
|
|
129
|
+
const wtlos = '0xd102ce6a4db07d247fcc28f366a623df0938ca9e';
|
|
130
|
+
const prefixManta = 'manta:';
|
|
131
|
+
const manta = '0x95cef13441be50d20ca4558cc0a27b601ac544e5';
|
|
128
132
|
// const prefixKaia = 'kaia:'
|
|
129
133
|
// const WKAIA = '0x19aac5f612f524b754ca7e7c41cbfa2e981a4432'
|
|
130
134
|
const datasAvalanche = [WAVAX, SAVAX].map((d) => prefixAvalanche + d).join(',');
|
|
@@ -144,7 +148,9 @@ const datasHyperEvm = [WYPE, WSTHYPE, kHYPE]
|
|
|
144
148
|
const datasSolana = [JITOSOL, SOL].map((d) => prefixSolana + d).join(',');
|
|
145
149
|
const datasBera = [WBERA].map((d) => prefixBera + d).join(',');
|
|
146
150
|
const datasXdc = [WXDC].map((d) => prefixXdc + d).join(',');
|
|
147
|
-
const
|
|
151
|
+
const datasCronos = [WCRO].map((d) => prefixCronos + d).join(',');
|
|
152
|
+
const datasManta = [manta].map((d) => prefixManta + d).join(',');
|
|
153
|
+
const datasTelos = [wtlos].map((d) => prefixTelos + d).join(',');
|
|
148
154
|
// const datasKaia = [WKAIA].map((d) => prefixKaia + d).join(',')
|
|
149
155
|
const URL = `https://coins.llama.fi/prices/current/${[
|
|
150
156
|
datasEthereum,
|
|
@@ -162,7 +168,9 @@ const URL = `https://coins.llama.fi/prices/current/${[
|
|
|
162
168
|
datasSolana,
|
|
163
169
|
datasBera,
|
|
164
170
|
datasXdc,
|
|
165
|
-
|
|
171
|
+
datasCronos,
|
|
172
|
+
datasManta,
|
|
173
|
+
datasTelos,
|
|
166
174
|
].join(',')}?searchWidth=4h`;
|
|
167
175
|
const URL_HIST = (ref) => `https://coins.llama.fi/prices/historical/${ref}/${[
|
|
168
176
|
datasEthereum,
|
|
@@ -248,10 +256,12 @@ const SYMBOL_MAP = {
|
|
|
248
256
|
usual: 'Usual::USUAL',
|
|
249
257
|
woeth: 'Wrapped OETH::WOETH',
|
|
250
258
|
jitosol: 'Jito Staked SOL::JitoSOL',
|
|
259
|
+
manta: 'Manta::MANTA',
|
|
251
260
|
sol: 'SOL',
|
|
252
261
|
wcro: 'WCRO',
|
|
253
262
|
wxdc: 'WXDC',
|
|
254
263
|
wbera: 'WBERA',
|
|
264
|
+
wtlos: 'WTLOS',
|
|
255
265
|
};
|
|
256
266
|
export async function fetchDefillamaData() {
|
|
257
267
|
try {
|
|
@@ -271,6 +281,7 @@ export async function fetchDefillamaData() {
|
|
|
271
281
|
prices['CRO'] = prices['WCRO'];
|
|
272
282
|
prices['XDC'] = prices['WXDC'];
|
|
273
283
|
prices['BERA'] = prices['WBERA'];
|
|
284
|
+
prices['TLOS'] = prices['WTLOS'];
|
|
274
285
|
// prices['WKAIA'] = prices['KAIA']
|
|
275
286
|
prices['USDBC'] = prices['USDC'];
|
|
276
287
|
prices['BTCB'] = prices['WBTC'];
|
|
@@ -311,6 +322,7 @@ export async function fetchDefillamaHistData() {
|
|
|
311
322
|
histPrices['BERA'] = histPrices['WBERA'];
|
|
312
323
|
histPrices['CRO'] = histPrices['WCRO'];
|
|
313
324
|
histPrices['XDC'] = histPrices['WXDC'];
|
|
325
|
+
histPrices['TLOS'] = histPrices['WTLOS'];
|
|
314
326
|
// histPrices['WKAIA'] = histPrices['KAIA']
|
|
315
327
|
histPrices['LUSD'] = histPrices['USDT'];
|
|
316
328
|
histPrices['XDAI'] = histPrices['DAI'];
|
|
@@ -324,6 +324,8 @@ function lowDecimalOracle(chainId, fork) {
|
|
|
324
324
|
}
|
|
325
325
|
if (chainId === Chain.XDC_NETWORK)
|
|
326
326
|
return true;
|
|
327
|
+
if (chainId === Chain.TELOS_EVM_MAINNET)
|
|
328
|
+
return true;
|
|
327
329
|
// otherwise, it depends on whether it is aave V3
|
|
328
330
|
return AAVE_V2_LENDERS.includes(fork);
|
|
329
331
|
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Lender } from '@1delta/lender-registry'
|
|
2
|
+
import {
|
|
3
|
+
getAaveAssets,
|
|
4
|
+
LENDER_MODE_NO_MODE,
|
|
5
|
+
toGenericPriceKey,
|
|
6
|
+
toOracleKey,
|
|
7
|
+
} from '../../assets'
|
|
8
|
+
import {
|
|
9
|
+
BPS,
|
|
10
|
+
convertRateToApr,
|
|
11
|
+
formatAaveRawApyToApr,
|
|
12
|
+
parseRawAmount,
|
|
13
|
+
} from '../../utils/parsing'
|
|
5
14
|
import {
|
|
6
15
|
AaveV2GeneralPublicResponse,
|
|
7
16
|
AaveV2TypeGetReserveConfigurationData,
|
|
8
17
|
AaveV2TypeGetReserveDataIndexes,
|
|
9
|
-
AaveV2TypeIncentivesControllerPoolInfoIndexes
|
|
10
|
-
} from
|
|
11
|
-
import { AdditionalYields } from
|
|
12
|
-
import { GenericTokenList } from
|
|
18
|
+
AaveV2TypeIncentivesControllerPoolInfoIndexes,
|
|
19
|
+
} from './types'
|
|
20
|
+
import { AdditionalYields } from '../../types'
|
|
21
|
+
import { GenericTokenList } from '../types'
|
|
22
|
+
import { Chain } from '@1delta/chain-registry'
|
|
13
23
|
|
|
14
24
|
export const getAaveV2ReservesDataConverter = (
|
|
15
25
|
lender: Lender,
|
|
16
26
|
chainId: string,
|
|
17
27
|
prices: { [asset: string]: number },
|
|
18
28
|
additionalYields: AdditionalYields,
|
|
19
|
-
tokenList: GenericTokenList = {}
|
|
29
|
+
tokenList: GenericTokenList = {},
|
|
20
30
|
): [(data: any[]) => AaveV2GeneralPublicResponse | undefined, number] => {
|
|
21
31
|
switch (lender) {
|
|
22
32
|
case Lender.AURELIUS: {
|
|
@@ -41,14 +51,34 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
41
51
|
const [, emission0PerSecondDebt, ,] = data[i * 6 + 4]
|
|
42
52
|
const [, emission1PerSecondDebt, ,] = data[i * 6 + 5]
|
|
43
53
|
|
|
44
|
-
const assetMeta = tokenList[asset]
|
|
54
|
+
const assetMeta = tokenList[asset]
|
|
45
55
|
const decimals = assetMeta?.decimals ?? 18
|
|
46
|
-
const totalStableDebt = parseRawAmount(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
const totalStableDebt = parseRawAmount(
|
|
57
|
+
reserveData?.[
|
|
58
|
+
AaveV2TypeGetReserveDataIndexes.totalStableDebt
|
|
59
|
+
]?.toString(),
|
|
60
|
+
decimals,
|
|
61
|
+
)
|
|
62
|
+
const totalVariableDebt = parseRawAmount(
|
|
63
|
+
reserveData?.[
|
|
64
|
+
AaveV2TypeGetReserveDataIndexes.totalVariableDebt
|
|
65
|
+
]?.toString(),
|
|
66
|
+
decimals,
|
|
67
|
+
)
|
|
68
|
+
const liquidity = parseRawAmount(
|
|
69
|
+
reserveData?.[
|
|
70
|
+
AaveV2TypeGetReserveDataIndexes.availableLiquidity
|
|
71
|
+
]?.toString(),
|
|
72
|
+
decimals,
|
|
73
|
+
)
|
|
74
|
+
const totalAToken =
|
|
75
|
+
Number(liquidity) +
|
|
76
|
+
Number(totalStableDebt) +
|
|
77
|
+
Number(totalVariableDebt)
|
|
78
|
+
|
|
79
|
+
const oracleKey =
|
|
80
|
+
toOracleKey(assetMeta?.assetGroup) ??
|
|
81
|
+
toGenericPriceKey(asset, chainId)
|
|
52
82
|
const price = prices[oracleKey] ?? 1
|
|
53
83
|
|
|
54
84
|
const totalDepositsUSD = totalAToken * price
|
|
@@ -69,42 +99,101 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
69
99
|
totalDebtUSD,
|
|
70
100
|
totalLiquidityUSD: Number(liquidity) * price,
|
|
71
101
|
// rates
|
|
72
|
-
depositRate: formatAaveRawApyToApr(
|
|
73
|
-
|
|
74
|
-
|
|
102
|
+
depositRate: formatAaveRawApyToApr(
|
|
103
|
+
reserveData?.[
|
|
104
|
+
AaveV2TypeGetReserveDataIndexes.liquidityRate
|
|
105
|
+
]?.toString(),
|
|
106
|
+
),
|
|
107
|
+
variableBorrowRate: formatAaveRawApyToApr(
|
|
108
|
+
reserveData?.[
|
|
109
|
+
AaveV2TypeGetReserveDataIndexes.variableBorrowRate
|
|
110
|
+
]?.toString(),
|
|
111
|
+
),
|
|
112
|
+
stableBorrowRate: formatAaveRawApyToApr(
|
|
113
|
+
reserveData?.[
|
|
114
|
+
AaveV2TypeGetReserveDataIndexes.stableBorrowRate
|
|
115
|
+
]?.toString(),
|
|
116
|
+
),
|
|
75
117
|
stakingYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
76
118
|
|
|
77
119
|
// rewards
|
|
78
120
|
rewards: {
|
|
79
121
|
WMNT: {
|
|
80
|
-
depositRate:
|
|
81
|
-
|
|
122
|
+
depositRate:
|
|
123
|
+
(convertRateToApr(
|
|
124
|
+
parseRawAmount(emission0PerSecondCollateral),
|
|
125
|
+
) /
|
|
126
|
+
totalDepositsUSD) *
|
|
127
|
+
prices['WMNT'],
|
|
128
|
+
variableBorrowRate:
|
|
129
|
+
(convertRateToApr(parseRawAmount(emission0PerSecondDebt)) /
|
|
130
|
+
totalDebtUSD) *
|
|
131
|
+
prices['WMNT'],
|
|
82
132
|
stableBorrowRate: 0,
|
|
83
133
|
},
|
|
84
134
|
// oAU allows for a 50% discount to pruchase AU, hence the price is the price of AU divided by 2
|
|
85
135
|
OAU: {
|
|
86
|
-
depositRate:
|
|
87
|
-
|
|
136
|
+
depositRate:
|
|
137
|
+
((convertRateToApr(
|
|
138
|
+
parseRawAmount(emission1PerSecondCollateral),
|
|
139
|
+
) /
|
|
140
|
+
totalDepositsUSD) *
|
|
141
|
+
(prices['AU'] ?? 0)) /
|
|
142
|
+
2,
|
|
143
|
+
variableBorrowRate:
|
|
144
|
+
((convertRateToApr(parseRawAmount(emission1PerSecondDebt)) /
|
|
145
|
+
totalDebtUSD) *
|
|
146
|
+
(prices['AU'] ?? 0)) /
|
|
147
|
+
2,
|
|
88
148
|
stableBorrowRate: 0,
|
|
89
149
|
},
|
|
90
150
|
},
|
|
91
|
-
decimals: Number(
|
|
151
|
+
decimals: Number(
|
|
152
|
+
configData?.[AaveV2TypeGetReserveConfigurationData.decimals],
|
|
153
|
+
),
|
|
92
154
|
config: {
|
|
93
155
|
[LENDER_MODE_NO_MODE]: {
|
|
94
156
|
category: LENDER_MODE_NO_MODE,
|
|
95
157
|
// collateral factors
|
|
96
|
-
borrowCollateralFactor:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
158
|
+
borrowCollateralFactor:
|
|
159
|
+
Number(
|
|
160
|
+
configData?.[
|
|
161
|
+
AaveV2TypeGetReserveConfigurationData.ltv
|
|
162
|
+
].toString(),
|
|
163
|
+
) / BPS,
|
|
164
|
+
collateralFactor:
|
|
165
|
+
Number(
|
|
166
|
+
configData?.[
|
|
167
|
+
AaveV2TypeGetReserveConfigurationData
|
|
168
|
+
.liquidationThreshold
|
|
169
|
+
].toString(),
|
|
170
|
+
) / BPS,
|
|
171
|
+
borrowFactor: 1,
|
|
172
|
+
},
|
|
100
173
|
},
|
|
101
|
-
liquidationBonus:
|
|
174
|
+
liquidationBonus:
|
|
175
|
+
Number(
|
|
176
|
+
configData?.[
|
|
177
|
+
AaveV2TypeGetReserveConfigurationData.liquidationBonus
|
|
178
|
+
].toString(),
|
|
179
|
+
) / BPS,
|
|
102
180
|
// flags
|
|
103
|
-
collateralActive:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
181
|
+
collateralActive:
|
|
182
|
+
configData?.[
|
|
183
|
+
AaveV2TypeGetReserveConfigurationData.usageAsCollateralEnabled
|
|
184
|
+
],
|
|
185
|
+
borrowingEnabled:
|
|
186
|
+
configData?.[
|
|
187
|
+
AaveV2TypeGetReserveConfigurationData.borrowingEnabled
|
|
188
|
+
],
|
|
189
|
+
hasStable:
|
|
190
|
+
configData?.[
|
|
191
|
+
AaveV2TypeGetReserveConfigurationData.stableBorrowRateEnabled
|
|
192
|
+
],
|
|
193
|
+
isActive:
|
|
194
|
+
configData?.[AaveV2TypeGetReserveConfigurationData.isActive],
|
|
195
|
+
isFrozen:
|
|
196
|
+
configData?.[AaveV2TypeGetReserveConfigurationData.isFrozen],
|
|
108
197
|
}
|
|
109
198
|
}
|
|
110
199
|
|
|
@@ -126,12 +215,16 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
126
215
|
return undefined
|
|
127
216
|
}
|
|
128
217
|
|
|
129
|
-
const rewardsPerSecond = Number(
|
|
130
|
-
|
|
218
|
+
const rewardsPerSecond = Number(
|
|
219
|
+
parseRawAmount(data[expectedNumberOfCalls - 2].toString(), 18),
|
|
220
|
+
)
|
|
221
|
+
const totalAllocPoint = Number(
|
|
222
|
+
data[expectedNumberOfCalls - 1].toString(),
|
|
223
|
+
)
|
|
131
224
|
|
|
132
225
|
const resultReserves: any = {}
|
|
133
226
|
|
|
134
|
-
const lendPrice = prices[
|
|
227
|
+
const lendPrice = prices['LEND']
|
|
135
228
|
|
|
136
229
|
for (let i = 0; i < assetsToQuery.length; i++) {
|
|
137
230
|
const asset = assetsToQuery[i]
|
|
@@ -140,18 +233,51 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
140
233
|
|
|
141
234
|
const collateralRewardIndex = i * 4 + 2
|
|
142
235
|
const borrowRewardIndex = i * 4 + 3
|
|
143
|
-
const collateralRewards =
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
236
|
+
const collateralRewards =
|
|
237
|
+
(Number(
|
|
238
|
+
data?.[collateralRewardIndex]?.[
|
|
239
|
+
AaveV2TypeIncentivesControllerPoolInfoIndexes.allocPoint
|
|
240
|
+
].toString(),
|
|
241
|
+
) /
|
|
242
|
+
totalAllocPoint) *
|
|
243
|
+
rewardsPerSecond
|
|
244
|
+
const borrowRewards =
|
|
245
|
+
(Number(
|
|
246
|
+
data?.[borrowRewardIndex]?.[
|
|
247
|
+
AaveV2TypeIncentivesControllerPoolInfoIndexes.allocPoint
|
|
248
|
+
].toString(),
|
|
249
|
+
) /
|
|
250
|
+
totalAllocPoint) *
|
|
251
|
+
rewardsPerSecond
|
|
252
|
+
|
|
253
|
+
const assetMeta = tokenList[asset]
|
|
148
254
|
const decimals = assetMeta?.decimals ?? 18
|
|
149
255
|
|
|
150
|
-
const totalStableDebt = parseRawAmount(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
256
|
+
const totalStableDebt = parseRawAmount(
|
|
257
|
+
reserveData?.[
|
|
258
|
+
AaveV2TypeGetReserveDataIndexes.totalStableDebt
|
|
259
|
+
]?.toString(),
|
|
260
|
+
decimals,
|
|
261
|
+
)
|
|
262
|
+
const totalVariableDebt = parseRawAmount(
|
|
263
|
+
reserveData?.[
|
|
264
|
+
AaveV2TypeGetReserveDataIndexes.totalVariableDebt
|
|
265
|
+
]?.toString(),
|
|
266
|
+
decimals,
|
|
267
|
+
)
|
|
268
|
+
const liquidity = parseRawAmount(
|
|
269
|
+
reserveData?.[
|
|
270
|
+
AaveV2TypeGetReserveDataIndexes.availableLiquidity
|
|
271
|
+
]?.toString(),
|
|
272
|
+
decimals,
|
|
273
|
+
)
|
|
274
|
+
const totalAToken =
|
|
275
|
+
Number(liquidity) +
|
|
276
|
+
Number(totalStableDebt) +
|
|
277
|
+
Number(totalVariableDebt)
|
|
278
|
+
const oracleKey =
|
|
279
|
+
toOracleKey(assetMeta?.assetGroup) ??
|
|
280
|
+
toGenericPriceKey(asset, chainId)
|
|
155
281
|
const price = prices?.[oracleKey] ?? 1
|
|
156
282
|
|
|
157
283
|
const totalDepositsUSD = totalAToken * price
|
|
@@ -172,36 +298,82 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
172
298
|
totalDebtUSD,
|
|
173
299
|
totalLiquidityUSD: Number(liquidity) * price,
|
|
174
300
|
// rates
|
|
175
|
-
depositRate: formatAaveRawApyToApr(
|
|
176
|
-
|
|
177
|
-
|
|
301
|
+
depositRate: formatAaveRawApyToApr(
|
|
302
|
+
reserveData?.[
|
|
303
|
+
AaveV2TypeGetReserveDataIndexes.liquidityRate
|
|
304
|
+
]?.toString(),
|
|
305
|
+
),
|
|
306
|
+
variableBorrowRate: formatAaveRawApyToApr(
|
|
307
|
+
reserveData?.[
|
|
308
|
+
AaveV2TypeGetReserveDataIndexes.variableBorrowRate
|
|
309
|
+
]?.toString(),
|
|
310
|
+
),
|
|
311
|
+
stableBorrowRate: formatAaveRawApyToApr(
|
|
312
|
+
reserveData?.[
|
|
313
|
+
AaveV2TypeGetReserveDataIndexes.stableBorrowRate
|
|
314
|
+
]?.toString(),
|
|
315
|
+
),
|
|
178
316
|
stakingYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
179
317
|
|
|
180
318
|
// rewards
|
|
181
319
|
rewards: {
|
|
182
320
|
LEND: {
|
|
183
|
-
depositRate:
|
|
184
|
-
|
|
321
|
+
depositRate:
|
|
322
|
+
convertRateToApr(collateralRewards / totalDepositsUSD) *
|
|
323
|
+
lendPrice,
|
|
324
|
+
variableBorrowRate:
|
|
325
|
+
convertRateToApr(
|
|
326
|
+
totalDebtUSD > 0 ? borrowRewards / totalDebtUSD : 0,
|
|
327
|
+
) * lendPrice,
|
|
185
328
|
stableBorrowRate: 0,
|
|
186
329
|
},
|
|
187
330
|
},
|
|
188
|
-
decimals: Number(
|
|
331
|
+
decimals: Number(
|
|
332
|
+
configData?.[AaveV2TypeGetReserveConfigurationData.decimals],
|
|
333
|
+
),
|
|
189
334
|
config: {
|
|
190
335
|
[LENDER_MODE_NO_MODE]: {
|
|
191
336
|
category: LENDER_MODE_NO_MODE,
|
|
192
337
|
// collateral factors
|
|
193
|
-
borrowCollateralFactor:
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
338
|
+
borrowCollateralFactor:
|
|
339
|
+
Number(
|
|
340
|
+
configData?.[
|
|
341
|
+
AaveV2TypeGetReserveConfigurationData.ltv
|
|
342
|
+
].toString(),
|
|
343
|
+
) / BPS,
|
|
344
|
+
collateralFactor:
|
|
345
|
+
Number(
|
|
346
|
+
configData?.[
|
|
347
|
+
AaveV2TypeGetReserveConfigurationData
|
|
348
|
+
.liquidationThreshold
|
|
349
|
+
].toString(),
|
|
350
|
+
) / BPS,
|
|
351
|
+
borrowFactor: 1,
|
|
352
|
+
},
|
|
197
353
|
},
|
|
198
|
-
liquidationBonus:
|
|
354
|
+
liquidationBonus:
|
|
355
|
+
Number(
|
|
356
|
+
configData?.[
|
|
357
|
+
AaveV2TypeGetReserveConfigurationData.liquidationBonus
|
|
358
|
+
].toString(),
|
|
359
|
+
) / BPS,
|
|
199
360
|
// flags
|
|
200
|
-
collateralActive:
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
361
|
+
collateralActive:
|
|
362
|
+
configData?.[
|
|
363
|
+
AaveV2TypeGetReserveConfigurationData.usageAsCollateralEnabled
|
|
364
|
+
],
|
|
365
|
+
borrowingEnabled:
|
|
366
|
+
configData?.[
|
|
367
|
+
AaveV2TypeGetReserveConfigurationData.borrowingEnabled
|
|
368
|
+
],
|
|
369
|
+
hasStable:
|
|
370
|
+
configData?.[
|
|
371
|
+
AaveV2TypeGetReserveConfigurationData.stableBorrowRateEnabled
|
|
372
|
+
],
|
|
373
|
+
isActive:
|
|
374
|
+
configData?.[AaveV2TypeGetReserveConfigurationData.isActive],
|
|
375
|
+
isFrozen:
|
|
376
|
+
configData?.[AaveV2TypeGetReserveConfigurationData.isFrozen],
|
|
205
377
|
}
|
|
206
378
|
}
|
|
207
379
|
return {
|
|
@@ -231,15 +403,35 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
231
403
|
const reserveData = data[i * 2]
|
|
232
404
|
const configData = data[i * 2 + 1]
|
|
233
405
|
|
|
234
|
-
const assetMeta = tokenList[asset]
|
|
406
|
+
const assetMeta = tokenList[asset]
|
|
235
407
|
const decimals = assetMeta?.decimals ?? 18
|
|
236
408
|
|
|
237
|
-
const totalStableDebt = parseRawAmount(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
409
|
+
const totalStableDebt = parseRawAmount(
|
|
410
|
+
reserveData?.[
|
|
411
|
+
AaveV2TypeGetReserveDataIndexes.totalStableDebt
|
|
412
|
+
]?.toString(),
|
|
413
|
+
decimals,
|
|
414
|
+
)
|
|
415
|
+
const totalVariableDebt = parseRawAmount(
|
|
416
|
+
reserveData?.[
|
|
417
|
+
AaveV2TypeGetReserveDataIndexes.totalVariableDebt
|
|
418
|
+
]?.toString(),
|
|
419
|
+
decimals,
|
|
420
|
+
)
|
|
421
|
+
const liquidity = Number(
|
|
422
|
+
parseRawAmount(
|
|
423
|
+
reserveData?.[
|
|
424
|
+
AaveV2TypeGetReserveDataIndexes.availableLiquidity
|
|
425
|
+
]?.toString(),
|
|
426
|
+
decimals,
|
|
427
|
+
),
|
|
428
|
+
)
|
|
429
|
+
const totalAToken =
|
|
430
|
+
liquidity + Number(totalStableDebt) + Number(totalVariableDebt)
|
|
431
|
+
|
|
432
|
+
const oracleKey =
|
|
433
|
+
toOracleKey(assetMeta?.assetGroup) ??
|
|
434
|
+
toGenericPriceKey(asset, chainId)
|
|
243
435
|
const price = prices[oracleKey] ?? 1
|
|
244
436
|
|
|
245
437
|
const totalDepositsUSD = Number(totalAToken) * price
|
|
@@ -260,36 +452,86 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
260
452
|
totalDebtUSD,
|
|
261
453
|
totalLiquidityUSD: liquidity * price,
|
|
262
454
|
// rates
|
|
263
|
-
depositRate: formatAaveRawApyToApr(
|
|
264
|
-
|
|
265
|
-
|
|
455
|
+
depositRate: formatAaveRawApyToApr(
|
|
456
|
+
reserveData?.[
|
|
457
|
+
AaveV2TypeGetReserveDataIndexes.liquidityRate
|
|
458
|
+
]?.toString(),
|
|
459
|
+
),
|
|
460
|
+
variableBorrowRate: formatAaveRawApyToApr(
|
|
461
|
+
reserveData?.[
|
|
462
|
+
AaveV2TypeGetReserveDataIndexes.variableBorrowRate
|
|
463
|
+
]?.toString(),
|
|
464
|
+
),
|
|
465
|
+
stableBorrowRate: formatAaveRawApyToApr(
|
|
466
|
+
reserveData?.[
|
|
467
|
+
AaveV2TypeGetReserveDataIndexes.stableBorrowRate
|
|
468
|
+
]?.toString(),
|
|
469
|
+
),
|
|
266
470
|
stakingYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
267
471
|
|
|
268
472
|
// rewards
|
|
269
|
-
rewards:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
473
|
+
rewards:
|
|
474
|
+
lender === Lender.MERIDIAN && chainId === Chain.TAIKO_ALETHIA
|
|
475
|
+
? {
|
|
476
|
+
TAIKO: {
|
|
477
|
+
depositRate:
|
|
478
|
+
additionalYields.lenderRewards[Lender.MERIDIAN]?.[
|
|
479
|
+
asset
|
|
480
|
+
]?.deposit ?? 0,
|
|
481
|
+
variableBorrowRate:
|
|
482
|
+
additionalYields.lenderRewards[Lender.MERIDIAN]?.[
|
|
483
|
+
asset
|
|
484
|
+
]?.borrow ?? 0,
|
|
485
|
+
stableBorrowRate: 0,
|
|
486
|
+
},
|
|
487
|
+
}
|
|
488
|
+
: {},
|
|
489
|
+
decimals: Number(
|
|
490
|
+
configData?.[AaveV2TypeGetReserveConfigurationData.decimals],
|
|
491
|
+
),
|
|
277
492
|
config: {
|
|
278
493
|
[LENDER_MODE_NO_MODE]: {
|
|
279
494
|
category: LENDER_MODE_NO_MODE,
|
|
280
495
|
// collateral factors
|
|
281
|
-
borrowCollateralFactor:
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
496
|
+
borrowCollateralFactor:
|
|
497
|
+
Number(
|
|
498
|
+
configData?.[
|
|
499
|
+
AaveV2TypeGetReserveConfigurationData.ltv
|
|
500
|
+
].toString(),
|
|
501
|
+
) / BPS,
|
|
502
|
+
collateralFactor:
|
|
503
|
+
Number(
|
|
504
|
+
configData?.[
|
|
505
|
+
AaveV2TypeGetReserveConfigurationData
|
|
506
|
+
.liquidationThreshold
|
|
507
|
+
].toString(),
|
|
508
|
+
) / BPS,
|
|
509
|
+
borrowFactor: 1,
|
|
510
|
+
},
|
|
285
511
|
},
|
|
286
|
-
liquidationBonus:
|
|
512
|
+
liquidationBonus:
|
|
513
|
+
Number(
|
|
514
|
+
configData?.[
|
|
515
|
+
AaveV2TypeGetReserveConfigurationData.liquidationBonus
|
|
516
|
+
].toString(),
|
|
517
|
+
) / BPS,
|
|
287
518
|
// flags
|
|
288
|
-
collateralActive:
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
519
|
+
collateralActive:
|
|
520
|
+
configData?.[
|
|
521
|
+
AaveV2TypeGetReserveConfigurationData.usageAsCollateralEnabled
|
|
522
|
+
],
|
|
523
|
+
borrowingEnabled:
|
|
524
|
+
configData?.[
|
|
525
|
+
AaveV2TypeGetReserveConfigurationData.borrowingEnabled
|
|
526
|
+
],
|
|
527
|
+
hasStable:
|
|
528
|
+
configData?.[
|
|
529
|
+
AaveV2TypeGetReserveConfigurationData.stableBorrowRateEnabled
|
|
530
|
+
],
|
|
531
|
+
isActive:
|
|
532
|
+
configData?.[AaveV2TypeGetReserveConfigurationData.isActive],
|
|
533
|
+
isFrozen:
|
|
534
|
+
configData?.[AaveV2TypeGetReserveConfigurationData.isFrozen],
|
|
293
535
|
}
|
|
294
536
|
}
|
|
295
537
|
|
|
@@ -302,4 +544,4 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
302
544
|
]
|
|
303
545
|
}
|
|
304
546
|
}
|
|
305
|
-
}
|
|
547
|
+
}
|
|
@@ -5,7 +5,10 @@ export const addressesMeridianCore = {
|
|
|
5
5
|
[Chain.TAIKO_ALETHIA]: '0xd79417be2cE02fc22F2E520869b1DfC02a677751',
|
|
6
6
|
},
|
|
7
7
|
IncentivesController: {
|
|
8
|
-
[Chain.TAIKO_ALETHIA]: '0xb3020EbFD800B488B64E92A8717E826cBf0d63E2'
|
|
8
|
+
[Chain.TAIKO_ALETHIA]: '0xb3020EbFD800B488B64E92A8717E826cBf0d63E2',
|
|
9
|
+
[Chain.TELOS_EVM_MAINNET]: '0x406F044A5aBF071db08E4482c3487331Cf284ADc',
|
|
10
|
+
[Chain.FUSE_MAINNET]: '0xd2Fa60C6fab6EdF77E78A0908066d04a5F5EB1E0',
|
|
11
|
+
[Chain.METER_MAINNET]: '0xBAE27c0F27A7bff3f391A19E0dE2d241E2497a09',
|
|
9
12
|
},
|
|
10
13
|
MultiFeeDistribution: {
|
|
11
14
|
[Chain.TAIKO_ALETHIA]: '0xb0e103e2A80489Ba697D882EEd0Ba552389Ca31E'
|
|
@@ -141,6 +141,12 @@ const WBERA = '0x6969696969696969696969696969696969696969'
|
|
|
141
141
|
const prefixCronos = 'cronos:'
|
|
142
142
|
const WCRO = '0x5c7f8a570d578ed84e63fdfa7b1ee72deae1ae23'
|
|
143
143
|
|
|
144
|
+
const prefixTelos = 'telos:'
|
|
145
|
+
const wtlos = '0xd102ce6a4db07d247fcc28f366a623df0938ca9e'
|
|
146
|
+
|
|
147
|
+
const prefixManta = 'manta:'
|
|
148
|
+
const manta = '0x95cef13441be50d20ca4558cc0a27b601ac544e5'
|
|
149
|
+
|
|
144
150
|
// const prefixKaia = 'kaia:'
|
|
145
151
|
// const WKAIA = '0x19aac5f612f524b754ca7e7c41cbfa2e981a4432'
|
|
146
152
|
|
|
@@ -161,7 +167,9 @@ const datasHyperEvm = [WYPE, WSTHYPE, kHYPE]
|
|
|
161
167
|
const datasSolana = [JITOSOL, SOL].map((d) => prefixSolana + d).join(',')
|
|
162
168
|
const datasBera = [WBERA].map((d) => prefixBera + d).join(',')
|
|
163
169
|
const datasXdc = [WXDC].map((d) => prefixXdc + d).join(',')
|
|
164
|
-
const
|
|
170
|
+
const datasCronos = [WCRO].map((d) => prefixCronos + d).join(',')
|
|
171
|
+
const datasManta = [manta].map((d) => prefixManta + d).join(',')
|
|
172
|
+
const datasTelos = [wtlos].map((d) => prefixTelos + d).join(',')
|
|
165
173
|
// const datasKaia = [WKAIA].map((d) => prefixKaia + d).join(',')
|
|
166
174
|
|
|
167
175
|
const URL = `https://coins.llama.fi/prices/current/${[
|
|
@@ -180,7 +188,9 @@ const URL = `https://coins.llama.fi/prices/current/${[
|
|
|
180
188
|
datasSolana,
|
|
181
189
|
datasBera,
|
|
182
190
|
datasXdc,
|
|
183
|
-
|
|
191
|
+
datasCronos,
|
|
192
|
+
datasManta,
|
|
193
|
+
datasTelos,
|
|
184
194
|
].join(',')}?searchWidth=4h`
|
|
185
195
|
const URL_HIST = (ref: number) =>
|
|
186
196
|
`https://coins.llama.fi/prices/historical/${ref}/${[
|
|
@@ -268,10 +278,12 @@ const SYMBOL_MAP = {
|
|
|
268
278
|
usual: 'Usual::USUAL',
|
|
269
279
|
woeth: 'Wrapped OETH::WOETH',
|
|
270
280
|
jitosol: 'Jito Staked SOL::JitoSOL',
|
|
281
|
+
manta: 'Manta::MANTA',
|
|
271
282
|
sol: 'SOL',
|
|
272
283
|
wcro: 'WCRO',
|
|
273
284
|
wxdc: 'WXDC',
|
|
274
285
|
wbera: 'WBERA',
|
|
286
|
+
wtlos: 'WTLOS',
|
|
275
287
|
}
|
|
276
288
|
|
|
277
289
|
export async function fetchDefillamaData() {
|
|
@@ -297,6 +309,7 @@ export async function fetchDefillamaData() {
|
|
|
297
309
|
prices['CRO'] = prices['WCRO']
|
|
298
310
|
prices['XDC'] = prices['WXDC']
|
|
299
311
|
prices['BERA'] = prices['WBERA']
|
|
312
|
+
prices['TLOS'] = prices['WTLOS']
|
|
300
313
|
// prices['WKAIA'] = prices['KAIA']
|
|
301
314
|
|
|
302
315
|
prices['USDBC'] = prices['USDC']
|
|
@@ -345,6 +358,7 @@ export async function fetchDefillamaHistData() {
|
|
|
345
358
|
histPrices['BERA'] = histPrices['WBERA']
|
|
346
359
|
histPrices['CRO'] = histPrices['WCRO']
|
|
347
360
|
histPrices['XDC'] = histPrices['WXDC']
|
|
361
|
+
histPrices['TLOS'] = histPrices['WTLOS']
|
|
348
362
|
// histPrices['WKAIA'] = histPrices['KAIA']
|
|
349
363
|
|
|
350
364
|
histPrices['LUSD'] = histPrices['USDT']
|
|
@@ -457,6 +457,7 @@ function lowDecimalOracle(chainId: string, fork: string) {
|
|
|
457
457
|
return false
|
|
458
458
|
}
|
|
459
459
|
if (chainId === Chain.XDC_NETWORK) return true
|
|
460
|
+
if (chainId === Chain.TELOS_EVM_MAINNET) return true
|
|
460
461
|
// otherwise, it depends on whether it is aave V3
|
|
461
462
|
return AAVE_V2_LENDERS.includes(fork as any)
|
|
462
463
|
}
|
|
@@ -15,11 +15,11 @@ describe(
|
|
|
15
15
|
it('flash liquidity for chain', async () => {
|
|
16
16
|
await fetchLenderMetaFromDirAndInitialize()
|
|
17
17
|
|
|
18
|
-
const chain = Chain.
|
|
18
|
+
const chain = Chain.MORPH
|
|
19
19
|
const list = await getDeltaTokenList(chain)
|
|
20
20
|
const liquidity = await fetchFlashLiquidityForChain(chain, multicallRetry, list)
|
|
21
21
|
|
|
22
|
-
console.log('liquidity', liquidity
|
|
22
|
+
console.log('liquidity', liquidity)
|
|
23
23
|
|
|
24
24
|
// const prices = await fetchMainPrices([chain])
|
|
25
25
|
|
package/test/lenderData.test.ts
CHANGED
|
@@ -20,7 +20,7 @@ describe(
|
|
|
20
20
|
it.only('should return lender data', async () => {
|
|
21
21
|
await fetchLenderMetaFromDirAndInitialize()
|
|
22
22
|
|
|
23
|
-
const chainId = Chain.
|
|
23
|
+
const chainId = Chain.MORPH
|
|
24
24
|
const list = await getDeltaTokenList(chainId)
|
|
25
25
|
const ps = [
|
|
26
26
|
fetchMainPrices([chainId], undefined, { [chainId]: { list } }),
|
|
@@ -32,7 +32,7 @@ describe(
|
|
|
32
32
|
// console.log("yields", yields)
|
|
33
33
|
// console.log("prices", prices)
|
|
34
34
|
|
|
35
|
-
const lenders =
|
|
35
|
+
const lenders = getLendersForChain(chainId) as any
|
|
36
36
|
console.log('lenders', lenders)
|
|
37
37
|
const lendingData = await getLenderPublicData(
|
|
38
38
|
chainId,
|
package/test/mainPrices.test.ts
CHANGED
|
@@ -9,10 +9,11 @@ describe(
|
|
|
9
9
|
it('should return prices for valid tokens', async () => {
|
|
10
10
|
|
|
11
11
|
await fetchLenderMetaFromDirAndInitialize()
|
|
12
|
-
const
|
|
12
|
+
const chainId = Chain.MORPH
|
|
13
|
+
const list = await getDeltaTokenList(chainId)
|
|
13
14
|
const mainPrices = await fetchMainPrices([
|
|
14
|
-
|
|
15
|
-
],undefined, {[
|
|
15
|
+
chainId,
|
|
16
|
+
],undefined, {[chainId]: {list}})
|
|
16
17
|
// console.log(mainPrices['Hemi::HEMI'])
|
|
17
18
|
prettyPrint(mainPrices)
|
|
18
19
|
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
getLenderUserDataResult,
|
|
4
|
+
convertLenderUserDataResult,
|
|
5
|
+
} from '../src/lending/user-data/fetchUserData'
|
|
6
|
+
import { getEvmClient } from '@1delta/providers'
|
|
7
|
+
import { Chain } from '@1delta/chain-registry'
|
|
8
|
+
import { prettyPrint } from './utils'
|
|
9
|
+
import { TestDataMainnet } from './dataMainnet'
|
|
10
|
+
import { fetchLenderMetaFromDirAndInitialize } from '../src/lending'
|
|
11
|
+
|
|
12
|
+
const queries = {
|
|
13
|
+
'40': [
|
|
14
|
+
{
|
|
15
|
+
account: '0xbadA9c382165b31419F4CC0eDf0Fa84f80A3C8E5',
|
|
16
|
+
lender: 'MERIDIAN',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function getUserData(chainIds: string[]) {
|
|
22
|
+
let promises: any[] = []
|
|
23
|
+
for (const chainId of chainIds) {
|
|
24
|
+
const chainQueries = queries[chainId]
|
|
25
|
+
if (!chainQueries?.length) continue
|
|
26
|
+
promises.push(
|
|
27
|
+
getLenderUserDataResult(
|
|
28
|
+
chainId,
|
|
29
|
+
chainQueries,
|
|
30
|
+
getEvmClient,
|
|
31
|
+
false,
|
|
32
|
+
undefined,
|
|
33
|
+
3,
|
|
34
|
+
false,
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const res = await Promise.all(promises)
|
|
40
|
+
const results: Record<string, any[]> = {}
|
|
41
|
+
chainIds.forEach((chainId, i) => {
|
|
42
|
+
results[chainId] = res[i]
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const userData: { [chainId: string]: any } = {}
|
|
46
|
+
|
|
47
|
+
for (const chainId of chainIds) {
|
|
48
|
+
const raw = results[chainId]
|
|
49
|
+
if (!raw) continue
|
|
50
|
+
// convert data
|
|
51
|
+
const converted = convertLenderUserDataResult(
|
|
52
|
+
chainId,
|
|
53
|
+
queries[chainId],
|
|
54
|
+
raw,
|
|
55
|
+
TestDataMainnet.allData.prices,
|
|
56
|
+
{},
|
|
57
|
+
TestDataMainnet.allData.data,
|
|
58
|
+
)
|
|
59
|
+
userData[chainId] = converted
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { userData }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe(
|
|
66
|
+
'user data fetching',
|
|
67
|
+
() => {
|
|
68
|
+
it.only(
|
|
69
|
+
'should fetch user data for Morpho on Base',
|
|
70
|
+
async () => {
|
|
71
|
+
await fetchLenderMetaFromDirAndInitialize()
|
|
72
|
+
|
|
73
|
+
const { userData } = await getUserData([Chain.TELOS_EVM_MAINNET])
|
|
74
|
+
|
|
75
|
+
prettyPrint(userData)
|
|
76
|
+
|
|
77
|
+
// Basic validation
|
|
78
|
+
expect(userData).toBeDefined()
|
|
79
|
+
expect(typeof userData).toBe('object')
|
|
80
|
+
},
|
|
81
|
+
{ timeout: 30000 },
|
|
82
|
+
)
|
|
83
|
+
},
|
|
84
|
+
{ timeout: 90000 },
|
|
85
|
+
)
|