@1delta/margin-fetcher 5.0.47 → 5.0.48

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 CHANGED
@@ -19453,6 +19453,19 @@ function parseVault(vault, chainId, prices, additionalYields, tokenList, liquidi
19453
19453
  const meta = tokenList[token];
19454
19454
  return toOracleKey(meta?.assetGroup) ?? toGenericPriceKey(token, chainId);
19455
19455
  };
19456
+ const basketRate = (legs) => {
19457
+ let value = 0;
19458
+ let weighted = 0;
19459
+ for (const leg of legs) {
19460
+ const v = leg.amount * (prices[priceKeyFor(leg.token)] ?? 0);
19461
+ if (v <= 0) continue;
19462
+ value += v;
19463
+ weighted += v * leg.rate;
19464
+ }
19465
+ return value > 0 ? weighted / value : legs[0]?.rate ?? 0;
19466
+ };
19467
+ const basketSupplyRate = isSmartCol ? basketRate(colLegs) : void 0;
19468
+ const basketBorrowRate = isSmartDebt ? basketRate(debtLegs) : void 0;
19456
19469
  const irmTotals = (state, decimals) => state ? {
19457
19470
  irmTotalDeposits: Number(parseRawAmount(state.totalSupply, decimals)),
19458
19471
  irmTotalDebt: Number(parseRawAmount(state.totalBorrow, decimals))
@@ -19518,8 +19531,49 @@ function parseVault(vault, chainId, prices, additionalYields, tokenList, liquidi
19518
19531
  * it a smart market is described as an ordinary pool — the generic
19519
19532
  * builder cannot tell them apart.
19520
19533
  */
19534
+ /**
19535
+ * THIS ROW'S ASSET IS NOT INDEPENDENTLY HOLDABLE.
19536
+ *
19537
+ * LENDER-AGNOSTIC ON PURPOSE — it sits on the ROW, not inside `fluid`,
19538
+ * because the shape is not Fluid's alone: Lista SmartLP's collateral
19539
+ * receipt, GMX's GM/GLV baskets and Fluid's smart sides are all market
19540
+ * sides whose position unit is a multi-token basket (the same set
19541
+ * LP_ACTIONS_PLAN.md enumerates). Any of them can set this, and a
19542
+ * consumer branches on it once instead of learning each protocol.
19543
+ *
19544
+ * True means: depositing any leg mints a share of a basket over ALL of
19545
+ * them, and the POOL — not the user — sets and continuously re-sets the
19546
+ * ratio. There is no way to "hold the ETH leg" of a USDC+ETH side; the
19547
+ * split drifts with every trade and with the range shifting around its
19548
+ * centre price.
19549
+ *
19550
+ * Three consequences a consumer must handle: "you deposited X" is false
19551
+ * from the first block; a single leg's rate is right per DOLLAR but is
19552
+ * NOT the position's rate (use the basket rate); and an exit has to be
19553
+ * sized in shares rather than in this token.
19554
+ */
19555
+ ...isSmartVault ? { autoBalanced: true } : {},
19521
19556
  fluid: isSmartVault ? {
19522
19557
  vaultType,
19558
+ /**
19559
+ * The rate of the POSITION, not of this leg.
19560
+ *
19561
+ * A per-leg rate is individually correct — every dollar in the LP
19562
+ * earns the DEX trading yield regardless of which token it sits in,
19563
+ * so `legRate = liquidityRate + tradingRate` is right per dollar.
19564
+ * What it is NOT is the vault's APR: ranking or headlining a single
19565
+ * leg overstates the position whenever the legs differ. On the live
19566
+ * USDC+ETH/USDC+ETH vault the legs read 11.81 % and 8.19 % while
19567
+ * the position earns 10.33 % — and a "best APR" taken as the max
19568
+ * over legs shows 11.81 %.
19569
+ *
19570
+ * Value-weighted by each leg's own share of the side, which is the
19571
+ * pool's composition as this vault holds it. Fluid's own UI
19572
+ * publishes exactly this figure (10.33 % supply / −1.72 % borrow),
19573
+ * and these match it to the basis point.
19574
+ */
19575
+ basketSupplyRate,
19576
+ basketBorrowRate,
19523
19577
  isSmartCol,
19524
19578
  isSmartDebt,
19525
19579
  /** Both legs of the collateral LP, in token0/token1 order. */