@morpho-org/morpho-sdk 10.5.0-next.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 (170) hide show
  1. package/README.md +44 -1
  2. package/lib/cjs/abis.d.ts +793 -0
  3. package/lib/cjs/abis.js +811 -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/midnight/supplyCollateralTakeBorrow.js +16 -11
  16. package/lib/cjs/actions/midnight/takeBorrow.js +14 -8
  17. package/lib/cjs/actions/midnight/takeLend.js +15 -9
  18. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
  19. package/lib/cjs/actions/midnight/takeWithdraw.js +14 -8
  20. package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  21. package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.js +59 -0
  22. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  23. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.js +193 -0
  24. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  25. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.js +66 -0
  26. package/lib/cjs/actions/requirements/blue/index.d.ts +3 -0
  27. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  30. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +11 -6
  31. package/lib/cjs/actions/requirements/getRequirementsApproval.js +29 -5
  32. package/lib/cjs/addresses.d.ts +1 -1
  33. package/lib/cjs/addresses.js +6 -1
  34. package/lib/cjs/blue/addresses.d.ts +1 -1
  35. package/lib/cjs/blue/addresses.js +6 -1
  36. package/lib/cjs/constants.d.ts +1 -1
  37. package/lib/cjs/constants.js +7 -2
  38. package/lib/cjs/entities/blue/blue.d.ts +486 -2
  39. package/lib/cjs/entities/blue/blue.js +529 -34
  40. package/lib/cjs/entities/index.d.ts +1 -1
  41. package/lib/cjs/entities/midnight/midnight.d.ts +6 -0
  42. package/lib/cjs/entities/midnight/midnight.js +21 -2
  43. package/lib/cjs/entities/requirements/assertContractCode.d.ts +0 -23
  44. package/lib/cjs/entities/requirements/assertContractCode.js +3 -28
  45. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +117 -0
  46. package/lib/cjs/entities/vaultV2BlueReallocationData.js +226 -2
  47. package/lib/cjs/helpers/constant.d.ts +41 -0
  48. package/lib/cjs/helpers/constant.js +42 -1
  49. package/lib/cjs/helpers/getZeroExLeverageBundle.d.ts +13 -0
  50. package/lib/cjs/helpers/getZeroExLeverageBundle.js +27 -0
  51. package/lib/cjs/helpers/index.d.ts +4 -1
  52. package/lib/cjs/helpers/index.js +29 -1
  53. package/lib/cjs/helpers/leverage/index.d.ts +1 -0
  54. package/lib/cjs/helpers/leverage/index.js +11 -0
  55. package/lib/cjs/helpers/leverage/limits.d.ts +472 -0
  56. package/lib/cjs/helpers/leverage/limits.js +715 -0
  57. package/lib/cjs/helpers/leverage/positionMarket.d.ts +17 -0
  58. package/lib/cjs/helpers/leverage/positionMarket.js +28 -0
  59. package/lib/cjs/helpers/leverage/reallocations.d.ts +159 -0
  60. package/lib/cjs/helpers/leverage/reallocations.js +276 -0
  61. package/lib/cjs/helpers/validate.d.ts +14 -0
  62. package/lib/cjs/helpers/validate.js +25 -1
  63. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  64. package/lib/cjs/helpers/validateRequirementSpender.js +4 -0
  65. package/lib/cjs/helpers/zeroExQuote.d.ts +250 -0
  66. package/lib/cjs/helpers/zeroExQuote.js +763 -0
  67. package/lib/cjs/index.d.ts +1 -0
  68. package/lib/cjs/index.js +5 -2
  69. package/lib/cjs/reads/assertContractCode.d.ts +25 -0
  70. package/lib/cjs/reads/assertContractCode.js +30 -0
  71. package/lib/cjs/reads/fetchZeroExQuote.d.ts +123 -0
  72. package/lib/cjs/reads/fetchZeroExQuote.js +330 -0
  73. package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +4 -0
  74. package/lib/cjs/transactionPlan/midnight/takeBorrow.js +8 -2
  75. package/lib/cjs/types/action.d.ts +130 -1
  76. package/lib/cjs/types/error.d.ts +84 -0
  77. package/lib/cjs/types/error.js +110 -3
  78. package/lib/cjs/types/index.d.ts +2 -0
  79. package/lib/cjs/types/index.js +2 -0
  80. package/lib/cjs/types/leverageError.d.ts +1552 -0
  81. package/lib/cjs/types/leverageError.js +1711 -0
  82. package/lib/cjs/types/zeroEx.d.ts +171 -0
  83. package/lib/cjs/types/zeroEx.js +2 -0
  84. package/lib/cjs/version.d.ts +1 -1
  85. package/lib/cjs/version.js +1 -1
  86. package/lib/esm/abis.d.ts +793 -0
  87. package/lib/esm/abis.js +809 -0
  88. package/lib/esm/actions/blue/close.d.ts +169 -0
  89. package/lib/esm/actions/blue/close.js +266 -0
  90. package/lib/esm/actions/blue/common.js +3 -3
  91. package/lib/esm/actions/blue/delever.d.ts +156 -0
  92. package/lib/esm/actions/blue/delever.js +219 -0
  93. package/lib/esm/actions/blue/index.d.ts +3 -0
  94. package/lib/esm/actions/blue/index.js +3 -0
  95. package/lib/esm/actions/blue/lever.d.ts +184 -0
  96. package/lib/esm/actions/blue/lever.js +268 -0
  97. package/lib/esm/actions/blue/leverageIntent.d.ts +65 -0
  98. package/lib/esm/actions/blue/leverageIntent.js +96 -0
  99. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
  100. package/lib/esm/actions/midnight/takeBorrow.js +14 -8
  101. package/lib/esm/actions/midnight/takeLend.js +15 -9
  102. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
  103. package/lib/esm/actions/midnight/takeWithdraw.js +14 -8
  104. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  105. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.js +55 -0
  106. package/lib/esm/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  107. package/lib/esm/actions/requirements/blue/getLeverageRequirements.js +189 -0
  108. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  109. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.js +62 -0
  110. package/lib/esm/actions/requirements/blue/index.d.ts +3 -0
  111. package/lib/esm/actions/requirements/blue/index.js +3 -0
  112. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  113. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  114. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +11 -6
  115. package/lib/esm/actions/requirements/getRequirementsApproval.js +29 -5
  116. package/lib/esm/addresses.d.ts +1 -1
  117. package/lib/esm/addresses.js +1 -1
  118. package/lib/esm/blue/addresses.d.ts +1 -1
  119. package/lib/esm/blue/addresses.js +1 -1
  120. package/lib/esm/constants.d.ts +1 -1
  121. package/lib/esm/constants.js +1 -1
  122. package/lib/esm/entities/blue/blue.d.ts +486 -2
  123. package/lib/esm/entities/blue/blue.js +501 -6
  124. package/lib/esm/entities/index.d.ts +1 -1
  125. package/lib/esm/entities/midnight/midnight.d.ts +6 -0
  126. package/lib/esm/entities/midnight/midnight.js +21 -2
  127. package/lib/esm/entities/requirements/assertContractCode.d.ts +0 -23
  128. package/lib/esm/entities/requirements/assertContractCode.js +1 -25
  129. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +117 -0
  130. package/lib/esm/entities/vaultV2BlueReallocationData.js +227 -3
  131. package/lib/esm/helpers/constant.d.ts +41 -0
  132. package/lib/esm/helpers/constant.js +41 -0
  133. package/lib/esm/helpers/getZeroExLeverageBundle.d.ts +13 -0
  134. package/lib/esm/helpers/getZeroExLeverageBundle.js +23 -0
  135. package/lib/esm/helpers/index.d.ts +4 -1
  136. package/lib/esm/helpers/index.js +4 -1
  137. package/lib/esm/helpers/leverage/index.d.ts +1 -0
  138. package/lib/esm/helpers/leverage/index.js +1 -0
  139. package/lib/esm/helpers/leverage/limits.d.ts +472 -0
  140. package/lib/esm/helpers/leverage/limits.js +705 -0
  141. package/lib/esm/helpers/leverage/positionMarket.d.ts +17 -0
  142. package/lib/esm/helpers/leverage/positionMarket.js +24 -0
  143. package/lib/esm/helpers/leverage/reallocations.d.ts +159 -0
  144. package/lib/esm/helpers/leverage/reallocations.js +271 -0
  145. package/lib/esm/helpers/validate.d.ts +14 -0
  146. package/lib/esm/helpers/validate.js +25 -2
  147. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  148. package/lib/esm/helpers/validateRequirementSpender.js +5 -1
  149. package/lib/esm/helpers/zeroExQuote.d.ts +250 -0
  150. package/lib/esm/helpers/zeroExQuote.js +754 -0
  151. package/lib/esm/index.d.ts +1 -0
  152. package/lib/esm/index.js +1 -0
  153. package/lib/esm/reads/assertContractCode.d.ts +25 -0
  154. package/lib/esm/reads/assertContractCode.js +26 -0
  155. package/lib/esm/reads/fetchZeroExQuote.d.ts +123 -0
  156. package/lib/esm/reads/fetchZeroExQuote.js +326 -0
  157. package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +4 -0
  158. package/lib/esm/transactionPlan/midnight/takeBorrow.js +9 -3
  159. package/lib/esm/types/action.d.ts +130 -1
  160. package/lib/esm/types/error.d.ts +84 -0
  161. package/lib/esm/types/error.js +103 -0
  162. package/lib/esm/types/index.d.ts +2 -0
  163. package/lib/esm/types/index.js +2 -0
  164. package/lib/esm/types/leverageError.d.ts +1552 -0
  165. package/lib/esm/types/leverageError.js +1660 -0
  166. package/lib/esm/types/zeroEx.d.ts +171 -0
  167. package/lib/esm/types/zeroEx.js +1 -0
  168. package/lib/esm/version.d.ts +1 -1
  169. package/lib/esm/version.js +1 -1
  170. package/package.json +7 -7
@@ -0,0 +1,1711 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LeverageReallocationOutsideCapsError = exports.LeverageInsufficientLiquidityError = exports.LeverageReallocationExceedsBorrowError = exports.LeverageReallocationPenaltyAboveLimitError = exports.LeverageReallocationNoFlowError = exports.LeverageReallocationMarketMismatchError = exports.LeverageUnsupportedChainError = exports.LeverageCloseInputExceedsCollateralError = exports.LeverageCloseWithoutDebtError = exports.LeverageCloseEmptyPositionError = exports.LeverageCloseBuyAboveDebtError = exports.LeverageCloseFloorBelowDebtPlusBufferError = exports.LeverageOraclePriceUnavailableError = exports.LeverageOraclePriceDeviationError = exports.LeverageWorstFillLtvError = exports.LeverageQuoteSlippageMismatchError = exports.LeverageSlippageAboveLimitError = exports.ZeroExQuoteRequiredError = exports.ZeroExQuoteMalformedResponseError = exports.ZeroExQuoteNoLiquidityError = exports.ZeroExQuoteRequestError = exports.ZeroExUnknownSwapKindError = exports.ZeroExExactOutputUnsupportedError = exports.ZeroExInvalidTxOriginError = exports.ZeroExQuoteTxOriginMismatchError = exports.ZeroExQuoteDeadlineMismatchError = exports.ZeroExQuoteUnsupportedActionError = exports.ZeroExQuoteShortTimeBoundError = exports.ZeroExQuoteSignedOrderActionError = exports.ZeroExQuoteUndecodableCalldataError = exports.ZeroExQuoteMalformedCalldataError = exports.ZeroExQuoteMinBuyAmountBelowSlippageError = exports.ZeroExQuoteMinAmountOutMismatchError = exports.ZeroExQuoteSellAmountMismatchError = exports.ZeroExQuoteAmountExceedsCapError = exports.ZeroExQuoteRecipientMismatchError = exports.ZeroExSettlerPausedError = exports.ZeroExSettlerOperatorTargetMismatchError = exports.ZeroExSettlerNotOfficialError = exports.ZeroExQuoteTargetMismatchError = exports.ZeroExQuoteNonZeroValueError = exports.ZeroExQuoteTakerMismatchError = exports.ZeroExQuoteTypeMismatchError = exports.ZeroExQuoteTokenMismatchError = exports.ZeroExQuoteChainMismatchError = exports.LeverageReallocationError = exports.LeverageLimitError = exports.ZeroExQuoteError = void 0;
4
+ const CLOSE_NO_SWAP_EXITS = "Or exit without a swap: repay or supplyCollateral to reduce risk, repayWithdrawCollateral to leave the position.";
5
+ /**
6
+ * Base class for leverage refusals caused by an unusable 0x quote or swap calldata.
7
+ * Fallback: fetch a new 0x quote and build again, except for five errors a new quote alone does not clear:
8
+ * {@link ZeroExExactOutputUnsupportedError}, refused before any request for a
9
+ * native and wrapped-native exact-output pair, {@link ZeroExQuoteNoLiquidityError}, which calls for a smaller
10
+ * amount or a no-swap exit, {@link ZeroExQuoteRequestError}, which a retry clears only when no response arrived,
11
+ * a 2xx response's body failed to download, or 0x answered 429 or 5xx, {@link ZeroExUnknownSwapKindError}, refused for an invalid action kind, and
12
+ * {@link ZeroExInvalidTxOriginError}, refused for a malformed `txOrigin`. Handle them before the generic requote
13
+ * branch. The leverage builders never throw {@link ZeroExSettlerPausedError} or {@link ZeroExSettlerNotOfficialError}:
14
+ * the `@morpho-org/evm-simulation` 0x Settler registry check reports the same conditions as non-blocking
15
+ * `ZERO_EX_SETTLER_UNVERIFIED` entries in `report.warnings`, with `reason` `"paused"` or `"notOfficial"`, read from
16
+ * the registry at the simulation block. The simulation still runs, and it returns no instance of these classes: read
17
+ * the warning's `code` and `reason`, not `instanceof`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import {
22
+ * ZeroExExactOutputUnsupportedError,
23
+ * ZeroExInvalidTxOriginError,
24
+ * ZeroExQuoteChainMismatchError,
25
+ * ZeroExQuoteError,
26
+ * ZeroExQuoteNoLiquidityError,
27
+ * ZeroExQuoteRequestError,
28
+ * ZeroExQuoteShortTimeBoundError,
29
+ * ZeroExUnknownSwapKindError,
30
+ * } from "@morpho-org/morpho-sdk";
31
+ *
32
+ * const controller = new AbortController(); // the caller aborts it to cancel the quote request
33
+ *
34
+ * function build(): never {
35
+ * throw new ZeroExQuoteChainMismatchError({ expected: 1, actual: 8453 });
36
+ * }
37
+ *
38
+ * try {
39
+ * build();
40
+ * } catch (error) {
41
+ * if (controller.signal.aborted) {
42
+ * // The caller cancelled the request (a fetch then fails with status null): do not retry.
43
+ * } else if (error instanceof ZeroExExactOutputUnsupportedError) {
44
+ * // 0x cannot buy an exact amount across a native and wrapped-native pair: offer an exit that needs no swap.
45
+ * } else if (error instanceof ZeroExQuoteNoLiquidityError) {
46
+ * // 0x has no route for this size: offer a smaller amount or an exit that needs no swap.
47
+ * } else if (
48
+ * error instanceof ZeroExQuoteRequestError &&
49
+ * error.status !== null &&
50
+ * error.status !== 429 &&
51
+ * error.status < 500
52
+ * ) {
53
+ * // 0x refused the request itself: fix the API key or the request; requoting hits the same refusal.
54
+ * } else if (error instanceof ZeroExUnknownSwapKindError) {
55
+ * // Fix the action kind; requoting hits the same refusal.
56
+ * } else if (error instanceof ZeroExInvalidTxOriginError) {
57
+ * // Pass a valid txOrigin, or omit it; requoting hits the same refusal.
58
+ * } else if (error instanceof ZeroExQuoteShortTimeBoundError) {
59
+ * // Fetch a new 0x quote; if the same word is refused again, offer a different amount, retry later or an exit
60
+ * // that needs no swap.
61
+ * } else if (error instanceof ZeroExQuoteError) {
62
+ * // Fetch a new 0x quote and build again.
63
+ * } else {
64
+ * throw error;
65
+ * }
66
+ * }
67
+ * ```
68
+ */
69
+ class ZeroExQuoteError extends Error {
70
+ }
71
+ exports.ZeroExQuoteError = ZeroExQuoteError;
72
+ /**
73
+ * Base class for leverage refusals where the action is unsafe at current prices or outside an SDK bound.
74
+ * Fallback: offer a no-swap exit (`repay` or `supplyCollateral`), a smaller action or a new quote. Five
75
+ * subclasses are exceptions: for {@link LeverageSlippageAboveLimitError}, the limit depends on neither the size
76
+ * nor the quote, so lower the slippage to `error.max` or less and build again, fetching a new quote with that
77
+ * slippage. For {@link LeverageCloseEmptyPositionError}, the position holds nothing, so there is no transaction to
78
+ * offer: tell the user there is nothing to close. For {@link LeverageCloseWithoutDebtError}, the position has
79
+ * collateral but no debt: offer `withdrawCollateral` instead. For {@link LeverageUnsupportedChainError},
80
+ * leverage is not available on the chain: offer only the no-swap actions, if Blue is available on the chain. For
81
+ * {@link LeverageOraclePriceUnavailableError}, the market has no usable oracle price, so a smaller action or a new
82
+ * quote fails the same way: on a Lever, read the leverage data again once the oracle answers; on a Delever or a
83
+ * Close, offer only the no-swap exits.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * import {
88
+ * InsufficientSharedLiquidityError,
89
+ * LeverageCloseEmptyPositionError,
90
+ * LeverageCloseWithoutDebtError,
91
+ * LeverageLimitError,
92
+ * LeverageOraclePriceUnavailableError,
93
+ * LeverageSlippageAboveLimitError,
94
+ * LeverageUnsupportedChainError,
95
+ * } from "@morpho-org/morpho-sdk";
96
+ *
97
+ * function build(): never {
98
+ * throw new LeverageSlippageAboveLimitError({
99
+ * operation: "lever",
100
+ * slippage: 20_000_000_000_000_000n,
101
+ * max: 10_000_000_000_000_000n,
102
+ * });
103
+ * }
104
+ *
105
+ * try {
106
+ * build();
107
+ * } catch (error) {
108
+ * if (error instanceof LeverageSlippageAboveLimitError) {
109
+ * // Lower the slippage to error.max or less and build again; fetch a new quote only if the action swaps.
110
+ * } else if (error instanceof LeverageCloseEmptyPositionError) {
111
+ * // Nothing to close: tell the user instead of offering another transaction.
112
+ * } else if (error instanceof LeverageCloseWithoutDebtError) {
113
+ * // Collateral but no debt: offer withdrawCollateral instead of a Close.
114
+ * } else if (error instanceof LeverageUnsupportedChainError) {
115
+ * // No leverage on this chain: if Blue is available here, offer repay, supplyCollateral or withdrawCollateral.
116
+ * } else if (error instanceof LeverageOraclePriceUnavailableError) {
117
+ * // No oracle price: on a Lever, read the leverage data again once the oracle answers; on a Delever or a
118
+ * // Close, offer only repay, supplyCollateral or repayWithdrawCollateral.
119
+ * } else if (error instanceof LeverageLimitError) {
120
+ * // Offer a smaller action, a no-swap exit or a new quote.
121
+ * } else if (error instanceof InsufficientSharedLiquidityError) {
122
+ * // Outside this base: a Lever's planned reallocations cannot fund the borrow, the shortfall the pure
123
+ * // builder reports as LeverageInsufficientLiquidityError. Offer a smaller Lever or other reallocations.
124
+ * } else {
125
+ * throw error;
126
+ * }
127
+ * }
128
+ * ```
129
+ */
130
+ class LeverageLimitError extends Error {
131
+ }
132
+ exports.LeverageLimitError = LeverageLimitError;
133
+ /**
134
+ * Base class for leverage refusals caused by an unsafe public-allocator liquidity route.
135
+ * Fallback: drop or replace the reallocations and build again.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * import {
140
+ * InconsistentReallocationPenaltyError,
141
+ * LeverageReallocationError,
142
+ * LeverageReallocationExceedsBorrowError,
143
+ * ReallocationLoanTokenMismatchError,
144
+ * ReallocationWithdrawalOnTargetMarketError,
145
+ * } from "@morpho-org/morpho-sdk";
146
+ *
147
+ * function build(): never {
148
+ * throw new LeverageReallocationExceedsBorrowError({
149
+ * total: 101n,
150
+ * maxBorrowAssets: 100n,
151
+ * });
152
+ * }
153
+ *
154
+ * try {
155
+ * build();
156
+ * } catch (error) {
157
+ * // Three existing classes outside this base also call for other reallocations: a penalty that differs
158
+ * // from the vault's configured one, a source market with another loan token, and a source that is
159
+ * // the Lever's own market.
160
+ * if (
161
+ * !(error instanceof LeverageReallocationError) &&
162
+ * !(error instanceof InconsistentReallocationPenaltyError) &&
163
+ * !(error instanceof ReallocationLoanTokenMismatchError) &&
164
+ * !(error instanceof ReallocationWithdrawalOnTargetMarketError)
165
+ * ) {
166
+ * throw error;
167
+ * }
168
+ * // Build again with other reallocations or none.
169
+ * }
170
+ * ```
171
+ */
172
+ class LeverageReallocationError extends Error {
173
+ }
174
+ exports.LeverageReallocationError = LeverageReallocationError;
175
+ /**
176
+ * Thrown when a 0x quote was built for another chain than the leverage action's market.
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * import { ZeroExQuoteChainMismatchError } from "@morpho-org/morpho-sdk";
181
+ *
182
+ * const error = new ZeroExQuoteChainMismatchError({ expected: 1, actual: 8453 });
183
+ * ```
184
+ */
185
+ class ZeroExQuoteChainMismatchError extends ZeroExQuoteError {
186
+ /**
187
+ * @param params - Chain comparison.
188
+ * @param params.expected - Chain id of the action's market.
189
+ * @param params.actual - Chain id of the quote.
190
+ */
191
+ constructor(params) {
192
+ super(`0x quote is for chain "${params.actual}", but the action runs on chain "${params.expected}". Fetch a new quote for chain "${params.expected}".`);
193
+ this.expected = params.expected;
194
+ this.actual = params.actual;
195
+ this.name = "ZeroExQuoteChainMismatchError";
196
+ }
197
+ /** Chain id of the action's market. */
198
+ expected;
199
+ /** Chain id of the quote. */
200
+ actual;
201
+ }
202
+ exports.ZeroExQuoteChainMismatchError = ZeroExQuoteChainMismatchError;
203
+ /**
204
+ * Thrown when a 0x quote sells or buys another token than the leverage action swaps, in its `sellToken` or `buyToken`
205
+ * field or in its calldata: the AllowanceHolder sell token or Settler's buy token.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * import { ZeroExQuoteTokenMismatchError } from "@morpho-org/morpho-sdk";
210
+ *
211
+ * const error = new ZeroExQuoteTokenMismatchError({
212
+ * field: "sellToken",
213
+ * expected: weth,
214
+ * actual: quotedSellToken,
215
+ * });
216
+ * ```
217
+ */
218
+ class ZeroExQuoteTokenMismatchError extends ZeroExQuoteError {
219
+ /**
220
+ * @param params - Token comparison.
221
+ * @param params.field - Swap side that differs: the input (`sellToken`) or output (`buyToken`), in the quote's fields or
222
+ * its calldata.
223
+ * @param params.expected - Token the action swaps on that side.
224
+ * @param params.actual - Token the quote's fields or calldata use on that side.
225
+ */
226
+ constructor(params) {
227
+ super(`0x quote ${params.field === "sellToken" ? "sells" : "buys"} "${params.actual}" in its ${params.field} field or its calldata, expected "${params.expected}". Fetch a new quote for the action's tokens.`);
228
+ this.field = params.field;
229
+ this.expected = params.expected;
230
+ this.actual = params.actual;
231
+ this.name = "ZeroExQuoteTokenMismatchError";
232
+ }
233
+ /** Swap side that differs, in the quote's fields or its calldata. */
234
+ field;
235
+ /** Token the action swaps on that side. */
236
+ expected;
237
+ /** Token the quote's fields or calldata use on that side. */
238
+ actual;
239
+ }
240
+ exports.ZeroExQuoteTokenMismatchError = ZeroExQuoteTokenMismatchError;
241
+ /**
242
+ * Thrown when a 0x quote fixes the wrong side of the swap for the leverage action:
243
+ * Lever and Close need an exact-output (`buyAmount`) quote, Delever an exact-input
244
+ * (`sellAmount`) quote.
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * import { ZeroExQuoteTypeMismatchError } from "@morpho-org/morpho-sdk";
249
+ *
250
+ * const error = new ZeroExQuoteTypeMismatchError({
251
+ * expected: "exactOutput",
252
+ * actual: "exactInput",
253
+ * });
254
+ * ```
255
+ */
256
+ class ZeroExQuoteTypeMismatchError extends ZeroExQuoteError {
257
+ /**
258
+ * @param params - Quote type comparison.
259
+ * @param params.expected - Quote type the action requires.
260
+ * @param params.actual - Quote type supplied.
261
+ */
262
+ constructor(params) {
263
+ super(`0x quote is "${params.actual}", but the action requires "${params.expected}". Fetch a new 0x quote of that type for this action.`);
264
+ this.expected = params.expected;
265
+ this.actual = params.actual;
266
+ this.name = "ZeroExQuoteTypeMismatchError";
267
+ }
268
+ /** Quote type the action requires. */
269
+ expected;
270
+ /** Quote type supplied. */
271
+ actual;
272
+ }
273
+ exports.ZeroExQuoteTypeMismatchError = ZeroExQuoteTypeMismatchError;
274
+ /**
275
+ * Thrown when a 0x quote's taker is not the leverage bundle that executes the swap.
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * import { ZeroExQuoteTakerMismatchError } from "@morpho-org/morpho-sdk";
280
+ *
281
+ * const error = new ZeroExQuoteTakerMismatchError({
282
+ * expected: zeroExLeverageBundle,
283
+ * actual: quotedTaker,
284
+ * });
285
+ * ```
286
+ */
287
+ class ZeroExQuoteTakerMismatchError extends ZeroExQuoteError {
288
+ /**
289
+ * @param params - Taker comparison.
290
+ * @param params.expected - Leverage bundle address.
291
+ * @param params.actual - Taker the quote was built for.
292
+ */
293
+ constructor(params) {
294
+ super(`0x quote taker is "${params.actual}", expected the leverage bundle "${params.expected}". Fetch a new quote with the bundle as taker.`);
295
+ this.expected = params.expected;
296
+ this.actual = params.actual;
297
+ this.name = "ZeroExQuoteTakerMismatchError";
298
+ }
299
+ /** Leverage bundle address. */
300
+ expected;
301
+ /** Taker the quote was built for. */
302
+ actual;
303
+ }
304
+ exports.ZeroExQuoteTakerMismatchError = ZeroExQuoteTakerMismatchError;
305
+ /**
306
+ * Thrown when a 0x quote's transaction carries native value; leverage swaps are ERC-20 only.
307
+ *
308
+ * @example
309
+ * ```ts
310
+ * import { ZeroExQuoteNonZeroValueError } from "@morpho-org/morpho-sdk";
311
+ *
312
+ * const error = new ZeroExQuoteNonZeroValueError(1n);
313
+ * ```
314
+ */
315
+ class ZeroExQuoteNonZeroValueError extends ZeroExQuoteError {
316
+ value;
317
+ /**
318
+ * @param value - Native value carried by the quote's transaction.
319
+ */
320
+ constructor(value) {
321
+ super(`0x quote transaction carries value "${value}", expected "0". Fetch a new ERC-20 quote without native value.`);
322
+ this.value = value;
323
+ this.name = "ZeroExQuoteNonZeroValueError";
324
+ }
325
+ }
326
+ exports.ZeroExQuoteNonZeroValueError = ZeroExQuoteNonZeroValueError;
327
+ /**
328
+ * Thrown when a 0x quote's transaction does not call the chain's AllowanceHolder.
329
+ *
330
+ * @example
331
+ * ```ts
332
+ * import { ZeroExQuoteTargetMismatchError } from "@morpho-org/morpho-sdk";
333
+ * import { ZERO_EX_ALLOWANCE_HOLDER_ADDRESS } from "@morpho-org/morpho-sdk/addresses";
334
+ *
335
+ * const error = new ZeroExQuoteTargetMismatchError({
336
+ * expected: ZERO_EX_ALLOWANCE_HOLDER_ADDRESS,
337
+ * actual: quotedTarget,
338
+ * });
339
+ * ```
340
+ */
341
+ class ZeroExQuoteTargetMismatchError extends ZeroExQuoteError {
342
+ /**
343
+ * @param params - Transaction target comparison.
344
+ * @param params.expected - AllowanceHolder address.
345
+ * @param params.actual - Address the quote's transaction calls.
346
+ */
347
+ constructor(params) {
348
+ super(`0x quote transaction calls "${params.actual}", expected AllowanceHolder "${params.expected}". Fetch a new allowance-holder quote.`);
349
+ this.expected = params.expected;
350
+ this.actual = params.actual;
351
+ this.name = "ZeroExQuoteTargetMismatchError";
352
+ }
353
+ /** AllowanceHolder address. */
354
+ expected;
355
+ /** Address the quote's transaction calls. */
356
+ actual;
357
+ }
358
+ exports.ZeroExQuoteTargetMismatchError = ZeroExQuoteTargetMismatchError;
359
+ /**
360
+ * Raised when the AllowanceHolder call's operator is not a Settler the 0x registry names for the taker
361
+ * feature (current, or previous during rotation). The leverage builders never throw it: the
362
+ * `@morpho-org/evm-simulation` 0x Settler registry check reports the same condition as a non-blocking
363
+ * `ZERO_EX_SETTLER_UNVERIFIED` entry in `report.warnings` with `reason: "notOfficial"`, from the registry state at
364
+ * the simulation block, not as an instance of this class; the simulation still runs. A new quote clears it once the registry names an eligible
365
+ * Settler; reading the leverage data again does not, because the leverage data holds no registry state.
366
+ *
367
+ * @example
368
+ * ```ts
369
+ * import { ZeroExSettlerNotOfficialError } from "@morpho-org/morpho-sdk";
370
+ *
371
+ * const error = new ZeroExSettlerNotOfficialError({
372
+ * field: "operator",
373
+ * actual: quotedOperator,
374
+ * official: [currentSettler],
375
+ * });
376
+ * ```
377
+ */
378
+ class ZeroExSettlerNotOfficialError extends ZeroExQuoteError {
379
+ /**
380
+ * @param params - Settler comparison.
381
+ * @param params.field - AllowanceHolder `exec` argument that differs.
382
+ * @param params.actual - Address found in the calldata.
383
+ * @param params.official - Settlers the registry accepts at the block it was read.
384
+ */
385
+ constructor(params) {
386
+ super(params.official.length === 0
387
+ ? `0x swap ${params.field} "${params.actual}" is not an official Settler, and the registry names no eligible Settler. Fetch a new quote only once the 0x registry names an eligible Settler.`
388
+ : `0x swap ${params.field} "${params.actual}" is not an official Settler, expected one of "${params.official.join('", "')}". Fetch a new quote.`);
389
+ this.field = params.field;
390
+ this.actual = params.actual;
391
+ this.official = params.official;
392
+ this.name = "ZeroExSettlerNotOfficialError";
393
+ }
394
+ /** AllowanceHolder `exec` argument that differs. */
395
+ field;
396
+ /** Address found in the calldata. */
397
+ actual;
398
+ /** Settlers the registry accepts at the block it was read. */
399
+ official;
400
+ }
401
+ exports.ZeroExSettlerNotOfficialError = ZeroExSettlerNotOfficialError;
402
+ /**
403
+ * Thrown when the AllowanceHolder call's target is not its operator: an address mismatch only. Neither
404
+ * address is checked against the 0x Settler registry here, so this refusal says nothing about whether the
405
+ * operator is an official Settler. Fetch a new quote.
406
+ *
407
+ * @example
408
+ * ```ts
409
+ * import { ZeroExSettlerOperatorTargetMismatchError } from "@morpho-org/morpho-sdk";
410
+ *
411
+ * const error = new ZeroExSettlerOperatorTargetMismatchError({
412
+ * operator: currentSettler,
413
+ * target: previousSettler,
414
+ * });
415
+ * ```
416
+ */
417
+ class ZeroExSettlerOperatorTargetMismatchError extends ZeroExQuoteError {
418
+ /**
419
+ * @param params - AllowanceHolder `exec` arguments.
420
+ * @param params.operator - Settler AllowanceHolder approves for the swap.
421
+ * @param params.target - Contract AllowanceHolder calls.
422
+ */
423
+ constructor(params) {
424
+ super(`0x swap target "${params.target}" is not its operator "${params.operator}": AllowanceHolder must call the Settler it approves. Fetch a new quote.`);
425
+ this.operator = params.operator;
426
+ this.target = params.target;
427
+ this.name = "ZeroExSettlerOperatorTargetMismatchError";
428
+ }
429
+ /** Settler AllowanceHolder approves for the swap. */
430
+ operator;
431
+ /** Contract AllowanceHolder calls. */
432
+ target;
433
+ }
434
+ exports.ZeroExSettlerOperatorTargetMismatchError = ZeroExSettlerOperatorTargetMismatchError;
435
+ /**
436
+ * Raised when the 0x registry lookup for the taker Settler reverts, which means 0x paused it. The leverage
437
+ * builders never throw it: the `@morpho-org/evm-simulation` 0x Settler registry check reports the same condition as
438
+ * a non-blocking `ZERO_EX_SETTLER_UNVERIFIED` entry in `report.warnings` with `reason: "paused"`, from the registry
439
+ * state at the simulation block, not as an instance of this class; the simulation still runs. Unlike the other
440
+ * {@link ZeroExQuoteError} subclasses, a new quote cannot clear it. Offer the no-swap exits instead (`repay`,
441
+ * `supplyCollateral`, `repayWithdrawCollateral`), or retry the swap once the registry shows 0x resumed it.
442
+ *
443
+ * @example
444
+ * ```ts
445
+ * import { ZeroExSettlerPausedError } from "@morpho-org/morpho-sdk";
446
+ * import { ZERO_EX_SETTLER_REGISTRY_ADDRESS } from "@morpho-org/morpho-sdk/addresses";
447
+ *
448
+ * const error = new ZeroExSettlerPausedError({
449
+ * registry: ZERO_EX_SETTLER_REGISTRY_ADDRESS,
450
+ * });
451
+ * ```
452
+ */
453
+ class ZeroExSettlerPausedError extends ZeroExQuoteError {
454
+ /**
455
+ * @param params - Registry details.
456
+ * @param params.registry - 0x Settler registry address whose lookup reverted.
457
+ * @param options - Standard error options; `cause` carries the revert.
458
+ */
459
+ constructor(params, options) {
460
+ super(`0x Settler registry "${params.registry}" reverted for the taker Settler, so 0x has paused swaps and no new quote can clear it. Exit without a swap with repay, supplyCollateral or repayWithdrawCollateral, or retry once the 0x registry shows swaps resumed.`, options);
461
+ this.registry = params.registry;
462
+ this.name = "ZeroExSettlerPausedError";
463
+ }
464
+ /** 0x Settler registry address whose lookup reverted. */
465
+ registry;
466
+ }
467
+ exports.ZeroExSettlerPausedError = ZeroExSettlerPausedError;
468
+ /**
469
+ * Thrown when the 0x swap pays its output to anyone but the leverage bundle.
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * import { ZeroExQuoteRecipientMismatchError } from "@morpho-org/morpho-sdk";
474
+ *
475
+ * const error = new ZeroExQuoteRecipientMismatchError({
476
+ * expected: zeroExLeverageBundle,
477
+ * actual: quotedRecipient,
478
+ * });
479
+ * ```
480
+ */
481
+ class ZeroExQuoteRecipientMismatchError extends ZeroExQuoteError {
482
+ /**
483
+ * @param params - Recipient comparison.
484
+ * @param params.expected - Leverage bundle address.
485
+ * @param params.actual - Recipient found in the swap calldata. A zero recipient means the Settler slippage is only
486
+ * partly zero (a nonzero buy token or minimum output), since only an all-zero slippage skips the recipient check;
487
+ * the message says so.
488
+ */
489
+ constructor(params) {
490
+ super(/^0x0{40}$/i.test(params.actual)
491
+ ? `0x swap's Settler slippage has a zero recipient but a nonzero buy token or minimum output, so it pays "${params.actual}", expected the leverage bundle "${params.expected}". Fetch a new quote that pays the leverage bundle.`
492
+ : `0x swap pays "${params.actual}", expected the leverage bundle "${params.expected}". Fetch a new quote that pays the leverage bundle.`);
493
+ this.expected = params.expected;
494
+ this.actual = params.actual;
495
+ this.name = "ZeroExQuoteRecipientMismatchError";
496
+ }
497
+ /** Leverage bundle address. */
498
+ expected;
499
+ /** Recipient found in the swap calldata. */
500
+ actual;
501
+ }
502
+ exports.ZeroExQuoteRecipientMismatchError = ZeroExQuoteRecipientMismatchError;
503
+ /**
504
+ * Thrown when the amount the AllowanceHolder call may pull exceeds the action's swap input cap.
505
+ *
506
+ * @example
507
+ * ```ts
508
+ * import { ZeroExQuoteAmountExceedsCapError } from "@morpho-org/morpho-sdk";
509
+ *
510
+ * const error = new ZeroExQuoteAmountExceedsCapError({ amount: 101n, cap: 100n });
511
+ * ```
512
+ */
513
+ class ZeroExQuoteAmountExceedsCapError extends ZeroExQuoteError {
514
+ /**
515
+ * @param params - Amount comparison.
516
+ * @param params.amount - Amount in the AllowanceHolder `exec` call.
517
+ * @param params.cap - Largest swap input the action signs.
518
+ */
519
+ constructor(params) {
520
+ super(`0x swap amount "${params.amount}" exceeds the action's swap input cap "${params.cap}". Fetch a new quote for the action's amounts.`);
521
+ this.amount = params.amount;
522
+ this.cap = params.cap;
523
+ this.name = "ZeroExQuoteAmountExceedsCapError";
524
+ }
525
+ /** Amount in the AllowanceHolder `exec` call. */
526
+ amount;
527
+ /** Largest swap input the action signs. */
528
+ cap;
529
+ }
530
+ exports.ZeroExQuoteAmountExceedsCapError = ZeroExQuoteAmountExceedsCapError;
531
+ /**
532
+ * Thrown when the amount the AllowanceHolder call pulls is not the amount the quote sells: `sellAmount` for an
533
+ * exact-input quote, `maxSellAmount` for an exact-output quote. The calldata does not match the quote's amounts.
534
+ *
535
+ * @example
536
+ * ```ts
537
+ * import { ZeroExQuoteSellAmountMismatchError } from "@morpho-org/morpho-sdk";
538
+ *
539
+ * const error = new ZeroExQuoteSellAmountMismatchError({ expected: 100n, actual: 99n });
540
+ * ```
541
+ */
542
+ class ZeroExQuoteSellAmountMismatchError extends ZeroExQuoteError {
543
+ /**
544
+ * @param params - Amount comparison.
545
+ * @param params.expected - Sell amount the quote reports.
546
+ * @param params.actual - Amount in the AllowanceHolder `exec` call.
547
+ */
548
+ constructor(params) {
549
+ super(`0x swap pulls "${params.actual}" of the sell token, expected the quote's sell amount "${params.expected}". Fetch a new quote.`);
550
+ this.expected = params.expected;
551
+ this.actual = params.actual;
552
+ this.name = "ZeroExQuoteSellAmountMismatchError";
553
+ }
554
+ /** Sell amount the quote reports. */
555
+ expected;
556
+ /** Amount in the AllowanceHolder `exec` call. */
557
+ actual;
558
+ }
559
+ exports.ZeroExQuoteSellAmountMismatchError = ZeroExQuoteSellAmountMismatchError;
560
+ /**
561
+ * Thrown when the Settler `execute` slippage asks for a minimum output that is zero or below the quote's own floor:
562
+ * `minBuyAmount` for an exact-input quote, `buyAmount` for an exact-output quote. An all-zero slippage struct is not
563
+ * this error: Settler then checks nothing and the bundle's onchain output check protects the swap.
564
+ *
565
+ * @example
566
+ * ```ts
567
+ * import { ZeroExQuoteMinAmountOutMismatchError } from "@morpho-org/morpho-sdk";
568
+ *
569
+ * const error = new ZeroExQuoteMinAmountOutMismatchError({ expected: 100n, actual: 0n });
570
+ * ```
571
+ */
572
+ class ZeroExQuoteMinAmountOutMismatchError extends ZeroExQuoteError {
573
+ /**
574
+ * @param params - Minimum output comparison.
575
+ * @param params.expected - Smallest minimum output the quote allows.
576
+ * @param params.actual - Minimum output in the Settler `execute` slippage.
577
+ */
578
+ constructor(params) {
579
+ super(params.actual === 0n
580
+ ? "0x swap's Settler minimum output is zero, so Settler checks no output. Fetch a new quote."
581
+ : `0x swap's Settler minimum output "${params.actual}" is below the quote's floor "${params.expected}". Fetch a new quote.`);
582
+ this.expected = params.expected;
583
+ this.actual = params.actual;
584
+ this.name = "ZeroExQuoteMinAmountOutMismatchError";
585
+ }
586
+ /** Smallest minimum output the quote allows. */
587
+ expected;
588
+ /** Minimum output in the Settler `execute` slippage. */
589
+ actual;
590
+ }
591
+ exports.ZeroExQuoteMinAmountOutMismatchError = ZeroExQuoteMinAmountOutMismatchError;
592
+ /**
593
+ * Thrown when a Delever quote's `minBuyAmount` is zero or below `buyAmount × (1 − slippage)`, with the caller's
594
+ * slippage rounded down to whole parts per million as 0x rounds it. The Delever signs the quote's `minBuyAmount`
595
+ * as is, so a lower floor would let the swap lose more than the caller's slippage. 0x builds its floor from the
596
+ * slippage it was sent: fetch a new quote with the caller's slippage.
597
+ *
598
+ * @example
599
+ * ```ts
600
+ * import { ZeroExQuoteMinBuyAmountBelowSlippageError } from "@morpho-org/morpho-sdk";
601
+ *
602
+ * const error = new ZeroExQuoteMinBuyAmountBelowSlippageError({
603
+ * buyAmount: 1_658_936n,
604
+ * minBuyAmount: 1_650_640n,
605
+ * slippage: 5_000_000_000_000_000n,
606
+ * slippageFloor: 1_650_641n,
607
+ * });
608
+ * ```
609
+ */
610
+ class ZeroExQuoteMinBuyAmountBelowSlippageError extends ZeroExQuoteError {
611
+ /**
612
+ * @param params - Floor comparison, in the buy token's smallest unit.
613
+ * @param params.buyAmount - Quote's expected output before slippage.
614
+ * @param params.minBuyAmount - Quote's minimum output.
615
+ * @param params.slippage - Slippage supplied by the caller, WAD-scaled.
616
+ * @param params.slippageFloor - Smallest `minBuyAmount` the caller's slippage accepts: `buyAmount` reduced by
617
+ * the slippage rounded down to whole parts per million, rounded down.
618
+ */
619
+ constructor(params) {
620
+ super(`Delever quote's minBuyAmount "${params.minBuyAmount}" is below "${params.slippageFloor}", its buyAmount "${params.buyAmount}" less the caller's slippage "${params.slippage}" (WAD), or is zero. Fetch a new quote with the caller's slippage.`);
621
+ this.buyAmount = params.buyAmount;
622
+ this.minBuyAmount = params.minBuyAmount;
623
+ this.slippage = params.slippage;
624
+ this.slippageFloor = params.slippageFloor;
625
+ this.name = "ZeroExQuoteMinBuyAmountBelowSlippageError";
626
+ }
627
+ /** Quote's expected output before slippage. */
628
+ buyAmount;
629
+ /** Quote's minimum output. */
630
+ minBuyAmount;
631
+ /** Slippage supplied by the caller, WAD-scaled. */
632
+ slippage;
633
+ /** Smallest `minBuyAmount` the caller's slippage accepts. */
634
+ slippageFloor;
635
+ }
636
+ exports.ZeroExQuoteMinBuyAmountBelowSlippageError = ZeroExQuoteMinBuyAmountBelowSlippageError;
637
+ /**
638
+ * Thrown when 0x quote calldata decodes as a call the leverage bundle cannot run, such as a Settler entry point
639
+ * other than the taker-submitted `execute` (`executeWithPermit` or a metatransaction). It is also thrown for a
640
+ * Settler `SELECT` that does not decode or is nested more than three levels deep, since its candidates would go
641
+ * unchecked, and for a time-bound action (`BASIC`, `BASIC_PUSH`, a permit action, `NATIVE_CHECK` or `ATTEST`) too
642
+ * short or malformed to read. `validateZeroExQuote` throws {@link ZeroExQuoteUndecodableCalldataError} instead for a
643
+ * calldata layer that does not decode at all.
644
+ *
645
+ * @example
646
+ * ```ts
647
+ * import { ZeroExQuoteMalformedCalldataError } from "@morpho-org/morpho-sdk";
648
+ *
649
+ * const error = new ZeroExQuoteMalformedCalldataError({
650
+ * reason: "Settler entry point is executeWithPermit, not execute",
651
+ * });
652
+ * ```
653
+ */
654
+ class ZeroExQuoteMalformedCalldataError extends ZeroExQuoteError {
655
+ /**
656
+ * @param params - Decoding details.
657
+ * @param params.reason - What failed to decode.
658
+ * @param options - Standard error options; `cause` carries the decoding error.
659
+ */
660
+ constructor(params, options) {
661
+ super(`0x quote calldata is malformed: ${params.reason}. Fetch a new allowance-holder quote.`, options);
662
+ this.reason = params.reason;
663
+ this.name = "ZeroExQuoteMalformedCalldataError";
664
+ }
665
+ /** What failed to decode. */
666
+ reason;
667
+ }
668
+ exports.ZeroExQuoteMalformedCalldataError = ZeroExQuoteMalformedCalldataError;
669
+ /**
670
+ * Thrown when a layer of 0x quote calldata does not decode, whichever leverage bundle takes the quote: calldata the SDK
671
+ * cannot read cannot be shown to carry no signed order or short time bound, so every layer must decode.
672
+ * `layer` is `"allowanceHolder"` when the calldata is not an AllowanceHolder `exec` call, `"settler"` when the
673
+ * `exec` data is not a Settler `execute` call.
674
+ *
675
+ * @example
676
+ * ```ts
677
+ * import { ZeroExQuoteUndecodableCalldataError } from "@morpho-org/morpho-sdk";
678
+ *
679
+ * const error = new ZeroExQuoteUndecodableCalldataError({
680
+ * layer: "settler",
681
+ * bundle: "0x000000000000000000000000000000000000bE01",
682
+ * });
683
+ * ```
684
+ */
685
+ class ZeroExQuoteUndecodableCalldataError extends ZeroExQuoteError {
686
+ /**
687
+ * @param params - Decoding details.
688
+ * @param params.layer - Calldata layer that does not decode.
689
+ * @param params.bundle - Leverage bundle taking the quote.
690
+ * @param options - Standard error options.
691
+ */
692
+ constructor(params, options) {
693
+ super(`0x quote ${params.layer === "allowanceHolder" ? "AllowanceHolder" : "Settler"} calldata does not decode, so it cannot be checked for leverage bundle "${params.bundle}". Fetch a new allowance-holder quote.`, options);
694
+ this.layer = params.layer;
695
+ this.bundle = params.bundle;
696
+ this.name = "ZeroExQuoteUndecodableCalldataError";
697
+ }
698
+ /** Calldata layer that does not decode. */
699
+ layer;
700
+ /** Leverage bundle taking the quote. */
701
+ bundle;
702
+ }
703
+ exports.ZeroExQuoteUndecodableCalldataError = ZeroExQuoteUndecodableCalldataError;
704
+ /**
705
+ * Thrown when decoded 0x Settler calldata fills a signed order instead of onchain AMM liquidity: an RFQ order (`RFQ`,
706
+ * `RFQ_VIP`), a Bebop order (`BEBOP`) or any metatransaction action (`METATXN_*`), at the top level of Settler's
707
+ * `execute` or in a candidate of a `SELECT` action at any depth. A signed order carries its maker's own expiry, which
708
+ * can fall before the leverage deadline, so the SDK refuses the quote. `path` names the action: `[1]` is
709
+ * the second top-level action, `[1].candidates[0][2]` the third action of the first candidate of that `SELECT`.
710
+ *
711
+ * @example
712
+ * ```ts
713
+ * import { ZeroExQuoteSignedOrderActionError } from "@morpho-org/morpho-sdk";
714
+ *
715
+ * const error = new ZeroExQuoteSignedOrderActionError({ action: "BEBOP", path: "[1]" });
716
+ * ```
717
+ */
718
+ class ZeroExQuoteSignedOrderActionError extends ZeroExQuoteError {
719
+ /**
720
+ * @param params - Signed-order action details.
721
+ * @param params.action - Settler action that fills the signed order.
722
+ * @param params.path - Position of the action in Settler's `execute` actions and `SELECT` candidates.
723
+ */
724
+ constructor(params) {
725
+ super(`0x quote fills a signed order through Settler action ${params.action} at ${params.path}, whose expiry can fall before the leverage deadline. Fetch a new quote with fetchZeroExQuote, which excludes 0x's short-lived sources.`);
726
+ this.action = params.action;
727
+ this.path = params.path;
728
+ this.name = "ZeroExQuoteSignedOrderActionError";
729
+ }
730
+ /** Settler action that fills the signed order. */
731
+ action;
732
+ /** Position of the action in Settler's `execute` actions and `SELECT` candidates. */
733
+ path;
734
+ }
735
+ exports.ZeroExQuoteSignedOrderActionError = ZeroExQuoteSignedOrderActionError;
736
+ /**
737
+ * Thrown when a decoded 0x Settler `BASIC` or `BASIC_PUSH` action, an opaque call to a venue, holds a 32-byte word
738
+ * that looks like a deadline shorter than the leverage deadline: a value from one hour and one day before `deadline`
739
+ * up to, but not including, `deadline`. The SDK cannot tell whether the word is a deadline. 0x writes router
740
+ * deadlines equal to `deadline`, so such a word may be a venue's own expiry, such as a signed quote, after which the
741
+ * swap would revert; the SDK refuses it as one. An ordinary value that falls in that window, such as an amount, is
742
+ * refused too. A new quote clears it only when it returns different calldata: a word that depends on the route,
743
+ * such as a minimum output, may move, but a fixed value such as the caller's own amount keeps refusing for up to a
744
+ * day, so offer a different amount, a retry later, or a no-swap exit. `word` is the index of the word in the call's
745
+ * data after its selector.
746
+ *
747
+ * @example
748
+ * ```ts
749
+ * import { ZeroExQuoteShortTimeBoundError } from "@morpho-org/morpho-sdk";
750
+ *
751
+ * const error = new ZeroExQuoteShortTimeBoundError({
752
+ * path: "[5]",
753
+ * word: 7,
754
+ * value: 1_700_000_060n,
755
+ * deadline: 1_700_003_600n,
756
+ * });
757
+ * ```
758
+ */
759
+ class ZeroExQuoteShortTimeBoundError extends ZeroExQuoteError {
760
+ /**
761
+ * @param params - Time bound details.
762
+ * @param params.path - Position of the action in Settler's `execute` actions and `SELECT` candidates.
763
+ * @param params.word - Index of the word in the call's data after its selector.
764
+ * @param params.value - Value of the word, in seconds.
765
+ * @param params.deadline - Leverage bundle deadline the action signs, in seconds.
766
+ */
767
+ constructor(params) {
768
+ super(`0x quote's Settler call at ${params.path} holds "${params.value}" in word ${params.word}, which looks like a deadline before the bundle deadline "${params.deadline}". Fetch a new quote with fetchZeroExQuote, which excludes 0x's short-lived sources. If the same word is refused again, offer a different amount, retry later, or exit without a swap.`);
769
+ this.path = params.path;
770
+ this.word = params.word;
771
+ this.value = params.value;
772
+ this.deadline = params.deadline;
773
+ this.name = "ZeroExQuoteShortTimeBoundError";
774
+ }
775
+ /** Position of the action in Settler's `execute` actions and `SELECT` candidates. */
776
+ path;
777
+ /** Index of the word in the call's data after its selector. */
778
+ word;
779
+ /** Value of the word, in seconds. */
780
+ value;
781
+ /** Leverage bundle deadline the action signs, in seconds. */
782
+ deadline;
783
+ }
784
+ exports.ZeroExQuoteShortTimeBoundError = ZeroExQuoteShortTimeBoundError;
785
+ /**
786
+ * Thrown when decoded 0x Settler calldata holds an action leverage does not accept where it stands: a selector that is
787
+ * no AMM, permit, time-check or opaque-call action of the deployed Settlers, a permit action anywhere but the first
788
+ * top-level action (Settler only runs one there), or a `NATIVE_CHECK` or `ATTEST` inside a `SELECT` candidate.
789
+ * Leverage refuses what it cannot classify rather than pass it unchecked.
790
+ *
791
+ * @example
792
+ * ```ts
793
+ * import { ZeroExQuoteUnsupportedActionError } from "@morpho-org/morpho-sdk";
794
+ *
795
+ * const error = new ZeroExQuoteUnsupportedActionError({ selector: "0xdeadbeef", path: "[2]" });
796
+ * ```
797
+ */
798
+ class ZeroExQuoteUnsupportedActionError extends ZeroExQuoteError {
799
+ /**
800
+ * @param params - Action details.
801
+ * @param params.selector - Four-byte selector of the action.
802
+ * @param params.path - Position of the action in Settler's `execute` actions and `SELECT` candidates.
803
+ */
804
+ constructor(params) {
805
+ super(`0x quote's Settler action ${params.selector} at ${params.path} is not one leverage accepts there. Fetch a new quote with fetchZeroExQuote.`);
806
+ this.selector = params.selector;
807
+ this.path = params.path;
808
+ this.name = "ZeroExQuoteUnsupportedActionError";
809
+ }
810
+ /** Four-byte selector of the action. */
811
+ selector;
812
+ /** Position of the action in Settler's `execute` actions and `SELECT` candidates. */
813
+ path;
814
+ }
815
+ exports.ZeroExQuoteUnsupportedActionError = ZeroExQuoteUnsupportedActionError;
816
+ /**
817
+ * Thrown when a decoded Settler time bound does not match the leverage bundle deadline the action signs: the permit
818
+ * of the first top-level action (`TRANSFER_FROM` or a `*_VIP` action) must equal it, and a top-level `NATIVE_CHECK`
819
+ * or `ATTEST` deadline must be at least it. Settler reverts once either has passed, so the quote must be fetched with
820
+ * `deadline` set to the bundle deadline; 0x otherwise sets the permit deadline to its quote block's timestamp plus
821
+ * 300 seconds.
822
+ *
823
+ * @example
824
+ * ```ts
825
+ * import { ZeroExQuoteDeadlineMismatchError } from "@morpho-org/morpho-sdk";
826
+ *
827
+ * const error = new ZeroExQuoteDeadlineMismatchError({
828
+ * expected: 1_700_003_600n,
829
+ * actual: 1_700_000_300n,
830
+ * action: "UNISWAPV3_VIP",
831
+ * });
832
+ * ```
833
+ */
834
+ class ZeroExQuoteDeadlineMismatchError extends ZeroExQuoteError {
835
+ /**
836
+ * @param params - Deadline comparison.
837
+ * @param params.expected - Leverage bundle deadline the action signs, in seconds.
838
+ * @param params.actual - Deadline in the Settler action, in seconds.
839
+ * @param params.action - Settler action that carries the deadline.
840
+ */
841
+ constructor(params) {
842
+ super(`0x quote's Settler ${params.action} deadline is "${params.actual}", which does not match the bundle deadline "${params.expected}". Fetch a new quote with fetchZeroExQuote and deadline set to the bundle deadline.`);
843
+ this.expected = params.expected;
844
+ this.actual = params.actual;
845
+ this.action = params.action;
846
+ this.name = "ZeroExQuoteDeadlineMismatchError";
847
+ }
848
+ /** Leverage bundle deadline the action signs, in seconds. */
849
+ expected;
850
+ /** Deadline in the Settler action, in seconds. */
851
+ actual;
852
+ /** Settler action that carries the deadline. */
853
+ action;
854
+ }
855
+ exports.ZeroExQuoteDeadlineMismatchError = ZeroExQuoteDeadlineMismatchError;
856
+ /**
857
+ * Thrown when the 0x quote was requested for another transaction origin than the action expects: the
858
+ * `txOrigin` the action is built with, or the user when none is given.
859
+ *
860
+ * @example
861
+ * ```ts
862
+ * import { ZeroExQuoteTxOriginMismatchError } from "@morpho-org/morpho-sdk";
863
+ *
864
+ * const error = new ZeroExQuoteTxOriginMismatchError({
865
+ * expected: userAddress,
866
+ * actual: quotedTxOrigin,
867
+ * });
868
+ * ```
869
+ */
870
+ class ZeroExQuoteTxOriginMismatchError extends ZeroExQuoteError {
871
+ /**
872
+ * @param params - txOrigin comparison.
873
+ * @param params.expected - Expected transaction origin: the action's `txOrigin`, or the user by default.
874
+ * @param params.actual - txOrigin the quote was requested for.
875
+ */
876
+ constructor(params) {
877
+ super(`0x quote txOrigin "${params.actual}" is not the expected transaction origin "${params.expected}". Fetch a new quote with the same txOrigin the action is built with (the user by default).`);
878
+ this.expected = params.expected;
879
+ this.actual = params.actual;
880
+ this.name = "ZeroExQuoteTxOriginMismatchError";
881
+ }
882
+ /** Expected transaction origin: the action's `txOrigin`, or the user by default. */
883
+ expected;
884
+ /** txOrigin the quote was requested for. */
885
+ actual;
886
+ }
887
+ exports.ZeroExQuoteTxOriginMismatchError = ZeroExQuoteTxOriginMismatchError;
888
+ /**
889
+ * Thrown when a leverage action's optional `txOrigin` is not a valid address. No new quote clears it: pass a
890
+ * valid address, or omit it to use the user.
891
+ *
892
+ * @example
893
+ * ```ts
894
+ * import { ZeroExInvalidTxOriginError } from "@morpho-org/morpho-sdk";
895
+ *
896
+ * const error = new ZeroExInvalidTxOriginError("0x1234");
897
+ * ```
898
+ */
899
+ class ZeroExInvalidTxOriginError extends ZeroExQuoteError {
900
+ /**
901
+ * @param txOrigin - Value passed as `txOrigin`.
902
+ */
903
+ constructor(txOrigin) {
904
+ super(`txOrigin ${typeof txOrigin === "string" ? `"${txOrigin}"` : `of type ${typeof txOrigin}`} is not a valid address. Pass the sender of the outer onchain transaction (a Safe's executing owner or an ERC-4337 bundler), or omit it to use the user.`);
905
+ this.txOrigin = txOrigin;
906
+ this.name = "ZeroExInvalidTxOriginError";
907
+ }
908
+ /** Value passed as `txOrigin`. */
909
+ txOrigin;
910
+ }
911
+ exports.ZeroExInvalidTxOriginError = ZeroExInvalidTxOriginError;
912
+ /**
913
+ * Thrown when an exact-output quote is requested for a native and wrapped-native pair, which 0x does not support.
914
+ *
915
+ * @example
916
+ * ```ts
917
+ * import { ZeroExExactOutputUnsupportedError } from "@morpho-org/morpho-sdk";
918
+ * import { NATIVE_ADDRESS } from "@morpho-org/morpho-sdk/addresses";
919
+ *
920
+ * const error = new ZeroExExactOutputUnsupportedError({
921
+ * sellToken: NATIVE_ADDRESS,
922
+ * buyToken: weth,
923
+ * });
924
+ * ```
925
+ */
926
+ class ZeroExExactOutputUnsupportedError extends ZeroExQuoteError {
927
+ /**
928
+ * @param params - Pair details.
929
+ * @param params.sellToken - Token the swap sells.
930
+ * @param params.buyToken - Token the swap buys.
931
+ */
932
+ constructor(params) {
933
+ super(`0x does not support exact-output quotes between "${params.sellToken}" and "${params.buyToken}", a native and wrapped-native pair. Use a market whose tokens are not a native and wrapped-native pair. ${CLOSE_NO_SWAP_EXITS}`);
934
+ this.sellToken = params.sellToken;
935
+ this.buyToken = params.buyToken;
936
+ this.name = "ZeroExExactOutputUnsupportedError";
937
+ }
938
+ /** Token the swap sells. */
939
+ sellToken;
940
+ /** Token the swap buys. */
941
+ buyToken;
942
+ }
943
+ exports.ZeroExExactOutputUnsupportedError = ZeroExExactOutputUnsupportedError;
944
+ /**
945
+ * Thrown when a 0x swap is requested for a value that is not a leverage swap kind, before any request or
946
+ * validation runs.
947
+ *
948
+ * @example
949
+ * ```ts
950
+ * import { ZeroExUnknownSwapKindError } from "@morpho-org/morpho-sdk";
951
+ *
952
+ * const error = new ZeroExUnknownSwapKindError({ kind: "leverage" });
953
+ * ```
954
+ */
955
+ class ZeroExUnknownSwapKindError extends ZeroExQuoteError {
956
+ /**
957
+ * @param params - Swap kind details.
958
+ * @param params.kind - Value supplied as the swap kind.
959
+ */
960
+ constructor(params) {
961
+ super(`Swap kind ${typeof params.kind === "string" ? `"${params.kind}"` : `of type ${typeof params.kind}`} is not a leverage swap kind. Use "lever", "delever" or "closeKeepCollateral".`);
962
+ this.kind = params.kind;
963
+ this.name = "ZeroExUnknownSwapKindError";
964
+ }
965
+ /** Value supplied as the swap kind. */
966
+ kind;
967
+ }
968
+ exports.ZeroExUnknownSwapKindError = ZeroExUnknownSwapKindError;
969
+ /**
970
+ * Thrown when the 0x quote request fails: a network error or a non-2xx response from the 0x API.
971
+ *
972
+ * @example
973
+ * ```ts
974
+ * import { ZeroExQuoteRequestError } from "@morpho-org/morpho-sdk";
975
+ *
976
+ * const error = new ZeroExQuoteRequestError({ status: 400, code: "INPUT_INVALID" });
977
+ * ```
978
+ */
979
+ class ZeroExQuoteRequestError extends ZeroExQuoteError {
980
+ /**
981
+ * @param params - Request failure.
982
+ * @param params.status - HTTP status, or `null` when no response arrived or a 2xx response's body failed to
983
+ * download. A non-2xx response keeps its status, with `code: null` when its body could not be read.
984
+ * @param params.code - 0x error name from the response body, or `null` when it has none.
985
+ * @param options - Standard error options; `cause` carries the underlying failure.
986
+ */
987
+ constructor(params, options) {
988
+ const retryable = params.status === null || params.status === 429 || params.status >= 500;
989
+ super(`0x quote request failed with status "${params.status ?? "no response or an incomplete response"}" and code "${params.code ?? "none"}". ${retryable ? "Fetch the quote again." : "Check the API key and the request, then fetch the quote again."}`, options);
990
+ this.status = params.status;
991
+ this.code = params.code;
992
+ this.name = "ZeroExQuoteRequestError";
993
+ }
994
+ /** HTTP status, or `null` when no response arrived or a 2xx response's body failed to download. */
995
+ status;
996
+ /** 0x error name from the response body, or `null` when it has none. */
997
+ code;
998
+ }
999
+ exports.ZeroExQuoteRequestError = ZeroExQuoteRequestError;
1000
+ /**
1001
+ * Thrown when 0x reports no liquidity for the requested swap.
1002
+ *
1003
+ * @example
1004
+ * ```ts
1005
+ * import { ZeroExQuoteNoLiquidityError } from "@morpho-org/morpho-sdk";
1006
+ *
1007
+ * const error = new ZeroExQuoteNoLiquidityError({
1008
+ * sellToken: weth,
1009
+ * buyToken: usdc,
1010
+ * });
1011
+ * ```
1012
+ */
1013
+ class ZeroExQuoteNoLiquidityError extends ZeroExQuoteError {
1014
+ /**
1015
+ * @param params - Pair details.
1016
+ * @param params.sellToken - Token the swap sells.
1017
+ * @param params.buyToken - Token the swap buys.
1018
+ */
1019
+ constructor(params) {
1020
+ super(`0x has no liquidity to swap "${params.sellToken}" for "${params.buyToken}". Try a smaller amount or exit without a swap.`);
1021
+ this.sellToken = params.sellToken;
1022
+ this.buyToken = params.buyToken;
1023
+ this.name = "ZeroExQuoteNoLiquidityError";
1024
+ }
1025
+ /** Token the swap sells. */
1026
+ sellToken;
1027
+ /** Token the swap buys. */
1028
+ buyToken;
1029
+ }
1030
+ exports.ZeroExQuoteNoLiquidityError = ZeroExQuoteNoLiquidityError;
1031
+ /**
1032
+ * Thrown when a 0x quote response does not have the documented allowance-holder quote shape, or does not answer the request that was sent.
1033
+ *
1034
+ * @example
1035
+ * ```ts
1036
+ * import { ZeroExQuoteMalformedResponseError } from "@morpho-org/morpho-sdk";
1037
+ *
1038
+ * const error = new ZeroExQuoteMalformedResponseError({ reason: "buyAmount is not an integer string" });
1039
+ * ```
1040
+ */
1041
+ class ZeroExQuoteMalformedResponseError extends ZeroExQuoteError {
1042
+ /**
1043
+ * @param params - Parsing details.
1044
+ * @param params.reason - What is wrong with the response.
1045
+ * @param options - Standard error options; `cause` carries the underlying failure.
1046
+ */
1047
+ constructor(params, options) {
1048
+ super(`0x quote response is malformed: ${params.reason}. Fetch a new allowance-holder quote.`, options);
1049
+ this.reason = params.reason;
1050
+ this.name = "ZeroExQuoteMalformedResponseError";
1051
+ }
1052
+ /** What is wrong with the response. */
1053
+ reason;
1054
+ }
1055
+ exports.ZeroExQuoteMalformedResponseError = ZeroExQuoteMalformedResponseError;
1056
+ /**
1057
+ * Thrown when a leverage action that swaps is built without a 0x quote, such as a Close of a
1058
+ * position that still has debt.
1059
+ *
1060
+ * @example
1061
+ * ```ts
1062
+ * import { ZeroExQuoteRequiredError } from "@morpho-org/morpho-sdk";
1063
+ *
1064
+ * const error = new ZeroExQuoteRequiredError({ operation: "close" });
1065
+ * ```
1066
+ */
1067
+ class ZeroExQuoteRequiredError extends ZeroExQuoteError {
1068
+ /**
1069
+ * @param params - Refused action.
1070
+ * @param params.operation - Leverage action that needs a quote.
1071
+ */
1072
+ constructor(params) {
1073
+ super(`${params.operation} needs a 0x quote ${params.operation === "lever" ? "to buy collateral with the borrowed assets" : "to swap collateral for the debt it repays"}. Fetch a quote with fetchZeroExQuote and build again.${params.operation === "close" ? ` ${CLOSE_NO_SWAP_EXITS}` : ""}`);
1074
+ this.operation = params.operation;
1075
+ this.name = "ZeroExQuoteRequiredError";
1076
+ }
1077
+ /** Leverage action that needs a quote. */
1078
+ operation;
1079
+ }
1080
+ exports.ZeroExQuoteRequiredError = ZeroExQuoteRequiredError;
1081
+ /**
1082
+ * Thrown when the caller's slippage exceeds the SDK's execution-loss limit for the action.
1083
+ *
1084
+ * @example
1085
+ * ```ts
1086
+ * import { LeverageSlippageAboveLimitError } from "@morpho-org/morpho-sdk";
1087
+ *
1088
+ * const error = new LeverageSlippageAboveLimitError({
1089
+ * operation: "lever",
1090
+ * slippage: 20_000_000_000_000_000n,
1091
+ * max: 10_000_000_000_000_000n,
1092
+ * });
1093
+ * ```
1094
+ */
1095
+ class LeverageSlippageAboveLimitError extends LeverageLimitError {
1096
+ /**
1097
+ * @param params - Slippage comparison, WAD-scaled.
1098
+ * @param params.operation - Leverage action refused.
1099
+ * @param params.slippage - Slippage supplied by the caller.
1100
+ * @param params.max - Largest slippage the SDK accepts for the action.
1101
+ */
1102
+ constructor(params) {
1103
+ super(`${params.operation} slippage "${params.slippage}" exceeds the SDK limit "${params.max}" (WAD). Lower the slippage.`);
1104
+ this.operation = params.operation;
1105
+ this.slippage = params.slippage;
1106
+ this.max = params.max;
1107
+ this.name = "LeverageSlippageAboveLimitError";
1108
+ }
1109
+ /** Leverage action refused. */
1110
+ operation;
1111
+ /** Slippage supplied by the caller, WAD-scaled. */
1112
+ slippage;
1113
+ /** Largest slippage the SDK accepts for the action, WAD-scaled. */
1114
+ max;
1115
+ }
1116
+ exports.LeverageSlippageAboveLimitError = LeverageSlippageAboveLimitError;
1117
+ /**
1118
+ * Thrown when the 0x quote was fetched with a slippage other than the one the caller passes. The
1119
+ * quote and the build must use the same slippage, or the transaction would carry a tolerance the
1120
+ * caller did not choose. For an exact-output quote (Lever, Close) the signed swap
1121
+ * cap is the quote's `maxSellAmount`, which carries the quote's own slippage. A Delever quote's
1122
+ * `minBuyAmount` below the caller's slippage throws {@link ZeroExQuoteMinBuyAmountBelowSlippageError} instead.
1123
+ *
1124
+ * @example
1125
+ * ```ts
1126
+ * import { LeverageQuoteSlippageMismatchError } from "@morpho-org/morpho-sdk";
1127
+ *
1128
+ * const error = new LeverageQuoteSlippageMismatchError({
1129
+ * operation: "lever",
1130
+ * slippage: 5_000_000_000_000_000n,
1131
+ * quoteSlippage: 8_000_000_000_000_000n,
1132
+ * });
1133
+ * ```
1134
+ */
1135
+ class LeverageQuoteSlippageMismatchError extends LeverageLimitError {
1136
+ /**
1137
+ * @param params - Slippage comparison, WAD-scaled.
1138
+ * @param params.operation - Leverage action refused.
1139
+ * @param params.slippage - Slippage supplied by the caller.
1140
+ * @param params.quoteSlippage - Slippage the quote was fetched with.
1141
+ */
1142
+ constructor(params) {
1143
+ super(`${params.operation} quote was fetched with slippage "${params.quoteSlippage}", not the caller's "${params.slippage}" (WAD). Fetch the quote with the same slippage.`);
1144
+ this.operation = params.operation;
1145
+ this.slippage = params.slippage;
1146
+ this.quoteSlippage = params.quoteSlippage;
1147
+ this.name = "LeverageQuoteSlippageMismatchError";
1148
+ }
1149
+ /** Leverage action refused. */
1150
+ operation;
1151
+ /** Slippage supplied by the caller, WAD-scaled. */
1152
+ slippage;
1153
+ /** Slippage the quote was fetched with, WAD-scaled. */
1154
+ quoteSlippage;
1155
+ }
1156
+ exports.LeverageQuoteSlippageMismatchError = LeverageQuoteSlippageMismatchError;
1157
+ /**
1158
+ * Thrown when a Lever's or a Delever's position LTV at the worst fill exceeds a bound: the action's signed
1159
+ * `maxLtv` (`check: "maxLtv"`), or the market LLTV at Blue's health check, which the contract
1160
+ * runs before repaying any surplus (`check: "health"`). Close never throws it: it signs no `maxLtv`, and Blue
1161
+ * clears the borrow shares before the repay callback withdraws the collateral, so that withdrawal's health check
1162
+ * always passes.
1163
+ *
1164
+ * @example
1165
+ * ```ts
1166
+ * import { LeverageWorstFillLtvError } from "@morpho-org/morpho-sdk";
1167
+ *
1168
+ * const error = new LeverageWorstFillLtvError({
1169
+ * operation: "lever",
1170
+ * check: "maxLtv",
1171
+ * ltv: 860_000_000_000_000_000n,
1172
+ * maxLtv: 855_000_000_000_000_000n,
1173
+ * });
1174
+ * ```
1175
+ */
1176
+ class LeverageWorstFillLtvError extends LeverageLimitError {
1177
+ /**
1178
+ * @param params - LTV comparison, WAD-scaled.
1179
+ * @param params.operation - Leverage action refused.
1180
+ * @param params.check - Bound exceeded: the signed `maxLtv` or Blue's mid-flow health check.
1181
+ * @param params.ltv - Position LTV at the worst fill.
1182
+ * @param params.maxLtv - Bound for that check.
1183
+ */
1184
+ constructor(params) {
1185
+ const bound = params.check === "maxLtv"
1186
+ ? "signed maxLtv"
1187
+ : "LLTV at Blue's health check";
1188
+ const fallback = {
1189
+ lever: "Lever a smaller amount or add collateral.",
1190
+ delever: "Fetch a better quote, or reduce risk without a swap with repay or supplyCollateral.",
1191
+ }[params.operation];
1192
+ super(`${params.operation} worst-fill LTV "${params.ltv}" exceeds the ${bound} "${params.maxLtv}" (WAD). ${fallback}`);
1193
+ this.operation = params.operation;
1194
+ this.check = params.check;
1195
+ this.ltv = params.ltv;
1196
+ this.maxLtv = params.maxLtv;
1197
+ this.name = "LeverageWorstFillLtvError";
1198
+ }
1199
+ /** Leverage action refused. */
1200
+ operation;
1201
+ /** Bound exceeded: the signed `maxLtv` or Blue's mid-flow health check. */
1202
+ check;
1203
+ /** Position LTV at the worst fill, WAD-scaled. */
1204
+ ltv;
1205
+ /** Bound for that check, WAD-scaled. */
1206
+ maxLtv;
1207
+ }
1208
+ exports.LeverageWorstFillLtvError = LeverageWorstFillLtvError;
1209
+ /**
1210
+ * Thrown when a Lever's worst swap price, the signed `maxSwapIn` per `minCollateralToBuy`, is more than
1211
+ * `LEVERAGE_MAX_ORACLE_DEVIATION` (15%) above the market's oracle price. A price below the oracle favours the user
1212
+ * and is never refused. Both prices are
1213
+ * loan-token units per collateral-token unit scaled by `ORACLE_PRICE_SCALE` (1e36), as Morpho oracles report
1214
+ * them, so token decimals are already accounted for. Only Lever checks it; Delever and Close do not. The worst price
1215
+ * uses `maxSwapIn`, which already includes the caller's slippage, so the room left for a gap between 0x's price and
1216
+ * the oracle is about 15% minus that slippage (5% at the 10% ceiling).
1217
+ *
1218
+ * @example
1219
+ * ```ts
1220
+ * import { LeverageOraclePriceDeviationError } from "@morpho-org/morpho-sdk";
1221
+ *
1222
+ * const error = new LeverageOraclePriceDeviationError({
1223
+ * quotePrice: 3_500n * 10n ** 24n,
1224
+ * oraclePrice: 3_000n * 10n ** 24n,
1225
+ * deviation: 166_666_666_666_666_667n,
1226
+ * max: 150_000_000_000_000_000n,
1227
+ * });
1228
+ * ```
1229
+ */
1230
+ class LeverageOraclePriceDeviationError extends LeverageLimitError {
1231
+ /**
1232
+ * @param params - Price comparison.
1233
+ * @param params.quotePrice - Worst swap price the Lever signs, scaled by `ORACLE_PRICE_SCALE`, rounded down.
1234
+ * @param params.oraclePrice - Market oracle price at the data block, scaled by `ORACLE_PRICE_SCALE`.
1235
+ * @param params.deviation - How far the quote price is above the oracle price, relative to it, WAD-scaled, rounded up.
1236
+ * @param params.max - Largest deviation accepted, WAD-scaled.
1237
+ */
1238
+ constructor(params) {
1239
+ super(`lever quote price "${params.quotePrice}" exceeds the oracle price "${params.oraclePrice}" by "${params.deviation}", above the limit "${params.max}" (WAD). Fetch a new quote, or lever a smaller amount.`);
1240
+ this.quotePrice = params.quotePrice;
1241
+ this.oraclePrice = params.oraclePrice;
1242
+ this.deviation = params.deviation;
1243
+ this.max = params.max;
1244
+ this.name = "LeverageOraclePriceDeviationError";
1245
+ }
1246
+ /** Worst swap price the Lever signs, scaled by `ORACLE_PRICE_SCALE`. */
1247
+ quotePrice;
1248
+ /** Market oracle price at the data block, scaled by `ORACLE_PRICE_SCALE`. */
1249
+ oraclePrice;
1250
+ /** Deviation from the oracle price, WAD-scaled. */
1251
+ deviation;
1252
+ /** Largest deviation accepted, WAD-scaled. */
1253
+ max;
1254
+ }
1255
+ exports.LeverageOraclePriceDeviationError = LeverageOraclePriceDeviationError;
1256
+ /**
1257
+ * Thrown when a Lever, a Delever or a Close with debt is built from leverage data without a usable oracle price: the
1258
+ * oracle call reverted or returned zero. Without it the SDK can derive neither the oracle deviation nor `maxLtv` and
1259
+ * the worst-fill checks, so it never signs such a swap. A Close without debt refuses with `LeverageCloseWithoutDebtError` first. For an
1260
+ * exit, the fallback is a no-swap exit, which needs no price once the debt is repaid.
1261
+ *
1262
+ * @example
1263
+ * ```ts
1264
+ * import { LeverageOraclePriceUnavailableError } from "@morpho-org/morpho-sdk";
1265
+ *
1266
+ * // `marketParams`: the market's `MarketParams`.
1267
+ * const error = new LeverageOraclePriceUnavailableError({
1268
+ * operation: "delever",
1269
+ * marketId: marketParams.id,
1270
+ * price: undefined,
1271
+ * });
1272
+ * ```
1273
+ */
1274
+ class LeverageOraclePriceUnavailableError extends LeverageLimitError {
1275
+ /**
1276
+ * @param params - Missing price.
1277
+ * @param params.operation - Leverage action refused.
1278
+ * @param params.marketId - Market whose oracle price is missing.
1279
+ * @param params.price - Price the leverage data holds: `undefined` when the oracle call reverted, else zero.
1280
+ */
1281
+ constructor(params) {
1282
+ super(`${params.operation} needs the oracle price of market "${params.marketId}", but the leverage data holds "${params.price}". ${params.operation === "lever" ? "Read the leverage data again once the oracle answers." : "Exit without a swap: repay or supplyCollateral to reduce risk, repayWithdrawCollateral to leave the position."}`);
1283
+ this.operation = params.operation;
1284
+ this.marketId = params.marketId;
1285
+ this.price = params.price;
1286
+ this.name = "LeverageOraclePriceUnavailableError";
1287
+ }
1288
+ /** Leverage action refused. */
1289
+ operation;
1290
+ /** Market whose oracle price is missing. */
1291
+ marketId;
1292
+ /** Price the leverage data holds: `undefined` when the oracle call reverted, else zero. */
1293
+ price;
1294
+ }
1295
+ exports.LeverageOraclePriceUnavailableError = LeverageOraclePriceUnavailableError;
1296
+ /**
1297
+ * Thrown when a Close's quote-based `minLoanOut` floor does not exceed the debt, or is below the debt
1298
+ * plus the interest buffer. The debt is never used as the floor.
1299
+ *
1300
+ * @example
1301
+ * ```ts
1302
+ * import { LeverageCloseFloorBelowDebtPlusBufferError } from "@morpho-org/morpho-sdk";
1303
+ *
1304
+ * const error = new LeverageCloseFloorBelowDebtPlusBufferError({ floor: 100n, debt: 100n });
1305
+ * ```
1306
+ */
1307
+ class LeverageCloseFloorBelowDebtPlusBufferError extends LeverageLimitError {
1308
+ /**
1309
+ * @param params - Floor comparison, in loan-token assets.
1310
+ * @param params.floor - Quote-based `minLoanOut`.
1311
+ * @param params.debt - Position's debt.
1312
+ * @param params.interestBuffer - Interest buffer the floor must also cover.
1313
+ */
1314
+ constructor(params) {
1315
+ super(`Close output floor "${params.floor}" ${params.interestBuffer === undefined ? `does not exceed debt "${params.debt}"` : `is below debt "${params.debt}" plus the interest buffer "${params.interestBuffer}"`}. Fetch a quote buying exactly the accrued debt plus the interest buffer, from the current leverage data. ${CLOSE_NO_SWAP_EXITS}`);
1316
+ this.floor = params.floor;
1317
+ this.debt = params.debt;
1318
+ this.interestBuffer = params.interestBuffer;
1319
+ this.name = "LeverageCloseFloorBelowDebtPlusBufferError";
1320
+ }
1321
+ /** Quote-based `minLoanOut`, in loan-token assets. */
1322
+ floor;
1323
+ /** Position's debt, in loan-token assets. */
1324
+ debt;
1325
+ /**
1326
+ * Interest buffer the floor must also cover, in loan-token assets (`computeCloseInterestBuffer`).
1327
+ * `computeCloseLimits` and `blueClose` always set it.
1328
+ */
1329
+ interestBuffer;
1330
+ }
1331
+ exports.LeverageCloseFloorBelowDebtPlusBufferError = LeverageCloseFloorBelowDebtPlusBufferError;
1332
+ /**
1333
+ * Thrown when a keep-collateral Close's exact-output quote buys more than the debt plus the
1334
+ * interest buffer. The extra loan token would come back to the user, but selling the collateral
1335
+ * for it costs price impact and fees, and gives up the collateral exposure the mode keeps. The
1336
+ * required amount moves whenever the leverage data does: a repay, accrued interest or a change in the borrow
1337
+ * rate (which scales the buffer) can raise or lower it, and a quote sized for another position usually
1338
+ * won't match it. Fetch a new quote for exactly `debt + interestBuffer` from the current leverageData.
1339
+ *
1340
+ * @example
1341
+ * ```ts
1342
+ * import { LeverageCloseBuyAboveDebtError } from "@morpho-org/morpho-sdk";
1343
+ *
1344
+ * const error = new LeverageCloseBuyAboveDebtError({ buyAmount: 70n, debt: 20n, interestBuffer: 1n });
1345
+ * ```
1346
+ */
1347
+ class LeverageCloseBuyAboveDebtError extends LeverageLimitError {
1348
+ /**
1349
+ * @param params - Buy comparison, in loan-token assets.
1350
+ * @param params.buyAmount - Quote's exact-output `buyAmount`.
1351
+ * @param params.debt - Position's accrued debt.
1352
+ * @param params.interestBuffer - Interest buffer from `computeCloseInterestBuffer`.
1353
+ */
1354
+ constructor(params) {
1355
+ super(`Keep-collateral Close quote buys "${params.buyAmount}" but the debt plus the interest buffer is "${params.debt + params.interestBuffer}". Fetch a quote buying exactly that amount. ${CLOSE_NO_SWAP_EXITS}`);
1356
+ this.buyAmount = params.buyAmount;
1357
+ this.debt = params.debt;
1358
+ this.interestBuffer = params.interestBuffer;
1359
+ this.name = "LeverageCloseBuyAboveDebtError";
1360
+ }
1361
+ /** Quote's exact-output `buyAmount`, in loan-token assets. */
1362
+ buyAmount;
1363
+ /** Position's accrued debt, in loan-token assets. */
1364
+ debt;
1365
+ /** Interest buffer the quote may add to the debt, in loan-token assets. */
1366
+ interestBuffer;
1367
+ }
1368
+ exports.LeverageCloseBuyAboveDebtError = LeverageCloseBuyAboveDebtError;
1369
+ /**
1370
+ * Thrown when a Close targets a position with neither debt nor collateral. The bundle would
1371
+ * withdraw zero collateral, which Morpho Blue rejects, so the transaction could only revert.
1372
+ *
1373
+ * @example
1374
+ * ```ts
1375
+ * import type { MarketId } from "@morpho-org/blue-sdk";
1376
+ * import { LeverageCloseEmptyPositionError } from "@morpho-org/morpho-sdk";
1377
+ *
1378
+ * const error = new LeverageCloseEmptyPositionError({
1379
+ * marketId: "0x3b3769cfca57be2eaed03fcc5299c25691b77781a1e124e7a8d520eb9a7eabb5" as MarketId,
1380
+ * user: userAddress,
1381
+ * });
1382
+ * ```
1383
+ */
1384
+ class LeverageCloseEmptyPositionError extends LeverageLimitError {
1385
+ /**
1386
+ * @param params - The empty position.
1387
+ * @param params.marketId - Market of the position.
1388
+ * @param params.user - Owner of the position.
1389
+ */
1390
+ constructor(params) {
1391
+ super(`Position of "${params.user}" on market "${params.marketId}" has no debt and no collateral, so there is nothing to close.`);
1392
+ this.marketId = params.marketId;
1393
+ this.user = params.user;
1394
+ this.name = "LeverageCloseEmptyPositionError";
1395
+ }
1396
+ /** Market of the position. */
1397
+ marketId;
1398
+ /** Owner of the position. */
1399
+ user;
1400
+ }
1401
+ exports.LeverageCloseEmptyPositionError = LeverageCloseEmptyPositionError;
1402
+ /**
1403
+ * Thrown when a Close targets a position that has collateral but no debt. ZeroExLeverageBundlesV1 still runs the
1404
+ * swap on such a position, and 0x AllowanceHolder reverts on the empty swap calldata a Close without debt would
1405
+ * sign, so the transaction could only revert. Withdraw the collateral with `market.withdrawCollateral` (`blueWithdrawCollateral`) instead.
1406
+ *
1407
+ * @see https://github.com/morpho-org/bundles/blob/3bf53141455051f8fc7a85cd00cc15bd89459238/src/leverage/ZeroExLeverageBundlesV1.sol#L180-L188
1408
+ * @example
1409
+ * ```ts
1410
+ * import type { MarketId } from "@morpho-org/blue-sdk";
1411
+ * import { LeverageCloseWithoutDebtError } from "@morpho-org/morpho-sdk";
1412
+ *
1413
+ * const error = new LeverageCloseWithoutDebtError({
1414
+ * marketId: "0x3b3769cfca57be2eaed03fcc5299c25691b77781a1e124e7a8d520eb9a7eabb5" as MarketId,
1415
+ * user: userAddress,
1416
+ * collateral: 10n ** 18n,
1417
+ * });
1418
+ * ```
1419
+ */
1420
+ class LeverageCloseWithoutDebtError extends LeverageLimitError {
1421
+ /**
1422
+ * @param params - The position without debt.
1423
+ * @param params.marketId - Market of the position.
1424
+ * @param params.user - Owner of the position.
1425
+ * @param params.collateral - Collateral of the position, in collateral-token assets.
1426
+ */
1427
+ constructor(params) {
1428
+ super(`Position of "${params.user}" on market "${params.marketId}" has no debt, so a Close would revert in its 0x swap. Withdraw its "${params.collateral}" collateral with market.withdrawCollateral (blueWithdrawCollateral) instead.`);
1429
+ this.marketId = params.marketId;
1430
+ this.user = params.user;
1431
+ this.collateral = params.collateral;
1432
+ this.name = "LeverageCloseWithoutDebtError";
1433
+ }
1434
+ /** Market of the position. */
1435
+ marketId;
1436
+ /** Owner of the position. */
1437
+ user;
1438
+ /** Collateral of the position, in collateral-token assets. */
1439
+ collateral;
1440
+ }
1441
+ exports.LeverageCloseWithoutDebtError = LeverageCloseWithoutDebtError;
1442
+ /**
1443
+ * Thrown when a Close's quote-based `maxCollateralIn` cap exceeds the position's collateral.
1444
+ *
1445
+ * @example
1446
+ * ```ts
1447
+ * import { LeverageCloseInputExceedsCollateralError } from "@morpho-org/morpho-sdk";
1448
+ *
1449
+ * const error = new LeverageCloseInputExceedsCollateralError({ cap: 101n, collateral: 100n });
1450
+ * ```
1451
+ */
1452
+ class LeverageCloseInputExceedsCollateralError extends LeverageLimitError {
1453
+ /**
1454
+ * @param params - Cap comparison, in collateral-token assets.
1455
+ * @param params.cap - Quote-based `maxCollateralIn`.
1456
+ * @param params.collateral - Position's collateral.
1457
+ */
1458
+ constructor(params) {
1459
+ super(`Close input cap "${params.cap}" exceeds position collateral "${params.collateral}". Fetch a quote selling at most the position's collateral. ${CLOSE_NO_SWAP_EXITS}`);
1460
+ this.cap = params.cap;
1461
+ this.collateral = params.collateral;
1462
+ this.name = "LeverageCloseInputExceedsCollateralError";
1463
+ }
1464
+ /** Quote-based `maxCollateralIn`, in collateral-token assets. */
1465
+ cap;
1466
+ /** Position's collateral, in collateral-token assets. */
1467
+ collateral;
1468
+ }
1469
+ exports.LeverageCloseInputExceedsCollateralError = LeverageCloseInputExceedsCollateralError;
1470
+ /**
1471
+ * Thrown when leverage is requested on a chain without a registered leverage bundle, or whose
1472
+ * AllowanceHolder is not at its Cancun address (excluded by the SDK's chain list, or no code at
1473
+ * the data block).
1474
+ *
1475
+ * @example
1476
+ * ```ts
1477
+ * import { LeverageUnsupportedChainError } from "@morpho-org/morpho-sdk";
1478
+ *
1479
+ * const error = new LeverageUnsupportedChainError({ chainId: 56, reason: "noBundle" });
1480
+ * ```
1481
+ */
1482
+ class LeverageUnsupportedChainError extends LeverageLimitError {
1483
+ /**
1484
+ * @param params - Chain details.
1485
+ * @param params.chainId - Chain id requested.
1486
+ * @param params.reason - `noBundle` when no leverage bundle is registered; `noAllowanceHolder` when AllowanceHolder is not at its Cancun address on the chain, either because the SDK's chain list excludes the chain or because a code read at the data block found none.
1487
+ */
1488
+ constructor(params) {
1489
+ const detail = params.reason === "noBundle"
1490
+ ? "has no registered leverage bundle"
1491
+ : "has no AllowanceHolder at its Cancun address";
1492
+ super(`Chain "${params.chainId}" ${detail}. Offer leverage only on supported chains.`);
1493
+ this.chainId = params.chainId;
1494
+ this.reason = params.reason;
1495
+ this.name = "LeverageUnsupportedChainError";
1496
+ }
1497
+ /** Chain id requested. */
1498
+ chainId;
1499
+ /** Why the chain is unsupported. */
1500
+ reason;
1501
+ }
1502
+ exports.LeverageUnsupportedChainError = LeverageUnsupportedChainError;
1503
+ /**
1504
+ * Thrown when a leverage reallocation targets another market than the action's market.
1505
+ * The contract checks only the loan token, so the SDK requires the exact market.
1506
+ *
1507
+ * @example
1508
+ * ```ts
1509
+ * import { LeverageReallocationMarketMismatchError } from "@morpho-org/morpho-sdk";
1510
+ *
1511
+ * const error = new LeverageReallocationMarketMismatchError({
1512
+ * vault: vaultAddress,
1513
+ * expected: leverMarketParams.id,
1514
+ * actual: reallocationMarketParams.id,
1515
+ * });
1516
+ * ```
1517
+ */
1518
+ class LeverageReallocationMarketMismatchError extends LeverageReallocationError {
1519
+ /**
1520
+ * @param params - Market comparison.
1521
+ * @param params.vault - Vault whose reallocation targets the wrong market.
1522
+ * @param params.expected - Action's market id.
1523
+ * @param params.actual - Market id the reallocation targets.
1524
+ */
1525
+ constructor(params) {
1526
+ super(`Reallocation from vault "${params.vault}" targets market "${params.actual}", expected the action's market "${params.expected}". Reallocate only into the action's market.`);
1527
+ this.vault = params.vault;
1528
+ this.expected = params.expected;
1529
+ this.actual = params.actual;
1530
+ this.name = "LeverageReallocationMarketMismatchError";
1531
+ }
1532
+ /** Vault whose reallocation targets the wrong market. */
1533
+ vault;
1534
+ /** Action's market id. */
1535
+ expected;
1536
+ /** Market id the reallocation targets. */
1537
+ actual;
1538
+ }
1539
+ exports.LeverageReallocationMarketMismatchError = LeverageReallocationMarketMismatchError;
1540
+ /**
1541
+ * Thrown when a leverage reallocation's route is unavailable at the data block: the vault has no
1542
+ * public-allocator flow into the action's market, or the selected idle or source-market leg cannot be
1543
+ * pulled. Another source in the same vault may still work.
1544
+ *
1545
+ * @example
1546
+ * ```ts
1547
+ * import { LeverageReallocationNoFlowError } from "@morpho-org/morpho-sdk";
1548
+ *
1549
+ * const error = new LeverageReallocationNoFlowError({
1550
+ * vault: vaultAddress,
1551
+ * marketId: leverMarketParams.id,
1552
+ * });
1553
+ * ```
1554
+ */
1555
+ class LeverageReallocationNoFlowError extends LeverageReallocationError {
1556
+ /**
1557
+ * @param params - Flow details.
1558
+ * @param params.vault - Vault whose selected route is unavailable.
1559
+ * @param params.marketId - Action's market id.
1560
+ */
1561
+ constructor(params) {
1562
+ super(`Vault "${params.vault}" has no usable public-allocator route into market "${params.marketId}" from the selected source. Choose another source in this vault, or reallocate from another vault.`);
1563
+ this.vault = params.vault;
1564
+ this.marketId = params.marketId;
1565
+ this.name = "LeverageReallocationNoFlowError";
1566
+ }
1567
+ /** Vault whose selected route is unavailable. */
1568
+ vault;
1569
+ /** Action's market id. */
1570
+ marketId;
1571
+ }
1572
+ exports.LeverageReallocationNoFlowError = LeverageReallocationNoFlowError;
1573
+ /**
1574
+ * Thrown when a leverage reallocation's penalty rate exceeds the SDK's ceiling.
1575
+ *
1576
+ * @example
1577
+ * ```ts
1578
+ * import { LeverageReallocationPenaltyAboveLimitError } from "@morpho-org/morpho-sdk";
1579
+ *
1580
+ * const error = new LeverageReallocationPenaltyAboveLimitError({
1581
+ * vault: vaultAddress,
1582
+ * penalty: 20_000_000_000_000_000n,
1583
+ * max: 10_000_000_000_000_000n,
1584
+ * });
1585
+ * ```
1586
+ */
1587
+ class LeverageReallocationPenaltyAboveLimitError extends LeverageReallocationError {
1588
+ /**
1589
+ * @param params - Penalty comparison, WAD-scaled.
1590
+ * @param params.vault - Vault charging the penalty.
1591
+ * @param params.penalty - Vault's penalty rate.
1592
+ * @param params.max - SDK penalty ceiling.
1593
+ */
1594
+ constructor(params) {
1595
+ super(`Penalty "${params.penalty}" of vault "${params.vault}" exceeds the SDK ceiling "${params.max}" (WAD). Drop this vault's reallocation.`);
1596
+ this.vault = params.vault;
1597
+ this.penalty = params.penalty;
1598
+ this.max = params.max;
1599
+ this.name = "LeverageReallocationPenaltyAboveLimitError";
1600
+ }
1601
+ /** Vault charging the penalty. */
1602
+ vault;
1603
+ /** Vault's penalty rate, WAD-scaled. */
1604
+ penalty;
1605
+ /** SDK penalty ceiling, WAD-scaled. */
1606
+ max;
1607
+ }
1608
+ exports.LeverageReallocationPenaltyAboveLimitError = LeverageReallocationPenaltyAboveLimitError;
1609
+ /**
1610
+ * Thrown when leverage reallocations together move more liquidity than the action's borrow cap
1611
+ * (`maxBorrowAssets`).
1612
+ *
1613
+ * @example
1614
+ * ```ts
1615
+ * import { LeverageReallocationExceedsBorrowError } from "@morpho-org/morpho-sdk";
1616
+ *
1617
+ * const error = new LeverageReallocationExceedsBorrowError({
1618
+ * total: 101n,
1619
+ * maxBorrowAssets: 100n,
1620
+ * });
1621
+ * ```
1622
+ */
1623
+ class LeverageReallocationExceedsBorrowError extends LeverageReallocationError {
1624
+ /**
1625
+ * @param params - Liquidity comparison, in loan-token assets.
1626
+ * @param params.total - Assets moved by all reallocations.
1627
+ * @param params.maxBorrowAssets - Action's signed borrow cap.
1628
+ */
1629
+ constructor(params) {
1630
+ super(`Reallocations move "${params.total}", more than the borrow cap "${params.maxBorrowAssets}". Reallocate only the liquidity the borrow needs.`);
1631
+ this.total = params.total;
1632
+ this.maxBorrowAssets = params.maxBorrowAssets;
1633
+ this.name = "LeverageReallocationExceedsBorrowError";
1634
+ }
1635
+ /** Assets moved by all reallocations. */
1636
+ total;
1637
+ /** Action's signed borrow cap (`maxBorrowAssets`), in loan-token assets. */
1638
+ maxBorrowAssets;
1639
+ }
1640
+ exports.LeverageReallocationExceedsBorrowError = LeverageReallocationExceedsBorrowError;
1641
+ /**
1642
+ * Thrown when the market's liquidity at the data block plus the assets the reallocations move
1643
+ * into it cannot fund the action's borrow (`maxBorrowAssets`), so the transaction would revert.
1644
+ *
1645
+ * @example
1646
+ * ```ts
1647
+ * import { LeverageInsufficientLiquidityError } from "@morpho-org/morpho-sdk";
1648
+ *
1649
+ * const error = new LeverageInsufficientLiquidityError({
1650
+ * liquidity: 40n,
1651
+ * reallocatedAssets: 50n,
1652
+ * maxBorrowAssets: 100n,
1653
+ * });
1654
+ * ```
1655
+ */
1656
+ class LeverageInsufficientLiquidityError extends LeverageLimitError {
1657
+ /**
1658
+ * @param params - Liquidity comparison, in loan-token assets.
1659
+ * @param params.liquidity - Market liquidity at the data block.
1660
+ * @param params.reallocatedAssets - Assets moved into the market by all reallocations.
1661
+ * @param params.maxBorrowAssets - Action's signed borrow cap.
1662
+ */
1663
+ constructor(params) {
1664
+ super(`Market liquidity "${params.liquidity}" plus reallocated assets "${params.reallocatedAssets}" cannot fund the borrow "${params.maxBorrowAssets}". Borrow less or reallocate more liquidity into the market.`);
1665
+ this.liquidity = params.liquidity;
1666
+ this.reallocatedAssets = params.reallocatedAssets;
1667
+ this.maxBorrowAssets = params.maxBorrowAssets;
1668
+ this.name = "LeverageInsufficientLiquidityError";
1669
+ }
1670
+ /** Market liquidity at the data block, in loan-token assets. */
1671
+ liquidity;
1672
+ /** Assets moved into the market by all reallocations, in loan-token assets. */
1673
+ reallocatedAssets;
1674
+ /** Action's signed borrow cap (`maxBorrowAssets`), in loan-token assets. */
1675
+ maxBorrowAssets;
1676
+ }
1677
+ exports.LeverageInsufficientLiquidityError = LeverageInsufficientLiquidityError;
1678
+ /**
1679
+ * Thrown when a Lever's planned reallocations, replayed in order at the data block, leave a
1680
+ * target cap of the market's vault over its cap: a leg trimmed below the amount the planner chose
1681
+ * failed the cap check, and the planner's own amounts no longer fit once trimming dropped other
1682
+ * legs. Executing the plan would revert.
1683
+ *
1684
+ * @example
1685
+ * ```ts
1686
+ * import { LeverageReallocationOutsideCapsError } from "@morpho-org/morpho-sdk";
1687
+ *
1688
+ * const error = new LeverageReallocationOutsideCapsError({
1689
+ * vault: vaultAddress,
1690
+ * assets: 100n,
1691
+ * });
1692
+ * ```
1693
+ */
1694
+ class LeverageReallocationOutsideCapsError extends LeverageReallocationError {
1695
+ /**
1696
+ * @param params - Leg that breaks a cap.
1697
+ * @param params.vault - Vault the leg reallocates from.
1698
+ * @param params.assets - Assets the leg moves, in loan-token assets.
1699
+ */
1700
+ constructor(params) {
1701
+ super(`Reallocating "${params.assets}" from vault "${params.vault}" leaves one of its target caps exceeded. Borrow a different amount or exclude this vault from reallocatableVaults.`);
1702
+ this.vault = params.vault;
1703
+ this.assets = params.assets;
1704
+ this.name = "LeverageReallocationOutsideCapsError";
1705
+ }
1706
+ /** Vault the leg reallocates from. */
1707
+ vault;
1708
+ /** Assets the leg moves, in loan-token assets. */
1709
+ assets;
1710
+ }
1711
+ exports.LeverageReallocationOutsideCapsError = LeverageReallocationOutsideCapsError;