@1delta/margin-fetcher 0.0.320 → 0.0.321

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
@@ -13447,7 +13447,18 @@ function getListaMarketDataConverter(lender, chainId, prices, additionalYields =
13447
13447
  rateCap: rateCap?.toString() ?? "0",
13448
13448
  rateFloor: rateFloor?.toString() ?? "0",
13449
13449
  // term menu for brokered markets (warm via fetchListaFixedTerms)
13450
- terms: fixedTermsForMarket
13450
+ terms: fixedTermsForMarket,
13451
+ // Canonical cross-protocol fixed-term descriptor (Lista + Midnight
13452
+ // share this shape). Lista: rolling-duration menu (no single
13453
+ // maturity), no market-level fees, and a per-loan early-repay
13454
+ // penalty (the concrete amount is position-level, on the loan's
13455
+ // `term.earlyRepayPenalty`).
13456
+ fixedTerm: {
13457
+ model: "lista",
13458
+ maturity: void 0,
13459
+ fees: {},
13460
+ earlyRepay: { kind: "penalty" }
13461
+ }
13451
13462
  }
13452
13463
  };
13453
13464
  data[m].chainId = chainId;
@@ -21021,11 +21032,6 @@ function convertMidnightMarketsToResponse(raw, chainId, prices = {}, _additional
21021
21032
  // Midnight is fixed-rate: expose the fixed borrow APR on stableBorrowRate
21022
21033
  // too, so fixed-rate consumers pick it up like a term product.
21023
21034
  stableBorrowRate: borrowAprPct,
21024
- // Mutable per-market fees (display convenience; authoritative raw values
21025
- // live on params.market). continuousFeeApr is a %/yr lender-side haircut;
21026
- // settlementFee is the effective fraction at the current TTM.
21027
- continuousFeeApr: continuousFeeAprPct,
21028
- settlementFee,
21029
21035
  intrinsicYield: 0,
21030
21036
  rewards: void 0,
21031
21037
  decimals: config.loanDecimals,
@@ -21121,13 +21127,23 @@ function convertMidnightMarketsToResponse(raw, chainId, prices = {}, _additional
21121
21127
  // Midnight-specific extras (consumed by calldata / worker-api resolvers)
21122
21128
  maturity: config.maturity,
21123
21129
  rcfThreshold: config.rcfThreshold,
21124
- // Mutable, on-chain-snapshotted fees. Raw values are authoritative for
21125
- // downstream ingest (yield-tracer); the derived `continuousFeeApr` (%)
21126
- // and `settlementFee` (fraction at current TTM) are convenience fields.
21130
+ // Raw on-chain-snapshotted fees authoritative for downstream ingest
21131
+ // (yield-tracer reads these verbatim).
21127
21132
  settlementFeeCbp: config.settlementFeeCbp,
21128
21133
  continuousFee: config.continuousFee,
21129
- continuousFeeApr: continuousFeeAprPct,
21130
- settlementFee,
21134
+ // Canonical cross-protocol fixed-term descriptor (Lista + Midnight share
21135
+ // this shape). Midnight: single calendar maturity, continuous +
21136
+ // settlement fees, and NO early-repay penalty (exit = buy debt units
21137
+ // back on the book at market price).
21138
+ fixedTerm: {
21139
+ model: "midnight",
21140
+ maturity: Number(config.maturity),
21141
+ fees: {
21142
+ continuousFeeApr: continuousFeeAprPct,
21143
+ settlementFee
21144
+ },
21145
+ earlyRepay: { kind: "none" }
21146
+ },
21131
21147
  enterGate: config.enterGate,
21132
21148
  liquidatorGate: config.liquidatorGate,
21133
21149
  collateralParams: config.collateralParams
@@ -22628,7 +22644,7 @@ var buildDolomiteUserCall = async (chainId, _lender, account, accountNumbers) =>
22628
22644
  params: [{ owner: account, number }]
22629
22645
  }));
22630
22646
  };
22631
- var midnightMarketCallCount = (collateralCount) => 1 + collateralCount;
22647
+ var midnightMarketCallCount = (collateralCount) => 2 + collateralCount;
22632
22648
  var buildMidnightUserCall = (chainId, _lender, account) => {
22633
22649
  const midnight = midnightConfig()?.[chainId]?.midnight;
22634
22650
  const markets = midnightMarketsByChain(chainId);
@@ -22640,6 +22656,29 @@ var buildMidnightUserCall = (chainId, _lender, account) => {
22640
22656
  name: "position",
22641
22657
  params: [market.marketId, account]
22642
22658
  });
22659
+ calls.push({
22660
+ address: midnight,
22661
+ name: "updatePositionView",
22662
+ params: [
22663
+ {
22664
+ chainId: BigInt(chainId),
22665
+ midnight,
22666
+ loanToken: market.loanToken,
22667
+ collateralParams: market.collateralParams.map((c) => ({
22668
+ token: c.token,
22669
+ lltv: BigInt(c.lltv),
22670
+ liquidationCursor: BigInt(c.liquidationCursor),
22671
+ oracle: c.oracle
22672
+ })),
22673
+ maturity: BigInt(market.maturity),
22674
+ rcfThreshold: BigInt(market.rcfThreshold),
22675
+ enterGate: market.enterGate,
22676
+ liquidatorGate: market.liquidatorGate
22677
+ },
22678
+ market.marketId,
22679
+ account
22680
+ ]
22681
+ });
22643
22682
  for (let index = 0; index < market.collateralParams.length; index++) {
22644
22683
  calls.push({
22645
22684
  address: midnight,
@@ -24909,6 +24948,21 @@ function readDebtUnits(positionResult) {
24909
24948
  return toBigInt10(positionResult.debt);
24910
24949
  return 0n;
24911
24950
  }
24951
+ function readUpdatedLender(updateResult) {
24952
+ if (Array.isArray(updateResult)) {
24953
+ return {
24954
+ credit: toBigInt10(updateResult[0]),
24955
+ pendingFee: toBigInt10(updateResult[1])
24956
+ };
24957
+ }
24958
+ if (updateResult && typeof updateResult === "object") {
24959
+ return {
24960
+ credit: toBigInt10(updateResult.newCredit),
24961
+ pendingFee: toBigInt10(updateResult.newPendingFee)
24962
+ };
24963
+ }
24964
+ return { credit: 0n, pendingFee: 0n };
24965
+ }
24912
24966
  var getMidnightUserDataConverter = (_lender, chainId, account, meta) => {
24913
24967
  const markets = midnightMarketsByChain(chainId);
24914
24968
  const totalCalls = markets.reduce(
@@ -24922,8 +24976,9 @@ var getMidnightUserDataConverter = (_lender, chainId, account, meta) => {
24922
24976
  let cursor = 0;
24923
24977
  for (const market of markets) {
24924
24978
  const positionResult = data[cursor];
24979
+ const updateResult = data[cursor + 1];
24925
24980
  const collateralResults = market.collateralParams.map(
24926
- (_c, i) => data[cursor + 1 + i]
24981
+ (_c, i) => data[cursor + 2 + i]
24927
24982
  );
24928
24983
  cursor += midnightMarketCallCount(market.collateralParams.length);
24929
24984
  const lenderKey = midnightLenderKey(market.marketId);
@@ -24938,24 +24993,40 @@ var getMidnightUserDataConverter = (_lender, chainId, account, meta) => {
24938
24993
  const debtUnits = readDebtUnits(positionResult);
24939
24994
  const debtStr = parseRawAmount(debtUnits.toString(), market.loanDecimals);
24940
24995
  const debtNum = Number(debtStr);
24996
+ const { credit, pendingFee } = readUpdatedLender(updateResult);
24997
+ const netCreditUnits = credit > pendingFee ? credit - pendingFee : 0n;
24998
+ const depositsStr = parseRawAmount(
24999
+ netCreditUnits.toString(),
25000
+ market.loanDecimals
25001
+ );
25002
+ const depositsNum = Number(depositsStr);
25003
+ const pendingFeeStr = parseRawAmount(
25004
+ pendingFee.toString(),
25005
+ market.loanDecimals
25006
+ );
24941
25007
  const posData = {};
24942
- let anyBalance = debtUnits > 0n;
24943
- let depositsUSD24h = 0;
25008
+ let anyBalance = debtUnits > 0n || netCreditUnits > 0n;
25009
+ let depositsUSD24h = depositsNum * loanPriceHist;
24944
25010
  posData[loanUid] = {
24945
25011
  marketUid: loanUid,
24946
25012
  underlying: loanAddr,
24947
- deposits: "0",
25013
+ deposits: depositsStr,
24948
25014
  debt: debtStr,
24949
25015
  debtStable: "0",
24950
- depositsUSD: 0,
25016
+ depositsUSD: depositsNum * loanDisplayPrice,
24951
25017
  debtUSD: debtNum * loanDisplayPrice,
24952
25018
  debtStableUSD: 0,
24953
- depositsUSDOracle: 0,
25019
+ depositsUSDOracle: depositsNum * loanOraclePrice,
24954
25020
  debtUSDOracle: debtNum * loanOraclePrice,
24955
25021
  debtStableUSDOracle: 0,
24956
25022
  stableBorrowRate: "0",
25023
+ // Supply on Midnight is a lend position, not collateral for a borrow.
24957
25024
  collateralEnabled: false,
24958
- claimableRewards: 0
25025
+ claimableRewards: 0,
25026
+ // Midnight-specific: accrued continuous fee owed by the lender (loan
25027
+ // units), already netted out of `deposits`. 0 on markets with no
25028
+ // continuous fee (the current live default).
25029
+ pendingFee: pendingFeeStr
24959
25030
  };
24960
25031
  market.collateralParams.forEach((c, i) => {
24961
25032
  const collAmt = toBigInt10(collateralResults[i]);
@@ -24968,19 +25039,19 @@ var getMidnightUserDataConverter = (_lender, chainId, account, meta) => {
24968
25039
  const collDisplayPrice = collMeta ? getDisplayPrice(collMeta) : 0;
24969
25040
  const collOraclePrice = collMeta ? getOraclePrice(collMeta) : 0;
24970
25041
  const collPriceHist = collMeta?.price?.priceUsd24h ?? collDisplayPrice;
24971
- const depositsStr = parseRawAmount(collAmt.toString(), collDec);
24972
- const depositsNum = Number(depositsStr);
24973
- depositsUSD24h += depositsNum * collPriceHist;
25042
+ const depositsStr2 = parseRawAmount(collAmt.toString(), collDec);
25043
+ const depositsNum2 = Number(depositsStr2);
25044
+ depositsUSD24h += depositsNum2 * collPriceHist;
24974
25045
  posData[collUid] = {
24975
25046
  marketUid: collUid,
24976
25047
  underlying: collAddr,
24977
- deposits: depositsStr,
25048
+ deposits: depositsStr2,
24978
25049
  debt: "0",
24979
25050
  debtStable: "0",
24980
- depositsUSD: depositsNum * collDisplayPrice,
25051
+ depositsUSD: depositsNum2 * collDisplayPrice,
24981
25052
  debtUSD: 0,
24982
25053
  debtStableUSD: 0,
24983
- depositsUSDOracle: depositsNum * collOraclePrice,
25054
+ depositsUSDOracle: depositsNum2 * collOraclePrice,
24984
25055
  debtUSDOracle: 0,
24985
25056
  debtStableUSDOracle: 0,
24986
25057
  stableBorrowRate: "0",