@1delta/margin-fetcher 0.0.221 → 0.0.223
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 +350 -479
- package/dist/index.js.map +1 -1
- package/dist/lending/public-data/aave-v4-type/fetcher/normalize.d.ts +36 -19
- package/dist/lending/public-data/aave-v4-type/fetcher/normalize.d.ts.map +1 -1
- package/dist/lending/public-data/aave-v4-type/publicCallBuild.d.ts +18 -15
- package/dist/lending/public-data/aave-v4-type/publicCallBuild.d.ts.map +1 -1
- package/dist/lending/public-data/aave-v4-type/publicCallParse.d.ts +9 -1
- package/dist/lending/public-data/aave-v4-type/publicCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/aave-v4-type/userCallBuild.d.ts +3 -4
- package/dist/lending/user-data/aave-v4-type/userCallBuild.d.ts.map +1 -1
- package/dist/lending/user-data/aave-v4-type/userCallParse.d.ts +10 -15
- package/dist/lending/user-data/aave-v4-type/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/fetch-balances/parse.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/aaveV4.d.ts.map +1 -1
- package/dist/prices/oracle-prices/types.d.ts +4 -3
- package/dist/prices/oracle-prices/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -6275,9 +6275,7 @@ globalThis[GLOBAL_LENDER_DATA_KEY] = {
|
|
|
6275
6275
|
compoundV3Bulker: {},
|
|
6276
6276
|
eulerConfigs: {},
|
|
6277
6277
|
eulerVaults: {},
|
|
6278
|
-
aaveV4Hubs: {},
|
|
6279
6278
|
aaveV4Spokes: {},
|
|
6280
|
-
aaveV4Reserves: {},
|
|
6281
6279
|
aaveV4Oracles: {},
|
|
6282
6280
|
aaveV4Peripherals: {}
|
|
6283
6281
|
};
|
|
@@ -6304,15 +6302,18 @@ var initConfig = () => getGlobalData2()?.initConfig;
|
|
|
6304
6302
|
var aaveOraclesConfig = () => getGlobalData2()?.aaveOraclesConfig;
|
|
6305
6303
|
var eulerConfigs = () => getGlobalData2()?.eulerConfigs;
|
|
6306
6304
|
var eulerVaults = () => getGlobalData2()?.eulerVaults;
|
|
6307
|
-
var aaveV4Hubs = () => getGlobalData2()?.aaveV4Hubs;
|
|
6308
6305
|
var aaveV4Spokes = () => getGlobalData2()?.aaveV4Spokes;
|
|
6309
|
-
var aaveV4Reserves = () => getGlobalData2()?.aaveV4Reserves;
|
|
6310
6306
|
var aaveV4Oracles = () => getGlobalData2()?.aaveV4Oracles;
|
|
6311
|
-
function aaveV4SpokeLenderKey(
|
|
6312
|
-
if (!spoke ||
|
|
6307
|
+
function aaveV4SpokeLenderKey(spoke) {
|
|
6308
|
+
if (!spoke || !spoke.startsWith("0x") || spoke.length !== 42) {
|
|
6313
6309
|
throw new Error(`aaveV4SpokeLenderKey: invalid spoke address ${spoke}`);
|
|
6314
6310
|
}
|
|
6315
|
-
return
|
|
6311
|
+
return `AAVE_V4_${spoke.slice(2).toUpperCase()}`;
|
|
6312
|
+
}
|
|
6313
|
+
function parseAaveV4SpokeLenderKey(lenderKey) {
|
|
6314
|
+
const match = lenderKey.match(/^AAVE_V4_([0-9A-F]{40})$/);
|
|
6315
|
+
if (!match) return void 0;
|
|
6316
|
+
return { spokeAddrLower: "0x" + match[1].toLowerCase() };
|
|
6316
6317
|
}
|
|
6317
6318
|
var getListUrl = (chainId) => `https://raw.githubusercontent.com/1delta-DAO/token-lists/main/${chainId}.json`;
|
|
6318
6319
|
async function fetchTokenList(chainId) {
|
|
@@ -7544,9 +7545,10 @@ var getLendersForChain = (c) => {
|
|
|
7544
7545
|
if (data[c]?.length > 0) lenders.push(l);
|
|
7545
7546
|
});
|
|
7546
7547
|
}
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7548
|
+
const v4ChainSpokes = aaveV4Spokes()?.[c] ?? {};
|
|
7549
|
+
for (const spokeAddr of Object.keys(v4ChainSpokes)) {
|
|
7550
|
+
lenders.push(aaveV4SpokeLenderKey(spokeAddr));
|
|
7551
|
+
}
|
|
7550
7552
|
return lenders;
|
|
7551
7553
|
};
|
|
7552
7554
|
var filterLendersByProtocol = (allLenders, protocolList) => {
|
|
@@ -17925,156 +17927,106 @@ var MAX_HUB_ASSETS = 25;
|
|
|
17925
17927
|
function isValidAddress(addr) {
|
|
17926
17928
|
return !!addr && addr !== "0x" && addr.length > 2;
|
|
17927
17929
|
}
|
|
17928
|
-
function getSpokeReserves(reservesMap, spokeAddr) {
|
|
17929
|
-
return reservesMap[spokeAddr.toLowerCase()] ?? reservesMap[spokeAddr] ?? [];
|
|
17930
|
-
}
|
|
17931
|
-
function getReserveAssetId(entry) {
|
|
17932
|
-
if (typeof entry === "object" && entry != null) {
|
|
17933
|
-
const v = entry.assetId;
|
|
17934
|
-
if (typeof v === "number") return v;
|
|
17935
|
-
}
|
|
17936
|
-
return void 0;
|
|
17937
|
-
}
|
|
17938
17930
|
function getDynamicConfigCount(spokeEntry) {
|
|
17939
|
-
const max = spokeEntry
|
|
17931
|
+
const max = spokeEntry?.dynamicConfigKeyMax ?? 0;
|
|
17940
17932
|
return max + 1;
|
|
17941
17933
|
}
|
|
17934
|
+
function resolveSpokeEntry(chainId, lender) {
|
|
17935
|
+
const parsed = parseAaveV4SpokeLenderKey(lender);
|
|
17936
|
+
if (!parsed) return void 0;
|
|
17937
|
+
return aaveV4Spokes()?.[chainId]?.[parsed.spokeAddrLower];
|
|
17938
|
+
}
|
|
17939
|
+
function distinctHubsInOrder(reserves) {
|
|
17940
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17941
|
+
const out = [];
|
|
17942
|
+
for (const r of reserves) {
|
|
17943
|
+
const h = (r?.hub ?? "").toLowerCase();
|
|
17944
|
+
if (!h || !isValidAddress(h)) continue;
|
|
17945
|
+
if (seen.has(h)) continue;
|
|
17946
|
+
seen.add(h);
|
|
17947
|
+
out.push(h);
|
|
17948
|
+
}
|
|
17949
|
+
return out;
|
|
17950
|
+
}
|
|
17942
17951
|
var buildAaveV4LenderReserveCall = (chainId, lender) => {
|
|
17943
|
-
const
|
|
17944
|
-
|
|
17945
|
-
|
|
17952
|
+
const spokeEntry = resolveSpokeEntry(chainId, lender);
|
|
17953
|
+
if (!spokeEntry) return [];
|
|
17954
|
+
const spokeAddr = spokeEntry.spoke.toLowerCase();
|
|
17955
|
+
if (!isValidAddress(spokeAddr)) return [];
|
|
17956
|
+
const reserves = spokeEntry.reserves ?? [];
|
|
17957
|
+
const dynConfigCount = getDynamicConfigCount(spokeEntry);
|
|
17946
17958
|
const calls = [];
|
|
17947
|
-
for (const
|
|
17948
|
-
|
|
17949
|
-
|
|
17950
|
-
|
|
17951
|
-
|
|
17952
|
-
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
{
|
|
17956
|
-
address: spokeAddr,
|
|
17957
|
-
name: "getReserve",
|
|
17958
|
-
params: [rid]
|
|
17959
|
-
},
|
|
17960
|
-
{
|
|
17961
|
-
address: spokeAddr,
|
|
17962
|
-
name: "getReserveConfig",
|
|
17963
|
-
params: [rid]
|
|
17964
|
-
},
|
|
17965
|
-
{
|
|
17966
|
-
address: spokeAddr,
|
|
17967
|
-
name: "getReserveSuppliedAssets",
|
|
17968
|
-
params: [rid]
|
|
17969
|
-
},
|
|
17970
|
-
{
|
|
17971
|
-
address: spokeAddr,
|
|
17972
|
-
name: "getReserveDebt",
|
|
17973
|
-
params: [rid]
|
|
17974
|
-
},
|
|
17975
|
-
{
|
|
17976
|
-
address: spokeAddr,
|
|
17977
|
-
name: "getReserveTotalDebt",
|
|
17978
|
-
params: [rid]
|
|
17979
|
-
}
|
|
17980
|
-
);
|
|
17981
|
-
for (let key = 0; key < dynConfigCount; key++) {
|
|
17982
|
-
calls.push({
|
|
17983
|
-
address: spokeAddr,
|
|
17984
|
-
name: "getDynamicReserveConfig",
|
|
17985
|
-
params: [rid, key]
|
|
17986
|
-
});
|
|
17987
|
-
}
|
|
17988
|
-
}
|
|
17989
|
-
calls.push({
|
|
17990
|
-
address: spokeAddr,
|
|
17991
|
-
name: "getLiquidationConfig",
|
|
17992
|
-
params: []
|
|
17993
|
-
});
|
|
17994
|
-
}
|
|
17995
|
-
for (const spokeEntry of spokes) {
|
|
17996
|
-
if (!isValidAddress(spokeEntry.spoke)) continue;
|
|
17997
|
-
const reserves = getSpokeReserves(reservesMap, spokeEntry.spoke);
|
|
17998
|
-
const rids = reserves.map(
|
|
17999
|
-
(e) => typeof e === "number" ? e : e.reserveId
|
|
17959
|
+
for (const r of reserves) {
|
|
17960
|
+
const rid = r.reserveId;
|
|
17961
|
+
calls.push(
|
|
17962
|
+
{ address: spokeAddr, name: "getReserve", params: [rid] },
|
|
17963
|
+
{ address: spokeAddr, name: "getReserveConfig", params: [rid] },
|
|
17964
|
+
{ address: spokeAddr, name: "getReserveSuppliedAssets", params: [rid] },
|
|
17965
|
+
{ address: spokeAddr, name: "getReserveDebt", params: [rid] },
|
|
17966
|
+
{ address: spokeAddr, name: "getReserveTotalDebt", params: [rid] }
|
|
18000
17967
|
);
|
|
18001
|
-
|
|
17968
|
+
for (let key = 0; key < dynConfigCount; key++) {
|
|
18002
17969
|
calls.push({
|
|
18003
|
-
address:
|
|
18004
|
-
name: "
|
|
18005
|
-
params: [
|
|
17970
|
+
address: spokeAddr,
|
|
17971
|
+
name: "getDynamicReserveConfig",
|
|
17972
|
+
params: [rid, key]
|
|
18006
17973
|
});
|
|
18007
17974
|
}
|
|
18008
17975
|
}
|
|
18009
|
-
|
|
18010
|
-
|
|
18011
|
-
|
|
17976
|
+
calls.push({
|
|
17977
|
+
address: spokeAddr,
|
|
17978
|
+
name: "getLiquidationConfig",
|
|
17979
|
+
params: []
|
|
17980
|
+
});
|
|
17981
|
+
const reserveIds = reserves.map((r) => r.reserveId);
|
|
17982
|
+
if (reserveIds.length > 0 && isValidAddress(spokeEntry.oracle)) {
|
|
18012
17983
|
calls.push({
|
|
18013
|
-
address:
|
|
18014
|
-
name: "
|
|
18015
|
-
params: []
|
|
17984
|
+
address: spokeEntry.oracle.toLowerCase(),
|
|
17985
|
+
name: "getReservesPrices",
|
|
17986
|
+
params: [reserveIds]
|
|
18016
17987
|
});
|
|
17988
|
+
}
|
|
17989
|
+
const distinctHubs = distinctHubsInOrder(reserves);
|
|
17990
|
+
for (const hub of distinctHubs) {
|
|
17991
|
+
calls.push({ address: hub, name: "getAssetCount", params: [] });
|
|
18017
17992
|
for (let i = 0; i < MAX_HUB_ASSETS; i++) {
|
|
18018
17993
|
calls.push(
|
|
18019
|
-
{
|
|
18020
|
-
|
|
18021
|
-
|
|
18022
|
-
params: [i]
|
|
18023
|
-
},
|
|
18024
|
-
{
|
|
18025
|
-
address: hubAddr,
|
|
18026
|
-
name: "getAddedAssets",
|
|
18027
|
-
params: [i]
|
|
18028
|
-
},
|
|
18029
|
-
{
|
|
18030
|
-
address: hubAddr,
|
|
18031
|
-
name: "getAssetTotalOwed",
|
|
18032
|
-
params: [i]
|
|
18033
|
-
}
|
|
17994
|
+
{ address: hub, name: "getAsset", params: [i] },
|
|
17995
|
+
{ address: hub, name: "getAddedAssets", params: [i] },
|
|
17996
|
+
{ address: hub, name: "getAssetTotalOwed", params: [i] }
|
|
18034
17997
|
);
|
|
18035
17998
|
}
|
|
18036
|
-
for (const
|
|
18037
|
-
if (
|
|
18038
|
-
const
|
|
18039
|
-
|
|
18040
|
-
|
|
18041
|
-
|
|
18042
|
-
|
|
18043
|
-
|
|
18044
|
-
|
|
18045
|
-
name: "getSpoke",
|
|
18046
|
-
params: [assetId, spokeAddr]
|
|
18047
|
-
});
|
|
18048
|
-
}
|
|
17999
|
+
for (const r of reserves) {
|
|
18000
|
+
if ((r?.hub ?? "").toLowerCase() !== hub) continue;
|
|
18001
|
+
const assetId = r.assetId;
|
|
18002
|
+
if (typeof assetId !== "number") continue;
|
|
18003
|
+
calls.push({
|
|
18004
|
+
address: hub,
|
|
18005
|
+
name: "getSpoke",
|
|
18006
|
+
params: [assetId, spokeAddr]
|
|
18007
|
+
});
|
|
18049
18008
|
}
|
|
18050
18009
|
}
|
|
18051
18010
|
return calls;
|
|
18052
18011
|
};
|
|
18053
18012
|
var getAaveV4ExpectedCallCount = (chainId, lender) => {
|
|
18054
|
-
const
|
|
18055
|
-
|
|
18013
|
+
const spokeEntry = resolveSpokeEntry(chainId, lender);
|
|
18014
|
+
if (!spokeEntry) return 0;
|
|
18015
|
+
if (!isValidAddress(spokeEntry.spoke)) return 0;
|
|
18016
|
+
const reserves = spokeEntry.reserves ?? [];
|
|
18017
|
+
const dynConfigCount = getDynamicConfigCount(spokeEntry);
|
|
18056
18018
|
let count = 0;
|
|
18057
|
-
|
|
18058
|
-
|
|
18059
|
-
|
|
18060
|
-
|
|
18061
|
-
count += reserves.length * (BASE_CALLS_PER_RESERVE + dynConfigCount) + CALLS_PER_SPOKE_TAIL;
|
|
18062
|
-
const rids = reserves.map(
|
|
18063
|
-
(e) => typeof e === "number" ? e : e.reserveId
|
|
18064
|
-
);
|
|
18065
|
-
if (rids.length > 0 && isValidAddress(spokeEntry.oracle)) {
|
|
18066
|
-
count += 1;
|
|
18067
|
-
}
|
|
18019
|
+
count += reserves.length * (BASE_CALLS_PER_RESERVE + dynConfigCount);
|
|
18020
|
+
count += CALLS_PER_SPOKE_TAIL;
|
|
18021
|
+
if (reserves.length > 0 && isValidAddress(spokeEntry.oracle)) {
|
|
18022
|
+
count += 1;
|
|
18068
18023
|
}
|
|
18069
|
-
const
|
|
18070
|
-
|
|
18024
|
+
const distinctHubs = distinctHubsInOrder(reserves);
|
|
18025
|
+
for (const hub of distinctHubs) {
|
|
18071
18026
|
count += 1 + MAX_HUB_ASSETS * 3;
|
|
18072
|
-
for (const
|
|
18073
|
-
if (
|
|
18074
|
-
|
|
18075
|
-
for (const entry of reserves) {
|
|
18076
|
-
if (getReserveAssetId(entry) != null) count += 1;
|
|
18077
|
-
}
|
|
18027
|
+
for (const r of reserves) {
|
|
18028
|
+
if ((r?.hub ?? "").toLowerCase() !== hub) continue;
|
|
18029
|
+
if (typeof r.assetId === "number") count += 1;
|
|
18078
18030
|
}
|
|
18079
18031
|
}
|
|
18080
18032
|
return count;
|
|
@@ -18109,23 +18061,24 @@ function rayRateToApr(rateRay) {
|
|
|
18109
18061
|
if (rateRay === 0n) return 0;
|
|
18110
18062
|
return Number(rateRay) / RAY2 * 100;
|
|
18111
18063
|
}
|
|
18112
|
-
function normalizeAaveV4(spokeDataList, chainId,
|
|
18113
|
-
const
|
|
18114
|
-
|
|
18115
|
-
|
|
18064
|
+
function normalizeAaveV4(spokeDataList, chainId, spokeLenderKeyArg, prices, additionalYields, tokenList, lenderShortNameFn, createMarketUidFn, toOracleKeyFn, toGenericPriceKeyFn) {
|
|
18065
|
+
const spokeData = spokeDataList[0];
|
|
18066
|
+
if (!spokeData) return void 0;
|
|
18067
|
+
{
|
|
18116
18068
|
const spokeAddr = spokeData.spoke.toLowerCase();
|
|
18117
|
-
const
|
|
18118
|
-
|
|
18069
|
+
const parsedFromArg = parseAaveV4SpokeLenderKey(spokeLenderKeyArg);
|
|
18070
|
+
const spokeLenderKey = parsedFromArg && parsedFromArg.spokeAddrLower === spokeAddr ? spokeLenderKeyArg : aaveV4SpokeLenderKey(spokeAddr);
|
|
18119
18071
|
const spokeReserves = spokeData.reserves;
|
|
18120
18072
|
const data = {};
|
|
18121
18073
|
for (const reserve of spokeReserves) {
|
|
18122
|
-
const reserveHub = reserve.reserve.hub
|
|
18123
|
-
if (hubFilter && reserveHub && reserveHub !== hubFilter)
|
|
18124
|
-
continue;
|
|
18125
|
-
if (!spokeHub) spokeHub = reserveHub ?? "";
|
|
18074
|
+
const reserveHub = (reserve.reserve.hub ?? "").toLowerCase();
|
|
18126
18075
|
const underlying = reserve.reserve.underlying.toLowerCase();
|
|
18127
18076
|
const decimals = reserve.reserve.decimals;
|
|
18128
|
-
const marketUid = createMarketUidFn(
|
|
18077
|
+
const marketUid = createMarketUidFn(
|
|
18078
|
+
chainId,
|
|
18079
|
+
spokeLenderKey,
|
|
18080
|
+
String(reserve.reserveId)
|
|
18081
|
+
);
|
|
18129
18082
|
const assetMeta = tokenList[underlying];
|
|
18130
18083
|
const oracleKey = toOracleKeyFn(assetMeta?.assetGroup ?? null) ?? toGenericPriceKeyFn(underlying, chainId);
|
|
18131
18084
|
let price = 0;
|
|
@@ -18134,15 +18087,9 @@ function normalizeAaveV4(spokeDataList, chainId, baseHubLender, prices, addition
|
|
|
18134
18087
|
} else {
|
|
18135
18088
|
price = prices[oracleKey] ?? 0;
|
|
18136
18089
|
}
|
|
18137
|
-
const totalDepositsStr = toTokenAmount2(
|
|
18138
|
-
reserve.suppliedAssets,
|
|
18139
|
-
decimals
|
|
18140
|
-
);
|
|
18090
|
+
const totalDepositsStr = toTokenAmount2(reserve.suppliedAssets, decimals);
|
|
18141
18091
|
const totalDebtStr = toTokenAmount2(reserve.totalDebt, decimals);
|
|
18142
|
-
const totalDepositsNum = toTokenNumber(
|
|
18143
|
-
reserve.suppliedAssets,
|
|
18144
|
-
decimals
|
|
18145
|
-
);
|
|
18092
|
+
const totalDepositsNum = toTokenNumber(reserve.suppliedAssets, decimals);
|
|
18146
18093
|
const totalDebtNum = toTokenNumber(reserve.totalDebt, decimals);
|
|
18147
18094
|
const totalDepositsUSD = totalDepositsNum * price;
|
|
18148
18095
|
const totalDebtUSD = totalDebtNum * price;
|
|
@@ -18176,11 +18123,9 @@ function normalizeAaveV4(spokeDataList, chainId, baseHubLender, prices, addition
|
|
|
18176
18123
|
const collateralRiskBps = reserve.config.collateralRisk || reserve.reserve.collateralRisk || 0;
|
|
18177
18124
|
const riskPremiumThresholdBps = reserve.spokeBinding?.riskPremiumThreshold ?? 0;
|
|
18178
18125
|
const config = {};
|
|
18179
|
-
for (const [keyStr, dynCfg] of Object.entries(
|
|
18180
|
-
reserve.dynamicConfigs
|
|
18181
|
-
)) {
|
|
18126
|
+
for (const [keyStr, dynCfg] of Object.entries(reserve.dynamicConfigs)) {
|
|
18182
18127
|
config[keyStr] = {
|
|
18183
|
-
category: keyStr,
|
|
18128
|
+
category: Number(keyStr),
|
|
18184
18129
|
label: `${spokeData.label} / Config ${keyStr}`,
|
|
18185
18130
|
borrowCollateralFactor: dynCfg.collateralFactor / BPS,
|
|
18186
18131
|
collateralFactor: dynCfg.collateralFactor / BPS,
|
|
@@ -18191,7 +18136,7 @@ function normalizeAaveV4(spokeDataList, chainId, baseHubLender, prices, addition
|
|
|
18191
18136
|
}
|
|
18192
18137
|
if (Object.keys(config).length === 0) {
|
|
18193
18138
|
config["0"] = {
|
|
18194
|
-
category:
|
|
18139
|
+
category: 0,
|
|
18195
18140
|
label: `${spokeData.label} / Default`,
|
|
18196
18141
|
borrowCollateralFactor: 0,
|
|
18197
18142
|
collateralFactor: 0,
|
|
@@ -18205,7 +18150,7 @@ function normalizeAaveV4(spokeDataList, chainId, baseHubLender, prices, addition
|
|
|
18205
18150
|
);
|
|
18206
18151
|
data[marketUid] = {
|
|
18207
18152
|
marketUid,
|
|
18208
|
-
name:
|
|
18153
|
+
name: "Aave V4 " + spokeData.label + " " + (assetMeta?.symbol ?? ""),
|
|
18209
18154
|
poolId: underlying,
|
|
18210
18155
|
underlying,
|
|
18211
18156
|
asset: assetMeta,
|
|
@@ -18238,167 +18183,155 @@ function normalizeAaveV4(spokeDataList, chainId, baseHubLender, prices, addition
|
|
|
18238
18183
|
params: {
|
|
18239
18184
|
metadata: {
|
|
18240
18185
|
assetId: reserve.reserve.assetId,
|
|
18241
|
-
reserveId: reserve.reserveId
|
|
18186
|
+
reserveId: reserve.reserveId,
|
|
18187
|
+
hub: reserveHub
|
|
18242
18188
|
}
|
|
18243
18189
|
},
|
|
18244
18190
|
collateralRiskBps,
|
|
18245
18191
|
riskPremiumThresholdBps
|
|
18246
18192
|
};
|
|
18247
18193
|
}
|
|
18248
|
-
if (Object.keys(data).length
|
|
18249
|
-
|
|
18250
|
-
|
|
18251
|
-
|
|
18252
|
-
|
|
18253
|
-
|
|
18254
|
-
|
|
18255
|
-
|
|
18256
|
-
|
|
18257
|
-
|
|
18258
|
-
}
|
|
18259
|
-
};
|
|
18260
|
-
}
|
|
18194
|
+
if (Object.keys(data).length === 0) return void 0;
|
|
18195
|
+
return {
|
|
18196
|
+
data,
|
|
18197
|
+
chainId,
|
|
18198
|
+
params: {
|
|
18199
|
+
spoke: spokeAddr,
|
|
18200
|
+
oracle: spokeData.oracle.toLowerCase(),
|
|
18201
|
+
label: spokeData.label
|
|
18202
|
+
}
|
|
18203
|
+
};
|
|
18261
18204
|
}
|
|
18262
|
-
return out;
|
|
18263
18205
|
}
|
|
18264
18206
|
|
|
18265
18207
|
// src/lending/public-data/aave-v4-type/publicCallParse.ts
|
|
18266
18208
|
function isValidAddress2(addr) {
|
|
18267
18209
|
return !!addr && addr !== "0x" && addr.length > 2;
|
|
18268
18210
|
}
|
|
18269
|
-
function getSpokeReserves2(reservesMap, spokeAddr) {
|
|
18270
|
-
return reservesMap[spokeAddr.toLowerCase()] ?? reservesMap[spokeAddr] ?? [];
|
|
18271
|
-
}
|
|
18272
18211
|
var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields, tokenList = {}) => {
|
|
18273
18212
|
const expectedCalls = getAaveV4ExpectedCallCount(chainId, lender);
|
|
18274
18213
|
const converter = (data) => {
|
|
18275
18214
|
if (data.length !== expectedCalls) return void 0;
|
|
18276
|
-
const
|
|
18277
|
-
|
|
18215
|
+
const parsed = parseAaveV4SpokeLenderKey(lender);
|
|
18216
|
+
if (!parsed) return void 0;
|
|
18217
|
+
const spokeEntry = aaveV4Spokes()?.[chainId]?.[parsed.spokeAddrLower];
|
|
18218
|
+
if (!spokeEntry) return void 0;
|
|
18219
|
+
const spokeAddr = spokeEntry.spoke.toLowerCase();
|
|
18220
|
+
const reserves = spokeEntry.reserves ?? [];
|
|
18221
|
+
const dynConfigCount = (spokeEntry.dynamicConfigKeyMax ?? 0) + 1;
|
|
18278
18222
|
let offset = 0;
|
|
18279
|
-
const
|
|
18280
|
-
for (const
|
|
18281
|
-
|
|
18282
|
-
const
|
|
18283
|
-
const
|
|
18284
|
-
const
|
|
18285
|
-
const
|
|
18286
|
-
|
|
18287
|
-
|
|
18288
|
-
|
|
18289
|
-
|
|
18290
|
-
const
|
|
18291
|
-
|
|
18292
|
-
|
|
18293
|
-
|
|
18294
|
-
|
|
18295
|
-
|
|
18296
|
-
|
|
18297
|
-
|
|
18298
|
-
|
|
18299
|
-
|
|
18300
|
-
dynamicConfigs[key] = {
|
|
18301
|
-
collateralFactor: Number(
|
|
18302
|
-
rawDynConfig?.collateralFactor ?? 0
|
|
18303
|
-
),
|
|
18304
|
-
maxLiquidationBonus: Number(
|
|
18305
|
-
rawDynConfig?.maxLiquidationBonus ?? 0
|
|
18306
|
-
),
|
|
18307
|
-
liquidationFee: Number(
|
|
18308
|
-
rawDynConfig?.liquidationFee ?? 0
|
|
18309
|
-
)
|
|
18310
|
-
};
|
|
18311
|
-
}
|
|
18312
|
-
}
|
|
18313
|
-
const reserve = {
|
|
18314
|
-
underlying: rawReserve?.underlying ?? "",
|
|
18315
|
-
hub: rawReserve?.hub ?? "",
|
|
18316
|
-
assetId: Number(rawReserve?.assetId ?? 0),
|
|
18317
|
-
decimals: Number(rawReserve?.decimals ?? 18),
|
|
18318
|
-
collateralRisk: Number(
|
|
18319
|
-
rawReserve?.collateralRisk ?? 0
|
|
18320
|
-
),
|
|
18321
|
-
flags: Number(rawReserve?.flags ?? 0),
|
|
18322
|
-
dynamicConfigKey: Number(
|
|
18323
|
-
rawReserve?.dynamicConfigKey ?? 0
|
|
18324
|
-
)
|
|
18325
|
-
};
|
|
18326
|
-
const config = {
|
|
18327
|
-
collateralRisk: Number(rawConfig?.collateralRisk ?? 0),
|
|
18328
|
-
paused: rawConfig?.paused ?? false,
|
|
18329
|
-
frozen: rawConfig?.frozen ?? false,
|
|
18330
|
-
borrowable: rawConfig?.borrowable ?? false,
|
|
18331
|
-
receiveSharesEnabled: rawConfig?.receiveSharesEnabled ?? false
|
|
18332
|
-
};
|
|
18333
|
-
let drawnDebt = 0n;
|
|
18334
|
-
let premiumDebt = 0n;
|
|
18335
|
-
if (Array.isArray(rawDebt)) {
|
|
18336
|
-
drawnDebt = BigInt(rawDebt[0] ?? 0);
|
|
18337
|
-
premiumDebt = BigInt(rawDebt[1] ?? 0);
|
|
18338
|
-
} else {
|
|
18339
|
-
drawnDebt = BigInt(rawDebt ?? 0);
|
|
18223
|
+
const parsedReserves = [];
|
|
18224
|
+
for (const r of reserves) {
|
|
18225
|
+
const reserveId = r.reserveId;
|
|
18226
|
+
const rawReserve = data[offset];
|
|
18227
|
+
const rawConfig = data[offset + 1];
|
|
18228
|
+
const rawSupplied = data[offset + 2];
|
|
18229
|
+
const rawDebt = data[offset + 3];
|
|
18230
|
+
const rawTotalDebt = data[offset + 4];
|
|
18231
|
+
offset += BASE_CALLS_PER_RESERVE;
|
|
18232
|
+
const dynamicConfigs = {};
|
|
18233
|
+
for (let key = 0; key < dynConfigCount; key++) {
|
|
18234
|
+
const rawDynConfig = data[offset];
|
|
18235
|
+
offset += 1;
|
|
18236
|
+
if (rawDynConfig && rawDynConfig !== "0x") {
|
|
18237
|
+
dynamicConfigs[key] = {
|
|
18238
|
+
collateralFactor: Number(rawDynConfig?.collateralFactor ?? 0),
|
|
18239
|
+
maxLiquidationBonus: Number(
|
|
18240
|
+
rawDynConfig?.maxLiquidationBonus ?? 0
|
|
18241
|
+
),
|
|
18242
|
+
liquidationFee: Number(rawDynConfig?.liquidationFee ?? 0)
|
|
18243
|
+
};
|
|
18340
18244
|
}
|
|
18341
|
-
parsedReserves.push({
|
|
18342
|
-
reserveId,
|
|
18343
|
-
reserve,
|
|
18344
|
-
config,
|
|
18345
|
-
dynamicConfigs,
|
|
18346
|
-
suppliedAssets: BigInt(rawSupplied ?? 0),
|
|
18347
|
-
drawnDebt,
|
|
18348
|
-
premiumDebt,
|
|
18349
|
-
totalDebt: BigInt(rawTotalDebt ?? 0),
|
|
18350
|
-
hubAsset: { drawnRate: 0n },
|
|
18351
|
-
price: 0n
|
|
18352
|
-
});
|
|
18353
18245
|
}
|
|
18354
|
-
const
|
|
18355
|
-
|
|
18356
|
-
const
|
|
18357
|
-
|
|
18358
|
-
|
|
18359
|
-
),
|
|
18360
|
-
|
|
18361
|
-
|
|
18362
|
-
),
|
|
18363
|
-
|
|
18364
|
-
rawLiqConfig?.liquidationBonusFactor ?? 0
|
|
18365
|
-
)
|
|
18246
|
+
const onChainHub = (rawReserve?.hub ?? "").toLowerCase();
|
|
18247
|
+
const reserveHub = isValidAddress2(onChainHub) ? onChainHub : (r.hub ?? "").toLowerCase();
|
|
18248
|
+
const reserve = {
|
|
18249
|
+
underlying: rawReserve?.underlying ?? r.underlying ?? "",
|
|
18250
|
+
hub: reserveHub,
|
|
18251
|
+
assetId: Number(rawReserve?.assetId ?? r.assetId ?? 0),
|
|
18252
|
+
decimals: Number(rawReserve?.decimals ?? 18),
|
|
18253
|
+
collateralRisk: Number(rawReserve?.collateralRisk ?? 0),
|
|
18254
|
+
flags: Number(rawReserve?.flags ?? 0),
|
|
18255
|
+
dynamicConfigKey: Number(rawReserve?.dynamicConfigKey ?? 0)
|
|
18366
18256
|
};
|
|
18367
|
-
|
|
18368
|
-
|
|
18369
|
-
|
|
18370
|
-
|
|
18371
|
-
|
|
18372
|
-
|
|
18373
|
-
|
|
18257
|
+
const config = {
|
|
18258
|
+
collateralRisk: Number(rawConfig?.collateralRisk ?? 0),
|
|
18259
|
+
paused: rawConfig?.paused ?? false,
|
|
18260
|
+
frozen: rawConfig?.frozen ?? false,
|
|
18261
|
+
borrowable: rawConfig?.borrowable ?? false,
|
|
18262
|
+
receiveSharesEnabled: rawConfig?.receiveSharesEnabled ?? false
|
|
18263
|
+
};
|
|
18264
|
+
let drawnDebt = 0n;
|
|
18265
|
+
let premiumDebt = 0n;
|
|
18266
|
+
if (Array.isArray(rawDebt)) {
|
|
18267
|
+
drawnDebt = BigInt(rawDebt[0] ?? 0);
|
|
18268
|
+
premiumDebt = BigInt(rawDebt[1] ?? 0);
|
|
18269
|
+
} else {
|
|
18270
|
+
drawnDebt = BigInt(rawDebt ?? 0);
|
|
18271
|
+
}
|
|
18272
|
+
parsedReserves.push({
|
|
18273
|
+
reserveId,
|
|
18274
|
+
reserve,
|
|
18275
|
+
config,
|
|
18276
|
+
dynamicConfigs,
|
|
18277
|
+
suppliedAssets: BigInt(rawSupplied ?? 0),
|
|
18278
|
+
drawnDebt,
|
|
18279
|
+
premiumDebt,
|
|
18280
|
+
totalDebt: BigInt(rawTotalDebt ?? 0),
|
|
18281
|
+
hubAsset: { drawnRate: 0n },
|
|
18282
|
+
price: 0n
|
|
18374
18283
|
});
|
|
18375
18284
|
}
|
|
18376
|
-
|
|
18377
|
-
|
|
18378
|
-
|
|
18379
|
-
|
|
18380
|
-
|
|
18381
|
-
|
|
18382
|
-
|
|
18383
|
-
|
|
18384
|
-
|
|
18385
|
-
|
|
18386
|
-
|
|
18387
|
-
|
|
18388
|
-
|
|
18389
|
-
|
|
18285
|
+
const rawLiqConfig = data[offset];
|
|
18286
|
+
offset += CALLS_PER_SPOKE_TAIL;
|
|
18287
|
+
const liquidationConfig = {
|
|
18288
|
+
targetHealthFactor: BigInt(rawLiqConfig?.targetHealthFactor ?? 0),
|
|
18289
|
+
healthFactorForMaxBonus: BigInt(
|
|
18290
|
+
rawLiqConfig?.healthFactorForMaxBonus ?? 0
|
|
18291
|
+
),
|
|
18292
|
+
liquidationBonusFactor: Number(
|
|
18293
|
+
rawLiqConfig?.liquidationBonusFactor ?? 0
|
|
18294
|
+
)
|
|
18295
|
+
};
|
|
18296
|
+
const spokeData = {
|
|
18297
|
+
spoke: spokeAddr,
|
|
18298
|
+
oracle: spokeEntry.oracle,
|
|
18299
|
+
label: spokeEntry.label,
|
|
18300
|
+
oracleDecimals: 8,
|
|
18301
|
+
liquidationConfig,
|
|
18302
|
+
reserves: parsedReserves
|
|
18303
|
+
};
|
|
18304
|
+
if (parsedReserves.length > 0 && isValidAddress2(spokeEntry.oracle)) {
|
|
18305
|
+
const rawPrices = data[offset];
|
|
18306
|
+
offset += 1;
|
|
18307
|
+
const priceArray = Array.isArray(rawPrices) ? rawPrices : [];
|
|
18308
|
+
for (let ri = 0; ri < parsedReserves.length; ri++) {
|
|
18309
|
+
if (ri < priceArray.length) {
|
|
18310
|
+
parsedReserves[ri].price = BigInt(priceArray[ri] ?? 0);
|
|
18390
18311
|
}
|
|
18391
18312
|
}
|
|
18392
18313
|
}
|
|
18393
|
-
const
|
|
18314
|
+
const distinctHubs = [];
|
|
18315
|
+
{
|
|
18316
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18317
|
+
for (const r of reserves) {
|
|
18318
|
+
const h = (r?.hub ?? "").toLowerCase();
|
|
18319
|
+
if (!h || !isValidAddress2(h)) continue;
|
|
18320
|
+
if (seen.has(h)) continue;
|
|
18321
|
+
seen.add(h);
|
|
18322
|
+
distinctHubs.push(h);
|
|
18323
|
+
}
|
|
18324
|
+
}
|
|
18394
18325
|
const hubAssetMap = /* @__PURE__ */ new Map();
|
|
18395
|
-
|
|
18326
|
+
for (const hub of distinctHubs) {
|
|
18396
18327
|
const rawAssetCount = data[offset];
|
|
18397
18328
|
offset += 1;
|
|
18398
18329
|
const assetCount = Math.min(
|
|
18399
18330
|
Number(rawAssetCount ?? 0),
|
|
18400
18331
|
MAX_HUB_ASSETS
|
|
18401
18332
|
);
|
|
18333
|
+
const inner = /* @__PURE__ */ new Map();
|
|
18334
|
+
hubAssetMap.set(hub, inner);
|
|
18402
18335
|
for (let i = 0; i < MAX_HUB_ASSETS; i++) {
|
|
18403
18336
|
const baseIdx = offset + i * 3;
|
|
18404
18337
|
const rawHubAsset = data[baseIdx];
|
|
@@ -18408,15 +18341,13 @@ var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields,
|
|
|
18408
18341
|
continue;
|
|
18409
18342
|
const underlying = (rawHubAsset?.underlying ?? "").toLowerCase();
|
|
18410
18343
|
if (!underlying) continue;
|
|
18411
|
-
|
|
18344
|
+
inner.set(underlying, {
|
|
18412
18345
|
liquidity: BigInt(rawHubAsset?.liquidity ?? 0),
|
|
18413
18346
|
realizedFees: BigInt(rawHubAsset?.realizedFees ?? 0),
|
|
18414
18347
|
decimals: Number(rawHubAsset?.decimals ?? 18),
|
|
18415
18348
|
addedShares: BigInt(rawHubAsset?.addedShares ?? 0),
|
|
18416
18349
|
swept: BigInt(rawHubAsset?.swept ?? 0),
|
|
18417
|
-
premiumOffsetRay: BigInt(
|
|
18418
|
-
rawHubAsset?.premiumOffsetRay ?? 0
|
|
18419
|
-
),
|
|
18350
|
+
premiumOffsetRay: BigInt(rawHubAsset?.premiumOffsetRay ?? 0),
|
|
18420
18351
|
drawnShares: BigInt(rawHubAsset?.drawnShares ?? 0),
|
|
18421
18352
|
premiumShares: BigInt(rawHubAsset?.premiumShares ?? 0),
|
|
18422
18353
|
liquidityFee: Number(rawHubAsset?.liquidityFee ?? 0),
|
|
@@ -18435,49 +18366,36 @@ var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields,
|
|
|
18435
18366
|
});
|
|
18436
18367
|
}
|
|
18437
18368
|
offset += MAX_HUB_ASSETS * 3;
|
|
18438
|
-
for (const
|
|
18439
|
-
|
|
18440
|
-
|
|
18441
|
-
|
|
18369
|
+
for (const r of reserves) {
|
|
18370
|
+
if ((r?.hub ?? "").toLowerCase() !== hub) continue;
|
|
18371
|
+
if (typeof r.assetId !== "number") continue;
|
|
18372
|
+
const rawBinding = data[offset];
|
|
18373
|
+
offset += 1;
|
|
18374
|
+
if (!rawBinding || rawBinding === "0x") continue;
|
|
18375
|
+
const binding = {
|
|
18376
|
+
riskPremiumThreshold: Number(
|
|
18377
|
+
rawBinding?.riskPremiumThreshold ?? 0
|
|
18378
|
+
),
|
|
18379
|
+
active: Boolean(rawBinding?.active ?? false),
|
|
18380
|
+
halted: Boolean(rawBinding?.halted ?? false),
|
|
18381
|
+
addCap: Number(rawBinding?.addCap ?? 0),
|
|
18382
|
+
drawCap: Number(rawBinding?.drawCap ?? 0)
|
|
18383
|
+
};
|
|
18384
|
+
const target = parsedReserves.find(
|
|
18385
|
+
(pr) => pr.reserveId === r.reserveId
|
|
18442
18386
|
);
|
|
18443
|
-
|
|
18444
|
-
const meta = spokeReservesMeta[ri];
|
|
18445
|
-
const assetId = typeof meta === "object" && meta != null ? meta.assetId : void 0;
|
|
18446
|
-
if (typeof assetId !== "number") continue;
|
|
18447
|
-
const rawBinding = data[offset];
|
|
18448
|
-
offset += 1;
|
|
18449
|
-
if (!rawBinding || rawBinding === "0x") continue;
|
|
18450
|
-
const binding = {
|
|
18451
|
-
riskPremiumThreshold: Number(
|
|
18452
|
-
rawBinding?.riskPremiumThreshold ?? 0
|
|
18453
|
-
),
|
|
18454
|
-
active: Boolean(rawBinding?.active ?? false),
|
|
18455
|
-
halted: Boolean(rawBinding?.halted ?? false),
|
|
18456
|
-
addCap: Number(rawBinding?.addCap ?? 0),
|
|
18457
|
-
drawCap: Number(rawBinding?.drawCap ?? 0)
|
|
18458
|
-
};
|
|
18459
|
-
const targetReserveId = typeof meta === "number" ? meta : meta.reserveId;
|
|
18460
|
-
const target = spokeData.reserves.find(
|
|
18461
|
-
(r) => r.reserveId === targetReserveId
|
|
18462
|
-
);
|
|
18463
|
-
if (target) target.spokeBinding = binding;
|
|
18464
|
-
}
|
|
18387
|
+
if (target) target.spokeBinding = binding;
|
|
18465
18388
|
}
|
|
18466
18389
|
}
|
|
18467
|
-
for (const
|
|
18468
|
-
|
|
18469
|
-
|
|
18470
|
-
|
|
18471
|
-
|
|
18472
|
-
|
|
18473
|
-
reserve.hubAsset = hubAsset;
|
|
18474
|
-
}
|
|
18475
|
-
}
|
|
18476
|
-
}
|
|
18390
|
+
for (const pr of parsedReserves) {
|
|
18391
|
+
const hub = pr.reserve.hub?.toLowerCase?.() ?? "";
|
|
18392
|
+
const underlying = pr.reserve.underlying?.toLowerCase?.() ?? "";
|
|
18393
|
+
if (!hub || !underlying) continue;
|
|
18394
|
+
const hubAsset = hubAssetMap.get(hub)?.get(underlying);
|
|
18395
|
+
if (hubAsset) pr.hubAsset = hubAsset;
|
|
18477
18396
|
}
|
|
18478
|
-
const expectedHub = hubEntry?.hub;
|
|
18479
18397
|
return normalizeAaveV4(
|
|
18480
|
-
|
|
18398
|
+
[spokeData],
|
|
18481
18399
|
chainId,
|
|
18482
18400
|
lender,
|
|
18483
18401
|
prices,
|
|
@@ -18486,8 +18404,7 @@ var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields,
|
|
|
18486
18404
|
lenderShortName,
|
|
18487
18405
|
createMarketUid,
|
|
18488
18406
|
toOracleKey,
|
|
18489
|
-
toGenericPriceKey
|
|
18490
|
-
expectedHub
|
|
18407
|
+
toGenericPriceKey
|
|
18491
18408
|
);
|
|
18492
18409
|
};
|
|
18493
18410
|
return [converter, expectedCalls];
|
|
@@ -19145,40 +19062,42 @@ var buildEulerUserCall = async (chainId, lender, account, subAccountIndexes) =>
|
|
|
19145
19062
|
|
|
19146
19063
|
// src/lending/user-data/aave-v4-type/userCallBuild.ts
|
|
19147
19064
|
var USER_CALLS_PER_RESERVE = 4;
|
|
19065
|
+
function resolveSpokeEntry2(chainId, lender) {
|
|
19066
|
+
const parsed = parseAaveV4SpokeLenderKey(lender);
|
|
19067
|
+
if (!parsed) return void 0;
|
|
19068
|
+
return aaveV4Spokes()?.[chainId]?.[parsed.spokeAddrLower];
|
|
19069
|
+
}
|
|
19148
19070
|
var buildAaveV4UserCall = (chainId, lender, account) => {
|
|
19149
|
-
const
|
|
19150
|
-
|
|
19151
|
-
|
|
19071
|
+
const spokeEntry = resolveSpokeEntry2(chainId, lender);
|
|
19072
|
+
if (!spokeEntry) return [];
|
|
19073
|
+
const spokeAddr = spokeEntry.spoke;
|
|
19074
|
+
if (!spokeAddr || spokeAddr === "0x" || spokeAddr.length <= 2) return [];
|
|
19075
|
+
const reserves = spokeEntry.reserves ?? [];
|
|
19152
19076
|
const calls = [];
|
|
19153
|
-
for (const
|
|
19154
|
-
const
|
|
19155
|
-
|
|
19156
|
-
|
|
19157
|
-
|
|
19158
|
-
|
|
19159
|
-
|
|
19160
|
-
|
|
19161
|
-
|
|
19162
|
-
|
|
19163
|
-
|
|
19164
|
-
|
|
19165
|
-
|
|
19166
|
-
|
|
19167
|
-
|
|
19168
|
-
|
|
19169
|
-
|
|
19170
|
-
|
|
19171
|
-
|
|
19172
|
-
|
|
19173
|
-
|
|
19174
|
-
|
|
19175
|
-
|
|
19176
|
-
|
|
19177
|
-
name: "getUserPosition",
|
|
19178
|
-
params: [rid, account]
|
|
19179
|
-
}
|
|
19180
|
-
);
|
|
19181
|
-
}
|
|
19077
|
+
for (const r of reserves) {
|
|
19078
|
+
const rid = r.reserveId;
|
|
19079
|
+
calls.push(
|
|
19080
|
+
{
|
|
19081
|
+
address: spokeAddr,
|
|
19082
|
+
name: "getUserSuppliedAssets",
|
|
19083
|
+
params: [rid, account]
|
|
19084
|
+
},
|
|
19085
|
+
{
|
|
19086
|
+
address: spokeAddr,
|
|
19087
|
+
name: "getUserDebt",
|
|
19088
|
+
params: [rid, account]
|
|
19089
|
+
},
|
|
19090
|
+
{
|
|
19091
|
+
address: spokeAddr,
|
|
19092
|
+
name: "getUserReserveStatus",
|
|
19093
|
+
params: [rid, account]
|
|
19094
|
+
},
|
|
19095
|
+
{
|
|
19096
|
+
address: spokeAddr,
|
|
19097
|
+
name: "getUserPosition",
|
|
19098
|
+
params: [rid, account]
|
|
19099
|
+
}
|
|
19100
|
+
);
|
|
19182
19101
|
}
|
|
19183
19102
|
return calls;
|
|
19184
19103
|
};
|
|
@@ -20582,61 +20501,30 @@ function createAaveV4UserState(payload, lenderData, totalDeposits24h = 0, totalD
|
|
|
20582
20501
|
}
|
|
20583
20502
|
|
|
20584
20503
|
// src/lending/user-data/aave-v4-type/userCallParse.ts
|
|
20585
|
-
var getAaveV4UserDataConverter = (lender, chainId, account,
|
|
20586
|
-
const
|
|
20587
|
-
const
|
|
20588
|
-
|
|
20589
|
-
|
|
20590
|
-
|
|
20591
|
-
|
|
20592
|
-
|
|
20593
|
-
|
|
20594
|
-
|
|
20595
|
-
|
|
20596
|
-
flatMeta[marketUid] = meta;
|
|
20597
|
-
}
|
|
20598
|
-
}
|
|
20599
|
-
}
|
|
20600
|
-
const oracleEntries = aaveV4Oracles()?.[lender]?.[chainId] ?? [];
|
|
20601
|
-
const spokeReserveToUnderlying = /* @__PURE__ */ new Map();
|
|
20602
|
-
for (const oe of oracleEntries) {
|
|
20603
|
-
if (oe.underlying && oe.spoke) {
|
|
20604
|
-
spokeReserveToUnderlying.set(
|
|
20605
|
-
`${oe.spoke.toLowerCase()}:${oe.reserveId}`,
|
|
20606
|
-
oe.underlying.toLowerCase()
|
|
20607
|
-
);
|
|
20608
|
-
}
|
|
20609
|
-
}
|
|
20610
|
-
const reserveEntries = [];
|
|
20611
|
-
for (const spokeEntry of spokes) {
|
|
20612
|
-
const spokeAddr = spokeEntry.spoke;
|
|
20613
|
-
if (!spokeAddr || spokeAddr === "0x" || spokeAddr.length <= 2) continue;
|
|
20614
|
-
const spokeAddrLc = spokeAddr.toLowerCase();
|
|
20615
|
-
const spokeLenderKey = aaveV4SpokeLenderKey(lender, spokeAddrLc);
|
|
20616
|
-
const reserves = reservesMap[spokeAddrLc] ?? reservesMap[spokeAddr] ?? [];
|
|
20617
|
-
for (const entry of reserves) {
|
|
20618
|
-
const rid = typeof entry === "number" ? entry : entry.reserveId;
|
|
20619
|
-
const underlying = ((typeof entry === "object" ? entry.underlying : void 0) ?? spokeReserveToUnderlying.get(`${spokeAddrLc}:${rid}`) ?? "").toLowerCase();
|
|
20620
|
-
reserveEntries.push({
|
|
20621
|
-
spokeAddr,
|
|
20622
|
-
spokeAddrLc,
|
|
20623
|
-
spokeLenderKey,
|
|
20624
|
-
reserveId: rid,
|
|
20625
|
-
underlying
|
|
20626
|
-
});
|
|
20627
|
-
}
|
|
20628
|
-
}
|
|
20629
|
-
const expectedNumberOfCalls = reserveEntries.length * USER_CALLS_PER_RESERVE;
|
|
20504
|
+
var getAaveV4UserDataConverter = (lender, chainId, account, meta) => {
|
|
20505
|
+
const parsed = parseAaveV4SpokeLenderKey(lender);
|
|
20506
|
+
const spokeEntry = parsed ? aaveV4Spokes()?.[chainId]?.[parsed.spokeAddrLower] : void 0;
|
|
20507
|
+
if (!spokeEntry) {
|
|
20508
|
+
return [() => void 0, 0];
|
|
20509
|
+
}
|
|
20510
|
+
const spokeAddr = spokeEntry.spoke;
|
|
20511
|
+
const spokeAddrLc = spokeAddr.toLowerCase();
|
|
20512
|
+
const reserves = spokeEntry.reserves ?? [];
|
|
20513
|
+
const flatMeta = meta ?? {};
|
|
20514
|
+
const expectedNumberOfCalls = reserves.length * USER_CALLS_PER_RESERVE;
|
|
20630
20515
|
return [
|
|
20631
20516
|
(data) => {
|
|
20632
20517
|
if (data.length !== expectedNumberOfCalls) {
|
|
20633
20518
|
return void 0;
|
|
20634
20519
|
}
|
|
20635
|
-
const
|
|
20636
|
-
|
|
20637
|
-
|
|
20520
|
+
const lendingPositions = {};
|
|
20521
|
+
let totalDeposits24h = 0;
|
|
20522
|
+
let totalDebt24h = 0;
|
|
20523
|
+
for (let i = 0; i < reserves.length; i++) {
|
|
20524
|
+
const r = reserves[i];
|
|
20525
|
+
const underlying = (r.underlying ?? "").toLowerCase();
|
|
20638
20526
|
if (!underlying) continue;
|
|
20639
|
-
const key = createMarketUid(chainId,
|
|
20527
|
+
const key = createMarketUid(chainId, lender, String(r.reserveId));
|
|
20640
20528
|
const metaEntity = flatMeta[key];
|
|
20641
20529
|
if (!metaEntity) continue;
|
|
20642
20530
|
const base = i * USER_CALLS_PER_RESERVE;
|
|
@@ -20653,30 +20541,21 @@ var getAaveV4UserDataConverter = (lender, chainId, account, metaMap) => {
|
|
|
20653
20541
|
);
|
|
20654
20542
|
if (!dataForAsset) continue;
|
|
20655
20543
|
dataForAsset.userConfigKey = String(userDynConfigKey);
|
|
20656
|
-
|
|
20657
|
-
|
|
20658
|
-
|
|
20659
|
-
totalDeposits24h: 0
|
|
20660
|
-
});
|
|
20661
|
-
bucket.totalDebt24h += addedDebt;
|
|
20662
|
-
bucket.totalDeposits24h += addedDeposits;
|
|
20663
|
-
bucket.lendingPositions[key] = dataForAsset;
|
|
20664
|
-
}
|
|
20665
|
-
const out = {};
|
|
20666
|
-
for (const [spokeLenderKey, bucket] of Object.entries(perSpoke)) {
|
|
20667
|
-
const payload = {
|
|
20668
|
-
chainId,
|
|
20669
|
-
account,
|
|
20670
|
-
lendingPositions: bucket.lendingPositions,
|
|
20671
|
-
rewards: []};
|
|
20672
|
-
out[spokeLenderKey] = createAaveV4UserState(
|
|
20673
|
-
payload,
|
|
20674
|
-
flatMeta,
|
|
20675
|
-
bucket.totalDeposits24h,
|
|
20676
|
-
bucket.totalDebt24h
|
|
20677
|
-
);
|
|
20544
|
+
totalDebt24h += addedDebt;
|
|
20545
|
+
totalDeposits24h += addedDeposits;
|
|
20546
|
+
lendingPositions[key] = dataForAsset;
|
|
20678
20547
|
}
|
|
20679
|
-
|
|
20548
|
+
const payload = {
|
|
20549
|
+
chainId,
|
|
20550
|
+
account,
|
|
20551
|
+
lendingPositions,
|
|
20552
|
+
rewards: []};
|
|
20553
|
+
return createAaveV4UserState(
|
|
20554
|
+
payload,
|
|
20555
|
+
flatMeta,
|
|
20556
|
+
totalDeposits24h,
|
|
20557
|
+
totalDebt24h
|
|
20558
|
+
);
|
|
20680
20559
|
},
|
|
20681
20560
|
expectedNumberOfCalls
|
|
20682
20561
|
];
|
|
@@ -20738,7 +20617,12 @@ function createAaveV4Entry(base, data, key, meta, spokeAddr) {
|
|
|
20738
20617
|
// src/lending/user-data/fetch-balances/parse.ts
|
|
20739
20618
|
function getUserDataConverter(lender, chainId, account, params, meta) {
|
|
20740
20619
|
if (isAaveV4Type(lender))
|
|
20741
|
-
return getAaveV4UserDataConverter(
|
|
20620
|
+
return getAaveV4UserDataConverter(
|
|
20621
|
+
lender,
|
|
20622
|
+
chainId,
|
|
20623
|
+
account,
|
|
20624
|
+
meta?.[lender]
|
|
20625
|
+
);
|
|
20742
20626
|
if (isYLDR(lender))
|
|
20743
20627
|
return getYldrUserDataConverter(lender, chainId, account, meta?.[lender]);
|
|
20744
20628
|
if (isAaveV2Type(lender))
|
|
@@ -32265,49 +32149,33 @@ var eulerV2Fetcher = {
|
|
|
32265
32149
|
getAbi: getEulerV2Abi
|
|
32266
32150
|
};
|
|
32267
32151
|
function getAaveV4OracleGroups(chainId) {
|
|
32268
|
-
const
|
|
32269
|
-
const
|
|
32270
|
-
const
|
|
32271
|
-
|
|
32272
|
-
|
|
32273
|
-
|
|
32274
|
-
|
|
32275
|
-
|
|
32276
|
-
|
|
32277
|
-
|
|
32278
|
-
const byOracle = /* @__PURE__ */ new Map();
|
|
32279
|
-
for (const entry of oracleEntries) {
|
|
32280
|
-
if (!entry.oracle || entry.oracle === "0x") continue;
|
|
32281
|
-
const key = entry.oracle.toLowerCase();
|
|
32282
|
-
let group = byOracle.get(key);
|
|
32283
|
-
if (!group) {
|
|
32284
|
-
group = { decimals: entry.decimals ?? 8, entries: [] };
|
|
32285
|
-
byOracle.set(key, group);
|
|
32286
|
-
}
|
|
32287
|
-
const spokeLc = entry.spoke.toLowerCase();
|
|
32288
|
-
const hub = spokeToHub.get(spokeLc) ?? "";
|
|
32289
|
-
group.entries.push({
|
|
32290
|
-
underlying: entry.underlying.toLowerCase(),
|
|
32291
|
-
hub,
|
|
32292
|
-
reserveId: entry.reserveId,
|
|
32293
|
-
spoke: spokeLc
|
|
32294
|
-
});
|
|
32295
|
-
}
|
|
32296
|
-
for (const [oracle, group] of byOracle) {
|
|
32297
|
-
groups.push({
|
|
32298
|
-
fork,
|
|
32299
|
-
oracle,
|
|
32300
|
-
decimals: group.decimals,
|
|
32301
|
-
entries: group.entries
|
|
32302
|
-
});
|
|
32152
|
+
const oracleEntries = aaveV4Oracles()?.[chainId] ?? [];
|
|
32153
|
+
const byOracle = /* @__PURE__ */ new Map();
|
|
32154
|
+
for (const entry of oracleEntries) {
|
|
32155
|
+
if (!entry?.oracle || entry.oracle === "0x") continue;
|
|
32156
|
+
if (!entry.spoke) continue;
|
|
32157
|
+
const key = entry.oracle.toLowerCase();
|
|
32158
|
+
let group = byOracle.get(key);
|
|
32159
|
+
if (!group) {
|
|
32160
|
+
group = { decimals: entry.decimals ?? 8, entries: [] };
|
|
32161
|
+
byOracle.set(key, group);
|
|
32303
32162
|
}
|
|
32163
|
+
group.entries.push({
|
|
32164
|
+
underlying: entry.underlying.toLowerCase(),
|
|
32165
|
+
reserveId: entry.reserveId,
|
|
32166
|
+
spoke: entry.spoke.toLowerCase()
|
|
32167
|
+
});
|
|
32168
|
+
}
|
|
32169
|
+
const groups = [];
|
|
32170
|
+
for (const [oracle, group] of byOracle) {
|
|
32171
|
+
groups.push({ oracle, decimals: group.decimals, entries: group.entries });
|
|
32304
32172
|
}
|
|
32305
32173
|
return groups;
|
|
32306
32174
|
}
|
|
32307
32175
|
function getAaveV4Calls(chainId) {
|
|
32308
32176
|
const groups = getAaveV4OracleGroups(chainId);
|
|
32309
32177
|
const results = [];
|
|
32310
|
-
for (const {
|
|
32178
|
+
for (const { oracle, decimals, entries } of groups) {
|
|
32311
32179
|
const calls = entries.map((e) => ({
|
|
32312
32180
|
address: oracle,
|
|
32313
32181
|
name: "getReservePrice",
|
|
@@ -32318,10 +32186,9 @@ function getAaveV4Calls(chainId) {
|
|
|
32318
32186
|
meta: {
|
|
32319
32187
|
oracle,
|
|
32320
32188
|
oracleDecimals: decimals,
|
|
32321
|
-
entries
|
|
32322
|
-
fork
|
|
32189
|
+
entries
|
|
32323
32190
|
},
|
|
32324
|
-
lender:
|
|
32191
|
+
lender: "AAVE_V4"
|
|
32325
32192
|
});
|
|
32326
32193
|
}
|
|
32327
32194
|
return results;
|
|
@@ -32338,12 +32205,16 @@ function parseAaveV4Results(data, meta, context) {
|
|
|
32338
32205
|
try {
|
|
32339
32206
|
const priceNum = Number(BigInt(rawPrice.toString())) / divisor;
|
|
32340
32207
|
if (isNaN(priceNum) || priceNum === 0) continue;
|
|
32341
|
-
const spokeLenderKey = aaveV4SpokeLenderKey(
|
|
32208
|
+
const spokeLenderKey = aaveV4SpokeLenderKey(entry.spoke);
|
|
32342
32209
|
entries.push({
|
|
32343
32210
|
asset: entry.underlying,
|
|
32344
32211
|
price: priceNum,
|
|
32345
32212
|
priceUSD: priceNum,
|
|
32346
|
-
marketUid: createMarketUid(
|
|
32213
|
+
marketUid: createMarketUid(
|
|
32214
|
+
chainId,
|
|
32215
|
+
spokeLenderKey,
|
|
32216
|
+
String(entry.reserveId)
|
|
32217
|
+
),
|
|
32347
32218
|
// Route into the per-spoke lender bucket so price entries live under
|
|
32348
32219
|
// the same lender key as the lending data (mirrors Morpho's pattern).
|
|
32349
32220
|
targetLender: spokeLenderKey,
|