@1delta/margin-fetcher 5.0.161 → 5.0.163
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 +24 -6
- package/dist/index.js +166 -31
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -237,9 +237,9 @@ interface PoolData {
|
|
|
237
237
|
totalDebt: string;
|
|
238
238
|
totalLiquidity: number;
|
|
239
239
|
/**
|
|
240
|
-
* Cap-adjusted borrow liquidity in token units
|
|
241
|
-
* `min(totalLiquidity, max(0, borrowCap - totalDebt))` when
|
|
242
|
-
*
|
|
240
|
+
* Cap-adjusted borrow liquidity in token units:
|
|
241
|
+
* `min(totalLiquidity, max(0, borrowCap - totalDebt))` when a cap is set,
|
|
242
|
+
* `totalLiquidity` when `borrowCap` is undefined (uncapped).
|
|
243
243
|
*/
|
|
244
244
|
borrowLiquidity: number;
|
|
245
245
|
totalDepositsUSD: number;
|
|
@@ -290,7 +290,22 @@ interface PoolData {
|
|
|
290
290
|
hasStable: boolean;
|
|
291
291
|
isActive: boolean;
|
|
292
292
|
isFrozen: boolean;
|
|
293
|
-
|
|
293
|
+
/**
|
|
294
|
+
* Total-debt ceiling in TOKEN units. No cap is `undefined`, never 0:
|
|
295
|
+
* yield-tracer re-caps `borrow_liquidity` at `borrowCap − totalDebt` whenever
|
|
296
|
+
* the field is set, so 0 reads as a CLOSED market (Aave forks, Alchemix and
|
|
297
|
+
* Flex all shipped uncapped debt legs that way, 2026-11-24). 0 is right only
|
|
298
|
+
* where new borrows really are shut (Euler `caps()` raw 6, a matured term).
|
|
299
|
+
*/
|
|
300
|
+
borrowCap?: number;
|
|
301
|
+
/**
|
|
302
|
+
* Remaining-deposit ceiling in TOKEN units. No cap is `undefined`, never 0:
|
|
303
|
+
* yield-tracer stores `depositable = supplyCap − totalDeposits` whenever the
|
|
304
|
+
* field is set, so 0 reads as a FULL cap and the pairs feed drops every pair
|
|
305
|
+
* on the leg (Flex shipped that way, TODO.md 2026-11-23). 0 is only right on
|
|
306
|
+
* a leg that is closed to deposits (cap 0 plus the flag) or one nobody
|
|
307
|
+
* deposits into (a minted debt token).
|
|
308
|
+
*/
|
|
294
309
|
supplyCap: number;
|
|
295
310
|
debtCeiling: string;
|
|
296
311
|
/**
|
|
@@ -5919,7 +5934,9 @@ declare function alchemixRedemptionPace(m: AlchemixMarketRaw, chainId: string):
|
|
|
5919
5934
|
* `totalDeposits` is 0. There is NO interest: `variableBorrowRate` is 0
|
|
5920
5935
|
* with `rateModel: 'zeroInterest'`. The borrower's cost is the redemption
|
|
5921
5936
|
* fee on EARMARKED debt (a fee per redemption, not an APR — it rides in
|
|
5922
|
-
* `alchemix.protocolFeeBps`) plus
|
|
5937
|
+
* `alchemix.protocolFeeBps`) plus the discount the alAsset trades at, both
|
|
5938
|
+
* lost on the part a redemption settles at face: a year's worth of that is
|
|
5939
|
+
* the row's `originationFee` (`alchemix.settlementCostPct`).
|
|
5923
5940
|
* `borrowLiquidity` is the headroom the market could still mint if its
|
|
5924
5941
|
* deposit cap were filled at max LTV (there is no separate debt ceiling).
|
|
5925
5942
|
*
|
|
@@ -5930,7 +5947,8 @@ declare function alchemixRedemptionPace(m: AlchemixMarketRaw, chainId: string):
|
|
|
5930
5947
|
* USD price, so the USD totals and every health figure built on them agree
|
|
5931
5948
|
* with the contract. The alAsset's MARKET price is lower (alUSD ≈ 0.955,
|
|
5932
5949
|
* alETH ≈ 0.975 ETH on 2026-10-19); that discount is a borrower cost and a
|
|
5933
|
-
* deleverage opportunity, never an input to health. It
|
|
5950
|
+
* deleverage opportunity, never an input to health. It enters the borrow
|
|
5951
|
+
* cost (`originationFee`, above) and the
|
|
5934
5952
|
* alAsset's BORROW-CAPACITY weight (`borrowFactor` = face / market, with
|
|
5935
5953
|
* `liquidationBorrowFactor: 1`), because a loop can only add as much
|
|
5936
5954
|
* collateral as the sold debt buys.
|
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';
|
|
@@ -7558,8 +7558,11 @@ var getAaveV3ReservesDataConverter = (lender, chainId, prices, additionalYields,
|
|
|
7558
7558
|
isActive: configData?.[8 /* isActive */],
|
|
7559
7559
|
isFrozen: configData?.[9 /* isFrozen */],
|
|
7560
7560
|
// caps
|
|
7561
|
-
|
|
7562
|
-
|
|
7561
|
+
// Aave's 0 = no cap; downstream no cap is undefined — yield-tracer
|
|
7562
|
+
// re-caps borrow_liquidity at `borrow_cap − debt` whenever it is set,
|
|
7563
|
+
// so a 0 zeroed every uncapped reserve (Spark DAI/USDS, Avalon, …)
|
|
7564
|
+
borrowCap: Number(reserveCaps[0]?.toString()) || void 0,
|
|
7565
|
+
supplyCap: Number(reserveCaps[1]?.toString()) || void 0,
|
|
7563
7566
|
debtCeiling: Number(
|
|
7564
7567
|
parseRawAmount(
|
|
7565
7568
|
debtCeiling?.toString(),
|
|
@@ -7999,8 +8002,9 @@ function parseAave32(chainId, lender, prices, additionalYields, tokenList) {
|
|
|
7999
8002
|
isActive: configData?.[8 /* isActive */],
|
|
8000
8003
|
isFrozen: configData?.[9 /* isFrozen */],
|
|
8001
8004
|
// caps
|
|
8002
|
-
|
|
8003
|
-
|
|
8005
|
+
// Aave's 0 = no cap; downstream no cap is undefined (0 reads closed)
|
|
8006
|
+
borrowCap: Number(reserveCaps[0]?.toString()) || void 0,
|
|
8007
|
+
supplyCap: Number(reserveCaps[1]?.toString()) || void 0,
|
|
8004
8008
|
debtCeiling: Number(
|
|
8005
8009
|
parseRawAmount(
|
|
8006
8010
|
debtCeiling?.toString(),
|
|
@@ -8090,10 +8094,9 @@ var getInitReservesDataConverter = (lender, chainId, prices, additionalYields, t
|
|
|
8090
8094
|
if (!poolId) return;
|
|
8091
8095
|
const marketUid = createMarketUid(chainId, lender, poolId);
|
|
8092
8096
|
const name = INIT_POOL_NAME_OVERRIDES[poolId.toLowerCase()] ?? lenderShortName(lender) + " " + (meta?.symbol ?? "");
|
|
8093
|
-
const borrowCap = Number(
|
|
8094
|
-
dat?.borrowCap.toString(),
|
|
8095
|
-
|
|
8096
|
-
));
|
|
8097
|
+
const borrowCap = Number(
|
|
8098
|
+
parseRawAmount(dat?.borrowCap.toString(), meta.decimals)
|
|
8099
|
+
);
|
|
8097
8100
|
const borrowLiq = borrowCap > 0 ? Math.min(liquidity, Math.max(0, borrowCap - Number(totalDebt))) : liquidity;
|
|
8098
8101
|
result[asset] = {
|
|
8099
8102
|
marketUid,
|
|
@@ -8101,7 +8104,8 @@ var getInitReservesDataConverter = (lender, chainId, prices, additionalYields, t
|
|
|
8101
8104
|
poolId: asset,
|
|
8102
8105
|
underlying: asset,
|
|
8103
8106
|
asset: meta,
|
|
8104
|
-
|
|
8107
|
+
// Init's 0 = no cap; downstream no cap is undefined (0 reads closed)
|
|
8108
|
+
borrowCap: borrowCap > 0 ? borrowCap : void 0,
|
|
8105
8109
|
canBurn: Boolean(dat?.canBurn),
|
|
8106
8110
|
canFlash: Boolean(dat?.canFlash),
|
|
8107
8111
|
canMint: Boolean(dat?.canMint),
|
|
@@ -8330,7 +8334,9 @@ var getCompoundV3ReservesDataConverter = (lender, chainId, prices, additionalYie
|
|
|
8330
8334
|
// collateral factots
|
|
8331
8335
|
borrowCollateralFactor: 0,
|
|
8332
8336
|
collateralFactor: 0,
|
|
8333
|
-
|
|
8337
|
+
// Comet caps collateral only — the base (the lend side) has no supply
|
|
8338
|
+
// cap, and 0 reads downstream as a FULL one (`canDeposit: false`).
|
|
8339
|
+
supplyCap: void 0,
|
|
8334
8340
|
config: {
|
|
8335
8341
|
[LENDER_MODE_NO_MODE]: {
|
|
8336
8342
|
category: LENDER_MODE_NO_MODE,
|
|
@@ -19784,7 +19790,7 @@ var getEulerV2ReservesDataConverter = (lender, chainId, prices, additionalYields
|
|
|
19784
19790
|
totalLiquidity: String(totalLiquidity),
|
|
19785
19791
|
...(() => {
|
|
19786
19792
|
const bc = entry2.borrowCap;
|
|
19787
|
-
const bl =
|
|
19793
|
+
const bl = Math.min(totalLiquidity, Math.max(0, bc - totalDebt));
|
|
19788
19794
|
return {
|
|
19789
19795
|
borrowLiquidity: bl,
|
|
19790
19796
|
borrowLiquidityUSD: bl * price2
|
|
@@ -19969,6 +19975,10 @@ function toTokenNumber(raw, decimals) {
|
|
|
19969
19975
|
}
|
|
19970
19976
|
var RAY3 = 1e27;
|
|
19971
19977
|
var MAX_SPOKE_CAP = 2 ** 40 - 1;
|
|
19978
|
+
function publishedCap(bindingExists, cap) {
|
|
19979
|
+
if (!bindingExists || cap >= MAX_SPOKE_CAP) return void 0;
|
|
19980
|
+
return cap;
|
|
19981
|
+
}
|
|
19972
19982
|
var RAY_BIGINT = 10n ** 27n;
|
|
19973
19983
|
function rayRateToApr(rateRay) {
|
|
19974
19984
|
if (rateRay === 0n) return 0;
|
|
@@ -20152,8 +20162,11 @@ function normalizeAaveV4(spokeDataList, chainId, spokeLenderKeyArg, prices, addi
|
|
|
20152
20162
|
hasStable: false,
|
|
20153
20163
|
isActive: !reserve.config.paused,
|
|
20154
20164
|
isFrozen: reserve.config.frozen,
|
|
20155
|
-
|
|
20156
|
-
|
|
20165
|
+
// Published caps: 0 only where the binding really blocks (yield-tracer
|
|
20166
|
+
// reads a set cap as `cap − total`, so 0 = closed); MAX_SPOKE_CAP and
|
|
20167
|
+
// an unknown binding are uncapped → undefined.
|
|
20168
|
+
borrowCap: publishedCap(bindingExists, borrowCap),
|
|
20169
|
+
supplyCap: publishedCap(bindingExists, supplyCap),
|
|
20157
20170
|
debtCeiling: 0,
|
|
20158
20171
|
// No close factor in V4 — the ceiling is the whole debt.
|
|
20159
20172
|
closeFactor: 1,
|
|
@@ -29301,7 +29314,7 @@ function convertRipeMarketsToResponse(raw, chainId, prices = {}, additionalYield
|
|
|
29301
29314
|
const token = tokens[a.address];
|
|
29302
29315
|
const totalDeposits = toHuman5(a.totalDeposited, decimals);
|
|
29303
29316
|
const capped2 = a.globalDepositLimit < UNCAPPED;
|
|
29304
|
-
const globalCap = capped2 ? toHuman5(a.globalDepositLimit, decimals) : 0;
|
|
29317
|
+
const globalCap = capped2 ? toHuman5(a.globalDepositLimit, decimals) : void 0;
|
|
29305
29318
|
const roomLeft = capped2 ? Math.max(0, globalCap - totalDeposits) : Infinity;
|
|
29306
29319
|
const allowlisted = a.whitelist !== zeroAddress;
|
|
29307
29320
|
const depositsEnabled = protocolCanDeposit && a.canDeposit && !allowlisted && roomLeft > 0;
|
|
@@ -29709,6 +29722,9 @@ function convertAlchemixMarketsToResponse(raw, chainId, prices = {}, additionalY
|
|
|
29709
29722
|
const borrowLiquidity = borrowingEnabled ? Math.max(0, maxMarketDebt - totalDebt) : 0;
|
|
29710
29723
|
const pace = alchemixRedemptionPace(m, chainId);
|
|
29711
29724
|
const t = m.transmuter;
|
|
29725
|
+
const pegDiscount = 1 - debtSaleRatio;
|
|
29726
|
+
const settledPerYear = Math.min(1, pace?.redemptionRate ?? 1);
|
|
29727
|
+
const settlementCost = (pegDiscount + m.protocolFee / BPS3) * settledPerYear * 100;
|
|
29712
29728
|
const entry2 = { data: {} };
|
|
29713
29729
|
const collUid = createMarketUid(chainId, lenderKey, myt2);
|
|
29714
29730
|
entry2.data[collUid] = {
|
|
@@ -29786,14 +29802,17 @@ function convertAlchemixMarketsToResponse(raw, chainId, prices = {}, additionalY
|
|
|
29786
29802
|
variableBorrowRate: 0,
|
|
29787
29803
|
stableBorrowRate: 0,
|
|
29788
29804
|
rateModel: "zeroInterest",
|
|
29789
|
-
//
|
|
29790
|
-
// a
|
|
29791
|
-
|
|
29805
|
+
// Not charged at open: the expected cost of settling the debt at face
|
|
29806
|
+
// within a year (`settlementCost` above), in the one field the pair book
|
|
29807
|
+
// amortizes into the borrow rate.
|
|
29808
|
+
originationFee: settlementCost,
|
|
29792
29809
|
intrinsicYield: 0,
|
|
29793
29810
|
rewards: void 0,
|
|
29794
29811
|
decimals: debtDecimals,
|
|
29795
29812
|
supplyCap: 0,
|
|
29796
|
-
|
|
29813
|
+
// The ceiling is already in `borrowLiquidity` (deposit-cap headroom × LTV).
|
|
29814
|
+
// A 0 here is read downstream as a CLOSED cap and zeroes the debt leg.
|
|
29815
|
+
borrowCap: void 0,
|
|
29797
29816
|
config: {
|
|
29798
29817
|
0: {
|
|
29799
29818
|
category: 0,
|
|
@@ -29889,6 +29908,12 @@ function convertAlchemixMarketsToResponse(raw, chainId, prices = {}, additionalY
|
|
|
29889
29908
|
* redeemed pays `protocolFeeBps` once.
|
|
29890
29909
|
*/
|
|
29891
29910
|
redemptionRatePerYear: pace?.redemptionRate,
|
|
29911
|
+
/** The alAsset's market price over face (≤ 1; 1 = no market feed). */
|
|
29912
|
+
debtSaleRatio,
|
|
29913
|
+
/** `1 − debtSaleRatio`, PERCENT: lost on each unit settled at face. */
|
|
29914
|
+
pegDiscountPct: pegDiscount * 100,
|
|
29915
|
+
/** Expected cost of a year's redemptions, PERCENT of the debt (= the row's `originationFee`). */
|
|
29916
|
+
settlementCostPct: settlementCost,
|
|
29892
29917
|
/** alAsset redeemed per year at the current queue, human units. */
|
|
29893
29918
|
redeemedPerYear: pace?.redeemedPerYear
|
|
29894
29919
|
}
|
|
@@ -30267,7 +30292,9 @@ function convertFlexMarketsToResponse(raw, chainId, prices = {}, additionalYield
|
|
|
30267
30292
|
intrinsicYield: additionalYields?.intrinsicYields?.[collToken?.assetGroup ?? ""] ?? 0,
|
|
30268
30293
|
rewards: void 0,
|
|
30269
30294
|
decimals: collDecimals,
|
|
30270
|
-
|
|
30295
|
+
// Flex has no collateral cap. undefined = uncapped downstream; 0 read as a
|
|
30296
|
+
// full cap (`depositable_long = 0`) and the pairs feed dropped every Flex loop.
|
|
30297
|
+
supplyCap: void 0,
|
|
30271
30298
|
borrowCap: 0,
|
|
30272
30299
|
config: {
|
|
30273
30300
|
0: {
|
|
@@ -30320,7 +30347,9 @@ function convertFlexMarketsToResponse(raw, chainId, prices = {}, additionalYield
|
|
|
30320
30347
|
rewards: void 0,
|
|
30321
30348
|
decimals: borrowDecimals,
|
|
30322
30349
|
supplyCap: depositRoom !== void 0 ? lenderAssets + depositRoom : void 0,
|
|
30323
|
-
|
|
30350
|
+
// No debt cap: `borrowLiquidity` is the Lender's idle cash. A 0 here is
|
|
30351
|
+
// read downstream as a CLOSED cap and zeroes the borrow leg.
|
|
30352
|
+
borrowCap: void 0,
|
|
30324
30353
|
config: {
|
|
30325
30354
|
0: {
|
|
30326
30355
|
category: 0,
|
|
@@ -68700,6 +68729,88 @@ var curvanceMerklRewardFetcher = {
|
|
|
68700
68729
|
);
|
|
68701
68730
|
}
|
|
68702
68731
|
};
|
|
68732
|
+
var ADDRESS2 = /^0x[0-9a-f]{40}$/;
|
|
68733
|
+
function minusOne(address) {
|
|
68734
|
+
const n = BigInt(address);
|
|
68735
|
+
if (n === 0n) return void 0;
|
|
68736
|
+
return `0x${(n - 1n).toString(16).padStart(40, "0")}`;
|
|
68737
|
+
}
|
|
68738
|
+
function compoundCampaignCandidates(opp) {
|
|
68739
|
+
const out = [];
|
|
68740
|
+
const explorer = opp.explorerAddress?.toLowerCase();
|
|
68741
|
+
if (explorer && ADDRESS2.test(explorer)) out.push(explorer);
|
|
68742
|
+
const id = opp.identifier?.toLowerCase();
|
|
68743
|
+
if (id && ADDRESS2.test(id)) {
|
|
68744
|
+
if (opp.action === "BORROW") {
|
|
68745
|
+
const shifted = minusOne(id);
|
|
68746
|
+
if (shifted) out.push(shifted);
|
|
68747
|
+
}
|
|
68748
|
+
out.push(id);
|
|
68749
|
+
}
|
|
68750
|
+
return [...new Set(out)];
|
|
68751
|
+
}
|
|
68752
|
+
function resolveCompoundOpp(opp, lookup, isOurLender) {
|
|
68753
|
+
if (opp.type === "COMPOUND_V2_BORROW_FROM_COLLATERAL") return void 0;
|
|
68754
|
+
if (isGatedMerklCampaign(opp)) return void 0;
|
|
68755
|
+
const bucket = opp.action === "LEND" ? "deposit" : opp.action === "BORROW" ? "borrow" : void 0;
|
|
68756
|
+
if (!bucket) return void 0;
|
|
68757
|
+
const chainId = String(opp.chainId);
|
|
68758
|
+
for (const address of compoundCampaignCandidates(opp)) {
|
|
68759
|
+
const owner = ownerOf(chainId, address, lookup);
|
|
68760
|
+
if (owner && isOurLender(owner.lender)) return { ...owner, bucket };
|
|
68761
|
+
}
|
|
68762
|
+
return void 0;
|
|
68763
|
+
}
|
|
68764
|
+
function ownerOf(chainId, address, lookup) {
|
|
68765
|
+
const cLender = lookup.cToken(chainId, address);
|
|
68766
|
+
if (cLender) return { lender: cLender, asset: address };
|
|
68767
|
+
const comet = lookup.comet(chainId, address);
|
|
68768
|
+
if (comet) return { lender: comet.lender, asset: comet.baseAsset };
|
|
68769
|
+
return void 0;
|
|
68770
|
+
}
|
|
68771
|
+
function dataSdkCompoundLookup() {
|
|
68772
|
+
const cTokens = /* @__PURE__ */ new Map();
|
|
68773
|
+
for (const [lender, chains] of Object.entries(compoundV2TokenArray() ?? {}))
|
|
68774
|
+
for (const [chainId, rows] of Object.entries(chains ?? {}))
|
|
68775
|
+
for (const r of rows ?? [])
|
|
68776
|
+
if (r?.cToken)
|
|
68777
|
+
cTokens.set(`${chainId}:${r.cToken.toLowerCase()}`, lender);
|
|
68778
|
+
const comets = /* @__PURE__ */ new Map();
|
|
68779
|
+
const base = compoundV3BaseData() ?? {};
|
|
68780
|
+
for (const [chainId, lenders] of Object.entries(compoundV3Pools() ?? {}))
|
|
68781
|
+
for (const [lender, comet] of Object.entries(lenders ?? {})) {
|
|
68782
|
+
const baseAsset = base[lender]?.[chainId]?.baseAsset;
|
|
68783
|
+
if (comet && baseAsset)
|
|
68784
|
+
comets.set(`${chainId}:${comet.toLowerCase()}`, {
|
|
68785
|
+
lender,
|
|
68786
|
+
baseAsset: baseAsset.toLowerCase()
|
|
68787
|
+
});
|
|
68788
|
+
}
|
|
68789
|
+
return {
|
|
68790
|
+
cToken: (chainId, address) => cTokens.get(`${chainId}:${address}`),
|
|
68791
|
+
comet: (chainId, address) => comets.get(`${chainId}:${address}`)
|
|
68792
|
+
};
|
|
68793
|
+
}
|
|
68794
|
+
function collectCompoundRewards(opps, merklProtocolId, lookup) {
|
|
68795
|
+
const isOurLender = merklProtocolId === "venus" ? isVenusType : (l) => l === "COMPOUND_V2" || isCompoundV3(l);
|
|
68796
|
+
return collectMerklRewards([opps], {
|
|
68797
|
+
merklProtocolId,
|
|
68798
|
+
lenderKey: merklProtocolId === "venus" ? "VENUS" : "COMPOUND_V2",
|
|
68799
|
+
resolveAsset: (opp) => resolveCompoundOpp(opp, lookup, isOurLender)
|
|
68800
|
+
});
|
|
68801
|
+
}
|
|
68802
|
+
function compoundFamilyFetcher(merklProtocolId) {
|
|
68803
|
+
return {
|
|
68804
|
+
label: `MERKL_${merklProtocolId.toUpperCase()}`,
|
|
68805
|
+
fetch: async () => collectCompoundRewards(
|
|
68806
|
+
await fetchMerklOpportunities(merklProtocolId),
|
|
68807
|
+
merklProtocolId,
|
|
68808
|
+
dataSdkCompoundLookup()
|
|
68809
|
+
)
|
|
68810
|
+
};
|
|
68811
|
+
}
|
|
68812
|
+
var venusMerklRewardFetcher = compoundFamilyFetcher("venus");
|
|
68813
|
+
var compoundMerklRewardFetcher = compoundFamilyFetcher("compound");
|
|
68703
68814
|
var DLEND_POOLS = [
|
|
68704
68815
|
{
|
|
68705
68816
|
chainId: Chain.ETHEREUM_MAINNET,
|
|
@@ -69330,12 +69441,15 @@ var MAX_BORROWABLE_UTILIZATION = 0.999;
|
|
|
69330
69441
|
var LENDER3 = "LISTA_DAO";
|
|
69331
69442
|
var LISTA_API_CHAIN = {
|
|
69332
69443
|
[Chain.BNB_SMART_CHAIN_MAINNET]: "bsc",
|
|
69333
|
-
[Chain.ETHEREUM_MAINNET]: "ethereum"
|
|
69444
|
+
[Chain.ETHEREUM_MAINNET]: "ethereum",
|
|
69445
|
+
// `rh` / `robinhood_chain` / `robinhoodchain` answer "unsupported chain"
|
|
69446
|
+
[Chain.ROBINHOOD_CHAIN]: "robinhood"
|
|
69334
69447
|
};
|
|
69335
69448
|
var LISTA_CLAIM_CHAIN = Chain.BNB_SMART_CHAIN_MAINNET;
|
|
69336
69449
|
var MOOLAH_FALLBACK = {
|
|
69337
69450
|
[Chain.BNB_SMART_CHAIN_MAINNET]: "0x8F73b65B4caAf64FBA2aF91cC5D4a2A1318E5D8C",
|
|
69338
|
-
[Chain.ETHEREUM_MAINNET]: "0xf820fB4680712CD7263a0D3D024D5b5aEA82Fd70"
|
|
69451
|
+
[Chain.ETHEREUM_MAINNET]: "0xf820fB4680712CD7263a0D3D024D5b5aEA82Fd70",
|
|
69452
|
+
[Chain.ROBINHOOD_CHAIN]: "0xE4153Eb04417bE05b8d6B2222E4Cdd8AE674ee76"
|
|
69339
69453
|
};
|
|
69340
69454
|
var LISTA_SOURCE = {
|
|
69341
69455
|
id: "lista:emission",
|
|
@@ -70021,7 +70135,9 @@ var rewardFetchers = [
|
|
|
70021
70135
|
listaEmissionRewardFetcher,
|
|
70022
70136
|
alchemixMerklRewardFetcher,
|
|
70023
70137
|
curvanceMerklRewardFetcher,
|
|
70024
|
-
aaveV4HubMerklRewardFetcher
|
|
70138
|
+
aaveV4HubMerklRewardFetcher,
|
|
70139
|
+
venusMerklRewardFetcher,
|
|
70140
|
+
compoundMerklRewardFetcher
|
|
70025
70141
|
];
|
|
70026
70142
|
function mergeReserveTokenRewards(target, source) {
|
|
70027
70143
|
for (const [chainId, byToken] of Object.entries(source)) {
|
|
@@ -78846,7 +78962,9 @@ async function fetchFlashLiquidityForChain(chain, multicallRetry, list = {}) {
|
|
|
78846
78962
|
});
|
|
78847
78963
|
const lendingAssets = RELEVANT_LENDING_ASSETS()?.[chain] ?? [];
|
|
78848
78964
|
const unifiedAssets = lodash.uniq([...allAaveUnderlyings, ...lendingAssets]);
|
|
78849
|
-
const morphoBs = RELEVANT_MORPHOB_FORKS()?.[chain] ?? []
|
|
78965
|
+
const morphoBs = (RELEVANT_MORPHOB_FORKS()?.[chain] ?? []).filter(
|
|
78966
|
+
(f) => !isFlashLoanSourceExcluded(chain, f.pool)
|
|
78967
|
+
);
|
|
78850
78968
|
const buildBalanceCalls = (forks) => {
|
|
78851
78969
|
const result = [];
|
|
78852
78970
|
for (const fork of forks) {
|
|
@@ -103701,6 +103819,18 @@ var alchemixAdapter = {
|
|
|
103701
103819
|
cap: 1e4,
|
|
103702
103820
|
description: "Taken from your collateral on the part of your debt that redemptions settle; the rest of the debt pays nothing."
|
|
103703
103821
|
});
|
|
103822
|
+
const pegDiscountPct = num19(a.pegDiscountPct);
|
|
103823
|
+
if (pegDiscountPct != null && pegDiscountPct > 0)
|
|
103824
|
+
fees2.push({
|
|
103825
|
+
id: "peg-discount",
|
|
103826
|
+
label: "Settled at par",
|
|
103827
|
+
when: "ongoing",
|
|
103828
|
+
unit: "percent",
|
|
103829
|
+
basis: "debt-repaid",
|
|
103830
|
+
value: pegDiscountPct,
|
|
103831
|
+
mutable: true,
|
|
103832
|
+
description: `The debt sells for ${(100 - pegDiscountPct).toFixed(1)}% of face when you borrow it, and redemptions settle it at 100% against your collateral: ${pegDiscountPct.toFixed(1)}% lost on every unit they settle. Repaying it yourself at market costs only the spread.`
|
|
103833
|
+
});
|
|
103704
103834
|
if (liquidatorFeeBps != null)
|
|
103705
103835
|
fees2.push({
|
|
103706
103836
|
id: "liquidation-bonus",
|
|
@@ -103796,10 +103926,10 @@ var alchemixAdapter = {
|
|
|
103796
103926
|
driver: "below-peg",
|
|
103797
103927
|
// Earmarks are proportional to debt across EVERY position.
|
|
103798
103928
|
order: "pro-rata",
|
|
103799
|
-
// Debt is cancelled against collateral at face
|
|
103800
|
-
//
|
|
103929
|
+
// Debt is cancelled against collateral at face: the borrower loses
|
|
103930
|
+
// the redemption fee and, below peg, the discount on that part.
|
|
103801
103931
|
valueImpact: "loss",
|
|
103802
|
-
defence: "Nothing exempts a position \u2014 redemptions are spread over every borrower in proportion to debt. They settle debt against your collateral at face value, so your LTV does not rise; the cost is the redemption fee on the settled part."
|
|
103932
|
+
defence: "Nothing exempts a position \u2014 redemptions are spread over every borrower in proportion to debt. They settle debt against your collateral at face value, so your LTV does not rise; the cost is the redemption fee on the settled part, plus the discount the debt token trades at while it is below peg."
|
|
103803
103933
|
}
|
|
103804
103934
|
},
|
|
103805
103935
|
fees: fees2,
|
|
@@ -103817,6 +103947,8 @@ var alchemixAdapter = {
|
|
|
103817
103947
|
debtValuation: "face",
|
|
103818
103948
|
redemptionFeeBps: protocolFeeBps,
|
|
103819
103949
|
redemptionRatePerYear: num19(a.redemptionRatePerYear),
|
|
103950
|
+
pegDiscountPct,
|
|
103951
|
+
settlementCostPct: num19(a.settlementCostPct),
|
|
103820
103952
|
transmuterTermSecs: termSecs,
|
|
103821
103953
|
transmuterTermBlocks: num19(a.transmuterQueue?.termBlocks)
|
|
103822
103954
|
}
|
|
@@ -103827,9 +103959,12 @@ var alchemixAdapter = {
|
|
|
103827
103959
|
positionModel: "nft",
|
|
103828
103960
|
positionIdMeaning: "The tokenId of the Alchemist\u2019s position NFT \u2014 one isolated position per token, many per wallet. Only the token\u2019s owner can withdraw or borrow from it directly; anyone may deposit into it or repay it."
|
|
103829
103961
|
},
|
|
103830
|
-
|
|
103831
|
-
|
|
103832
|
-
|
|
103962
|
+
// Without a market feed for the alAsset the discount is unknown, not 0.
|
|
103963
|
+
...num19(a.debtSaleRatio) != null && a.debtSaleRatio < 1 ? {} : {
|
|
103964
|
+
coverage: {
|
|
103965
|
+
pending: {
|
|
103966
|
+
"borrow.marketDiscount": "alasset-market-price-not-wired-debt-is-stated-at-face"
|
|
103967
|
+
}
|
|
103833
103968
|
}
|
|
103834
103969
|
}
|
|
103835
103970
|
};
|