@defisaver/positions-sdk 2.1.150-cirbtc-dev → 2.1.151-midnight-dev

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.
Files changed (38) hide show
  1. package/cjs/claiming/compV3.js +0 -1
  2. package/cjs/config/contracts.d.ts +4 -0
  3. package/cjs/config/contracts.js +4 -0
  4. package/cjs/helpers/morphoMidnightHelpers/tenor.d.ts +6 -2
  5. package/cjs/helpers/morphoMidnightHelpers/tenor.js +5 -1
  6. package/cjs/markets/index.d.ts +1 -1
  7. package/cjs/markets/index.js +2 -1
  8. package/cjs/markets/morphoBlue/index.js +122 -122
  9. package/cjs/markets/morphoMidnight/index.d.ts +44 -10
  10. package/cjs/markets/morphoMidnight/index.js +380 -59
  11. package/cjs/morphoMidnight/index.js +11 -1
  12. package/cjs/portfolio/index.js +3 -27
  13. package/cjs/types/morphoMidnight.d.ts +35 -4
  14. package/cjs/types/morphoMidnight.js +23 -0
  15. package/esm/claiming/compV3.js +0 -1
  16. package/esm/config/contracts.d.ts +4 -0
  17. package/esm/config/contracts.js +4 -0
  18. package/esm/helpers/morphoMidnightHelpers/tenor.d.ts +6 -2
  19. package/esm/helpers/morphoMidnightHelpers/tenor.js +6 -2
  20. package/esm/markets/index.d.ts +1 -1
  21. package/esm/markets/index.js +1 -1
  22. package/esm/markets/morphoBlue/index.js +122 -122
  23. package/esm/markets/morphoMidnight/index.d.ts +44 -10
  24. package/esm/markets/morphoMidnight/index.js +356 -58
  25. package/esm/morphoMidnight/index.js +11 -1
  26. package/esm/portfolio/index.js +4 -28
  27. package/esm/types/morphoMidnight.d.ts +35 -4
  28. package/esm/types/morphoMidnight.js +23 -0
  29. package/package.json +1 -1
  30. package/src/claiming/compV3.ts +0 -1
  31. package/src/config/contracts.ts +4 -0
  32. package/src/helpers/morphoMidnightHelpers/tenor.ts +6 -2
  33. package/src/markets/index.ts +1 -0
  34. package/src/markets/morphoBlue/index.ts +122 -122
  35. package/src/markets/morphoMidnight/index.ts +446 -60
  36. package/src/morphoMidnight/index.ts +8 -1
  37. package/src/portfolio/index.ts +3 -27
  38. package/src/types/morphoMidnight.ts +37 -3
@@ -71,8 +71,12 @@ export async function _getMorphoMidnightMarketData(provider: Client, network: Ne
71
71
  borrowIncentives: [],
72
72
  };
73
73
 
74
+ // `collaterals` is the full on-chain set, so `i` is the index `prices` is keyed by. Hidden entries
75
+ // (curator vaults, the loan token itself) are skipped rather than filtered out beforehand, which would
76
+ // shift every later collateral onto the wrong price.
74
77
  const collateralSymbols: string[] = [];
75
78
  collaterals.forEach((coll, i) => {
79
+ if (coll.hidden) return;
76
80
  const collInfo = getAssetInfoByAddress(coll.token, network);
77
81
  const collSym = wethToEth(collInfo.symbol);
78
82
  collateralSymbols.push(collSym);
@@ -138,8 +142,10 @@ export async function _getMorphoMidnightAccountData(provider: Client, network: N
138
142
  borrowedUsd: new Dec(debt).mul(loanTokenData.price).toString(),
139
143
  };
140
144
 
141
- // positionInfo.collateral is index-aligned with the market's collateral set (0 where unused).
145
+ // positionInfo.collateral is index-aligned with the market's full on-chain collateral set (0 where
146
+ // unused), so hidden entries are skipped in place rather than filtered out first.
142
147
  collaterals.forEach((coll, i) => {
148
+ if (coll.hidden) return;
143
149
  const collInfo = getAssetInfoByAddress(coll.token, network);
144
150
  const collSym = wethToEth(collInfo.symbol);
145
151
  const rawAmount = positionInfo.collateral[i] ? positionInfo.collateral[i].toString() : '0';
@@ -228,6 +234,7 @@ export const _getMorphoMidnightAccountBalances = async (provider: Client, networ
228
234
 
229
235
  const collateral: Record<string, string> = {};
230
236
  collaterals.forEach((coll, i) => {
237
+ if (coll.hidden) return;
231
238
  const collInfo = getAssetInfoByAddress(coll.token, network);
232
239
  const rawAmount = positionInfo.collateral[i] ? positionInfo.collateral[i].toString() : '0';
233
240
  collateral[addressMapping ? collInfo.address.toLowerCase() : wethToEth(collInfo.symbol)] = assetAmountInEth(rawAmount, wethToEth(collInfo.symbol));
@@ -12,7 +12,7 @@ import {
12
12
  SparkMarkets,
13
13
  } from '../markets';
14
14
  import { _getMorphoBlueAccountData, _getMorphoBluePortfolioMarketData, getMorphoEarn } from '../morphoBlue';
15
- import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData, getMorphoMidnightEarn } from '../morphoMidnight';
15
+ import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData } from '../morphoMidnight';
16
16
  import {
17
17
  AaveV2MarketData,
18
18
  AaveV3MarketData,
@@ -137,7 +137,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
137
137
  stakingPositions[address.toLowerCase() as EthAddress] = {
138
138
  aaveV3: {},
139
139
  morphoBlue: {},
140
- morphoMidnight: {},
141
140
  compoundV3: {},
142
141
  spark: {},
143
142
  aaveV2: {},
@@ -487,31 +486,8 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
487
486
  })).flat(),
488
487
  ...morphoMidnightMarkets.map((market) => addresses.map(async (address) => {
489
488
  try {
490
- const [accDataPromise, earnDataPromise] = await Promise.allSettled([
491
- _getMorphoMidnightAccountData(client, network, address, market, morphoMidnightMarketsData[market.value]),
492
- getMorphoMidnightEarn(client, network, address, market, morphoMidnightMarketsData[market.value]),
493
- ]);
494
- if (accDataPromise.status === 'rejected') {
495
- console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, accDataPromise.reason);
496
- positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
497
- }
498
- if (earnDataPromise.status === 'rejected') {
499
- console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, earnDataPromise.reason);
500
- positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
501
- }
502
- if (accDataPromise.status !== 'rejected') {
503
- const accData = accDataPromise.value;
504
- if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: '', data: accData };
505
- }
506
- if (earnDataPromise.status !== 'rejected') {
507
- const earnData = earnDataPromise.value;
508
- if (earnData && new Dec(earnData.amount).gt(0)) {
509
- stakingPositions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = {
510
- error: '',
511
- data: earnData,
512
- };
513
- }
514
- }
489
+ const accData = await _getMorphoMidnightAccountData(client, network, address, market, morphoMidnightMarketsData[market.value]);
490
+ if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: '', data: accData };
515
491
  } catch (error) {
516
492
  console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, error);
517
493
  positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
@@ -39,6 +39,29 @@ export enum MorphoMidnightVersions {
39
39
  MorphoMidnightTenorCbETHWETH_20261127_Base = 'morphomidnighttenorcbethweth_20261127_base',
40
40
  MorphoMidnightTenorCbETHWETH_20261225_Base = 'morphomidnighttenorcbethweth_20261225_base',
41
41
  MorphoMidnightTenorCbETHWETH_20270129_Base = 'morphomidnighttenorcbethweth_20270129_base',
42
+ // ETHEREUM
43
+ // Sourced from the official listing at https://markets.morpho.org/fixed?chains=1
44
+ MorphoMidnightWBTCUSDC_860_20260925_Eth = 'morphomidnightwbtcusdc_860_20260925_eth',
45
+ MorphoMidnightWBTCUSDC_860_20261030_Eth = 'morphomidnightwbtcusdc_860_20261030_eth',
46
+ MorphoMidnightWBTCUSDC_860_20261127_Eth = 'morphomidnightwbtcusdc_860_20261127_eth',
47
+ MorphoMidnightWBTCUSDC_860_20261225_Eth = 'morphomidnightwbtcusdc_860_20261225_eth',
48
+ MorphoMidnightWBTCUSDC_860_20270129_Eth = 'morphomidnightwbtcusdc_860_20270129_eth',
49
+ MorphoMidnightWBTCUSDC_860_20270226_Eth = 'morphomidnightwbtcusdc_860_20270226_eth',
50
+ MorphoMidnightWBTCUSDC_860_20270326_Eth = 'morphomidnightwbtcusdc_860_20270326_eth',
51
+ MorphoMidnightCbBTCUSDC_860_20260925_Eth = 'morphomidnightcbbtcusdc_860_20260925_eth',
52
+ MorphoMidnightCbBTCUSDC_860_20261030_Eth = 'morphomidnightcbbtcusdc_860_20261030_eth',
53
+ MorphoMidnightCbBTCUSDC_860_20261127_Eth = 'morphomidnightcbbtcusdc_860_20261127_eth',
54
+ MorphoMidnightCbBTCUSDC_860_20261225_Eth = 'morphomidnightcbbtcusdc_860_20261225_eth',
55
+ MorphoMidnightCbBTCUSDC_860_20270129_Eth = 'morphomidnightcbbtcusdc_860_20270129_eth',
56
+ MorphoMidnightCbBTCUSDC_860_20270226_Eth = 'morphomidnightcbbtcusdc_860_20270226_eth',
57
+ MorphoMidnightCbBTCUSDC_860_20270326_Eth = 'morphomidnightcbbtcusdc_860_20270326_eth',
58
+ // Tenor-hosted Midnight markets (same core, different order book)
59
+ MorphoMidnightTenorWETHUSDC_20260925_Eth = 'morphomidnighttenorwethusdc_20260925_eth',
60
+ MorphoMidnightTenorStrUSDUSDC_20260925_Eth = 'morphomidnighttenorstrusdusdc_20260925_eth',
61
+ MorphoMidnightTenorWsrUSDUSDC_20260925_Eth = 'morphomidnighttenorwsrusdusdc_20260925_eth',
62
+ MorphoMidnightTenorUSD3USDC_20260925_Eth = 'morphomidnighttenorusd3usdc_20260925_eth',
63
+ MorphoMidnightTenorReUSDUSDC_20260925_Eth = 'morphomidnighttenorreusdusdc_20260925_eth',
64
+ MorphoMidnightTenorSiUSDUSDC_20260925_Eth = 'morphomidnighttenorsiusdusdc_20260925_eth',
42
65
  }
43
66
 
44
67
  export type MorphoMidnightCurator = 'Morpho' | 'Tenor';
@@ -48,6 +71,13 @@ export interface MorphoMidnightCollateralParams {
48
71
  lltv: number | string,
49
72
  liquidationCursor: number | string,
50
73
  oracle: EthAddress,
74
+ /**
75
+ * A collateral the market carries on-chain but the app never surfaces: a curator's own vault share
76
+ * token (Tenor's collateral vaults) or the loan token itself (Morpho's mainnet ladders list USDC at
77
+ * 98% next to the real collateral). It is not an asset the app deals in — nothing renders, prices or
78
+ * supplies it — but it stays in `collaterals` because the market id is the hash of the full set.
79
+ */
80
+ hidden?: boolean,
51
81
  }
52
82
 
53
83
  export interface MorphoMidnightMarketData {
@@ -58,11 +88,15 @@ export interface MorphoMidnightMarketData {
58
88
  value: MorphoMidnightVersions,
59
89
  midnight: EthAddress,
60
90
  loanToken: EthAddress,
61
- collaterals: MorphoMidnightCollateralParams[],
62
91
  /**
63
- * Tenor's curated markets list the curator's own vault share token next to the real collateral.
92
+ * Every collateral the market carries on-chain, in the chain's own order which is what the id is
93
+ * hashed from, so neither the set nor the order may be rearranged. Entries the app does not deal in
94
+ * are flagged `hidden` rather than kept in a second list: their on-chain position varies per market
95
+ * (Morpho's mainnet cbBTC ladder lists USDC first, its WBTC ladder second), so a separate list can
96
+ * only be re-joined by guessing, and every positional read — `MarketInfo.prices[i]`,
97
+ * `PositionInfo.collateral[i]`, the collateral index a supply call takes — indexes into *this* array.
64
98
  */
65
- hiddenCollaterals?: MorphoMidnightCollateralParams[],
99
+ collaterals: MorphoMidnightCollateralParams[],
66
100
  maturity: number, // unix timestamp (seconds)
67
101
  rcfThreshold: number | string,
68
102
  enterGate: EthAddress,