@1delta/margin-fetcher 5.0.161 → 5.0.162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -0
- package/dist/index.js +101 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -291,6 +291,14 @@ interface PoolData {
|
|
|
291
291
|
isActive: boolean;
|
|
292
292
|
isFrozen: boolean;
|
|
293
293
|
borrowCap: number;
|
|
294
|
+
/**
|
|
295
|
+
* Remaining-deposit ceiling in TOKEN units. No cap is `undefined`, never 0:
|
|
296
|
+
* yield-tracer stores `depositable = supplyCap − totalDeposits` whenever the
|
|
297
|
+
* field is set, so 0 reads as a FULL cap and the pairs feed drops every pair
|
|
298
|
+
* on the leg (Flex shipped that way, TODO.md 2026-11-23). 0 is only right on
|
|
299
|
+
* a leg that is closed to deposits (cap 0 plus the flag) or one nobody
|
|
300
|
+
* deposits into (a minted debt token, Compound V3's base).
|
|
301
|
+
*/
|
|
294
302
|
supplyCap: number;
|
|
295
303
|
debtCeiling: string;
|
|
296
304
|
/**
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ 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, isRipe, isAlchemix, isFlex, isTwyne, isFraxlend, isAaveV4Type, isKamino, isJupiterLend, isSave, isLoopscale, isProject0, isZodial, isDefituna, isJupiterOfferbook, LIQUITY_FAMILY_LENDERS, isAaveType, isCompoundV3, isCompoundV2Type, isMultiMarket, isSiloV2Type, isSiloV3Type, isDolomite, isMorphoType, isUsdd, isSky, hasCrossMarginRisk, isEulerType, isInit, isVenusType, normalizeLenderKey, isSumerType, AAVE_V3_LENDERS, AAVE_V2_LENDERS, isMorphoBlue, kaminoMarketFromKey, jupiterLendVaultFromKey, saveMarketFromKey, loopscaleMarketFromKey, project0GroupFromKey, zodialGroupFromKey, defiTunaPoolFromKey, jupiterOfferbookMarketFromKey, 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,
|
|
6
|
+
import { fetchTokenLists, fetchTokenList, compoundV2TokenArray, compoundV3BaseData, compoundV3Pools, aavePools, initConfig, morphoPools, compoundV2Pools, eulerVaults, siloMarkets, siloV2LenderKey, siloMarketsV3, siloV3LenderKey, aaveV4Spokes, aaveV4SpokeLenderKey, fluidResolvers, gearboxResolvers, dolomiteConfigs, midnightConfig, termConfig, termMarketsByChain, exactlyConfig, flyingTulipLendersByChain, liquityLendersByChain, riverLendersByChain, inverseLendersByChain, coolerLendersByChain, ripeLendersByChain, alchemixLendersByChain, flexLendersByChain, llamaLendLendersByChain, usddLendersByChain, skyLendersByChain, frankencoinLendersByChain, resupplyLendersByChain, curvanceLendersByChain, fraxlendLendersByChain, twyneLendersByChain, tellerConfigByChain, tellerPoolsByChain, termMaxConfigByChain, aaveReserves, compoundV3Reserves, dolomiteIsolationMarket, morphoTypeMarkets, resolveTermApiBase, flyingTulipConfigFor, flyingTulipAssetsFor, liquityConfigFor, liquityBranchesByChain, riverConfigFor, riverChainData, termMaxApiBaseUrl, termMaxLenderKey, inverseConfigFor, inverseChainData, coolerConfigFor, llamaLendConfigFor, llamaLendChainData, llamaLendApiBaseUrl, resupplyConfigFor, fraxlendConfigFor, alchemixMarketsFor, alchemixMarketKey, flexMarketsFor, flexMarketKey, dssConfigFor, dssChainData, dssDebtToken, dssDebtJoin, frankencoinConfigFor, frankencoinChainData, aaveTokens, morphoTypeVaults, eulerConfigs, fluidVaultEntries, gearboxMarketConfigurators, dolomiteIsolation, liquityMarkets, riverMarkets, tellerConfig, tellerPools, termMarkets, termMaxConfig, midnightMarkets, midnightCollateralRef, llamaLendMarkets, fraxlendPairsFor, inverseMarkets, curvanceConfig, frankencoinMarkets, ripeConfigFor, twyneMarkets, twyneConfigFor, exactlyMarkets, aaveOracles, resolveMidnightApiBase, llamaLendMarketByVault, getSiloV2MarketEntry, getSiloV3MarketEntry, dolomiteEmode, curvanceConfigFor, isMidnightCollateralVault, listaCollateralProvider, gearboxMarketCompressor, gearboxV3LenderKey, RIPE_HQ_IDS, midnightMarketsByChain, twyneChainData, parseAaveV4SpokeLenderKey, gearboxAccountCompressor, compoundV2Tokens, exactlyMarketsByChain, aaveOraclesConfig, compoundV2Oracles, compoundV2OraclesConfig, compoundV3OraclesData, compoundV2Reserves, aaveV4Oracles, morphoTypeOracles, fluidVaults } from '@1delta/data-sdk';
|
|
7
7
|
import lodash from 'lodash';
|
|
8
8
|
import { Chain, isEvmChainId, isRetiredChain, isSvmChainId } from '@1delta/chain-registry';
|
|
9
9
|
import { multicallRetryUniversal, getEvmClient, getEvmClientWithCustomRpcsUniversal, LIST_OVERRIDES, getEvmChain, createMulticallRetryUniversal, getEvmClientUniversal } from '@1delta/providers';
|
|
@@ -7559,7 +7559,8 @@ var getAaveV3ReservesDataConverter = (lender, chainId, prices, additionalYields,
|
|
|
7559
7559
|
isFrozen: configData?.[9 /* isFrozen */],
|
|
7560
7560
|
// caps
|
|
7561
7561
|
borrowCap: Number(reserveCaps[0]?.toString()),
|
|
7562
|
-
|
|
7562
|
+
// Aave's 0 = no cap; downstream no cap is undefined (0 reads full)
|
|
7563
|
+
supplyCap: Number(reserveCaps[1]?.toString()) || void 0,
|
|
7563
7564
|
debtCeiling: Number(
|
|
7564
7565
|
parseRawAmount(
|
|
7565
7566
|
debtCeiling?.toString(),
|
|
@@ -8000,7 +8001,8 @@ function parseAave32(chainId, lender, prices, additionalYields, tokenList) {
|
|
|
8000
8001
|
isFrozen: configData?.[9 /* isFrozen */],
|
|
8001
8002
|
// caps
|
|
8002
8003
|
borrowCap: Number(reserveCaps[0]?.toString()),
|
|
8003
|
-
|
|
8004
|
+
// Aave's 0 = no cap; downstream no cap is undefined (0 reads full)
|
|
8005
|
+
supplyCap: Number(reserveCaps[1]?.toString()) || void 0,
|
|
8004
8006
|
debtCeiling: Number(
|
|
8005
8007
|
parseRawAmount(
|
|
8006
8008
|
debtCeiling?.toString(),
|
|
@@ -30267,7 +30269,9 @@ function convertFlexMarketsToResponse(raw, chainId, prices = {}, additionalYield
|
|
|
30267
30269
|
intrinsicYield: additionalYields?.intrinsicYields?.[collToken?.assetGroup ?? ""] ?? 0,
|
|
30268
30270
|
rewards: void 0,
|
|
30269
30271
|
decimals: collDecimals,
|
|
30270
|
-
|
|
30272
|
+
// Flex has no collateral cap. undefined = uncapped downstream; 0 read as a
|
|
30273
|
+
// full cap (`depositable_long = 0`) and the pairs feed dropped every Flex loop.
|
|
30274
|
+
supplyCap: void 0,
|
|
30271
30275
|
borrowCap: 0,
|
|
30272
30276
|
config: {
|
|
30273
30277
|
0: {
|
|
@@ -68700,6 +68704,88 @@ var curvanceMerklRewardFetcher = {
|
|
|
68700
68704
|
);
|
|
68701
68705
|
}
|
|
68702
68706
|
};
|
|
68707
|
+
var ADDRESS2 = /^0x[0-9a-f]{40}$/;
|
|
68708
|
+
function minusOne(address) {
|
|
68709
|
+
const n = BigInt(address);
|
|
68710
|
+
if (n === 0n) return void 0;
|
|
68711
|
+
return `0x${(n - 1n).toString(16).padStart(40, "0")}`;
|
|
68712
|
+
}
|
|
68713
|
+
function compoundCampaignCandidates(opp) {
|
|
68714
|
+
const out = [];
|
|
68715
|
+
const explorer = opp.explorerAddress?.toLowerCase();
|
|
68716
|
+
if (explorer && ADDRESS2.test(explorer)) out.push(explorer);
|
|
68717
|
+
const id = opp.identifier?.toLowerCase();
|
|
68718
|
+
if (id && ADDRESS2.test(id)) {
|
|
68719
|
+
if (opp.action === "BORROW") {
|
|
68720
|
+
const shifted = minusOne(id);
|
|
68721
|
+
if (shifted) out.push(shifted);
|
|
68722
|
+
}
|
|
68723
|
+
out.push(id);
|
|
68724
|
+
}
|
|
68725
|
+
return [...new Set(out)];
|
|
68726
|
+
}
|
|
68727
|
+
function resolveCompoundOpp(opp, lookup, isOurLender) {
|
|
68728
|
+
if (opp.type === "COMPOUND_V2_BORROW_FROM_COLLATERAL") return void 0;
|
|
68729
|
+
if (isGatedMerklCampaign(opp)) return void 0;
|
|
68730
|
+
const bucket = opp.action === "LEND" ? "deposit" : opp.action === "BORROW" ? "borrow" : void 0;
|
|
68731
|
+
if (!bucket) return void 0;
|
|
68732
|
+
const chainId = String(opp.chainId);
|
|
68733
|
+
for (const address of compoundCampaignCandidates(opp)) {
|
|
68734
|
+
const owner = ownerOf(chainId, address, lookup);
|
|
68735
|
+
if (owner && isOurLender(owner.lender)) return { ...owner, bucket };
|
|
68736
|
+
}
|
|
68737
|
+
return void 0;
|
|
68738
|
+
}
|
|
68739
|
+
function ownerOf(chainId, address, lookup) {
|
|
68740
|
+
const cLender = lookup.cToken(chainId, address);
|
|
68741
|
+
if (cLender) return { lender: cLender, asset: address };
|
|
68742
|
+
const comet = lookup.comet(chainId, address);
|
|
68743
|
+
if (comet) return { lender: comet.lender, asset: comet.baseAsset };
|
|
68744
|
+
return void 0;
|
|
68745
|
+
}
|
|
68746
|
+
function dataSdkCompoundLookup() {
|
|
68747
|
+
const cTokens = /* @__PURE__ */ new Map();
|
|
68748
|
+
for (const [lender, chains] of Object.entries(compoundV2TokenArray() ?? {}))
|
|
68749
|
+
for (const [chainId, rows] of Object.entries(chains ?? {}))
|
|
68750
|
+
for (const r of rows ?? [])
|
|
68751
|
+
if (r?.cToken)
|
|
68752
|
+
cTokens.set(`${chainId}:${r.cToken.toLowerCase()}`, lender);
|
|
68753
|
+
const comets = /* @__PURE__ */ new Map();
|
|
68754
|
+
const base = compoundV3BaseData() ?? {};
|
|
68755
|
+
for (const [chainId, lenders] of Object.entries(compoundV3Pools() ?? {}))
|
|
68756
|
+
for (const [lender, comet] of Object.entries(lenders ?? {})) {
|
|
68757
|
+
const baseAsset = base[lender]?.[chainId]?.baseAsset;
|
|
68758
|
+
if (comet && baseAsset)
|
|
68759
|
+
comets.set(`${chainId}:${comet.toLowerCase()}`, {
|
|
68760
|
+
lender,
|
|
68761
|
+
baseAsset: baseAsset.toLowerCase()
|
|
68762
|
+
});
|
|
68763
|
+
}
|
|
68764
|
+
return {
|
|
68765
|
+
cToken: (chainId, address) => cTokens.get(`${chainId}:${address}`),
|
|
68766
|
+
comet: (chainId, address) => comets.get(`${chainId}:${address}`)
|
|
68767
|
+
};
|
|
68768
|
+
}
|
|
68769
|
+
function collectCompoundRewards(opps, merklProtocolId, lookup) {
|
|
68770
|
+
const isOurLender = merklProtocolId === "venus" ? isVenusType : (l) => l === "COMPOUND_V2" || isCompoundV3(l);
|
|
68771
|
+
return collectMerklRewards([opps], {
|
|
68772
|
+
merklProtocolId,
|
|
68773
|
+
lenderKey: merklProtocolId === "venus" ? "VENUS" : "COMPOUND_V2",
|
|
68774
|
+
resolveAsset: (opp) => resolveCompoundOpp(opp, lookup, isOurLender)
|
|
68775
|
+
});
|
|
68776
|
+
}
|
|
68777
|
+
function compoundFamilyFetcher(merklProtocolId) {
|
|
68778
|
+
return {
|
|
68779
|
+
label: `MERKL_${merklProtocolId.toUpperCase()}`,
|
|
68780
|
+
fetch: async () => collectCompoundRewards(
|
|
68781
|
+
await fetchMerklOpportunities(merklProtocolId),
|
|
68782
|
+
merklProtocolId,
|
|
68783
|
+
dataSdkCompoundLookup()
|
|
68784
|
+
)
|
|
68785
|
+
};
|
|
68786
|
+
}
|
|
68787
|
+
var venusMerklRewardFetcher = compoundFamilyFetcher("venus");
|
|
68788
|
+
var compoundMerklRewardFetcher = compoundFamilyFetcher("compound");
|
|
68703
68789
|
var DLEND_POOLS = [
|
|
68704
68790
|
{
|
|
68705
68791
|
chainId: Chain.ETHEREUM_MAINNET,
|
|
@@ -69330,12 +69416,15 @@ var MAX_BORROWABLE_UTILIZATION = 0.999;
|
|
|
69330
69416
|
var LENDER3 = "LISTA_DAO";
|
|
69331
69417
|
var LISTA_API_CHAIN = {
|
|
69332
69418
|
[Chain.BNB_SMART_CHAIN_MAINNET]: "bsc",
|
|
69333
|
-
[Chain.ETHEREUM_MAINNET]: "ethereum"
|
|
69419
|
+
[Chain.ETHEREUM_MAINNET]: "ethereum",
|
|
69420
|
+
// `rh` / `robinhood_chain` / `robinhoodchain` answer "unsupported chain"
|
|
69421
|
+
[Chain.ROBINHOOD_CHAIN]: "robinhood"
|
|
69334
69422
|
};
|
|
69335
69423
|
var LISTA_CLAIM_CHAIN = Chain.BNB_SMART_CHAIN_MAINNET;
|
|
69336
69424
|
var MOOLAH_FALLBACK = {
|
|
69337
69425
|
[Chain.BNB_SMART_CHAIN_MAINNET]: "0x8F73b65B4caAf64FBA2aF91cC5D4a2A1318E5D8C",
|
|
69338
|
-
[Chain.ETHEREUM_MAINNET]: "0xf820fB4680712CD7263a0D3D024D5b5aEA82Fd70"
|
|
69426
|
+
[Chain.ETHEREUM_MAINNET]: "0xf820fB4680712CD7263a0D3D024D5b5aEA82Fd70",
|
|
69427
|
+
[Chain.ROBINHOOD_CHAIN]: "0xE4153Eb04417bE05b8d6B2222E4Cdd8AE674ee76"
|
|
69339
69428
|
};
|
|
69340
69429
|
var LISTA_SOURCE = {
|
|
69341
69430
|
id: "lista:emission",
|
|
@@ -70021,7 +70110,9 @@ var rewardFetchers = [
|
|
|
70021
70110
|
listaEmissionRewardFetcher,
|
|
70022
70111
|
alchemixMerklRewardFetcher,
|
|
70023
70112
|
curvanceMerklRewardFetcher,
|
|
70024
|
-
aaveV4HubMerklRewardFetcher
|
|
70113
|
+
aaveV4HubMerklRewardFetcher,
|
|
70114
|
+
venusMerklRewardFetcher,
|
|
70115
|
+
compoundMerklRewardFetcher
|
|
70025
70116
|
];
|
|
70026
70117
|
function mergeReserveTokenRewards(target, source) {
|
|
70027
70118
|
for (const [chainId, byToken] of Object.entries(source)) {
|
|
@@ -78846,7 +78937,9 @@ async function fetchFlashLiquidityForChain(chain, multicallRetry, list = {}) {
|
|
|
78846
78937
|
});
|
|
78847
78938
|
const lendingAssets = RELEVANT_LENDING_ASSETS()?.[chain] ?? [];
|
|
78848
78939
|
const unifiedAssets = lodash.uniq([...allAaveUnderlyings, ...lendingAssets]);
|
|
78849
|
-
const morphoBs = RELEVANT_MORPHOB_FORKS()?.[chain] ?? []
|
|
78940
|
+
const morphoBs = (RELEVANT_MORPHOB_FORKS()?.[chain] ?? []).filter(
|
|
78941
|
+
(f) => !isFlashLoanSourceExcluded(chain, f.pool)
|
|
78942
|
+
);
|
|
78850
78943
|
const buildBalanceCalls = (forks) => {
|
|
78851
78944
|
const result = [];
|
|
78852
78945
|
for (const fork of forks) {
|