@morpho-org/morpho-sdk 10.5.0 → 10.6.0-next.0

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 (192) hide show
  1. package/README.md +44 -1
  2. package/lib/cjs/abis.d.ts +794 -1
  3. package/lib/cjs/abis.js +815 -1
  4. package/lib/cjs/actions/blue/close.d.ts +169 -0
  5. package/lib/cjs/actions/blue/close.js +270 -0
  6. package/lib/cjs/actions/blue/common.js +2 -2
  7. package/lib/cjs/actions/blue/delever.d.ts +156 -0
  8. package/lib/cjs/actions/blue/delever.js +223 -0
  9. package/lib/cjs/actions/blue/index.d.ts +3 -0
  10. package/lib/cjs/actions/blue/index.js +3 -0
  11. package/lib/cjs/actions/blue/lever.d.ts +184 -0
  12. package/lib/cjs/actions/blue/lever.js +272 -0
  13. package/lib/cjs/actions/blue/leverageIntent.d.ts +65 -0
  14. package/lib/cjs/actions/blue/leverageIntent.js +103 -0
  15. package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  16. package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.js +59 -0
  17. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  18. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.js +193 -0
  19. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  20. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.js +66 -0
  21. package/lib/cjs/actions/requirements/blue/index.d.ts +3 -0
  22. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  23. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  24. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  25. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +11 -6
  26. package/lib/cjs/actions/requirements/getRequirementsApproval.js +29 -5
  27. package/lib/cjs/addresses.d.ts +1 -1
  28. package/lib/cjs/addresses.js +6 -1
  29. package/lib/cjs/blue/abis.d.ts +1 -1
  30. package/lib/cjs/blue/abis.js +5 -1
  31. package/lib/cjs/blue/addresses.d.ts +1 -1
  32. package/lib/cjs/blue/addresses.js +6 -1
  33. package/lib/cjs/blue/entities.d.ts +4 -4
  34. package/lib/cjs/blue/entities.js +3 -1
  35. package/lib/cjs/blue/errors.d.ts +2 -2
  36. package/lib/cjs/blue/errors.js +5 -1
  37. package/lib/cjs/blue/fetch.d.ts +2 -2
  38. package/lib/cjs/blue/fetch.js +3 -1
  39. package/lib/cjs/blue/utils.d.ts +1 -1
  40. package/lib/cjs/blue/utils.js +2 -1
  41. package/lib/cjs/constants.d.ts +1 -1
  42. package/lib/cjs/constants.js +6 -2
  43. package/lib/cjs/entities/blue/blue.d.ts +486 -2
  44. package/lib/cjs/entities/blue/blue.js +529 -34
  45. package/lib/cjs/entities/index.d.ts +5 -5
  46. package/lib/cjs/entities/index.js +3 -1
  47. package/lib/cjs/entities/requirements/assertContractCode.d.ts +0 -23
  48. package/lib/cjs/entities/requirements/assertContractCode.js +3 -28
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +39 -1
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +120 -2
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +232 -4
  53. package/lib/cjs/errors.d.ts +4 -4
  54. package/lib/cjs/errors.js +7 -5
  55. package/lib/cjs/fetch.d.ts +2 -2
  56. package/lib/cjs/fetch.js +3 -1
  57. package/lib/cjs/helpers/constant.d.ts +34 -0
  58. package/lib/cjs/helpers/constant.js +35 -1
  59. package/lib/cjs/helpers/deadShares.js +3 -0
  60. package/lib/cjs/helpers/getZeroExLeverageBundle.d.ts +13 -0
  61. package/lib/cjs/helpers/getZeroExLeverageBundle.js +27 -0
  62. package/lib/cjs/helpers/index.d.ts +4 -1
  63. package/lib/cjs/helpers/index.js +28 -1
  64. package/lib/cjs/helpers/leverage/index.d.ts +1 -0
  65. package/lib/cjs/helpers/leverage/index.js +11 -0
  66. package/lib/cjs/helpers/leverage/limits.d.ts +472 -0
  67. package/lib/cjs/helpers/leverage/limits.js +715 -0
  68. package/lib/cjs/helpers/leverage/positionMarket.d.ts +17 -0
  69. package/lib/cjs/helpers/leverage/positionMarket.js +28 -0
  70. package/lib/cjs/helpers/leverage/reallocations.d.ts +159 -0
  71. package/lib/cjs/helpers/leverage/reallocations.js +276 -0
  72. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  73. package/lib/cjs/helpers/validateRequirementSpender.js +4 -0
  74. package/lib/cjs/helpers/zeroExQuote.d.ts +250 -0
  75. package/lib/cjs/helpers/zeroExQuote.js +763 -0
  76. package/lib/cjs/index.d.ts +1 -0
  77. package/lib/cjs/index.js +5 -2
  78. package/lib/cjs/midnight/errors.d.ts +2 -1
  79. package/lib/cjs/midnight/errors.js +5 -4
  80. package/lib/cjs/reads/assertContractCode.d.ts +25 -0
  81. package/lib/cjs/reads/assertContractCode.js +30 -0
  82. package/lib/cjs/reads/fetchZeroExQuote.d.ts +123 -0
  83. package/lib/cjs/reads/fetchZeroExQuote.js +330 -0
  84. package/lib/cjs/types/action.d.ts +130 -1
  85. package/lib/cjs/types/error.d.ts +59 -0
  86. package/lib/cjs/types/error.js +82 -3
  87. package/lib/cjs/types/index.d.ts +2 -0
  88. package/lib/cjs/types/index.js +2 -0
  89. package/lib/cjs/types/leverageError.d.ts +1552 -0
  90. package/lib/cjs/types/leverageError.js +1711 -0
  91. package/lib/cjs/types/zeroEx.d.ts +171 -0
  92. package/lib/cjs/types/zeroEx.js +2 -0
  93. package/lib/cjs/utils.d.ts +2 -2
  94. package/lib/cjs/utils.js +4 -2
  95. package/lib/cjs/version.d.ts +1 -1
  96. package/lib/cjs/version.js +1 -1
  97. package/lib/esm/abis.d.ts +794 -1
  98. package/lib/esm/abis.js +810 -1
  99. package/lib/esm/actions/blue/close.d.ts +169 -0
  100. package/lib/esm/actions/blue/close.js +266 -0
  101. package/lib/esm/actions/blue/common.js +3 -3
  102. package/lib/esm/actions/blue/delever.d.ts +156 -0
  103. package/lib/esm/actions/blue/delever.js +219 -0
  104. package/lib/esm/actions/blue/index.d.ts +3 -0
  105. package/lib/esm/actions/blue/index.js +3 -0
  106. package/lib/esm/actions/blue/lever.d.ts +184 -0
  107. package/lib/esm/actions/blue/lever.js +268 -0
  108. package/lib/esm/actions/blue/leverageIntent.d.ts +65 -0
  109. package/lib/esm/actions/blue/leverageIntent.js +96 -0
  110. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  111. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.js +55 -0
  112. package/lib/esm/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  113. package/lib/esm/actions/requirements/blue/getLeverageRequirements.js +189 -0
  114. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  115. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.js +62 -0
  116. package/lib/esm/actions/requirements/blue/index.d.ts +3 -0
  117. package/lib/esm/actions/requirements/blue/index.js +3 -0
  118. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  119. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  120. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +11 -6
  121. package/lib/esm/actions/requirements/getRequirementsApproval.js +29 -5
  122. package/lib/esm/addresses.d.ts +1 -1
  123. package/lib/esm/addresses.js +1 -1
  124. package/lib/esm/blue/abis.d.ts +1 -1
  125. package/lib/esm/blue/abis.js +1 -1
  126. package/lib/esm/blue/addresses.d.ts +1 -1
  127. package/lib/esm/blue/addresses.js +1 -1
  128. package/lib/esm/blue/entities.d.ts +4 -4
  129. package/lib/esm/blue/entities.js +2 -2
  130. package/lib/esm/blue/errors.d.ts +2 -2
  131. package/lib/esm/blue/errors.js +2 -2
  132. package/lib/esm/blue/fetch.d.ts +2 -2
  133. package/lib/esm/blue/fetch.js +2 -2
  134. package/lib/esm/blue/utils.d.ts +1 -1
  135. package/lib/esm/blue/utils.js +1 -1
  136. package/lib/esm/constants.d.ts +1 -1
  137. package/lib/esm/constants.js +1 -1
  138. package/lib/esm/entities/blue/blue.d.ts +486 -2
  139. package/lib/esm/entities/blue/blue.js +501 -6
  140. package/lib/esm/entities/index.d.ts +5 -5
  141. package/lib/esm/entities/index.js +2 -2
  142. package/lib/esm/entities/requirements/assertContractCode.d.ts +0 -23
  143. package/lib/esm/entities/requirements/assertContractCode.js +1 -25
  144. package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
  145. package/lib/esm/entities/vaultV2/vaultV2.js +40 -2
  146. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +120 -2
  147. package/lib/esm/entities/vaultV2BlueReallocationData.js +233 -5
  148. package/lib/esm/errors.d.ts +4 -4
  149. package/lib/esm/errors.js +4 -4
  150. package/lib/esm/fetch.d.ts +2 -2
  151. package/lib/esm/fetch.js +2 -2
  152. package/lib/esm/helpers/constant.d.ts +34 -0
  153. package/lib/esm/helpers/constant.js +34 -0
  154. package/lib/esm/helpers/deadShares.js +4 -1
  155. package/lib/esm/helpers/getZeroExLeverageBundle.d.ts +13 -0
  156. package/lib/esm/helpers/getZeroExLeverageBundle.js +23 -0
  157. package/lib/esm/helpers/index.d.ts +4 -1
  158. package/lib/esm/helpers/index.js +4 -1
  159. package/lib/esm/helpers/leverage/index.d.ts +1 -0
  160. package/lib/esm/helpers/leverage/index.js +1 -0
  161. package/lib/esm/helpers/leverage/limits.d.ts +472 -0
  162. package/lib/esm/helpers/leverage/limits.js +705 -0
  163. package/lib/esm/helpers/leverage/positionMarket.d.ts +17 -0
  164. package/lib/esm/helpers/leverage/positionMarket.js +24 -0
  165. package/lib/esm/helpers/leverage/reallocations.d.ts +159 -0
  166. package/lib/esm/helpers/leverage/reallocations.js +271 -0
  167. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  168. package/lib/esm/helpers/validateRequirementSpender.js +5 -1
  169. package/lib/esm/helpers/zeroExQuote.d.ts +250 -0
  170. package/lib/esm/helpers/zeroExQuote.js +754 -0
  171. package/lib/esm/index.d.ts +1 -0
  172. package/lib/esm/index.js +1 -0
  173. package/lib/esm/midnight/errors.d.ts +2 -1
  174. package/lib/esm/midnight/errors.js +2 -1
  175. package/lib/esm/reads/assertContractCode.d.ts +25 -0
  176. package/lib/esm/reads/assertContractCode.js +26 -0
  177. package/lib/esm/reads/fetchZeroExQuote.d.ts +123 -0
  178. package/lib/esm/reads/fetchZeroExQuote.js +326 -0
  179. package/lib/esm/types/action.d.ts +130 -1
  180. package/lib/esm/types/error.d.ts +59 -0
  181. package/lib/esm/types/error.js +76 -0
  182. package/lib/esm/types/index.d.ts +2 -0
  183. package/lib/esm/types/index.js +2 -0
  184. package/lib/esm/types/leverageError.d.ts +1552 -0
  185. package/lib/esm/types/leverageError.js +1660 -0
  186. package/lib/esm/types/zeroEx.d.ts +171 -0
  187. package/lib/esm/types/zeroEx.js +1 -0
  188. package/lib/esm/utils.d.ts +2 -2
  189. package/lib/esm/utils.js +2 -2
  190. package/lib/esm/version.d.ts +1 -1
  191. package/lib/esm/version.js +1 -1
  192. package/package.json +7 -7
@@ -1,6 +1,6 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  fetchPreLiquidationParams as fetchBluePreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
5
+ fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
6
6
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
package/lib/esm/fetch.js CHANGED
@@ -1,6 +1,6 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  fetchPreLiquidationParams as fetchBluePreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
5
+ fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
6
6
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
@@ -21,8 +21,42 @@ export declare const MAX_SLIPPAGE_TOLERANCE: bigint;
21
21
  export declare const DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
22
22
  /** Maximum Vault V2 reallocation penalty: 100%. */
23
23
  export declare const MAX_REALLOCATION_PENALTY = 1000000000000000000n;
24
+ /**
25
+ * Maximum penalty rate a ZeroExLeverageBundlesV1 Lever accepts per public-allocator reallocation:
26
+ * 1%, WAD-scaled. Fixed; no caller option.
27
+ */
28
+ export declare const LEVERAGE_MAX_REALLOCATION_PENALTY: bigint;
24
29
  /** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
25
30
  export declare const DEFAULT_LLTV_BUFFER: bigint;
31
+ /**
32
+ * SDK slippage ceiling per leverage action, WAD-scaled: `MAX_SLIPPAGE_TOLERANCE` (10%) for every action, the
33
+ * ceiling `fetchZeroExQuote` enforces, so the fetch and the builders cannot drift apart. Not configurable.
34
+ */
35
+ export declare const LEVERAGE_MAX_EXECUTION_LOSS: Readonly<{
36
+ readonly lever: bigint;
37
+ readonly delever: bigint;
38
+ readonly close: bigint;
39
+ }>;
40
+ /**
41
+ * Largest amount a Lever's worst swap price (`maxSwapIn` per `minCollateralToBuy`) may be above the market's oracle
42
+ * price, WAD-scaled: 15%. Exactly 15% is accepted, and a price below the oracle, which favours the user, is never
43
+ * refused. Delever and Close are not checked. The worst price uses `maxSwapIn`, which already includes the caller's
44
+ * slippage, so the room left for a gap between 0x's price and the oracle is about 15% minus that slippage (5% at the
45
+ * 10% ceiling).
46
+ * Not configurable.
47
+ */
48
+ export declare const LEVERAGE_MAX_ORACLE_DEVIATION: bigint;
49
+ /** Leverage deadline window after the data block, in seconds (1 hour). */
50
+ export declare const LEVERAGE_DEADLINE_WINDOW = 3600n;
51
+ /**
52
+ * Margin applied to the interest a Close's debt may accrue before its deadline: the buffer is the debt accrued for
53
+ * the one-hour deadline window at 4× the data block's borrow rate. The factor matches the AdaptiveCurveIrm curve
54
+ * steepness (`AdaptiveCurveIrmLib.CURVE_STEEPNESS` in blue-sdk), the most utilization can raise the rate over its
55
+ * rate at target, while that rate at target itself drifts by well under 1% in an hour (`ADJUSTMENT_SPEED` is 50 per
56
+ * year). It does not cover a rate that rises more than 4×, such as one quoted below target that jumps to full
57
+ * utilization; the Close then reverts instead of overpaying. Fixed; no caller option.
58
+ */
59
+ export declare const LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR = 4n;
26
60
  /**
27
61
  * Forward interest-accrual window, in seconds (2 hours), reserved in target-market
28
62
  * cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
@@ -23,8 +23,42 @@ export const MAX_SLIPPAGE_TOLERANCE = MathLib.WAD / 10n;
23
23
  export const DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
24
24
  /** Maximum Vault V2 reallocation penalty: 100%. */
25
25
  export const MAX_REALLOCATION_PENALTY = MathLib.WAD;
26
+ /**
27
+ * Maximum penalty rate a ZeroExLeverageBundlesV1 Lever accepts per public-allocator reallocation:
28
+ * 1%, WAD-scaled. Fixed; no caller option.
29
+ */
30
+ export const LEVERAGE_MAX_REALLOCATION_PENALTY = MathLib.WAD / 100n;
26
31
  /** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
27
32
  export const DEFAULT_LLTV_BUFFER = MathLib.WAD / 200n;
33
+ /**
34
+ * SDK slippage ceiling per leverage action, WAD-scaled: `MAX_SLIPPAGE_TOLERANCE` (10%) for every action, the
35
+ * ceiling `fetchZeroExQuote` enforces, so the fetch and the builders cannot drift apart. Not configurable.
36
+ */
37
+ export const LEVERAGE_MAX_EXECUTION_LOSS = Object.freeze({
38
+ lever: MAX_SLIPPAGE_TOLERANCE,
39
+ delever: MAX_SLIPPAGE_TOLERANCE,
40
+ close: MAX_SLIPPAGE_TOLERANCE,
41
+ });
42
+ /**
43
+ * Largest amount a Lever's worst swap price (`maxSwapIn` per `minCollateralToBuy`) may be above the market's oracle
44
+ * price, WAD-scaled: 15%. Exactly 15% is accepted, and a price below the oracle, which favours the user, is never
45
+ * refused. Delever and Close are not checked. The worst price uses `maxSwapIn`, which already includes the caller's
46
+ * slippage, so the room left for a gap between 0x's price and the oracle is about 15% minus that slippage (5% at the
47
+ * 10% ceiling).
48
+ * Not configurable.
49
+ */
50
+ export const LEVERAGE_MAX_ORACLE_DEVIATION = (MathLib.WAD * 15n) / 100n;
51
+ /** Leverage deadline window after the data block, in seconds (1 hour). */
52
+ export const LEVERAGE_DEADLINE_WINDOW = 3600n;
53
+ /**
54
+ * Margin applied to the interest a Close's debt may accrue before its deadline: the buffer is the debt accrued for
55
+ * the one-hour deadline window at 4× the data block's borrow rate. The factor matches the AdaptiveCurveIrm curve
56
+ * steepness (`AdaptiveCurveIrmLib.CURVE_STEEPNESS` in blue-sdk), the most utilization can raise the rate over its
57
+ * rate at target, while that rate at target itself drifts by well under 1% in an hour (`ADJUSTMENT_SPEED` is 50 per
58
+ * year). It does not cover a rate that rises more than 4×, such as one quoted below target that jumps to full
59
+ * utilization; the Close then reverts instead of overpaying. Fixed; no caller option.
60
+ */
61
+ export const LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR = 4n;
28
62
  /**
29
63
  * Forward interest-accrual window, in seconds (2 hours), reserved in target-market
30
64
  * cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
@@ -1,4 +1,4 @@
1
- import { AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
1
+ import { AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
2
2
  import { InsufficientDeadSharesError, MissingDeadSharesDataError, } from "../types/error.js";
3
3
  import { MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS } from "./constant.js";
4
4
  /**
@@ -188,6 +188,9 @@ function getDeadSharesAbsoluteCap(id, { absoluteCaps, entity, adapter, }) {
188
188
  }
189
189
  /** Checks the currently allocated positions of one supported adapter. @internal */
190
190
  function assertAdapterDeadShares(adapter, { absoluteCaps, entity, }) {
191
+ if (adapter instanceof AccrualVaultV2MidnightAdapter) {
192
+ return;
193
+ }
191
194
  if (adapter instanceof AccrualVaultV2MorphoVaultV1Adapter) {
192
195
  const id = VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
193
196
  if (getDeadSharesAbsoluteCap(id, {
@@ -0,0 +1,13 @@
1
+ import { type Address } from "viem";
2
+ /**
3
+ * Returns the ZeroExLeverageBundlesV1 address registered for `chainId`, whether or not the bundle
4
+ * can run there.
5
+ *
6
+ * @param chainId - Target chain id.
7
+ * @returns The registered ZeroExLeverageBundlesV1 address.
8
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
9
+ * @throws {LeverageUnsupportedChainError} with reason `noBundle` when no bundle, the zero address or a value that
10
+ * is not an address is registered.
11
+ * @internal
12
+ */
13
+ export declare const getRegisteredZeroExLeverageBundle: (chainId: number) => Address;
@@ -0,0 +1,23 @@
1
+ import { getChainAddresses } from "@morpho-org/blue-sdk";
2
+ import { isAddress, isAddressEqual, zeroAddress } from "viem";
3
+ import { LeverageUnsupportedChainError } from "../types/index.js";
4
+ /**
5
+ * Returns the ZeroExLeverageBundlesV1 address registered for `chainId`, whether or not the bundle
6
+ * can run there.
7
+ *
8
+ * @param chainId - Target chain id.
9
+ * @returns The registered ZeroExLeverageBundlesV1 address.
10
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
11
+ * @throws {LeverageUnsupportedChainError} with reason `noBundle` when no bundle, the zero address or a value that
12
+ * is not an address is registered.
13
+ * @internal
14
+ */
15
+ export const getRegisteredZeroExLeverageBundle = (chainId) => {
16
+ const bundle = getChainAddresses(chainId).bundles?.zeroExLeverageBundlesV1;
17
+ if (typeof bundle !== "string" ||
18
+ !isAddress(bundle, { strict: false }) ||
19
+ isAddressEqual(bundle, zeroAddress)) {
20
+ throw new LeverageUnsupportedChainError({ chainId, reason: "noBundle" });
21
+ }
22
+ return bundle;
23
+ };
@@ -1,6 +1,8 @@
1
1
  export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR, LEVERAGE_DEADLINE_WINDOW, LEVERAGE_MAX_EXECUTION_LOSS, LEVERAGE_MAX_ORACLE_DEVIATION, LEVERAGE_MAX_REALLOCATION_PENALTY, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
3
3
  export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
4
+ export * from "./leverage/index.js";
5
+ export { computeLeveragePenaltyAssets, type LeverageAllocatorState, type LeverageReallocation, validateLeverageReallocations, } from "./leverage/reallocations.js";
4
6
  export { addTransactionMetadata } from "./metadata.js";
5
7
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
6
8
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
@@ -11,3 +13,4 @@ export { getMidnightMaxSafeDebt, validateAccrualPosition, validateChainId, valid
11
13
  export { validateOfferSides } from "./validateOfferSides.js";
12
14
  export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
13
15
  export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
16
+ export { getZeroExSwapRoute, validateZeroExQuote, type ZeroExSwapRoute, } from "./zeroExQuote.js";
@@ -1,6 +1,8 @@
1
1
  export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR, LEVERAGE_DEADLINE_WINDOW, LEVERAGE_MAX_EXECUTION_LOSS, LEVERAGE_MAX_ORACLE_DEVIATION, LEVERAGE_MAX_REALLOCATION_PENALTY, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
3
3
  export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
4
+ export * from "./leverage/index.js";
5
+ export { computeLeveragePenaltyAssets, validateLeverageReallocations, } from "./leverage/reallocations.js";
4
6
  export { addTransactionMetadata } from "./metadata.js";
5
7
  export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
6
8
  export { previewVaultV2InKindRedeem, } from "./previewVaultV2InKindRedeem.js";
@@ -11,3 +13,4 @@ export { getMidnightMaxSafeDebt, validateAccrualPosition, validateChainId, valid
11
13
  export { validateOfferSides } from "./validateOfferSides.js";
12
14
  export { validateRequirementSpender, } from "./validateRequirementSpender.js";
13
15
  export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
16
+ export { getZeroExSwapRoute, validateZeroExQuote, } from "./zeroExQuote.js";
@@ -0,0 +1 @@
1
+ export { type CloseLimits, type CloseLimitsParams, computeCloseInterestBuffer, computeCloseLimits, computeDeleverLimits, computeLeverageOracleDeviation, computeLeverLimits, type DeleverLimits, type DeleverLimitsParams, type LeverageActionOracleDeviation, type LeverageLimitsData, type LeverageLimitsInput, type LeverageOperation, type LeverageOracleDeviation, type LeverageOracleDeviationParams, type LeverageQuoteAmounts, type LeverLimits, type LeverLimitsParams, leverageDeadline, validateLeverageInputs, } from "./limits.js";
@@ -0,0 +1 @@
1
+ export { computeCloseInterestBuffer, computeCloseLimits, computeDeleverLimits, computeLeverageOracleDeviation, computeLeverLimits, leverageDeadline, validateLeverageInputs, } from "./limits.js";