@defisaver/positions-sdk 2.1.127-midnight-8-dev → 2.1.127-midnight-10-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 (119) hide show
  1. package/cjs/aaveV4/index.js +26 -10
  2. package/cjs/aaveV4/merkl.d.ts +2 -1
  3. package/cjs/aaveV4/merkl.js +42 -35
  4. package/cjs/config/contracts.d.ts +0 -938
  5. package/cjs/config/contracts.js +2 -8
  6. package/cjs/contracts.d.ts +0 -23433
  7. package/cjs/contracts.js +2 -3
  8. package/cjs/helpers/aaveV4Helpers/index.d.ts +7 -1
  9. package/cjs/helpers/aaveV4Helpers/index.js +22 -10
  10. package/cjs/helpers/index.d.ts +0 -1
  11. package/cjs/helpers/index.js +1 -2
  12. package/cjs/helpers/morphoMidnightHelpers/index.d.ts +4 -57
  13. package/cjs/helpers/morphoMidnightHelpers/index.js +15 -72
  14. package/cjs/helpers/morphoMidnightHelpers/rate.d.ts +4 -0
  15. package/cjs/helpers/morphoMidnightHelpers/rate.js +14 -1
  16. package/cjs/helpers/morphoMidnightHelpers/tenor.d.ts +8 -4
  17. package/cjs/helpers/morphoMidnightHelpers/tenor.js +12 -14
  18. package/cjs/index.d.ts +1 -2
  19. package/cjs/index.js +1 -3
  20. package/cjs/markets/index.d.ts +0 -1
  21. package/cjs/markets/index.js +1 -3
  22. package/cjs/markets/morphoBlue/index.d.ts +6 -0
  23. package/cjs/markets/morphoBlue/index.js +53 -2
  24. package/cjs/portfolio/discovery.d.ts +1 -1
  25. package/cjs/portfolio/discovery.js +1 -1
  26. package/cjs/portfolio/index.js +0 -32
  27. package/cjs/services/utils.d.ts +1 -0
  28. package/cjs/services/utils.js +3 -1
  29. package/cjs/staking/staking.js +1 -2
  30. package/cjs/types/aaveV4.d.ts +5 -0
  31. package/cjs/types/common.d.ts +4 -0
  32. package/cjs/types/common.js +6 -1
  33. package/cjs/types/index.d.ts +0 -1
  34. package/cjs/types/index.js +0 -1
  35. package/cjs/types/merkl.d.ts +3 -4
  36. package/cjs/types/morphoBlue.d.ts +3 -0
  37. package/cjs/types/morphoBlue.js +3 -0
  38. package/cjs/types/portfolio.d.ts +0 -4
  39. package/esm/aaveV4/index.js +27 -11
  40. package/esm/aaveV4/merkl.d.ts +2 -1
  41. package/esm/aaveV4/merkl.js +41 -35
  42. package/esm/config/contracts.d.ts +0 -938
  43. package/esm/config/contracts.js +0 -6
  44. package/esm/contracts.d.ts +0 -23433
  45. package/esm/contracts.js +0 -1
  46. package/esm/helpers/aaveV4Helpers/index.d.ts +7 -1
  47. package/esm/helpers/aaveV4Helpers/index.js +21 -10
  48. package/esm/helpers/index.d.ts +0 -1
  49. package/esm/helpers/index.js +0 -1
  50. package/esm/helpers/morphoMidnightHelpers/index.d.ts +4 -57
  51. package/esm/helpers/morphoMidnightHelpers/index.js +14 -73
  52. package/esm/helpers/morphoMidnightHelpers/rate.d.ts +4 -0
  53. package/esm/helpers/morphoMidnightHelpers/rate.js +12 -0
  54. package/esm/helpers/morphoMidnightHelpers/tenor.d.ts +8 -4
  55. package/esm/helpers/morphoMidnightHelpers/tenor.js +12 -13
  56. package/esm/index.d.ts +1 -2
  57. package/esm/index.js +1 -2
  58. package/esm/markets/index.d.ts +0 -1
  59. package/esm/markets/index.js +0 -1
  60. package/esm/markets/morphoBlue/index.d.ts +6 -0
  61. package/esm/markets/morphoBlue/index.js +48 -0
  62. package/esm/portfolio/discovery.d.ts +1 -1
  63. package/esm/portfolio/discovery.js +1 -1
  64. package/esm/portfolio/index.js +1 -33
  65. package/esm/services/utils.d.ts +1 -0
  66. package/esm/services/utils.js +1 -0
  67. package/esm/staking/staking.js +1 -2
  68. package/esm/types/aaveV4.d.ts +5 -0
  69. package/esm/types/common.d.ts +4 -0
  70. package/esm/types/common.js +5 -0
  71. package/esm/types/index.d.ts +0 -1
  72. package/esm/types/index.js +0 -1
  73. package/esm/types/merkl.d.ts +3 -4
  74. package/esm/types/morphoBlue.d.ts +3 -0
  75. package/esm/types/morphoBlue.js +3 -0
  76. package/esm/types/portfolio.d.ts +0 -4
  77. package/package.json +1 -1
  78. package/src/aaveV4/index.ts +29 -11
  79. package/src/aaveV4/merkl.ts +41 -32
  80. package/src/config/contracts.ts +0 -6
  81. package/src/contracts.ts +0 -1
  82. package/src/helpers/aaveV4Helpers/index.ts +22 -9
  83. package/src/helpers/index.ts +0 -1
  84. package/src/helpers/morphoMidnightHelpers/index.ts +16 -69
  85. package/src/helpers/morphoMidnightHelpers/rate.ts +25 -0
  86. package/src/helpers/morphoMidnightHelpers/tenor.ts +12 -16
  87. package/src/index.ts +0 -2
  88. package/src/markets/index.ts +0 -1
  89. package/src/markets/morphoBlue/index.ts +49 -1
  90. package/src/portfolio/discovery.ts +1 -1
  91. package/src/portfolio/index.ts +0 -33
  92. package/src/services/utils.ts +2 -0
  93. package/src/staking/staking.ts +1 -2
  94. package/src/types/aaveV4.ts +5 -0
  95. package/src/types/common.ts +5 -0
  96. package/src/types/index.ts +0 -1
  97. package/src/types/merkl.ts +3 -3
  98. package/src/types/morphoBlue.ts +3 -0
  99. package/src/types/portfolio.ts +0 -4
  100. package/cjs/eulerV2/index.d.ts +0 -47
  101. package/cjs/eulerV2/index.js +0 -225
  102. package/cjs/helpers/eulerHelpers/index.d.ts +0 -22
  103. package/cjs/helpers/eulerHelpers/index.js +0 -231
  104. package/cjs/markets/euler/index.d.ts +0 -8
  105. package/cjs/markets/euler/index.js +0 -30
  106. package/cjs/types/euler.d.ts +0 -153
  107. package/cjs/types/euler.js +0 -14
  108. package/esm/eulerV2/index.d.ts +0 -47
  109. package/esm/eulerV2/index.js +0 -215
  110. package/esm/helpers/eulerHelpers/index.d.ts +0 -22
  111. package/esm/helpers/eulerHelpers/index.js +0 -218
  112. package/esm/markets/euler/index.d.ts +0 -8
  113. package/esm/markets/euler/index.js +0 -24
  114. package/esm/types/euler.d.ts +0 -153
  115. package/esm/types/euler.js +0 -11
  116. package/src/eulerV2/index.ts +0 -331
  117. package/src/helpers/eulerHelpers/index.ts +0 -232
  118. package/src/markets/euler/index.ts +0 -27
  119. package/src/types/euler.ts +0 -178
package/esm/contracts.js CHANGED
@@ -107,7 +107,6 @@ export const WstETHPriceFeedContractViem = createViemContractFromConfigFunc('Wst
107
107
  export const CompV3ViewContractViem = createViemContractFromConfigFunc('CompV3View');
108
108
  export const SparkViewContractViem = createViemContractFromConfigFunc('SparkView');
109
109
  export const SparkIncentiveDataProviderContractViem = createViemContractFromConfigFunc('SparkIncentiveDataProvider');
110
- export const EulerV2ViewContractViem = createViemContractFromConfigFunc('EulerV2View');
111
110
  export const CrvUSDViewContractViem = createViemContractFromConfigFunc('crvUSDView');
112
111
  export const CrvUSDFactoryContractViem = createViemContractFromConfigFunc('crvUSDFactory');
113
112
  export const LlamaLendViewContractViem = createViemContractFromConfigFunc('LlamaLendView');
@@ -1,5 +1,11 @@
1
- import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4SpokeInfo, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets, EthereumProvider, LeverageType, NetworkNumber } from '../../types';
1
+ import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4SpokeInfo, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets, EthereumProvider, IncentiveData, IncentiveSide, LeverageType, NetworkNumber } from '../../types';
2
2
  export declare const calcUserRiskPremiumBps: (usedAssets: AaveV4UsedReserveAssets, assetsData: AaveV4AssetsData) => number;
3
+ /**
4
+ * The incentives that actually accrue to a position on this reserve for the given side: the
5
+ * intrinsic (staking) incentives plus the single applicable Merkl reward. Display surfaces should
6
+ * use this rather than picking a scoped list directly, so badges always match the net APY math.
7
+ */
8
+ export declare const getAaveV4ApplicableIncentives: (assetData: AaveV4ReserveAssetData, side: IncentiveSide) => IncentiveData[];
3
9
  export declare const calculateNetApyAaveV4: ({ usedAssets, assetsData, }: {
4
10
  usedAssets: AaveV4UsedReserveAssets;
5
11
  assetsData: AaveV4AssetsData;
@@ -11,7 +11,7 @@ import Dec from 'decimal.js';
11
11
  import { assetAmountInWei } from '@defisaver/tokens';
12
12
  import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS, } from '../../moneymarket';
13
13
  import { calculateInterestEarned } from '../../staking';
14
- import { LeverageType, } from '../../types';
14
+ import { IncentiveSide, LeverageType, } from '../../types';
15
15
  import { borrowOperations } from '../../constants';
16
16
  import { AaveV4ViewContractViem } from '../../contracts';
17
17
  import { getViemProvider } from '../../services/viem';
@@ -69,14 +69,25 @@ export const calcUserRiskPremiumBps = (usedAssets, assetsData) => {
69
69
  };
70
70
  /**
71
71
  * `spokeXIncentives`/`hubXIncentives` are each the intrinsic `base` list with at most one Merkl
72
- * reward appended (see attachAaveV4MerklIncentives). Both scopes can apply to the same position at
73
- * once (spoke-specific + hub-wide), so the full applicable set is base + whatever each scope appended.
72
+ * reward appended (see attachAaveV4MerklIncentives). Merkl regularly publishes the same reward
73
+ * stream at both scopes (a spoke campaign and a hub campaign covering the same borrows, e.g. USDC
74
+ * borrowed from the Prime Hub via the Bluechip Spoke), so the scopes must never be summed — the
75
+ * more specific spoke reward wins and the hub reward only applies when no spoke campaign exists,
76
+ * which is also what every per-asset APY badge (and Aave's own UI) shows.
74
77
  */
75
- const mergeScopedIncentives = (base = [], spokeScoped, hubScoped) => [
76
- ...base,
77
- ...(spokeScoped ? spokeScoped.slice(base.length) : []),
78
- ...(hubScoped ? hubScoped.slice(base.length) : []),
79
- ];
78
+ const mergeScopedIncentives = (base = [], spokeScoped, hubScoped) => {
79
+ const spokeExtras = spokeScoped ? spokeScoped.slice(base.length) : [];
80
+ const hubExtras = hubScoped ? hubScoped.slice(base.length) : [];
81
+ return [...base, ...(spokeExtras.length ? spokeExtras : hubExtras)];
82
+ };
83
+ /**
84
+ * The incentives that actually accrue to a position on this reserve for the given side: the
85
+ * intrinsic (staking) incentives plus the single applicable Merkl reward. Display surfaces should
86
+ * use this rather than picking a scoped list directly, so badges always match the net APY math.
87
+ */
88
+ export const getAaveV4ApplicableIncentives = (assetData, side) => (side === IncentiveSide.Supply
89
+ ? mergeScopedIncentives(assetData.supplyIncentives, assetData.spokeSupplyIncentives, assetData.hubSupplyIncentives)
90
+ : mergeScopedIncentives(assetData.borrowIncentives, assetData.spokeBorrowIncentives, assetData.hubBorrowIncentives));
80
91
  export const calculateNetApyAaveV4 = ({ usedAssets, assetsData, }) => {
81
92
  const riskPremiumBps = calcUserRiskPremiumBps(usedAssets, assetsData);
82
93
  const riskPremiumFraction = new Dec(riskPremiumBps).div(10000);
@@ -90,7 +101,7 @@ export const calculateNetApyAaveV4 = ({ usedAssets, assetsData, }) => {
90
101
  acc.suppliedUsd = new Dec(acc.suppliedUsd).add(amount).toString();
91
102
  const supplyInterest = calculateInterestEarned(amount, assetData.supplyRate, 'year', true);
92
103
  acc.supplyInterest = new Dec(acc.supplyInterest).add(supplyInterest.toString()).toString();
93
- const supplyIncentives = mergeScopedIncentives(assetData.supplyIncentives, assetData.spokeSupplyIncentives, assetData.hubSupplyIncentives);
104
+ const supplyIncentives = getAaveV4ApplicableIncentives(assetData, IncentiveSide.Supply);
94
105
  for (const supplyIncentive of supplyIncentives) {
95
106
  const incentiveInterest = calculateInterestEarned(amount, supplyIncentive.apy, 'year', true);
96
107
  acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
@@ -106,7 +117,7 @@ export const calculateNetApyAaveV4 = ({ usedAssets, assetsData, }) => {
106
117
  const userBorrowRate = aprToApy(userBorrowApr.toString());
107
118
  const borrowInterest = calculateInterestEarned(amount, userBorrowRate, 'year', true);
108
119
  acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
109
- const borrowIncentives = mergeScopedIncentives(assetData.borrowIncentives, assetData.spokeBorrowIncentives, assetData.hubBorrowIncentives);
120
+ const borrowIncentives = getAaveV4ApplicableIncentives(assetData, IncentiveSide.Borrow);
110
121
  for (const borrowIncentive of borrowIncentives) {
111
122
  const incentiveInterest = calculateInterestEarned(amount, borrowIncentive.apy, 'year', true);
112
123
  acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
@@ -7,6 +7,5 @@ export * as morphoBlueHelpers from './morphoBlueHelpers';
7
7
  export * as morphoMidnightHelpers from './morphoMidnightHelpers';
8
8
  export * as llamaLendHelpers from './llamaLendHelpers';
9
9
  export * as liquityV2Helpers from './liquityV2Helpers';
10
- export * as eulerV2Helpers from './eulerHelpers';
11
10
  export * as fluidHelpers from './fluidHelpers';
12
11
  export * as aaveV4Helpers from './aaveV4Helpers';
@@ -7,6 +7,5 @@ export * as morphoBlueHelpers from './morphoBlueHelpers';
7
7
  export * as morphoMidnightHelpers from './morphoMidnightHelpers';
8
8
  export * as llamaLendHelpers from './llamaLendHelpers';
9
9
  export * as liquityV2Helpers from './liquityV2Helpers';
10
- export * as eulerV2Helpers from './eulerHelpers';
11
10
  export * as fluidHelpers from './fluidHelpers';
12
11
  export * as aaveV4Helpers from './aaveV4Helpers';
@@ -1,7 +1,7 @@
1
1
  import Dec from 'decimal.js';
2
2
  import { MMUsedAssets, NetworkNumber } from '../../types/common';
3
3
  import { MorphoMidnightAggregatedPositionData, MorphoMidnightAssetsData, MorphoMidnightBookSide, MorphoMidnightMarketData, MorphoMidnightMarketInfo, MorphoMidnightParsedBook } from '../../types';
4
- export { buildMidnightParsedBook, midnightApyFromPrice, midnightBookBestFirst, midnightPriceFromApy, midnightTimeToMaturityDays, } from './rate';
4
+ export { buildMidnightParsedBook, midnightApyFromPrice, midnightBookBestFirst, midnightBoundPrice, midnightPriceFromApy, midnightTimeToMaturityDays, MIDNIGHT_DEFAULT_RATE_SLIPPAGE, } from './rate';
5
5
  export { tenorBookKeyFor, tenorBookRateToApyPercent, tenorOfferFillToApiFill, tenorOfferToApiOffer, } from './tenor';
6
6
  /**
7
7
  * Aggregate a Morpho Midnight position. Midnight markets are multi-collateral, so the borrow limit is
@@ -88,59 +88,6 @@ export declare const getMorphoMidnightUserBorrowInfo: (account: string, marketId
88
88
  * JSON, so without the `res.ok` check it parses as an empty book and the market silently vanishes.
89
89
  */
90
90
  export declare const getMorphoMidnightMarketBook: (market: MorphoMidnightMarketData, network: NetworkNumber, side?: MorphoMidnightBookSide) => Promise<MorphoMidnightParsedBook | null>;
91
- /**
92
- * Quote a prospective borrow against the Midnight order book: the estimated rate, the debt units it adds,
93
- * and the `maxUnits` cap sent on-chain to protect the user if better offers get filled first. `assetsRaw`
94
- * (and the returned `newUnits`/`maxUnits`) are raw loan-token base units — callers convert to/from human
95
- * amounts. Throws if the book can't fill the amount (caller handles).
96
- *
97
- * Two ways to set the cap:
98
- * - `maxBorrowRate` — an absolute APY ceiling, honoured **exactly**: the cap price is derived locally via
99
- * `midnightPriceFromApy`. Prefer this when a user pins a max rate.
100
- * - otherwise `slippagePercent`, the API's own knob. Note it is a **price**-level slippage, not APY points:
101
- * near maturity the annualisation factor (365 / ttmDays) multiplies it heavily, so on a 22-day market a
102
- * slippage of 0.5 permitted an APY ~9pp above the estimate, not 0.5pp. It also saturates at the book's
103
- * cheapest bid. `maxRate` therefore reports what the cap actually permits, derived from the cap price.
104
- *
105
- * A `maxBorrowRate` below `estBorrowRate` yields `maxUnits < newUnits` — the borrow would revert on-chain.
106
- * Compare the two before submitting and tell the user their ceiling is under the market rate.
107
- *
108
- * Tenor-hosted markets (see `isTenorMidnightMarket`) are quoted against Tenor's router instead of Morpho's
109
- * book API. Slippage is applied locally to `maxUnits`; `taker` is the position owner (the smart wallet).
110
- */
111
- export declare const getMorphoMidnightBorrowQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, maxBorrowRate?: Dec.Value, taker?: string) => Promise<MorphoMidnightBorrowQuote>;
112
- /**
113
- * Quote a prospective payback against the ask side of the Midnight order book: the rate the repayment
114
- * retires debt at, the debt units it buys, and the `minUnits` floor sent on-chain to protect the user if
115
- * the cheap offers get taken first. `assetsRaw` is the amount **spent** (raw loan-token base units) —
116
- * matching `MidnightPaybackFromOrders`, whose `amount` is what leaves the wallet; the units bought, and
117
- * therefore the debt retired, exceed it because a unit costs less than one loan token before maturity.
118
- * Throws if the book can't fill the amount (caller handles).
119
- *
120
- * The mirror image of the borrow quote in every respect. A repayer wants a *high* rate, i.e. cheap units,
121
- * so the guard is a floor rather than a ceiling:
122
- * - `minPaybackRate` — an absolute APY floor, honoured **exactly** via `midnightPriceFromApy`. Prefer
123
- * this when a user pins a min rate.
124
- * - otherwise `slippagePercent`, the API's own price-level knob, whose APY effect is amplified by the
125
- * annualisation factor near maturity. `minRate` reports what the floor actually permits.
126
- *
127
- * A `minPaybackRate` above `estPaybackRate` yields `minUnits > newUnits` — the payback would revert
128
- * on-chain. Compare the two before submitting and tell the user their floor is over the market rate.
129
- */
130
- export declare const getMorphoMidnightPaybackQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string) => Promise<MorphoMidnightPaybackQuote>;
131
- /**
132
- * Payback quoted against a **units** target instead of a spend: "retire exactly these debt units, and tell
133
- * me what that costs". The sibling of `getMorphoMidnightPaybackQuote` in every other respect — same ask
134
- * side, same rate floor, same offer list — but with the two amounts swapped, so the on-chain guard becomes
135
- * a ceiling on assets spent rather than a floor on units bought.
136
- *
137
- * This is what a **full close** must be sized with. Retiring N units costs less than N loan tokens before
138
- * maturity, so quoting the close as a spend of the debt's face value asks the book for more depth than the
139
- * close needs (and can be refused for liquidity that is in fact there), and caps the taker's spend at more
140
- * than the position is worth. Callers that cannot refund an overspend — a taker calling the bundler
141
- * directly, rather than through an action contract that sweeps the remainder back — need this quote.
142
- *
143
- * A `minPaybackRate` above `estPaybackRate` yields `maxAssets < newAssets`: the ceiling is under what the
144
- * buy costs and it would revert on-chain, the mirror of the assets-target quote's `minUnits > newUnits`.
145
- */
146
- export declare const getMorphoMidnightPaybackUnitsQuote: (marketId: string, unitsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string) => Promise<MorphoMidnightPaybackUnitsQuote>;
91
+ export declare const getMorphoMidnightBorrowQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, maxBorrowRate?: Dec.Value, taker?: string, rateSlippagePercent?: Dec.Value) => Promise<MorphoMidnightBorrowQuote>;
92
+ export declare const getMorphoMidnightPaybackQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string, rateSlippagePercent?: Dec.Value) => Promise<MorphoMidnightPaybackQuote>;
93
+ export declare const getMorphoMidnightPaybackUnitsQuote: (marketId: string, unitsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string, rateSlippagePercent?: Dec.Value) => Promise<MorphoMidnightPaybackUnitsQuote>;
@@ -15,9 +15,9 @@ import { LeverageType, } from '../../types/common';
15
15
  import { WAD } from '../../constants';
16
16
  import { LONGER_TIMEOUT } from '../../services/utils';
17
17
  import { isTenorMidnightMarket } from '../../markets/morphoMidnight';
18
- import { buildMidnightParsedBook, midnightApyFromPrice, midnightPriceFromApy, midnightTimeToMaturityDays, } from './rate';
18
+ import { buildMidnightParsedBook, midnightApyFromPrice, midnightBoundPrice, midnightTimeToMaturityDays, } from './rate';
19
19
  import { getTenorBorrowQuote, getTenorMarketBook, getTenorPaybackQuote, getTenorPaybackUnitsQuote, } from './tenor';
20
- export { buildMidnightParsedBook, midnightApyFromPrice, midnightBookBestFirst, midnightPriceFromApy, midnightTimeToMaturityDays, } from './rate';
20
+ export { buildMidnightParsedBook, midnightApyFromPrice, midnightBookBestFirst, midnightBoundPrice, midnightPriceFromApy, midnightTimeToMaturityDays, MIDNIGHT_DEFAULT_RATE_SLIPPAGE, } from './rate';
21
21
  export { tenorBookKeyFor, tenorBookRateToApyPercent, tenorOfferFillToApiFill, tenorOfferToApiOffer, } from './tenor';
22
22
  /**
23
23
  * Aggregate a Morpho Midnight position. Midnight markets are multi-collateral, so the borrow limit is
@@ -175,39 +175,17 @@ const fetchMorphoMidnightQuote = (marketId, side, size, slippagePercent) => __aw
175
175
  takeableOffers: d.takeable_offers || [],
176
176
  };
177
177
  });
178
- /**
179
- * Quote a prospective borrow against the Midnight order book: the estimated rate, the debt units it adds,
180
- * and the `maxUnits` cap sent on-chain to protect the user if better offers get filled first. `assetsRaw`
181
- * (and the returned `newUnits`/`maxUnits`) are raw loan-token base units — callers convert to/from human
182
- * amounts. Throws if the book can't fill the amount (caller handles).
183
- *
184
- * Two ways to set the cap:
185
- * - `maxBorrowRate` — an absolute APY ceiling, honoured **exactly**: the cap price is derived locally via
186
- * `midnightPriceFromApy`. Prefer this when a user pins a max rate.
187
- * - otherwise `slippagePercent`, the API's own knob. Note it is a **price**-level slippage, not APY points:
188
- * near maturity the annualisation factor (365 / ttmDays) multiplies it heavily, so on a 22-day market a
189
- * slippage of 0.5 permitted an APY ~9pp above the estimate, not 0.5pp. It also saturates at the book's
190
- * cheapest bid. `maxRate` therefore reports what the cap actually permits, derived from the cap price.
191
- *
192
- * A `maxBorrowRate` below `estBorrowRate` yields `maxUnits < newUnits` — the borrow would revert on-chain.
193
- * Compare the two before submitting and tell the user their ceiling is under the market rate.
194
- *
195
- * Tenor-hosted markets (see `isTenorMidnightMarket`) are quoted against Tenor's router instead of Morpho's
196
- * book API. Slippage is applied locally to `maxUnits`; `taker` is the position owner (the smart wallet).
197
- */
198
- export const getMorphoMidnightBorrowQuote = (marketId, assetsRaw, slippagePercent, maturity, maxBorrowRate, taker) => __awaiter(void 0, void 0, void 0, function* () {
178
+ export const getMorphoMidnightBorrowQuote = (marketId, assetsRaw, slippagePercent, maturity, maxBorrowRate, taker, rateSlippagePercent) => __awaiter(void 0, void 0, void 0, function* () {
199
179
  if (isTenorMidnightMarket(marketId)) {
200
- return getTenorBorrowQuote(marketId, assetsRaw, slippagePercent, maturity, maxBorrowRate, taker);
180
+ return getTenorBorrowQuote(marketId, assetsRaw, slippagePercent, maturity, maxBorrowRate, taker, rateSlippagePercent);
201
181
  }
202
182
  const quote = yield fetchMorphoMidnightQuote(marketId, 'bids', { assets: assetsRaw }, slippagePercent);
203
- const { bestPrice, worstPrice } = quote;
183
+ const { bestPrice } = quote;
204
184
  const ttmDays = midnightTimeToMaturityDays(maturity);
205
185
  const estBorrowRate = midnightApyFromPrice(bestPrice, ttmDays);
206
186
  // Price the cap sits at, and the rate that price represents — one derivation, so `maxRate` and
207
187
  // `maxUnits` can never disagree about what the user is protected at.
208
- const capPrice = maxBorrowRate !== undefined && new Dec(maxBorrowRate).gt(0)
209
- ? midnightPriceFromApy(maxBorrowRate, ttmDays)
210
- : worstPrice;
188
+ const capPrice = midnightBoundPrice(estBorrowRate, ttmDays, 'ceiling', maxBorrowRate, rateSlippagePercent);
211
189
  const maxRate = midnightApyFromPrice(capPrice, ttmDays);
212
190
  const newUnits = new Dec(bestPrice).lte(0) ? '0' : new Dec(assetsRaw).div(bestPrice).toFixed(0);
213
191
  const maxUnits = new Dec(capPrice).lte(0) ? '0' : new Dec(assetsRaw).div(capPrice).toFixed(0);
@@ -216,35 +194,15 @@ export const getMorphoMidnightBorrowQuote = (marketId, assetsRaw, slippagePercen
216
194
  newUnits,
217
195
  maxUnits });
218
196
  });
219
- /**
220
- * Quote a prospective payback against the ask side of the Midnight order book: the rate the repayment
221
- * retires debt at, the debt units it buys, and the `minUnits` floor sent on-chain to protect the user if
222
- * the cheap offers get taken first. `assetsRaw` is the amount **spent** (raw loan-token base units) —
223
- * matching `MidnightPaybackFromOrders`, whose `amount` is what leaves the wallet; the units bought, and
224
- * therefore the debt retired, exceed it because a unit costs less than one loan token before maturity.
225
- * Throws if the book can't fill the amount (caller handles).
226
- *
227
- * The mirror image of the borrow quote in every respect. A repayer wants a *high* rate, i.e. cheap units,
228
- * so the guard is a floor rather than a ceiling:
229
- * - `minPaybackRate` — an absolute APY floor, honoured **exactly** via `midnightPriceFromApy`. Prefer
230
- * this when a user pins a min rate.
231
- * - otherwise `slippagePercent`, the API's own price-level knob, whose APY effect is amplified by the
232
- * annualisation factor near maturity. `minRate` reports what the floor actually permits.
233
- *
234
- * A `minPaybackRate` above `estPaybackRate` yields `minUnits > newUnits` — the payback would revert
235
- * on-chain. Compare the two before submitting and tell the user their floor is over the market rate.
236
- */
237
- export const getMorphoMidnightPaybackQuote = (marketId, assetsRaw, slippagePercent, maturity, minPaybackRate, taker) => __awaiter(void 0, void 0, void 0, function* () {
197
+ export const getMorphoMidnightPaybackQuote = (marketId, assetsRaw, slippagePercent, maturity, minPaybackRate, taker, rateSlippagePercent) => __awaiter(void 0, void 0, void 0, function* () {
238
198
  if (isTenorMidnightMarket(marketId)) {
239
- return getTenorPaybackQuote(marketId, assetsRaw, slippagePercent, maturity, minPaybackRate, taker);
199
+ return getTenorPaybackQuote(marketId, assetsRaw, slippagePercent, maturity, minPaybackRate, taker, rateSlippagePercent);
240
200
  }
241
201
  const quote = yield fetchMorphoMidnightQuote(marketId, 'asks', { assets: assetsRaw }, slippagePercent);
242
- const { bestPrice, worstPrice } = quote;
202
+ const { bestPrice } = quote;
243
203
  const ttmDays = midnightTimeToMaturityDays(maturity);
244
204
  const estPaybackRate = midnightApyFromPrice(bestPrice, ttmDays);
245
- const capPrice = minPaybackRate !== undefined && new Dec(minPaybackRate).gt(0)
246
- ? midnightPriceFromApy(minPaybackRate, ttmDays)
247
- : worstPrice;
205
+ const capPrice = midnightBoundPrice(estPaybackRate, ttmDays, 'floor', minPaybackRate, rateSlippagePercent);
248
206
  const minRate = midnightApyFromPrice(capPrice, ttmDays);
249
207
  // Rounded down on both counts: `newUnits` must not overstate the debt the user sees retired, and a
250
208
  // `minUnits` rounded up would be a stricter floor than asked for and revert a payback that was fine.
@@ -255,32 +213,15 @@ export const getMorphoMidnightPaybackQuote = (marketId, assetsRaw, slippagePerce
255
213
  newUnits,
256
214
  minUnits });
257
215
  });
258
- /**
259
- * Payback quoted against a **units** target instead of a spend: "retire exactly these debt units, and tell
260
- * me what that costs". The sibling of `getMorphoMidnightPaybackQuote` in every other respect — same ask
261
- * side, same rate floor, same offer list — but with the two amounts swapped, so the on-chain guard becomes
262
- * a ceiling on assets spent rather than a floor on units bought.
263
- *
264
- * This is what a **full close** must be sized with. Retiring N units costs less than N loan tokens before
265
- * maturity, so quoting the close as a spend of the debt's face value asks the book for more depth than the
266
- * close needs (and can be refused for liquidity that is in fact there), and caps the taker's spend at more
267
- * than the position is worth. Callers that cannot refund an overspend — a taker calling the bundler
268
- * directly, rather than through an action contract that sweeps the remainder back — need this quote.
269
- *
270
- * A `minPaybackRate` above `estPaybackRate` yields `maxAssets < newAssets`: the ceiling is under what the
271
- * buy costs and it would revert on-chain, the mirror of the assets-target quote's `minUnits > newUnits`.
272
- */
273
- export const getMorphoMidnightPaybackUnitsQuote = (marketId, unitsRaw, slippagePercent, maturity, minPaybackRate, taker) => __awaiter(void 0, void 0, void 0, function* () {
216
+ export const getMorphoMidnightPaybackUnitsQuote = (marketId, unitsRaw, slippagePercent, maturity, minPaybackRate, taker, rateSlippagePercent) => __awaiter(void 0, void 0, void 0, function* () {
274
217
  if (isTenorMidnightMarket(marketId)) {
275
- return getTenorPaybackUnitsQuote(marketId, unitsRaw, slippagePercent, maturity, minPaybackRate, taker);
218
+ return getTenorPaybackUnitsQuote(marketId, unitsRaw, slippagePercent, maturity, minPaybackRate, taker, rateSlippagePercent);
276
219
  }
277
220
  const quote = yield fetchMorphoMidnightQuote(marketId, 'asks', { units: unitsRaw }, slippagePercent);
278
- const { bestPrice, worstPrice } = quote;
221
+ const { bestPrice } = quote;
279
222
  const ttmDays = midnightTimeToMaturityDays(maturity);
280
223
  const estPaybackRate = midnightApyFromPrice(bestPrice, ttmDays);
281
- const capPrice = minPaybackRate !== undefined && new Dec(minPaybackRate).gt(0)
282
- ? midnightPriceFromApy(minPaybackRate, ttmDays)
283
- : worstPrice;
224
+ const capPrice = midnightBoundPrice(estPaybackRate, ttmDays, 'floor', minPaybackRate, rateSlippagePercent);
284
225
  const minRate = midnightApyFromPrice(capPrice, ttmDays);
285
226
  // Rounded UP on both counts — the mirror of the assets-target quote's ROUND_DOWN. Here the figures are
286
227
  // what the taker SPENDS, so a value rounded down understates the cost by a base unit and would leave the
@@ -7,5 +7,9 @@ export declare const midnightApyFromPrice: (price: Dec.Value, ttmDays: Dec.Value
7
7
  * price = (1 + rate)^(−ttmDays / 365).
8
8
  */
9
9
  export declare const midnightPriceFromApy: (ratePercent: Dec.Value, ttmDays: Dec.Value) => string;
10
+ export declare const MIDNIGHT_DEFAULT_RATE_SLIPPAGE = 0.1;
11
+ /** Which side of the estimate a guard sits on: a ceiling for borrows, a floor for paybacks. */
12
+ export type MidnightRateBoundKind = 'ceiling' | 'floor';
13
+ export declare const midnightBoundPrice: (estRate: Dec.Value, ttmDays: Dec.Value, kind: MidnightRateBoundKind, boundRate?: Dec.Value, rateSlippagePercent?: Dec.Value) => string;
10
14
  export declare const midnightBookBestFirst: (side: MorphoMidnightBookSide) => 1 | -1;
11
15
  export declare const buildMidnightParsedBook: (offers: MorphoMidnightBookOffer[], side: MorphoMidnightBookSide) => MorphoMidnightParsedBook | null;
@@ -25,6 +25,18 @@ export const midnightPriceFromApy = (ratePercent, ttmDays) => {
25
25
  return '1';
26
26
  return new Dec(1).div(new Dec(1).add(rate.div(100)).pow(ttm.div(365))).toString();
27
27
  };
28
+ export const MIDNIGHT_DEFAULT_RATE_SLIPPAGE = 0.1;
29
+ const MIDNIGHT_MIN_FLOOR_RATIO = 0.5;
30
+ export const midnightBoundPrice = (estRate, ttmDays, kind, boundRate, rateSlippagePercent = MIDNIGHT_DEFAULT_RATE_SLIPPAGE) => {
31
+ if (boundRate !== undefined && new Dec(boundRate).gt(0))
32
+ return midnightPriceFromApy(boundRate, ttmDays);
33
+ const est = new Dec(estRate);
34
+ const slippage = new Dec(rateSlippagePercent);
35
+ const bound = kind === 'ceiling'
36
+ ? est.add(slippage)
37
+ : Dec.max(est.sub(slippage), est.mul(MIDNIGHT_MIN_FLOOR_RATIO));
38
+ return midnightPriceFromApy(bound, ttmDays);
39
+ };
28
40
  export const midnightBookBestFirst = (side) => (side === 'asks' ? -1 : 1);
29
41
  export const buildMidnightParsedBook = (offers, side) => {
30
42
  const bestFirst = [...offers].sort((a, b) => new Dec(a.rate).minus(b.rate).mul(midnightBookBestFirst(side)).toNumber());
@@ -4,7 +4,6 @@ import type { MorphoMidnightBorrowQuote, MorphoMidnightPaybackQuote, MorphoMidni
4
4
  type TenorBookKey = 'asks' | 'bids';
5
5
  export declare const tenorBookKeyFor: (side: MorphoMidnightBookSide) => TenorBookKey;
6
6
  export declare const tenorBookRateToApyPercent: (rate: Dec.Value) => string;
7
- export declare const tenorCapPrice: (bestPrice: string, slippagePercent: Dec.Value, direction: 1 | -1, ttmDays: Dec.Value, boundRate?: Dec.Value) => string;
8
7
  interface TenorOfferCollateral {
9
8
  token: string;
10
9
  lltv: string | number;
@@ -119,7 +118,12 @@ export declare const parseTenorBookSide: (json: TenorBookResponse, side: MorphoM
119
118
  }[];
120
119
  export declare const parseTenorOrderBook: (json: TenorBookResponse, side: MorphoMidnightBookSide, loanSymbol: string) => MorphoMidnightParsedBook | null;
121
120
  export declare const getTenorMarketBook: (market: MorphoMidnightMarketData, network: NetworkNumber, side?: MorphoMidnightBookSide) => Promise<MorphoMidnightParsedBook | null>;
122
- export declare const getTenorBorrowQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, maxBorrowRate?: Dec.Value, taker?: string, network?: NetworkNumber) => Promise<MorphoMidnightBorrowQuote>;
123
- export declare const getTenorPaybackQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string, network?: NetworkNumber) => Promise<MorphoMidnightPaybackQuote>;
124
- export declare const getTenorPaybackUnitsQuote: (marketId: string, unitsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string, network?: NetworkNumber) => Promise<MorphoMidnightPaybackUnitsQuote>;
121
+ /**
122
+ * Tenor's router takes no slippage of its own — it prices the fill and hands back the offers. `slippagePercent`
123
+ * is therefore accepted only to keep the signature aligned with the Morpho-hosted quote that `index.ts`
124
+ * forwards to positionally; the guard comes from `rateSlippagePercent` via `midnightBoundPrice`.
125
+ */
126
+ export declare const getTenorBorrowQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, maxBorrowRate?: Dec.Value, taker?: string, rateSlippagePercent?: Dec.Value, network?: NetworkNumber) => Promise<MorphoMidnightBorrowQuote>;
127
+ export declare const getTenorPaybackQuote: (marketId: string, assetsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string, rateSlippagePercent?: Dec.Value, network?: NetworkNumber) => Promise<MorphoMidnightPaybackQuote>;
128
+ export declare const getTenorPaybackUnitsQuote: (marketId: string, unitsRaw: string, slippagePercent: Dec.Value, maturity: number, minPaybackRate?: Dec.Value, taker?: string, rateSlippagePercent?: Dec.Value, network?: NetworkNumber) => Promise<MorphoMidnightPaybackUnitsQuote>;
125
129
  export {};
@@ -12,7 +12,7 @@ import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
12
12
  import { ZERO_ADDRESS, ZERO_BYTES32 } from '../../constants';
13
13
  import { NetworkNumber, } from '../../types';
14
14
  import { isTenorMidnightMarket, MIDNIGHT_BASE } from '../../markets/morphoMidnight';
15
- import { buildMidnightParsedBook, midnightApyFromPrice, midnightPriceFromApy, midnightTimeToMaturityDays, } from './rate';
15
+ import { buildMidnightParsedBook, midnightApyFromPrice, midnightBoundPrice, midnightTimeToMaturityDays, } from './rate';
16
16
  // Notion doc by Rajko: https://app.notion.com/p/defisaver/Tenor-API-3ba0be682adc80dfad35c81a9a4cb442
17
17
  const TENOR_QUOTES_URL = 'https://router.tenor.finance/v1/quotes';
18
18
  const TENOR_ORDERBOOK_URL = 'https://router.tenor.finance/v1/orderbook';
@@ -23,12 +23,6 @@ export const tenorBookKeyFor = (side) => (side === 'bids' ? 'asks' : 'bids');
23
23
  // Tenor order-book levels are annualized APR in basis points: 25 → 0.25%, 700 → 7%.
24
24
  export const tenorBookRateToApyPercent = (rate) => new Dec(rate || 0).div(100).toString();
25
25
  const tenorFillPrice = (assets, units) => (new Dec(units).lte(0) ? '0' : new Dec(assets).div(units).toString());
26
- export const tenorCapPrice = (bestPrice, slippagePercent, direction, ttmDays, boundRate) => {
27
- if (boundRate !== undefined && new Dec(boundRate).gt(0))
28
- return midnightPriceFromApy(boundRate, ttmDays);
29
- const band = new Dec(1).add(new Dec(slippagePercent || 0).div(100).mul(direction));
30
- return Dec.max(0, new Dec(bestPrice).mul(band)).toString();
31
- };
32
26
  /**
33
27
  * Tenor's offer JSON is flat (market fields live on the offer). Morpho's is nested, and that nested
34
28
  * shape is what the app encodes for `Midnight.take`. Map Tenor into that shape so recipes stay on one encoder.
@@ -152,7 +146,12 @@ const fetchTenorQuote = (_a) => __awaiter(void 0, [_a], void 0, function* ({ mar
152
146
  };
153
147
  });
154
148
  const TENOR_NO_AVAILABLE_UNITS = '0';
155
- export const getTenorBorrowQuote = (marketId_1, assetsRaw_1, slippagePercent_1, maturity_1, maxBorrowRate_1, taker_1, ...args_1) => __awaiter(void 0, [marketId_1, assetsRaw_1, slippagePercent_1, maturity_1, maxBorrowRate_1, taker_1, ...args_1], void 0, function* (marketId, assetsRaw, slippagePercent, maturity, maxBorrowRate, taker, network = NetworkNumber.Base) {
149
+ /**
150
+ * Tenor's router takes no slippage of its own — it prices the fill and hands back the offers. `slippagePercent`
151
+ * is therefore accepted only to keep the signature aligned with the Morpho-hosted quote that `index.ts`
152
+ * forwards to positionally; the guard comes from `rateSlippagePercent` via `midnightBoundPrice`.
153
+ */
154
+ export const getTenorBorrowQuote = (marketId_1, assetsRaw_1, slippagePercent_1, maturity_1, maxBorrowRate_1, taker_1, rateSlippagePercent_1, ...args_1) => __awaiter(void 0, [marketId_1, assetsRaw_1, slippagePercent_1, maturity_1, maxBorrowRate_1, taker_1, rateSlippagePercent_1, ...args_1], void 0, function* (marketId, assetsRaw, slippagePercent, maturity, maxBorrowRate, taker, rateSlippagePercent, network = NetworkNumber.Base) {
156
155
  if (!isTenorMidnightMarket(marketId)) {
157
156
  throw new Error(tenorQuoteError(`Not a Tenor Midnight market: ${marketId}`));
158
157
  }
@@ -165,7 +164,7 @@ export const getTenorBorrowQuote = (marketId_1, assetsRaw_1, slippagePercent_1,
165
164
  const ttmDays = midnightTimeToMaturityDays(maturity);
166
165
  const bestPrice = tenorFillPrice(assetsRaw, quote.units);
167
166
  const estBorrowRate = midnightApyFromPrice(bestPrice, ttmDays);
168
- const capPrice = tenorCapPrice(bestPrice, slippagePercent, -1, ttmDays, maxBorrowRate);
167
+ const capPrice = midnightBoundPrice(estBorrowRate, ttmDays, 'ceiling', maxBorrowRate, rateSlippagePercent);
169
168
  const maxRate = midnightApyFromPrice(capPrice, ttmDays);
170
169
  const maxUnits = new Dec(capPrice).lte(0) ? '0' : new Dec(assetsRaw).div(capPrice).toFixed(0);
171
170
  return {
@@ -180,7 +179,7 @@ export const getTenorBorrowQuote = (marketId_1, assetsRaw_1, slippagePercent_1,
180
179
  takeableOffers: quote.offerFills,
181
180
  };
182
181
  });
183
- export const getTenorPaybackQuote = (marketId_1, assetsRaw_1, slippagePercent_1, maturity_1, minPaybackRate_1, taker_1, ...args_1) => __awaiter(void 0, [marketId_1, assetsRaw_1, slippagePercent_1, maturity_1, minPaybackRate_1, taker_1, ...args_1], void 0, function* (marketId, assetsRaw, slippagePercent, maturity, minPaybackRate, taker, network = NetworkNumber.Base) {
182
+ export const getTenorPaybackQuote = (marketId_1, assetsRaw_1, slippagePercent_1, maturity_1, minPaybackRate_1, taker_1, rateSlippagePercent_1, ...args_1) => __awaiter(void 0, [marketId_1, assetsRaw_1, slippagePercent_1, maturity_1, minPaybackRate_1, taker_1, rateSlippagePercent_1, ...args_1], void 0, function* (marketId, assetsRaw, slippagePercent, maturity, minPaybackRate, taker, rateSlippagePercent, network = NetworkNumber.Base) {
184
183
  if (!isTenorMidnightMarket(marketId)) {
185
184
  throw new Error(tenorQuoteError(`Not a Tenor Midnight market: ${marketId}`));
186
185
  }
@@ -193,7 +192,7 @@ export const getTenorPaybackQuote = (marketId_1, assetsRaw_1, slippagePercent_1,
193
192
  const ttmDays = midnightTimeToMaturityDays(maturity);
194
193
  const bestPrice = tenorFillPrice(assetsRaw, quote.units);
195
194
  const estPaybackRate = midnightApyFromPrice(bestPrice, ttmDays);
196
- const capPrice = tenorCapPrice(bestPrice, slippagePercent, 1, ttmDays, minPaybackRate);
195
+ const capPrice = midnightBoundPrice(estPaybackRate, ttmDays, 'floor', minPaybackRate, rateSlippagePercent);
197
196
  const minRate = midnightApyFromPrice(capPrice, ttmDays);
198
197
  const minUnits = new Dec(capPrice).lte(0) ? '0' : new Dec(assetsRaw).div(capPrice).toFixed(0, Dec.ROUND_DOWN);
199
198
  return {
@@ -208,7 +207,7 @@ export const getTenorPaybackQuote = (marketId_1, assetsRaw_1, slippagePercent_1,
208
207
  takeableOffers: quote.offerFills,
209
208
  };
210
209
  });
211
- export const getTenorPaybackUnitsQuote = (marketId_1, unitsRaw_1, slippagePercent_1, maturity_1, minPaybackRate_1, taker_1, ...args_1) => __awaiter(void 0, [marketId_1, unitsRaw_1, slippagePercent_1, maturity_1, minPaybackRate_1, taker_1, ...args_1], void 0, function* (marketId, unitsRaw, slippagePercent, maturity, minPaybackRate, taker, network = NetworkNumber.Base) {
210
+ export const getTenorPaybackUnitsQuote = (marketId_1, unitsRaw_1, slippagePercent_1, maturity_1, minPaybackRate_1, taker_1, rateSlippagePercent_1, ...args_1) => __awaiter(void 0, [marketId_1, unitsRaw_1, slippagePercent_1, maturity_1, minPaybackRate_1, taker_1, rateSlippagePercent_1, ...args_1], void 0, function* (marketId, unitsRaw, slippagePercent, maturity, minPaybackRate, taker, rateSlippagePercent, network = NetworkNumber.Base) {
212
211
  if (!isTenorMidnightMarket(marketId)) {
213
212
  throw new Error(tenorQuoteError(`Not a Tenor Midnight market: ${marketId}`));
214
213
  }
@@ -222,7 +221,7 @@ export const getTenorPaybackUnitsQuote = (marketId_1, unitsRaw_1, slippagePercen
222
221
  const newAssets = quote.buyerAssets;
223
222
  const bestPrice = tenorFillPrice(newAssets, unitsRaw);
224
223
  const estPaybackRate = midnightApyFromPrice(bestPrice, ttmDays);
225
- const capPrice = tenorCapPrice(bestPrice, slippagePercent, 1, ttmDays, minPaybackRate);
224
+ const capPrice = midnightBoundPrice(estPaybackRate, ttmDays, 'floor', minPaybackRate, rateSlippagePercent);
226
225
  const minRate = midnightApyFromPrice(capPrice, ttmDays);
227
226
  const maxAssets = new Dec(unitsRaw).mul(capPrice).toFixed(0, Dec.ROUND_UP);
228
227
  return {
package/esm/index.d.ts CHANGED
@@ -18,9 +18,8 @@ import * as exchange from './exchange';
18
18
  import * as morphoBlue from './morphoBlue';
19
19
  import * as morphoMidnight from './morphoMidnight';
20
20
  import * as llamaLend from './llamaLend';
21
- import * as eulerV2 from './eulerV2';
22
21
  import * as portfolio from './portfolio';
23
22
  import * as claiming from './claiming';
24
23
  import * as savings from './savings';
25
24
  export * from './types';
26
- export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, morphoMidnight, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
25
+ export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, morphoMidnight, llamaLend, fluid, portfolio, claiming, savings, };
package/esm/index.js CHANGED
@@ -18,9 +18,8 @@ import * as exchange from './exchange';
18
18
  import * as morphoBlue from './morphoBlue';
19
19
  import * as morphoMidnight from './morphoMidnight';
20
20
  import * as llamaLend from './llamaLend';
21
- import * as eulerV2 from './eulerV2';
22
21
  import * as portfolio from './portfolio';
23
22
  import * as claiming from './claiming';
24
23
  import * as savings from './savings';
25
24
  export * from './types';
26
- export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, morphoMidnight, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
25
+ export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, morphoMidnight, llamaLend, fluid, portfolio, claiming, savings, };
@@ -6,6 +6,5 @@ export { MorphoBlueMarkets, findMorphoBlueMarket } from './morphoBlue';
6
6
  export { MorphoMidnightMarkets, findMorphoMidnightMarket, isTenorMidnightMarket, morphoMidnightMarketCollateralParams, } from './morphoMidnight';
7
7
  export { LlamaLendMarkets } from './llamaLend';
8
8
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
9
- export { EulerV2Markets } from './euler';
10
9
  export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
11
10
  export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
@@ -6,6 +6,5 @@ export { MorphoBlueMarkets, findMorphoBlueMarket } from './morphoBlue';
6
6
  export { MorphoMidnightMarkets, findMorphoMidnightMarket, isTenorMidnightMarket, morphoMidnightMarketCollateralParams, } from './morphoMidnight';
7
7
  export { LlamaLendMarkets } from './llamaLend';
8
8
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
9
- export { EulerV2Markets } from './euler';
10
9
  export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
11
10
  export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
@@ -65,6 +65,8 @@ export declare const MORPHO_BLUE_WBTC_USDT_860: (networkId?: NetworkNumber) => M
65
65
  export declare const MORPHO_BLUE_WSTETH_USDT_860: (networkId?: NetworkNumber) => MorphoBlueMarketData;
66
66
  export declare const MORPHO_BLUE_SYRUPUSDC_RLUSD_915: (networkId?: NetworkNumber) => MorphoBlueMarketData;
67
67
  export declare const MORPHO_BLUE_WEETH_USDC_770: (networkId?: NetworkNumber) => MorphoBlueMarketData;
68
+ export declare const MORPHO_BLUE_WEETH_USDC_860: (networkId?: NetworkNumber) => MorphoBlueMarketData;
69
+ export declare const MORPHO_BLUE_WEETH_USDC_860_85252BB8: (networkId?: NetworkNumber) => MorphoBlueMarketData;
68
70
  export declare const MORPHO_BLUE_ETH_USDC_860_94B823E6: (networkId?: NetworkNumber) => MorphoBlueMarketData;
69
71
  export declare const MORPHO_BLUE_USD3_USDC_915: (networkId?: NetworkNumber) => MorphoBlueMarketData;
70
72
  export declare const MORPHO_BLUE_STUSDS_USDC_860: (networkId?: NetworkNumber) => MorphoBlueMarketData;
@@ -72,6 +74,7 @@ export declare const MORPHO_BLUE_CBBTC_RLUSD_860: (networkId?: NetworkNumber) =>
72
74
  export declare const MORPHO_BLUE_WBTC_ETH_915: (networkId?: NetworkNumber) => MorphoBlueMarketData;
73
75
  export declare const MORPHO_BLUE_CBBTC_ETH_915_12DBF493: (networkId?: NetworkNumber) => MorphoBlueMarketData;
74
76
  export declare const MORPHO_BLUE_WEETH_USDT_860: (networkId?: NetworkNumber) => MorphoBlueMarketData;
77
+ export declare const MORPHO_BLUE_WEETH_USDT_860_A6A4C1F1: (networkId?: NetworkNumber) => MorphoBlueMarketData;
75
78
  export declare const MORPHO_BLUE_SYRUPUSDT_USDT_915: (networkId?: NetworkNumber) => MorphoBlueMarketData;
76
79
  export declare const MORPHO_BLUE_CBBTC_PYUSD_860: (networkId?: NetworkNumber) => MorphoBlueMarketData;
77
80
  export declare const MORPHO_BLUE_WEETH_USDT_770: (networkId?: NetworkNumber) => MorphoBlueMarketData;
@@ -185,6 +188,8 @@ export declare const MorphoBlueMarkets: (networkId: NetworkNumber) => {
185
188
  readonly morphobluewstethusdt_860: MorphoBlueMarketData;
186
189
  readonly morphobluesyrupusdcrlusd_915: MorphoBlueMarketData;
187
190
  readonly morphoblueweethusdc_770: MorphoBlueMarketData;
191
+ readonly morphoblueweethusdc_860: MorphoBlueMarketData;
192
+ readonly morphoblueweethusdc_860_85252bb8: MorphoBlueMarketData;
188
193
  readonly morphoblueethusdc_860_94b823e6: MorphoBlueMarketData;
189
194
  readonly morphoblueusd3usdc_915: MorphoBlueMarketData;
190
195
  readonly morphobluestusdsusdc_860: MorphoBlueMarketData;
@@ -192,6 +197,7 @@ export declare const MorphoBlueMarkets: (networkId: NetworkNumber) => {
192
197
  readonly morphobluewbtceth_915: MorphoBlueMarketData;
193
198
  readonly morphobluecbbtceth_915_12dbf493: MorphoBlueMarketData;
194
199
  readonly morphoblueweethusdt_860: MorphoBlueMarketData;
200
+ readonly morphoblueweethusdt_860_a6a4c1f1: MorphoBlueMarketData;
195
201
  readonly morphobluesyrupusdtusdt_915: MorphoBlueMarketData;
196
202
  readonly morphobluecbbtcpyusd_860: MorphoBlueMarketData;
197
203
  readonly morphoblueweethusdt_770: MorphoBlueMarketData;
@@ -991,6 +991,36 @@ export const MORPHO_BLUE_WEETH_USDC_770 = (networkId = NetworkNumber.Eth) => ({
991
991
  marketId: '0x34377fc4f617c51818e92c79df31ff270c6a91bc94ad32e367fdf59b9f4ac5dd',
992
992
  protocolName: 'morpho-blue',
993
993
  });
994
+ export const MORPHO_BLUE_WEETH_USDC_860 = (networkId = NetworkNumber.Eth) => ({
995
+ chainIds: [NetworkNumber.Eth],
996
+ label: 'Morpho',
997
+ shortLabel: 'weETH/USDC',
998
+ value: MorphoBlueVersions.MorphoBlueWeEthUSDC_860,
999
+ url: 'weethusdc-61765602',
1000
+ loanToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
1001
+ collateralToken: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
1002
+ oracle: '0x5635a2F38c5dFd1d8fDB176d9CB5AEFA07bf6A68',
1003
+ oracleType: MorphoBlueOracleType.MARKET_RATE,
1004
+ irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1005
+ lltv: 0.86,
1006
+ marketId: '0x61765602144e91e5ac9f9e98b8584eae308f9951596fd7f5e0f59f21cd2bf664',
1007
+ protocolName: 'morpho-blue',
1008
+ });
1009
+ export const MORPHO_BLUE_WEETH_USDC_860_85252BB8 = (networkId = NetworkNumber.Eth) => ({
1010
+ chainIds: [NetworkNumber.Eth],
1011
+ label: 'Morpho',
1012
+ shortLabel: 'weETH/USDC',
1013
+ value: MorphoBlueVersions.MorphoBlueWeEthUSDC_860_85252bb8,
1014
+ url: 'weethusdc-85252bb8',
1015
+ loanToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
1016
+ collateralToken: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
1017
+ oracle: '0xa3A7A3ceFee206f9d7Fe00eC3C83324ED4228411',
1018
+ oracleType: MorphoBlueOracleType.MARKET_RATE,
1019
+ irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1020
+ lltv: 0.86,
1021
+ marketId: '0x85252bb8485c99bba46fe149c7dd2aad83672640f53c630890673cf1848ba16e',
1022
+ protocolName: 'morpho-blue',
1023
+ });
994
1024
  export const MORPHO_BLUE_ETH_USDC_860_94B823E6 = (networkId = NetworkNumber.Eth) => ({
995
1025
  chainIds: [NetworkNumber.Eth],
996
1026
  label: 'Morpho',
@@ -1096,6 +1126,21 @@ export const MORPHO_BLUE_WEETH_USDT_860 = (networkId = NetworkNumber.Eth) => ({
1096
1126
  marketId: '0xc2c53d2b868e163da71de14a5113cc2743fc9b5ad7488334720ed2846566a8f6',
1097
1127
  protocolName: 'morpho-blue',
1098
1128
  });
1129
+ export const MORPHO_BLUE_WEETH_USDT_860_A6A4C1F1 = (networkId = NetworkNumber.Eth) => ({
1130
+ chainIds: [NetworkNumber.Eth],
1131
+ label: 'Morpho',
1132
+ shortLabel: 'weETH/USDT',
1133
+ value: MorphoBlueVersions.MorphoBlueWeEthUSDT_860_a6a4c1f1,
1134
+ url: 'weethusdt-a6a4c1f1',
1135
+ loanToken: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
1136
+ collateralToken: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
1137
+ oracle: '0xa3A7A3ceFee206f9d7Fe00eC3C83324ED4228411',
1138
+ oracleType: MorphoBlueOracleType.MARKET_RATE,
1139
+ irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1140
+ lltv: 0.86,
1141
+ marketId: '0xa6a4c1f15490a1ff39d9de3a366b408dd5647a436d8b179726d3e0562aff1292',
1142
+ protocolName: 'morpho-blue',
1143
+ });
1099
1144
  export const MORPHO_BLUE_SYRUPUSDT_USDT_915 = (networkId = NetworkNumber.Eth) => ({
1100
1145
  chainIds: [NetworkNumber.Eth],
1101
1146
  label: 'Morpho',
@@ -1856,6 +1901,8 @@ export const MorphoBlueMarkets = (networkId) => ({
1856
1901
  [MorphoBlueVersions.MorphoBlueWstEthUSDT_860]: MORPHO_BLUE_WSTETH_USDT_860(networkId),
1857
1902
  [MorphoBlueVersions.MorphoBlueSyrupUSDCRLUSD_915]: MORPHO_BLUE_SYRUPUSDC_RLUSD_915(networkId),
1858
1903
  [MorphoBlueVersions.MorphoBlueWeEthUSDC_770]: MORPHO_BLUE_WEETH_USDC_770(networkId),
1904
+ [MorphoBlueVersions.MorphoBlueWeEthUSDC_860]: MORPHO_BLUE_WEETH_USDC_860(networkId),
1905
+ [MorphoBlueVersions.MorphoBlueWeEthUSDC_860_85252bb8]: MORPHO_BLUE_WEETH_USDC_860_85252BB8(networkId),
1859
1906
  [MorphoBlueVersions.MorphoBlueEthUSDC_860_94b823e6]: MORPHO_BLUE_ETH_USDC_860_94B823E6(networkId),
1860
1907
  [MorphoBlueVersions.MorphoBlueUSD3USDC_915]: MORPHO_BLUE_USD3_USDC_915(networkId),
1861
1908
  [MorphoBlueVersions.MorphoBlueStUSDSUSDC_860]: MORPHO_BLUE_STUSDS_USDC_860(networkId),
@@ -1863,6 +1910,7 @@ export const MorphoBlueMarkets = (networkId) => ({
1863
1910
  [MorphoBlueVersions.MorphoBlueWBTCEth_915]: MORPHO_BLUE_WBTC_ETH_915(networkId),
1864
1911
  [MorphoBlueVersions.MorphoBlueCbBTCEth_915_12dbf493]: MORPHO_BLUE_CBBTC_ETH_915_12DBF493(networkId),
1865
1912
  [MorphoBlueVersions.MorphoBlueWeEthUSDT_860]: MORPHO_BLUE_WEETH_USDT_860(networkId),
1913
+ [MorphoBlueVersions.MorphoBlueWeEthUSDT_860_a6a4c1f1]: MORPHO_BLUE_WEETH_USDT_860_A6A4C1F1(networkId),
1866
1914
  [MorphoBlueVersions.MorphoBlueSyrupUSDTUSDT_915]: MORPHO_BLUE_SYRUPUSDT_USDT_915(networkId),
1867
1915
  [MorphoBlueVersions.MorphoBlueCbBTCPYUSD_860]: MORPHO_BLUE_CBBTC_PYUSD_860(networkId),
1868
1916
  [MorphoBlueVersions.MorphoBlueWeEthUSDT_770]: MORPHO_BLUE_WEETH_USDT_770(networkId),
@@ -7,7 +7,7 @@ import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
7
7
  * Uses one shared, multicall-batched viem client (same pattern as getPortfolioData) so all
8
8
  * per-market reads collapse into a handful of RPC round trips.
9
9
  *
10
- * Not covered: Maker, Liquity, Liquity V2, Fluid, Euler V2 — these already expose cheap,
10
+ * Not covered: Maker, Liquity, Liquity V2, Fluid — these already expose cheap,
11
11
  * user-scoped discovery entry points elsewhere in the SDK (e.g. _getUserCdps, _getUserPositionsPortfolio).
12
12
  */
13
13
  export declare function getUserPositionsExistence(provider: EthereumProvider, network: NetworkNumber, address: EthAddress, isSim?: boolean): Promise<Record<string, boolean>>;