@defisaver/positions-sdk 2.1.144-dev → 2.1.145

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 (96) hide show
  1. package/cjs/config/contracts.d.ts +249 -0
  2. package/cjs/config/contracts.js +11 -1
  3. package/cjs/constants/index.d.ts +1 -0
  4. package/cjs/constants/index.js +2 -1
  5. package/cjs/contracts.d.ts +1510 -0
  6. package/cjs/contracts.js +3 -2
  7. package/cjs/fluid/index.js +6 -2
  8. package/cjs/helpers/fluidHelpers/index.js +5 -4
  9. package/cjs/helpers/index.d.ts +1 -0
  10. package/cjs/helpers/index.js +2 -1
  11. package/cjs/helpers/morphoMidnightHelpers/headroom.d.ts +48 -0
  12. package/cjs/helpers/morphoMidnightHelpers/headroom.js +52 -0
  13. package/cjs/helpers/morphoMidnightHelpers/index.d.ts +113 -0
  14. package/cjs/helpers/morphoMidnightHelpers/index.js +298 -0
  15. package/cjs/helpers/morphoMidnightHelpers/rate.d.ts +15 -0
  16. package/cjs/helpers/morphoMidnightHelpers/rate.js +62 -0
  17. package/cjs/helpers/morphoMidnightHelpers/tenor.d.ts +129 -0
  18. package/cjs/helpers/morphoMidnightHelpers/tenor.js +254 -0
  19. package/cjs/index.d.ts +2 -1
  20. package/cjs/index.js +3 -1
  21. package/cjs/markets/index.d.ts +1 -0
  22. package/cjs/markets/index.js +6 -1
  23. package/cjs/markets/morphoMidnight/index.d.ts +60 -0
  24. package/cjs/markets/morphoMidnight/index.js +659 -0
  25. package/cjs/morphoMidnight/index.d.ts +14 -0
  26. package/cjs/morphoMidnight/index.js +261 -0
  27. package/cjs/portfolio/discovery.js +4 -0
  28. package/cjs/portfolio/index.js +44 -0
  29. package/cjs/services/viem.d.ts +11 -11
  30. package/cjs/staking/eligibility.d.ts +15 -1
  31. package/cjs/staking/eligibility.js +12 -1
  32. package/cjs/staking/staking.js +18 -22
  33. package/cjs/types/index.d.ts +1 -0
  34. package/cjs/types/index.js +1 -0
  35. package/cjs/types/morphoMidnight.d.ts +141 -0
  36. package/cjs/types/morphoMidnight.js +47 -0
  37. package/cjs/types/portfolio.d.ts +4 -0
  38. package/esm/config/contracts.d.ts +249 -0
  39. package/esm/config/contracts.js +9 -0
  40. package/esm/constants/index.d.ts +1 -0
  41. package/esm/constants/index.js +1 -0
  42. package/esm/contracts.d.ts +1510 -0
  43. package/esm/contracts.js +1 -0
  44. package/esm/fluid/index.js +6 -2
  45. package/esm/helpers/fluidHelpers/index.js +6 -5
  46. package/esm/helpers/index.d.ts +1 -0
  47. package/esm/helpers/index.js +1 -0
  48. package/esm/helpers/morphoMidnightHelpers/headroom.d.ts +48 -0
  49. package/esm/helpers/morphoMidnightHelpers/headroom.js +45 -0
  50. package/esm/helpers/morphoMidnightHelpers/index.d.ts +113 -0
  51. package/esm/helpers/morphoMidnightHelpers/index.js +271 -0
  52. package/esm/helpers/morphoMidnightHelpers/rate.d.ts +15 -0
  53. package/esm/helpers/morphoMidnightHelpers/rate.js +50 -0
  54. package/esm/helpers/morphoMidnightHelpers/tenor.d.ts +129 -0
  55. package/esm/helpers/morphoMidnightHelpers/tenor.js +238 -0
  56. package/esm/index.d.ts +2 -1
  57. package/esm/index.js +2 -1
  58. package/esm/markets/index.d.ts +1 -0
  59. package/esm/markets/index.js +1 -0
  60. package/esm/markets/morphoMidnight/index.d.ts +60 -0
  61. package/esm/markets/morphoMidnight/index.js +631 -0
  62. package/esm/morphoMidnight/index.d.ts +14 -0
  63. package/esm/morphoMidnight/index.js +248 -0
  64. package/esm/portfolio/discovery.js +5 -1
  65. package/esm/portfolio/index.js +45 -1
  66. package/esm/services/viem.d.ts +11 -11
  67. package/esm/staking/eligibility.d.ts +15 -1
  68. package/esm/staking/eligibility.js +10 -0
  69. package/esm/staking/staking.js +19 -23
  70. package/esm/types/index.d.ts +1 -0
  71. package/esm/types/index.js +1 -0
  72. package/esm/types/morphoMidnight.d.ts +141 -0
  73. package/esm/types/morphoMidnight.js +44 -0
  74. package/esm/types/portfolio.d.ts +4 -0
  75. package/package.json +1 -1
  76. package/src/config/contracts.ts +9 -0
  77. package/src/constants/index.ts +1 -0
  78. package/src/contracts.ts +1 -0
  79. package/src/fluid/index.ts +6 -2
  80. package/src/helpers/fluidHelpers/index.ts +6 -5
  81. package/src/helpers/index.ts +1 -0
  82. package/src/helpers/morphoMidnightHelpers/headroom.ts +82 -0
  83. package/src/helpers/morphoMidnightHelpers/index.ts +485 -0
  84. package/src/helpers/morphoMidnightHelpers/rate.ts +71 -0
  85. package/src/helpers/morphoMidnightHelpers/tenor.ts +407 -0
  86. package/src/index.ts +2 -0
  87. package/src/markets/index.ts +3 -0
  88. package/src/markets/morphoMidnight/index.ts +675 -0
  89. package/src/morphoMidnight/index.ts +276 -0
  90. package/src/portfolio/discovery.ts +6 -0
  91. package/src/portfolio/index.ts +44 -0
  92. package/src/staking/eligibility.ts +29 -2
  93. package/src/staking/staking.ts +20 -22
  94. package/src/types/index.ts +1 -0
  95. package/src/types/morphoMidnight.ts +163 -0
  96. package/src/types/portfolio.ts +4 -0
@@ -0,0 +1,163 @@
1
+ import {
2
+ EthAddress, IncentiveData, LeverageType, MMUsedAssets, NetworkNumber,
3
+ } from './common';
4
+
5
+ export enum MorphoMidnightVersions {
6
+ // BASE
7
+ // Fixed-term markets are disambiguated by maturity (YYYYMMDD), so the same pair recurs across dates.
8
+ // Sourced from the official listing at https://markets.morpho.org/fixed/base (see sitemap.xml).
9
+ MorphoMidnightCbBTCUSDC_860_20260731_Base = 'morphomidnightcbbtcusdc_860_20260731_base',
10
+ MorphoMidnightCbBTCUSDC_860_20260828_Base = 'morphomidnightcbbtcusdc_860_20260828_base',
11
+ MorphoMidnightCbBTCUSDC_860_20260925_Base = 'morphomidnightcbbtcusdc_860_20260925_base',
12
+ MorphoMidnightCbBTCUSDC_860_20261030_Base = 'morphomidnightcbbtcusdc_860_20261030_base',
13
+ MorphoMidnightCbBTCUSDC_860_20261127_Base = 'morphomidnightcbbtcusdc_860_20261127_base',
14
+ MorphoMidnightCbBTCUSDC_860_20261225_Base = 'morphomidnightcbbtcusdc_860_20261225_base',
15
+ // Tenor-hosted Midnight markets (same core, different order book)
16
+ MorphoMidnightTenorCbBTCUSDC_20260827_Base = 'morphomidnighttenorcbbtcusdc_20260827_base',
17
+ MorphoMidnightTenorCbBTCUSDC_20260924_Base = 'morphomidnighttenorcbbtcusdc_20260924_base',
18
+ MorphoMidnightTenorCbBTCUSDC_20261022_Base = 'morphomidnighttenorcbbtcusdc_20261022_base',
19
+ MorphoMidnightTenorCbBTCUSDC_20261119_Base = 'morphomidnighttenorcbbtcusdc_20261119_base',
20
+ MorphoMidnightTenorCbBTCUSDC_20261217_Base = 'morphomidnighttenorcbbtcusdc_20261217_base',
21
+ MorphoMidnightTenorWETHUSDC_20260827_Base = 'morphomidnighttenorwethusdc_20260827_base',
22
+ MorphoMidnightTenorWETHUSDC_20260924_Base = 'morphomidnighttenorwethusdc_20260924_base',
23
+ MorphoMidnightTenorWETHUSDC_20261022_Base = 'morphomidnighttenorwethusdc_20261022_base',
24
+ MorphoMidnightTenorWETHUSDC_20261119_Base = 'morphomidnighttenorwethusdc_20261119_base',
25
+ MorphoMidnightTenorWETHUSDC_20261217_Base = 'morphomidnighttenorwethusdc_20261217_base',
26
+ MorphoMidnightTenorCbETHWETH_20260827_Base = 'morphomidnighttenorcbethweth_20260827_base',
27
+ MorphoMidnightTenorCbETHWETH_20260924_Base = 'morphomidnighttenorcbethweth_20260924_base',
28
+ MorphoMidnightTenorCbETHWETH_20261022_Base = 'morphomidnighttenorcbethweth_20261022_base',
29
+ MorphoMidnightTenorCbETHWETH_20261119_Base = 'morphomidnighttenorcbethweth_20261119_base',
30
+ MorphoMidnightTenorCbETHWETH_20261217_Base = 'morphomidnighttenorcbethweth_20261217_base',
31
+ }
32
+
33
+ export type MorphoMidnightCurator = 'Morpho' | 'Tenor';
34
+
35
+ export interface MorphoMidnightCollateralParams {
36
+ token: EthAddress,
37
+ lltv: number | string,
38
+ liquidationCursor: number | string,
39
+ oracle: EthAddress,
40
+ }
41
+
42
+ export interface MorphoMidnightMarketData {
43
+ chainIds: NetworkNumber[],
44
+ label: string,
45
+ shortLabel: string,
46
+ url: string,
47
+ value: MorphoMidnightVersions,
48
+ midnight: EthAddress,
49
+ loanToken: EthAddress,
50
+ collaterals: MorphoMidnightCollateralParams[],
51
+ /**
52
+ * Tenor's curated markets list the curator's own vault share token next to the real collateral.
53
+ */
54
+ hiddenCollaterals?: MorphoMidnightCollateralParams[],
55
+ maturity: number, // unix timestamp (seconds)
56
+ rcfThreshold: number | string,
57
+ enterGate: EthAddress,
58
+ liquidatorGate: EthAddress,
59
+ marketId: string, // bytes32, precomputed off-chain (verify with MidnightView.toId)
60
+ protocolName: string,
61
+ curator: MorphoMidnightCurator,
62
+ }
63
+
64
+ export interface MorphoMidnightAssetData {
65
+ symbol: string,
66
+ address: string,
67
+ price: string,
68
+ supplyRate: string,
69
+ borrowRate: string,
70
+ supplyIncentives: IncentiveData[],
71
+ borrowIncentives: IncentiveData[],
72
+ totalSupply?: string,
73
+ totalBorrow?: string,
74
+ canBeSupplied?: boolean,
75
+ canBeBorrowed?: boolean,
76
+ lltv?: string,
77
+ }
78
+
79
+ export type MorphoMidnightAssetsData = { [key: string]: MorphoMidnightAssetData };
80
+
81
+ export interface MorphoMidnightMarketInfo {
82
+ id: string,
83
+ loanToken: string,
84
+ collaterals: string[], // collateral symbols, index-aligned with the market's collateral set
85
+ maturity: number, // unix timestamp (seconds)
86
+ isMatured: boolean, // true once now >= maturity; no new debt can be opened
87
+ totalUnits: string, // face-value units on the market (= totalDebt + withdrawable)
88
+ withdrawable: string, // loan-token liquidity available for withdraw
89
+ totalDebt: string,
90
+ lossFactor: string, // bad-debt socialization factor applied to lender credit
91
+ tickSpacing: number, // orderbook price granularity (relevant to phase-2 rate math)
92
+ utillization: string,
93
+ assetsData: MorphoMidnightAssetsData,
94
+ }
95
+
96
+ // Which half of the order book a caller is taking from: `bids` are the lend offers a borrower fills,
97
+ // `asks` the sell offers a repayer buys debt units from.
98
+ export type MorphoMidnightBookSide = 'bids' | 'asks';
99
+
100
+ // One resting offer on a market's order book, as an annualized rate rather than the API's raw WAD price.
101
+ export interface MorphoMidnightBookOffer {
102
+ rate: string, // fixed APY, percent
103
+ liquidity: string, // loan-token amount available at this rate
104
+ }
105
+
106
+ export interface MorphoMidnightParsedBook {
107
+ bestRate: string, // best rate for the taker of this side (= offers[0].rate)
108
+ totalLiquidity: string, // Σ offers[].liquidity, loan-token units
109
+ offers: MorphoMidnightBookOffer[], // best-first: bids ascending by rate, asks descending
110
+ }
111
+
112
+ export interface MorphoMidnightAggregatedPositionData {
113
+ suppliedUsd: string,
114
+ suppliedCollateralUsd: string,
115
+ borrowedUsd: string,
116
+ borrowLimitUsd: string,
117
+ liquidationLimitUsd: string,
118
+ leftToBorrowUsd: string,
119
+ leftToBorrow: string,
120
+ netApy: string,
121
+ incentiveUsd: string,
122
+ totalInterestUsd: string,
123
+ ltv: string,
124
+ ratio: string, // health ratio as a percentage (from MidnightView.ratio, 1e18-scaled)
125
+ healthRatio: string, // liquidationLimitUsd / borrowedUsd
126
+ leveragedType: LeverageType,
127
+ leveragedAsset?: string,
128
+ currentVolatilePairRatio?: string,
129
+ liquidationPrice?: string,
130
+ minCollRatio?: string,
131
+ collLiquidationRatio?: string,
132
+ exposure: string,
133
+ }
134
+
135
+ /**
136
+ * How much weight `borrowRate` / `debtBase` / `debtInterest` carry on a given position. They fall back to
137
+ * `'0'` / `debt` / `'0'`, which is indistinguishable from a real 0%-interest position, so anything
138
+ * displaying them has to read this to know whether it is looking at a number or at a placeholder.
139
+ *
140
+ * - `Available` — reported and reconciled against the on-chain debt (also lenders and debt-free positions,
141
+ * which have nothing to report).
142
+ * - `Pending` — the indexer has not caught up with the chain yet: it does not know the position, or its
143
+ * split describes a different debt. Refetching resolves it; `getMorphoMidnightUserBorrowInfo` failing
144
+ * outright lands here too, since the next call may well succeed.
145
+ */
146
+ export enum MorphoMidnightBorrowInfoStatus {
147
+ Available = 'available',
148
+ Pending = 'pending',
149
+ }
150
+
151
+ // Fixed-rate/YTM (derived from entry price + orderbook) is intentionally absent in MVP:
152
+ // MidnightView exposes no per-position rate, so a variable-MM-style APY would be misleading.
153
+ export interface MorphoMidnightPositionData extends MorphoMidnightAggregatedPositionData {
154
+ usedAssets: MMUsedAssets,
155
+ credit: string, // lender credit units, face value at maturity (with interest); 0 for borrowers
156
+ debt: string, // borrower debt, face value at maturity (with interest); 0 for lenders
157
+ borrowRate: string, // weighted-average borrow APY as a percent
158
+ debtBase: string, // base borrowed (principal), loan-token units
159
+ debtInterest: string, // debt − debtBase (fixed interest owed at maturity), loan-token units
160
+ borrowInfoStatus: MorphoMidnightBorrowInfoStatus,
161
+ maturity: number,
162
+ isMatured: boolean,
163
+ }
@@ -9,6 +9,7 @@ import { LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
9
9
  import { LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
10
10
  import { CdpData } from './maker';
11
11
  import { MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
12
+ import { MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
12
13
  import { SparkPositionData, SparkVersions } from './spark';
13
14
 
14
15
  export interface PortfolioProtocolData<T> {
@@ -23,6 +24,9 @@ export interface PortfolioPositionsDataForAddress {
23
24
  morphoBlue: {
24
25
  [key in MorphoBlueVersions]?: PortfolioProtocolData<MorphoBluePositionData>;
25
26
  };
27
+ morphoMidnight: {
28
+ [key in MorphoMidnightVersions]?: PortfolioProtocolData<MorphoMidnightPositionData>;
29
+ };
26
30
  compoundV3: {
27
31
  [key in CompoundVersions]?: PortfolioProtocolData<CompoundV3PositionData>;
28
32
  };