@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,21 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateVaultV2DeadShares = exports.validateVaultV1DeadShares = exports.validateBlueMarketDeadShares = exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
17
+ exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateLeverageReallocations = exports.computeLeveragePenaltyAssets = exports.validateVaultV2DeadShares = exports.validateVaultV1DeadShares = exports.validateBlueMarketDeadShares = exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.LEVERAGE_MAX_REALLOCATION_PENALTY = exports.LEVERAGE_MAX_ORACLE_DEVIATION = exports.LEVERAGE_MAX_EXECUTION_LOSS = exports.LEVERAGE_DEADLINE_WINDOW = exports.LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
18
+ exports.validateZeroExQuote = exports.getZeroExSwapRoute = exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = void 0;
4
19
  var callback_js_1 = require("./callback.js");
5
20
  Object.defineProperty(exports, "getMidnightBlueBuyCallbackAddress", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackAddress; } });
6
21
  Object.defineProperty(exports, "getMidnightBlueBuyCallbackData", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackData; } });
@@ -12,6 +27,11 @@ Object.defineProperty(exports, "DEFAULT_LLTV_BUFFER", { enumerable: true, get: f
12
27
  Object.defineProperty(exports, "DEFAULT_MAX_REALLOCATION_PENALTY", { enumerable: true, get: function () { return constant_js_1.DEFAULT_MAX_REALLOCATION_PENALTY; } });
13
28
  Object.defineProperty(exports, "DEFAULT_SUPPLY_TARGET_UTILIZATION", { enumerable: true, get: function () { return constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION; } });
14
29
  Object.defineProperty(exports, "DEFAULT_WITHDRAWAL_TARGET_UTILIZATION", { enumerable: true, get: function () { return constant_js_1.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION; } });
30
+ Object.defineProperty(exports, "LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR", { enumerable: true, get: function () { return constant_js_1.LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR; } });
31
+ Object.defineProperty(exports, "LEVERAGE_DEADLINE_WINDOW", { enumerable: true, get: function () { return constant_js_1.LEVERAGE_DEADLINE_WINDOW; } });
32
+ Object.defineProperty(exports, "LEVERAGE_MAX_EXECUTION_LOSS", { enumerable: true, get: function () { return constant_js_1.LEVERAGE_MAX_EXECUTION_LOSS; } });
33
+ Object.defineProperty(exports, "LEVERAGE_MAX_ORACLE_DEVIATION", { enumerable: true, get: function () { return constant_js_1.LEVERAGE_MAX_ORACLE_DEVIATION; } });
34
+ Object.defineProperty(exports, "LEVERAGE_MAX_REALLOCATION_PENALTY", { enumerable: true, get: function () { return constant_js_1.LEVERAGE_MAX_REALLOCATION_PENALTY; } });
15
35
  Object.defineProperty(exports, "MAX_ABSOLUTE_SHARE_PRICE", { enumerable: true, get: function () { return constant_js_1.MAX_ABSOLUTE_SHARE_PRICE; } });
16
36
  Object.defineProperty(exports, "MAX_REALLOCATION_PENALTY", { enumerable: true, get: function () { return constant_js_1.MAX_REALLOCATION_PENALTY; } });
17
37
  Object.defineProperty(exports, "MAX_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return constant_js_1.MAX_SLIPPAGE_TOLERANCE; } });
@@ -25,6 +45,10 @@ var deadShares_js_1 = require("./deadShares.js");
25
45
  Object.defineProperty(exports, "validateBlueMarketDeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateBlueMarketDeadShares; } });
26
46
  Object.defineProperty(exports, "validateVaultV1DeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateVaultV1DeadShares; } });
27
47
  Object.defineProperty(exports, "validateVaultV2DeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateVaultV2DeadShares; } });
48
+ __exportStar(require("./leverage/index.js"), exports);
49
+ var reallocations_js_1 = require("./leverage/reallocations.js");
50
+ Object.defineProperty(exports, "computeLeveragePenaltyAssets", { enumerable: true, get: function () { return reallocations_js_1.computeLeveragePenaltyAssets; } });
51
+ Object.defineProperty(exports, "validateLeverageReallocations", { enumerable: true, get: function () { return reallocations_js_1.validateLeverageReallocations; } });
28
52
  var metadata_js_1 = require("./metadata.js");
29
53
  Object.defineProperty(exports, "addTransactionMetadata", { enumerable: true, get: function () { return metadata_js_1.addTransactionMetadata; } });
30
54
  var previewVaultV2ForceWithdraw_js_1 = require("./previewVaultV2ForceWithdraw.js");
@@ -64,3 +88,6 @@ Object.defineProperty(exports, "computeVaultV2ForceWithdrawMinSharesBurnt", { en
64
88
  Object.defineProperty(exports, "computeVaultV2ForceWithdrawPlan", { enumerable: true, get: function () { return vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawPlan; } });
65
89
  Object.defineProperty(exports, "computeVaultV2ForceWithdrawSharesBurnt", { enumerable: true, get: function () { return vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawSharesBurnt; } });
66
90
  Object.defineProperty(exports, "resolveVaultV2ForceWithdrawEligibility", { enumerable: true, get: function () { return vaultV2ForceWithdrawPlan_js_1.resolveVaultV2ForceWithdrawEligibility; } });
91
+ var zeroExQuote_js_1 = require("./zeroExQuote.js");
92
+ Object.defineProperty(exports, "getZeroExSwapRoute", { enumerable: true, get: function () { return zeroExQuote_js_1.getZeroExSwapRoute; } });
93
+ Object.defineProperty(exports, "validateZeroExQuote", { enumerable: true, get: function () { return zeroExQuote_js_1.validateZeroExQuote; } });
@@ -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,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateLeverageInputs = exports.leverageDeadline = exports.computeLeverLimits = exports.computeLeverageOracleDeviation = exports.computeDeleverLimits = exports.computeCloseLimits = exports.computeCloseInterestBuffer = void 0;
4
+ var limits_js_1 = require("./limits.js");
5
+ Object.defineProperty(exports, "computeCloseInterestBuffer", { enumerable: true, get: function () { return limits_js_1.computeCloseInterestBuffer; } });
6
+ Object.defineProperty(exports, "computeCloseLimits", { enumerable: true, get: function () { return limits_js_1.computeCloseLimits; } });
7
+ Object.defineProperty(exports, "computeDeleverLimits", { enumerable: true, get: function () { return limits_js_1.computeDeleverLimits; } });
8
+ Object.defineProperty(exports, "computeLeverageOracleDeviation", { enumerable: true, get: function () { return limits_js_1.computeLeverageOracleDeviation; } });
9
+ Object.defineProperty(exports, "computeLeverLimits", { enumerable: true, get: function () { return limits_js_1.computeLeverLimits; } });
10
+ Object.defineProperty(exports, "leverageDeadline", { enumerable: true, get: function () { return limits_js_1.leverageDeadline; } });
11
+ Object.defineProperty(exports, "validateLeverageInputs", { enumerable: true, get: function () { return limits_js_1.validateLeverageInputs; } });
@@ -0,0 +1,472 @@
1
+ import { type AccrualPosition } from "@morpho-org/blue-sdk";
2
+ import { LEVERAGE_MAX_EXECUTION_LOSS } from "../constant.js";
3
+ /** Leverage action whose limits are computed. */
4
+ export type LeverageOperation = keyof typeof LEVERAGE_MAX_EXECUTION_LOSS;
5
+ /**
6
+ * Amounts of a 0x allowance-holder quote that the leverage limits read, in each token's smallest
7
+ * unit; a 0x quote of the same mode satisfies it. `exactInput` quotes (Delever)
8
+ * sell exactly `sellAmount` for an expected `buyAmount`, before slippage, and at least `minBuyAmount` after it. `exactOutput` quotes
9
+ * (Lever, Close) buy exactly `buyAmount` and spend at most `maxSellAmount`, which
10
+ * already includes the slippage the caller passed to 0x: the Settler pulls that whole amount and
11
+ * refunds the rest, so it is the swap's input cap as is. These amounts carry no slippage of their
12
+ * own, so the limits cannot tell a quote fetched with another tolerance: pass amounts from a quote
13
+ * fetched with the same `slippage`. The leverage builders check that on the full quote and throw
14
+ * `LeverageQuoteSlippageMismatchError`.
15
+ */
16
+ export type LeverageQuoteAmounts = {
17
+ readonly mode: "exactInput";
18
+ readonly sellAmount: bigint;
19
+ readonly buyAmount: bigint;
20
+ readonly minBuyAmount: bigint;
21
+ } | {
22
+ readonly mode: "exactOutput";
23
+ readonly maxSellAmount: bigint;
24
+ readonly buyAmount: bigint;
25
+ };
26
+ /**
27
+ * One-block state the leverage limits read: the block timestamp, the user's position on the
28
+ * action's market as stored at that block, not accrued to its timestamp, with the market's own oracle price
29
+ * when it could be read (it may be absent), and the market's per-second
30
+ * borrow rate at that block (WAD-scaled). Read all three at the same block:
31
+ * `MorphoBlue.getLeverageData` returns a `BlueLeverageData`, which extends this type, or build
32
+ * it as below.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { fetchAccrualPosition } from "@morpho-org/blue-sdk-viem";
37
+ * import type { LeverageLimitsData } from "@morpho-org/morpho-sdk";
38
+ * import { createPublicClient, http } from "viem";
39
+ * import { base } from "viem/chains";
40
+ *
41
+ * // The funded WETH/USDC position every leverage limits example reads: `userAddress` holds 30 WETH of
42
+ * // collateral against 60,060 USDC of debt on the WETH/USDC market, at block timestamp 1_700_000_000n,
43
+ * // and the market oracle reads 3,000 USDC per WETH.
44
+ * const client = createPublicClient({ chain: base, transport: http() });
45
+ * const block = await client.getBlock();
46
+ * const fetched = await fetchAccrualPosition(
47
+ * userAddress,
48
+ * wethUsdcMarketParams.id,
49
+ * client,
50
+ * { blockNumber: block.number },
51
+ * );
52
+ * // Pass the position as stored, as `getLeverageData` does: the limits accrue it once from the market's last
53
+ * // update, as Blue does. The borrow rate is read from a copy accrued to the block.
54
+ * const leverageData: LeverageLimitsData = {
55
+ * block: { timestamp: block.timestamp },
56
+ * position: fetched,
57
+ * borrowRate: fetched.market
58
+ * .accrueInterest(block.timestamp)
59
+ * .getEndBorrowRate(block.timestamp),
60
+ * };
61
+ * ```
62
+ */
63
+ export interface LeverageLimitsData {
64
+ readonly block: {
65
+ readonly timestamp: bigint;
66
+ };
67
+ readonly position: AccrualPosition;
68
+ readonly borrowRate: bigint;
69
+ }
70
+ /** Caller inputs shared by every leverage action. */
71
+ export interface LeverageLimitsInput {
72
+ readonly quote: LeverageQuoteAmounts;
73
+ readonly slippage: bigint;
74
+ readonly leverageData: LeverageLimitsData;
75
+ }
76
+ /** Caller inputs of {@link computeLeverLimits}. */
77
+ export interface LeverLimitsParams extends LeverageLimitsInput {
78
+ readonly intent: {
79
+ readonly collateralAssets: bigint;
80
+ readonly loanAssets: bigint;
81
+ };
82
+ readonly penaltyAssets: bigint;
83
+ }
84
+ /** Caller inputs of {@link computeDeleverLimits}: the quote's `sellAmount` is the collateral sold. */
85
+ export type DeleverLimitsParams = LeverageLimitsInput;
86
+ /** Caller inputs of {@link computeCloseLimits}: an exact-output quote buys the debt plus its interest buffer. */
87
+ export type CloseLimitsParams = LeverageLimitsInput;
88
+ /** Signed limits of a `zeroExLeverageBundlesV1Lever` call. */
89
+ export interface LeverLimits {
90
+ readonly minCollateralToBuy: bigint;
91
+ readonly maxBorrowAssets: bigint;
92
+ readonly maxSwapIn: bigint;
93
+ readonly penaltyAssets: bigint;
94
+ readonly maxLtv: bigint;
95
+ readonly deadline: bigint;
96
+ /** Worst price against the oracle, from {@link computeLeverageOracleDeviation}; at most 15% above it. */
97
+ readonly oracleDeviation: LeverageOracleDeviation;
98
+ }
99
+ /** Signed limits of a `zeroExLeverageBundlesV1Delever` call. */
100
+ export interface DeleverLimits {
101
+ readonly maxCollateralToSell: bigint;
102
+ readonly minRepayAssets: bigint;
103
+ readonly maxLtv: bigint;
104
+ readonly deadline: bigint;
105
+ /** Worst fill against the oracle, from {@link computeLeverageOracleDeviation}; reported, never refused. */
106
+ readonly oracleDeviation: LeverageOracleDeviation;
107
+ }
108
+ /** Signed limits of a `zeroExLeverageBundlesV1Close` call. */
109
+ export interface CloseLimits {
110
+ readonly maxCollateralIn: bigint;
111
+ readonly minLoanOut: bigint;
112
+ readonly deadline: bigint;
113
+ /** Worst fill against the oracle, from {@link computeLeverageOracleDeviation}; reported, never refused. */
114
+ readonly oracleDeviation: LeverageOracleDeviation;
115
+ }
116
+ /** A leverage action's worst signed price against the market oracle, from {@link computeLeverageOracleDeviation}. */
117
+ export interface LeverageOracleDeviation {
118
+ /** Worst price the action signs, loan-token units per collateral-token unit scaled by `ORACLE_PRICE_SCALE`, rounded down. */
119
+ readonly worstPrice: bigint;
120
+ /** Market oracle price at the data block, scaled by `ORACLE_PRICE_SCALE`. */
121
+ readonly oraclePrice: bigint;
122
+ /** Deviation from the oracle price, WAD-scaled, positive when it costs the user, rounded up. */
123
+ readonly deviation: bigint;
124
+ }
125
+ /**
126
+ * Oracle deviation a Lever, Delever or Close reports in its action metadata: `"measured"` with the worst price, the
127
+ * oracle price and the deviation. Every one of them swaps, so every one measures it: a Close without debt refuses
128
+ * with `LeverageCloseWithoutDebtError`.
129
+ */
130
+ export type LeverageActionOracleDeviation = {
131
+ readonly status: "measured";
132
+ } & LeverageOracleDeviation;
133
+ /**
134
+ * Returns the deadline of a leverage action: the data block's timestamp plus
135
+ * `LEVERAGE_DEADLINE_WINDOW` (1 hour). The caller cannot set it. It is the `deadline` to pass to
136
+ * `fetchZeroExQuote` and `validateZeroExQuote`, so the quote's Settler permit carries the deadline the action signs.
137
+ *
138
+ * @param leverageData - One-block leverage data.
139
+ * @returns Deadline in Unix seconds.
140
+ * @throws {InvalidBigIntInputError} when the data block timestamp is not a bigint.
141
+ * @throws {NonPositiveInputError} when the deadline is zero or negative.
142
+ * @throws {InputExceedsMaxError} when the deadline exceeds `uint256`.
143
+ * @example
144
+ * ```ts
145
+ * import { leverageDeadline } from "@morpho-org/morpho-sdk";
146
+ *
147
+ * // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
148
+ * const deadline = leverageDeadline(leverageData);
149
+ * // leverageData.block.timestamp === 1_700_000_000n
150
+ * // deadline === 1_700_003_600n
151
+ * ```
152
+ */
153
+ export declare const leverageDeadline: (leverageData: LeverageLimitsData) => bigint;
154
+ /**
155
+ * Validates the caller inputs shared by every leverage action and returns the position accrued to
156
+ * the data block. Slippage must be between zero and the action's
157
+ * `LEVERAGE_MAX_EXECUTION_LOSS`, and the quote must fix the side the action requires with positive
158
+ * amounts.
159
+ *
160
+ * @param params - Shared leverage inputs.
161
+ * @param params.operation - Leverage action.
162
+ * @param params.quote - Quote amounts.
163
+ * @param params.slippage - Caller slippage, WAD-scaled.
164
+ * @param params.leverageData - One-block leverage data.
165
+ * @returns The leverage data position accrued to the data block's timestamp.
166
+ * @throws {InvalidBigIntInputError} when `slippage`, `quote.buyAmount`, the quote's sell amount
167
+ * (`sellAmount`, or `maxSellAmount` for exact output), an exact-input quote's `minBuyAmount` or the data
168
+ * block timestamp is missing or not a bigint.
169
+ * @throws {InvalidLeverageOperationError} when `operation` is missing or not `lever`, `delever` or `close`.
170
+ * @throws {NegativeInputError} when `slippage` is negative.
171
+ * @throws {LeverageSlippageAboveLimitError} when `slippage` exceeds the action's limit.
172
+ * @throws {NonPositiveInputError} when the quote's sell amount or `buyAmount` is not positive.
173
+ * @throws {ZeroExQuoteMinBuyAmountBelowSlippageError} when an exact-input quote's `minBuyAmount` is zero or below
174
+ * `buyAmount × (1 − slippage)`, the slippage rounded down to whole parts per million.
175
+ * @throws {ZeroExQuoteRequiredError} when the quote is missing.
176
+ * @throws {ZeroExQuoteTypeMismatchError} when the quote fixes the wrong side.
177
+ * @throws {UnsupportedMarketIrmError} when accruing the position's debt needs an unsupported IRM.
178
+ * @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
179
+ * @example
180
+ * ```ts
181
+ * import { validateLeverageInputs } from "@morpho-org/morpho-sdk";
182
+ *
183
+ * // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
184
+ * const accrued = validateLeverageInputs({
185
+ * operation: "delever",
186
+ * quote: {
187
+ * mode: "exactInput",
188
+ * sellAmount: 10n ** 19n,
189
+ * buyAmount: 29_970_000_000n,
190
+ * minBuyAmount: 29_820_150_000n,
191
+ * },
192
+ * slippage: 5_000_000_000_000_000n,
193
+ * leverageData,
194
+ * });
195
+ * ```
196
+ */
197
+ export declare const validateLeverageInputs: (params: LeverageLimitsInput & {
198
+ readonly operation: LeverageOperation;
199
+ }) => AccrualPosition;
200
+ /** Inputs of {@link computeLeverageOracleDeviation}: a leverage action's signed swap bounds and the oracle price. */
201
+ export type LeverageOracleDeviationParams = {
202
+ readonly oraclePrice: bigint;
203
+ } & ({
204
+ readonly operation: "lever";
205
+ readonly limits: Pick<LeverLimits, "maxSwapIn" | "minCollateralToBuy">;
206
+ } | {
207
+ readonly operation: "delever";
208
+ readonly limits: Pick<DeleverLimits, "maxCollateralToSell" | "minRepayAssets">;
209
+ } | {
210
+ readonly operation: "close";
211
+ readonly limits: Pick<CloseLimits, "maxCollateralIn" | "minLoanOut">;
212
+ });
213
+ /**
214
+ * Computes how far a leverage action's worst signed execution price is from the market's oracle price, relative to
215
+ * the oracle value of the collateral traded, WAD-scaled and signed so that a positive value costs the user.
216
+ *
217
+ * - Lever buys `minCollateralToBuy` for at most `maxSwapIn`: `(maxSwapIn × SCALE − minCollateralToBuy × price) /
218
+ * (minCollateralToBuy × price)`, positive when it pays more than the oracle value.
219
+ * - Delever sells `maxCollateralToSell` for at least `minRepayAssets`, and Close sells at most `maxCollateralIn` for at
220
+ * least `minLoanOut`: `(collateral × price − loan × SCALE) / (collateral × price)`, positive when the worst fill
221
+ * returns less than the oracle value.
222
+ *
223
+ * `SCALE` is `ORACLE_PRICE_SCALE` (1e36): a Morpho oracle price is loan-token units per collateral-token unit, so
224
+ * token decimals need no adjustment. The result is rounded up (towards the unfavourable side), so for any whole WAD
225
+ * bound `max`, `deviation > max` exactly when the unrounded deviation exceeds it. Pure: reads nothing on chain.
226
+ * Lever refuses a deviation above `LEVERAGE_MAX_ORACLE_DEVIATION` (15%); Delever and Close return it in their
227
+ * limits and never refuse on it, so an app can warn or ask for confirmation at its own thresholds.
228
+ *
229
+ * @param params - The action, its signed swap bounds and the oracle price.
230
+ * @param params.operation - `"lever"`, `"delever"` or `"close"`.
231
+ * @param params.limits - Signed swap bounds, such as the action's limits or its `action.args`.
232
+ * @param params.oraclePrice - Market oracle price, scaled by `ORACLE_PRICE_SCALE`.
233
+ * @returns The worst price (rounded down), the oracle price and the deviation, WAD-scaled and rounded up:
234
+ * `150_000_000_000_000_000n` is 15% worse than the oracle, a negative value better.
235
+ * @throws {InvalidBigIntInputError} when `oraclePrice` or a bound is missing or not a bigint.
236
+ * @throws {NonPositiveInputError} when `oraclePrice` or the collateral bound is not positive.
237
+ * @throws {NegativeInputError} when the loan-token bound is negative.
238
+ * @throws {InvalidLeverageOperationError} when `operation` is not `lever`, `delever` or `close`.
239
+ * @example
240
+ * ```ts
241
+ * import { computeLeverageOracleDeviation } from "@morpho-org/morpho-sdk";
242
+ *
243
+ * // Selling 10 WETH (18 decimals) for at least 27,000 USDC (6 decimals) with the oracle at 3,000 USDC per WETH.
244
+ * const { deviation } = computeLeverageOracleDeviation({
245
+ * operation: "delever",
246
+ * limits: { maxCollateralToSell: 10n * 10n ** 18n, minRepayAssets: 27_000n * 10n ** 6n },
247
+ * oraclePrice: 3_000n * 10n ** 24n,
248
+ * });
249
+ * // deviation === 100_000_000_000_000_000n: the worst fill is 10% below the oracle value
250
+ * ```
251
+ */
252
+ export declare const computeLeverageOracleDeviation: (params: LeverageOracleDeviationParams) => LeverageOracleDeviation;
253
+ /**
254
+ * Computes the signed limits of a Lever from an exact-output 0x quote.
255
+ *
256
+ * - `minCollateralToBuy` is the quote's `buyAmount`; the swap input cap `maxSwapIn` is the quote's
257
+ * `maxSellAmount`, which already carries the caller's slippage: the bundle approves exactly
258
+ * `maxSwapIn` and the Settler pulls the whole `maxSellAmount` before refunding, so a smaller cap
259
+ * would revert. No oracle enters a bound.
260
+ * - The worst swap price, `maxSwapIn` per `minCollateralToBuy` scaled by `ORACLE_PRICE_SCALE`, must be at most
261
+ * `LEVERAGE_MAX_ORACLE_DEVIATION` (15%) above the market's oracle price at the data block; exactly 15% is
262
+ * accepted, and a price below the oracle, which favours the user, is never refused. The comparison is exact (cross-multiplied, no rounding). It refuses the Lever and changes no
263
+ * signed bound. The price and the debt are the data block's; until the deadline only the signed `maxLtv` and
264
+ * Blue's health check guard execution. The deviation compares `maxSwapIn` alone: reallocation penalties
265
+ * (`penaltyAssets`, at most 1% each) are paid on top.
266
+ * - `maxBorrowAssets = maxSwapIn + penaltyAssets − loanAssets`, so the contract's swap cap
267
+ * `loanAssets + maxBorrowAssets − penaltyAssets` equals the quote cap.
268
+ * - `maxLtv` is the LLTV minus `DEFAULT_LLTV_BUFFER`, never `type(uint256).max`. The worst fill is
269
+ * the full `maxBorrowAssets` borrowed with exactly `minCollateralToBuy` received, which is also the
270
+ * state Blue's health check sees mid-flow, before any surplus repays debt. It is checked with the
271
+ * contract's rounding (debt rounded up against collateral value, the bound rounded down), first
272
+ * against the LLTV (Blue's health check, `check: "health"`, also when `maxLtv` fails too, because
273
+ * the contract hits that check first), then against `maxLtv` (`check: "maxLtv"`). The debt is the position's
274
+ * debt at the data block; interest accrued before execution is not checked. `DEFAULT_LLTV_BUFFER` leaves room
275
+ * for it under the LLTV only: a worst fill at the signed `maxLtv` has none, so whether interest fits under
276
+ * `maxLtv` depends on the position and the fill, and a Lever that exceeds it reverts onchain.
277
+ * - The deadline is the leverage data timestamp plus `LEVERAGE_DEADLINE_WINDOW`.
278
+ *
279
+ * @param params - Lever inputs.
280
+ * @param params.intent - Collateral and loan assets the user deposits.
281
+ * @param params.quote - Exact-output quote amounts; `buyAmount` is the collateral to buy.
282
+ * @param params.slippage - Slippage the caller passed to 0x, WAD-scaled, at most 10%.
283
+ * @param params.leverageData - One-block leverage data.
284
+ * @param params.penaltyAssets - Total public-allocator penalty of the action's reallocations, summed
285
+ * per entry as the contract does (zero without reallocations).
286
+ * @returns The Lever's signed limits.
287
+ * @throws {InvalidBigIntInputError} when `slippage`, an intent amount, `penaltyAssets`, `quote.buyAmount`,
288
+ * `quote.maxSellAmount` or the data block timestamp is not a bigint.
289
+ * @throws {NegativeInputError} when an intent amount, `penaltyAssets` or `slippage` is negative.
290
+ * @throws {InputExceedsMaxError} when `loanAssets` exceeds `maxSwapIn + penaltyAssets`, which would
291
+ * lift the signed swap cap above the quote cap, or when an intent amount, `penaltyAssets`, a signed amount or
292
+ * the deadline exceeds the uint256 range.
293
+ * @throws {LeverageWorstFillLtvError} with `check: "health"` when the worst fill fails Blue's mid-flow
294
+ * health check at the LLTV, or `check: "maxLtv"` when it passes that check but exceeds `maxLtv`.
295
+ * @throws {LeverageSlippageAboveLimitError} when `slippage` exceeds 10%.
296
+ * @throws {ZeroExQuoteRequiredError} when the quote is missing.
297
+ * @throws {ZeroExQuoteTypeMismatchError} when the quote is not exact output.
298
+ * @throws {UnsupportedMarketIrmError} when accruing the position's debt needs an unsupported IRM.
299
+ * @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
300
+ * @throws {NonPositiveInputError} when a quote amount or the deadline is not positive.
301
+ * @throws {LeverageOraclePriceUnavailableError} when the market's oracle price is unknown or zero; a present price
302
+ * that is not a bigint throws `InvalidBigIntInputError`.
303
+ * @throws {LeverageOraclePriceDeviationError} when the worst swap price is more than
304
+ * `LEVERAGE_MAX_ORACLE_DEVIATION` (15%) above the oracle price.
305
+ * @example
306
+ * ```ts
307
+ * import { computeLeverLimits } from "@morpho-org/morpho-sdk";
308
+ *
309
+ * // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
310
+ * const limits = computeLeverLimits({
311
+ * intent: { collateralAssets: 10n ** 19n, loanAssets: 0n },
312
+ * quote: { mode: "exactOutput", maxSellAmount: 60_360_300_000n, buyAmount: 2n * 10n ** 19n },
313
+ * slippage: 5_000_000_000_000_000n,
314
+ * leverageData,
315
+ * penaltyAssets: 0n,
316
+ * });
317
+ * // limits.maxBorrowAssets === 60_360_300_000n: the 30 WETH position grows to 60 WETH
318
+ * ```
319
+ */
320
+ export declare const computeLeverLimits: (params: LeverLimitsParams) => LeverLimits;
321
+ /**
322
+ * Computes the signed limits of a Delever (pay back with collateral) from an exact-input 0x quote
323
+ * and the caller's slippage.
324
+ *
325
+ * - `maxCollateralToSell` is the quote's `sellAmount`; `minRepayAssets` is the quote's `minBuyAmount` as is, so
326
+ * 0x's floor is the one source of truth and a fill at it passes the bundle's output check. It must be positive
327
+ * and at least `buyAmount × (1 − slippage)`. That bound uses the whole-ppm slippage sent to 0x, which rounds the
328
+ * caller's slippage down and so raises the bound in the user's favour, and rounds the amount down as 0x does,
329
+ * so every quote 0x builds for that slippage passes and one unit less is refused. No oracle enters a bound.
330
+ * - `maxLtv` is the position's LTV with its debt accrued to the deadline, at the data block's
331
+ * oracle price (rounded up, as Blue's `getLtv`): the LTV of doing nothing until the deadline. A
332
+ * position already past the LLTV buffer can still delever. The accrual is a projection from the leverage data
333
+ * block's market and IRM state, run once from the market's stored last update as Blue accrues it, so a
334
+ * fetched position must be passed unaccrued: interest that follows it does not make a small Delever revert, but a rate
335
+ * that rises before execution can. The worst fill withdraws all of
336
+ * `maxCollateralToSell` and repays only `minRepayAssets` of the debt accrued to the deadline, the latest
337
+ * and costliest moment the contract can run; Blue checks health on that state before any surplus
338
+ * is repaid, and the contract checks `maxLtv` after it. Refuses when it fails either, so a Delever
339
+ * never ends above the LTV projected from the data block. That cap is fixed when the Delever is built: an
340
+ * oracle price rise or new debt before inclusion can let a poor fill raise the live LTV and still pass it.
341
+ *
342
+ * @param params - Delever inputs.
343
+ * @param params.quote - Exact-input quote amounts; `sellAmount` is the collateral to sell.
344
+ * @param params.slippage - Caller slippage, WAD-scaled, at most 10%.
345
+ * @param params.leverageData - One-block leverage data.
346
+ * @returns The Delever's signed limits.
347
+ * @throws {ZeroExQuoteMinBuyAmountBelowSlippageError} when `quote.minBuyAmount` is zero or below
348
+ * `buyAmount × (1 − slippage)`, the slippage rounded down to whole parts per million: the quote allows more
349
+ * slippage than the caller's. Fetch a new quote with the caller's slippage.
350
+ * @throws {RepayExceedsDebtError} when `minRepayAssets` exceeds the debt; use Close instead.
351
+ * @throws {RepaySharesExceedDebtError} when `minRepayAssets`, repaid by assets as the contract
352
+ * does, would burn more borrow shares than the position holds; use Close instead.
353
+ * @throws {WithdrawExceedsCollateralError} when `maxCollateralToSell` exceeds the position's collateral.
354
+ * @throws {LeverageWorstFillLtvError} when the worst fill fails Blue's health check or `maxLtv`, or
355
+ * when the collateral is worth zero at the market price, which would make `maxLtv` unlimited.
356
+ * @throws {LeverageSlippageAboveLimitError} when `slippage` exceeds 10%.
357
+ * @throws {ZeroExQuoteRequiredError} when the quote is missing.
358
+ * @throws {ZeroExQuoteTypeMismatchError} when the quote is not exact input.
359
+ * @throws {UnsupportedMarketIrmError} when accruing the position's debt needs an unsupported IRM.
360
+ * @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
361
+ * @throws {InvalidBigIntInputError} when `slippage`, `quote.buyAmount`, `quote.minBuyAmount`, the quote's sell amount
362
+ * or the data block timestamp is not a bigint.
363
+ * @throws {NegativeInputError} when `slippage` is negative.
364
+ * @throws {NonPositiveInputError} when `quote.sellAmount`, `quote.buyAmount` or the deadline is not positive.
365
+ * @throws {InputExceedsMaxError} when the deadline exceeds the uint256 range.
366
+ * @throws {LeverageOraclePriceUnavailableError} when the market's oracle price is unknown or zero; a present price
367
+ * that is not a bigint throws `InvalidBigIntInputError`.
368
+ * @example
369
+ * ```ts
370
+ * import { computeDeleverLimits } from "@morpho-org/morpho-sdk";
371
+ *
372
+ * // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
373
+ * const limits = computeDeleverLimits({
374
+ * quote: {
375
+ * mode: "exactInput",
376
+ * sellAmount: 10n ** 19n,
377
+ * buyAmount: 29_970_000_000n,
378
+ * minBuyAmount: 29_820_150_000n,
379
+ * },
380
+ * slippage: 5_000_000_000_000_000n,
381
+ * leverageData,
382
+ * });
383
+ * // limits.minRepayAssets === 29_820_150_000n
384
+ * ```
385
+ */
386
+ export declare const computeDeleverLimits: (params: DeleverLimitsParams) => DeleverLimits;
387
+ /**
388
+ * Computes the signed limits of a Close with debt, from an exact-output 0x quote and the caller's
389
+ * slippage. The Close keeps the collateral it does not sell.
390
+ *
391
+ * - `minLoanOut` is the quote's `buyAmount` and `maxCollateralIn` its `maxSellAmount`, which
392
+ * already carries the caller's slippage and must not exceed the position's collateral (the
393
+ * contract does not cap it). Unsold collateral returns to the wallet.
394
+ * - `minLoanOut` must cover the debt at the data block plus `computeCloseInterestBuffer` (at
395
+ * least 1 wei), as headroom for the interest that accrues before execution. It is not a minimum returned to the
396
+ * user: `maxCollateralIn` can be the whole collateral, so a fill at the floor can sell all of it, repay the debt
397
+ * and return nothing. The buffer is an estimate at the
398
+ * data block's borrow rate: it reduces interest-driven reverts of a fill at the floor but does not
399
+ * rule them out if the rate jumps before execution. The debt is never used as the floor.
400
+ * - Close has no `maxLtv`.
401
+ * - This helper only checks that `minLoanOut` covers at least the debt plus the buffer. `blueClose` accepts only that
402
+ * exact size and refuses a larger `buyAmount` with `LeverageCloseBuyAboveDebtError`, so a caller that uses this
403
+ * helper directly must enforce the exact size itself.
404
+ *
405
+ * A Close without debt has no limits: this function refuses it, and `blueClose` refuses it earlier with
406
+ * `LeverageCloseWithoutDebtError`.
407
+ *
408
+ * @param params - Close inputs.
409
+ * @param params.quote - Exact-output quote amounts.
410
+ * @param params.slippage - Caller slippage, WAD-scaled, at most 10%.
411
+ * @param params.leverageData - One-block leverage data.
412
+ * @returns The Close's signed limits.
413
+ * @throws {NonPositiveInputError} when the position has no debt, or a quote amount or the deadline is not positive.
414
+ * @throws {LeverageCloseInputExceedsCollateralError} when `maxCollateralIn` exceeds the collateral.
415
+ * @throws {LeverageCloseFloorBelowDebtPlusBufferError} when `minLoanOut` is below the debt plus the interest buffer.
416
+ * @throws {InputExceedsMaxError} when `minLoanOut` or the deadline exceeds the uint256 range.
417
+ * @throws {LeverageSlippageAboveLimitError} when `slippage` exceeds 10%.
418
+ * @throws {ZeroExQuoteRequiredError} when the quote is missing.
419
+ * @throws {ZeroExQuoteTypeMismatchError} when the quote is not an exact-output quote.
420
+ * @throws {UnsupportedMarketIrmError} when accruing the position's debt needs an unsupported IRM.
421
+ * @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
422
+ * @throws {InvalidBigIntInputError} when `slippage`, `quote.buyAmount`, the quote's sell amount or the data
423
+ * block timestamp is not a bigint, or when the position has debt and `leverageData.borrowRate` is not a bigint.
424
+ * @throws {NegativeInputError} when `slippage` is negative, or when the position has debt and `leverageData.borrowRate` is
425
+ * negative.
426
+ * @throws {LeverageOraclePriceUnavailableError} when the market's oracle price is unknown or zero; a present price
427
+ * that is not a bigint throws `InvalidBigIntInputError`.
428
+ * @example
429
+ * ```ts
430
+ * import { computeCloseInterestBuffer, computeCloseLimits } from "@morpho-org/morpho-sdk";
431
+ *
432
+ * // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
433
+ * // Size the exact-output quote from the same snapshot: the debt at the data block plus the interest buffer.
434
+ * const buyAmount =
435
+ * leverageData.position.accrueInterest(leverageData.block.timestamp).borrowAssets +
436
+ * computeCloseInterestBuffer(leverageData);
437
+ * const limits = computeCloseLimits({
438
+ * quote: { mode: "exactOutput", maxSellAmount: 205n * 10n ** 17n, buyAmount },
439
+ * slippage: 5_000_000_000_000_000n,
440
+ * leverageData,
441
+ * });
442
+ * // limits.minLoanOut === buyAmount: exactly the debt plus the buffer, the only size blueClose accepts
443
+ * ```
444
+ */
445
+ export declare const computeCloseLimits: (params: CloseLimitsParams) => CloseLimits;
446
+ /**
447
+ * Computes the interest buffer a Close floor must cover above the debt; a keep-collateral Close adds it to the debt when it asks 0x for an
448
+ * exact output: `debt × borrowRate × LEVERAGE_DEADLINE_WINDOW × LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR`,
449
+ * rounded up and at least 1 wei when there is debt, so `debt + buffer` always passes the floor
450
+ * check of `computeCloseLimits` (a zero-rate market included), with the debt and the market's
451
+ * per-second borrow rate at the data block. Not a
452
+ * safety value: the contract returns any excess to the user as loan token, and a shortfall only
453
+ * makes Blue's repay pull revert.
454
+ *
455
+ * @param leverageData - One-block leverage data.
456
+ * @returns Interest buffer in loan-token assets.
457
+ * @throws {InvalidBigIntInputError} when `leverageData.block.timestamp` is missing or not a bigint, or when the position
458
+ * has debt and `leverageData.borrowRate` is missing or not a bigint.
459
+ * @throws {NegativeInputError} when the position has debt and `leverageData.borrowRate` is negative.
460
+ * @throws {UnsupportedMarketIrmError} when accruing a debt needs an unsupported IRM.
461
+ * @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
462
+ * @example
463
+ * ```ts
464
+ * import { computeCloseInterestBuffer } from "@morpho-org/morpho-sdk";
465
+ *
466
+ * // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
467
+ * const buffer = computeCloseInterestBuffer(leverageData);
468
+ * const buyAmount =
469
+ * leverageData.position.accrueInterest(leverageData.block.timestamp).borrowAssets + buffer;
470
+ * ```
471
+ */
472
+ export declare const computeCloseInterestBuffer: (leverageData: LeverageLimitsData) => bigint;