@morpho-org/morpho-sdk 4.1.0 → 5.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 (178) hide show
  1. package/README.md +12 -12
  2. package/lib/cjs/actions/blue/borrow.d.ts +12 -2
  3. package/lib/cjs/actions/blue/borrow.js +7 -1
  4. package/lib/cjs/actions/blue/refinance.d.ts +13 -3
  5. package/lib/cjs/actions/blue/refinance.js +8 -2
  6. package/lib/cjs/actions/blue/repay.d.ts +6 -5
  7. package/lib/cjs/actions/blue/repay.js +10 -18
  8. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +15 -6
  9. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +16 -18
  10. package/lib/cjs/actions/blue/supply.d.ts +7 -7
  11. package/lib/cjs/actions/blue/supply.js +10 -20
  12. package/lib/cjs/actions/blue/supplyCollateral.d.ts +8 -8
  13. package/lib/cjs/actions/blue/supplyCollateral.js +11 -21
  14. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +18 -6
  15. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -19
  16. package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
  17. package/lib/cjs/actions/blue/withdraw.js +7 -1
  18. package/lib/cjs/actions/index.d.ts +1 -0
  19. package/lib/cjs/actions/index.js +1 -0
  20. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  21. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
  22. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
  23. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  24. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  25. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
  26. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
  30. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  31. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
  32. package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
  33. package/lib/cjs/actions/requirements/encode/index.js +2 -1
  34. package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  35. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
  36. package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  37. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
  38. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  39. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
  40. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
  41. package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
  42. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
  43. package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
  44. package/lib/cjs/actions/requirements/index.d.ts +2 -5
  45. package/lib/cjs/actions/requirements/index.js +2 -5
  46. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  47. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
  48. package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  49. package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
  50. package/lib/cjs/actions/signatures/index.d.ts +2 -0
  51. package/lib/cjs/actions/signatures/index.js +18 -0
  52. package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
  53. package/lib/cjs/actions/vaultV1/deposit.js +11 -21
  54. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
  55. package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
  56. package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
  57. package/lib/cjs/actions/vaultV2/deposit.js +11 -21
  58. package/lib/cjs/addresses.d.ts +2 -2
  59. package/lib/cjs/addresses.js +2 -1
  60. package/lib/cjs/bundler/actions.d.ts +44 -4
  61. package/lib/cjs/bundler/actions.js +75 -2
  62. package/lib/cjs/bundler/types.d.ts +6 -0
  63. package/lib/cjs/constants.d.ts +2 -2
  64. package/lib/cjs/constants.js +3 -3
  65. package/lib/cjs/entities/blue/blue.d.ts +58 -33
  66. package/lib/cjs/entities/blue/blue.js +171 -125
  67. package/lib/cjs/entities/reallocationData.d.ts +12 -12
  68. package/lib/cjs/entities/reallocationData.js +19 -19
  69. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
  70. package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
  71. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
  72. package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
  73. package/lib/cjs/errors.d.ts +3 -2
  74. package/lib/cjs/errors.js +5 -2
  75. package/lib/cjs/helpers/validate.d.ts +2 -2
  76. package/lib/cjs/helpers/validate.js +1 -1
  77. package/lib/cjs/types/action.d.ts +113 -9
  78. package/lib/cjs/types/action.js +79 -5
  79. package/lib/cjs/types/error.d.ts +73 -0
  80. package/lib/cjs/types/error.js +89 -4
  81. package/lib/cjs/types.d.ts +2 -1
  82. package/lib/cjs/utils.d.ts +1 -1
  83. package/lib/cjs/utils.js +2 -3
  84. package/lib/esm/actions/blue/borrow.d.ts +12 -2
  85. package/lib/esm/actions/blue/borrow.js +7 -1
  86. package/lib/esm/actions/blue/refinance.d.ts +13 -3
  87. package/lib/esm/actions/blue/refinance.js +8 -2
  88. package/lib/esm/actions/blue/repay.d.ts +6 -5
  89. package/lib/esm/actions/blue/repay.js +10 -18
  90. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +15 -6
  91. package/lib/esm/actions/blue/repayWithdrawCollateral.js +16 -18
  92. package/lib/esm/actions/blue/supply.d.ts +7 -7
  93. package/lib/esm/actions/blue/supply.js +10 -20
  94. package/lib/esm/actions/blue/supplyCollateral.d.ts +8 -8
  95. package/lib/esm/actions/blue/supplyCollateral.js +11 -21
  96. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +18 -6
  97. package/lib/esm/actions/blue/supplyCollateralBorrow.js +17 -19
  98. package/lib/esm/actions/blue/withdraw.d.ts +10 -2
  99. package/lib/esm/actions/blue/withdraw.js +7 -1
  100. package/lib/esm/actions/index.d.ts +1 -0
  101. package/lib/esm/actions/index.js +1 -0
  102. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  103. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
  104. package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
  105. package/lib/esm/actions/requirements/blue/index.js +1 -0
  106. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  107. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
  108. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  109. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
  110. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  111. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
  112. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  113. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
  114. package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
  115. package/lib/esm/actions/requirements/encode/index.js +2 -1
  116. package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  117. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
  118. package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  119. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
  120. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  121. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
  122. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
  123. package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
  124. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
  125. package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
  126. package/lib/esm/actions/requirements/index.d.ts +2 -5
  127. package/lib/esm/actions/requirements/index.js +2 -5
  128. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  129. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
  130. package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  131. package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
  132. package/lib/esm/actions/signatures/index.d.ts +2 -0
  133. package/lib/esm/actions/signatures/index.js +2 -0
  134. package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
  135. package/lib/esm/actions/vaultV1/deposit.js +11 -21
  136. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
  137. package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
  138. package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
  139. package/lib/esm/actions/vaultV2/deposit.js +11 -21
  140. package/lib/esm/addresses.d.ts +2 -2
  141. package/lib/esm/addresses.js +1 -1
  142. package/lib/esm/bundler/actions.d.ts +44 -4
  143. package/lib/esm/bundler/actions.js +77 -4
  144. package/lib/esm/bundler/types.d.ts +6 -0
  145. package/lib/esm/constants.d.ts +2 -2
  146. package/lib/esm/constants.js +2 -2
  147. package/lib/esm/entities/blue/blue.d.ts +58 -33
  148. package/lib/esm/entities/blue/blue.js +173 -127
  149. package/lib/esm/entities/reallocationData.d.ts +12 -12
  150. package/lib/esm/entities/reallocationData.js +18 -18
  151. package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
  152. package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
  153. package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
  154. package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
  155. package/lib/esm/errors.d.ts +3 -2
  156. package/lib/esm/errors.js +2 -1
  157. package/lib/esm/helpers/validate.d.ts +2 -2
  158. package/lib/esm/helpers/validate.js +1 -1
  159. package/lib/esm/types/action.d.ts +113 -9
  160. package/lib/esm/types/action.js +75 -4
  161. package/lib/esm/types/error.d.ts +73 -0
  162. package/lib/esm/types/error.js +84 -2
  163. package/lib/esm/types.d.ts +2 -1
  164. package/lib/esm/utils.d.ts +1 -1
  165. package/lib/esm/utils.js +1 -1
  166. package/package.json +6 -6
  167. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  168. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
  169. package/lib/cjs/actions/requirements/getRequirements.js +0 -112
  170. package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
  171. package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  172. package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
  173. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  174. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
  175. package/lib/esm/actions/requirements/getRequirements.js +0 -108
  176. package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
  177. package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  178. package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
@@ -200,28 +200,28 @@ export declare class ReallocationData implements InputReallocationData {
200
200
  */
201
201
  getPublicReallocationLiquidity(marketId: MarketId, options?: PublicAllocatorOptions): bigint;
202
202
  /**
203
- * Computes the liquidity available to bring `marketId` to `targetUtilization`,
203
+ * Computes the liquidity available to bring `marketId` to `utilization`,
204
204
  * counting the public-allocator liquidity reallocatable into it.
205
205
  *
206
206
  * Returns the max borrow `x` keeping post-borrow utilization
207
- * `(borrow + x) / (supply + L) ≤ targetUtilization`, where `L` is the
207
+ * `(borrow + x) / (supply + L) ≤ utilization`, where `L` is the
208
208
  * reallocatable liquidity added to the market's supply — equivalently
209
- * `getBorrowToUtilization({ supply + L, borrow }, targetUtilization)`. Below
210
- * the target this is the market's own borrow headroom plus `targetUtilization · L`;
209
+ * `getBorrowToUtilization({ supply + L, borrow }, utilization)`. Below
210
+ * `utilization` this is the market's own borrow headroom plus `utilization · L`;
211
211
  * reallocated supply also raises the supply denominator, so only that scaled
212
212
  * share backs further borrow.
213
213
  *
214
214
  * Read-only metric — never throws on insufficiency:
215
215
  * - returns only the market's own borrow headroom when
216
- * `supplyTargetUtilization > targetUtilization` (reallocation would not
217
- * trigger at that target);
218
- * - returns `0n` when the market is already at or above the target and `L` is
219
- * too small to bring it back under.
216
+ * `supplyTargetUtilization > utilization` (reallocation would not
217
+ * trigger at that utilization);
218
+ * - returns `0n` when the market is already at or above `utilization` and `L`
219
+ * is too small to bring it back under.
220
220
  *
221
221
  * @param marketId - Target market to borrow from.
222
- * @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
222
+ * @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
223
223
  * @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
224
- * @returns Available liquidity to the target utilization in loan-token units; `0n` when none is available.
224
+ * @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
225
225
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
226
226
  * @example
227
227
  * ```ts
@@ -245,14 +245,14 @@ export declare class ReallocationData implements InputReallocationData {
245
245
  *
246
246
  * // Max borrow keeping utilization at or below 90%, counting shared liquidity.
247
247
  * const available: bigint =
248
- * reallocationData.getAvailableLiquidityToTargetUtilization(
248
+ * reallocationData.getAvailableLiquidityToUtilization(
249
249
  * marketParams.id,
250
250
  * parseEther("0.9"),
251
251
  * { timestamp: block.timestamp },
252
252
  * );
253
253
  * ```
254
254
  */
255
- getAvailableLiquidityToTargetUtilization(marketId: MarketId, targetUtilization?: bigint, options?: ReallocationComputeOptions): bigint;
255
+ getAvailableLiquidityToUtilization(marketId: MarketId, utilization?: bigint, options?: ReallocationComputeOptions): bigint;
256
256
  /**
257
257
  * Gets the largest currently valid source-market withdrawal for a vault.
258
258
  *
@@ -348,28 +348,28 @@ class ReallocationData {
348
348
  return withdrawals.reduce((total, { assets }) => total + assets, 0n);
349
349
  }
350
350
  /**
351
- * Computes the liquidity available to bring `marketId` to `targetUtilization`,
351
+ * Computes the liquidity available to bring `marketId` to `utilization`,
352
352
  * counting the public-allocator liquidity reallocatable into it.
353
353
  *
354
354
  * Returns the max borrow `x` keeping post-borrow utilization
355
- * `(borrow + x) / (supply + L) ≤ targetUtilization`, where `L` is the
355
+ * `(borrow + x) / (supply + L) ≤ utilization`, where `L` is the
356
356
  * reallocatable liquidity added to the market's supply — equivalently
357
- * `getBorrowToUtilization({ supply + L, borrow }, targetUtilization)`. Below
358
- * the target this is the market's own borrow headroom plus `targetUtilization · L`;
357
+ * `getBorrowToUtilization({ supply + L, borrow }, utilization)`. Below
358
+ * `utilization` this is the market's own borrow headroom plus `utilization · L`;
359
359
  * reallocated supply also raises the supply denominator, so only that scaled
360
360
  * share backs further borrow.
361
361
  *
362
362
  * Read-only metric — never throws on insufficiency:
363
363
  * - returns only the market's own borrow headroom when
364
- * `supplyTargetUtilization > targetUtilization` (reallocation would not
365
- * trigger at that target);
366
- * - returns `0n` when the market is already at or above the target and `L` is
367
- * too small to bring it back under.
364
+ * `supplyTargetUtilization > utilization` (reallocation would not
365
+ * trigger at that utilization);
366
+ * - returns `0n` when the market is already at or above `utilization` and `L`
367
+ * is too small to bring it back under.
368
368
  *
369
369
  * @param marketId - Target market to borrow from.
370
- * @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
370
+ * @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
371
371
  * @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
372
- * @returns Available liquidity to the target utilization in loan-token units; `0n` when none is available.
372
+ * @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
373
373
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
374
374
  * @example
375
375
  * ```ts
@@ -393,26 +393,26 @@ class ReallocationData {
393
393
  *
394
394
  * // Max borrow keeping utilization at or below 90%, counting shared liquidity.
395
395
  * const available: bigint =
396
- * reallocationData.getAvailableLiquidityToTargetUtilization(
396
+ * reallocationData.getAvailableLiquidityToUtilization(
397
397
  * marketParams.id,
398
398
  * parseEther("0.9"),
399
399
  * { timestamp: block.timestamp },
400
400
  * );
401
401
  * ```
402
402
  */
403
- // biome-ignore lint/complexity/useMaxParams: (marketId, targetUtilization, options) is the metric's public API
404
- getAvailableLiquidityToTargetUtilization(marketId, targetUtilization = constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
403
+ // biome-ignore lint/complexity/useMaxParams: (marketId, utilization, options) is the metric's public API
404
+ getAvailableLiquidityToUtilization(marketId, utilization = constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
405
405
  const market = this.getMarket(marketId).accrueInterest(options?.timestamp);
406
406
  // Below the allocator's trigger, no reallocation happens: own headroom only.
407
407
  const supplyTargetUtilization = (0, utilization_js_1.getSupplyTargetUtilization)(marketId, options);
408
- if (supplyTargetUtilization > targetUtilization)
409
- return market.getBorrowToUtilization(targetUtilization);
408
+ if (supplyTargetUtilization > utilization)
409
+ return market.getBorrowToUtilization(utilization);
410
410
  // Borrow-to-target on the post-reallocation supply; clamps to 0n above target.
411
411
  const availableLiquidity = this.getPublicReallocationLiquidity(marketId, options);
412
412
  return blue_sdk_1.MarketUtils.getBorrowToUtilization({
413
413
  totalSupplyAssets: market.totalSupplyAssets + availableLiquidity,
414
414
  totalBorrowAssets: market.totalBorrowAssets,
415
- }, targetUtilization);
415
+ }, utilization);
416
416
  }
417
417
  /**
418
418
  * Gets the largest currently valid source-market withdrawal for a vault.
@@ -423,7 +423,7 @@ class ReallocationData {
423
423
  * @internal
424
424
  */
425
425
  getLargestVaultWithdrawal({ vault, marketId, withdrawals, defaultMaxWithdrawalUtilization, maxWithdrawalUtilization, timestamp, }) {
426
- return (0, blue_sdk_1._try)(() => {
426
+ return (0, morpho_ts_1._try)(() => {
427
427
  const { cap, pendingCap, publicAllocatorConfig } = this.getVaultMarketConfig(vault, marketId);
428
428
  const validCap = pendingCap.validAt >= timestamp
429
429
  ? blue_sdk_1.MathLib.min(pendingCap.value, cap)
@@ -434,7 +434,7 @@ class ReallocationData {
434
434
  .withdrawQueue.filter((srcMarketId) => srcMarketId !== marketId &&
435
435
  !withdrawals.some((withdrawal) => withdrawal.id === srcMarketId && withdrawal.vault === vault))
436
436
  .map((srcMarketId) => {
437
- const withdrawal = (0, blue_sdk_1._try)(() => {
437
+ const withdrawal = (0, morpho_ts_1._try)(() => {
438
438
  const srcPosition = this.getAccrualPosition(vault, srcMarketId).accrueInterest(timestamp);
439
439
  const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
440
440
  defaultMaxWithdrawalUtilization);
@@ -510,7 +510,7 @@ class ReallocationData {
510
510
  .supply(withdrawal.assets, 0n, timestamp);
511
511
  data.markets[supplyMarketId] = cloneMarket(supplyPosition.market);
512
512
  data.positions[vault][supplyMarketId] = clonePosition(supplyPosition);
513
- void (0, blue_sdk_1._try)(() => {
513
+ void (0, morpho_ts_1._try)(() => {
514
514
  const vaultData = data.getVault(vault);
515
515
  vaultData.totalAssets = vaultData.withdrawQueue.reduce((total, marketId) => total + data.getAccrualPosition(vault, marketId).supplyAssets, 0n);
516
516
  }, blue_sdk_1.UnknownDataError);
@@ -2,7 +2,7 @@ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
2
  import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
5
- import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
5
+ import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
6
6
  export interface VaultV1Actions {
7
7
  /**
8
8
  * Fetches the latest vault data with accrued interest.
@@ -30,10 +30,10 @@ export interface VaultV1Actions {
30
30
  vaultData: AccrualVault;
31
31
  slippageTolerance?: bigint;
32
32
  } & DepositAmountArgs) => {
33
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1DepositAction>>;
33
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
34
34
  getRequirements: (params?: {
35
35
  useSimplePermit?: boolean;
36
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
36
+ }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
37
37
  };
38
38
  /**
39
39
  * Prepares a withdraw from a VaultV1 (MetaMorpho) contract.
@@ -84,8 +84,8 @@ export interface VaultV1Actions {
84
84
  shares: bigint;
85
85
  slippageTolerance?: bigint;
86
86
  }) => {
87
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
88
- getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
87
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
88
+ getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
89
89
  };
90
90
  }
91
91
  export declare class MorphoVaultV1 implements VaultV1Actions {
@@ -101,8 +101,8 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
101
101
  } & DepositAmountArgs): {
102
102
  getRequirements: (params?: {
103
103
  useSimplePermit?: boolean;
104
- }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
105
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1DepositAction>>;
104
+ }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
105
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
106
106
  };
107
107
  withdraw({ amount, userAddress }: {
108
108
  amount: bigint;
@@ -123,7 +123,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
123
123
  shares: bigint;
124
124
  slippageTolerance?: bigint;
125
125
  }): {
126
- getRequirements: () => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
127
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
126
+ getRequirements: () => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
127
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
128
128
  };
129
129
  }
@@ -68,7 +68,7 @@ class MorphoVaultV1 {
68
68
  }
69
69
  const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
70
70
  return {
71
- getRequirements: async (params) => await (0, index_js_1.getRequirements)(this.client.viemClient, {
71
+ getRequirements: (params) => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
72
72
  address: vaultData.asset,
73
73
  chainId: this.chainId,
74
74
  supportSignature: this.client.options.supportSignature,
@@ -79,21 +79,26 @@ class MorphoVaultV1 {
79
79
  from: userAddress,
80
80
  },
81
81
  }),
82
- buildTx: (requirementSignature) => (0, index_js_1.vaultV1Deposit)({
83
- vault: {
84
- chainId: this.chainId,
85
- address: this.vault,
86
- asset: vaultData.asset,
87
- },
88
- args: {
89
- amount,
90
- maxSharePrice,
91
- recipient: userAddress,
92
- requirementSignature,
93
- nativeAmount,
94
- },
95
- metadata: this.client.options.metadata,
96
- }),
82
+ buildTx: (signatures) => {
83
+ const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
84
+ permit: true,
85
+ });
86
+ return (0, index_js_1.vaultV1Deposit)({
87
+ vault: {
88
+ chainId: this.chainId,
89
+ address: this.vault,
90
+ asset: vaultData.asset,
91
+ },
92
+ args: {
93
+ amount,
94
+ maxSharePrice,
95
+ recipient: userAddress,
96
+ requirementSignature: permit,
97
+ nativeAmount,
98
+ },
99
+ metadata: this.client.options.metadata,
100
+ });
101
+ },
97
102
  };
98
103
  }
99
104
  withdraw({ amount, userAddress }) {
@@ -158,7 +163,7 @@ class MorphoVaultV1 {
158
163
  }
159
164
  const maxSharePriceVaultV2 = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), v2RefShares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
160
165
  return {
161
- getRequirements: async () => await (0, index_js_1.getRequirements)(this.client.viemClient, {
166
+ getRequirements: () => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
162
167
  address: this.vault,
163
168
  chainId: this.chainId,
164
169
  supportSignature: this.client.options.supportSignature,
@@ -170,23 +175,28 @@ class MorphoVaultV1 {
170
175
  from: userAddress,
171
176
  },
172
177
  }),
173
- buildTx: (requirementSignature) => (0, index_js_1.vaultV1MigrateToV2)({
174
- vault: {
175
- chainId: this.chainId,
176
- address: this.vault,
177
- asset: sourceVault.asset,
178
- },
179
- args: {
180
- targetVault: targetVault.address,
181
- targetAsset: targetVault.asset,
182
- shares,
183
- minSharePriceVaultV1,
184
- maxSharePriceVaultV2,
185
- recipient: userAddress,
186
- requirementSignature,
187
- },
188
- metadata: this.client.options.metadata,
189
- }),
178
+ buildTx: (signatures) => {
179
+ const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
180
+ permit: true,
181
+ });
182
+ return (0, index_js_1.vaultV1MigrateToV2)({
183
+ vault: {
184
+ chainId: this.chainId,
185
+ address: this.vault,
186
+ asset: sourceVault.asset,
187
+ },
188
+ args: {
189
+ targetVault: targetVault.address,
190
+ targetAsset: targetVault.asset,
191
+ shares,
192
+ minSharePriceVaultV1,
193
+ maxSharePriceVaultV2,
194
+ recipient: userAddress,
195
+ requirementSignature: permit,
196
+ },
197
+ metadata: this.client.options.metadata,
198
+ });
199
+ },
190
200
  };
191
201
  }
192
202
  }
@@ -2,7 +2,7 @@ import { type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
2
  import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
5
- import { type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
5
+ import { type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
6
6
  export interface VaultV2Actions {
7
7
  /**
8
8
  * Fetches the latest vault data.
@@ -29,17 +29,17 @@ export interface VaultV2Actions {
29
29
  * @param {bigint} [params.nativeAmount] - Amount of native token to wrap into wNative. Vault asset must be wNative.
30
30
  * @returns {Object} The result object.
31
31
  * @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
32
- * @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>} returns.getRequirements The function for retrieving all required approval transactions.
32
+ * @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>} returns.getRequirements The function for retrieving all required approval transactions.
33
33
  */
34
34
  deposit: (params: {
35
35
  userAddress: Address;
36
36
  vaultData: AccrualVaultV2;
37
37
  slippageTolerance?: bigint;
38
38
  } & DepositAmountArgs) => {
39
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV2DepositAction>>;
39
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
40
40
  getRequirements: (params?: {
41
41
  useSimplePermit?: boolean;
42
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
42
+ }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
43
43
  };
44
44
  /**
45
45
  * Prepares a withdraw transaction for the VaultV2 contract.
@@ -144,8 +144,8 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
144
144
  } & DepositAmountArgs): {
145
145
  getRequirements: (params?: {
146
146
  useSimplePermit?: boolean;
147
- }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
148
- buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV2DepositAction>>;
147
+ }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
148
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
149
149
  };
150
150
  withdraw({ amount, userAddress }: {
151
151
  amount: bigint;
@@ -71,7 +71,7 @@ class MorphoVaultV2 {
71
71
  }
72
72
  const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), blue_sdk_1.MathLib.RAY * 100n);
73
73
  return {
74
- getRequirements: async (params) => await (0, index_js_1.getRequirements)(this.client.viemClient, {
74
+ getRequirements: (params) => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
75
75
  address: vaultData.asset,
76
76
  chainId: this.chainId,
77
77
  supportSignature: this.client.options.supportSignature,
@@ -82,21 +82,26 @@ class MorphoVaultV2 {
82
82
  from: userAddress,
83
83
  },
84
84
  }),
85
- buildTx: (requirementSignature) => (0, index_js_1.vaultV2Deposit)({
86
- vault: {
87
- chainId: this.chainId,
88
- address: this.vault,
89
- asset: vaultData.asset,
90
- },
91
- args: {
92
- amount,
93
- maxSharePrice,
94
- recipient: userAddress,
95
- requirementSignature,
96
- nativeAmount,
97
- },
98
- metadata: this.client.options.metadata,
99
- }),
85
+ buildTx: (signatures) => {
86
+ const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, {
87
+ permit: true,
88
+ });
89
+ return (0, index_js_1.vaultV2Deposit)({
90
+ vault: {
91
+ chainId: this.chainId,
92
+ address: this.vault,
93
+ asset: vaultData.asset,
94
+ },
95
+ args: {
96
+ amount,
97
+ maxSharePrice,
98
+ recipient: userAddress,
99
+ requirementSignature: permit,
100
+ nativeAmount,
101
+ },
102
+ metadata: this.client.options.metadata,
103
+ });
104
+ },
100
105
  };
101
106
  }
102
107
  withdraw({ amount, userAddress }) {
@@ -1,2 +1,3 @@
1
- export type { ErrorClass } from "@morpho-org/blue-sdk";
2
- export { _try, BlueErrors, InvalidMarketParamsError, UnknownDataError, UnknownFactory, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
1
+ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
2
+ export type { ErrorClass } from "@morpho-org/morpho-ts";
3
+ export { _try } from "@morpho-org/morpho-ts";
package/lib/cjs/errors.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownOfFactory = exports.UnknownMarketParamsError = exports.UnknownFactory = exports.UnknownDataError = exports.InvalidMarketParamsError = exports.BlueErrors = exports._try = void 0;
3
+ exports._try = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownOfFactory = exports.UnknownMarketParamsError = exports.UnknownFactory = exports.UnknownDataError = exports.UnknownAddressError = exports.InvalidMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
4
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- Object.defineProperty(exports, "_try", { enumerable: true, get: function () { return blue_sdk_1._try; } });
6
5
  Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
6
+ Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
7
7
  Object.defineProperty(exports, "InvalidMarketParamsError", { enumerable: true, get: function () { return blue_sdk_1.InvalidMarketParamsError; } });
8
+ Object.defineProperty(exports, "UnknownAddressError", { enumerable: true, get: function () { return blue_sdk_1.UnknownAddressError; } });
8
9
  Object.defineProperty(exports, "UnknownDataError", { enumerable: true, get: function () { return blue_sdk_1.UnknownDataError; } });
9
10
  Object.defineProperty(exports, "UnknownFactory", { enumerable: true, get: function () { return blue_sdk_1.UnknownFactory; } });
10
11
  Object.defineProperty(exports, "UnknownMarketParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnknownMarketParamsError; } });
@@ -16,3 +17,5 @@ Object.defineProperty(exports, "UnsupportedChainIdError", { enumerable: true, ge
16
17
  Object.defineProperty(exports, "UnsupportedPreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
17
18
  Object.defineProperty(exports, "UnsupportedVaultV2AdapterError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedVaultV2AdapterError; } });
18
19
  Object.defineProperty(exports, "VaultV2Errors", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Errors; } });
20
+ var morpho_ts_1 = require("@morpho-org/morpho-ts");
21
+ Object.defineProperty(exports, "_try", { enumerable: true, get: function () { return morpho_ts_1._try; } });
@@ -2,13 +2,13 @@ import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
2
2
  import { type Address } from "viem";
3
3
  import { type VaultReallocation } from "../types/index.js";
4
4
  /** @internal */
5
- export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => 0 | 1 | -1;
5
+ export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => 1 | 0 | -1;
6
6
  /**
7
7
  * Asserts that the client has a connected account AND that it matches
8
8
  * the provided user address.
9
9
  *
10
10
  * Used internally by the signature requirements (`encodeErc20Permit`,
11
- * `encodeErc20Permit2`) to enforce builder = signer at `sign()` time:
11
+ * `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
12
12
  * the signing flow is the only path where an account/address mismatch
13
13
  * is a real security concern (rather than just an integrator footgun).
14
14
  *
@@ -23,7 +23,7 @@ exports.compareMarketIds = compareMarketIds;
23
23
  * the provided user address.
24
24
  *
25
25
  * Used internally by the signature requirements (`encodeErc20Permit`,
26
- * `encodeErc20Permit2`) to enforce builder = signer at `sign()` time:
26
+ * `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
27
27
  * the signing flow is the only path where an account/address mismatch
28
28
  * is a real security concern (rather than just an integrator footgun).
29
29
  *
@@ -180,12 +180,13 @@ export type AssetsOrSharesArgs = {
180
180
  };
181
181
  /** @deprecated Use {@link AssetsOrSharesArgs}. Kept as an alias for back-compat. */
182
182
  export type RepayAmountArgs = AssetsOrSharesArgs;
183
- export interface MorphoAuthorizationAction extends BaseAction<"morphoAuthorization", {
183
+ /** Metadata for a Blue authorization prerequisite transaction. */
184
+ export interface BlueAuthorizationAction extends BaseAction<"blueAuthorization", {
184
185
  authorized: Address;
185
186
  isAuthorized: boolean;
186
187
  }> {
187
188
  }
188
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | MorphoAuthorizationAction;
189
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | BlueAuthorizationAction;
189
190
  export interface Transaction<TAction extends BaseAction = TransactionAction> {
190
191
  readonly to: Address;
191
192
  readonly value: bigint;
@@ -223,9 +224,36 @@ export interface Permit2Args {
223
224
  deadline: bigint;
224
225
  expiration: bigint;
225
226
  }
226
- export interface Requirement {
227
- sign: (client: WalletClient, userAddress: Address) => Promise<RequirementSignature>;
228
- action: PermitAction | Permit2Action;
227
+ /**
228
+ * Signed Morpho Blue authorization payload produced when an integrator opts into offchain
229
+ * signatures (`supportSignature: true`). Consumed by the action layer to emit a
230
+ * `setAuthorizationWithSig` bundler call in place of a standalone `setAuthorization` transaction.
231
+ */
232
+ export interface AuthorizationSignatureArgs {
233
+ /** Account granting the authorization (the position owner). */
234
+ owner: Address;
235
+ /** Account being authorized to operate on Morpho on the owner's behalf (GeneralAdapter1). */
236
+ authorized: Address;
237
+ /** Whether the authorization is granted (`true`) or revoked (`false`). */
238
+ isAuthorized: boolean;
239
+ /** Morpho authorization nonce consumed by the signature. */
240
+ nonce: bigint;
241
+ /** Signature deadline timestamp in seconds. */
242
+ deadline: bigint;
243
+ /** EIP-712 signature over the Morpho `Authorization` typed data. */
244
+ signature: Hex;
245
+ }
246
+ /**
247
+ * A signable approval / authorization requirement. `sign()` returns the matching
248
+ * {@link RequirementSignature}; `action` describes the requirement without signing.
249
+ *
250
+ * Generic over the signature it produces so permit encoders narrow to
251
+ * {@link PermitRequirementSignature} and the authorization encoder to
252
+ * {@link AuthorizationRequirementSignature}; the default keeps the broad union for mixed arrays.
253
+ */
254
+ export interface Requirement<TSignature extends RequirementSignature = RequirementSignature> {
255
+ sign: (client: WalletClient, userAddress: Address) => Promise<TSignature>;
256
+ action: TSignature["action"];
229
257
  }
230
258
  export interface PermitAction extends BaseAction<"permit", {
231
259
  spender: Address;
@@ -240,10 +268,86 @@ export interface Permit2Action extends BaseAction<"permit2", {
240
268
  expiration: bigint;
241
269
  }> {
242
270
  }
243
- export interface RequirementSignature {
271
+ /**
272
+ * Signable Morpho authorization requirement. Emitted by the entity layer when a bundled path
273
+ * needs GeneralAdapter1 authorized and the client opts into offchain signatures.
274
+ */
275
+ export interface AuthorizationAction extends BaseAction<"authorization", {
276
+ authorized: Address;
277
+ isAuthorized: boolean;
278
+ deadline: bigint;
279
+ }> {
280
+ }
281
+ /** A signed ERC-2612 permit or Permit2 approval requirement. */
282
+ export interface PermitRequirementSignature {
244
283
  args: PermitArgs | Permit2Args;
245
284
  action: PermitAction | Permit2Action;
246
285
  }
247
- export declare function isRequirementApproval(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Transaction<ERC20ApprovalAction>;
248
- export declare function isRequirementAuthorization(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Transaction<MorphoAuthorizationAction>;
249
- export declare function isRequirementSignature(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Requirement;
286
+ /** A signed Morpho authorization requirement (consumed via `setAuthorizationWithSig`). */
287
+ export interface AuthorizationRequirementSignature {
288
+ args: AuthorizationSignatureArgs;
289
+ action: AuthorizationAction;
290
+ }
291
+ /**
292
+ * The deep-frozen output of `Requirement.sign()`. Discriminated on `action.type`:
293
+ * `"permit"` / `"permit2"` carry token-approval args, `"authorization"` carries the signed
294
+ * Morpho authorization. Narrow with {@link isPermitSignature} / {@link isAuthorizationSignature}.
295
+ */
296
+ export type RequirementSignature = PermitRequirementSignature | AuthorizationRequirementSignature;
297
+ /** Bundler3 token signature requirement. */
298
+ export type Bundler3TokenSignatureRequirement = Requirement<PermitRequirementSignature>;
299
+ export declare function isRequirementApproval(requirement: unknown): requirement is Transaction<ERC20ApprovalAction>;
300
+ /** Checks whether an action requirement is a Blue authorization transaction. */
301
+ export declare function isRequirementBlueAuthorization(requirement: unknown): requirement is Transaction<BlueAuthorizationAction>;
302
+ export declare function isRequirementSignature<T extends RequirementSignature = RequirementSignature>(requirement: Transaction<ERC20ApprovalAction> | Transaction<BlueAuthorizationAction> | Requirement<T> | undefined): requirement is Requirement<T>;
303
+ /**
304
+ * Narrows a {@link RequirementSignature} to a permit / Permit2 token-approval signature.
305
+ *
306
+ * @param signature - The signed requirement to test.
307
+ * @returns `true` when `signature.action.type` is `"permit"` or `"permit2"`.
308
+ */
309
+ export declare function isPermitSignature(signature: RequirementSignature): signature is PermitRequirementSignature;
310
+ /**
311
+ * Narrows a {@link RequirementSignature} to a signed Morpho authorization.
312
+ *
313
+ * @param signature - The signed requirement to test.
314
+ * @returns `true` when `signature.action.type` is `"authorization"`.
315
+ */
316
+ export declare function isAuthorizationSignature(signature: RequirementSignature): signature is AuthorizationRequirementSignature;
317
+ /** The typed permit / authorization slots a bundled path consumes, split from a `buildTx` array. */
318
+ export interface SelectedRequirementSignatures {
319
+ /** The single permit / Permit2 signature, when present. */
320
+ permit?: PermitRequirementSignature;
321
+ /** The single Morpho authorization signature, when present. */
322
+ authorization?: AuthorizationRequirementSignature;
323
+ }
324
+ /**
325
+ * Splits a `buildTx` signature array into its typed permit / authorization slots, rejecting
326
+ * ambiguous or unexpected input so a path never silently consumes the wrong signature.
327
+ *
328
+ * A bundled path consumes at most one permit and one authorization signature. Passing several of
329
+ * the same kind, or a kind the path does not consume, is rejected with a typed error rather than
330
+ * silently dropping the extras — the latter could otherwise leave a required authorization or
331
+ * permit unsigned (and the bundle reverting on-chain) or apply the wrong signature.
332
+ *
333
+ * @param signatures - The signatures passed to `buildTx`.
334
+ * @param accepts - Which signature kinds this operation consumes.
335
+ * @param accepts.permit - Whether a permit / Permit2 signature is consumed.
336
+ * @param accepts.authorization - Whether a Morpho authorization signature is consumed.
337
+ * @returns The single permit and/or authorization signature, when present.
338
+ * @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
339
+ * @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
340
+ * @example
341
+ * ```ts
342
+ * import { selectRequirementSignatures } from "@morpho-org/morpho-sdk";
343
+ *
344
+ * const { permit, authorization } = selectRequirementSignatures(signatures, {
345
+ * permit: true,
346
+ * authorization: true,
347
+ * });
348
+ * ```
349
+ */
350
+ export declare function selectRequirementSignatures(signatures: readonly RequirementSignature[] | undefined, accepts: {
351
+ permit?: boolean;
352
+ authorization?: boolean;
353
+ }): SelectedRequirementSignatures;