@1delta/margin-fetcher 0.0.245 → 0.0.247
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 +248 -189
- package/dist/index.js.map +1 -1
- package/dist/lending/public-data/gearbox/publicCallBuild.d.ts +18 -8
- package/dist/lending/public-data/gearbox/publicCallBuild.d.ts.map +1 -1
- package/dist/lending/public-data/gearbox/publicCallParse.d.ts +20 -12
- package/dist/lending/public-data/gearbox/publicCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/gearbox/userCallBuild.d.ts +12 -9
- package/dist/lending/user-data/gearbox/userCallBuild.d.ts.map +1 -1
- package/dist/lending/user-data/gearbox/userCallParse.d.ts +18 -14
- package/dist/lending/user-data/gearbox/userCallParse.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/gearbox.d.ts +510 -514
- package/dist/prices/oracle-prices/fetchers/gearbox.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/morpho.d.ts.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/vaults/gearbox/publicCallBuild.d.ts +10 -5
- package/dist/vaults/gearbox/publicCallBuild.d.ts.map +1 -1
- package/dist/vaults/gearbox/publicCallParse.d.ts +13 -3
- package/dist/vaults/gearbox/publicCallParse.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Lender, isAaveType, isCompoundV3, isMultiMarket, isSiloV2Type, isSiloV3
|
|
|
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, getEvmClient, getEvmClientUniversal, multicallRetryUniversal } from '@1delta/providers';
|
|
8
|
-
import { FluidLendingResolverAbi, MorphoLensAbi, AaveV4SpokeAbi, AaveV4OracleAbi, AaveV4HubAbi, FluidVaultResolverAbi,
|
|
8
|
+
import { FluidLendingResolverAbi, MorphoLensAbi, AaveV4SpokeAbi, AaveV4OracleAbi, AaveV4HubAbi, FluidVaultResolverAbi, GearboxMarketCompressorV310Abi, MorphoBlueAbi, GearboxCreditAccountCompressorV310Abi } from '@1delta/abis';
|
|
9
9
|
export { MorphoLensAbi } from '@1delta/abis';
|
|
10
10
|
import { prepareDebitDataMulticall, prepareLenderDebitMulticall, parseDebitDataResult, parseLenderDebitResult, getPermit2ContractAddress, getCompoundV3CometAddress as getCompoundV3CometAddress$1, getMorphoAddress, getAaveCollateralTokenAddress, getSiloHalfForUnderlying, InitMarginAddresses } from '@1delta/calldata-sdk';
|
|
11
11
|
import { BALANCER_V2_FORKS, BALANCER_V3_FORKS, UNISWAP_V4_FORKS, isFlashLoanSourceExcluded, FLASH_LOAN_IDS } from '@1delta/dex-registry';
|
|
@@ -6284,7 +6284,11 @@ globalThis[GLOBAL_LENDER_DATA_KEY] = {
|
|
|
6284
6284
|
siloPeripheralsV3: {},
|
|
6285
6285
|
fluidResolvers: {},
|
|
6286
6286
|
fluidVaults: {},
|
|
6287
|
-
gearboxResolvers: {
|
|
6287
|
+
gearboxResolvers: {
|
|
6288
|
+
addressProviderV310: "",
|
|
6289
|
+
marketCompressorV310: "",
|
|
6290
|
+
chains: {}
|
|
6291
|
+
}
|
|
6288
6292
|
};
|
|
6289
6293
|
function getGlobalData2() {
|
|
6290
6294
|
return globalThis[GLOBAL_LENDER_DATA_KEY];
|
|
@@ -6314,6 +6318,10 @@ var siloMarkets = () => getGlobalData2()?.siloMarkets;
|
|
|
6314
6318
|
var siloMarketsV3 = () => getGlobalData2()?.siloMarketsV3;
|
|
6315
6319
|
var fluidResolvers = () => getGlobalData2()?.fluidResolvers;
|
|
6316
6320
|
var gearboxResolvers = () => getGlobalData2()?.gearboxResolvers;
|
|
6321
|
+
var gearboxMarketCompressor = () => getGlobalData2()?.gearboxResolvers?.marketCompressorV310 || void 0;
|
|
6322
|
+
var GEARBOX_ACCOUNT_COMPRESSOR_V310 = "0x4115708Fc8fe6bB392De2e0C21c2C81dA2222394";
|
|
6323
|
+
var gearboxAccountCompressor = () => GEARBOX_ACCOUNT_COMPRESSOR_V310;
|
|
6324
|
+
var gearboxMarketConfigurators = (chainId) => getGlobalData2()?.gearboxResolvers?.chains?.[chainId]?.marketConfigurators;
|
|
6317
6325
|
function aaveV4SpokeLenderKey(spoke) {
|
|
6318
6326
|
if (!spoke || !spoke.startsWith("0x") || spoke.length !== 42) {
|
|
6319
6327
|
throw new Error(`aaveV4SpokeLenderKey: invalid spoke address ${spoke}`);
|
|
@@ -7622,7 +7630,7 @@ var getLendersForChain = (c) => {
|
|
|
7622
7630
|
if (fluidResolvers()?.[c]) {
|
|
7623
7631
|
lenders.push(Lender.FLUID);
|
|
7624
7632
|
}
|
|
7625
|
-
if (gearboxResolvers()?.[c]) {
|
|
7633
|
+
if (gearboxResolvers()?.chains?.[c]?.marketConfigurators) {
|
|
7626
7634
|
lenders.push(Lender.GEARBOX_V3);
|
|
7627
7635
|
}
|
|
7628
7636
|
return lenders;
|
|
@@ -19373,18 +19381,22 @@ function parseVault(vault, chainId, prices, additionalYields, tokenList) {
|
|
|
19373
19381
|
|
|
19374
19382
|
// src/lending/public-data/gearbox/publicCallBuild.ts
|
|
19375
19383
|
var buildGearboxCall = (chainId, _lender) => {
|
|
19376
|
-
const
|
|
19377
|
-
|
|
19384
|
+
const compressor = gearboxMarketCompressor();
|
|
19385
|
+
const configurators = gearboxMarketConfigurators(chainId);
|
|
19386
|
+
if (!compressor || !configurators) return [];
|
|
19387
|
+
const curatorAddrs = Object.keys(configurators);
|
|
19388
|
+
if (curatorAddrs.length === 0) return [];
|
|
19378
19389
|
return [
|
|
19379
19390
|
{
|
|
19380
|
-
address:
|
|
19381
|
-
name: "
|
|
19382
|
-
params: [
|
|
19383
|
-
|
|
19384
|
-
|
|
19385
|
-
|
|
19386
|
-
|
|
19387
|
-
|
|
19391
|
+
address: compressor,
|
|
19392
|
+
name: "getMarkets",
|
|
19393
|
+
params: [
|
|
19394
|
+
{
|
|
19395
|
+
configurators: curatorAddrs,
|
|
19396
|
+
pools: [],
|
|
19397
|
+
underlying: zeroAddress
|
|
19398
|
+
}
|
|
19399
|
+
]
|
|
19388
19400
|
}
|
|
19389
19401
|
];
|
|
19390
19402
|
};
|
|
@@ -19396,171 +19408,200 @@ var scaleGearboxRate = (raw) => {
|
|
|
19396
19408
|
return Number(raw) / RAY_TO_PERCENT;
|
|
19397
19409
|
};
|
|
19398
19410
|
var getGearboxV3PublicDataConverter = (_lender, chainId, prices, additionalYields, tokenList = {}) => {
|
|
19399
|
-
const expectedNumberOfCalls =
|
|
19411
|
+
const expectedNumberOfCalls = 1;
|
|
19400
19412
|
return [
|
|
19401
19413
|
(data) => {
|
|
19402
19414
|
if (data.length !== expectedNumberOfCalls) return void 0;
|
|
19403
|
-
const [
|
|
19415
|
+
const [markets] = data;
|
|
19416
|
+
if (!Array.isArray(markets)) return void 0;
|
|
19404
19417
|
const out = {};
|
|
19405
|
-
const
|
|
19406
|
-
for (const
|
|
19407
|
-
const
|
|
19408
|
-
if (!addr) continue;
|
|
19409
|
-
poolByAddr[addr] = pool;
|
|
19410
|
-
}
|
|
19411
|
-
for (const cm of cmsData ?? []) {
|
|
19412
|
-
const cmAddr = (cm.addr ?? "").toString().toLowerCase();
|
|
19413
|
-
if (!cmAddr) continue;
|
|
19414
|
-
const poolAddr = (cm.pool ?? "").toString().toLowerCase();
|
|
19415
|
-
const pool = poolByAddr[poolAddr];
|
|
19418
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
19419
|
+
for (const m of markets) {
|
|
19420
|
+
const pool = m?.pool;
|
|
19416
19421
|
if (!pool) continue;
|
|
19417
19422
|
if (pool.isPaused) continue;
|
|
19418
|
-
const
|
|
19419
|
-
|
|
19420
|
-
|
|
19423
|
+
const poolAddr = (pool.baseParams?.addr ?? "").toString().toLowerCase();
|
|
19424
|
+
const rawUnderlying = (pool.underlying ?? "").toString().toLowerCase();
|
|
19425
|
+
if (!poolAddr || !rawUnderlying) continue;
|
|
19426
|
+
const underlying = rawUnderlying;
|
|
19421
19427
|
const underlyingMeta = tokenList[underlying];
|
|
19422
|
-
const underlyingDecimals = Number(
|
|
19423
|
-
|
|
19424
|
-
const borrowRate = scaleGearboxRate(
|
|
19425
|
-
cm.baseBorrowRate ?? pool.baseInterestRate
|
|
19428
|
+
const underlyingDecimals = Number(
|
|
19429
|
+
underlyingMeta?.decimals ?? pool.decimals ?? 18
|
|
19426
19430
|
);
|
|
19431
|
+
const supplyRate = scaleGearboxRate(pool.supplyRate);
|
|
19427
19432
|
const underlyingPriceKey = toOracleKey(underlyingMeta?.assetGroup) ?? toGenericPriceKey(underlying, chainId);
|
|
19428
19433
|
const underlyingPrice = prices[underlyingPriceKey] ?? 0;
|
|
19429
|
-
|
|
19430
|
-
|
|
19431
|
-
|
|
19432
|
-
|
|
19433
|
-
|
|
19434
|
+
const debtByCm = {};
|
|
19435
|
+
for (const dp of pool.creditManagerDebtParams ?? []) {
|
|
19436
|
+
const addr = (dp?.creditManager ?? "").toString().toLowerCase();
|
|
19437
|
+
if (!addr) continue;
|
|
19438
|
+
debtByCm[addr] = {
|
|
19439
|
+
borrowed: BigInt(dp.borrowed ?? 0),
|
|
19440
|
+
limit: BigInt(dp.limit ?? 0),
|
|
19441
|
+
available: BigInt(dp.available ?? 0)
|
|
19442
|
+
};
|
|
19434
19443
|
}
|
|
19435
|
-
const
|
|
19444
|
+
const poolExpectedLiquidity = Number(
|
|
19436
19445
|
parseRawAmount(
|
|
19437
|
-
|
|
19446
|
+
pool.expectedLiquidity?.toString(),
|
|
19438
19447
|
underlyingDecimals
|
|
19439
19448
|
)
|
|
19440
19449
|
);
|
|
19441
|
-
const
|
|
19442
|
-
parseRawAmount(
|
|
19450
|
+
const poolTotalBorrowed = Number(
|
|
19451
|
+
parseRawAmount(pool.totalBorrowed?.toString(), underlyingDecimals)
|
|
19443
19452
|
);
|
|
19444
|
-
const
|
|
19445
|
-
const
|
|
19446
|
-
|
|
19447
|
-
|
|
19448
|
-
|
|
19449
|
-
|
|
19450
|
-
|
|
19451
|
-
|
|
19452
|
-
|
|
19453
|
-
|
|
19454
|
-
|
|
19455
|
-
|
|
19456
|
-
|
|
19457
|
-
|
|
19458
|
-
|
|
19459
|
-
|
|
19460
|
-
|
|
19461
|
-
|
|
19462
|
-
|
|
19463
|
-
|
|
19464
|
-
|
|
19465
|
-
|
|
19466
|
-
|
|
19467
|
-
|
|
19468
|
-
|
|
19469
|
-
|
|
19470
|
-
|
|
19471
|
-
|
|
19472
|
-
|
|
19473
|
-
|
|
19474
|
-
|
|
19475
|
-
|
|
19476
|
-
|
|
19477
|
-
|
|
19478
|
-
|
|
19479
|
-
|
|
19480
|
-
|
|
19481
|
-
|
|
19482
|
-
|
|
19483
|
-
|
|
19484
|
-
isActive: true,
|
|
19485
|
-
isFrozen: false
|
|
19486
|
-
};
|
|
19487
|
-
const collateralTokens = Array.isArray(cm.collateralTokens) ? cm.collateralTokens : [];
|
|
19488
|
-
const liquidationThresholds = Array.isArray(
|
|
19489
|
-
cm.liquidationThresholds
|
|
19490
|
-
) ? cm.liquidationThresholds : [];
|
|
19491
|
-
for (let i = 0; i < collateralTokens.length; i++) {
|
|
19492
|
-
const rawToken = (collateralTokens[i] ?? "").toString().toLowerCase();
|
|
19493
|
-
if (!rawToken) continue;
|
|
19494
|
-
const token = rawToken;
|
|
19495
|
-
const ltRaw = Number(liquidationThresholds[i] ?? 0);
|
|
19496
|
-
const lt = ltRaw / BPS;
|
|
19497
|
-
if (lt <= 0) continue;
|
|
19498
|
-
const ctMeta = tokenList[token];
|
|
19499
|
-
const ctDecimals = Number(ctMeta?.decimals ?? 18);
|
|
19500
|
-
const ctPriceKey = toOracleKey(ctMeta?.assetGroup) ?? toGenericPriceKey(token, chainId);
|
|
19501
|
-
const colMarketUid = createMarketUid(chainId, lender, token);
|
|
19502
|
-
if (colMarketUid === loanMarketUid) continue;
|
|
19503
|
-
data2[colMarketUid] = {
|
|
19504
|
-
marketUid: colMarketUid,
|
|
19505
|
-
name: "Collateral " + (ctMeta?.symbol ?? ""),
|
|
19506
|
-
poolId: token,
|
|
19507
|
-
underlying: token,
|
|
19508
|
-
asset: ctMeta,
|
|
19509
|
-
totalDeposits: 0,
|
|
19453
|
+
const poolUtilization = poolExpectedLiquidity > 0 ? poolTotalBorrowed / poolExpectedLiquidity : 0;
|
|
19454
|
+
for (const cm of m.creditManagers ?? []) {
|
|
19455
|
+
const facade = cm?.creditFacade;
|
|
19456
|
+
const manager = cm?.creditManager;
|
|
19457
|
+
if (!facade || !manager) continue;
|
|
19458
|
+
const expDate = Number(facade.expirationDate ?? 0);
|
|
19459
|
+
const isExpired = !!facade.expirable && expDate > 0 && expDate <= now;
|
|
19460
|
+
if (facade.isPaused || isExpired) continue;
|
|
19461
|
+
const degenNFT = (facade.degenNFT ?? zeroAddress).toString().toLowerCase();
|
|
19462
|
+
if (degenNFT !== zeroAddress.toLowerCase()) continue;
|
|
19463
|
+
const cmAddr = (manager.baseParams?.addr ?? "").toString().toLowerCase();
|
|
19464
|
+
const facadeAddr = (facade.baseParams?.addr ?? "").toString().toLowerCase();
|
|
19465
|
+
if (!cmAddr || !facadeAddr) continue;
|
|
19466
|
+
let lender;
|
|
19467
|
+
try {
|
|
19468
|
+
lender = gearboxV3LenderKey(cmAddr);
|
|
19469
|
+
} catch {
|
|
19470
|
+
continue;
|
|
19471
|
+
}
|
|
19472
|
+
const cmDebt = debtByCm[cmAddr] ?? {
|
|
19473
|
+
borrowed: 0n,
|
|
19474
|
+
available: 0n
|
|
19475
|
+
};
|
|
19476
|
+
const availableToBorrow = Number(
|
|
19477
|
+
parseRawAmount(cmDebt.available.toString(), underlyingDecimals)
|
|
19478
|
+
);
|
|
19479
|
+
const totalDebtCm = Number(
|
|
19480
|
+
parseRawAmount(cmDebt.borrowed.toString(), underlyingDecimals)
|
|
19481
|
+
);
|
|
19482
|
+
const totalDepositsCm = availableToBorrow + totalDebtCm;
|
|
19483
|
+
const borrowRate = scaleGearboxRate(pool.baseInterestRate);
|
|
19484
|
+
const data2 = {};
|
|
19485
|
+
const loanMarketUid = createMarketUid(chainId, lender, underlying);
|
|
19486
|
+
data2[loanMarketUid] = {
|
|
19487
|
+
marketUid: loanMarketUid,
|
|
19488
|
+
name: "Loan " + (underlyingMeta?.symbol ?? pool.symbol ?? ""),
|
|
19489
|
+
poolId: underlying,
|
|
19490
|
+
underlying,
|
|
19491
|
+
asset: underlyingMeta,
|
|
19492
|
+
totalDeposits: totalDepositsCm,
|
|
19510
19493
|
totalDebtStable: 0,
|
|
19511
|
-
totalDebt:
|
|
19512
|
-
totalLiquidity:
|
|
19513
|
-
borrowLiquidity:
|
|
19514
|
-
totalDepositsUSD:
|
|
19494
|
+
totalDebt: totalDebtCm,
|
|
19495
|
+
totalLiquidity: availableToBorrow,
|
|
19496
|
+
borrowLiquidity: availableToBorrow,
|
|
19497
|
+
totalDepositsUSD: totalDepositsCm * underlyingPrice,
|
|
19515
19498
|
totalDebtStableUSD: 0,
|
|
19516
|
-
totalDebtUSD:
|
|
19517
|
-
totalLiquidityUSD:
|
|
19518
|
-
borrowLiquidityUSD:
|
|
19519
|
-
utilization:
|
|
19520
|
-
depositRate:
|
|
19521
|
-
variableBorrowRate:
|
|
19499
|
+
totalDebtUSD: totalDebtCm * underlyingPrice,
|
|
19500
|
+
totalLiquidityUSD: availableToBorrow * underlyingPrice,
|
|
19501
|
+
borrowLiquidityUSD: availableToBorrow * underlyingPrice,
|
|
19502
|
+
utilization: poolUtilization,
|
|
19503
|
+
depositRate: supplyRate,
|
|
19504
|
+
variableBorrowRate: borrowRate,
|
|
19522
19505
|
stableBorrowRate: 0,
|
|
19523
|
-
intrinsicYield: additionalYields?.intrinsicYields?.[
|
|
19506
|
+
intrinsicYield: additionalYields?.intrinsicYields?.[underlyingPriceKey] ?? 0,
|
|
19524
19507
|
rewards: [],
|
|
19525
|
-
decimals:
|
|
19508
|
+
decimals: underlyingDecimals,
|
|
19526
19509
|
config: {
|
|
19527
19510
|
"0": {
|
|
19528
19511
|
category: 0,
|
|
19529
|
-
borrowCollateralFactor:
|
|
19530
|
-
collateralFactor:
|
|
19512
|
+
borrowCollateralFactor: 0,
|
|
19513
|
+
collateralFactor: 0,
|
|
19531
19514
|
borrowFactor: 1,
|
|
19532
|
-
collateralDisabled:
|
|
19533
|
-
debtDisabled:
|
|
19515
|
+
collateralDisabled: true,
|
|
19516
|
+
debtDisabled: false
|
|
19534
19517
|
}
|
|
19535
19518
|
},
|
|
19536
19519
|
liquidationBonus: 0,
|
|
19537
|
-
collateralActive:
|
|
19538
|
-
borrowingEnabled:
|
|
19520
|
+
collateralActive: false,
|
|
19521
|
+
borrowingEnabled: true,
|
|
19539
19522
|
depositsEnabled: false,
|
|
19540
19523
|
hasStable: false,
|
|
19541
19524
|
isActive: true,
|
|
19542
19525
|
isFrozen: false
|
|
19543
19526
|
};
|
|
19527
|
+
const collateralTokens = Array.isArray(
|
|
19528
|
+
manager.collateralTokens
|
|
19529
|
+
) ? manager.collateralTokens : [];
|
|
19530
|
+
for (const ct of collateralTokens) {
|
|
19531
|
+
const rawToken = (ct?.token ?? "").toString().toLowerCase();
|
|
19532
|
+
if (!rawToken) continue;
|
|
19533
|
+
const token = rawToken;
|
|
19534
|
+
const ltRaw = Number(ct?.liquidationThreshold ?? 0);
|
|
19535
|
+
const lt = ltRaw / BPS;
|
|
19536
|
+
if (lt <= 0) continue;
|
|
19537
|
+
const ctMeta = tokenList[token];
|
|
19538
|
+
const ctDecimals = Number(ctMeta?.decimals ?? 18);
|
|
19539
|
+
const ctPriceKey = toOracleKey(ctMeta?.assetGroup) ?? toGenericPriceKey(token, chainId);
|
|
19540
|
+
const colMarketUid = createMarketUid(chainId, lender, token);
|
|
19541
|
+
if (colMarketUid === loanMarketUid) continue;
|
|
19542
|
+
data2[colMarketUid] = {
|
|
19543
|
+
marketUid: colMarketUid,
|
|
19544
|
+
name: "Collateral " + (ctMeta?.symbol ?? ""),
|
|
19545
|
+
poolId: token,
|
|
19546
|
+
underlying: token,
|
|
19547
|
+
asset: ctMeta,
|
|
19548
|
+
totalDeposits: 0,
|
|
19549
|
+
totalDebtStable: 0,
|
|
19550
|
+
totalDebt: 0,
|
|
19551
|
+
totalLiquidity: 0,
|
|
19552
|
+
borrowLiquidity: 0,
|
|
19553
|
+
totalDepositsUSD: 0,
|
|
19554
|
+
totalDebtStableUSD: 0,
|
|
19555
|
+
totalDebtUSD: 0,
|
|
19556
|
+
totalLiquidityUSD: 0,
|
|
19557
|
+
borrowLiquidityUSD: 0,
|
|
19558
|
+
utilization: 0,
|
|
19559
|
+
depositRate: 0,
|
|
19560
|
+
variableBorrowRate: 0,
|
|
19561
|
+
stableBorrowRate: 0,
|
|
19562
|
+
intrinsicYield: additionalYields?.intrinsicYields?.[ctPriceKey] ?? 0,
|
|
19563
|
+
rewards: [],
|
|
19564
|
+
decimals: ctDecimals,
|
|
19565
|
+
config: {
|
|
19566
|
+
"0": {
|
|
19567
|
+
category: 0,
|
|
19568
|
+
borrowCollateralFactor: lt,
|
|
19569
|
+
collateralFactor: lt,
|
|
19570
|
+
borrowFactor: 1,
|
|
19571
|
+
collateralDisabled: false,
|
|
19572
|
+
debtDisabled: true
|
|
19573
|
+
}
|
|
19574
|
+
},
|
|
19575
|
+
liquidationBonus: 0,
|
|
19576
|
+
collateralActive: true,
|
|
19577
|
+
borrowingEnabled: false,
|
|
19578
|
+
depositsEnabled: false,
|
|
19579
|
+
hasStable: false,
|
|
19580
|
+
isActive: true,
|
|
19581
|
+
isFrozen: false
|
|
19582
|
+
};
|
|
19583
|
+
}
|
|
19584
|
+
out[lender] = {
|
|
19585
|
+
data: data2,
|
|
19586
|
+
params: {
|
|
19587
|
+
creditManager: {
|
|
19588
|
+
lender,
|
|
19589
|
+
creditManager: cmAddr,
|
|
19590
|
+
creditFacade: facadeAddr,
|
|
19591
|
+
pool: poolAddr,
|
|
19592
|
+
underlying,
|
|
19593
|
+
underlyingDecimals,
|
|
19594
|
+
minDebt: facade.minDebt?.toString() ?? "0",
|
|
19595
|
+
maxDebt: facade.maxDebt?.toString() ?? "0",
|
|
19596
|
+
degenNFT,
|
|
19597
|
+
forbiddenTokenMask: facade.forbiddenTokensMask?.toString() ?? "0",
|
|
19598
|
+
isDegenMode: false
|
|
19599
|
+
// filtered above; kept for shape-compat
|
|
19600
|
+
}
|
|
19601
|
+
},
|
|
19602
|
+
chainId
|
|
19603
|
+
};
|
|
19544
19604
|
}
|
|
19545
|
-
out[lender] = {
|
|
19546
|
-
data: data2,
|
|
19547
|
-
params: {
|
|
19548
|
-
creditManager: {
|
|
19549
|
-
lender,
|
|
19550
|
-
creditManager: cmAddr,
|
|
19551
|
-
creditFacade: (cm.creditFacade ?? "").toString().toLowerCase(),
|
|
19552
|
-
pool: poolAddr,
|
|
19553
|
-
underlying,
|
|
19554
|
-
underlyingDecimals,
|
|
19555
|
-
minDebt: cm.minDebt?.toString() ?? "0",
|
|
19556
|
-
maxDebt: cm.maxDebt?.toString() ?? "0",
|
|
19557
|
-
degenNFT: (cm.degenNFT ?? zeroAddress).toString().toLowerCase(),
|
|
19558
|
-
forbiddenTokenMask: cm.forbiddenTokenMask?.toString() ?? "0",
|
|
19559
|
-
isDegenMode: !!cm.isDegenMode
|
|
19560
|
-
}
|
|
19561
|
-
},
|
|
19562
|
-
chainId
|
|
19563
|
-
};
|
|
19564
19605
|
}
|
|
19565
19606
|
return out;
|
|
19566
19607
|
},
|
|
@@ -19732,7 +19773,7 @@ var getAbi = (lender) => {
|
|
|
19732
19773
|
if (isFluid(lender))
|
|
19733
19774
|
return [...FluidVaultResolverAbi];
|
|
19734
19775
|
if (isGearboxV3(lender))
|
|
19735
|
-
return [...
|
|
19776
|
+
return [...GearboxMarketCompressorV310Abi];
|
|
19736
19777
|
if (isSumerType(lender)) return [...SumerLensAbi, ...SumerComptrollerAbi];
|
|
19737
19778
|
if (lender === Lender.TAKARA) return [...TakaraMarketStateAbi];
|
|
19738
19779
|
if (isCompoundV2Type(lender)) return VenusLensAbi;
|
|
@@ -20966,17 +21007,40 @@ var buildFluidUserCall = (chainId, _lender, account) => {
|
|
|
20966
21007
|
};
|
|
20967
21008
|
|
|
20968
21009
|
// src/lending/user-data/gearbox/userCallBuild.ts
|
|
21010
|
+
var CA_QUERY_LIMIT = 128;
|
|
20969
21011
|
var GEARBOX_V3_USER_CALL_COUNT = 1;
|
|
20970
21012
|
var buildGearboxV3UserCall = (chainId, _lender, account) => {
|
|
20971
|
-
const
|
|
20972
|
-
|
|
21013
|
+
const compressor = gearboxAccountCompressor();
|
|
21014
|
+
const configurators = gearboxMarketConfigurators(chainId);
|
|
21015
|
+
if (!configurators) return [];
|
|
21016
|
+
const curatorAddrs = Object.keys(configurators);
|
|
21017
|
+
if (curatorAddrs.length === 0) return [];
|
|
20973
21018
|
return [
|
|
20974
21019
|
{
|
|
20975
|
-
address:
|
|
20976
|
-
name: "
|
|
20977
|
-
|
|
20978
|
-
|
|
20979
|
-
|
|
21020
|
+
address: compressor,
|
|
21021
|
+
name: "getCreditAccounts",
|
|
21022
|
+
params: [
|
|
21023
|
+
{
|
|
21024
|
+
configurators: curatorAddrs,
|
|
21025
|
+
creditManagers: [],
|
|
21026
|
+
pools: [],
|
|
21027
|
+
underlying: zeroAddress
|
|
21028
|
+
},
|
|
21029
|
+
{
|
|
21030
|
+
owner: account,
|
|
21031
|
+
// Include even 0-debt accounts (user may hold collateral with no
|
|
21032
|
+
// borrow), and don't filter by health factor.
|
|
21033
|
+
includeZeroDebt: true,
|
|
21034
|
+
minHealthFactor: 0n,
|
|
21035
|
+
maxHealthFactor: (1n << 256n) - 1n,
|
|
21036
|
+
// `reverting: false` → skip CAs whose data fetch reverted
|
|
21037
|
+
// rather than returning `success: false` stubs. We can flip
|
|
21038
|
+
// this later if we want to surface malformed CAs to the UI.
|
|
21039
|
+
reverting: false
|
|
21040
|
+
},
|
|
21041
|
+
0n,
|
|
21042
|
+
BigInt(CA_QUERY_LIMIT)
|
|
21043
|
+
]
|
|
20980
21044
|
}
|
|
20981
21045
|
];
|
|
20982
21046
|
};
|
|
@@ -22880,12 +22944,13 @@ var getGearboxV3UserDataConverter = (_lender, chainId, account, meta) => {
|
|
|
22880
22944
|
return [
|
|
22881
22945
|
(data) => {
|
|
22882
22946
|
if (!data || data.length !== GEARBOX_V3_USER_CALL_COUNT) return void 0;
|
|
22883
|
-
const
|
|
22947
|
+
const first = data[0];
|
|
22948
|
+
const creditAccounts = Array.isArray(first) ? first : first?.data ?? first?.[0];
|
|
22884
22949
|
if (!Array.isArray(creditAccounts) || creditAccounts.length === 0)
|
|
22885
22950
|
return void 0;
|
|
22886
22951
|
const perCM = /* @__PURE__ */ new Map();
|
|
22887
22952
|
for (const ca of creditAccounts) {
|
|
22888
|
-
if (!ca?.
|
|
22953
|
+
if (!ca?.success) continue;
|
|
22889
22954
|
const cm = (ca.creditManager ?? "").toString().toLowerCase();
|
|
22890
22955
|
if (!cm) continue;
|
|
22891
22956
|
if (!perCM.has(cm)) perCM.set(cm, []);
|
|
@@ -22915,23 +22980,25 @@ var getGearboxV3UserDataConverter = (_lender, chainId, account, meta) => {
|
|
|
22915
22980
|
const modes = {};
|
|
22916
22981
|
const histData = {};
|
|
22917
22982
|
for (const ca of accounts) {
|
|
22918
|
-
const caAddress = (ca.addr ?? "").toString().toLowerCase();
|
|
22983
|
+
const caAddress = (ca.creditAccount ?? ca.addr ?? "").toString().toLowerCase();
|
|
22919
22984
|
if (!caAddress) continue;
|
|
22920
22985
|
const debtRaw = toBigInt8(ca.debt);
|
|
22921
|
-
const
|
|
22922
|
-
const hasAnyBalance =
|
|
22986
|
+
const tokens = Array.isArray(ca.tokens) ? ca.tokens : Array.isArray(ca.balances) ? ca.balances : [];
|
|
22987
|
+
const hasAnyBalance = tokens.some(
|
|
22923
22988
|
(b) => toBigInt8(b?.balance) > 0n
|
|
22924
22989
|
);
|
|
22925
22990
|
if (debtRaw === 0n && !hasAnyBalance) continue;
|
|
22926
22991
|
modes[caAddress] = 0;
|
|
22927
22992
|
const posData = {};
|
|
22928
22993
|
let totalDepositsUSD = 0;
|
|
22929
|
-
for (const bal of
|
|
22994
|
+
for (const bal of tokens) {
|
|
22930
22995
|
const rawToken = (bal?.token ?? "").toString().toLowerCase();
|
|
22931
22996
|
if (!rawToken) continue;
|
|
22932
22997
|
const token = rawToken;
|
|
22933
22998
|
const balRaw = toBigInt8(bal.balance);
|
|
22934
22999
|
if (balRaw === 0n) continue;
|
|
23000
|
+
const quotaRaw = toBigInt8(bal.quota);
|
|
23001
|
+
const isQuoted = quotaRaw > 0n || !!bal?.isQuoted;
|
|
22935
23002
|
const colMarketUid = createMarketUid(chainId, lenderKey, token);
|
|
22936
23003
|
const colMeta = metaMap[colMarketUid];
|
|
22937
23004
|
const colDec = colMeta?.asset?.decimals ?? 18;
|
|
@@ -22951,7 +23018,7 @@ var getGearboxV3UserDataConverter = (_lender, chainId, account, meta) => {
|
|
|
22951
23018
|
deposits: combinedDeposits,
|
|
22952
23019
|
depositsUSD: existing.depositsUSD + depositsUSD,
|
|
22953
23020
|
depositsUSDOracle: existing.depositsUSDOracle + depositsUSDOracle,
|
|
22954
|
-
collateralEnabled: existing.collateralEnabled ||
|
|
23021
|
+
collateralEnabled: existing.collateralEnabled || isQuoted
|
|
22955
23022
|
};
|
|
22956
23023
|
} else {
|
|
22957
23024
|
posData[colMarketUid] = {
|
|
@@ -22967,7 +23034,7 @@ var getGearboxV3UserDataConverter = (_lender, chainId, account, meta) => {
|
|
|
22967
23034
|
debtUSDOracle: 0,
|
|
22968
23035
|
debtStableUSDOracle: 0,
|
|
22969
23036
|
stableBorrowRate: "0",
|
|
22970
|
-
collateralEnabled:
|
|
23037
|
+
collateralEnabled: isQuoted,
|
|
22971
23038
|
claimableRewards: 0
|
|
22972
23039
|
};
|
|
22973
23040
|
}
|
|
@@ -27754,7 +27821,7 @@ var getAbi2 = (lender) => {
|
|
|
27754
27821
|
return [...SiloAbi];
|
|
27755
27822
|
if (isFluid(lender)) return [...FluidVaultResolverAbi];
|
|
27756
27823
|
if (isGearboxV3(lender))
|
|
27757
|
-
return [...
|
|
27824
|
+
return [...GearboxCreditAccountCompressorV310Abi];
|
|
27758
27825
|
return [];
|
|
27759
27826
|
};
|
|
27760
27827
|
|
|
@@ -30954,6 +31021,7 @@ function morphoApiAvailable(chainId) {
|
|
|
30954
31021
|
if (chainId === Chain.SEI_NETWORK) return false;
|
|
30955
31022
|
if (chainId === Chain.CELO_MAINNET) return false;
|
|
30956
31023
|
if (chainId === Chain.LISK) return false;
|
|
31024
|
+
if (chainId === Chain.BNB_SMART_CHAIN_MAINNET) return false;
|
|
30957
31025
|
return true;
|
|
30958
31026
|
}
|
|
30959
31027
|
function generateMarketId(oracle, loanAsset, collateralAsset) {
|
|
@@ -32167,43 +32235,35 @@ var fluidFetcher = {
|
|
|
32167
32235
|
parse: parseFluidResults,
|
|
32168
32236
|
getAbi: getFluidAbi
|
|
32169
32237
|
};
|
|
32170
|
-
function getGearboxV3Calls(
|
|
32171
|
-
|
|
32172
|
-
if (!resolvers?.dataCompressor) return [];
|
|
32173
|
-
const call = {
|
|
32174
|
-
address: resolvers.dataCompressor,
|
|
32175
|
-
name: "getPoolsV3List",
|
|
32176
|
-
params: []
|
|
32177
|
-
};
|
|
32178
|
-
return [
|
|
32179
|
-
{
|
|
32180
|
-
calls: [call],
|
|
32181
|
-
meta: { _: [] },
|
|
32182
|
-
lender: Lender.GEARBOX_V3
|
|
32183
|
-
}
|
|
32184
|
-
];
|
|
32238
|
+
function getGearboxV3Calls(_chainId) {
|
|
32239
|
+
return [];
|
|
32185
32240
|
}
|
|
32186
32241
|
function parseGearboxV3Results(data, _meta, context) {
|
|
32187
32242
|
const { chainId, usdPrices, tokenList } = context;
|
|
32188
32243
|
const entries = [];
|
|
32189
32244
|
const now = Math.floor(Date.now() / 1e3);
|
|
32190
|
-
const
|
|
32191
|
-
if (!Array.isArray(
|
|
32245
|
+
const markets = data[0];
|
|
32246
|
+
if (!Array.isArray(markets) || markets.length === 0) return entries;
|
|
32192
32247
|
const resolvePriceUSD = (token) => {
|
|
32193
32248
|
const key = tokenList?.[token]?.assetGroup ?? `${chainId}-${token}`;
|
|
32194
32249
|
return usdPrices[key] ?? usdPrices[token];
|
|
32195
32250
|
};
|
|
32196
|
-
for (const
|
|
32251
|
+
for (const m of markets) {
|
|
32197
32252
|
try {
|
|
32253
|
+
const pool = m?.pool;
|
|
32254
|
+
if (!pool || pool.isPaused) continue;
|
|
32198
32255
|
const underlying = (pool.underlying ?? "").toString().toLowerCase();
|
|
32199
32256
|
if (!underlying) continue;
|
|
32200
32257
|
const underlyingUSD = resolvePriceUSD(underlying);
|
|
32201
32258
|
if (!underlyingUSD) continue;
|
|
32202
|
-
for (const cm of
|
|
32203
|
-
const
|
|
32259
|
+
for (const cm of m.creditManagers ?? []) {
|
|
32260
|
+
const facade = cm?.creditFacade;
|
|
32261
|
+
const manager = cm?.creditManager;
|
|
32262
|
+
if (!facade || !manager) continue;
|
|
32263
|
+
const expDate = Number(facade.expirationDate ?? 0);
|
|
32264
|
+
if (facade.isPaused || expDate > 0 && expDate <= now) continue;
|
|
32265
|
+
const cmAddr = (manager.baseParams?.addr ?? "").toString().toLowerCase();
|
|
32204
32266
|
if (!cmAddr) continue;
|
|
32205
|
-
const expirationDate = Number(cm.expirationDate ?? 0);
|
|
32206
|
-
if (expirationDate > 0 && expirationDate < now) continue;
|
|
32207
32267
|
let lenderKey;
|
|
32208
32268
|
try {
|
|
32209
32269
|
lenderKey = gearboxV3LenderKey(cmAddr);
|
|
@@ -32220,10 +32280,9 @@ function parseGearboxV3Results(data, _meta, context) {
|
|
|
32220
32280
|
staticBase: true,
|
|
32221
32281
|
baseAsset: underlying
|
|
32222
32282
|
});
|
|
32223
|
-
for (const ct of
|
|
32224
|
-
const token = (ct
|
|
32225
|
-
if (!token) continue;
|
|
32226
|
-
if (token === underlying) continue;
|
|
32283
|
+
for (const ct of manager.collateralTokens ?? []) {
|
|
32284
|
+
const token = (ct?.token ?? "").toString().toLowerCase();
|
|
32285
|
+
if (!token || token === underlying) continue;
|
|
32227
32286
|
const tokenUSD = resolvePriceUSD(token);
|
|
32228
32287
|
if (!tokenUSD) continue;
|
|
32229
32288
|
entries.push({
|
|
@@ -32242,7 +32301,7 @@ function parseGearboxV3Results(data, _meta, context) {
|
|
|
32242
32301
|
return entries;
|
|
32243
32302
|
}
|
|
32244
32303
|
function getGearboxV3Abi() {
|
|
32245
|
-
return
|
|
32304
|
+
return GearboxMarketCompressorV310Abi;
|
|
32246
32305
|
}
|
|
32247
32306
|
var gearboxV3Fetcher = {
|
|
32248
32307
|
getCalls: getGearboxV3Calls,
|