@1delta/margin-fetcher 0.0.213 → 0.0.214
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/index.js +787 -6
- package/dist/index.js.map +1 -1
- package/dist/lending/public-data/aave-v4-type/fetcher/normalize.d.ts +96 -0
- package/dist/lending/public-data/aave-v4-type/fetcher/normalize.d.ts.map +1 -0
- package/dist/lending/public-data/aave-v4-type/fetcher/types.d.ts +85 -0
- package/dist/lending/public-data/aave-v4-type/fetcher/types.d.ts.map +1 -0
- package/dist/lending/public-data/aave-v4-type/publicCallBuild.d.ts +37 -0
- package/dist/lending/public-data/aave-v4-type/publicCallBuild.d.ts.map +1 -0
- package/dist/lending/public-data/aave-v4-type/publicCallParse.d.ts +10 -0
- package/dist/lending/public-data/aave-v4-type/publicCallParse.d.ts.map +1 -0
- package/dist/lending/public-data/fetchLender.d.ts.map +1 -1
- package/dist/lending/user-data/aave-v4-type/userCallBuild.d.ts +22 -0
- package/dist/lending/user-data/aave-v4-type/userCallBuild.d.ts.map +1 -0
- package/dist/lending/user-data/aave-v4-type/userCallParse.d.ts +15 -0
- package/dist/lending/user-data/aave-v4-type/userCallParse.d.ts.map +1 -0
- package/dist/lending/user-data/abis.d.ts.map +1 -1
- package/dist/lending/user-data/fetch-balances/parse.d.ts.map +1 -1
- package/dist/lending/user-data/fetch-balances/prepare.d.ts.map +1 -1
- package/dist/lending/user-data/with-permissions/evaluate.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchOraclePrices.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/aaveV4.d.ts +31 -0
- package/dist/prices/oracle-prices/fetchers/aaveV4.d.ts.map +1 -0
- package/dist/prices/oracle-prices/fetchers/index.d.ts +1 -0
- package/dist/prices/oracle-prices/fetchers/index.d.ts.map +1 -1
- package/dist/prices/oracle-prices/types.d.ts +18 -0
- package/dist/prices/oracle-prices/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { parseAbi, formatEther, BaseError, encodeFunctionData, formatUnits, decodeFunctionResult, decodeAbiParameters, AbiEncodingLengthMismatchError, concatHex, isAddress, InvalidAddressError, pad, stringToHex, boolToHex, integerRegex, numberToHex, bytesRegex, BytesSizeMismatchError, arrayRegex, UnsupportedPackedAbiType } from './chunk-ZVIJSUIM.js';
|
|
2
2
|
import './chunk-BYTNVMX7.js';
|
|
3
3
|
import './chunk-PR4QN5HX.js';
|
|
4
|
-
import { Lender, isAaveType, isCompoundV3, isMultiMarket, isInit, isMorphoType, isCompoundV2Type, isVenusType, isSumerType, AAVE_V3_LENDERS, AAVE_V2_LENDERS, isAaveV2Type, isAaveV32Type, isAaveV3Type, isEulerType, isYLDR, isCompoundV3Type, isTectonicType, isBenqiType
|
|
4
|
+
import { Lender, isAaveType, isCompoundV3, isMultiMarket, isInit, isMorphoType, isCompoundV2Type, isVenusType, isSumerType, AAVE_V3_LENDERS, AAVE_V2_LENDERS, isAaveV2Type, isAaveV32Type, isAaveV3Type, isEulerType, isAaveV4Type, isYLDR, isCompoundV3Type, isLista, isTectonicType, isBenqiType } from '@1delta/lender-registry';
|
|
5
5
|
export { isAaveType, isAaveV2Type, isAaveV32Type, isAaveV3Type, isCompoundV3, isCompoundV3Type, isInit, isMorphoType, isMultiMarket, isYLDR } from '@1delta/lender-registry';
|
|
6
6
|
import lodash from 'lodash';
|
|
7
7
|
import { getEvmChain, multicallRetryUniversal, getEvmClient, getEvmClientUniversal } from '@1delta/providers';
|
|
8
|
-
import { MorphoLensAbi, MorphoBlueAbi } from '@1delta/abis';
|
|
8
|
+
import { MorphoLensAbi, AaveV4SpokeAbi, AaveV4OracleAbi, AaveV4HubAbi, MorphoBlueAbi } from '@1delta/abis';
|
|
9
9
|
export { MorphoLensAbi } from '@1delta/abis';
|
|
10
|
-
import { prepareDebitDataMulticall, prepareLenderDebitMulticall, parseDebitDataResult, parseLenderDebitResult, getPermit2ContractAddress, InitMarginAddresses } from '@1delta/calldata-sdk';
|
|
10
|
+
import { prepareDebitDataMulticall, prepareLenderDebitMulticall, parseDebitDataResult, parseLenderDebitResult, getPermit2ContractAddress, getCompoundV3CometAddress as getCompoundV3CometAddress$1, getMorphoAddress, getAaveCollateralTokenAddress, InitMarginAddresses } from '@1delta/calldata-sdk';
|
|
11
11
|
import { BALANCER_V2_FORKS, BALANCER_V3_FORKS, UNISWAP_V4_FORKS, FLASH_LOAN_IDS } from '@1delta/dex-registry';
|
|
12
12
|
|
|
13
13
|
// src/abis/aave-v2/ProtocolDataProvider.ts
|
|
@@ -6274,7 +6274,10 @@ globalThis[GLOBAL_LENDER_DATA_KEY] = {
|
|
|
6274
6274
|
listaNativeProvider: {},
|
|
6275
6275
|
compoundV3Bulker: {},
|
|
6276
6276
|
eulerConfigs: {},
|
|
6277
|
-
eulerVaults: {}
|
|
6277
|
+
eulerVaults: {},
|
|
6278
|
+
aaveV4Spokes: {},
|
|
6279
|
+
aaveV4Reserves: {},
|
|
6280
|
+
aaveV4Oracles: {}
|
|
6278
6281
|
};
|
|
6279
6282
|
function getGlobalData2() {
|
|
6280
6283
|
return globalThis[GLOBAL_LENDER_DATA_KEY];
|
|
@@ -6299,6 +6302,9 @@ var initConfig = () => getGlobalData2()?.initConfig;
|
|
|
6299
6302
|
var aaveOraclesConfig = () => getGlobalData2()?.aaveOraclesConfig;
|
|
6300
6303
|
var eulerConfigs = () => getGlobalData2()?.eulerConfigs;
|
|
6301
6304
|
var eulerVaults = () => getGlobalData2()?.eulerVaults;
|
|
6305
|
+
var aaveV4Spokes = () => getGlobalData2()?.aaveV4Spokes;
|
|
6306
|
+
var aaveV4Reserves = () => getGlobalData2()?.aaveV4Reserves;
|
|
6307
|
+
var aaveV4Oracles = () => getGlobalData2()?.aaveV4Oracles;
|
|
6302
6308
|
var getListUrl = (chainId) => `https://raw.githubusercontent.com/1delta-DAO/token-lists/main/${chainId}.json`;
|
|
6303
6309
|
async function fetchTokenList(chainId) {
|
|
6304
6310
|
const data = await fetch(getListUrl(chainId));
|
|
@@ -7529,6 +7535,9 @@ var getLendersForChain = (c) => {
|
|
|
7529
7535
|
if (data[c]?.length > 0) lenders.push(l);
|
|
7530
7536
|
});
|
|
7531
7537
|
}
|
|
7538
|
+
Object.entries(aaveV4Spokes() ?? {}).forEach(([l, data]) => {
|
|
7539
|
+
if (data[c]?.length > 0) lenders.push(l);
|
|
7540
|
+
});
|
|
7532
7541
|
return lenders;
|
|
7533
7542
|
};
|
|
7534
7543
|
var filterLendersByProtocol = (allLenders, protocolList) => {
|
|
@@ -17883,7 +17892,499 @@ var getEulerV2ReservesDataConverter = (lender, chainId, prices, additionalYields
|
|
|
17883
17892
|
];
|
|
17884
17893
|
};
|
|
17885
17894
|
|
|
17886
|
-
// src/lending/public-data/
|
|
17895
|
+
// src/lending/public-data/aave-v4-type/publicCallBuild.ts
|
|
17896
|
+
var CALLS_PER_RESERVE = 6;
|
|
17897
|
+
var CALLS_PER_SPOKE_TAIL = 2;
|
|
17898
|
+
function hasValidOracle(oracle) {
|
|
17899
|
+
return !!oracle && oracle !== "0x" && oracle.length > 2;
|
|
17900
|
+
}
|
|
17901
|
+
function getSpokeReserves(reservesMap, spokeAddr) {
|
|
17902
|
+
return reservesMap[spokeAddr.toLowerCase()] ?? reservesMap[spokeAddr] ?? [];
|
|
17903
|
+
}
|
|
17904
|
+
var buildAaveV4LenderReserveCall = (chainId, lender) => {
|
|
17905
|
+
const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
|
|
17906
|
+
const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
|
|
17907
|
+
if (spokes.length === 0) return [];
|
|
17908
|
+
const calls = [];
|
|
17909
|
+
const hubAssetKeys = /* @__PURE__ */ new Set();
|
|
17910
|
+
const hubAssetList = [];
|
|
17911
|
+
for (const spokeEntry of spokes) {
|
|
17912
|
+
const spokeAddr = spokeEntry.spoke;
|
|
17913
|
+
const reserves = getSpokeReserves(reservesMap, spokeAddr);
|
|
17914
|
+
for (const entry of reserves) {
|
|
17915
|
+
const rid = typeof entry === "number" ? entry : entry.reserveId;
|
|
17916
|
+
calls.push(
|
|
17917
|
+
{
|
|
17918
|
+
address: spokeAddr,
|
|
17919
|
+
name: "getReserve",
|
|
17920
|
+
params: [rid]
|
|
17921
|
+
},
|
|
17922
|
+
{
|
|
17923
|
+
address: spokeAddr,
|
|
17924
|
+
name: "getReserveConfig",
|
|
17925
|
+
params: [rid]
|
|
17926
|
+
},
|
|
17927
|
+
{
|
|
17928
|
+
address: spokeAddr,
|
|
17929
|
+
name: "getReserveSuppliedAssets",
|
|
17930
|
+
params: [rid]
|
|
17931
|
+
},
|
|
17932
|
+
{
|
|
17933
|
+
address: spokeAddr,
|
|
17934
|
+
name: "getReserveDebt",
|
|
17935
|
+
params: [rid]
|
|
17936
|
+
},
|
|
17937
|
+
{
|
|
17938
|
+
address: spokeAddr,
|
|
17939
|
+
name: "getReserveTotalDebt",
|
|
17940
|
+
params: [rid]
|
|
17941
|
+
},
|
|
17942
|
+
{
|
|
17943
|
+
address: spokeAddr,
|
|
17944
|
+
name: "getDynamicReserveConfig",
|
|
17945
|
+
params: [rid, 0]
|
|
17946
|
+
}
|
|
17947
|
+
);
|
|
17948
|
+
if (typeof entry === "object" && spokeEntry.hub && entry.assetId !== void 0) {
|
|
17949
|
+
const key = `${spokeEntry.hub}:${entry.assetId}`;
|
|
17950
|
+
if (!hubAssetKeys.has(key)) {
|
|
17951
|
+
hubAssetKeys.add(key);
|
|
17952
|
+
hubAssetList.push({
|
|
17953
|
+
hub: spokeEntry.hub,
|
|
17954
|
+
assetId: entry.assetId
|
|
17955
|
+
});
|
|
17956
|
+
}
|
|
17957
|
+
}
|
|
17958
|
+
}
|
|
17959
|
+
calls.push(
|
|
17960
|
+
{
|
|
17961
|
+
address: spokeAddr,
|
|
17962
|
+
name: "getLiquidationConfig",
|
|
17963
|
+
params: []
|
|
17964
|
+
},
|
|
17965
|
+
{
|
|
17966
|
+
address: spokeAddr,
|
|
17967
|
+
name: "ORACLE",
|
|
17968
|
+
params: []
|
|
17969
|
+
}
|
|
17970
|
+
);
|
|
17971
|
+
}
|
|
17972
|
+
for (const spokeEntry of spokes) {
|
|
17973
|
+
const reserves = getSpokeReserves(
|
|
17974
|
+
reservesMap,
|
|
17975
|
+
spokeEntry.spoke
|
|
17976
|
+
);
|
|
17977
|
+
const rids = reserves.map(
|
|
17978
|
+
(e) => typeof e === "number" ? e : e.reserveId
|
|
17979
|
+
);
|
|
17980
|
+
if (rids.length > 0 && hasValidOracle(spokeEntry.oracle)) {
|
|
17981
|
+
calls.push({
|
|
17982
|
+
address: spokeEntry.oracle,
|
|
17983
|
+
name: "getReservesPrices",
|
|
17984
|
+
params: [rids]
|
|
17985
|
+
});
|
|
17986
|
+
}
|
|
17987
|
+
}
|
|
17988
|
+
for (const { hub, assetId } of hubAssetList) {
|
|
17989
|
+
calls.push(
|
|
17990
|
+
{
|
|
17991
|
+
address: hub,
|
|
17992
|
+
name: "getAsset",
|
|
17993
|
+
params: [assetId]
|
|
17994
|
+
},
|
|
17995
|
+
{
|
|
17996
|
+
address: hub,
|
|
17997
|
+
name: "getAddedAssets",
|
|
17998
|
+
params: [assetId]
|
|
17999
|
+
},
|
|
18000
|
+
{
|
|
18001
|
+
address: hub,
|
|
18002
|
+
name: "getAssetTotalOwed",
|
|
18003
|
+
params: [assetId]
|
|
18004
|
+
}
|
|
18005
|
+
);
|
|
18006
|
+
}
|
|
18007
|
+
return calls;
|
|
18008
|
+
};
|
|
18009
|
+
var getAaveV4ExpectedCallCount = (chainId, lender) => {
|
|
18010
|
+
const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
|
|
18011
|
+
const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
|
|
18012
|
+
let count = 0;
|
|
18013
|
+
const hubAssetKeys = /* @__PURE__ */ new Set();
|
|
18014
|
+
for (const spokeEntry of spokes) {
|
|
18015
|
+
const reserves = getSpokeReserves(
|
|
18016
|
+
reservesMap,
|
|
18017
|
+
spokeEntry.spoke
|
|
18018
|
+
);
|
|
18019
|
+
count += reserves.length * CALLS_PER_RESERVE + CALLS_PER_SPOKE_TAIL;
|
|
18020
|
+
const rids = reserves.map(
|
|
18021
|
+
(e) => typeof e === "number" ? e : e.reserveId
|
|
18022
|
+
);
|
|
18023
|
+
if (rids.length > 0 && hasValidOracle(spokeEntry.oracle)) {
|
|
18024
|
+
count += 1;
|
|
18025
|
+
}
|
|
18026
|
+
for (const entry of reserves) {
|
|
18027
|
+
if (typeof entry === "object" && spokeEntry.hub && entry.assetId !== void 0) {
|
|
18028
|
+
hubAssetKeys.add(`${spokeEntry.hub}:${entry.assetId}`);
|
|
18029
|
+
}
|
|
18030
|
+
}
|
|
18031
|
+
}
|
|
18032
|
+
count += hubAssetKeys.size * 3;
|
|
18033
|
+
return count;
|
|
18034
|
+
};
|
|
18035
|
+
|
|
18036
|
+
// src/lending/public-data/aave-v4-type/fetcher/normalize.ts
|
|
18037
|
+
function toTokenAmount2(raw, decimals) {
|
|
18038
|
+
if (raw === 0n) return "0";
|
|
18039
|
+
const divisor = 10 ** decimals;
|
|
18040
|
+
return (Number(raw) / divisor).toString();
|
|
18041
|
+
}
|
|
18042
|
+
function toTokenNumber(raw, decimals) {
|
|
18043
|
+
if (raw === 0n) return 0;
|
|
18044
|
+
return Number(raw) / 10 ** decimals;
|
|
18045
|
+
}
|
|
18046
|
+
var RAY2 = 1e27;
|
|
18047
|
+
function rayRateToApr(rateRay) {
|
|
18048
|
+
if (rateRay === 0n) return 0;
|
|
18049
|
+
return Number(rateRay) / RAY2 * 100;
|
|
18050
|
+
}
|
|
18051
|
+
function normalizeAaveV4(spokeDataList, chainId, lender, prices, additionalYields, tokenList, lenderShortNameFn, createMarketUidFn, toOracleKeyFn, toGenericPriceKeyFn) {
|
|
18052
|
+
const data = {};
|
|
18053
|
+
const eModes = {};
|
|
18054
|
+
for (const spokeData of spokeDataList) {
|
|
18055
|
+
const spokeAddr = spokeData.spoke.toLowerCase();
|
|
18056
|
+
const spokeReserves = spokeData.reserves;
|
|
18057
|
+
for (const reserve of spokeReserves) {
|
|
18058
|
+
for (const [keyStr, dynCfg] of Object.entries(
|
|
18059
|
+
reserve.dynamicConfigs
|
|
18060
|
+
)) {
|
|
18061
|
+
const configKey = `${spokeAddr}:${keyStr}`;
|
|
18062
|
+
if (!eModes[configKey] && dynCfg.collateralFactor > 0) {
|
|
18063
|
+
eModes[configKey] = {
|
|
18064
|
+
category: configKey,
|
|
18065
|
+
label: `${spokeData.label} / Config ${keyStr}`,
|
|
18066
|
+
borrowCollateralFactor: dynCfg.collateralFactor / BPS,
|
|
18067
|
+
collateralFactor: dynCfg.collateralFactor / BPS,
|
|
18068
|
+
priceSource: spokeData.oracle
|
|
18069
|
+
};
|
|
18070
|
+
}
|
|
18071
|
+
}
|
|
18072
|
+
}
|
|
18073
|
+
for (const reserve of spokeReserves) {
|
|
18074
|
+
const underlying = reserve.reserve.underlying.toLowerCase();
|
|
18075
|
+
const decimals = reserve.reserve.decimals;
|
|
18076
|
+
const refAddress = `${spokeAddr}:${reserve.reserveId}`;
|
|
18077
|
+
const marketUid = createMarketUidFn(chainId, lender, refAddress);
|
|
18078
|
+
const assetMeta = tokenList[underlying];
|
|
18079
|
+
const oracleKey = toOracleKeyFn(assetMeta?.assetGroup ?? null) ?? toGenericPriceKeyFn(underlying, chainId);
|
|
18080
|
+
let price = 0;
|
|
18081
|
+
if (reserve.price > 0n) {
|
|
18082
|
+
price = Number(reserve.price) / 10 ** spokeData.oracleDecimals;
|
|
18083
|
+
} else {
|
|
18084
|
+
price = prices[oracleKey] ?? 0;
|
|
18085
|
+
}
|
|
18086
|
+
const totalDeposits = toTokenAmount2(
|
|
18087
|
+
reserve.suppliedAssets,
|
|
18088
|
+
decimals
|
|
18089
|
+
);
|
|
18090
|
+
const totalDebt = toTokenAmount2(reserve.totalDebt, decimals);
|
|
18091
|
+
const totalDepositsNum = toTokenNumber(
|
|
18092
|
+
reserve.suppliedAssets,
|
|
18093
|
+
decimals
|
|
18094
|
+
);
|
|
18095
|
+
const totalDebtNum = toTokenNumber(reserve.totalDebt, decimals);
|
|
18096
|
+
const liquidity = totalDepositsNum - totalDebtNum;
|
|
18097
|
+
const variableBorrowRate = rayRateToApr(
|
|
18098
|
+
reserve.hubAsset.drawnRate
|
|
18099
|
+
);
|
|
18100
|
+
const hubDecimals = reserve.hubAsset.decimals || decimals;
|
|
18101
|
+
const hubTotalSupply = toTokenNumber(
|
|
18102
|
+
reserve.hubAsset.totalAddedAssets ?? 0n,
|
|
18103
|
+
hubDecimals
|
|
18104
|
+
);
|
|
18105
|
+
const hubTotalOwed = toTokenNumber(
|
|
18106
|
+
reserve.hubAsset.totalOwedAssets ?? 0n,
|
|
18107
|
+
hubDecimals
|
|
18108
|
+
);
|
|
18109
|
+
const hubUtilization = hubTotalSupply > 0 ? hubTotalOwed / hubTotalSupply : 0;
|
|
18110
|
+
const feeRate = reserve.hubAsset.liquidityFee ? reserve.hubAsset.liquidityFee / BPS : 0;
|
|
18111
|
+
const depositRate = variableBorrowRate * hubUtilization * (1 - feeRate);
|
|
18112
|
+
const config = {};
|
|
18113
|
+
for (const [keyStr, dynCfg] of Object.entries(
|
|
18114
|
+
reserve.dynamicConfigs
|
|
18115
|
+
)) {
|
|
18116
|
+
const configKey = `${spokeAddr}:${keyStr}`;
|
|
18117
|
+
config[configKey] = {
|
|
18118
|
+
category: configKey,
|
|
18119
|
+
label: `${spokeData.label} / Config ${keyStr}`,
|
|
18120
|
+
borrowCollateralFactor: dynCfg.collateralFactor / BPS,
|
|
18121
|
+
collateralFactor: dynCfg.collateralFactor / BPS,
|
|
18122
|
+
borrowFactor: 1,
|
|
18123
|
+
collateralDisabled: dynCfg.collateralFactor === 0 || reserve.config.paused,
|
|
18124
|
+
debtDisabled: !reserve.config.borrowable || reserve.config.paused
|
|
18125
|
+
};
|
|
18126
|
+
}
|
|
18127
|
+
if (Object.keys(config).length === 0) {
|
|
18128
|
+
const defaultKey = `${spokeAddr}:0`;
|
|
18129
|
+
config[defaultKey] = {
|
|
18130
|
+
category: defaultKey,
|
|
18131
|
+
label: `${spokeData.label} / Default`,
|
|
18132
|
+
borrowCollateralFactor: 0,
|
|
18133
|
+
collateralFactor: 0,
|
|
18134
|
+
borrowFactor: 1,
|
|
18135
|
+
collateralDisabled: true,
|
|
18136
|
+
debtDisabled: !reserve.config.borrowable || reserve.config.paused
|
|
18137
|
+
};
|
|
18138
|
+
}
|
|
18139
|
+
data[marketUid] = {
|
|
18140
|
+
marketUid,
|
|
18141
|
+
name: lenderShortNameFn(lender) + " " + (assetMeta?.symbol ?? ""),
|
|
18142
|
+
poolId: underlying,
|
|
18143
|
+
underlying,
|
|
18144
|
+
asset: assetMeta,
|
|
18145
|
+
totalDeposits,
|
|
18146
|
+
totalDebtStable: "0",
|
|
18147
|
+
totalDebt,
|
|
18148
|
+
totalLiquidity: liquidity,
|
|
18149
|
+
totalDepositsUSD: totalDepositsNum * price,
|
|
18150
|
+
totalDebtStableUSD: 0,
|
|
18151
|
+
totalDebtUSD: totalDebtNum * price,
|
|
18152
|
+
totalLiquidityUSD: liquidity * price,
|
|
18153
|
+
depositRate,
|
|
18154
|
+
variableBorrowRate,
|
|
18155
|
+
stableBorrowRate: 0,
|
|
18156
|
+
intrinsicYield: additionalYields?.intrinsicYields?.[oracleKey] ?? 0,
|
|
18157
|
+
rewards: [],
|
|
18158
|
+
decimals,
|
|
18159
|
+
config,
|
|
18160
|
+
collateralActive: Object.values(reserve.dynamicConfigs).some(
|
|
18161
|
+
(c) => c.collateralFactor > 0
|
|
18162
|
+
),
|
|
18163
|
+
borrowingEnabled: reserve.config.borrowable,
|
|
18164
|
+
hasStable: false,
|
|
18165
|
+
isActive: !reserve.config.paused,
|
|
18166
|
+
isFrozen: reserve.config.frozen,
|
|
18167
|
+
borrowCap: 0,
|
|
18168
|
+
supplyCap: 0,
|
|
18169
|
+
debtCeiling: 0,
|
|
18170
|
+
params: {
|
|
18171
|
+
metadata: {
|
|
18172
|
+
spoke: spokeAddr,
|
|
18173
|
+
hub: reserve.reserve.hub.toLowerCase(),
|
|
18174
|
+
assetId: reserve.reserve.assetId,
|
|
18175
|
+
reserveId: reserve.reserveId,
|
|
18176
|
+
oracle: spokeData.oracle.toLowerCase()
|
|
18177
|
+
}
|
|
18178
|
+
}
|
|
18179
|
+
};
|
|
18180
|
+
}
|
|
18181
|
+
}
|
|
18182
|
+
return { data, chainId, eModes };
|
|
18183
|
+
}
|
|
18184
|
+
|
|
18185
|
+
// src/lending/public-data/aave-v4-type/publicCallParse.ts
|
|
18186
|
+
function hasValidOracle2(oracle) {
|
|
18187
|
+
return !!oracle && oracle !== "0x" && oracle.length > 2;
|
|
18188
|
+
}
|
|
18189
|
+
function getSpokeReserves2(reservesMap, spokeAddr) {
|
|
18190
|
+
return reservesMap[spokeAddr.toLowerCase()] ?? reservesMap[spokeAddr] ?? [];
|
|
18191
|
+
}
|
|
18192
|
+
var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields, tokenList = {}) => {
|
|
18193
|
+
const expectedCalls = getAaveV4ExpectedCallCount(chainId, lender);
|
|
18194
|
+
const converter = (data) => {
|
|
18195
|
+
if (data.length !== expectedCalls) return void 0;
|
|
18196
|
+
const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
|
|
18197
|
+
const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
|
|
18198
|
+
let offset = 0;
|
|
18199
|
+
const spokeDataList = [];
|
|
18200
|
+
const hubAssetKeys = /* @__PURE__ */ new Set();
|
|
18201
|
+
const hubAssetList = [];
|
|
18202
|
+
for (const spokeEntry of spokes) {
|
|
18203
|
+
const spokeAddr = spokeEntry.spoke;
|
|
18204
|
+
const reserves = getSpokeReserves2(reservesMap, spokeAddr);
|
|
18205
|
+
const reserveCount = reserves.length;
|
|
18206
|
+
const parsedReserves = [];
|
|
18207
|
+
for (let i = 0; i < reserveCount; i++) {
|
|
18208
|
+
const entry = reserves[i];
|
|
18209
|
+
const reserveId = typeof entry === "number" ? entry : entry.reserveId;
|
|
18210
|
+
const baseIdx = offset + i * CALLS_PER_RESERVE;
|
|
18211
|
+
const rawReserve = data[baseIdx];
|
|
18212
|
+
const rawConfig = data[baseIdx + 1];
|
|
18213
|
+
const rawSupplied = data[baseIdx + 2];
|
|
18214
|
+
const rawDebt = data[baseIdx + 3];
|
|
18215
|
+
const rawTotalDebt = data[baseIdx + 4];
|
|
18216
|
+
const rawDynConfig = data[baseIdx + 5];
|
|
18217
|
+
const reserve = {
|
|
18218
|
+
underlying: rawReserve?.underlying ?? "",
|
|
18219
|
+
hub: rawReserve?.hub ?? "",
|
|
18220
|
+
assetId: Number(rawReserve?.assetId ?? 0),
|
|
18221
|
+
decimals: Number(rawReserve?.decimals ?? 18),
|
|
18222
|
+
collateralRisk: Number(
|
|
18223
|
+
rawReserve?.collateralRisk ?? 0
|
|
18224
|
+
),
|
|
18225
|
+
flags: Number(rawReserve?.flags ?? 0),
|
|
18226
|
+
dynamicConfigKey: Number(
|
|
18227
|
+
rawReserve?.dynamicConfigKey ?? 0
|
|
18228
|
+
)
|
|
18229
|
+
};
|
|
18230
|
+
const config = {
|
|
18231
|
+
collateralRisk: Number(rawConfig?.collateralRisk ?? 0),
|
|
18232
|
+
paused: rawConfig?.paused ?? false,
|
|
18233
|
+
frozen: rawConfig?.frozen ?? false,
|
|
18234
|
+
borrowable: rawConfig?.borrowable ?? false,
|
|
18235
|
+
receiveSharesEnabled: rawConfig?.receiveSharesEnabled ?? false
|
|
18236
|
+
};
|
|
18237
|
+
let drawnDebt = 0n;
|
|
18238
|
+
let premiumDebt = 0n;
|
|
18239
|
+
if (Array.isArray(rawDebt)) {
|
|
18240
|
+
drawnDebt = BigInt(rawDebt[0] ?? 0);
|
|
18241
|
+
premiumDebt = BigInt(rawDebt[1] ?? 0);
|
|
18242
|
+
} else {
|
|
18243
|
+
drawnDebt = BigInt(rawDebt ?? 0);
|
|
18244
|
+
}
|
|
18245
|
+
const dynamicConfigs = {};
|
|
18246
|
+
if (rawDynConfig && rawDynConfig !== "0x") {
|
|
18247
|
+
dynamicConfigs[0] = {
|
|
18248
|
+
collateralFactor: Number(
|
|
18249
|
+
rawDynConfig?.collateralFactor ?? 0
|
|
18250
|
+
),
|
|
18251
|
+
maxLiquidationBonus: Number(
|
|
18252
|
+
rawDynConfig?.maxLiquidationBonus ?? 0
|
|
18253
|
+
),
|
|
18254
|
+
liquidationFee: Number(
|
|
18255
|
+
rawDynConfig?.liquidationFee ?? 0
|
|
18256
|
+
)
|
|
18257
|
+
};
|
|
18258
|
+
}
|
|
18259
|
+
if (spokeEntry.hub && typeof entry === "object" && entry.assetId !== void 0) {
|
|
18260
|
+
const key = `${spokeEntry.hub}:${entry.assetId}`;
|
|
18261
|
+
if (!hubAssetKeys.has(key)) {
|
|
18262
|
+
hubAssetKeys.add(key);
|
|
18263
|
+
hubAssetList.push({
|
|
18264
|
+
hub: spokeEntry.hub,
|
|
18265
|
+
assetId: entry.assetId
|
|
18266
|
+
});
|
|
18267
|
+
}
|
|
18268
|
+
}
|
|
18269
|
+
parsedReserves.push({
|
|
18270
|
+
reserveId,
|
|
18271
|
+
reserve,
|
|
18272
|
+
config,
|
|
18273
|
+
dynamicConfigs,
|
|
18274
|
+
suppliedAssets: BigInt(rawSupplied ?? 0),
|
|
18275
|
+
drawnDebt,
|
|
18276
|
+
premiumDebt,
|
|
18277
|
+
totalDebt: BigInt(rawTotalDebt ?? 0),
|
|
18278
|
+
hubAsset: { drawnRate: 0n },
|
|
18279
|
+
price: 0n
|
|
18280
|
+
});
|
|
18281
|
+
}
|
|
18282
|
+
offset += reserveCount * CALLS_PER_RESERVE;
|
|
18283
|
+
const rawLiqConfig = data[offset];
|
|
18284
|
+
const rawOracle = data[offset + 1];
|
|
18285
|
+
offset += CALLS_PER_SPOKE_TAIL;
|
|
18286
|
+
const liquidationConfig = {
|
|
18287
|
+
targetHealthFactor: BigInt(
|
|
18288
|
+
rawLiqConfig?.targetHealthFactor ?? 0
|
|
18289
|
+
),
|
|
18290
|
+
healthFactorForMaxBonus: BigInt(
|
|
18291
|
+
rawLiqConfig?.healthFactorForMaxBonus ?? 0
|
|
18292
|
+
),
|
|
18293
|
+
liquidationBonusFactor: Number(
|
|
18294
|
+
rawLiqConfig?.liquidationBonusFactor ?? 0
|
|
18295
|
+
)
|
|
18296
|
+
};
|
|
18297
|
+
spokeDataList.push({
|
|
18298
|
+
spoke: spokeAddr,
|
|
18299
|
+
oracle: rawOracle ?? spokeEntry.oracle,
|
|
18300
|
+
label: spokeEntry.label,
|
|
18301
|
+
oracleDecimals: 8,
|
|
18302
|
+
liquidationConfig,
|
|
18303
|
+
reserves: parsedReserves
|
|
18304
|
+
});
|
|
18305
|
+
}
|
|
18306
|
+
for (let si = 0; si < spokes.length; si++) {
|
|
18307
|
+
const reserves = getSpokeReserves2(
|
|
18308
|
+
reservesMap,
|
|
18309
|
+
spokes[si].spoke
|
|
18310
|
+
);
|
|
18311
|
+
const rids = reserves.map(
|
|
18312
|
+
(e) => typeof e === "number" ? e : e.reserveId
|
|
18313
|
+
);
|
|
18314
|
+
if (rids.length > 0 && hasValidOracle2(spokes[si].oracle)) {
|
|
18315
|
+
const rawPrices = data[offset];
|
|
18316
|
+
offset += 1;
|
|
18317
|
+
const priceArray = Array.isArray(rawPrices) ? rawPrices : [];
|
|
18318
|
+
for (let ri = 0; ri < spokeDataList[si].reserves.length; ri++) {
|
|
18319
|
+
if (ri < priceArray.length) {
|
|
18320
|
+
spokeDataList[si].reserves[ri].price = BigInt(
|
|
18321
|
+
priceArray[ri] ?? 0
|
|
18322
|
+
);
|
|
18323
|
+
}
|
|
18324
|
+
}
|
|
18325
|
+
}
|
|
18326
|
+
}
|
|
18327
|
+
const hubAssetMap = /* @__PURE__ */ new Map();
|
|
18328
|
+
for (let hi = 0; hi < hubAssetList.length; hi++) {
|
|
18329
|
+
const baseIdx = offset + hi * 3;
|
|
18330
|
+
const rawHubAsset = data[baseIdx];
|
|
18331
|
+
const rawAddedAssets = data[baseIdx + 1];
|
|
18332
|
+
const rawTotalOwed = data[baseIdx + 2];
|
|
18333
|
+
if (!rawHubAsset || rawHubAsset === "0x") continue;
|
|
18334
|
+
const underlying = (rawHubAsset?.underlying ?? "").toLowerCase();
|
|
18335
|
+
const key = underlying || `${hubAssetList[hi].hub}:${hubAssetList[hi].assetId}`;
|
|
18336
|
+
hubAssetMap.set(key, {
|
|
18337
|
+
liquidity: BigInt(rawHubAsset?.liquidity ?? 0),
|
|
18338
|
+
realizedFees: BigInt(rawHubAsset?.realizedFees ?? 0),
|
|
18339
|
+
decimals: Number(rawHubAsset?.decimals ?? 18),
|
|
18340
|
+
addedShares: BigInt(rawHubAsset?.addedShares ?? 0),
|
|
18341
|
+
swept: BigInt(rawHubAsset?.swept ?? 0),
|
|
18342
|
+
premiumOffsetRay: BigInt(
|
|
18343
|
+
rawHubAsset?.premiumOffsetRay ?? 0
|
|
18344
|
+
),
|
|
18345
|
+
drawnShares: BigInt(rawHubAsset?.drawnShares ?? 0),
|
|
18346
|
+
premiumShares: BigInt(rawHubAsset?.premiumShares ?? 0),
|
|
18347
|
+
liquidityFee: Number(rawHubAsset?.liquidityFee ?? 0),
|
|
18348
|
+
drawnIndex: BigInt(rawHubAsset?.drawnIndex ?? 0),
|
|
18349
|
+
drawnRate: BigInt(rawHubAsset?.drawnRate ?? 0),
|
|
18350
|
+
lastUpdateTimestamp: Number(
|
|
18351
|
+
rawHubAsset?.lastUpdateTimestamp ?? 0
|
|
18352
|
+
),
|
|
18353
|
+
underlying: rawHubAsset?.underlying ?? "",
|
|
18354
|
+
irStrategy: rawHubAsset?.irStrategy ?? "",
|
|
18355
|
+
reinvestmentController: rawHubAsset?.reinvestmentController ?? "",
|
|
18356
|
+
feeReceiver: rawHubAsset?.feeReceiver ?? "",
|
|
18357
|
+
deficitRay: BigInt(rawHubAsset?.deficitRay ?? 0),
|
|
18358
|
+
totalAddedAssets: BigInt(rawAddedAssets ?? 0),
|
|
18359
|
+
totalOwedAssets: BigInt(rawTotalOwed ?? 0)
|
|
18360
|
+
});
|
|
18361
|
+
}
|
|
18362
|
+
for (const spokeData of spokeDataList) {
|
|
18363
|
+
for (const reserve of spokeData.reserves) {
|
|
18364
|
+
const underlying = reserve.reserve.underlying?.toLowerCase?.() ?? "";
|
|
18365
|
+
if (underlying) {
|
|
18366
|
+
const hubAsset = hubAssetMap.get(underlying);
|
|
18367
|
+
if (hubAsset) {
|
|
18368
|
+
reserve.hubAsset = hubAsset;
|
|
18369
|
+
}
|
|
18370
|
+
}
|
|
18371
|
+
}
|
|
18372
|
+
}
|
|
18373
|
+
return normalizeAaveV4(
|
|
18374
|
+
spokeDataList,
|
|
18375
|
+
chainId,
|
|
18376
|
+
lender,
|
|
18377
|
+
prices,
|
|
18378
|
+
additionalYields,
|
|
18379
|
+
tokenList,
|
|
18380
|
+
lenderShortName,
|
|
18381
|
+
createMarketUid,
|
|
18382
|
+
toOracleKey,
|
|
18383
|
+
toGenericPriceKey
|
|
18384
|
+
);
|
|
18385
|
+
};
|
|
18386
|
+
return [converter, expectedCalls];
|
|
18387
|
+
};
|
|
17887
18388
|
function getMorphoTypeMarketConverter(lender, chainId, prices, additionalYields, tokenList = {}, marketsOverride) {
|
|
17888
18389
|
if (lender.startsWith("LISTA_DAO"))
|
|
17889
18390
|
return getListaMarketDataConverter(
|
|
@@ -17917,6 +18418,7 @@ function buildLenderCall(chainId, lender) {
|
|
|
17917
18418
|
if (isCompoundV2Type(lender))
|
|
17918
18419
|
return buildCompoundV2StyleLenderReserveCall(chainId, lender);
|
|
17919
18420
|
if (isEulerType(lender)) return buildEulerV2LenderReserveCall(chainId, lender);
|
|
18421
|
+
if (isAaveV4Type(lender)) return buildAaveV4LenderReserveCall(chainId, lender);
|
|
17920
18422
|
return [];
|
|
17921
18423
|
}
|
|
17922
18424
|
function getLenderDataConverter(lender, chainId, prices, additionalYields, tokenList = {}) {
|
|
@@ -17977,6 +18479,14 @@ function getLenderDataConverter(lender, chainId, prices, additionalYields, token
|
|
|
17977
18479
|
additionalYields,
|
|
17978
18480
|
tokenList
|
|
17979
18481
|
);
|
|
18482
|
+
if (isAaveV4Type(lender))
|
|
18483
|
+
return getAaveV4ReservesDataConverter(
|
|
18484
|
+
lender,
|
|
18485
|
+
chainId,
|
|
18486
|
+
prices,
|
|
18487
|
+
additionalYields,
|
|
18488
|
+
tokenList
|
|
18489
|
+
);
|
|
17980
18490
|
return [() => null, 0];
|
|
17981
18491
|
}
|
|
17982
18492
|
var getAbi = (lender) => {
|
|
@@ -17996,6 +18506,7 @@ var getAbi = (lender) => {
|
|
|
17996
18506
|
if (isInit(lender)) return InitLensAbi;
|
|
17997
18507
|
if (isMorphoType(lender)) return MorphoLensAbi;
|
|
17998
18508
|
if (isEulerType(lender)) return vaultLensAbi;
|
|
18509
|
+
if (isAaveV4Type(lender)) return [...AaveV4SpokeAbi, ...AaveV4OracleAbi, ...AaveV4HubAbi];
|
|
17999
18510
|
if (isSumerType(lender)) return [...SumerLensAbi, ...SumerComptrollerAbi];
|
|
18000
18511
|
if (lender === Lender.TAKARA) return [...TakaraMarketStateAbi];
|
|
18001
18512
|
if (isCompoundV2Type(lender)) return VenusLensAbi;
|
|
@@ -18527,8 +19038,43 @@ var buildEulerUserCall = async (chainId, lender, account, subAccountIndexes) =>
|
|
|
18527
19038
|
}));
|
|
18528
19039
|
};
|
|
18529
19040
|
|
|
19041
|
+
// src/lending/user-data/aave-v4-type/userCallBuild.ts
|
|
19042
|
+
var USER_CALLS_PER_RESERVE = 3;
|
|
19043
|
+
var buildAaveV4UserCall = (chainId, lender, account) => {
|
|
19044
|
+
const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
|
|
19045
|
+
const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
|
|
19046
|
+
if (spokes.length === 0) return [];
|
|
19047
|
+
const calls = [];
|
|
19048
|
+
for (const spokeEntry of spokes) {
|
|
19049
|
+
const spokeAddr = spokeEntry.spoke;
|
|
19050
|
+
const reserveIds = reservesMap[spokeAddr.toLowerCase()] ?? reservesMap[spokeAddr] ?? [];
|
|
19051
|
+
for (const entry of reserveIds) {
|
|
19052
|
+
const rid = typeof entry === "number" ? entry : entry.reserveId;
|
|
19053
|
+
calls.push(
|
|
19054
|
+
{
|
|
19055
|
+
address: spokeAddr,
|
|
19056
|
+
name: "getUserSuppliedAssets",
|
|
19057
|
+
params: [rid, account]
|
|
19058
|
+
},
|
|
19059
|
+
{
|
|
19060
|
+
address: spokeAddr,
|
|
19061
|
+
name: "getUserDebt",
|
|
19062
|
+
params: [rid, account]
|
|
19063
|
+
},
|
|
19064
|
+
{
|
|
19065
|
+
address: spokeAddr,
|
|
19066
|
+
name: "getUserReserveStatus",
|
|
19067
|
+
params: [rid, account]
|
|
19068
|
+
}
|
|
19069
|
+
);
|
|
19070
|
+
}
|
|
19071
|
+
}
|
|
19072
|
+
return calls;
|
|
19073
|
+
};
|
|
19074
|
+
|
|
18530
19075
|
// src/lending/user-data/fetch-balances/prepare.ts
|
|
18531
19076
|
async function buildUserCall(chainId, lender, account, params) {
|
|
19077
|
+
if (isAaveV4Type(lender)) return buildAaveV4UserCall(chainId, lender, account);
|
|
18532
19078
|
if (isAaveV2Type(lender)) return buildAaveV2UserCall(chainId, lender, account);
|
|
18533
19079
|
if (isAaveV3Type(lender)) return buildAaveV3UserCall(chainId, lender, account);
|
|
18534
19080
|
if (isInit(lender)) return buildInitUserCall(chainId, lender, account);
|
|
@@ -19687,8 +20233,114 @@ var getEulerUserDataConverter = (lender, chainId, account, metaMap, subAccountIn
|
|
|
19687
20233
|
];
|
|
19688
20234
|
};
|
|
19689
20235
|
|
|
20236
|
+
// src/lending/user-data/aave-v4-type/userCallParse.ts
|
|
20237
|
+
var getAaveV4UserDataConverter = (lender, chainId, account, metaMap) => {
|
|
20238
|
+
const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
|
|
20239
|
+
const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
|
|
20240
|
+
const reserveEntries = [];
|
|
20241
|
+
for (const spokeEntry of spokes) {
|
|
20242
|
+
const spokeAddr = spokeEntry.spoke;
|
|
20243
|
+
const reserveIds = reservesMap[spokeAddr.toLowerCase()] ?? reservesMap[spokeAddr] ?? [];
|
|
20244
|
+
for (const entry of reserveIds) {
|
|
20245
|
+
const rid = typeof entry === "number" ? entry : entry.reserveId;
|
|
20246
|
+
reserveEntries.push({ spokeAddr, reserveId: rid });
|
|
20247
|
+
}
|
|
20248
|
+
}
|
|
20249
|
+
const expectedNumberOfCalls = reserveEntries.length * USER_CALLS_PER_RESERVE;
|
|
20250
|
+
return [
|
|
20251
|
+
(data) => {
|
|
20252
|
+
if (data.length !== expectedNumberOfCalls) {
|
|
20253
|
+
return void 0;
|
|
20254
|
+
}
|
|
20255
|
+
const lendingPositions = {};
|
|
20256
|
+
let totalDebt24h = 0;
|
|
20257
|
+
let totalDeposits24h = 0;
|
|
20258
|
+
for (let i = 0; i < reserveEntries.length; i++) {
|
|
20259
|
+
const { spokeAddr, reserveId } = reserveEntries[i];
|
|
20260
|
+
const refAddress = `${spokeAddr.toLowerCase()}:${reserveId}`;
|
|
20261
|
+
const key = createMarketUid(chainId, lender, refAddress);
|
|
20262
|
+
const metaEntity = metaMap?.[key];
|
|
20263
|
+
if (!metaEntity) continue;
|
|
20264
|
+
const base = i * USER_CALLS_PER_RESERVE;
|
|
20265
|
+
const { dataForAsset, addedDebt, addedDeposits } = createAaveV4Entry(
|
|
20266
|
+
base,
|
|
20267
|
+
data,
|
|
20268
|
+
key,
|
|
20269
|
+
metaEntity
|
|
20270
|
+
);
|
|
20271
|
+
if (!dataForAsset) continue;
|
|
20272
|
+
totalDebt24h += addedDebt;
|
|
20273
|
+
totalDeposits24h += addedDeposits;
|
|
20274
|
+
lendingPositions[key] = dataForAsset;
|
|
20275
|
+
}
|
|
20276
|
+
const payload = {
|
|
20277
|
+
chainId,
|
|
20278
|
+
account,
|
|
20279
|
+
lendingPositions,
|
|
20280
|
+
rewards: [],
|
|
20281
|
+
userEMode: 0
|
|
20282
|
+
};
|
|
20283
|
+
const userData = createBaseTypeUserState(
|
|
20284
|
+
payload,
|
|
20285
|
+
metaMap,
|
|
20286
|
+
totalDeposits24h,
|
|
20287
|
+
totalDebt24h
|
|
20288
|
+
);
|
|
20289
|
+
return userData;
|
|
20290
|
+
},
|
|
20291
|
+
expectedNumberOfCalls
|
|
20292
|
+
];
|
|
20293
|
+
};
|
|
20294
|
+
function createAaveV4Entry(base, data, key, meta) {
|
|
20295
|
+
const rawSupply = data[base];
|
|
20296
|
+
const debtResult = data[base + 1];
|
|
20297
|
+
const statusResult = data[base + 2];
|
|
20298
|
+
const suppliedRaw = rawSupply === "0x" || rawSupply === void 0 ? "0" : rawSupply.toString();
|
|
20299
|
+
const drawnDebtRaw = Array.isArray(debtResult) ? debtResult[0]?.toString() ?? "0" : "0";
|
|
20300
|
+
const premiumDebtRaw = Array.isArray(debtResult) ? debtResult[1]?.toString() ?? "0" : "0";
|
|
20301
|
+
const totalDebtRaw = (BigInt(drawnDebtRaw || "0") + BigInt(premiumDebtRaw || "0")).toString();
|
|
20302
|
+
if ((suppliedRaw === "0" || !suppliedRaw) && totalDebtRaw === "0") {
|
|
20303
|
+
return {
|
|
20304
|
+
dataForAsset: void 0,
|
|
20305
|
+
addedDeposits: 0,
|
|
20306
|
+
addedDebt: 0
|
|
20307
|
+
};
|
|
20308
|
+
}
|
|
20309
|
+
const assetMeta = meta.asset;
|
|
20310
|
+
const decimals = assetMeta?.decimals ?? 18;
|
|
20311
|
+
const currentDeposits = parseRawAmount(suppliedRaw, decimals);
|
|
20312
|
+
const currentDebt = parseRawAmount(totalDebtRaw, decimals);
|
|
20313
|
+
const collateralEnabled = Boolean(statusResult?.[0]);
|
|
20314
|
+
const price = getDisplayPrice(meta);
|
|
20315
|
+
const oPrice = getOraclePrice(meta);
|
|
20316
|
+
const priceHist = meta?.price?.priceUsd24h ?? price;
|
|
20317
|
+
const dataForAsset = {
|
|
20318
|
+
marketUid: key,
|
|
20319
|
+
underlying: assetMeta.address,
|
|
20320
|
+
deposits: currentDeposits,
|
|
20321
|
+
debtStable: "0",
|
|
20322
|
+
debt: currentDebt,
|
|
20323
|
+
depositsUSD: Number(currentDeposits) * price,
|
|
20324
|
+
debtStableUSD: 0,
|
|
20325
|
+
debtUSD: Number(currentDebt) * price,
|
|
20326
|
+
depositsUSDOracle: Number(currentDeposits) * oPrice,
|
|
20327
|
+
debtStableUSDOracle: 0,
|
|
20328
|
+
debtUSDOracle: Number(currentDebt) * oPrice,
|
|
20329
|
+
stableBorrowRate: 0,
|
|
20330
|
+
collateralEnabled,
|
|
20331
|
+
claimableRewards: 0
|
|
20332
|
+
};
|
|
20333
|
+
return {
|
|
20334
|
+
dataForAsset,
|
|
20335
|
+
addedDeposits: Number(currentDeposits) * priceHist,
|
|
20336
|
+
addedDebt: Number(currentDebt) * priceHist
|
|
20337
|
+
};
|
|
20338
|
+
}
|
|
20339
|
+
|
|
19690
20340
|
// src/lending/user-data/fetch-balances/parse.ts
|
|
19691
20341
|
function getUserDataConverter(lender, chainId, account, params, meta) {
|
|
20342
|
+
if (isAaveV4Type(lender))
|
|
20343
|
+
return getAaveV4UserDataConverter(lender, chainId, account, meta?.[lender]);
|
|
19692
20344
|
if (isYLDR(lender))
|
|
19693
20345
|
return getYldrUserDataConverter(lender, chainId, account, meta?.[lender]);
|
|
19694
20346
|
if (isAaveV2Type(lender))
|
|
@@ -24367,6 +25019,7 @@ var accountLensAbi = [
|
|
|
24367
25019
|
|
|
24368
25020
|
// src/lending/user-data/abis.ts
|
|
24369
25021
|
var getAbi2 = (lender) => {
|
|
25022
|
+
if (isAaveV4Type(lender)) return [...AaveV4SpokeAbi];
|
|
24370
25023
|
if (isAaveV2Type(lender))
|
|
24371
25024
|
return [
|
|
24372
25025
|
...AavePoolAndDataProviderAbi,
|
|
@@ -24807,12 +25460,27 @@ function resolveDebitDataKey(chainId, lender, tokenAddress, cToken) {
|
|
|
24807
25460
|
if (resolved) return resolved.toLowerCase();
|
|
24808
25461
|
}
|
|
24809
25462
|
}
|
|
25463
|
+
if (isCompoundV3Type(lender)) {
|
|
25464
|
+
const comet = getCompoundV3CometAddress$1(chainId, lender);
|
|
25465
|
+
if (comet) return comet;
|
|
25466
|
+
}
|
|
25467
|
+
if (isMorphoType(lender)) {
|
|
25468
|
+
const comet = getMorphoAddress(
|
|
25469
|
+
chainId,
|
|
25470
|
+
isLista(lender) ? Lender.LISTA_DAO : Lender.MORPHO_BLUE
|
|
25471
|
+
);
|
|
25472
|
+
if (comet) return comet;
|
|
25473
|
+
}
|
|
25474
|
+
if (isAaveType(lender)) {
|
|
25475
|
+
const aToken = getAaveCollateralTokenAddress(chainId, lender, tokenAddress);
|
|
25476
|
+
if (aToken) return aToken;
|
|
25477
|
+
}
|
|
24810
25478
|
return tokenAddress.toLowerCase();
|
|
24811
25479
|
}
|
|
24812
25480
|
function needsLenderApproval(params) {
|
|
24813
25481
|
const { lender, lenderDebitData, tokenAddress, amount, chainId, cToken } = params;
|
|
24814
25482
|
if (!lenderDebitData) return true;
|
|
24815
|
-
if (isInit(lender) || isMorphoType(lender)) {
|
|
25483
|
+
if (isInit(lender) || isMorphoType(lender) || isCompoundV3(lender)) {
|
|
24816
25484
|
const entry2 = Object.values(lenderDebitData)[0];
|
|
24817
25485
|
if (!entry2 || entry2.amount === void 0) return true;
|
|
24818
25486
|
return entry2.amount === 0n;
|
|
@@ -31207,6 +31875,96 @@ var eulerV2Fetcher = {
|
|
|
31207
31875
|
parse: parseEulerV2Results,
|
|
31208
31876
|
getAbi: getEulerV2Abi
|
|
31209
31877
|
};
|
|
31878
|
+
function getAaveV4OracleGroups(chainId) {
|
|
31879
|
+
const oracles = aaveV4Oracles() ?? {};
|
|
31880
|
+
const groups = [];
|
|
31881
|
+
for (const [fork, chains] of Object.entries(oracles)) {
|
|
31882
|
+
const oracleEntries = chains[chainId] ?? [];
|
|
31883
|
+
if (oracleEntries.length === 0) continue;
|
|
31884
|
+
const byOracle = /* @__PURE__ */ new Map();
|
|
31885
|
+
for (const entry of oracleEntries) {
|
|
31886
|
+
if (!entry.oracle || entry.oracle === "0x") continue;
|
|
31887
|
+
const key = entry.oracle.toLowerCase();
|
|
31888
|
+
let group = byOracle.get(key);
|
|
31889
|
+
if (!group) {
|
|
31890
|
+
group = { decimals: entry.decimals ?? 8, entries: [] };
|
|
31891
|
+
byOracle.set(key, group);
|
|
31892
|
+
}
|
|
31893
|
+
group.entries.push({
|
|
31894
|
+
underlying: entry.underlying.toLowerCase(),
|
|
31895
|
+
spoke: entry.spoke.toLowerCase(),
|
|
31896
|
+
reserveId: entry.reserveId
|
|
31897
|
+
});
|
|
31898
|
+
}
|
|
31899
|
+
for (const [oracle, group] of byOracle) {
|
|
31900
|
+
groups.push({
|
|
31901
|
+
fork,
|
|
31902
|
+
oracle,
|
|
31903
|
+
decimals: group.decimals,
|
|
31904
|
+
entries: group.entries
|
|
31905
|
+
});
|
|
31906
|
+
}
|
|
31907
|
+
}
|
|
31908
|
+
return groups;
|
|
31909
|
+
}
|
|
31910
|
+
function getAaveV4Calls(chainId) {
|
|
31911
|
+
const groups = getAaveV4OracleGroups(chainId);
|
|
31912
|
+
const results = [];
|
|
31913
|
+
for (const { fork, oracle, decimals, entries } of groups) {
|
|
31914
|
+
const calls = entries.map((e) => ({
|
|
31915
|
+
address: oracle,
|
|
31916
|
+
name: "getReservePrice",
|
|
31917
|
+
params: [e.reserveId]
|
|
31918
|
+
}));
|
|
31919
|
+
results.push({
|
|
31920
|
+
calls,
|
|
31921
|
+
meta: {
|
|
31922
|
+
oracle,
|
|
31923
|
+
oracleDecimals: decimals,
|
|
31924
|
+
entries,
|
|
31925
|
+
fork
|
|
31926
|
+
},
|
|
31927
|
+
lender: fork
|
|
31928
|
+
});
|
|
31929
|
+
}
|
|
31930
|
+
return results;
|
|
31931
|
+
}
|
|
31932
|
+
function parseAaveV4Results(data, meta, context) {
|
|
31933
|
+
const { chainId } = context;
|
|
31934
|
+
const entries = [];
|
|
31935
|
+
if (data.length === 0) return entries;
|
|
31936
|
+
const divisor = 10 ** meta.oracleDecimals;
|
|
31937
|
+
for (let i = 0; i < meta.entries.length; i++) {
|
|
31938
|
+
const rawPrice = data[i];
|
|
31939
|
+
if (rawPrice === void 0 || rawPrice === "0x") continue;
|
|
31940
|
+
const entry = meta.entries[i];
|
|
31941
|
+
try {
|
|
31942
|
+
const priceNum = Number(BigInt(rawPrice.toString())) / divisor;
|
|
31943
|
+
if (isNaN(priceNum) || priceNum === 0) continue;
|
|
31944
|
+
entries.push({
|
|
31945
|
+
asset: entry.underlying,
|
|
31946
|
+
price: priceNum,
|
|
31947
|
+
priceUSD: priceNum,
|
|
31948
|
+
marketUid: createMarketUid(
|
|
31949
|
+
chainId,
|
|
31950
|
+
meta.fork,
|
|
31951
|
+
`${entry.spoke}:${entry.reserveId}`
|
|
31952
|
+
)
|
|
31953
|
+
});
|
|
31954
|
+
} catch {
|
|
31955
|
+
continue;
|
|
31956
|
+
}
|
|
31957
|
+
}
|
|
31958
|
+
return entries;
|
|
31959
|
+
}
|
|
31960
|
+
function getAaveV4Abi() {
|
|
31961
|
+
return AaveV4OracleAbi;
|
|
31962
|
+
}
|
|
31963
|
+
var aaveV4Fetcher = {
|
|
31964
|
+
getCalls: getAaveV4Calls,
|
|
31965
|
+
parse: parseAaveV4Results,
|
|
31966
|
+
getAbi: getAaveV4Abi
|
|
31967
|
+
};
|
|
31210
31968
|
|
|
31211
31969
|
// src/prices/oracle-prices/fetchOraclePrices.ts
|
|
31212
31970
|
function countFailures(data, offset, count) {
|
|
@@ -31346,6 +32104,11 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31346
32104
|
() => eulerV2Fetcher.getCalls(chainId),
|
|
31347
32105
|
getCallsErrors
|
|
31348
32106
|
) : [];
|
|
32107
|
+
const aaveV4Results = isActive("aavev4") ? safeGetCalls(
|
|
32108
|
+
"aaveV4",
|
|
32109
|
+
() => aaveV4Fetcher.getCalls(chainId),
|
|
32110
|
+
getCallsErrors
|
|
32111
|
+
) : [];
|
|
31349
32112
|
const morphoResults = isActive("morpho") ? safeGetCalls(
|
|
31350
32113
|
"morpho",
|
|
31351
32114
|
() => morphoFetcher.getCalls(chainId, {
|
|
@@ -31383,6 +32146,12 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31383
32146
|
eulerV2Fetcher.parse,
|
|
31384
32147
|
getEulerV2Abi()
|
|
31385
32148
|
);
|
|
32149
|
+
const aaveV4Group = buildGroup(
|
|
32150
|
+
"aaveV4",
|
|
32151
|
+
aaveV4Results,
|
|
32152
|
+
aaveV4Fetcher.parse,
|
|
32153
|
+
getAaveV4Abi()
|
|
32154
|
+
);
|
|
31386
32155
|
const morphoGroup = buildGroup(
|
|
31387
32156
|
"morpho",
|
|
31388
32157
|
morphoResults,
|
|
@@ -31395,6 +32164,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31395
32164
|
compoundV3Group,
|
|
31396
32165
|
listaGroup,
|
|
31397
32166
|
eulerGroup,
|
|
32167
|
+
aaveV4Group,
|
|
31398
32168
|
morphoGroup
|
|
31399
32169
|
];
|
|
31400
32170
|
const totalCalls = allGroups.reduce((s, g) => s + g.calls.length, 0);
|
|
@@ -31420,6 +32190,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31420
32190
|
compoundV3Data,
|
|
31421
32191
|
listaData,
|
|
31422
32192
|
eulerData,
|
|
32193
|
+
aaveV4Data,
|
|
31423
32194
|
morphoGqlEntries
|
|
31424
32195
|
] = await Promise.all([
|
|
31425
32196
|
executeGroup(
|
|
@@ -31462,6 +32233,14 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31462
32233
|
allowFailure,
|
|
31463
32234
|
rpcOverrides
|
|
31464
32235
|
),
|
|
32236
|
+
executeGroup(
|
|
32237
|
+
aaveV4Group,
|
|
32238
|
+
chainId,
|
|
32239
|
+
chainBatchSize,
|
|
32240
|
+
retries,
|
|
32241
|
+
allowFailure,
|
|
32242
|
+
rpcOverrides
|
|
32243
|
+
),
|
|
31465
32244
|
morphoGqlPromise
|
|
31466
32245
|
]);
|
|
31467
32246
|
if (morphoGqlEntries == null && isActive("morpho")) {
|
|
@@ -31482,6 +32261,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31482
32261
|
{ group: compoundV3Group, data: compoundV3Data },
|
|
31483
32262
|
{ group: listaGroup, data: listaData },
|
|
31484
32263
|
{ group: eulerGroup, data: eulerData },
|
|
32264
|
+
{ group: aaveV4Group, data: aaveV4Data },
|
|
31485
32265
|
...useMorphoGql ? [] : [{ group: morphoGroup, data: morphoData }]
|
|
31486
32266
|
];
|
|
31487
32267
|
for (const { group, data } of groupResults) {
|
|
@@ -31536,6 +32316,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31536
32316
|
parseTrackers(compoundV3Group, compoundV3Data.results);
|
|
31537
32317
|
parseTrackers(listaGroup, listaData.results);
|
|
31538
32318
|
parseTrackers(eulerGroup, eulerData.results);
|
|
32319
|
+
parseTrackers(aaveV4Group, aaveV4Data.results);
|
|
31539
32320
|
if (stalenessThresholdSeconds > 0) {
|
|
31540
32321
|
const nowSeconds = Math.floor(Date.now() / 1e3);
|
|
31541
32322
|
for (const tracker of compoundV3Group.trackers) {
|