@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.2

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 (174) hide show
  1. package/MIGRATION-v5-to-v6.md +127 -16
  2. package/README.md +17 -11
  3. package/lib/cjs/abis.d.ts +17 -2
  4. package/lib/cjs/abis.js +14 -1
  5. package/lib/cjs/actions/blue/common.js +5 -26
  6. package/lib/cjs/actions/blue/supply.js +2 -7
  7. package/lib/cjs/actions/bundles/common.d.ts +32 -2
  8. package/lib/cjs/actions/bundles/common.js +68 -30
  9. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  10. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
  11. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
  12. package/lib/cjs/actions/requirements/blue/index.js +0 -1
  13. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  14. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +20 -20
  15. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -27
  17. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  18. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  19. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  20. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  21. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  22. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  23. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  24. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  25. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  26. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
  27. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
  28. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
  29. package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
  30. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  31. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  32. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
  33. package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
  34. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  35. package/lib/cjs/blue/abis.d.ts +5 -1
  36. package/lib/cjs/blue/abis.js +2 -0
  37. package/lib/cjs/blue/entities.d.ts +8 -2
  38. package/lib/cjs/blue/entities.js +1 -0
  39. package/lib/cjs/blue/errors.d.ts +1 -1
  40. package/lib/cjs/blue/errors.js +2 -1
  41. package/lib/cjs/blue/fetch.d.ts +3 -1
  42. package/lib/cjs/blue/fetch.js +1 -0
  43. package/lib/cjs/entities/blue/blue.d.ts +15 -6
  44. package/lib/cjs/entities/blue/blue.js +3 -0
  45. package/lib/cjs/entities/index.d.ts +8 -2
  46. package/lib/cjs/entities/index.js +1 -0
  47. package/lib/cjs/entities/midnight/midnight.js +20 -24
  48. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  49. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
  50. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  51. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  52. package/lib/cjs/entities/requirements/index.js +1 -0
  53. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +10 -5
  54. package/lib/cjs/entities/vaultV1/vaultV1.js +13 -1
  55. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  56. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  57. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +140 -34
  58. package/lib/cjs/entities/vaultV2/vaultV2.js +229 -16
  59. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  60. package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
  61. package/lib/cjs/errors.d.ts +1 -1
  62. package/lib/cjs/errors.js +3 -2
  63. package/lib/cjs/fetch.d.ts +3 -1
  64. package/lib/cjs/fetch.js +1 -0
  65. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  66. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  67. package/lib/cjs/helpers/index.d.ts +3 -1
  68. package/lib/cjs/helpers/index.js +10 -1
  69. package/lib/cjs/helpers/metadata.d.ts +3 -5
  70. package/lib/cjs/helpers/metadata.js +4 -6
  71. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  72. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  73. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  74. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  75. package/lib/cjs/helpers/slippage.d.ts +46 -0
  76. package/lib/cjs/helpers/slippage.js +65 -0
  77. package/lib/cjs/helpers/validate.d.ts +65 -8
  78. package/lib/cjs/helpers/validate.js +83 -9
  79. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  80. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  81. package/lib/cjs/types/action.d.ts +95 -13
  82. package/lib/cjs/types/error.d.ts +290 -12
  83. package/lib/cjs/types/error.js +312 -24
  84. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  85. package/lib/cjs/utils.d.ts +3 -1
  86. package/lib/cjs/utils.js +10 -1
  87. package/lib/esm/abis.d.ts +17 -2
  88. package/lib/esm/abis.js +17 -2
  89. package/lib/esm/actions/blue/common.js +7 -28
  90. package/lib/esm/actions/blue/supply.js +4 -9
  91. package/lib/esm/actions/bundles/common.d.ts +32 -2
  92. package/lib/esm/actions/bundles/common.js +68 -31
  93. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  94. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
  95. package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
  96. package/lib/esm/actions/requirements/blue/index.js +0 -1
  97. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  98. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
  99. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  100. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -28
  101. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  102. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  103. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  104. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  105. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  106. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  107. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  108. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  109. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  110. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
  111. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
  112. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
  113. package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
  114. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  115. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  116. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
  117. package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
  118. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  119. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  120. package/lib/esm/blue/abis.d.ts +5 -1
  121. package/lib/esm/blue/abis.js +5 -1
  122. package/lib/esm/blue/entities.d.ts +8 -2
  123. package/lib/esm/blue/entities.js +3 -1
  124. package/lib/esm/blue/errors.d.ts +1 -1
  125. package/lib/esm/blue/errors.js +1 -1
  126. package/lib/esm/blue/fetch.d.ts +3 -1
  127. package/lib/esm/blue/fetch.js +3 -1
  128. package/lib/esm/entities/blue/blue.d.ts +15 -6
  129. package/lib/esm/entities/blue/blue.js +3 -0
  130. package/lib/esm/entities/index.d.ts +8 -2
  131. package/lib/esm/entities/index.js +3 -1
  132. package/lib/esm/entities/midnight/midnight.js +20 -24
  133. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  134. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
  135. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  136. package/lib/esm/entities/requirements/index.d.ts +1 -0
  137. package/lib/esm/entities/requirements/index.js +1 -0
  138. package/lib/esm/entities/vaultV1/vaultV1.d.ts +10 -5
  139. package/lib/esm/entities/vaultV1/vaultV1.js +14 -2
  140. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  141. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  142. package/lib/esm/entities/vaultV2/vaultV2.d.ts +140 -34
  143. package/lib/esm/entities/vaultV2/vaultV2.js +234 -21
  144. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  145. package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
  146. package/lib/esm/errors.d.ts +1 -1
  147. package/lib/esm/errors.js +1 -1
  148. package/lib/esm/fetch.d.ts +3 -1
  149. package/lib/esm/fetch.js +3 -1
  150. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  151. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  152. package/lib/esm/helpers/index.d.ts +3 -1
  153. package/lib/esm/helpers/index.js +3 -1
  154. package/lib/esm/helpers/metadata.d.ts +3 -5
  155. package/lib/esm/helpers/metadata.js +4 -6
  156. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  157. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  158. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  159. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  160. package/lib/esm/helpers/slippage.d.ts +46 -0
  161. package/lib/esm/helpers/slippage.js +65 -1
  162. package/lib/esm/helpers/validate.d.ts +65 -8
  163. package/lib/esm/helpers/validate.js +82 -10
  164. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  165. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  166. package/lib/esm/types/action.d.ts +95 -13
  167. package/lib/esm/types/error.d.ts +290 -12
  168. package/lib/esm/types/error.js +301 -19
  169. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  170. package/lib/esm/utils.d.ts +3 -1
  171. package/lib/esm/utils.js +3 -1
  172. package/package.json +7 -7
  173. /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
  174. /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
@@ -97,8 +97,23 @@ export class ExpiredDeadlineError extends Error {
97
97
  this.name = "ExpiredDeadlineError";
98
98
  }
99
99
  }
100
- /** Thrown when Vault V2 in-kind redemption is attempted with anything other than one adapter. */
101
- export class InKindRedeemRequiresSingleAdapterError extends Error {
100
+ /**
101
+ * Thrown when a VaultExitBundlesV1 Vault V2 exit targets a vault without exactly one adapter.
102
+ *
103
+ * Both `vaultExitBundlesV1InKindRedemptionVaultV2` and
104
+ * `vaultExitBundlesV1ForceWithdrawVaultV2` require `adaptersLength() == 1`.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * import { VaultV2SingleAdapterRequiredError } from "@morpho-org/morpho-sdk";
109
+ *
110
+ * const error = new VaultV2SingleAdapterRequiredError(vault, 2);
111
+ * if (error instanceof VaultV2SingleAdapterRequiredError) {
112
+ * console.error(error.vault, error.adapters);
113
+ * }
114
+ * ```
115
+ */
116
+ export class VaultV2SingleAdapterRequiredError extends Error {
102
117
  vault;
103
118
  adapters;
104
119
  /**
@@ -106,12 +121,14 @@ export class InKindRedeemRequiresSingleAdapterError extends Error {
106
121
  * @param adapters - Number of adapters in the supplied vault snapshot.
107
122
  */
108
123
  constructor(vault, adapters) {
109
- super(`Vault "${vault}" has "${adapters}" adapters. In-kind redemption requires exactly one MorphoMarketV1AdapterV2.`);
124
+ super(`Vault "${vault}" has "${adapters}" adapters. VaultExitBundlesV1 exits require exactly one MorphoMarketV1AdapterV2.`);
110
125
  this.vault = vault;
111
126
  this.adapters = adapters;
112
- this.name = "InKindRedeemRequiresSingleAdapterError";
127
+ this.name = "VaultV2SingleAdapterRequiredError";
113
128
  }
114
129
  }
130
+ /** @deprecated Use {@link VaultV2SingleAdapterRequiredError}. */
131
+ export const InKindRedeemRequiresSingleAdapterError = VaultV2SingleAdapterRequiredError;
115
132
  /** Thrown when a requested in-kind redemption adapter is not part of the Vault V2 snapshot. */
116
133
  export class AdapterNotPartOfVaultError extends Error {
117
134
  vault;
@@ -127,16 +144,290 @@ export class AdapterNotPartOfVaultError extends Error {
127
144
  this.name = "AdapterNotPartOfVaultError";
128
145
  }
129
146
  }
130
- /** Thrown when the Vault V2 adapter cannot expose MorphoMarketV1AdapterV2 market shares. */
131
- export class UnsupportedInKindAdapterError extends Error {
147
+ /**
148
+ * Thrown when the Vault V2 adapter cannot expose MorphoMarketV1AdapterV2 market shares.
149
+ *
150
+ * VaultExitBundlesV1 casts the adapter to `IMorphoMarketV1AdapterV2`, so a legacy
151
+ * positions-based `MorphoMarketV1Adapter` or a `MorphoVaultV1Adapter` cannot be exited.
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * import { VaultV2UnsupportedExitAdapterError } from "@morpho-org/morpho-sdk";
156
+ *
157
+ * const error = new VaultV2UnsupportedExitAdapterError(adapter);
158
+ * if (error instanceof VaultV2UnsupportedExitAdapterError) {
159
+ * console.error(error.adapter);
160
+ * }
161
+ * ```
162
+ */
163
+ export class VaultV2UnsupportedExitAdapterError extends Error {
132
164
  adapter;
133
165
  /**
134
166
  * @param adapter - Unsupported Vault V2 adapter address.
135
167
  */
136
168
  constructor(adapter) {
137
- super(`Adapter "${adapter}" does not support Vault V2 in-kind redemption. Use a MorphoMarketV1AdapterV2-backed vault.`);
169
+ super(`Adapter "${adapter}" does not support Vault V2 exits through VaultExitBundlesV1. Use a MorphoMarketV1AdapterV2-backed vault.`);
138
170
  this.adapter = adapter;
139
- this.name = "UnsupportedInKindAdapterError";
171
+ this.name = "VaultV2UnsupportedExitAdapterError";
172
+ }
173
+ }
174
+ /** @deprecated Use {@link VaultV2UnsupportedExitAdapterError}. */
175
+ export const UnsupportedInKindAdapterError = VaultV2UnsupportedExitAdapterError;
176
+ /**
177
+ * Thrown when a Vault V2 exit cannot resolve the vault's configured liquidity adapter.
178
+ *
179
+ * `VaultExitBundlesV1.vaultExitBundlesV1ForceWithdrawVaultV2` casts `liquidityAdapter` to
180
+ * `IMorphoMarketV1AdapterV2` and ABI-decodes `liquidityData` as `MarketParams`. Because the exit
181
+ * also requires `adaptersLength() == 1`, the only resolvable configurations are an unset
182
+ * liquidity adapter or the vault's sole adapter.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * import { VaultV2UnsupportedLiquidityAdapterError } from "@morpho-org/morpho-sdk";
187
+ *
188
+ * const error = new VaultV2UnsupportedLiquidityAdapterError({
189
+ * vault,
190
+ * liquidityAdapter,
191
+ * adapter,
192
+ * });
193
+ * if (error instanceof VaultV2UnsupportedLiquidityAdapterError) {
194
+ * console.error(error.liquidityAdapter, error.adapter);
195
+ * }
196
+ * ```
197
+ */
198
+ export class VaultV2UnsupportedLiquidityAdapterError extends Error {
199
+ /** Vault V2 address. */
200
+ vault;
201
+ /** Liquidity adapter configured on the vault. */
202
+ liquidityAdapter;
203
+ /** Sole adapter the exit targets. */
204
+ adapter;
205
+ /**
206
+ * @param params - Liquidity-adapter mismatch details.
207
+ * @param params.vault - Vault V2 address.
208
+ * @param params.liquidityAdapter - Liquidity adapter configured on the vault.
209
+ * @param params.adapter - Sole adapter the exit targets.
210
+ */
211
+ constructor(params) {
212
+ super(`Vault "${params.vault}" routes liquidity through "${params.liquidityAdapter}", which is neither unset nor its sole adapter "${params.adapter}". Use another exit path until the vault routes liquidity through its sole MorphoMarketV1AdapterV2.`);
213
+ this.vault = params.vault;
214
+ this.liquidityAdapter = params.liquidityAdapter;
215
+ this.adapter = params.adapter;
216
+ this.name = "VaultV2UnsupportedLiquidityAdapterError";
217
+ }
218
+ }
219
+ /**
220
+ * Thrown when a Vault V2 exit cannot ABI-decode the vault's `liquidityData` as `MarketParams`.
221
+ *
222
+ * Distinct from {@link VaultV2UnsupportedLiquidityAdapterError}: the liquidity adapter *is* the
223
+ * vault's sole adapter, but the market params stored alongside it are unusable, so the contract's
224
+ * `abi.decode` would revert. Only the vault curator can repair this by re-setting the liquidity
225
+ * adapter and data.
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * import { VaultV2UndecodableLiquidityDataError } from "@morpho-org/morpho-sdk";
230
+ *
231
+ * try {
232
+ * vault.forceWithdraw({ exitAssets: 1_000_000n, vaultData, userAddress });
233
+ * } catch (error) {
234
+ * if (error instanceof VaultV2UndecodableLiquidityDataError) {
235
+ * console.error(error.liquidityData, error.cause);
236
+ * }
237
+ * }
238
+ * ```
239
+ */
240
+ export class VaultV2UndecodableLiquidityDataError extends Error {
241
+ /** Vault V2 address. */
242
+ vault;
243
+ /** Liquidity adapter configured on the vault. */
244
+ liquidityAdapter;
245
+ /** Raw `liquidityData` that failed to decode. */
246
+ liquidityData;
247
+ /**
248
+ * @param params - Undecodable liquidity-data details.
249
+ * @param params.vault - Vault V2 address.
250
+ * @param params.liquidityAdapter - Liquidity adapter configured on the vault.
251
+ * @param params.liquidityData - Raw `liquidityData` that failed to decode.
252
+ * @param params.cause - Underlying decode failure.
253
+ */
254
+ constructor(params) {
255
+ super(`Vault "${params.vault}" stores liquidity data "${params.liquidityData}" for adapter "${params.liquidityAdapter}" that does not decode as MarketParams. Use another exit path until the vault curator re-sets its liquidity adapter and data.`, { cause: params.cause });
256
+ this.vault = params.vault;
257
+ this.liquidityAdapter = params.liquidityAdapter;
258
+ this.liquidityData = params.liquidityData;
259
+ this.name = "VaultV2UndecodableLiquidityDataError";
260
+ }
261
+ }
262
+ /**
263
+ * Thrown when the adapter's markets cannot cover a Vault V2 force withdrawal.
264
+ *
265
+ * `vaultExitBundlesV1ForceWithdrawVaultV2` loops over the adapter's market list without a bound,
266
+ * so an under-covered request reverts on-chain with a raw `panic 0x32`. This error surfaces that
267
+ * failure before submission.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * import { VaultV2ForceWithdrawCoverageError } from "@morpho-org/morpho-sdk";
272
+ *
273
+ * const error = new VaultV2ForceWithdrawCoverageError({
274
+ * required: 100n,
275
+ * covered: 40n,
276
+ * maxExitAssets: 60n,
277
+ * });
278
+ * if (error instanceof VaultV2ForceWithdrawCoverageError) {
279
+ * console.error(error.maxExitAssets);
280
+ * }
281
+ * ```
282
+ */
283
+ export class VaultV2ForceWithdrawCoverageError extends Error {
284
+ /** Assets that must be force-deallocated from the adapter's markets. */
285
+ required;
286
+ /** Assets the adapter's markets can actually release. */
287
+ covered;
288
+ /** Largest penalty-inclusive `exitAssets` the current vault state supports. */
289
+ maxExitAssets;
290
+ /**
291
+ * @param params - Coverage values used to explain the rejected exit.
292
+ * @param params.required - Assets that must be force-deallocated.
293
+ * @param params.covered - Assets the adapter's markets can release.
294
+ * @param params.maxExitAssets - Largest supported penalty-inclusive `exitAssets`.
295
+ */
296
+ constructor(params) {
297
+ super(`Force withdrawal requires "${params.required}" force-deallocated assets but the adapter's markets only release "${params.covered}". Reduce exitAssets to at most "${params.maxExitAssets}" or wait for market liquidity.`);
298
+ this.required = params.required;
299
+ this.covered = params.covered;
300
+ this.maxExitAssets = params.maxExitAssets;
301
+ this.name = "VaultV2ForceWithdrawCoverageError";
302
+ }
303
+ }
304
+ /**
305
+ * Thrown when a Vault V2 force withdrawal would withdraw nothing while still consuming its permit.
306
+ *
307
+ * Happens on a dust `exitAssets` when the vault has no penalty-free liquidity and the
308
+ * penalty-adjusted remainder rounds down to zero.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * import { VaultV2ForceWithdrawZeroWithdrawalError } from "@morpho-org/morpho-sdk";
313
+ *
314
+ * const error = new VaultV2ForceWithdrawZeroWithdrawalError({
315
+ * vault,
316
+ * exitAssets: 1n,
317
+ * penalty: 20_000000000000000n,
318
+ * });
319
+ * if (error instanceof VaultV2ForceWithdrawZeroWithdrawalError) {
320
+ * console.error(error.exitAssets, error.penalty);
321
+ * }
322
+ * ```
323
+ */
324
+ export class VaultV2ForceWithdrawZeroWithdrawalError extends Error {
325
+ /** Vault V2 address. */
326
+ vault;
327
+ /** Positive penalty-inclusive amount requested by the caller. */
328
+ exitAssets;
329
+ /** WAD-scaled force-deallocation penalty applied by the adapter. */
330
+ penalty;
331
+ /**
332
+ * @param params - Values that caused the exit to withdraw nothing.
333
+ * @param params.vault - Vault V2 address.
334
+ * @param params.exitAssets - Positive penalty-inclusive amount requested by the caller.
335
+ * @param params.penalty - WAD-scaled force-deallocation penalty applied by the adapter.
336
+ */
337
+ constructor(params) {
338
+ super(`Vault "${params.vault}" has no penalty-free liquidity, and force-withdraw exitAssets "${params.exitAssets}" rounds to zero withdrawn assets after applying penalty "${params.penalty}". Increase exitAssets or use another exit path.`);
339
+ this.vault = params.vault;
340
+ this.exitAssets = params.exitAssets;
341
+ this.penalty = params.penalty;
342
+ this.name = "VaultV2ForceWithdrawZeroWithdrawalError";
343
+ }
344
+ }
345
+ /**
346
+ * Thrown when a Vault V2 force withdrawal's derived share-price floor rounds down to zero.
347
+ *
348
+ * VaultExitBundlesV1 reads `minSharePriceE27 == 0` as "no bound at all", so emitting a rounded-down
349
+ * zero would silently ship an exit with none of the slippage protection this path exists to add.
350
+ * Reaching it means the exit burns more shares than `withdrawnAssets` can price at RAY scale — a
351
+ * vault whose share price has collapsed below `1e-27` assets per share, or a dust exit against one.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * import { VaultV2ForceWithdrawZeroSharePriceError } from "@morpho-org/morpho-sdk";
356
+ *
357
+ * try {
358
+ * vault.forceWithdraw({ exitAssets, vaultData, userAddress });
359
+ * } catch (error) {
360
+ * if (error instanceof VaultV2ForceWithdrawZeroSharePriceError) {
361
+ * console.error(error.withdrawnAssets, error.sharesBurnt);
362
+ * }
363
+ * }
364
+ * ```
365
+ */
366
+ export class VaultV2ForceWithdrawZeroSharePriceError extends Error {
367
+ /** Assets the exit withdraws in total, before the referral fee. */
368
+ withdrawnAssets;
369
+ /** Upper bound of the vault shares the exit burns. */
370
+ sharesBurnt;
371
+ /** WAD-scaled slippage tolerance applied to the floor. */
372
+ slippageTolerance;
373
+ /**
374
+ * @param params - Values whose ratio rounded down to a zero share-price floor.
375
+ * @param params.withdrawnAssets - Assets the exit withdraws in total, before the referral fee.
376
+ * @param params.sharesBurnt - Upper bound of the vault shares the exit burns.
377
+ * @param params.slippageTolerance - WAD-scaled slippage tolerance applied to the floor.
378
+ */
379
+ constructor(params) {
380
+ super(`Force-withdraw share-price floor rounds to zero: withdrawnAssets "${params.withdrawnAssets}" over sharesBurnt "${params.sharesBurnt}" at slippageTolerance "${params.slippageTolerance}". The contract reads a zero floor as no bound at all, so this exit cannot be built safely — increase exitAssets or use another exit path.`);
381
+ this.withdrawnAssets = params.withdrawnAssets;
382
+ this.sharesBurnt = params.sharesBurnt;
383
+ this.slippageTolerance = params.slippageTolerance;
384
+ this.name = "VaultV2ForceWithdrawZeroSharePriceError";
385
+ }
386
+ }
387
+ /**
388
+ * Thrown when fee shares projected to the accepted deadline reach the lower force-withdraw
389
+ * burn bound at that time.
390
+ *
391
+ * VaultExitBundlesV1 measures shares burned after its first withdrawal accrues fees. If the
392
+ * recipient's fee shares are at least the measured burn bound, its share-price check is skipped or
393
+ * reverts due to an underflow.
394
+ *
395
+ * @example
396
+ * ```ts
397
+ * import { VaultV2ForceWithdrawFeeSharesExceedBurnError } from "@morpho-org/morpho-sdk";
398
+ *
399
+ * try {
400
+ * vault.forceWithdraw({ exitAssets, vaultData, userAddress });
401
+ * } catch (error) {
402
+ * if (error instanceof VaultV2ForceWithdrawFeeSharesExceedBurnError) {
403
+ * console.error(error.sharesBurnt, error.feeShares);
404
+ * }
405
+ * }
406
+ * ```
407
+ */
408
+ export class VaultV2ForceWithdrawFeeSharesExceedBurnError extends Error {
409
+ /** Vault V2 address being exited. */
410
+ vault;
411
+ /** Fee-recipient account submitting the exit. */
412
+ userAddress;
413
+ /** Lower bound of shares measured as burned by VaultExitBundlesV1. */
414
+ sharesBurnt;
415
+ /** Fee shares projected for `userAddress` at the accepted deadline. */
416
+ feeShares;
417
+ /**
418
+ * @param params - Fee-share and burn-bound values that make the exit unsafe.
419
+ * @param params.vault - Vault V2 address being exited.
420
+ * @param params.userAddress - Fee-recipient account submitting the exit.
421
+ * @param params.sharesBurnt - Lower bound of shares measured as burned by VaultExitBundlesV1.
422
+ * @param params.feeShares - Fee shares projected for `userAddress` at the accepted deadline.
423
+ */
424
+ constructor(params) {
425
+ super(`Vault V2 "${params.vault}" fee-recipient account "${params.userAddress}" accrues "${params.feeShares}" fee shares, reaching the lower force-withdraw share-burn bound "${params.sharesBurnt}". VaultExitBundlesV1's share-price check would be skipped or revert. Increase exitAssets or let the vault accrue first.`);
426
+ this.vault = params.vault;
427
+ this.userAddress = params.userAddress;
428
+ this.sharesBurnt = params.sharesBurnt;
429
+ this.feeShares = params.feeShares;
430
+ this.name = "VaultV2ForceWithdrawFeeSharesExceedBurnError";
140
431
  }
141
432
  }
142
433
  /** Thrown when a Vault V2 in-kind redemption rounds to no deallocated assets. */
@@ -287,15 +578,6 @@ export class BundlesRequirementSignatureMismatchError extends Error {
287
578
  }
288
579
  /** @deprecated Use {@link BundlesRequirementSignatureMismatchError}. */
289
580
  export { BundlesRequirementSignatureMismatchError as BlueBundlesV1RequirementSignatureMismatchError, };
290
- /** Thrown when Permit2 SignatureTransfer is selected without an explicit unordered nonce. */
291
- export class MissingPermit2SignatureTransferNonceError extends Error {
292
- constructor() {
293
- super("Permit2 SignatureTransfer requires an explicit unused permit2Nonce. Generate a unique uint256 nonce, pass it to getRequirements(), and resolve the requirements again.");
294
- this.name = "MissingPermit2SignatureTransferNonceError";
295
- }
296
- }
297
- /** @deprecated Use {@link MissingPermit2SignatureTransferNonceError}. */
298
- export { MissingPermit2SignatureTransferNonceError as MissingPermit2TransferFromNonceError, };
299
581
  /** Thrown when an explicit Permit2 SignatureTransfer unordered nonce is already consumed. */
300
582
  export class Permit2SignatureTransferNonceAlreadyUsedError extends Error {
301
583
  owner;
@@ -1258,10 +1540,10 @@ export class MidnightOfferRootOfferCountMismatchError extends Error {
1258
1540
  super(`Midnight offer root offer-count mismatch: expected "${params.expectedOffers}", got "${params.actualOffers}". Rebuild the flow and sign again.`);
1259
1541
  }
1260
1542
  }
1261
- /** Thrown when a Midnight offer-root signature was not prepared by this maker flow. */
1543
+ /** Thrown when a Midnight offer-root signature carries no encoded payload. */
1262
1544
  export class UnpreparedMidnightOfferRootSignatureError extends Error {
1263
1545
  constructor() {
1264
- super("Midnight offer root signature was not prepared for this offer tree. Sign this flow's offer-root requirement before building the submit transaction.");
1546
+ super("Midnight offer root signature carries no encoded payload. Sign the offer-root requirement (its signature already includes the payload) before building the submit transaction.");
1265
1547
  }
1266
1548
  }
1267
1549
  /** Thrown when a Midnight redeem flow finds no credit units for the user. */
@@ -24,8 +24,8 @@ export interface PublicAllocatorOptions {
24
24
  * The maximum utilization each source market may reach when withdrawing
25
25
  * shared liquidity, scaled by WAD.
26
26
  *
27
- * @deprecated Per-market source ceilings will be removed in the next major.
28
- * Use `defaultMaxWithdrawalUtilization` to configure one ceiling for every source.
27
+ * @deprecated Vault V1 shared-liquidity planning will be removed in the next major.
28
+ * Use `VaultV2BluePublicAllocatorOptions.maxWithdrawalUtilization` with the Vault V2 planner.
29
29
  */
30
30
  readonly maxWithdrawalUtilization?: Readonly<Record<MarketId, bigint | undefined>>;
31
31
  /**
@@ -34,6 +34,8 @@ export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDotte
34
34
  export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
35
35
  export { computeReallocations, computeVaultV1Reallocations, } from "./helpers/computeVaultV1Reallocations.js";
36
36
  export { addTransactionMetadata } from "./helpers/metadata.js";
37
+ export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./helpers/previewVaultV2ForceWithdraw.js";
37
38
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./helpers/previewVaultV2InKindRedeem.js";
38
- export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, } from "./helpers/slippage.js";
39
+ export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, computeMinForceWithdrawSharePrice, } from "./helpers/slippage.js";
39
40
  export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./helpers/validate.js";
41
+ export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./helpers/vaultV2ForceWithdrawPlan.js";
package/lib/esm/utils.js CHANGED
@@ -32,6 +32,8 @@ TreeUtils, } from "@morpho-org/midnight-sdk";
32
32
  export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
33
33
  export { computeReallocations, computeVaultV1Reallocations, } from "./helpers/computeVaultV1Reallocations.js";
34
34
  export { addTransactionMetadata } from "./helpers/metadata.js";
35
+ export { previewVaultV2ForceWithdraw, } from "./helpers/previewVaultV2ForceWithdraw.js";
35
36
  export { previewVaultV2InKindRedeem, } from "./helpers/previewVaultV2InKindRedeem.js";
36
- export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, } from "./helpers/slippage.js";
37
+ export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, computeMinForceWithdrawSharePrice, } from "./helpers/slippage.js";
37
38
  export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./helpers/validate.js";
39
+ export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./helpers/vaultV2ForceWithdrawPlan.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/morpho-sdk",
3
3
  "description": "Abstraction layer for Morpho's complexity.",
4
- "version": "6.0.0-next.1",
4
+ "version": "6.0.0-next.2",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Foulks-Plb <https://x.com/FoulkPlb>"
@@ -162,10 +162,10 @@
162
162
  ],
163
163
  "dependencies": {
164
164
  "zod": "^4.4.3",
165
- "@morpho-org/blue-sdk": "^6.7.0",
166
- "@morpho-org/blue-sdk-viem": "^5.5.1-next.0",
167
- "@morpho-org/midnight-sdk": "^1.4.0-next.0",
168
- "@morpho-org/morpho-ts": "^2.11.1"
165
+ "@morpho-org/blue-sdk": "^6.10.0-next.0",
166
+ "@morpho-org/blue-sdk-viem": "^5.7.0",
167
+ "@morpho-org/midnight-sdk": "^1.4.0",
168
+ "@morpho-org/morpho-ts": "^2.13.0"
169
169
  },
170
170
  "peerDependencies": {
171
171
  "viem": "^2.0.0"
@@ -179,8 +179,8 @@
179
179
  "@morpho-org/test": "^2.10.0"
180
180
  },
181
181
  "scripts": {
182
- "prepublish": "$npm_execpath build",
183
- "build": "tsc --noEmit && $npm_execpath build:cjs && $npm_execpath build:esm",
182
+ "prepublish": "pnpm build",
183
+ "build": "tsc --noEmit && pnpm build:cjs && pnpm build:esm",
184
184
  "build:cjs": "tsc --build tsconfig.build.cjs.json && echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json",
185
185
  "build:esm": "tsc --build tsconfig.build.esm.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
186
186
  "test": "vitest --root ../.. --project morpho-sdk --project morpho-sdk-fork"