@1delta/margin-fetcher 5.0.73 → 5.0.75
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/README.md +1 -1
- package/dist/index.d.ts +47 -6
- package/dist/index.js +206 -117
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { parseAbi, keccak256, encodeAbiParameters, formatEther, BaseError, erc20Abi, stringToHex, isAddress, pad, encodeFunctionData, formatUnits, getAddress, decodeFunctionResult, decodeAbiParameters, concat, parseAbiParameters, AbiEncodingLengthMismatchError, concatHex, toBytes, slice,
|
|
1
|
+
import { parseAbi, keccak256, encodeAbiParameters, formatEther, BaseError, erc20Abi, stringToHex, isAddress, pad, encodeFunctionData, formatUnits, getAddress, decodeFunctionResult, decodeAbiParameters, concat, parseAbiParameters, hexToString, AbiEncodingLengthMismatchError, concatHex, toBytes, slice, InvalidAddressError, boolToHex, integerRegex, numberToHex, bytesRegex, BytesSizeMismatchError, arrayRegex, UnsupportedPackedAbiType } from './chunk-JUYF2XLF.js';
|
|
2
2
|
import './chunk-BYTNVMX7.js';
|
|
3
3
|
import './chunk-PR4QN5HX.js';
|
|
4
4
|
import { Lender, isExactly, isMidnight, isTerm, isTermMax, isTeller, isListaDao, isLiquityFamily, isRiver, isInverse, isCooler, isDssType, isCompoundV3Type, isFluid, isGearboxV3, isLlamaLend, isFrankencoin, isResupply, isCurvance, isFlyingTulip, isTwyne, isFraxlend, isAaveV4Type, LIQUITY_FAMILY_LENDERS, isAaveType, isCompoundV3, isCompoundV2Type, isMultiMarket, isSiloV2Type, isSiloV3Type, isDolomite, isMorphoType, isUsdd, isSky, hasCrossMarginRisk, isEulerType, isInit, isVenusType, isSumerType, AAVE_V3_LENDERS, AAVE_V2_LENDERS, isMorphoBlue, isAaveV2Type, isAaveV32Type, isAaveV3Type, isYLDR, isLista, hasSubAccounts, isTectonicType, isKineticType, isBenqiType } from '@1delta/lender-registry';
|
|
5
5
|
export { hasCrossMarginRisk, isAaveType, isAaveV2Type, isAaveV32Type, isAaveV3Type, isCompoundV3, isCompoundV3Type, isInit, isMorphoType, isMultiMarket, isYLDR } from '@1delta/lender-registry';
|
|
6
|
-
import { fetchTokenLists, fetchTokenList, aavePools, compoundV3Pools, initConfig, morphoPools, compoundV2Pools, eulerVaults, siloMarkets, siloV2LenderKey, siloMarketsV3, siloV3LenderKey, aaveV4Spokes, aaveV4SpokeLenderKey, fluidResolvers, gearboxResolvers, dolomiteConfigs, midnightConfig, termConfig, termMarketsByChain, exactlyConfig, flyingTulipLendersByChain, liquityLendersByChain, riverLendersByChain, inverseLendersByChain, coolerLendersByChain, llamaLendLendersByChain, usddLendersByChain, skyLendersByChain, frankencoinLendersByChain, resupplyLendersByChain, curvanceLendersByChain, fraxlendLendersByChain, twyneLendersByChain, tellerConfigByChain, tellerPoolsByChain, termMaxConfigByChain, aaveReserves, compoundV3Reserves, resolveTermApiBase, flyingTulipConfigFor, flyingTulipAssetsFor, liquityConfigFor, liquityBranchesByChain, riverConfigFor, riverChainData, termMaxApiBaseUrl, termMaxLenderKey, inverseConfigFor, inverseChainData, coolerConfigFor, llamaLendConfigFor, llamaLendChainData, llamaLendApiBaseUrl, resupplyConfigFor, fraxlendConfigFor, dssConfigFor, dssChainData, dssDebtToken, dssDebtJoin, frankencoinConfigFor, frankencoinChainData, aaveOracles, morphoTypeMarkets, resolveMidnightApiBase, llamaLendMarketByVault, getSiloV2MarketEntry, getSiloV3MarketEntry, dolomiteEmode, curvanceConfigFor, aaveTokens, morphoTypeVaults, listaCollateralProvider, eulerConfigs, gearboxMarketCompressor, gearboxMarketConfigurators, compoundV2TokenArray, gearboxV3LenderKey, midnightMarketsByChain, twyneConfigFor, twyneChainData, parseAaveV4SpokeLenderKey, fraxlendPairsFor, gearboxAccountCompressor, compoundV2Tokens, exactlyMarketsByChain, aaveOraclesConfig, compoundV2Oracles, compoundV2OraclesConfig, compoundV3OraclesData, compoundV3BaseData, compoundV2Reserves, aaveV4Oracles, morphoTypeOracles } from '@1delta/data-sdk';
|
|
6
|
+
import { fetchTokenLists, fetchTokenList, aavePools, compoundV3Pools, initConfig, morphoPools, compoundV2Pools, eulerVaults, siloMarkets, siloV2LenderKey, siloMarketsV3, siloV3LenderKey, aaveV4Spokes, aaveV4SpokeLenderKey, fluidResolvers, gearboxResolvers, dolomiteConfigs, midnightConfig, termConfig, termMarketsByChain, exactlyConfig, flyingTulipLendersByChain, liquityLendersByChain, riverLendersByChain, inverseLendersByChain, coolerLendersByChain, llamaLendLendersByChain, usddLendersByChain, skyLendersByChain, frankencoinLendersByChain, resupplyLendersByChain, curvanceLendersByChain, fraxlendLendersByChain, twyneLendersByChain, tellerConfigByChain, tellerPoolsByChain, termMaxConfigByChain, aaveReserves, compoundV3Reserves, resolveTermApiBase, flyingTulipConfigFor, flyingTulipAssetsFor, liquityConfigFor, liquityBranchesByChain, riverConfigFor, riverChainData, termMaxApiBaseUrl, termMaxLenderKey, inverseConfigFor, inverseChainData, coolerConfigFor, llamaLendConfigFor, llamaLendChainData, llamaLendApiBaseUrl, resupplyConfigFor, fraxlendConfigFor, dssConfigFor, dssChainData, dssDebtToken, dssDebtJoin, frankencoinConfigFor, frankencoinChainData, aaveOracles, morphoTypeMarkets, resolveMidnightApiBase, llamaLendMarketByVault, getSiloV2MarketEntry, getSiloV3MarketEntry, dolomiteEmode, curvanceConfigFor, aaveTokens, morphoTypeVaults, listaCollateralProvider, eulerConfigs, gearboxMarketCompressor, gearboxMarketConfigurators, compoundV2TokenArray, gearboxV3LenderKey, midnightMarketsByChain, twyneConfigFor, twyneChainData, midnightCollateralRef, parseAaveV4SpokeLenderKey, fraxlendPairsFor, gearboxAccountCompressor, compoundV2Tokens, exactlyMarketsByChain, aaveOraclesConfig, compoundV2Oracles, compoundV2OraclesConfig, compoundV3OraclesData, compoundV3BaseData, compoundV2Reserves, aaveV4Oracles, morphoTypeOracles } from '@1delta/data-sdk';
|
|
7
7
|
import lodash from 'lodash';
|
|
8
8
|
import { Chain, isEvmChainId } from '@1delta/chain-registry';
|
|
9
|
-
import { multicallRetryUniversal, getEvmClient, getEvmChain, getEvmClientUniversal } from '@1delta/providers';
|
|
9
|
+
import { multicallRetryUniversal, getEvmClient, getEvmChain, createMulticallRetryUniversal, LIST_OVERRIDES, getEvmClientUniversal } from '@1delta/providers';
|
|
10
10
|
import { LiquityTroveManagerAbi, LiquityActivePoolAbi, LiquityStabilityPoolAbi, LiquityPriceFeedAbi, LiquitySortedTrovesAbi, RiverTroveManagerAbi, RiverStabilityPoolAbi, TellerMarketRegistryAbi, TellerV2Abi, InverseMarketAbi, InverseOracleAbi, InverseDbrAbi, CurveTricryptoOracleAbi, Erc20Abi, CoolerMonoAbi, CoolerLtvOracleAbi, LlamaLendControllerAbi, LlamaLendControllerV1Abi, LlamaLendControllerV2Abi, LlamaLendVaultAbi, LlamaLendAmmAbi, TwyneCollateralVaultAbi, MetaMorphoAbi, FluidDexResolverAbi, ExactlyPreviewerAbi, ExactlyAuditorAbi, FlyingTulipLendingLensAbi, LenderCommitmentGroupAbi, ResupplyRegistryAbi, ResupplyPairAbi, ResupplyUtilitiesAbi, ResupplyRewardHandlerAbi, ResupplyPairEmissionsAbi, ConvexPoolUtilAbi, FraxlendPairAbi, FraxlendLeverAbi, FrankencoinPositionAbi, FluidLendingResolverAbi, FluidVaultResolverAbi, FluidLiquidityResolverAbi, MoolahVaultAbi, UsddVatAbi, UsddJugAbi, UsddSpotAbi, MorphoLensAbi, AaveV4SpokeAbi, AaveV4OracleAbi, AaveV4HubAbi, DolomiteMarginAbi, GearboxMarketCompressorV310Abi, MorphoBlueAbi, MidnightAbi, TermRepoTokenAbi, TermRepoServicerAbi, TermRepoCollateralManagerAbi, LiquityTroveNFTAbi, LiquityCollSurplusPoolAbi, TellerCollateralManagerAbi, TermMaxViewerAbi, InverseEscrowAbi, CurvanceMarketManagerAbi, CurvanceCTokenAbi, GearboxCreditAccountCompressorV310Abi, TwyneVaultManagerAbi, TwyneCollateralVaultFactoryAbi, AaveV2V3Abi, TwyneATokenWrapperAbi, UsddCdpManagerAbi, UsddProxyRegistryAbi, CurvanceProtocolReaderAbi, CurvanceCentralRegistryAbi, TermPriceConsumerAbi, CurvanceOracleManagerAbi, TermMaxOracleAggregatorV2Abi } from '@1delta/abis';
|
|
11
11
|
export { MorphoLensAbi } from '@1delta/abis';
|
|
12
12
|
import { prepareDebitDataMulticall, prepareLenderDebitMulticall, parseDebitDataResult, parseLenderDebitResult, getPermit2ContractAddress, getLstAcceptedInputs, savingsVerbRequires, savingsSupportsVerb, getCompoundV2Comptroller as getCompoundV2Comptroller$1, getCompoundV3CometAddress as getCompoundV3CometAddress$1, getMorphoAddress, FLUID_VAULT_FACTORY, getAaveStyleLenderTokenAddress, LendingMode, getAaveCollateralTokenAddress, getSiloHalfForUnderlying, findSavingsWithdrawEntry, bandLtvCurve, InitMarginAddresses, ignoresReceiver, buildLstWithdrawRequest, SAVINGS_RECEIVER_CAPABILITY } from '@1delta/calldata-sdk';
|
|
@@ -11737,58 +11737,72 @@ function convertMarketsToMorphoResponse(response, chainId, additionalYields = {
|
|
|
11737
11737
|
m,
|
|
11738
11738
|
collateralAssetAddress
|
|
11739
11739
|
);
|
|
11740
|
-
data[m].data[collateralMarketUid]
|
|
11741
|
-
|
|
11742
|
-
|
|
11743
|
-
|
|
11744
|
-
underlying: collateralAssetAddress,
|
|
11745
|
-
asset: metaCollateral,
|
|
11746
|
-
totalDeposits: formatNr(
|
|
11747
|
-
state.collateralAssets,
|
|
11748
|
-
collateralAsset.decimals
|
|
11749
|
-
),
|
|
11750
|
-
totalDebtStable: 0,
|
|
11751
|
-
totalDebt: 0,
|
|
11752
|
-
totalLiquidity: formatNr(
|
|
11753
|
-
state.collateralAssets,
|
|
11754
|
-
collateralAsset.decimals
|
|
11755
|
-
),
|
|
11756
|
-
borrowLiquidity: formatNr(
|
|
11757
|
-
state.collateralAssets,
|
|
11758
|
-
collateralAsset.decimals
|
|
11759
|
-
),
|
|
11760
|
-
totalLiquidityUSD: Number(state.collateralAssetsUsd),
|
|
11761
|
-
borrowLiquidityUSD: Number(state.collateralAssetsUsd),
|
|
11762
|
-
totalDepositsUSD: Number(state.collateralAssetsUsd),
|
|
11763
|
-
totalDebtStableUSD: 0,
|
|
11764
|
-
totalDebtUSD: 0,
|
|
11765
|
-
utilization: 0,
|
|
11766
|
-
depositRate: 0,
|
|
11767
|
-
variableBorrowRate: 0,
|
|
11768
|
-
stableBorrowRate: 0,
|
|
11769
|
-
intrinsicYield: additionalYields?.intrinsicYields?.[metaCollateral?.assetGroup] ?? 0,
|
|
11770
|
-
rewards: void 0,
|
|
11771
|
-
decimals: collateralAsset.decimals,
|
|
11772
|
-
config: {
|
|
11740
|
+
const existingLoanRow = data[m].data[collateralMarketUid];
|
|
11741
|
+
if (existingLoanRow) {
|
|
11742
|
+
existingLoanRow.collateralActive = true;
|
|
11743
|
+
existingLoanRow.config = {
|
|
11773
11744
|
0: {
|
|
11774
|
-
|
|
11745
|
+
...existingLoanRow.config?.[0] ?? {},
|
|
11775
11746
|
borrowCollateralFactor: ltv,
|
|
11776
11747
|
collateralFactor: ltv,
|
|
11777
|
-
borrowFactor: 1,
|
|
11778
11748
|
liquidationPenalty,
|
|
11779
|
-
|
|
11780
|
-
collateralDisabled: false,
|
|
11781
|
-
debtDisabled: true
|
|
11749
|
+
collateralDisabled: false
|
|
11782
11750
|
}
|
|
11783
|
-
}
|
|
11784
|
-
|
|
11785
|
-
|
|
11786
|
-
|
|
11787
|
-
|
|
11788
|
-
|
|
11789
|
-
|
|
11790
|
-
|
|
11791
|
-
|
|
11751
|
+
};
|
|
11752
|
+
} else {
|
|
11753
|
+
data[m].data[collateralMarketUid] = {
|
|
11754
|
+
marketUid: collateralMarketUid,
|
|
11755
|
+
name: "Collateral " + (metaCollateral?.symbol ?? collateralAsset.symbol ?? ""),
|
|
11756
|
+
poolId: collateralAssetAddress,
|
|
11757
|
+
underlying: collateralAssetAddress,
|
|
11758
|
+
asset: metaCollateral,
|
|
11759
|
+
totalDeposits: formatNr(
|
|
11760
|
+
state.collateralAssets,
|
|
11761
|
+
collateralAsset.decimals
|
|
11762
|
+
),
|
|
11763
|
+
totalDebtStable: 0,
|
|
11764
|
+
totalDebt: 0,
|
|
11765
|
+
totalLiquidity: formatNr(
|
|
11766
|
+
state.collateralAssets,
|
|
11767
|
+
collateralAsset.decimals
|
|
11768
|
+
),
|
|
11769
|
+
borrowLiquidity: formatNr(
|
|
11770
|
+
state.collateralAssets,
|
|
11771
|
+
collateralAsset.decimals
|
|
11772
|
+
),
|
|
11773
|
+
totalLiquidityUSD: Number(state.collateralAssetsUsd),
|
|
11774
|
+
borrowLiquidityUSD: Number(state.collateralAssetsUsd),
|
|
11775
|
+
totalDepositsUSD: Number(state.collateralAssetsUsd),
|
|
11776
|
+
totalDebtStableUSD: 0,
|
|
11777
|
+
totalDebtUSD: 0,
|
|
11778
|
+
utilization: 0,
|
|
11779
|
+
depositRate: 0,
|
|
11780
|
+
variableBorrowRate: 0,
|
|
11781
|
+
stableBorrowRate: 0,
|
|
11782
|
+
intrinsicYield: additionalYields?.intrinsicYields?.[metaCollateral?.assetGroup] ?? 0,
|
|
11783
|
+
rewards: void 0,
|
|
11784
|
+
decimals: collateralAsset.decimals,
|
|
11785
|
+
config: {
|
|
11786
|
+
0: {
|
|
11787
|
+
category: 0,
|
|
11788
|
+
borrowCollateralFactor: ltv,
|
|
11789
|
+
collateralFactor: ltv,
|
|
11790
|
+
borrowFactor: 1,
|
|
11791
|
+
liquidationPenalty,
|
|
11792
|
+
closeFactor: 1,
|
|
11793
|
+
collateralDisabled: false,
|
|
11794
|
+
debtDisabled: true
|
|
11795
|
+
}
|
|
11796
|
+
},
|
|
11797
|
+
closeFactor: 1,
|
|
11798
|
+
collateralActive: true,
|
|
11799
|
+
borrowingEnabled: false,
|
|
11800
|
+
depositsEnabled: true,
|
|
11801
|
+
hasStable: false,
|
|
11802
|
+
isActive: true,
|
|
11803
|
+
isFrozen: false
|
|
11804
|
+
};
|
|
11805
|
+
}
|
|
11792
11806
|
data[m].params = {
|
|
11793
11807
|
market: {
|
|
11794
11808
|
lender: m,
|
|
@@ -16664,13 +16678,13 @@ var REPAIR_BACKOFF_JITTER_MS = 60;
|
|
|
16664
16678
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
|
|
16665
16679
|
var backoffForRound = (round) => REPAIR_BACKOFF_BASE_MS * 2 ** round + Math.random() * REPAIR_BACKOFF_JITTER_MS;
|
|
16666
16680
|
var endpointUrl = (client, rpcId) => client?.transport?.url ?? `rpc#${rpcId}`;
|
|
16667
|
-
var resolveEndpoint = (chainId,
|
|
16681
|
+
var resolveEndpoint = (chainId, getEvmClient19, startRpcId, tried, maxProbe = 12, timeoutMs) => {
|
|
16668
16682
|
let fallback = null;
|
|
16669
16683
|
for (let probe = 0; probe < maxProbe; probe++) {
|
|
16670
16684
|
const rpcId = startRpcId + probe;
|
|
16671
16685
|
let client;
|
|
16672
16686
|
try {
|
|
16673
|
-
client =
|
|
16687
|
+
client = getEvmClient19(chainId, rpcId, { timeoutMs });
|
|
16674
16688
|
} catch {
|
|
16675
16689
|
break;
|
|
16676
16690
|
}
|
|
@@ -16699,7 +16713,7 @@ var recordPermanentFailures = (slots, offset, collector) => {
|
|
|
16699
16713
|
if (slots[i].permanent) collector.add(offset + i);
|
|
16700
16714
|
}
|
|
16701
16715
|
};
|
|
16702
|
-
var repairFailedSlots = async (chainId, contracts, slots,
|
|
16716
|
+
var repairFailedSlots = async (chainId, contracts, slots, getEvmClient19, nextRpcId, batchSize, logs, rounds = MULTICALL_REPAIR_ROUNDS, options) => {
|
|
16703
16717
|
let searchFrom = nextRpcId;
|
|
16704
16718
|
for (let round = 0; round < rounds; round++) {
|
|
16705
16719
|
const failedIdx = [];
|
|
@@ -16709,7 +16723,7 @@ var repairFailedSlots = async (chainId, contracts, slots, getEvmClient20, nextRp
|
|
|
16709
16723
|
if (failedIdx.length === 0) return slots;
|
|
16710
16724
|
const endpoint = resolveEndpoint(
|
|
16711
16725
|
chainId,
|
|
16712
|
-
|
|
16726
|
+
getEvmClient19,
|
|
16713
16727
|
searchFrom,
|
|
16714
16728
|
options?.tried
|
|
16715
16729
|
);
|
|
@@ -16761,7 +16775,7 @@ var repairFailedSlots = async (chainId, contracts, slots, getEvmClient20, nextRp
|
|
|
16761
16775
|
}
|
|
16762
16776
|
return slots;
|
|
16763
16777
|
};
|
|
16764
|
-
var multicallShardedAbiArray = async (chainId, abi, calls,
|
|
16778
|
+
var multicallShardedAbiArray = async (chainId, abi, calls, getEvmClient19, poolSize, retries = maxRetries, allowFailure = true, batchSize = MULTICALL_DEFAULT_BATCH_SIZE, logs = false, retryFailed = false, permanentFailures, options) => {
|
|
16765
16779
|
const abiIsArray = isArray(abi[0]);
|
|
16766
16780
|
const contracts = calls.map(({ address, name, params }, i) => ({
|
|
16767
16781
|
abi: abiIsArray ? abi?.[i] : abi,
|
|
@@ -16835,7 +16849,7 @@ var multicallShardedAbiArray = async (chainId, abi, calls, getEvmClient20, poolS
|
|
|
16835
16849
|
const attemptHedged = async (items, startRpcId, tried) => {
|
|
16836
16850
|
const primary = resolveEndpoint(
|
|
16837
16851
|
chainId,
|
|
16838
|
-
|
|
16852
|
+
getEvmClient19,
|
|
16839
16853
|
startRpcId,
|
|
16840
16854
|
tried,
|
|
16841
16855
|
12,
|
|
@@ -16859,7 +16873,7 @@ var multicallShardedAbiArray = async (chainId, abi, calls, getEvmClient20, poolS
|
|
|
16859
16873
|
clearTimeout(timer);
|
|
16860
16874
|
const alt = resolveEndpoint(
|
|
16861
16875
|
chainId,
|
|
16862
|
-
|
|
16876
|
+
getEvmClient19,
|
|
16863
16877
|
primary.rpcId + 1,
|
|
16864
16878
|
tried,
|
|
16865
16879
|
12,
|
|
@@ -16911,7 +16925,7 @@ var multicallShardedAbiArray = async (chainId, abi, calls, getEvmClient20, poolS
|
|
|
16911
16925
|
chainId,
|
|
16912
16926
|
batch.items,
|
|
16913
16927
|
slots,
|
|
16914
|
-
|
|
16928
|
+
getEvmClient19,
|
|
16915
16929
|
won.rpcId + 1,
|
|
16916
16930
|
requestBytes,
|
|
16917
16931
|
logs,
|
|
@@ -16933,7 +16947,7 @@ var multicallShardedAbiArray = async (chainId, abi, calls, getEvmClient20, poolS
|
|
|
16933
16947
|
const tried = /* @__PURE__ */ new Set();
|
|
16934
16948
|
const start = resolveEndpoint(
|
|
16935
16949
|
chainId,
|
|
16936
|
-
|
|
16950
|
+
getEvmClient19,
|
|
16937
16951
|
workerId,
|
|
16938
16952
|
void 0,
|
|
16939
16953
|
12,
|
|
@@ -21517,6 +21531,14 @@ function convertMidnightMarketsToResponse(raw, chainId, prices = {}, _additional
|
|
|
21517
21531
|
// Midnight is fixed-rate: expose the fixed borrow APR on stableBorrowRate
|
|
21518
21532
|
// too, so fixed-rate consumers pick it up like a term product.
|
|
21519
21533
|
stableBorrowRate: borrowAprPct,
|
|
21534
|
+
// The rate card is a BORROW-side fact, so it lives on the row that has a
|
|
21535
|
+
// borrow side — natively, not by a consumer matching `loanAddress`
|
|
21536
|
+
// against each row's asset. That match is what broke when the loan token
|
|
21537
|
+
// was also a collateral leg: the leg row carries the same token, so it
|
|
21538
|
+
// matched too and was served a "Fixed from X %" it cannot offer.
|
|
21539
|
+
// `params.market.terms` still carries the same card for readers of the
|
|
21540
|
+
// market-level shape; the collateral legs below never carry one.
|
|
21541
|
+
terms,
|
|
21520
21542
|
intrinsicYield: 0,
|
|
21521
21543
|
rewards: void 0,
|
|
21522
21544
|
decimals: config.loanDecimals,
|
|
@@ -21544,31 +21566,17 @@ function convertMidnightMarketsToResponse(raw, chainId, prices = {}, _additional
|
|
|
21544
21566
|
isActive: true,
|
|
21545
21567
|
isFrozen: false
|
|
21546
21568
|
};
|
|
21547
|
-
config.collateralParams.forEach((c) => {
|
|
21569
|
+
config.collateralParams.forEach((c, i) => {
|
|
21548
21570
|
const collAddr = c.token.toLowerCase();
|
|
21549
21571
|
const ltv = parseLtv(c.lltv);
|
|
21550
21572
|
const cursor = toBigIntOr0(c.liquidationCursor);
|
|
21551
21573
|
const liquidationPenalty = cursor > 0n ? midnightLiquidationPenaltyNumber(toBigIntOr0(c.lltv), cursor) : liquidationPenaltyFromLltv(ltv);
|
|
21552
|
-
const collUid = createMarketUid(chainId, m, collAddr);
|
|
21574
|
+
const collUid = createMarketUid(chainId, m, midnightCollateralRef(collAddr, i));
|
|
21553
21575
|
const collAsset = tokens[collAddr];
|
|
21554
21576
|
const collKey = toOracleKey(collAsset?.assetGroup) || toGenericPriceKey(collAddr, chainId);
|
|
21555
21577
|
const collPrice = prices[collKey] ?? 0;
|
|
21556
21578
|
const collCapacityUSD = ltv > 0 ? borrowLiquidity * loanPrice / ltv : borrowLiquidity * loanPrice;
|
|
21557
21579
|
const collCapacity = collPrice > 0 ? collCapacityUSD / collPrice : 0;
|
|
21558
|
-
const existing = entry.data[collUid];
|
|
21559
|
-
if (existing) {
|
|
21560
|
-
existing.collateralActive = true;
|
|
21561
|
-
existing.config = {
|
|
21562
|
-
0: {
|
|
21563
|
-
...existing.config?.[0] ?? {},
|
|
21564
|
-
borrowCollateralFactor: ltv,
|
|
21565
|
-
collateralFactor: ltv,
|
|
21566
|
-
liquidationPenalty,
|
|
21567
|
-
collateralDisabled: false
|
|
21568
|
-
}
|
|
21569
|
-
};
|
|
21570
|
-
return;
|
|
21571
|
-
}
|
|
21572
21580
|
entry.data[collUid] = {
|
|
21573
21581
|
marketUid: collUid,
|
|
21574
21582
|
name: "Collateral " + (tokens[collAddr]?.symbol ?? ""),
|
|
@@ -35021,7 +35029,11 @@ var getMidnightUserDataConverter = (_lender, chainId, account, meta) => {
|
|
|
35021
35029
|
if (collAmt === 0n) return;
|
|
35022
35030
|
anyBalance = true;
|
|
35023
35031
|
const collAddr = c.token.toLowerCase();
|
|
35024
|
-
const collUid = createMarketUid(
|
|
35032
|
+
const collUid = createMarketUid(
|
|
35033
|
+
chainId,
|
|
35034
|
+
lenderKey,
|
|
35035
|
+
midnightCollateralRef(collAddr, i)
|
|
35036
|
+
);
|
|
35025
35037
|
const collMeta = metaMap[collUid];
|
|
35026
35038
|
const collDec = collMeta?.asset?.decimals ?? c.decimals;
|
|
35027
35039
|
const collDisplayPrice = collMeta ? getDisplayPrice(collMeta) : 0;
|
|
@@ -42365,7 +42377,7 @@ function unflattenLenderData(pools) {
|
|
|
42365
42377
|
}
|
|
42366
42378
|
return result;
|
|
42367
42379
|
}
|
|
42368
|
-
var getLenderUserDataResult = async (chainId, queriesRaw,
|
|
42380
|
+
var getLenderUserDataResult = async (chainId, queriesRaw, getEvmClient19, allowFailure = true, batchSize = MULTICALL_DEFAULT_BATCH_SIZE, retries = 3, logs = false, concurrency = 1, permanentFailures, onEndpointFailure) => {
|
|
42369
42381
|
const queries = organizeUserQueries(queriesRaw);
|
|
42370
42382
|
const builtCalls = await Promise.all(
|
|
42371
42383
|
queries.map(async (query3) => {
|
|
@@ -42375,7 +42387,7 @@ var getLenderUserDataResult = async (chainId, queriesRaw, getEvmClient20, allowF
|
|
|
42375
42387
|
query3.lender,
|
|
42376
42388
|
query3.account,
|
|
42377
42389
|
query3.params,
|
|
42378
|
-
|
|
42390
|
+
getEvmClient19
|
|
42379
42391
|
);
|
|
42380
42392
|
return callData.map((call) => ({ call, abi: call.abi ?? abi }));
|
|
42381
42393
|
})
|
|
@@ -42385,7 +42397,7 @@ var getLenderUserDataResult = async (chainId, queriesRaw, getEvmClient20, allowF
|
|
|
42385
42397
|
chainId,
|
|
42386
42398
|
calls.map((call) => call.abi),
|
|
42387
42399
|
calls.map((call) => call.call),
|
|
42388
|
-
|
|
42400
|
+
getEvmClient19,
|
|
42389
42401
|
concurrency,
|
|
42390
42402
|
retries,
|
|
42391
42403
|
allowFailure,
|
|
@@ -54970,15 +54982,16 @@ function getMidnightCalls(chainId) {
|
|
|
54970
54982
|
if (!market.marketId || !market.loanToken) continue;
|
|
54971
54983
|
const legs = [];
|
|
54972
54984
|
const calls = [];
|
|
54973
|
-
|
|
54974
|
-
if (!c.oracle || !c.token)
|
|
54985
|
+
(market.collateralParams ?? []).forEach((c, collateralIndex) => {
|
|
54986
|
+
if (!c.oracle || !c.token) return;
|
|
54975
54987
|
legs.push({
|
|
54976
54988
|
collateralAsset: c.token.toLowerCase(),
|
|
54977
54989
|
collateralDecimals: c.decimals,
|
|
54978
|
-
oracle: c.oracle
|
|
54990
|
+
oracle: c.oracle,
|
|
54991
|
+
collateralIndex
|
|
54979
54992
|
});
|
|
54980
54993
|
calls.push({ address: c.oracle, name: "price", params: [] });
|
|
54981
|
-
}
|
|
54994
|
+
});
|
|
54982
54995
|
if (legs.length === 0) continue;
|
|
54983
54996
|
results.push({
|
|
54984
54997
|
calls,
|
|
@@ -55027,7 +55040,11 @@ function parseMidnightResults(data, meta, context) {
|
|
|
55027
55040
|
price: priceDebtToCollateral,
|
|
55028
55041
|
// raw: collateral price in loan asset terms
|
|
55029
55042
|
priceUSD: priceDebtToCollateral * loanAssetUSD,
|
|
55030
|
-
marketUid: createMarketUid(
|
|
55043
|
+
marketUid: createMarketUid(
|
|
55044
|
+
chainId,
|
|
55045
|
+
lenderKey,
|
|
55046
|
+
midnightCollateralRef(leg.collateralAsset, leg.collateralIndex)
|
|
55047
|
+
),
|
|
55031
55048
|
targetLender: lenderKey,
|
|
55032
55049
|
baseAsset: loanAsset
|
|
55033
55050
|
});
|
|
@@ -76210,7 +76227,7 @@ function parseMulticallRpcResponses(responses, batches, allowFailure = true, per
|
|
|
76210
76227
|
});
|
|
76211
76228
|
return allResults;
|
|
76212
76229
|
}
|
|
76213
|
-
var
|
|
76230
|
+
var ERC20_STRING_ABI = [
|
|
76214
76231
|
{
|
|
76215
76232
|
inputs: [],
|
|
76216
76233
|
name: "name",
|
|
@@ -76233,38 +76250,110 @@ var ERC20MetadataAbi = [
|
|
|
76233
76250
|
type: "function"
|
|
76234
76251
|
}
|
|
76235
76252
|
];
|
|
76236
|
-
|
|
76237
|
-
|
|
76238
|
-
|
|
76239
|
-
|
|
76240
|
-
|
|
76241
|
-
|
|
76242
|
-
|
|
76243
|
-
|
|
76244
|
-
|
|
76245
|
-
|
|
76246
|
-
|
|
76247
|
-
|
|
76248
|
-
|
|
76249
|
-
|
|
76250
|
-
|
|
76251
|
-
|
|
76252
|
-
|
|
76253
|
-
|
|
76254
|
-
|
|
76255
|
-
|
|
76256
|
-
|
|
76257
|
-
|
|
76258
|
-
|
|
76259
|
-
|
|
76260
|
-
|
|
76261
|
-
|
|
76253
|
+
var ERC20_BYTES32_ABI = [
|
|
76254
|
+
{
|
|
76255
|
+
inputs: [],
|
|
76256
|
+
name: "name",
|
|
76257
|
+
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
76258
|
+
stateMutability: "view",
|
|
76259
|
+
type: "function"
|
|
76260
|
+
},
|
|
76261
|
+
{
|
|
76262
|
+
inputs: [],
|
|
76263
|
+
name: "symbol",
|
|
76264
|
+
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
76265
|
+
stateMutability: "view",
|
|
76266
|
+
type: "function"
|
|
76267
|
+
}
|
|
76268
|
+
];
|
|
76269
|
+
var FAILED = "0x";
|
|
76270
|
+
function decodeBytes32(value) {
|
|
76271
|
+
if (typeof value !== "string" || !value.startsWith("0x")) return void 0;
|
|
76272
|
+
if (value === FAILED) return void 0;
|
|
76273
|
+
try {
|
|
76274
|
+
const decoded = hexToString(value).replace(/\0+$/, "").trim();
|
|
76275
|
+
return decoded.length > 0 ? decoded : void 0;
|
|
76276
|
+
} catch {
|
|
76277
|
+
return void 0;
|
|
76278
|
+
}
|
|
76279
|
+
}
|
|
76280
|
+
function asString(value) {
|
|
76281
|
+
if (typeof value !== "string") return void 0;
|
|
76282
|
+
if (value === FAILED) return void 0;
|
|
76283
|
+
const trimmed = value.trim();
|
|
76284
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
76285
|
+
}
|
|
76286
|
+
async function fetchTokenMetadata(chain, addrs, options = {}) {
|
|
76287
|
+
const { rpcUrls, maxRetries: maxRetries2 = 3 } = options;
|
|
76288
|
+
const unique = [
|
|
76289
|
+
...new Set(
|
|
76290
|
+
addrs.filter((a) => typeof a === "string" && isAddress(a, { strict: false })).map((a) => a.toLowerCase())
|
|
76291
|
+
)
|
|
76292
|
+
];
|
|
76293
|
+
if (unique.length === 0) return {};
|
|
76294
|
+
const multicall = createMulticallRetryUniversal(
|
|
76295
|
+
rpcUrls?.length ? { [chain]: rpcUrls } : LIST_OVERRIDES
|
|
76296
|
+
);
|
|
76297
|
+
const calls = unique.flatMap((address) => [
|
|
76298
|
+
{ address, name: "name", args: [] },
|
|
76299
|
+
{ address, name: "symbol", args: [] },
|
|
76300
|
+
{ address, name: "decimals", args: [] }
|
|
76301
|
+
]);
|
|
76302
|
+
const results = await multicall({
|
|
76303
|
+
chain,
|
|
76304
|
+
calls,
|
|
76305
|
+
abi: ERC20_STRING_ABI,
|
|
76306
|
+
maxRetries: maxRetries2,
|
|
76307
|
+
allowFailure: true
|
|
76308
|
+
});
|
|
76309
|
+
const names = /* @__PURE__ */ new Map();
|
|
76310
|
+
const symbols = /* @__PURE__ */ new Map();
|
|
76311
|
+
const decimalsByAddr = /* @__PURE__ */ new Map();
|
|
76312
|
+
unique.forEach((address, i) => {
|
|
76313
|
+
names.set(address, asString(results[i * 3]));
|
|
76314
|
+
symbols.set(address, asString(results[i * 3 + 1]));
|
|
76315
|
+
const raw = results[i * 3 + 2];
|
|
76316
|
+
decimalsByAddr.set(
|
|
76317
|
+
address,
|
|
76318
|
+
typeof raw === "number" ? raw : typeof raw === "bigint" ? Number(raw) : void 0
|
|
76319
|
+
);
|
|
76262
76320
|
});
|
|
76263
|
-
|
|
76264
|
-
|
|
76265
|
-
|
|
76266
|
-
|
|
76267
|
-
const
|
|
76321
|
+
const needsBytes32 = unique.filter(
|
|
76322
|
+
(a) => decimalsByAddr.get(a) !== void 0 && (names.get(a) === void 0 || symbols.get(a) === void 0)
|
|
76323
|
+
);
|
|
76324
|
+
if (needsBytes32.length > 0) {
|
|
76325
|
+
const b32Calls = needsBytes32.flatMap((address) => [
|
|
76326
|
+
{ address, name: "name", args: [] },
|
|
76327
|
+
{ address, name: "symbol", args: [] }
|
|
76328
|
+
]);
|
|
76329
|
+
try {
|
|
76330
|
+
const b32 = await multicall({
|
|
76331
|
+
chain,
|
|
76332
|
+
calls: b32Calls,
|
|
76333
|
+
abi: ERC20_BYTES32_ABI,
|
|
76334
|
+
maxRetries: maxRetries2,
|
|
76335
|
+
allowFailure: true
|
|
76336
|
+
});
|
|
76337
|
+
needsBytes32.forEach((address, i) => {
|
|
76338
|
+
if (names.get(address) === void 0) {
|
|
76339
|
+
const decoded = decodeBytes32(b32[i * 2]);
|
|
76340
|
+
if (decoded) names.set(address, decoded);
|
|
76341
|
+
}
|
|
76342
|
+
if (symbols.get(address) === void 0) {
|
|
76343
|
+
const decoded = decodeBytes32(b32[i * 2 + 1]);
|
|
76344
|
+
if (decoded) symbols.set(address, decoded);
|
|
76345
|
+
}
|
|
76346
|
+
});
|
|
76347
|
+
} catch {
|
|
76348
|
+
}
|
|
76349
|
+
}
|
|
76350
|
+
const tokens = {};
|
|
76351
|
+
for (const address of unique) {
|
|
76352
|
+
const decimals = decimalsByAddr.get(address);
|
|
76353
|
+
if (decimals === void 0 || !Number.isInteger(decimals)) continue;
|
|
76354
|
+
if (decimals < 0 || decimals > 36) continue;
|
|
76355
|
+
const symbol = symbols.get(address) ?? `${address.slice(0, 6)}\u2026`;
|
|
76356
|
+
const name = names.get(address) ?? symbol;
|
|
76268
76357
|
tokens[address] = {
|
|
76269
76358
|
chainId: String(chain),
|
|
76270
76359
|
decimals,
|
|
@@ -76274,7 +76363,7 @@ async function fetchTokenMetadata(chain, addrs) {
|
|
|
76274
76363
|
assetGroup: `${symbol}::${name}`,
|
|
76275
76364
|
currencyId: `${symbol}::${name}`
|
|
76276
76365
|
};
|
|
76277
|
-
}
|
|
76366
|
+
}
|
|
76278
76367
|
return tokens;
|
|
76279
76368
|
}
|
|
76280
76369
|
function balanceFetcher() {
|