@1delta/margin-fetcher 0.0.213 → 0.0.215
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.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +805 -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/utils/types.d.ts +9 -0
- package/dist/lending/user-data/utils/types.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 +32 -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,502 @@ 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 isValidAddress(addr) {
|
|
17899
|
+
return !!addr && addr !== "0x" && addr.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
|
+
if (!isValidAddress(spokeEntry.spoke)) continue;
|
|
17913
|
+
const spokeAddr = spokeEntry.spoke;
|
|
17914
|
+
const reserves = getSpokeReserves(reservesMap, spokeAddr);
|
|
17915
|
+
for (const entry of reserves) {
|
|
17916
|
+
const rid = typeof entry === "number" ? entry : entry.reserveId;
|
|
17917
|
+
calls.push(
|
|
17918
|
+
{
|
|
17919
|
+
address: spokeAddr,
|
|
17920
|
+
name: "getReserve",
|
|
17921
|
+
params: [rid]
|
|
17922
|
+
},
|
|
17923
|
+
{
|
|
17924
|
+
address: spokeAddr,
|
|
17925
|
+
name: "getReserveConfig",
|
|
17926
|
+
params: [rid]
|
|
17927
|
+
},
|
|
17928
|
+
{
|
|
17929
|
+
address: spokeAddr,
|
|
17930
|
+
name: "getReserveSuppliedAssets",
|
|
17931
|
+
params: [rid]
|
|
17932
|
+
},
|
|
17933
|
+
{
|
|
17934
|
+
address: spokeAddr,
|
|
17935
|
+
name: "getReserveDebt",
|
|
17936
|
+
params: [rid]
|
|
17937
|
+
},
|
|
17938
|
+
{
|
|
17939
|
+
address: spokeAddr,
|
|
17940
|
+
name: "getReserveTotalDebt",
|
|
17941
|
+
params: [rid]
|
|
17942
|
+
},
|
|
17943
|
+
{
|
|
17944
|
+
address: spokeAddr,
|
|
17945
|
+
name: "getDynamicReserveConfig",
|
|
17946
|
+
params: [rid, 0]
|
|
17947
|
+
}
|
|
17948
|
+
);
|
|
17949
|
+
if (typeof entry === "object" && spokeEntry.hub && entry.assetId !== void 0) {
|
|
17950
|
+
const hubLc = spokeEntry.hub.toLowerCase();
|
|
17951
|
+
const key = `${hubLc}:${entry.assetId}`;
|
|
17952
|
+
if (!hubAssetKeys.has(key)) {
|
|
17953
|
+
hubAssetKeys.add(key);
|
|
17954
|
+
hubAssetList.push({
|
|
17955
|
+
hub: hubLc,
|
|
17956
|
+
assetId: entry.assetId
|
|
17957
|
+
});
|
|
17958
|
+
}
|
|
17959
|
+
}
|
|
17960
|
+
}
|
|
17961
|
+
calls.push(
|
|
17962
|
+
{
|
|
17963
|
+
address: spokeAddr,
|
|
17964
|
+
name: "getLiquidationConfig",
|
|
17965
|
+
params: []
|
|
17966
|
+
},
|
|
17967
|
+
{
|
|
17968
|
+
address: spokeAddr,
|
|
17969
|
+
name: "ORACLE",
|
|
17970
|
+
params: []
|
|
17971
|
+
}
|
|
17972
|
+
);
|
|
17973
|
+
}
|
|
17974
|
+
for (const spokeEntry of spokes) {
|
|
17975
|
+
if (!isValidAddress(spokeEntry.spoke)) continue;
|
|
17976
|
+
const reserves = getSpokeReserves(
|
|
17977
|
+
reservesMap,
|
|
17978
|
+
spokeEntry.spoke
|
|
17979
|
+
);
|
|
17980
|
+
const rids = reserves.map(
|
|
17981
|
+
(e) => typeof e === "number" ? e : e.reserveId
|
|
17982
|
+
);
|
|
17983
|
+
if (rids.length > 0 && isValidAddress(spokeEntry.oracle)) {
|
|
17984
|
+
calls.push({
|
|
17985
|
+
address: spokeEntry.oracle,
|
|
17986
|
+
name: "getReservesPrices",
|
|
17987
|
+
params: [rids]
|
|
17988
|
+
});
|
|
17989
|
+
}
|
|
17990
|
+
}
|
|
17991
|
+
for (const { hub, assetId } of hubAssetList) {
|
|
17992
|
+
calls.push(
|
|
17993
|
+
{
|
|
17994
|
+
address: hub,
|
|
17995
|
+
name: "getAsset",
|
|
17996
|
+
params: [assetId]
|
|
17997
|
+
},
|
|
17998
|
+
{
|
|
17999
|
+
address: hub,
|
|
18000
|
+
name: "getAddedAssets",
|
|
18001
|
+
params: [assetId]
|
|
18002
|
+
},
|
|
18003
|
+
{
|
|
18004
|
+
address: hub,
|
|
18005
|
+
name: "getAssetTotalOwed",
|
|
18006
|
+
params: [assetId]
|
|
18007
|
+
}
|
|
18008
|
+
);
|
|
18009
|
+
}
|
|
18010
|
+
return calls;
|
|
18011
|
+
};
|
|
18012
|
+
var getAaveV4ExpectedCallCount = (chainId, lender) => {
|
|
18013
|
+
const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
|
|
18014
|
+
const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
|
|
18015
|
+
let count = 0;
|
|
18016
|
+
const hubAssetKeys = /* @__PURE__ */ new Set();
|
|
18017
|
+
for (const spokeEntry of spokes) {
|
|
18018
|
+
if (!isValidAddress(spokeEntry.spoke)) continue;
|
|
18019
|
+
const reserves = getSpokeReserves(
|
|
18020
|
+
reservesMap,
|
|
18021
|
+
spokeEntry.spoke
|
|
18022
|
+
);
|
|
18023
|
+
count += reserves.length * CALLS_PER_RESERVE + CALLS_PER_SPOKE_TAIL;
|
|
18024
|
+
const rids = reserves.map(
|
|
18025
|
+
(e) => typeof e === "number" ? e : e.reserveId
|
|
18026
|
+
);
|
|
18027
|
+
if (rids.length > 0 && isValidAddress(spokeEntry.oracle)) {
|
|
18028
|
+
count += 1;
|
|
18029
|
+
}
|
|
18030
|
+
for (const entry of reserves) {
|
|
18031
|
+
if (typeof entry === "object" && spokeEntry.hub && entry.assetId !== void 0) {
|
|
18032
|
+
hubAssetKeys.add(`${spokeEntry.hub.toLowerCase()}:${entry.assetId}`);
|
|
18033
|
+
}
|
|
18034
|
+
}
|
|
18035
|
+
}
|
|
18036
|
+
count += hubAssetKeys.size * 3;
|
|
18037
|
+
return count;
|
|
18038
|
+
};
|
|
18039
|
+
|
|
18040
|
+
// src/lending/public-data/aave-v4-type/fetcher/normalize.ts
|
|
18041
|
+
function toTokenAmount2(raw, decimals) {
|
|
18042
|
+
if (raw === 0n) return "0";
|
|
18043
|
+
const divisor = 10 ** decimals;
|
|
18044
|
+
return (Number(raw) / divisor).toString();
|
|
18045
|
+
}
|
|
18046
|
+
function toTokenNumber(raw, decimals) {
|
|
18047
|
+
if (raw === 0n) return 0;
|
|
18048
|
+
return Number(raw) / 10 ** decimals;
|
|
18049
|
+
}
|
|
18050
|
+
var RAY2 = 1e27;
|
|
18051
|
+
function rayRateToApr(rateRay) {
|
|
18052
|
+
if (rateRay === 0n) return 0;
|
|
18053
|
+
return Number(rateRay) / RAY2 * 100;
|
|
18054
|
+
}
|
|
18055
|
+
function normalizeAaveV4(spokeDataList, chainId, lender, prices, additionalYields, tokenList, lenderShortNameFn, createMarketUidFn, toOracleKeyFn, toGenericPriceKeyFn) {
|
|
18056
|
+
const data = {};
|
|
18057
|
+
const eModes = {};
|
|
18058
|
+
for (const spokeData of spokeDataList) {
|
|
18059
|
+
const spokeAddr = spokeData.spoke.toLowerCase();
|
|
18060
|
+
const spokeReserves = spokeData.reserves;
|
|
18061
|
+
for (const reserve of spokeReserves) {
|
|
18062
|
+
for (const [keyStr, dynCfg] of Object.entries(
|
|
18063
|
+
reserve.dynamicConfigs
|
|
18064
|
+
)) {
|
|
18065
|
+
const configKey = `${spokeAddr}:${keyStr}`;
|
|
18066
|
+
if (!eModes[configKey] && dynCfg.collateralFactor > 0) {
|
|
18067
|
+
eModes[configKey] = {
|
|
18068
|
+
category: configKey,
|
|
18069
|
+
label: `${spokeData.label} / Config ${keyStr}`,
|
|
18070
|
+
borrowCollateralFactor: dynCfg.collateralFactor / BPS,
|
|
18071
|
+
collateralFactor: dynCfg.collateralFactor / BPS,
|
|
18072
|
+
priceSource: spokeData.oracle
|
|
18073
|
+
};
|
|
18074
|
+
}
|
|
18075
|
+
}
|
|
18076
|
+
}
|
|
18077
|
+
for (const reserve of spokeReserves) {
|
|
18078
|
+
const underlying = reserve.reserve.underlying.toLowerCase();
|
|
18079
|
+
const decimals = reserve.reserve.decimals;
|
|
18080
|
+
const hubAddr = reserve.reserve.hub.toLowerCase();
|
|
18081
|
+
const refAddress = `${hubAddr}:${underlying}`;
|
|
18082
|
+
const marketUid = createMarketUidFn(chainId, lender, refAddress);
|
|
18083
|
+
const assetMeta = tokenList[underlying];
|
|
18084
|
+
const oracleKey = toOracleKeyFn(assetMeta?.assetGroup ?? null) ?? toGenericPriceKeyFn(underlying, chainId);
|
|
18085
|
+
let price = 0;
|
|
18086
|
+
if (reserve.price > 0n) {
|
|
18087
|
+
price = Number(reserve.price) / 10 ** spokeData.oracleDecimals;
|
|
18088
|
+
} else {
|
|
18089
|
+
price = prices[oracleKey] ?? 0;
|
|
18090
|
+
}
|
|
18091
|
+
const totalDeposits = toTokenAmount2(
|
|
18092
|
+
reserve.suppliedAssets,
|
|
18093
|
+
decimals
|
|
18094
|
+
);
|
|
18095
|
+
const totalDebt = toTokenAmount2(reserve.totalDebt, decimals);
|
|
18096
|
+
const totalDepositsNum = toTokenNumber(
|
|
18097
|
+
reserve.suppliedAssets,
|
|
18098
|
+
decimals
|
|
18099
|
+
);
|
|
18100
|
+
const totalDebtNum = toTokenNumber(reserve.totalDebt, decimals);
|
|
18101
|
+
const liquidity = totalDepositsNum - totalDebtNum;
|
|
18102
|
+
const variableBorrowRate = rayRateToApr(
|
|
18103
|
+
reserve.hubAsset.drawnRate
|
|
18104
|
+
);
|
|
18105
|
+
const hubDecimals = reserve.hubAsset.decimals || decimals;
|
|
18106
|
+
const hubTotalSupply = toTokenNumber(
|
|
18107
|
+
reserve.hubAsset.totalAddedAssets ?? 0n,
|
|
18108
|
+
hubDecimals
|
|
18109
|
+
);
|
|
18110
|
+
const hubTotalOwed = toTokenNumber(
|
|
18111
|
+
reserve.hubAsset.totalOwedAssets ?? 0n,
|
|
18112
|
+
hubDecimals
|
|
18113
|
+
);
|
|
18114
|
+
const hubUtilization = hubTotalSupply > 0 ? hubTotalOwed / hubTotalSupply : 0;
|
|
18115
|
+
const feeRate = reserve.hubAsset.liquidityFee ? reserve.hubAsset.liquidityFee / BPS : 0;
|
|
18116
|
+
const depositRate = variableBorrowRate * hubUtilization * (1 - feeRate);
|
|
18117
|
+
const config = {};
|
|
18118
|
+
for (const [keyStr, dynCfg] of Object.entries(
|
|
18119
|
+
reserve.dynamicConfigs
|
|
18120
|
+
)) {
|
|
18121
|
+
const configKey = `${spokeAddr}:${keyStr}`;
|
|
18122
|
+
config[configKey] = {
|
|
18123
|
+
category: configKey,
|
|
18124
|
+
label: `${spokeData.label} / Config ${keyStr}`,
|
|
18125
|
+
borrowCollateralFactor: dynCfg.collateralFactor / BPS,
|
|
18126
|
+
collateralFactor: dynCfg.collateralFactor / BPS,
|
|
18127
|
+
borrowFactor: 1,
|
|
18128
|
+
collateralDisabled: dynCfg.collateralFactor === 0 || reserve.config.paused,
|
|
18129
|
+
debtDisabled: !reserve.config.borrowable || reserve.config.paused
|
|
18130
|
+
};
|
|
18131
|
+
}
|
|
18132
|
+
if (Object.keys(config).length === 0) {
|
|
18133
|
+
const defaultKey = `${spokeAddr}:0`;
|
|
18134
|
+
config[defaultKey] = {
|
|
18135
|
+
category: defaultKey,
|
|
18136
|
+
label: `${spokeData.label} / Default`,
|
|
18137
|
+
borrowCollateralFactor: 0,
|
|
18138
|
+
collateralFactor: 0,
|
|
18139
|
+
borrowFactor: 1,
|
|
18140
|
+
collateralDisabled: true,
|
|
18141
|
+
debtDisabled: !reserve.config.borrowable || reserve.config.paused
|
|
18142
|
+
};
|
|
18143
|
+
}
|
|
18144
|
+
data[marketUid] = {
|
|
18145
|
+
marketUid,
|
|
18146
|
+
name: lenderShortNameFn(lender) + " " + (assetMeta?.symbol ?? ""),
|
|
18147
|
+
poolId: underlying,
|
|
18148
|
+
underlying,
|
|
18149
|
+
asset: assetMeta,
|
|
18150
|
+
totalDeposits,
|
|
18151
|
+
totalDebtStable: "0",
|
|
18152
|
+
totalDebt,
|
|
18153
|
+
totalLiquidity: liquidity,
|
|
18154
|
+
totalDepositsUSD: totalDepositsNum * price,
|
|
18155
|
+
totalDebtStableUSD: 0,
|
|
18156
|
+
totalDebtUSD: totalDebtNum * price,
|
|
18157
|
+
totalLiquidityUSD: liquidity * price,
|
|
18158
|
+
depositRate,
|
|
18159
|
+
variableBorrowRate,
|
|
18160
|
+
stableBorrowRate: 0,
|
|
18161
|
+
intrinsicYield: additionalYields?.intrinsicYields?.[oracleKey] ?? 0,
|
|
18162
|
+
rewards: [],
|
|
18163
|
+
decimals,
|
|
18164
|
+
config,
|
|
18165
|
+
collateralActive: Object.values(reserve.dynamicConfigs).some(
|
|
18166
|
+
(c) => c.collateralFactor > 0
|
|
18167
|
+
),
|
|
18168
|
+
borrowingEnabled: reserve.config.borrowable,
|
|
18169
|
+
hasStable: false,
|
|
18170
|
+
isActive: !reserve.config.paused,
|
|
18171
|
+
isFrozen: reserve.config.frozen,
|
|
18172
|
+
borrowCap: 0,
|
|
18173
|
+
supplyCap: 0,
|
|
18174
|
+
debtCeiling: 0,
|
|
18175
|
+
params: {
|
|
18176
|
+
metadata: {
|
|
18177
|
+
spoke: spokeAddr,
|
|
18178
|
+
hub: reserve.reserve.hub.toLowerCase(),
|
|
18179
|
+
assetId: reserve.reserve.assetId,
|
|
18180
|
+
reserveId: reserve.reserveId,
|
|
18181
|
+
oracle: spokeData.oracle.toLowerCase()
|
|
18182
|
+
}
|
|
18183
|
+
}
|
|
18184
|
+
};
|
|
18185
|
+
}
|
|
18186
|
+
}
|
|
18187
|
+
return { data, chainId, eModes };
|
|
18188
|
+
}
|
|
18189
|
+
|
|
18190
|
+
// src/lending/public-data/aave-v4-type/publicCallParse.ts
|
|
18191
|
+
function isValidAddress2(addr) {
|
|
18192
|
+
return !!addr && addr !== "0x" && addr.length > 2;
|
|
18193
|
+
}
|
|
18194
|
+
function getSpokeReserves2(reservesMap, spokeAddr) {
|
|
18195
|
+
return reservesMap[spokeAddr.toLowerCase()] ?? reservesMap[spokeAddr] ?? [];
|
|
18196
|
+
}
|
|
18197
|
+
var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields, tokenList = {}) => {
|
|
18198
|
+
const expectedCalls = getAaveV4ExpectedCallCount(chainId, lender);
|
|
18199
|
+
const converter = (data) => {
|
|
18200
|
+
if (data.length !== expectedCalls) return void 0;
|
|
18201
|
+
const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
|
|
18202
|
+
const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
|
|
18203
|
+
let offset = 0;
|
|
18204
|
+
const spokeDataList = [];
|
|
18205
|
+
const hubAssetKeys = /* @__PURE__ */ new Set();
|
|
18206
|
+
const hubAssetList = [];
|
|
18207
|
+
for (const spokeEntry of spokes) {
|
|
18208
|
+
if (!isValidAddress2(spokeEntry.spoke)) continue;
|
|
18209
|
+
const spokeAddr = spokeEntry.spoke;
|
|
18210
|
+
const reserves = getSpokeReserves2(reservesMap, spokeAddr);
|
|
18211
|
+
const reserveCount = reserves.length;
|
|
18212
|
+
const parsedReserves = [];
|
|
18213
|
+
for (let i = 0; i < reserveCount; i++) {
|
|
18214
|
+
const entry = reserves[i];
|
|
18215
|
+
const reserveId = typeof entry === "number" ? entry : entry.reserveId;
|
|
18216
|
+
const baseIdx = offset + i * CALLS_PER_RESERVE;
|
|
18217
|
+
const rawReserve = data[baseIdx];
|
|
18218
|
+
const rawConfig = data[baseIdx + 1];
|
|
18219
|
+
const rawSupplied = data[baseIdx + 2];
|
|
18220
|
+
const rawDebt = data[baseIdx + 3];
|
|
18221
|
+
const rawTotalDebt = data[baseIdx + 4];
|
|
18222
|
+
const rawDynConfig = data[baseIdx + 5];
|
|
18223
|
+
const reserve = {
|
|
18224
|
+
underlying: rawReserve?.underlying ?? "",
|
|
18225
|
+
hub: rawReserve?.hub ?? "",
|
|
18226
|
+
assetId: Number(rawReserve?.assetId ?? 0),
|
|
18227
|
+
decimals: Number(rawReserve?.decimals ?? 18),
|
|
18228
|
+
collateralRisk: Number(
|
|
18229
|
+
rawReserve?.collateralRisk ?? 0
|
|
18230
|
+
),
|
|
18231
|
+
flags: Number(rawReserve?.flags ?? 0),
|
|
18232
|
+
dynamicConfigKey: Number(
|
|
18233
|
+
rawReserve?.dynamicConfigKey ?? 0
|
|
18234
|
+
)
|
|
18235
|
+
};
|
|
18236
|
+
const config = {
|
|
18237
|
+
collateralRisk: Number(rawConfig?.collateralRisk ?? 0),
|
|
18238
|
+
paused: rawConfig?.paused ?? false,
|
|
18239
|
+
frozen: rawConfig?.frozen ?? false,
|
|
18240
|
+
borrowable: rawConfig?.borrowable ?? false,
|
|
18241
|
+
receiveSharesEnabled: rawConfig?.receiveSharesEnabled ?? false
|
|
18242
|
+
};
|
|
18243
|
+
let drawnDebt = 0n;
|
|
18244
|
+
let premiumDebt = 0n;
|
|
18245
|
+
if (Array.isArray(rawDebt)) {
|
|
18246
|
+
drawnDebt = BigInt(rawDebt[0] ?? 0);
|
|
18247
|
+
premiumDebt = BigInt(rawDebt[1] ?? 0);
|
|
18248
|
+
} else {
|
|
18249
|
+
drawnDebt = BigInt(rawDebt ?? 0);
|
|
18250
|
+
}
|
|
18251
|
+
const dynamicConfigs = {};
|
|
18252
|
+
if (rawDynConfig && rawDynConfig !== "0x") {
|
|
18253
|
+
dynamicConfigs[0] = {
|
|
18254
|
+
collateralFactor: Number(
|
|
18255
|
+
rawDynConfig?.collateralFactor ?? 0
|
|
18256
|
+
),
|
|
18257
|
+
maxLiquidationBonus: Number(
|
|
18258
|
+
rawDynConfig?.maxLiquidationBonus ?? 0
|
|
18259
|
+
),
|
|
18260
|
+
liquidationFee: Number(
|
|
18261
|
+
rawDynConfig?.liquidationFee ?? 0
|
|
18262
|
+
)
|
|
18263
|
+
};
|
|
18264
|
+
}
|
|
18265
|
+
if (spokeEntry.hub && typeof entry === "object" && entry.assetId !== void 0) {
|
|
18266
|
+
const hubLc = spokeEntry.hub.toLowerCase();
|
|
18267
|
+
const key = `${hubLc}:${entry.assetId}`;
|
|
18268
|
+
if (!hubAssetKeys.has(key)) {
|
|
18269
|
+
hubAssetKeys.add(key);
|
|
18270
|
+
hubAssetList.push({
|
|
18271
|
+
hub: hubLc,
|
|
18272
|
+
assetId: entry.assetId
|
|
18273
|
+
});
|
|
18274
|
+
}
|
|
18275
|
+
}
|
|
18276
|
+
parsedReserves.push({
|
|
18277
|
+
reserveId,
|
|
18278
|
+
reserve,
|
|
18279
|
+
config,
|
|
18280
|
+
dynamicConfigs,
|
|
18281
|
+
suppliedAssets: BigInt(rawSupplied ?? 0),
|
|
18282
|
+
drawnDebt,
|
|
18283
|
+
premiumDebt,
|
|
18284
|
+
totalDebt: BigInt(rawTotalDebt ?? 0),
|
|
18285
|
+
hubAsset: { drawnRate: 0n },
|
|
18286
|
+
price: 0n
|
|
18287
|
+
});
|
|
18288
|
+
}
|
|
18289
|
+
offset += reserveCount * CALLS_PER_RESERVE;
|
|
18290
|
+
const rawLiqConfig = data[offset];
|
|
18291
|
+
const rawOracle = data[offset + 1];
|
|
18292
|
+
offset += CALLS_PER_SPOKE_TAIL;
|
|
18293
|
+
const liquidationConfig = {
|
|
18294
|
+
targetHealthFactor: BigInt(
|
|
18295
|
+
rawLiqConfig?.targetHealthFactor ?? 0
|
|
18296
|
+
),
|
|
18297
|
+
healthFactorForMaxBonus: BigInt(
|
|
18298
|
+
rawLiqConfig?.healthFactorForMaxBonus ?? 0
|
|
18299
|
+
),
|
|
18300
|
+
liquidationBonusFactor: Number(
|
|
18301
|
+
rawLiqConfig?.liquidationBonusFactor ?? 0
|
|
18302
|
+
)
|
|
18303
|
+
};
|
|
18304
|
+
spokeDataList.push({
|
|
18305
|
+
spoke: spokeAddr,
|
|
18306
|
+
oracle: rawOracle ?? spokeEntry.oracle,
|
|
18307
|
+
label: spokeEntry.label,
|
|
18308
|
+
oracleDecimals: 8,
|
|
18309
|
+
liquidationConfig,
|
|
18310
|
+
reserves: parsedReserves
|
|
18311
|
+
});
|
|
18312
|
+
}
|
|
18313
|
+
for (let si = 0; si < spokeDataList.length; si++) {
|
|
18314
|
+
const sd = spokeDataList[si];
|
|
18315
|
+
const reserves = getSpokeReserves2(reservesMap, sd.spoke);
|
|
18316
|
+
const rids = reserves.map(
|
|
18317
|
+
(e) => typeof e === "number" ? e : e.reserveId
|
|
18318
|
+
);
|
|
18319
|
+
if (rids.length > 0 && isValidAddress2(sd.oracle)) {
|
|
18320
|
+
const rawPrices = data[offset];
|
|
18321
|
+
offset += 1;
|
|
18322
|
+
const priceArray = Array.isArray(rawPrices) ? rawPrices : [];
|
|
18323
|
+
for (let ri = 0; ri < sd.reserves.length; ri++) {
|
|
18324
|
+
if (ri < priceArray.length) {
|
|
18325
|
+
sd.reserves[ri].price = BigInt(priceArray[ri] ?? 0);
|
|
18326
|
+
}
|
|
18327
|
+
}
|
|
18328
|
+
}
|
|
18329
|
+
}
|
|
18330
|
+
const hubAssetMap = /* @__PURE__ */ new Map();
|
|
18331
|
+
for (let hi = 0; hi < hubAssetList.length; hi++) {
|
|
18332
|
+
const baseIdx = offset + hi * 3;
|
|
18333
|
+
const rawHubAsset = data[baseIdx];
|
|
18334
|
+
const rawAddedAssets = data[baseIdx + 1];
|
|
18335
|
+
const rawTotalOwed = data[baseIdx + 2];
|
|
18336
|
+
if (!rawHubAsset || rawHubAsset === "0x") continue;
|
|
18337
|
+
const underlying = (rawHubAsset?.underlying ?? "").toLowerCase();
|
|
18338
|
+
const key = underlying || `${hubAssetList[hi].hub}:${hubAssetList[hi].assetId}`;
|
|
18339
|
+
hubAssetMap.set(key, {
|
|
18340
|
+
liquidity: BigInt(rawHubAsset?.liquidity ?? 0),
|
|
18341
|
+
realizedFees: BigInt(rawHubAsset?.realizedFees ?? 0),
|
|
18342
|
+
decimals: Number(rawHubAsset?.decimals ?? 18),
|
|
18343
|
+
addedShares: BigInt(rawHubAsset?.addedShares ?? 0),
|
|
18344
|
+
swept: BigInt(rawHubAsset?.swept ?? 0),
|
|
18345
|
+
premiumOffsetRay: BigInt(
|
|
18346
|
+
rawHubAsset?.premiumOffsetRay ?? 0
|
|
18347
|
+
),
|
|
18348
|
+
drawnShares: BigInt(rawHubAsset?.drawnShares ?? 0),
|
|
18349
|
+
premiumShares: BigInt(rawHubAsset?.premiumShares ?? 0),
|
|
18350
|
+
liquidityFee: Number(rawHubAsset?.liquidityFee ?? 0),
|
|
18351
|
+
drawnIndex: BigInt(rawHubAsset?.drawnIndex ?? 0),
|
|
18352
|
+
drawnRate: BigInt(rawHubAsset?.drawnRate ?? 0),
|
|
18353
|
+
lastUpdateTimestamp: Number(
|
|
18354
|
+
rawHubAsset?.lastUpdateTimestamp ?? 0
|
|
18355
|
+
),
|
|
18356
|
+
underlying: rawHubAsset?.underlying ?? "",
|
|
18357
|
+
irStrategy: rawHubAsset?.irStrategy ?? "",
|
|
18358
|
+
reinvestmentController: rawHubAsset?.reinvestmentController ?? "",
|
|
18359
|
+
feeReceiver: rawHubAsset?.feeReceiver ?? "",
|
|
18360
|
+
deficitRay: BigInt(rawHubAsset?.deficitRay ?? 0),
|
|
18361
|
+
totalAddedAssets: BigInt(rawAddedAssets ?? 0),
|
|
18362
|
+
totalOwedAssets: BigInt(rawTotalOwed ?? 0)
|
|
18363
|
+
});
|
|
18364
|
+
}
|
|
18365
|
+
for (const spokeData of spokeDataList) {
|
|
18366
|
+
for (const reserve of spokeData.reserves) {
|
|
18367
|
+
const underlying = reserve.reserve.underlying?.toLowerCase?.() ?? "";
|
|
18368
|
+
if (underlying) {
|
|
18369
|
+
const hubAsset = hubAssetMap.get(underlying);
|
|
18370
|
+
if (hubAsset) {
|
|
18371
|
+
reserve.hubAsset = hubAsset;
|
|
18372
|
+
}
|
|
18373
|
+
}
|
|
18374
|
+
}
|
|
18375
|
+
}
|
|
18376
|
+
return normalizeAaveV4(
|
|
18377
|
+
spokeDataList,
|
|
18378
|
+
chainId,
|
|
18379
|
+
lender,
|
|
18380
|
+
prices,
|
|
18381
|
+
additionalYields,
|
|
18382
|
+
tokenList,
|
|
18383
|
+
lenderShortName,
|
|
18384
|
+
createMarketUid,
|
|
18385
|
+
toOracleKey,
|
|
18386
|
+
toGenericPriceKey
|
|
18387
|
+
);
|
|
18388
|
+
};
|
|
18389
|
+
return [converter, expectedCalls];
|
|
18390
|
+
};
|
|
17887
18391
|
function getMorphoTypeMarketConverter(lender, chainId, prices, additionalYields, tokenList = {}, marketsOverride) {
|
|
17888
18392
|
if (lender.startsWith("LISTA_DAO"))
|
|
17889
18393
|
return getListaMarketDataConverter(
|
|
@@ -17917,6 +18421,7 @@ function buildLenderCall(chainId, lender) {
|
|
|
17917
18421
|
if (isCompoundV2Type(lender))
|
|
17918
18422
|
return buildCompoundV2StyleLenderReserveCall(chainId, lender);
|
|
17919
18423
|
if (isEulerType(lender)) return buildEulerV2LenderReserveCall(chainId, lender);
|
|
18424
|
+
if (isAaveV4Type(lender)) return buildAaveV4LenderReserveCall(chainId, lender);
|
|
17920
18425
|
return [];
|
|
17921
18426
|
}
|
|
17922
18427
|
function getLenderDataConverter(lender, chainId, prices, additionalYields, tokenList = {}) {
|
|
@@ -17977,6 +18482,14 @@ function getLenderDataConverter(lender, chainId, prices, additionalYields, token
|
|
|
17977
18482
|
additionalYields,
|
|
17978
18483
|
tokenList
|
|
17979
18484
|
);
|
|
18485
|
+
if (isAaveV4Type(lender))
|
|
18486
|
+
return getAaveV4ReservesDataConverter(
|
|
18487
|
+
lender,
|
|
18488
|
+
chainId,
|
|
18489
|
+
prices,
|
|
18490
|
+
additionalYields,
|
|
18491
|
+
tokenList
|
|
18492
|
+
);
|
|
17980
18493
|
return [() => null, 0];
|
|
17981
18494
|
}
|
|
17982
18495
|
var getAbi = (lender) => {
|
|
@@ -17996,6 +18509,7 @@ var getAbi = (lender) => {
|
|
|
17996
18509
|
if (isInit(lender)) return InitLensAbi;
|
|
17997
18510
|
if (isMorphoType(lender)) return MorphoLensAbi;
|
|
17998
18511
|
if (isEulerType(lender)) return vaultLensAbi;
|
|
18512
|
+
if (isAaveV4Type(lender)) return [...AaveV4SpokeAbi, ...AaveV4OracleAbi, ...AaveV4HubAbi];
|
|
17999
18513
|
if (isSumerType(lender)) return [...SumerLensAbi, ...SumerComptrollerAbi];
|
|
18000
18514
|
if (lender === Lender.TAKARA) return [...TakaraMarketStateAbi];
|
|
18001
18515
|
if (isCompoundV2Type(lender)) return VenusLensAbi;
|
|
@@ -18527,8 +19041,44 @@ var buildEulerUserCall = async (chainId, lender, account, subAccountIndexes) =>
|
|
|
18527
19041
|
}));
|
|
18528
19042
|
};
|
|
18529
19043
|
|
|
19044
|
+
// src/lending/user-data/aave-v4-type/userCallBuild.ts
|
|
19045
|
+
var USER_CALLS_PER_RESERVE = 3;
|
|
19046
|
+
var buildAaveV4UserCall = (chainId, lender, account) => {
|
|
19047
|
+
const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
|
|
19048
|
+
const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
|
|
19049
|
+
if (spokes.length === 0) return [];
|
|
19050
|
+
const calls = [];
|
|
19051
|
+
for (const spokeEntry of spokes) {
|
|
19052
|
+
const spokeAddr = spokeEntry.spoke;
|
|
19053
|
+
if (!spokeAddr || spokeAddr === "0x" || spokeAddr.length <= 2) continue;
|
|
19054
|
+
const reserveIds = reservesMap[spokeAddr.toLowerCase()] ?? reservesMap[spokeAddr] ?? [];
|
|
19055
|
+
for (const entry of reserveIds) {
|
|
19056
|
+
const rid = typeof entry === "number" ? entry : entry.reserveId;
|
|
19057
|
+
calls.push(
|
|
19058
|
+
{
|
|
19059
|
+
address: spokeAddr,
|
|
19060
|
+
name: "getUserSuppliedAssets",
|
|
19061
|
+
params: [rid, account]
|
|
19062
|
+
},
|
|
19063
|
+
{
|
|
19064
|
+
address: spokeAddr,
|
|
19065
|
+
name: "getUserDebt",
|
|
19066
|
+
params: [rid, account]
|
|
19067
|
+
},
|
|
19068
|
+
{
|
|
19069
|
+
address: spokeAddr,
|
|
19070
|
+
name: "getUserReserveStatus",
|
|
19071
|
+
params: [rid, account]
|
|
19072
|
+
}
|
|
19073
|
+
);
|
|
19074
|
+
}
|
|
19075
|
+
}
|
|
19076
|
+
return calls;
|
|
19077
|
+
};
|
|
19078
|
+
|
|
18530
19079
|
// src/lending/user-data/fetch-balances/prepare.ts
|
|
18531
19080
|
async function buildUserCall(chainId, lender, account, params) {
|
|
19081
|
+
if (isAaveV4Type(lender)) return buildAaveV4UserCall(chainId, lender, account);
|
|
18532
19082
|
if (isAaveV2Type(lender)) return buildAaveV2UserCall(chainId, lender, account);
|
|
18533
19083
|
if (isAaveV3Type(lender)) return buildAaveV3UserCall(chainId, lender, account);
|
|
18534
19084
|
if (isInit(lender)) return buildInitUserCall(chainId, lender, account);
|
|
@@ -19687,8 +20237,119 @@ var getEulerUserDataConverter = (lender, chainId, account, metaMap, subAccountIn
|
|
|
19687
20237
|
];
|
|
19688
20238
|
};
|
|
19689
20239
|
|
|
20240
|
+
// src/lending/user-data/aave-v4-type/userCallParse.ts
|
|
20241
|
+
var getAaveV4UserDataConverter = (lender, chainId, account, metaMap) => {
|
|
20242
|
+
const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
|
|
20243
|
+
const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
|
|
20244
|
+
const reserveEntries = [];
|
|
20245
|
+
for (const spokeEntry of spokes) {
|
|
20246
|
+
const spokeAddr = spokeEntry.spoke;
|
|
20247
|
+
if (!spokeAddr || spokeAddr === "0x" || spokeAddr.length <= 2) continue;
|
|
20248
|
+
const reserves = reservesMap[spokeAddr.toLowerCase()] ?? reservesMap[spokeAddr] ?? [];
|
|
20249
|
+
for (const entry of reserves) {
|
|
20250
|
+
reserveEntries.push({
|
|
20251
|
+
spokeAddr,
|
|
20252
|
+
reserveId: typeof entry === "number" ? entry : entry.reserveId,
|
|
20253
|
+
hub: (spokeEntry.hub ?? "").toLowerCase(),
|
|
20254
|
+
underlying: (typeof entry === "object" ? entry.underlying ?? "" : "").toLowerCase()
|
|
20255
|
+
});
|
|
20256
|
+
}
|
|
20257
|
+
}
|
|
20258
|
+
const expectedNumberOfCalls = reserveEntries.length * USER_CALLS_PER_RESERVE;
|
|
20259
|
+
return [
|
|
20260
|
+
(data) => {
|
|
20261
|
+
if (data.length !== expectedNumberOfCalls) {
|
|
20262
|
+
return void 0;
|
|
20263
|
+
}
|
|
20264
|
+
const lendingPositions = {};
|
|
20265
|
+
let totalDebt24h = 0;
|
|
20266
|
+
let totalDeposits24h = 0;
|
|
20267
|
+
for (let i = 0; i < reserveEntries.length; i++) {
|
|
20268
|
+
const { hub, underlying } = reserveEntries[i];
|
|
20269
|
+
const refAddress = `${hub}:${underlying}`;
|
|
20270
|
+
const key = createMarketUid(chainId, lender, refAddress);
|
|
20271
|
+
const metaEntity = metaMap?.[key];
|
|
20272
|
+
if (!metaEntity) continue;
|
|
20273
|
+
const base = i * USER_CALLS_PER_RESERVE;
|
|
20274
|
+
const { dataForAsset, addedDebt, addedDeposits } = createAaveV4Entry(
|
|
20275
|
+
base,
|
|
20276
|
+
data,
|
|
20277
|
+
key,
|
|
20278
|
+
metaEntity
|
|
20279
|
+
);
|
|
20280
|
+
if (!dataForAsset) continue;
|
|
20281
|
+
totalDebt24h += addedDebt;
|
|
20282
|
+
totalDeposits24h += addedDeposits;
|
|
20283
|
+
lendingPositions[key] = dataForAsset;
|
|
20284
|
+
}
|
|
20285
|
+
const payload = {
|
|
20286
|
+
chainId,
|
|
20287
|
+
account,
|
|
20288
|
+
lendingPositions,
|
|
20289
|
+
rewards: [],
|
|
20290
|
+
userEMode: 0
|
|
20291
|
+
};
|
|
20292
|
+
const userData = createBaseTypeUserState(
|
|
20293
|
+
payload,
|
|
20294
|
+
metaMap,
|
|
20295
|
+
totalDeposits24h,
|
|
20296
|
+
totalDebt24h
|
|
20297
|
+
);
|
|
20298
|
+
return userData;
|
|
20299
|
+
},
|
|
20300
|
+
expectedNumberOfCalls
|
|
20301
|
+
];
|
|
20302
|
+
};
|
|
20303
|
+
function createAaveV4Entry(base, data, key, meta) {
|
|
20304
|
+
const rawSupply = data[base];
|
|
20305
|
+
const debtResult = data[base + 1];
|
|
20306
|
+
const statusResult = data[base + 2];
|
|
20307
|
+
const suppliedRaw = rawSupply === "0x" || rawSupply === void 0 ? "0" : rawSupply.toString();
|
|
20308
|
+
const drawnDebtRaw = Array.isArray(debtResult) ? debtResult[0]?.toString() ?? "0" : "0";
|
|
20309
|
+
const premiumDebtRaw = Array.isArray(debtResult) ? debtResult[1]?.toString() ?? "0" : "0";
|
|
20310
|
+
const totalDebtRaw = (BigInt(drawnDebtRaw || "0") + BigInt(premiumDebtRaw || "0")).toString();
|
|
20311
|
+
if ((suppliedRaw === "0" || !suppliedRaw) && totalDebtRaw === "0") {
|
|
20312
|
+
return {
|
|
20313
|
+
dataForAsset: void 0,
|
|
20314
|
+
addedDeposits: 0,
|
|
20315
|
+
addedDebt: 0
|
|
20316
|
+
};
|
|
20317
|
+
}
|
|
20318
|
+
const assetMeta = meta.asset;
|
|
20319
|
+
const decimals = assetMeta?.decimals ?? 18;
|
|
20320
|
+
const currentDeposits = parseRawAmount(suppliedRaw, decimals);
|
|
20321
|
+
const currentDebt = parseRawAmount(totalDebtRaw, decimals);
|
|
20322
|
+
const collateralEnabled = Boolean(statusResult?.[0]);
|
|
20323
|
+
const price = getDisplayPrice(meta);
|
|
20324
|
+
const oPrice = getOraclePrice(meta);
|
|
20325
|
+
const priceHist = meta?.price?.priceUsd24h ?? price;
|
|
20326
|
+
const dataForAsset = {
|
|
20327
|
+
marketUid: key,
|
|
20328
|
+
underlying: assetMeta.address,
|
|
20329
|
+
deposits: currentDeposits,
|
|
20330
|
+
debtStable: "0",
|
|
20331
|
+
debt: currentDebt,
|
|
20332
|
+
depositsUSD: Number(currentDeposits) * price,
|
|
20333
|
+
debtStableUSD: 0,
|
|
20334
|
+
debtUSD: Number(currentDebt) * price,
|
|
20335
|
+
depositsUSDOracle: Number(currentDeposits) * oPrice,
|
|
20336
|
+
debtStableUSDOracle: 0,
|
|
20337
|
+
debtUSDOracle: Number(currentDebt) * oPrice,
|
|
20338
|
+
stableBorrowRate: 0,
|
|
20339
|
+
collateralEnabled,
|
|
20340
|
+
claimableRewards: 0
|
|
20341
|
+
};
|
|
20342
|
+
return {
|
|
20343
|
+
dataForAsset,
|
|
20344
|
+
addedDeposits: Number(currentDeposits) * priceHist,
|
|
20345
|
+
addedDebt: Number(currentDebt) * priceHist
|
|
20346
|
+
};
|
|
20347
|
+
}
|
|
20348
|
+
|
|
19690
20349
|
// src/lending/user-data/fetch-balances/parse.ts
|
|
19691
20350
|
function getUserDataConverter(lender, chainId, account, params, meta) {
|
|
20351
|
+
if (isAaveV4Type(lender))
|
|
20352
|
+
return getAaveV4UserDataConverter(lender, chainId, account, meta?.[lender]);
|
|
19692
20353
|
if (isYLDR(lender))
|
|
19693
20354
|
return getYldrUserDataConverter(lender, chainId, account, meta?.[lender]);
|
|
19694
20355
|
if (isAaveV2Type(lender))
|
|
@@ -24367,6 +25028,7 @@ var accountLensAbi = [
|
|
|
24367
25028
|
|
|
24368
25029
|
// src/lending/user-data/abis.ts
|
|
24369
25030
|
var getAbi2 = (lender) => {
|
|
25031
|
+
if (isAaveV4Type(lender)) return [...AaveV4SpokeAbi];
|
|
24370
25032
|
if (isAaveV2Type(lender))
|
|
24371
25033
|
return [
|
|
24372
25034
|
...AavePoolAndDataProviderAbi,
|
|
@@ -24807,12 +25469,27 @@ function resolveDebitDataKey(chainId, lender, tokenAddress, cToken) {
|
|
|
24807
25469
|
if (resolved) return resolved.toLowerCase();
|
|
24808
25470
|
}
|
|
24809
25471
|
}
|
|
25472
|
+
if (isCompoundV3Type(lender)) {
|
|
25473
|
+
const comet = getCompoundV3CometAddress$1(chainId, lender);
|
|
25474
|
+
if (comet) return comet;
|
|
25475
|
+
}
|
|
25476
|
+
if (isMorphoType(lender)) {
|
|
25477
|
+
const comet = getMorphoAddress(
|
|
25478
|
+
chainId,
|
|
25479
|
+
isLista(lender) ? Lender.LISTA_DAO : Lender.MORPHO_BLUE
|
|
25480
|
+
);
|
|
25481
|
+
if (comet) return comet;
|
|
25482
|
+
}
|
|
25483
|
+
if (isAaveType(lender)) {
|
|
25484
|
+
const aToken = getAaveCollateralTokenAddress(chainId, lender, tokenAddress);
|
|
25485
|
+
if (aToken) return aToken;
|
|
25486
|
+
}
|
|
24810
25487
|
return tokenAddress.toLowerCase();
|
|
24811
25488
|
}
|
|
24812
25489
|
function needsLenderApproval(params) {
|
|
24813
25490
|
const { lender, lenderDebitData, tokenAddress, amount, chainId, cToken } = params;
|
|
24814
25491
|
if (!lenderDebitData) return true;
|
|
24815
|
-
if (isInit(lender) || isMorphoType(lender)) {
|
|
25492
|
+
if (isInit(lender) || isMorphoType(lender) || isCompoundV3(lender)) {
|
|
24816
25493
|
const entry2 = Object.values(lenderDebitData)[0];
|
|
24817
25494
|
if (!entry2 || entry2.amount === void 0) return true;
|
|
24818
25495
|
return entry2.amount === 0n;
|
|
@@ -31207,6 +31884,105 @@ var eulerV2Fetcher = {
|
|
|
31207
31884
|
parse: parseEulerV2Results,
|
|
31208
31885
|
getAbi: getEulerV2Abi
|
|
31209
31886
|
};
|
|
31887
|
+
function getAaveV4OracleGroups(chainId) {
|
|
31888
|
+
const oracles = aaveV4Oracles() ?? {};
|
|
31889
|
+
const spokes = aaveV4Spokes() ?? {};
|
|
31890
|
+
const groups = [];
|
|
31891
|
+
for (const [fork, chains] of Object.entries(oracles)) {
|
|
31892
|
+
const oracleEntries = chains[chainId] ?? [];
|
|
31893
|
+
if (oracleEntries.length === 0) continue;
|
|
31894
|
+
const spokeToHub = /* @__PURE__ */ new Map();
|
|
31895
|
+
for (const s of spokes[fork]?.[chainId] ?? []) {
|
|
31896
|
+
if (s.hub) spokeToHub.set(s.spoke.toLowerCase(), s.hub.toLowerCase());
|
|
31897
|
+
}
|
|
31898
|
+
const byOracle = /* @__PURE__ */ new Map();
|
|
31899
|
+
for (const entry of oracleEntries) {
|
|
31900
|
+
if (!entry.oracle || entry.oracle === "0x") continue;
|
|
31901
|
+
const key = entry.oracle.toLowerCase();
|
|
31902
|
+
let group = byOracle.get(key);
|
|
31903
|
+
if (!group) {
|
|
31904
|
+
group = { decimals: entry.decimals ?? 8, entries: [] };
|
|
31905
|
+
byOracle.set(key, group);
|
|
31906
|
+
}
|
|
31907
|
+
const spokeLc = entry.spoke.toLowerCase();
|
|
31908
|
+
const hub = spokeToHub.get(spokeLc) ?? "";
|
|
31909
|
+
group.entries.push({
|
|
31910
|
+
underlying: entry.underlying.toLowerCase(),
|
|
31911
|
+
hub,
|
|
31912
|
+
reserveId: entry.reserveId,
|
|
31913
|
+
spoke: spokeLc
|
|
31914
|
+
});
|
|
31915
|
+
}
|
|
31916
|
+
for (const [oracle, group] of byOracle) {
|
|
31917
|
+
groups.push({
|
|
31918
|
+
fork,
|
|
31919
|
+
oracle,
|
|
31920
|
+
decimals: group.decimals,
|
|
31921
|
+
entries: group.entries
|
|
31922
|
+
});
|
|
31923
|
+
}
|
|
31924
|
+
}
|
|
31925
|
+
return groups;
|
|
31926
|
+
}
|
|
31927
|
+
function getAaveV4Calls(chainId) {
|
|
31928
|
+
const groups = getAaveV4OracleGroups(chainId);
|
|
31929
|
+
const results = [];
|
|
31930
|
+
for (const { fork, oracle, decimals, entries } of groups) {
|
|
31931
|
+
const calls = entries.map((e) => ({
|
|
31932
|
+
address: oracle,
|
|
31933
|
+
name: "getReservePrice",
|
|
31934
|
+
params: [e.reserveId]
|
|
31935
|
+
}));
|
|
31936
|
+
results.push({
|
|
31937
|
+
calls,
|
|
31938
|
+
meta: {
|
|
31939
|
+
oracle,
|
|
31940
|
+
oracleDecimals: decimals,
|
|
31941
|
+
entries,
|
|
31942
|
+
fork
|
|
31943
|
+
},
|
|
31944
|
+
lender: fork
|
|
31945
|
+
});
|
|
31946
|
+
}
|
|
31947
|
+
return results;
|
|
31948
|
+
}
|
|
31949
|
+
function parseAaveV4Results(data, meta, context) {
|
|
31950
|
+
const { chainId } = context;
|
|
31951
|
+
const entries = [];
|
|
31952
|
+
if (data.length === 0) return entries;
|
|
31953
|
+
const divisor = 10 ** meta.oracleDecimals;
|
|
31954
|
+
for (let i = 0; i < meta.entries.length; i++) {
|
|
31955
|
+
const rawPrice = data[i];
|
|
31956
|
+
if (rawPrice === void 0 || rawPrice === "0x") continue;
|
|
31957
|
+
const entry = meta.entries[i];
|
|
31958
|
+
try {
|
|
31959
|
+
const priceNum = Number(BigInt(rawPrice.toString())) / divisor;
|
|
31960
|
+
if (isNaN(priceNum) || priceNum === 0) continue;
|
|
31961
|
+
entries.push({
|
|
31962
|
+
asset: entry.underlying,
|
|
31963
|
+
price: priceNum,
|
|
31964
|
+
priceUSD: priceNum,
|
|
31965
|
+
marketUid: createMarketUid(
|
|
31966
|
+
chainId,
|
|
31967
|
+
meta.fork,
|
|
31968
|
+
`${entry.hub}:${entry.underlying}`
|
|
31969
|
+
),
|
|
31970
|
+
configId: entry.spoke
|
|
31971
|
+
});
|
|
31972
|
+
} catch {
|
|
31973
|
+
continue;
|
|
31974
|
+
}
|
|
31975
|
+
}
|
|
31976
|
+
return entries;
|
|
31977
|
+
}
|
|
31978
|
+
function getAaveV4Abi() {
|
|
31979
|
+
return AaveV4OracleAbi;
|
|
31980
|
+
}
|
|
31981
|
+
var aaveV4Fetcher = {
|
|
31982
|
+
getCalls: getAaveV4Calls,
|
|
31983
|
+
parse: parseAaveV4Results,
|
|
31984
|
+
getAbi: getAaveV4Abi
|
|
31985
|
+
};
|
|
31210
31986
|
|
|
31211
31987
|
// src/prices/oracle-prices/fetchOraclePrices.ts
|
|
31212
31988
|
function countFailures(data, offset, count) {
|
|
@@ -31346,6 +32122,11 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31346
32122
|
() => eulerV2Fetcher.getCalls(chainId),
|
|
31347
32123
|
getCallsErrors
|
|
31348
32124
|
) : [];
|
|
32125
|
+
const aaveV4Results = isActive("aavev4") ? safeGetCalls(
|
|
32126
|
+
"aaveV4",
|
|
32127
|
+
() => aaveV4Fetcher.getCalls(chainId),
|
|
32128
|
+
getCallsErrors
|
|
32129
|
+
) : [];
|
|
31349
32130
|
const morphoResults = isActive("morpho") ? safeGetCalls(
|
|
31350
32131
|
"morpho",
|
|
31351
32132
|
() => morphoFetcher.getCalls(chainId, {
|
|
@@ -31383,6 +32164,12 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31383
32164
|
eulerV2Fetcher.parse,
|
|
31384
32165
|
getEulerV2Abi()
|
|
31385
32166
|
);
|
|
32167
|
+
const aaveV4Group = buildGroup(
|
|
32168
|
+
"aaveV4",
|
|
32169
|
+
aaveV4Results,
|
|
32170
|
+
aaveV4Fetcher.parse,
|
|
32171
|
+
getAaveV4Abi()
|
|
32172
|
+
);
|
|
31386
32173
|
const morphoGroup = buildGroup(
|
|
31387
32174
|
"morpho",
|
|
31388
32175
|
morphoResults,
|
|
@@ -31395,6 +32182,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31395
32182
|
compoundV3Group,
|
|
31396
32183
|
listaGroup,
|
|
31397
32184
|
eulerGroup,
|
|
32185
|
+
aaveV4Group,
|
|
31398
32186
|
morphoGroup
|
|
31399
32187
|
];
|
|
31400
32188
|
const totalCalls = allGroups.reduce((s, g) => s + g.calls.length, 0);
|
|
@@ -31420,6 +32208,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31420
32208
|
compoundV3Data,
|
|
31421
32209
|
listaData,
|
|
31422
32210
|
eulerData,
|
|
32211
|
+
aaveV4Data,
|
|
31423
32212
|
morphoGqlEntries
|
|
31424
32213
|
] = await Promise.all([
|
|
31425
32214
|
executeGroup(
|
|
@@ -31462,6 +32251,14 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31462
32251
|
allowFailure,
|
|
31463
32252
|
rpcOverrides
|
|
31464
32253
|
),
|
|
32254
|
+
executeGroup(
|
|
32255
|
+
aaveV4Group,
|
|
32256
|
+
chainId,
|
|
32257
|
+
chainBatchSize,
|
|
32258
|
+
retries,
|
|
32259
|
+
allowFailure,
|
|
32260
|
+
rpcOverrides
|
|
32261
|
+
),
|
|
31465
32262
|
morphoGqlPromise
|
|
31466
32263
|
]);
|
|
31467
32264
|
if (morphoGqlEntries == null && isActive("morpho")) {
|
|
@@ -31482,6 +32279,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31482
32279
|
{ group: compoundV3Group, data: compoundV3Data },
|
|
31483
32280
|
{ group: listaGroup, data: listaData },
|
|
31484
32281
|
{ group: eulerGroup, data: eulerData },
|
|
32282
|
+
{ group: aaveV4Group, data: aaveV4Data },
|
|
31485
32283
|
...useMorphoGql ? [] : [{ group: morphoGroup, data: morphoData }]
|
|
31486
32284
|
];
|
|
31487
32285
|
for (const { group, data } of groupResults) {
|
|
@@ -31536,6 +32334,7 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31536
32334
|
parseTrackers(compoundV3Group, compoundV3Data.results);
|
|
31537
32335
|
parseTrackers(listaGroup, listaData.results);
|
|
31538
32336
|
parseTrackers(eulerGroup, eulerData.results);
|
|
32337
|
+
parseTrackers(aaveV4Group, aaveV4Data.results);
|
|
31539
32338
|
if (stalenessThresholdSeconds > 0) {
|
|
31540
32339
|
const nowSeconds = Math.floor(Date.now() / 1e3);
|
|
31541
32340
|
for (const tracker of compoundV3Group.trackers) {
|