@1delta/margin-fetcher 5.0.8 → 5.0.10

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 CHANGED
@@ -33,6 +33,50 @@ interface RewardEntry$1 extends BaseYields$1 {
33
33
  asset: string;
34
34
  }
35
35
  type RewardsList$1 = RewardEntry$1[];
36
+ /**
37
+ * The knob the BORROWER turns at open, when this config's numbers depend on one.
38
+ *
39
+ * Absent on every protocol whose factors are constants (Aave, Morpho, Compound…).
40
+ * Present where a per-loan choice moves them — LlamaLend's band count `N` moves
41
+ * the collateral factor; Liquity's chosen interest rate moves the cost.
42
+ *
43
+ * This describes the DOMAIN only. The value a given position actually chose is
44
+ * per-position and lives in the user-data `modes[posId]` slot — it cannot live
45
+ * here, because a lender with sub-accounts (Liquity troves, TermMax GTs) has
46
+ * several live values in one market at once.
47
+ *
48
+ * `kind` is what tells a consumer how to READ that number: without it a UI
49
+ * renders a band count of 15 as "e-mode 15", since `modes` historically only
50
+ * ever carried e-mode categories.
51
+ *
52
+ * See POSITION_PARAMETERS_PLAN.md.
53
+ */
54
+ interface OpenParameter {
55
+ /** Discriminator — how to interpret the matching `modes[posId]` value. */
56
+ kind: 'llamalend-bands' | 'interest-rate';
57
+ /** Which of this config's numbers moves with the parameter. */
58
+ dimension: 'collateralFactor' | 'rate';
59
+ /** Allowed values: a continuous range, or a discrete set. */
60
+ domain: {
61
+ min: number;
62
+ max: number;
63
+ } | {
64
+ values: number[];
65
+ };
66
+ /**
67
+ * The value THIS config's numbers were computed at. A consumer that quotes a
68
+ * different value must recompute — it must not reuse `collateralFactor`.
69
+ */
70
+ default: number;
71
+ /**
72
+ * `true` ⇒ fixed for the life of the loan; changing it means close & reopen
73
+ * (LlamaLend — `_add_collateral_borrow` reuses the tick width).
74
+ * `false` ⇒ adjustable in place (Liquity), subject to the friction below.
75
+ */
76
+ immutableAfterOpen: boolean;
77
+ /** Adjustment cooldown, when mutable (Liquity `interestRateAdjCooldownSeconds`). */
78
+ adjustCooldownSeconds?: number;
79
+ }
36
80
  interface ConfigEntry {
37
81
  category: number;
38
82
  borrowCollateralFactor: number;
@@ -63,6 +107,8 @@ interface ConfigEntry {
63
107
  targetHealthFactor?: number;
64
108
  collateralDisabled?: boolean;
65
109
  debtDisabled?: boolean;
110
+ /** Borrower-chosen open-time parameter this config's numbers depend on. */
111
+ openParameter?: OpenParameter;
66
112
  }
67
113
  interface PoolConfig {
68
114
  [category: string]: ConfigEntry;
@@ -630,6 +676,12 @@ interface LenderConfigData {
630
676
  targetHealthFactor?: number;
631
677
  collateralDisabled?: boolean;
632
678
  debtDisabled?: boolean;
679
+ /**
680
+ * Borrower-chosen open-time parameter this config's numbers depend on.
681
+ * Mirrors the API-side `ConfigEntry.openParameter`; see
682
+ * POSITION_PARAMETERS_PLAN.md.
683
+ */
684
+ openParameter?: OpenParameter;
633
685
  }
634
686
  interface ModeBase {
635
687
  category: number;
@@ -2299,11 +2351,45 @@ interface LenderRewards {
2299
2351
  };
2300
2352
  };
2301
2353
  }
2354
+ /**
2355
+ * Rewards keyed by the RESERVE TOKEN the campaign pays on — the aToken for a
2356
+ * supply campaign, the variable debt token for a borrow one.
2357
+ *
2358
+ * Why this exists: a protocol's Merkl campaigns cover every deployment under
2359
+ * one `mainProtocolId` ("aave" spans V3 mainnet, Horizon, Prime, Ether.fi and
2360
+ * every V4 hub/spoke), and nothing in the opportunity payload names the
2361
+ * deployment reliably — `depositUrl`'s `marketName` is wrong on at least one
2362
+ * live campaign ("Borrow USDC on Aave" claims `proto_mainnet` while paying on
2363
+ * `variableDebtHorRwaUSDC`, i.e. Horizon). Attributing by (lender, underlying)
2364
+ * therefore collapsed every deployment's campaign onto the base lender key and
2365
+ * SUMMED them: Aave V3 USDC read 5.75% borrow (1.75 + 2 + 2 across three
2366
+ * deployments) and V3 USDG read 12% (two V4 hubs), while Horizon/Prime/V4
2367
+ * markets read 0%.
2368
+ *
2369
+ * The reserve token is unambiguous — it exists in exactly one market of exactly
2370
+ * one deployment. Consumers hold the other half of the join already: Aave-type
2371
+ * market nodes carry `params.metadata.{aToken, vToken}`, so matching on those
2372
+ * lands each campaign on exactly one marketUid, and cross-deployment summing
2373
+ * becomes impossible by construction.
2374
+ */
2375
+ interface RewardsByReserveToken {
2376
+ /** chainId → lowercased reserve-token address → reward */
2377
+ [chainId: string]: {
2378
+ [reserveToken: string]: LenderAssetReward;
2379
+ };
2380
+ }
2302
2381
  interface YieldDataWithTimestamp {
2303
2382
  intrinsicYields: {
2304
2383
  [asset: string]: number | undefined;
2305
2384
  };
2306
2385
  lenderRewards: LenderRewards;
2386
+ /**
2387
+ * Reserve-token-keyed rewards for protocols whose campaigns cannot be
2388
+ * attributed to a deployment from the campaign payload alone (Aave).
2389
+ * Those protocols are absent from `lenderRewards` — better no reward than
2390
+ * one filed against the wrong market.
2391
+ */
2392
+ rewardsByReserveToken: RewardsByReserveToken;
2307
2393
  }
2308
2394
  interface LenderRewardsByMarketUid {
2309
2395
  [marketUid: string]: LenderAssetReward;
@@ -2312,7 +2398,25 @@ interface YieldDataByMarketUid {
2312
2398
  intrinsicYields: {
2313
2399
  [asset: string]: number | undefined;
2314
2400
  };
2401
+ /**
2402
+ * Flattened to marketUid via `createMarketUid(chain, lender, asset)`.
2403
+ *
2404
+ * CAVEAT: that construction assumes a market's uid ends in its underlying
2405
+ * address, which is not universal — Aave V4 uids end in a numeric RESERVE ID
2406
+ * (`AAVE_V4_94E7A5DC…:1:3` is WBTC), so a reward flattened this way can never
2407
+ * match one. Prefer `rewardsByLenderAsset` when the consumer has the market
2408
+ * nodes to hand; this stays for callers that only have uids.
2409
+ */
2315
2410
  lenderRewards: LenderRewardsByMarketUid;
2411
+ /**
2412
+ * The same lender-keyed rewards UNflattened — (chain → lender → underlying).
2413
+ * Consumers holding market nodes should join on this: it needs no assumption
2414
+ * about how a lender composes its marketUid.
2415
+ */
2416
+ rewardsByLenderAsset: LenderRewards;
2417
+ /** See {@link RewardsByReserveToken} — joined by the consumer against each
2418
+ * market node's `params.metadata.{aToken, vToken}`. */
2419
+ rewardsByReserveToken: RewardsByReserveToken;
2316
2420
  }
2317
2421
 
2318
2422
  declare const fetchGeneralYields: () => Promise<YieldDataWithTimestamp>;
@@ -3252,11 +3356,41 @@ interface ResupplyPairRaw {
3252
3356
  collateralPrice: bigint | null;
3253
3357
  /** Cached `1e36 / collateralPrice` from the pair (stale between writes). */
3254
3358
  exchangeRate: bigint | null;
3359
+ /** Convex pool id the collateral is staked into. 0 = not staked, no rewards. */
3360
+ convexPid: bigint | null;
3361
+ /** This pair's WEIGHT in the RSUP emission stream (not a token balance). */
3362
+ rsupWeight: bigint | null;
3363
+ /** Convex reward streams on the staked collateral: reward wei per second per
3364
+ * 1e18 of staked SHARES, aggregated by token (a pool can list the same
3365
+ * token twice). */
3366
+ collateralRewards: {
3367
+ token: string;
3368
+ ratePerSecPerShare: bigint;
3369
+ }[];
3370
+ }
3371
+ /**
3372
+ * Chain-level RSUP emission state — one read for the whole roster.
3373
+ *
3374
+ * `pairEmissions` stakes governance WEIGHT, not tokens: `totalWeight` is the
3375
+ * sum over all pairs and each pair's slice is its `rsupWeight`. A pair's RSUP
3376
+ * per second is `rewardRate x rsupWeight / totalWeight`.
3377
+ */
3378
+ interface ResupplyRsupEmissions {
3379
+ /** The RSUP token. */
3380
+ govToken: string;
3381
+ /** RSUP wei per second across ALL pairs. */
3382
+ rewardRate: bigint;
3383
+ /** Sum of every pair's weight. */
3384
+ totalWeight: bigint;
3385
+ /** Emissions stop here; past it the stream pays nothing. */
3386
+ periodFinish: bigint;
3255
3387
  }
3256
3388
  interface ResupplyMarketsRaw {
3257
3389
  lender: string;
3258
3390
  config?: ResupplyConfigChain;
3259
3391
  pairs: ResupplyPairRaw[];
3392
+ /** Absent when the stream has ended or could not be read. */
3393
+ rsup?: ResupplyRsupEmissions;
3260
3394
  }
3261
3395
 
3262
3396
  /**
@@ -3504,28 +3638,6 @@ declare function llamaLendKeyParts(key: string): {
3504
3638
  lender: string;
3505
3639
  controller: string;
3506
3640
  } | undefined;
3507
- /**
3508
- * Map the LlamaLend batch into the shared `MorphoGeneralPublicResponse` shape,
3509
- * keyed by `LLAMALEND_<CONTROLLER_ADDR>` — one key per market.
3510
- *
3511
- * Per market, two entries in the isolated-pair layout:
3512
- *
3513
- * - COLLATERAL entry — deposit-only. `collateralFactor` is the LTV AT THE
3514
- * MARKET'S DEFAULT BAND COUNT, because LlamaLend has no market-constant
3515
- * LTV: it is a function of `N` and moves 0.886..0.991 on a single market.
3516
- * The whole curve rides along in `params.market.llamalend.bandLtv` so the
3517
- * UI can show the trade-off and the leverage sizer can use the real number
3518
- * for the `N` the user actually picks.
3519
- * - LOAN entry — the borrowed token. Supply side is the ERC-4626 vault, so
3520
- * unlike Inverse this one HAS `totalDeposits`.
3521
- *
3522
- * SOFT LIQUIDATION is the thing this shape cannot express natively, so it is
3523
- * carried explicitly in the descriptor. `liquidationPenalty` here is the HARD
3524
- * liquidation bonus only — it applies below the entire band range. Inside the
3525
- * range a position is converted gradually through the market's own AMM with no
3526
- * penalty at all, and a consumer that renders `liquidationPenalty` as "what
3527
- * you lose when the price hits X" is describing the wrong event.
3528
- */
3529
3641
  declare function convertLlamaLendMarketsToResponse(raw: LlamaLendMarketsRaw, chainId: string, prices?: {
3530
3642
  [asset: string]: number;
3531
3643
  }, additionalYields?: AdditionalYields, tokens?: GenericTokenList): {