@morpho-org/morpho-sdk 6.0.0-next.3 → 6.0.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 (123) hide show
  1. package/MIGRATION-v5-to-v6.md +24 -16
  2. package/README.md +6 -4
  3. package/lib/cjs/abis.d.ts +5 -1
  4. package/lib/cjs/abis.js +2 -0
  5. package/lib/cjs/actions/bundles/common.d.ts +20 -25
  6. package/lib/cjs/actions/bundles/common.js +46 -85
  7. package/lib/cjs/actions/bundles/index.d.ts +1 -1
  8. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
  9. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
  10. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
  11. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
  12. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
  13. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +19 -1
  14. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
  15. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +12 -0
  16. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +2 -1
  17. package/lib/cjs/actions/vaultV1/inKindRedeem.js +2 -1
  18. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +62 -17
  19. package/lib/cjs/actions/vaultV1/migrateToV2.js +48 -17
  20. package/lib/cjs/actions/vaultV1/redeem.d.ts +28 -1
  21. package/lib/cjs/actions/vaultV1/redeem.js +17 -1
  22. package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
  23. package/lib/cjs/actions/vaultV1/withdraw.js +1 -1
  24. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +3 -2
  25. package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -2
  26. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +2 -1
  27. package/lib/cjs/actions/vaultV2/inKindRedeem.js +2 -1
  28. package/lib/cjs/actions/vaultV2/redeem.d.ts +28 -1
  29. package/lib/cjs/actions/vaultV2/redeem.js +17 -1
  30. package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
  31. package/lib/cjs/actions/vaultV2/withdraw.js +1 -1
  32. package/lib/cjs/augment/AccrualPosition.d.ts +1 -0
  33. package/lib/cjs/blue/abis.d.ts +5 -1
  34. package/lib/cjs/blue/abis.js +2 -0
  35. package/lib/cjs/blue/entities.d.ts +10 -2
  36. package/lib/cjs/blue/entities.js +2 -0
  37. package/lib/cjs/blue/errors.d.ts +4 -2
  38. package/lib/cjs/blue/errors.js +3 -1
  39. package/lib/cjs/blue/fetch.d.ts +5 -1
  40. package/lib/cjs/blue/fetch.js +2 -0
  41. package/lib/cjs/blue/utils.d.ts +5 -1
  42. package/lib/cjs/blue/utils.js +2 -0
  43. package/lib/cjs/entities/index.d.ts +10 -2
  44. package/lib/cjs/entities/index.js +2 -0
  45. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
  46. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
  47. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +31 -21
  48. package/lib/cjs/entities/vaultV1/vaultV1.js +50 -83
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +52 -35
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +71 -81
  51. package/lib/cjs/errors.d.ts +5 -3
  52. package/lib/cjs/errors.js +4 -1
  53. package/lib/cjs/fetch.d.ts +5 -1
  54. package/lib/cjs/fetch.js +2 -0
  55. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +11 -5
  56. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
  57. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +48 -15
  58. package/lib/cjs/midnight/errors.d.ts +1 -1
  59. package/lib/cjs/midnight/errors.js +2 -1
  60. package/lib/cjs/types/action.d.ts +1 -0
  61. package/lib/cjs/utils.d.ts +5 -1
  62. package/lib/cjs/utils.js +2 -0
  63. package/lib/esm/abis.d.ts +5 -1
  64. package/lib/esm/abis.js +5 -1
  65. package/lib/esm/actions/bundles/common.d.ts +20 -25
  66. package/lib/esm/actions/bundles/common.js +44 -82
  67. package/lib/esm/actions/bundles/index.d.ts +1 -1
  68. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
  69. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
  70. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
  71. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
  72. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
  73. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -3
  74. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
  75. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +14 -2
  76. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +2 -1
  77. package/lib/esm/actions/vaultV1/inKindRedeem.js +2 -1
  78. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +62 -17
  79. package/lib/esm/actions/vaultV1/migrateToV2.js +48 -17
  80. package/lib/esm/actions/vaultV1/redeem.d.ts +28 -1
  81. package/lib/esm/actions/vaultV1/redeem.js +17 -1
  82. package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
  83. package/lib/esm/actions/vaultV1/withdraw.js +1 -1
  84. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +3 -2
  85. package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -2
  86. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +2 -1
  87. package/lib/esm/actions/vaultV2/inKindRedeem.js +2 -1
  88. package/lib/esm/actions/vaultV2/redeem.d.ts +28 -1
  89. package/lib/esm/actions/vaultV2/redeem.js +17 -1
  90. package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
  91. package/lib/esm/actions/vaultV2/withdraw.js +1 -1
  92. package/lib/esm/augment/AccrualPosition.d.ts +1 -0
  93. package/lib/esm/blue/abis.d.ts +5 -1
  94. package/lib/esm/blue/abis.js +5 -1
  95. package/lib/esm/blue/entities.d.ts +10 -2
  96. package/lib/esm/blue/entities.js +5 -1
  97. package/lib/esm/blue/errors.d.ts +4 -2
  98. package/lib/esm/blue/errors.js +4 -2
  99. package/lib/esm/blue/fetch.d.ts +5 -1
  100. package/lib/esm/blue/fetch.js +5 -1
  101. package/lib/esm/blue/utils.d.ts +5 -1
  102. package/lib/esm/blue/utils.js +5 -1
  103. package/lib/esm/entities/index.d.ts +10 -2
  104. package/lib/esm/entities/index.js +5 -1
  105. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
  106. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
  107. package/lib/esm/entities/vaultV1/vaultV1.d.ts +31 -21
  108. package/lib/esm/entities/vaultV1/vaultV1.js +52 -85
  109. package/lib/esm/entities/vaultV2/vaultV2.d.ts +52 -35
  110. package/lib/esm/entities/vaultV2/vaultV2.js +73 -83
  111. package/lib/esm/errors.d.ts +5 -3
  112. package/lib/esm/errors.js +5 -3
  113. package/lib/esm/fetch.d.ts +5 -1
  114. package/lib/esm/fetch.js +5 -1
  115. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +11 -5
  116. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
  117. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +48 -15
  118. package/lib/esm/midnight/errors.d.ts +1 -1
  119. package/lib/esm/midnight/errors.js +1 -1
  120. package/lib/esm/types/action.d.ts +1 -0
  121. package/lib/esm/utils.d.ts +5 -1
  122. package/lib/esm/utils.js +5 -1
  123. package/package.json +6 -9
@@ -192,23 +192,34 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
192
192
  * The result is the **denominator of {@link computeMinForceWithdrawSharePrice}** — the largest share
193
193
  * burn the realized exit price is measured against. It takes the max over the two supplied snapshots
194
194
  * because interest lowers the burn while management fees raise it, so neither snapshot alone bounds
195
- * execution. The entity passes both accrued to `now` (execution time): the raw `lastUpdate` snapshot
196
- * underestimates the burn a stale fee-bearing vault realizes — the first withdrawal accrues pending
197
- * management fees before burning shares — which lifts the floor above the faithful price and trips
198
- * `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`, tracks execution without
199
- * letting a long deadline silently weaken the guard; `slippageTolerance` absorbs the residual drift
200
- * until inclusion. Pass distinct snapshots to bound the burn across an accrual window.
195
+ * execution. The entity passes the raw `lastUpdate` snapshot and the same vault accrued to `now`
196
+ * (execution time): the raw snapshot underestimates the burn a stale fee-bearing vault realizes —
197
+ * the first withdrawal accrues pending management fees before burning shares — while the `now`
198
+ * accrual underestimates it when it projects interest the chain has not realized (a wall clock
199
+ * running ahead of the chain, or a capped `maxRate`); either alone would lift the floor above the
200
+ * faithful price and trip `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`,
201
+ * tracks execution without letting a long deadline silently weaken the guard; `slippageTolerance`
202
+ * absorbs the residual drift until inclusion.
201
203
  *
202
- * This is **not** the share allowance to authorize. The price floor's denominator is this bound
203
- * minus `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`: the
204
- * contract measures the *net* burn, which fee mints to `owner` shrink. The allowance is
205
- * `min(mulDivUp(exitAssets, RAY, minSharePriceE27) + computeVaultV2ForceWithdrawFeeSharesMinted({
206
- * vaultData, owner, timestamp: deadline }), maxUint256)`: the permit pays for the *gross* burn.
204
+ * This is **not** the share allowance to authorize. The contract measures the *net* burn, which
205
+ * fee mints to `owner` shrink, and the raw snapshot mints none while the `now` accrual mints
206
+ * `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`; so the
207
+ * entity nets each endpoint before taking the max (`max(burnRaw, burnNow - feeSharesNow)`) rather
208
+ * than subtracting the `now` fee from a gross max. The allowance is
209
+ * `min(max(mulDivUp(exitAssets, RAY, max(min(mulDivDown(minSharePriceE27, WAD - slippageTolerance,
210
+ * WAD), minSharePriceE27 - 1), 1)), mulDivUp(exitAssets, RAY, minSharePriceE27) + 1)
211
+ * + computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: deadline }),
212
+ * maxUint256)`: the permit pays for the *gross* burn, covering a burn at least one tolerance step
213
+ * below the floor whenever the floor exceeds one RAY unit and, in any case, at least one share
214
+ * above the burn at the floor, so a price within that headroom below the floor reverts on the
215
+ * contract's `minSharePriceE27` check rather than on the allowance; a deeper drop can still
216
+ * surface as an ERC-20 allowance underflow.
207
217
  *
208
218
  * @param params - Share-bound inputs.
209
219
  * @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
210
220
  * @param params.deadlineVaultData - The same vault accrued to a second timestamp; the max of the two
211
- * share burns is returned. The entity passes the `now`-accrued snapshot for both.
221
+ * share burns is returned. The entity calls this twice — the raw snapshot for both parameters,
222
+ * then the `now` accrual for both — and nets each result before taking the max.
212
223
  * @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
213
224
  * @returns An upper bound, in vault shares, of what the exit burns.
214
225
  * @example
@@ -220,7 +231,12 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
220
231
  * } from "@morpho-org/morpho-sdk";
221
232
  *
222
233
  * const { vault: nowVaultData } = vaultData.accrueInterest(now);
223
- * const sharesBurnt = computeVaultV2ForceWithdrawSharesBurnt({
234
+ * const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
235
+ * vaultData,
236
+ * deadlineVaultData: vaultData,
237
+ * plan,
238
+ * });
239
+ * const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
224
240
  * vaultData: nowVaultData,
225
241
  * deadlineVaultData: nowVaultData,
226
242
  * plan,
@@ -230,9 +246,26 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
230
246
  * owner,
231
247
  * timestamp: now,
232
248
  * });
233
- * const sharesBurntForFloor = sharesBurnt - feeSharesNow;
249
+ * const sharesBurntForFloor = MathLib.max(
250
+ * sharesBurntRaw,
251
+ * sharesBurntNow - feeSharesNow,
252
+ * );
253
+ * const allowanceSharePriceE27 = MathLib.max(
254
+ * MathLib.min(
255
+ * MathLib.mulDivDown(
256
+ * minSharePriceE27,
257
+ * MathLib.WAD - slippageTolerance,
258
+ * MathLib.WAD,
259
+ * ),
260
+ * minSharePriceE27 - 1n,
261
+ * ),
262
+ * 1n,
263
+ * );
234
264
  * const requiredShareAllowance = MathLib.min(
235
- * MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) +
265
+ * MathLib.max(
266
+ * MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27),
267
+ * MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n,
268
+ * ) +
236
269
  * computeVaultV2ForceWithdrawFeeSharesMinted({
237
270
  * vaultData,
238
271
  * owner,
@@ -269,23 +269,34 @@ function computeVaultV2ForceWithdrawPlan(params) {
269
269
  * The result is the **denominator of {@link computeMinForceWithdrawSharePrice}** — the largest share
270
270
  * burn the realized exit price is measured against. It takes the max over the two supplied snapshots
271
271
  * because interest lowers the burn while management fees raise it, so neither snapshot alone bounds
272
- * execution. The entity passes both accrued to `now` (execution time): the raw `lastUpdate` snapshot
273
- * underestimates the burn a stale fee-bearing vault realizes — the first withdrawal accrues pending
274
- * management fees before burning shares — which lifts the floor above the faithful price and trips
275
- * `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`, tracks execution without
276
- * letting a long deadline silently weaken the guard; `slippageTolerance` absorbs the residual drift
277
- * until inclusion. Pass distinct snapshots to bound the burn across an accrual window.
272
+ * execution. The entity passes the raw `lastUpdate` snapshot and the same vault accrued to `now`
273
+ * (execution time): the raw snapshot underestimates the burn a stale fee-bearing vault realizes —
274
+ * the first withdrawal accrues pending management fees before burning shares — while the `now`
275
+ * accrual underestimates it when it projects interest the chain has not realized (a wall clock
276
+ * running ahead of the chain, or a capped `maxRate`); either alone would lift the floor above the
277
+ * faithful price and trip `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`,
278
+ * tracks execution without letting a long deadline silently weaken the guard; `slippageTolerance`
279
+ * absorbs the residual drift until inclusion.
278
280
  *
279
- * This is **not** the share allowance to authorize. The price floor's denominator is this bound
280
- * minus `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`: the
281
- * contract measures the *net* burn, which fee mints to `owner` shrink. The allowance is
282
- * `min(mulDivUp(exitAssets, RAY, minSharePriceE27) + computeVaultV2ForceWithdrawFeeSharesMinted({
283
- * vaultData, owner, timestamp: deadline }), maxUint256)`: the permit pays for the *gross* burn.
281
+ * This is **not** the share allowance to authorize. The contract measures the *net* burn, which
282
+ * fee mints to `owner` shrink, and the raw snapshot mints none while the `now` accrual mints
283
+ * `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`; so the
284
+ * entity nets each endpoint before taking the max (`max(burnRaw, burnNow - feeSharesNow)`) rather
285
+ * than subtracting the `now` fee from a gross max. The allowance is
286
+ * `min(max(mulDivUp(exitAssets, RAY, max(min(mulDivDown(minSharePriceE27, WAD - slippageTolerance,
287
+ * WAD), minSharePriceE27 - 1), 1)), mulDivUp(exitAssets, RAY, minSharePriceE27) + 1)
288
+ * + computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: deadline }),
289
+ * maxUint256)`: the permit pays for the *gross* burn, covering a burn at least one tolerance step
290
+ * below the floor whenever the floor exceeds one RAY unit and, in any case, at least one share
291
+ * above the burn at the floor, so a price within that headroom below the floor reverts on the
292
+ * contract's `minSharePriceE27` check rather than on the allowance; a deeper drop can still
293
+ * surface as an ERC-20 allowance underflow.
284
294
  *
285
295
  * @param params - Share-bound inputs.
286
296
  * @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
287
297
  * @param params.deadlineVaultData - The same vault accrued to a second timestamp; the max of the two
288
- * share burns is returned. The entity passes the `now`-accrued snapshot for both.
298
+ * share burns is returned. The entity calls this twice — the raw snapshot for both parameters,
299
+ * then the `now` accrual for both — and nets each result before taking the max.
289
300
  * @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
290
301
  * @returns An upper bound, in vault shares, of what the exit burns.
291
302
  * @example
@@ -297,7 +308,12 @@ function computeVaultV2ForceWithdrawPlan(params) {
297
308
  * } from "@morpho-org/morpho-sdk";
298
309
  *
299
310
  * const { vault: nowVaultData } = vaultData.accrueInterest(now);
300
- * const sharesBurnt = computeVaultV2ForceWithdrawSharesBurnt({
311
+ * const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
312
+ * vaultData,
313
+ * deadlineVaultData: vaultData,
314
+ * plan,
315
+ * });
316
+ * const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
301
317
  * vaultData: nowVaultData,
302
318
  * deadlineVaultData: nowVaultData,
303
319
  * plan,
@@ -307,9 +323,26 @@ function computeVaultV2ForceWithdrawPlan(params) {
307
323
  * owner,
308
324
  * timestamp: now,
309
325
  * });
310
- * const sharesBurntForFloor = sharesBurnt - feeSharesNow;
326
+ * const sharesBurntForFloor = MathLib.max(
327
+ * sharesBurntRaw,
328
+ * sharesBurntNow - feeSharesNow,
329
+ * );
330
+ * const allowanceSharePriceE27 = MathLib.max(
331
+ * MathLib.min(
332
+ * MathLib.mulDivDown(
333
+ * minSharePriceE27,
334
+ * MathLib.WAD - slippageTolerance,
335
+ * MathLib.WAD,
336
+ * ),
337
+ * minSharePriceE27 - 1n,
338
+ * ),
339
+ * 1n,
340
+ * );
311
341
  * const requiredShareAllowance = MathLib.min(
312
- * MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) +
342
+ * MathLib.max(
343
+ * MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27),
344
+ * MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n,
345
+ * ) +
313
346
  * computeVaultV2ForceWithdrawFeeSharesMinted({
314
347
  * vaultData,
315
348
  * owner,
@@ -1 +1 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.ChainIdMismatchError = void 0;
3
+ exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.ChainIdMismatchError = void 0;
4
4
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  Object.defineProperty(exports, "ChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
6
6
  Object.defineProperty(exports, "InvalidEcrecoverSignatureVError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureVError; } });
7
7
  Object.defineProperty(exports, "InvalidMarketParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMarketParameterError; } });
8
+ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiQuoteTargetError; } });
8
9
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
9
10
  Object.defineProperty(exports, "InvalidOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
10
11
  Object.defineProperty(exports, "InvalidOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
@@ -482,6 +482,7 @@ export interface MidnightOfferRootSignatureArgs {
482
482
  }
483
483
  /** EIP-712 payload carried by a signable requirement action. */
484
484
  export type RequirementTypedData = TypedDataDefinition<Record<string, unknown>, string>;
485
+ /** Signable ERC-2612 permit requirement for a fixed-bundles token pull. */
485
486
  export interface PermitAction extends BaseAction<"permit", {
486
487
  readonly spender: Address;
487
488
  readonly amount: bigint;
@@ -1,5 +1,9 @@
1
1
  export type { CapacityLimit, RoundingDirection } from "@morpho-org/blue-sdk";
2
- export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason, defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry, getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
2
+ export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
3
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
+ defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
5
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
+ getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
3
7
  export { decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
4
8
  export { EcrecoverRatifierUtils as MidnightEcrecoverRatifierUtils, eip712Digest, GroupUtils as MidnightGroupUtils, MarketUtils as MidnightMarketUtils, OfferChainUtils as MidnightOfferChainUtils, OfferUtils as MidnightOfferUtils, Payload as MidnightPayload, PositionUtils as MidnightPositionUtils, RatifierUtils as MidnightRatifierUtils, SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
5
9
  export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, } from "@morpho-org/morpho-ts";
package/lib/cjs/utils.js CHANGED
@@ -5,7 +5,9 @@ exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWith
5
5
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  Object.defineProperty(exports, "BlueAdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
7
7
  Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
8
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
8
9
  Object.defineProperty(exports, "blueDefaultPreLiquidationParamsRegistry", { enumerable: true, get: function () { return blue_sdk_1.defaultPreLiquidationParamsRegistry; } });
10
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
9
11
  Object.defineProperty(exports, "getBlueDefaultPreLiquidationParams", { enumerable: true, get: function () { return blue_sdk_1.getDefaultPreLiquidationParams; } });
10
12
  Object.defineProperty(exports, "BlueMarketUtils", { enumerable: true, get: function () { return blue_sdk_1.MarketUtils; } });
11
13
  Object.defineProperty(exports, "MathLib", { enumerable: true, get: function () { return blue_sdk_1.MathLib; } });
package/lib/esm/abis.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
2
- export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi, preLiquidationAbi as bluePreLiquidationAbi, preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
2
+ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
3
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
+ preLiquidationAbi as bluePreLiquidationAbi,
5
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
+ preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
3
7
  export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
4
8
  /** ABI for the VaultExitBundlesV1 periphery contract. */
5
9
  export declare const vaultExitBundlesV1Abi: readonly [{
package/lib/esm/abis.js CHANGED
@@ -1,5 +1,9 @@
1
1
  export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
2
- export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi, preLiquidationAbi as bluePreLiquidationAbi, preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
2
+ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
3
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
+ preLiquidationAbi as bluePreLiquidationAbi,
5
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
+ preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
3
7
  export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
4
8
  /** ABI for the VaultExitBundlesV1 periphery contract. */
5
9
  export const vaultExitBundlesV1Abi = [
@@ -1,5 +1,5 @@
1
1
  import { type Address, type Hex } from "viem";
2
- import { type BaseAction, type BundlesFundingArgs, type BundlesTokenRequirementSignature, type Erc2612RequirementSignature, type Metadata, type Permit2SignatureTransferAction, type PermitAction, type PermitRequirementSignature, type RequirementSignature, type TokenRequirementSignature, type Transaction } from "../../types/index.js";
2
+ import { type BaseAction, type BundlesFundingArgs, type BundlesTokenRequirementSignature, type Erc2612RequirementSignature, type Metadata, type PermitRequirementSignature, type RequirementSignature, type TokenRequirementSignature, type Transaction } from "../../types/index.js";
3
3
  /** Numeric permit kinds consumed by `TokenLib.pullToken`. */
4
4
  export declare const BundlesPermitKind: {
5
5
  readonly None: 0;
@@ -30,8 +30,6 @@ export interface BundleSharesPermit {
30
30
  /** ECDSA signature `s`, or zero for the empty sentinel. */
31
31
  readonly s: Hex;
32
32
  }
33
- /** Compatibility alias for the canonical {@link BundleSharesPermit} tuple. */
34
- export type BundlesSharesPermit = BundleSharesPermit;
35
33
  /** Common deadline and referral fields shared by fixed bundles calls. */
36
34
  export interface BundlesCommonParams {
37
35
  /** Contract execution deadline. */
@@ -156,8 +154,8 @@ export declare const normalizeBundlesSignature: (serializedSignature: Hex, onInv
156
154
  * @returns The signed share permit or the contract's empty-permit sentinel.
157
155
  * @throws {NonPositiveInputError} when a bundle or permit deadline is not positive.
158
156
  * @throws {InputExceedsMaxError} when a bundle or permit deadline exceeds uint256.
159
- * @throws {BundlesPermitMismatchError} when the requirement kind, token, owner, spender, amount or
160
- * deadline, or signature is invalid.
157
+ * @throws {BundlesPermitMismatchError} when the requirement kind, token, owner, spender, amount,
158
+ * deadline or a supplied action nonce, or signature is invalid.
161
159
  * @example
162
160
  * ```ts
163
161
  * import { getBundlesSharesPermit } from "@morpho-org/morpho-sdk";
@@ -184,27 +182,21 @@ export declare const getBundlesSharesPermit: (params: {
184
182
  * @internal
185
183
  *
186
184
  * @param signatures - Signatures passed to `buildTx`.
187
- * @param expectedRequirement - Signature requirement captured by this prepared operation.
185
+ * @param expected - Immutable spender, amount, and deadline required by the operation.
186
+ * @param expected.spender - Fixed bundles contract the signature must authorize.
187
+ * @param expected.amount - Exact pull amount the signature must cover.
188
+ * @param expected.deadline - Deadline the signature must carry.
188
189
  * @returns The selected ERC-2612 or Permit2 SignatureTransfer signature.
189
190
  * @throws {UnexpectedRequirementSignatureError} when a non-token signature is supplied.
190
191
  * @throws {AmbiguousRequirementSignaturesError} when both token signature kinds are supplied.
192
+ * @throws {BundlesPermitMismatchError} when the signature's spender, amount, or deadline differ
193
+ * from the operation's, or when a carried action nonce is inconsistent with the signed nonce.
191
194
  */
192
- export declare const selectBundlesTokenRequirementSignature: (signatures: readonly RequirementSignature[] | undefined, expectedRequirement?: PermitAction | Permit2SignatureTransferAction) => BundlesTokenRequirementSignature | undefined;
193
- /**
194
- * Selects the exact ERC-2612 vault-share permit produced for one prepared exit.
195
- *
196
- * @internal
197
- *
198
- * @param signatures - Signatures passed to the prepared operation's `buildTx` function.
199
- * @param prepared - Exact share cap and permit requirement captured by this prepared operation.
200
- * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
201
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, was built for another
202
- * share cap, or is supplied before this operation resolves its share cap.
203
- */
204
- export declare const selectBundlesSharesRequirementSignature: (signatures: readonly RequirementSignature[] | undefined, prepared: {
205
- readonly requiredShareAllowance: bigint | undefined;
206
- readonly expectedRequirement?: PermitAction;
207
- }) => Erc2612RequirementSignature | undefined;
195
+ export declare const selectBundlesTokenRequirementSignature: (signatures: readonly RequirementSignature[] | undefined, expected: {
196
+ readonly spender: Address;
197
+ readonly amount: bigint;
198
+ readonly deadline: bigint;
199
+ }) => BundlesTokenRequirementSignature | undefined;
208
200
  /**
209
201
  * Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
210
202
  *
@@ -212,10 +204,13 @@ export declare const selectBundlesSharesRequirementSignature: (signatures: reado
212
204
  *
213
205
  * @param signatures - Signatures passed to the operation's `buildTx` function.
214
206
  * @param expected - Immutable spender, amount, and deadline required by the operation.
207
+ * @param expected.spender - Fixed bundles contract the permit must authorize.
208
+ * @param expected.amount - Exact share allowance the permit must cover.
209
+ * @param expected.deadline - Deadline the permit must carry.
215
210
  * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
216
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
217
- * deadline differ from the operation's. The nonce is not checked here: it is onchain state the
218
- * vault's `permit` verifies at execution.
211
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount
212
+ * or deadline differ from the operation's. The nonce is not checked here: it is onchain state
213
+ * the vault's `permit` verifies at execution.
219
214
  */
220
215
  export declare const selectBundlesSharesPermitSignature: (signatures: readonly RequirementSignature[] | undefined, expected: {
221
216
  readonly spender: Address;
@@ -228,8 +228,8 @@ export const normalizeBundlesSignature = (serializedSignature, onInvalid = (deta
228
228
  * @returns The signed share permit or the contract's empty-permit sentinel.
229
229
  * @throws {NonPositiveInputError} when a bundle or permit deadline is not positive.
230
230
  * @throws {InputExceedsMaxError} when a bundle or permit deadline exceeds uint256.
231
- * @throws {BundlesPermitMismatchError} when the requirement kind, token, owner, spender, amount or
232
- * deadline, or signature is invalid.
231
+ * @throws {BundlesPermitMismatchError} when the requirement kind, token, owner, spender, amount,
232
+ * deadline or a supplied action nonce, or signature is invalid.
233
233
  * @example
234
234
  * ```ts
235
235
  * import { getBundlesSharesPermit } from "@morpho-org/morpho-sdk";
@@ -316,6 +316,14 @@ export const getBundlesSharesPermit = (params) => {
316
316
  actual: String(requirementSignature.action.args.deadline),
317
317
  });
318
318
  }
319
+ if (requirementSignature.action.args.nonce != null &&
320
+ requirementSignature.action.args.nonce !== requirementSignature.args.nonce) {
321
+ throw new BundlesPermitMismatchError({
322
+ field: "nonce",
323
+ expected: String(requirementSignature.args.nonce),
324
+ actual: String(requirementSignature.action.args.nonce),
325
+ });
326
+ }
319
327
  const signature = normalizeBundlesSignature(requirementSignature.args.signature);
320
328
  return {
321
329
  value: requirementSignature.args.amount,
@@ -330,12 +338,17 @@ export const getBundlesSharesPermit = (params) => {
330
338
  * @internal
331
339
  *
332
340
  * @param signatures - Signatures passed to `buildTx`.
333
- * @param expectedRequirement - Signature requirement captured by this prepared operation.
341
+ * @param expected - Immutable spender, amount, and deadline required by the operation.
342
+ * @param expected.spender - Fixed bundles contract the signature must authorize.
343
+ * @param expected.amount - Exact pull amount the signature must cover.
344
+ * @param expected.deadline - Deadline the signature must carry.
334
345
  * @returns The selected ERC-2612 or Permit2 SignatureTransfer signature.
335
346
  * @throws {UnexpectedRequirementSignatureError} when a non-token signature is supplied.
336
347
  * @throws {AmbiguousRequirementSignaturesError} when both token signature kinds are supplied.
348
+ * @throws {BundlesPermitMismatchError} when the signature's spender, amount, or deadline differ
349
+ * from the operation's, or when a carried action nonce is inconsistent with the signed nonce.
337
350
  */
338
- export const selectBundlesTokenRequirementSignature = (signatures, expectedRequirement) => {
351
+ export const selectBundlesTokenRequirementSignature = (signatures, expected) => {
339
352
  if (signatures == null || signatures.length === 0)
340
353
  return undefined;
341
354
  const selected = signatures.filter((signature) => signature.action.type === "permit" ||
@@ -355,97 +368,43 @@ export const selectBundlesTokenRequirementSignature = (signatures, expectedRequi
355
368
  const selectedSignature = selected[0];
356
369
  if (selectedSignature == null)
357
370
  return undefined;
358
- validatePreparedBundlesRequirementSignature(selectedSignature, expectedRequirement);
359
- return selectedSignature;
360
- };
361
- const validatePreparedBundlesRequirementSignature = (signature, expectedRequirement) => {
362
- if (expectedRequirement == null) {
363
- throw new BundlesPermitMismatchError({
364
- field: "nonce",
365
- expected: "the nonce from getRequirements()",
366
- actual: String(signature.args.nonce),
367
- });
368
- }
369
- if (signature.action.type !== expectedRequirement.type) {
370
- throw new BundlesPermitMismatchError({
371
- field: "type",
372
- expected: expectedRequirement.type,
373
- actual: signature.action.type,
374
- });
375
- }
376
- const expectedArgs = expectedRequirement.args;
377
- if (!isAddressEqual(signature.action.args.spender, expectedArgs.spender)) {
371
+ const { action } = selectedSignature;
372
+ if (!isAddressEqual(action.args.spender, expected.spender)) {
378
373
  throw new BundlesPermitMismatchError({
379
374
  field: "spender",
380
- expected: expectedArgs.spender,
381
- actual: signature.action.args.spender,
375
+ expected: expected.spender,
376
+ actual: action.args.spender,
382
377
  });
383
378
  }
384
- if (signature.args.amount !== expectedArgs.amount ||
385
- signature.action.args.amount !== expectedArgs.amount) {
379
+ if (selectedSignature.args.amount !== expected.amount ||
380
+ action.args.amount !== expected.amount) {
386
381
  throw new BundlesPermitMismatchError({
387
382
  field: "amount",
388
- expected: String(expectedArgs.amount),
389
- actual: String(signature.args.amount),
383
+ expected: String(expected.amount),
384
+ actual: String(selectedSignature.args.amount !== expected.amount
385
+ ? selectedSignature.args.amount
386
+ : action.args.amount),
390
387
  });
391
388
  }
392
- if (signature.args.deadline !== expectedArgs.deadline ||
393
- signature.action.args.deadline !== expectedArgs.deadline) {
389
+ if (selectedSignature.args.deadline !== expected.deadline ||
390
+ action.args.deadline !== expected.deadline) {
394
391
  throw new BundlesPermitMismatchError({
395
392
  field: "deadline",
396
- expected: String(expectedArgs.deadline),
397
- actual: String(signature.args.deadline),
393
+ expected: String(expected.deadline),
394
+ actual: String(selectedSignature.args.deadline !== expected.deadline
395
+ ? selectedSignature.args.deadline
396
+ : action.args.deadline),
398
397
  });
399
398
  }
400
- if (expectedArgs.nonce == null ||
401
- signature.args.nonce !== expectedArgs.nonce ||
402
- signature.action.args.nonce !== expectedArgs.nonce) {
399
+ if (action.args.nonce != null &&
400
+ action.args.nonce !== selectedSignature.args.nonce) {
403
401
  throw new BundlesPermitMismatchError({
404
402
  field: "nonce",
405
- expected: expectedArgs.nonce == null
406
- ? "the nonce from getRequirements()"
407
- : String(expectedArgs.nonce),
408
- actual: String(signature.args.nonce),
403
+ expected: String(selectedSignature.args.nonce),
404
+ actual: String(action.args.nonce),
409
405
  });
410
406
  }
411
- };
412
- /**
413
- * Selects the exact ERC-2612 vault-share permit produced for one prepared exit.
414
- *
415
- * @internal
416
- *
417
- * @param signatures - Signatures passed to the prepared operation's `buildTx` function.
418
- * @param prepared - Exact share cap and permit requirement captured by this prepared operation.
419
- * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
420
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, was built for another
421
- * share cap, or is supplied before this operation resolves its share cap.
422
- */
423
- export const selectBundlesSharesRequirementSignature = (signatures, prepared) => {
424
- const { permit } = selectRequirementSignatures(signatures, { permit: true });
425
- if (permit == null)
426
- return undefined;
427
- const { action } = permit;
428
- if (action.type !== "permit") {
429
- throw new BundlesPermitMismatchError({
430
- field: "type",
431
- expected: "permit",
432
- actual: action.type,
433
- });
434
- }
435
- if (prepared.requiredShareAllowance == null ||
436
- permit.args.amount !== prepared.requiredShareAllowance ||
437
- action.args.amount !== prepared.requiredShareAllowance) {
438
- throw new BundlesPermitMismatchError({
439
- field: "amount",
440
- expected: prepared.requiredShareAllowance == null
441
- ? "the current cap from getRequirements()"
442
- : String(prepared.requiredShareAllowance),
443
- actual: String(permit.args.amount),
444
- });
445
- }
446
- const selectedPermit = { args: permit.args, action };
447
- validatePreparedBundlesRequirementSignature(selectedPermit, prepared.expectedRequirement);
448
- return selectedPermit;
407
+ return selectedSignature;
449
408
  };
450
409
  /**
451
410
  * Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
@@ -454,10 +413,13 @@ export const selectBundlesSharesRequirementSignature = (signatures, prepared) =>
454
413
  *
455
414
  * @param signatures - Signatures passed to the operation's `buildTx` function.
456
415
  * @param expected - Immutable spender, amount, and deadline required by the operation.
416
+ * @param expected.spender - Fixed bundles contract the permit must authorize.
417
+ * @param expected.amount - Exact share allowance the permit must cover.
418
+ * @param expected.deadline - Deadline the permit must carry.
457
419
  * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
458
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
459
- * deadline differ from the operation's. The nonce is not checked here: it is onchain state the
460
- * vault's `permit` verifies at execution.
420
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount
421
+ * or deadline differ from the operation's. The nonce is not checked here: it is onchain state
422
+ * the vault's `permit` verifies at execution.
461
423
  */
462
424
  export const selectBundlesSharesPermitSignature = (signatures, expected) => {
463
425
  const { permit } = selectRequirementSignatures(signatures, { permit: true });
@@ -1,3 +1,3 @@
1
- export type { BundleSharesPermit, BundlesCommonParams, BundlesSharesPermit, BundlesTokenPermit, NormalizedBundlesCommonParams, } from "./common.js";
1
+ export type { BundleSharesPermit, BundlesCommonParams, BundlesTokenPermit, NormalizedBundlesCommonParams, } from "./common.js";
2
2
  export { BundlesPermitKind, getBundlesSharesPermit, getBundlesTokenPermit, resolveBundlesFunding, } from "./common.js";
3
3
  export * from "./resolveBundlesTokenRequirements.js";
@@ -30,7 +30,8 @@ export type BundlesTokenRequirementsState = {
30
30
  * @param params.owner - Account funding the operation and owning the Permit2 nonce bitmap.
31
31
  * @param params.chainId - Target chain id used to resolve supported approval spenders and canonical Permit2.
32
32
  * @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
33
- * @param params.deadline - Signature expiration as a Unix timestamp in seconds.
33
+ * @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
34
+ * SignatureTransfer branch it must be positive, within uint256, and in the future.
34
35
  * @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
35
36
  * @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
36
37
  * @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
@@ -43,10 +44,13 @@ export type BundlesTokenRequirementsState = {
43
44
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
44
45
  * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
45
46
  * @throws {NegativeInputError} when an amount or Permit2 nonce is negative.
46
- * @throws {InputExceedsMaxError} when `amount` or the Permit2 nonce exceeds uint256.
47
+ * @throws {InputExceedsMaxError} when `amount`, the Permit2 nonce, or the SignatureTransfer
48
+ * `deadline` exceeds uint256.
47
49
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
48
50
  * @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
49
51
  * @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
52
+ * @throws {NonPositiveInputError} when the SignatureTransfer `deadline` is not positive.
53
+ * @throws {ExpiredDeadlineError} when the SignatureTransfer `deadline` is positive but not in the future.
50
54
  * @example
51
55
  * ```ts
52
56
  * import { resolveBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
@@ -22,7 +22,8 @@ import { getRequirementsApproval } from "../requirements/getRequirementsApproval
22
22
  * @param params.owner - Account funding the operation and owning the Permit2 nonce bitmap.
23
23
  * @param params.chainId - Target chain id used to resolve supported approval spenders and canonical Permit2.
24
24
  * @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
25
- * @param params.deadline - Signature expiration as a Unix timestamp in seconds.
25
+ * @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
26
+ * SignatureTransfer branch it must be positive, within uint256, and in the future.
26
27
  * @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
27
28
  * @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
28
29
  * @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
@@ -35,10 +36,13 @@ import { getRequirementsApproval } from "../requirements/getRequirementsApproval
35
36
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
36
37
  * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
37
38
  * @throws {NegativeInputError} when an amount or Permit2 nonce is negative.
38
- * @throws {InputExceedsMaxError} when `amount` or the Permit2 nonce exceeds uint256.
39
+ * @throws {InputExceedsMaxError} when `amount`, the Permit2 nonce, or the SignatureTransfer
40
+ * `deadline` exceeds uint256.
39
41
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
40
42
  * @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
41
43
  * @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
44
+ * @throws {NonPositiveInputError} when the SignatureTransfer `deadline` is not positive.
45
+ * @throws {ExpiredDeadlineError} when the SignatureTransfer `deadline` is positive but not in the future.
42
46
  * @example
43
47
  * ```ts
44
48
  * import { resolveBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
@@ -30,6 +30,7 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
30
30
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
31
31
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
32
32
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
33
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered on the target chain.
33
34
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
34
35
  * @example
35
36
  * ```ts
@@ -34,6 +34,7 @@ import { encodeBlueSignatureAuthorization } from "../encode/encodeBlueSignatureA
34
34
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
35
35
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
36
36
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
37
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered on the target chain.
37
38
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
38
39
  * @example
39
40
  * ```ts