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

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 (243) hide show
  1. package/MIGRATION-v5-to-v6.md +404 -0
  2. package/README.md +127 -69
  3. package/lib/cjs/abis.d.ts +210 -0
  4. package/lib/cjs/abis.js +142 -2
  5. package/lib/cjs/actions/blue/borrow.d.ts +62 -61
  6. package/lib/cjs/actions/blue/borrow.js +48 -80
  7. package/lib/cjs/actions/blue/common.d.ts +86 -0
  8. package/lib/cjs/actions/blue/common.js +205 -0
  9. package/lib/cjs/actions/blue/refinance.d.ts +72 -112
  10. package/lib/cjs/actions/blue/refinance.js +97 -199
  11. package/lib/cjs/actions/blue/repay.d.ts +72 -68
  12. package/lib/cjs/actions/blue/repay.js +56 -118
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
  15. package/lib/cjs/actions/blue/supply.d.ts +62 -45
  16. package/lib/cjs/actions/blue/supply.js +94 -70
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
  18. package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -90
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -120
  21. package/lib/cjs/actions/blue/withdraw.d.ts +68 -79
  22. package/lib/cjs/actions/blue/withdraw.js +101 -97
  23. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
  24. package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
  25. package/lib/cjs/actions/bundles/common.d.ts +200 -0
  26. package/lib/cjs/actions/bundles/common.js +469 -0
  27. package/lib/cjs/actions/bundles/index.d.ts +3 -0
  28. package/lib/cjs/actions/bundles/index.js +23 -0
  29. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  30. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
  31. package/lib/cjs/actions/index.d.ts +2 -1
  32. package/lib/cjs/actions/index.js +1 -0
  33. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  34. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  35. package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
  36. package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
  37. package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
  38. package/lib/cjs/actions/midnight/takeLend.js +2 -2
  39. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  40. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
  41. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  42. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
  43. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
  44. package/lib/cjs/actions/requirements/blue/index.js +1 -0
  45. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  46. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
  47. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  48. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +8 -2
  49. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  50. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -6
  51. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
  52. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +123 -0
  53. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  54. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  55. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  56. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  57. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  58. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +6 -4
  59. package/lib/cjs/actions/requirements/getRequirementsApproval.js +6 -4
  60. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  61. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
  62. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  63. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
  64. package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
  65. package/lib/cjs/actions/vaultV1/deposit.js +110 -109
  66. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
  67. package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
  68. package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
  69. package/lib/cjs/actions/vaultV1/redeem.js +56 -33
  70. package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
  71. package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
  72. package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
  73. package/lib/cjs/actions/vaultV2/deposit.js +111 -109
  74. package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
  75. package/lib/cjs/actions/vaultV2/redeem.js +56 -34
  76. package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
  77. package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
  78. package/lib/cjs/bundler/actions.d.ts +4 -4
  79. package/lib/cjs/bundler/actions.js +4 -4
  80. package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
  81. package/lib/cjs/client/morphoViemExtension.js +2 -1
  82. package/lib/cjs/entities/blue/blue.d.ts +806 -374
  83. package/lib/cjs/entities/blue/blue.js +449 -696
  84. package/lib/cjs/entities/index.d.ts +2 -0
  85. package/lib/cjs/entities/index.js +15 -0
  86. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  87. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
  88. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +203 -0
  89. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  90. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
  91. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  92. package/lib/cjs/entities/requirements/index.js +17 -0
  93. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
  94. package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
  95. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
  96. package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
  97. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +3 -9
  98. package/lib/cjs/helpers/computeVaultV1Reallocations.js +3 -9
  99. package/lib/cjs/helpers/index.d.ts +2 -1
  100. package/lib/cjs/helpers/index.js +5 -1
  101. package/lib/cjs/helpers/referralFee.d.ts +21 -0
  102. package/lib/cjs/helpers/referralFee.js +35 -0
  103. package/lib/cjs/helpers/slippage.d.ts +90 -1
  104. package/lib/cjs/helpers/slippage.js +123 -0
  105. package/lib/cjs/helpers/validate.d.ts +16 -23
  106. package/lib/cjs/helpers/validate.js +41 -48
  107. package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
  108. package/lib/cjs/helpers/validateRequirementSpender.js +3 -0
  109. package/lib/cjs/index.d.ts +1 -0
  110. package/lib/cjs/index.js +1 -0
  111. package/lib/cjs/types/action.d.ts +303 -210
  112. package/lib/cjs/types/action.js +29 -2
  113. package/lib/cjs/types/client.d.ts +9 -0
  114. package/lib/cjs/types/error.d.ts +193 -18
  115. package/lib/cjs/types/error.js +267 -24
  116. package/lib/cjs/types/sharedLiquidity.d.ts +0 -7
  117. package/lib/esm/abis.d.ts +210 -0
  118. package/lib/esm/abis.js +140 -0
  119. package/lib/esm/actions/blue/borrow.d.ts +62 -61
  120. package/lib/esm/actions/blue/borrow.js +48 -80
  121. package/lib/esm/actions/blue/common.d.ts +86 -0
  122. package/lib/esm/actions/blue/common.js +193 -0
  123. package/lib/esm/actions/blue/refinance.d.ts +72 -112
  124. package/lib/esm/actions/blue/refinance.js +98 -200
  125. package/lib/esm/actions/blue/repay.d.ts +72 -68
  126. package/lib/esm/actions/blue/repay.js +56 -118
  127. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  128. package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
  129. package/lib/esm/actions/blue/supply.d.ts +62 -45
  130. package/lib/esm/actions/blue/supply.js +94 -70
  131. package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
  132. package/lib/esm/actions/blue/supplyCollateral.js +52 -69
  133. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -90
  134. package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -121
  135. package/lib/esm/actions/blue/withdraw.d.ts +68 -79
  136. package/lib/esm/actions/blue/withdraw.js +100 -96
  137. package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
  138. package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
  139. package/lib/esm/actions/bundles/common.d.ts +200 -0
  140. package/lib/esm/actions/bundles/common.js +457 -0
  141. package/lib/esm/actions/bundles/index.d.ts +3 -0
  142. package/lib/esm/actions/bundles/index.js +2 -0
  143. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  144. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
  145. package/lib/esm/actions/index.d.ts +2 -1
  146. package/lib/esm/actions/index.js +1 -0
  147. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  148. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  149. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  150. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  151. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  152. package/lib/esm/actions/midnight/takeLend.js +2 -2
  153. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  154. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
  155. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  156. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
  157. package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
  158. package/lib/esm/actions/requirements/blue/index.js +1 -0
  159. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  160. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
  161. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  162. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -3
  163. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  164. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -7
  165. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
  166. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +119 -0
  167. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  168. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  169. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  170. package/lib/esm/actions/requirements/encode/index.js +1 -0
  171. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  172. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +6 -4
  173. package/lib/esm/actions/requirements/getRequirementsApproval.js +6 -4
  174. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  175. package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
  176. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  177. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
  178. package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
  179. package/lib/esm/actions/vaultV1/deposit.js +112 -111
  180. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
  181. package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
  182. package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
  183. package/lib/esm/actions/vaultV1/redeem.js +56 -33
  184. package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
  185. package/lib/esm/actions/vaultV1/withdraw.js +86 -34
  186. package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
  187. package/lib/esm/actions/vaultV2/deposit.js +113 -111
  188. package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
  189. package/lib/esm/actions/vaultV2/redeem.js +56 -34
  190. package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
  191. package/lib/esm/actions/vaultV2/withdraw.js +86 -35
  192. package/lib/esm/bundler/actions.d.ts +4 -4
  193. package/lib/esm/bundler/actions.js +4 -4
  194. package/lib/esm/client/morphoViemExtension.d.ts +2 -1
  195. package/lib/esm/client/morphoViemExtension.js +2 -1
  196. package/lib/esm/entities/blue/blue.d.ts +806 -374
  197. package/lib/esm/entities/blue/blue.js +455 -702
  198. package/lib/esm/entities/index.d.ts +2 -0
  199. package/lib/esm/entities/index.js +1 -0
  200. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  201. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
  202. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +199 -0
  203. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  204. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
  205. package/lib/esm/entities/requirements/index.d.ts +1 -0
  206. package/lib/esm/entities/requirements/index.js +1 -0
  207. package/lib/esm/entities/vaultV1/vaultV1.d.ts +348 -98
  208. package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
  209. package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
  210. package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
  211. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +3 -9
  212. package/lib/esm/helpers/computeVaultV1Reallocations.js +3 -9
  213. package/lib/esm/helpers/index.d.ts +2 -1
  214. package/lib/esm/helpers/index.js +2 -1
  215. package/lib/esm/helpers/referralFee.d.ts +21 -0
  216. package/lib/esm/helpers/referralFee.js +31 -0
  217. package/lib/esm/helpers/slippage.d.ts +90 -1
  218. package/lib/esm/helpers/slippage.js +122 -2
  219. package/lib/esm/helpers/validate.d.ts +16 -23
  220. package/lib/esm/helpers/validate.js +40 -48
  221. package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
  222. package/lib/esm/helpers/validateRequirementSpender.js +3 -0
  223. package/lib/esm/index.d.ts +1 -0
  224. package/lib/esm/index.js +1 -0
  225. package/lib/esm/types/action.d.ts +303 -210
  226. package/lib/esm/types/action.js +28 -2
  227. package/lib/esm/types/client.d.ts +9 -0
  228. package/lib/esm/types/error.d.ts +193 -18
  229. package/lib/esm/types/error.js +252 -21
  230. package/lib/esm/types/sharedLiquidity.d.ts +0 -7
  231. package/package.json +6 -5
  232. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
  233. package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
  234. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
  235. package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
  236. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
  237. package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
  238. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
  239. package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
  240. package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
  241. package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
  242. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
  243. package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
@@ -1,6 +1,6 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
- import type { Client } from "viem";
3
- import { type PermitRequirementSignature, type Requirement } from "../../../types/index.js";
2
+ import { type Client } from "viem";
3
+ import { type Erc2612RequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeErc20Permit}. */
5
5
  interface EncodeErc20PermitParams {
6
6
  token: Address;
@@ -9,6 +9,7 @@ interface EncodeErc20PermitParams {
9
9
  chainId: number;
10
10
  nonce: bigint;
11
11
  supportDeployless?: boolean;
12
+ deadline?: bigint;
12
13
  }
13
14
  /**
14
15
  * Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
@@ -16,20 +17,28 @@ interface EncodeErc20PermitParams {
16
17
  *
17
18
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
18
19
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
19
- * the bundler action helpers can consume. Deadline defaults to two hours from `Time.timestamp()`.
20
+ * the selected transaction route can consume. Deadline defaults to two hours from
21
+ * `Time.timestamp()`.
20
22
  *
21
23
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
22
24
  * @param params - Permit encoding parameters.
23
25
  * @param params.token - ERC-20 token address (must support EIP-2612).
24
- * @param params.spender - Permit spender. Must be GeneralAdapter1 or MidnightBundles for the chain.
26
+ * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
27
+ * VaultBundlesV1, or BlueBundlesV1 for the chain.
25
28
  * @param params.amount - Permit allowance amount.
26
29
  * @param params.chainId - Target chain id.
27
30
  * @param params.nonce - The user's current EIP-2612 nonce on `token`.
28
31
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
32
+ * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
29
33
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
30
34
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
31
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or
32
- * MidnightBundles for `chainId`.
35
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
36
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
37
+ * MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
38
+ * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
39
+ * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
40
+ * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
41
+ * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
33
42
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
34
43
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
35
44
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -50,5 +59,5 @@ interface EncodeErc20PermitParams {
50
59
  * // requirement satisfies Requirement
51
60
  * ```
52
61
  */
53
- export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<PermitRequirementSignature>>;
62
+ export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<Erc2612RequirementSignature>>;
54
63
  export {};
@@ -1,28 +1,37 @@
1
1
  import { fetchToken, getPermitTypedData } from "@morpho-org/blue-sdk-viem";
2
2
  import { deepFreeze, Time } from "@morpho-org/morpho-ts";
3
+ import { maxUint256 } from "viem";
3
4
  import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
4
5
  import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
5
- import { ChainIdMismatchError, } from "../../../types/index.js";
6
+ import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } from "../../../types/index.js";
6
7
  /**
7
8
  * Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
8
9
  * `amount` of `token`.
9
10
  *
10
11
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
11
12
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
12
- * the bundler action helpers can consume. Deadline defaults to two hours from `Time.timestamp()`.
13
+ * the selected transaction route can consume. Deadline defaults to two hours from
14
+ * `Time.timestamp()`.
13
15
  *
14
16
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
15
17
  * @param params - Permit encoding parameters.
16
18
  * @param params.token - ERC-20 token address (must support EIP-2612).
17
- * @param params.spender - Permit spender. Must be GeneralAdapter1 or MidnightBundles for the chain.
19
+ * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
20
+ * VaultBundlesV1, or BlueBundlesV1 for the chain.
18
21
  * @param params.amount - Permit allowance amount.
19
22
  * @param params.chainId - Target chain id.
20
23
  * @param params.nonce - The user's current EIP-2612 nonce on `token`.
21
24
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
25
+ * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
22
26
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
23
27
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
24
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or
25
- * MidnightBundles for `chainId`.
28
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
29
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
30
+ * MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
31
+ * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
32
+ * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
33
+ * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
34
+ * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
26
35
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
27
36
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
28
37
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -51,10 +60,33 @@ export const encodeErc20Permit = async (viemClient, params) => {
51
60
  validateRequirementSpender({
52
61
  chainId,
53
62
  spender,
54
- allowed: ["generalAdapter1", "midnightBundles"],
63
+ allowed: [
64
+ "generalAdapter1",
65
+ "midnightBundles",
66
+ "vaultBundlesV1",
67
+ "blueBundlesV1",
68
+ ],
55
69
  });
56
70
  const now = Time.timestamp();
57
- const deadline = now + Time.s.from.h(2n);
71
+ // Validate an explicit deadline before the token-metadata read: this exported encoder can be
72
+ // called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
73
+ // deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
74
+ if (params.deadline != null) {
75
+ if (params.deadline <= 0n) {
76
+ throw new NonPositiveInputError("deadline", params.deadline);
77
+ }
78
+ if (params.deadline > maxUint256) {
79
+ throw new InputExceedsMaxError({
80
+ field: "deadline",
81
+ value: params.deadline,
82
+ max: maxUint256,
83
+ });
84
+ }
85
+ if (params.deadline <= now) {
86
+ throw new ExpiredDeadlineError(params.deadline, now);
87
+ }
88
+ }
89
+ const deadline = params.deadline ?? now + Time.s.from.h(2n);
58
90
  const tokenData = await fetchToken(token, viemClient, {
59
91
  deployless: supportDeployless,
60
92
  });
@@ -64,6 +96,7 @@ export const encodeErc20Permit = async (viemClient, params) => {
64
96
  spender,
65
97
  amount,
66
98
  deadline,
99
+ nonce,
67
100
  },
68
101
  };
69
102
  return {
@@ -0,0 +1,61 @@
1
+ import type { Address } from "@morpho-org/blue-sdk";
2
+ import { type Permit2SignatureTransferRequirementSignature, type Requirement } from "../../../types/index.js";
3
+ /** Parameters for {@link encodeErc20Permit2SignatureTransfer}. */
4
+ export interface EncodeErc20Permit2SignatureTransferParams {
5
+ /** ERC-20 token pulled through Permit2. */
6
+ readonly token: Address;
7
+ /** Registered fixed bundles deployment receiving permission to pull the token. */
8
+ readonly spender: Address;
9
+ /** Exact token amount authorized by the one-time transfer. */
10
+ readonly amount: bigint;
11
+ /** Target chain id. */
12
+ readonly chainId: number;
13
+ /** Unused Permit2 unordered nonce. */
14
+ readonly nonce: bigint;
15
+ /** Signature expiration timestamp in seconds. */
16
+ readonly deadline: bigint;
17
+ }
18
+ /**
19
+ * Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
20
+ *
21
+ * Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
22
+ * it has no managed allowance expiration.
23
+ *
24
+ * @param params - SignatureTransfer parameters.
25
+ * @param params.token - ERC-20 token pulled through Permit2.
26
+ * @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
27
+ * @param params.amount - Exact `uint256` token amount authorized.
28
+ * @param params.chainId - Target chain id.
29
+ * @param params.nonce - Unused Permit2 unordered nonce.
30
+ * @param params.deadline - Signature expiration timestamp in seconds.
31
+ * @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
32
+ * @throws {NegativeInputError} when `amount` or `nonce` is negative.
33
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
34
+ * @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
35
+ * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
36
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
37
+ * @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
38
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
39
+ * @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
40
+ * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
41
+ * @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
42
+ * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
43
+ * @example
44
+ * ```ts
45
+ * import { addressesRegistry } from "@morpho-org/blue-sdk";
46
+ * import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
47
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
48
+ * import { mainnet } from "viem/chains";
49
+ *
50
+ * const requirement = encodeErc20Permit2SignatureTransfer({
51
+ * token: addressesRegistry[mainnet.id].usdc,
52
+ * spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
53
+ * amount: 1_000_000n,
54
+ * chainId: mainnet.id,
55
+ * nonce: 0n,
56
+ * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
57
+ * });
58
+ * // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
59
+ * ```
60
+ */
61
+ export declare const encodeErc20Permit2SignatureTransfer: (params: EncodeErc20Permit2SignatureTransferParams) => Requirement<Permit2SignatureTransferRequirementSignature>;
@@ -0,0 +1,119 @@
1
+ import { getPermit2TransferFromTypedData } from "@morpho-org/blue-sdk-viem";
2
+ import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
3
+ import { maxUint256 } from "viem";
4
+ import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
5
+ import { validateUint256Field } from "../../../helpers/validate.js";
6
+ import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
7
+ import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } from "../../../types/index.js";
8
+ /**
9
+ * Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
10
+ *
11
+ * Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
12
+ * it has no managed allowance expiration.
13
+ *
14
+ * @param params - SignatureTransfer parameters.
15
+ * @param params.token - ERC-20 token pulled through Permit2.
16
+ * @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
17
+ * @param params.amount - Exact `uint256` token amount authorized.
18
+ * @param params.chainId - Target chain id.
19
+ * @param params.nonce - Unused Permit2 unordered nonce.
20
+ * @param params.deadline - Signature expiration timestamp in seconds.
21
+ * @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
22
+ * @throws {NegativeInputError} when `amount` or `nonce` is negative.
23
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
24
+ * @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
25
+ * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
26
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
27
+ * @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
28
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
29
+ * @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
30
+ * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
31
+ * @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
32
+ * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
33
+ * @example
34
+ * ```ts
35
+ * import { addressesRegistry } from "@morpho-org/blue-sdk";
36
+ * import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
37
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
38
+ * import { mainnet } from "viem/chains";
39
+ *
40
+ * const requirement = encodeErc20Permit2SignatureTransfer({
41
+ * token: addressesRegistry[mainnet.id].usdc,
42
+ * spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
43
+ * amount: 1_000_000n,
44
+ * chainId: mainnet.id,
45
+ * nonce: 0n,
46
+ * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
47
+ * });
48
+ * // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
49
+ * ```
50
+ */
51
+ export const encodeErc20Permit2SignatureTransfer = (params) => {
52
+ const { token, spender, amount, chainId, nonce, deadline } = params;
53
+ // Bound every uint256 field before signing: getPermit2TransferFromTypedData silently clamps an
54
+ // oversized allowance to maxUint256, which would desync the signed value from the requirement
55
+ // metadata that blueSupply verifies. Direct callers bypass the token-requirement resolver, so
56
+ // this public encoder must reject the same out-of-range inputs itself.
57
+ validateUint256Field("amount", amount);
58
+ validateUint256Field("nonce", nonce);
59
+ if (deadline <= 0n) {
60
+ throw new NonPositiveInputError("deadline", deadline);
61
+ }
62
+ if (deadline > maxUint256) {
63
+ throw new InputExceedsMaxError({
64
+ field: "deadline",
65
+ value: deadline,
66
+ max: maxUint256,
67
+ });
68
+ }
69
+ // Reject an already-expired deadline before signing so a direct caller is never walked through a
70
+ // wallet EIP-712 prompt for a SignatureTransfer that Permit2 would revert with `SignatureExpired`.
71
+ // The sibling encodeErc20Permit and the token-requirement resolver enforce the same guard.
72
+ const timestamp = Time.timestamp();
73
+ if (deadline <= timestamp) {
74
+ throw new ExpiredDeadlineError(deadline, timestamp);
75
+ }
76
+ validateRequirementSpender({
77
+ chainId,
78
+ spender,
79
+ allowed: ["vaultBundlesV1", "blueBundlesV1"],
80
+ });
81
+ // getPermit2TransferFromTypedData derives its EIP-712 domain's verifyingContract from
82
+ // getChainAddresses(chainId).permit2. A chain that registers BlueBundlesV1 but no canonical Permit2
83
+ // leaves that undefined, and viem drops the undefined field from the domain — the wallet would then
84
+ // sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
85
+ // this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
86
+ getChainAddress(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
87
+ const action = {
88
+ type: "permit2SignatureTransfer",
89
+ args: { spender, amount, nonce, deadline },
90
+ };
91
+ return {
92
+ action,
93
+ async sign(client, userAddress) {
94
+ const typedData = getPermit2TransferFromTypedData({
95
+ erc20: token,
96
+ allowance: amount,
97
+ spender,
98
+ nonce,
99
+ deadline,
100
+ }, chainId);
101
+ const signature = await signAndVerifyTypedData({
102
+ client,
103
+ userAddress,
104
+ typedData,
105
+ });
106
+ return deepFreeze({
107
+ args: {
108
+ owner: userAddress,
109
+ asset: token,
110
+ amount,
111
+ nonce,
112
+ deadline,
113
+ signature,
114
+ },
115
+ action,
116
+ });
117
+ },
118
+ };
119
+ };
@@ -6,7 +6,7 @@ export interface EncodeVaultSharesPermitParams {
6
6
  readonly vault: Token;
7
7
  /** Vault generation, which selects the standard V1 or two-field V2 domain. */
8
8
  readonly version: "vaultV1" | "vaultV2";
9
- /** VaultExitBundlesV1 spender. */
9
+ /** Registered fixed vault bundles spender. */
10
10
  readonly spender: Address;
11
11
  /** Account that owns the vault shares. */
12
12
  readonly owner: Address;
@@ -27,15 +27,15 @@ export interface EncodeVaultSharesPermitParams {
27
27
  *
28
28
  * @param params.vault - Vault share token, including V1 permit-domain metadata when available.
29
29
  * @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
30
- * @param params.spender - Registered VaultExitBundlesV1 spender.
30
+ * @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
31
31
  * @param params.owner - Account that owns and authorizes spending of the vault shares.
32
32
  * @param params.chainId - Chain on which the vault and spender are deployed.
33
33
  * @param params.nonce - Current vault permit nonce for the owner.
34
34
  * @param params.amount - Vault-share allowance to authorize.
35
35
  * @param params.deadline - Shared permit and bundle deadline.
36
- * @returns A requirement whose `sign()` result can be embedded in VaultExitBundlesV1 calldata.
36
+ * @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
37
37
  * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
38
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the registered VaultExitBundlesV1.
38
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
39
39
  * @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
40
40
  * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
41
41
  * @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
@@ -13,15 +13,15 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
13
13
  *
14
14
  * @param params.vault - Vault share token, including V1 permit-domain metadata when available.
15
15
  * @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
16
- * @param params.spender - Registered VaultExitBundlesV1 spender.
16
+ * @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
17
17
  * @param params.owner - Account that owns and authorizes spending of the vault shares.
18
18
  * @param params.chainId - Chain on which the vault and spender are deployed.
19
19
  * @param params.nonce - Current vault permit nonce for the owner.
20
20
  * @param params.amount - Vault-share allowance to authorize.
21
21
  * @param params.deadline - Shared permit and bundle deadline.
22
- * @returns A requirement whose `sign()` result can be embedded in VaultExitBundlesV1 calldata.
22
+ * @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
23
23
  * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
24
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the registered VaultExitBundlesV1.
24
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
25
25
  * @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
26
26
  * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
27
27
  * @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
@@ -76,11 +76,11 @@ export const encodeVaultSharesPermit = (params) => {
76
76
  extensions: [...inputDomain.extensions],
77
77
  }),
78
78
  });
79
- // Bind the permit to the standalone vault-exit deployment for this chain.
79
+ // Bind the permit to one of the registered fixed vault bundles deployments.
80
80
  validateRequirementSpender({
81
81
  chainId,
82
82
  spender,
83
- allowed: ["vaultExitBundlesV1"],
83
+ allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
84
84
  });
85
85
  const action = {
86
86
  type: "permit",
@@ -88,6 +88,7 @@ export const encodeVaultSharesPermit = (params) => {
88
88
  spender,
89
89
  amount,
90
90
  deadline,
91
+ nonce,
91
92
  },
92
93
  };
93
94
  return {
@@ -2,4 +2,5 @@ export * from "./encodeBlueSignatureAuthorization.js";
2
2
  export * from "./encodeErc20Approval.js";
3
3
  export * from "./encodeErc20Permit.js";
4
4
  export * from "./encodeErc20Permit2Approve.js";
5
+ export * from "./encodeErc20Permit2SignatureTransfer.js";
5
6
  export * from "./encodeVaultSharesPermit.js";
@@ -2,4 +2,5 @@ export * from "./encodeBlueSignatureAuthorization.js";
2
2
  export * from "./encodeErc20Approval.js";
3
3
  export * from "./encodeErc20Permit.js";
4
4
  export * from "./encodeErc20Permit2Approve.js";
5
+ export * from "./encodeErc20Permit2SignatureTransfer.js";
5
6
  export * from "./encodeVaultSharesPermit.js";
@@ -34,4 +34,4 @@ export declare const getGeneralAdapterRequirementsPermit: (viemClient: Client, p
34
34
  };
35
35
  nonce: bigint;
36
36
  supportDeployless?: boolean;
37
- }) => Promise<import("../../../index.js").Requirement<import("../../../index.js").PermitRequirementSignature, undefined>[]>;
37
+ }) => Promise<import("../../../index.js").Requirement<import("../../../index.js").Erc2612RequirementSignature, undefined>[]>;
@@ -5,8 +5,8 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
5
5
  * allowance.
6
6
  *
7
7
  * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
8
- * GeneralAdapter1, Permit2, Midnight, MidnightBundles, and VaultExitBundlesV1 addresses when
9
- * configured.
8
+ * GeneralAdapter1, Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and
9
+ * BlueBundlesV1 addresses when configured.
10
10
  *
11
11
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
12
12
  * `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
@@ -18,13 +18,15 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
18
18
  * and token approval caps.
19
19
  * @param params.args.spendAmount - The amount the bundle will actually pull.
20
20
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
21
- * may be `MAX_UINT_160` for Permit2 prerequisites).
21
+ * may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
22
22
  * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
23
- * Permit2, Midnight, MidnightBundles, or VaultExitBundlesV1 for `chainId`.
23
+ * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for
24
+ * `chainId`.
24
25
  * @param params.allowances - The user's current allowance of `address` for `spender`.
25
26
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
26
27
  * followed by the new approval. Empty when no approval is needed.
27
28
  * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < spendAmount`.
29
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
28
30
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
29
31
  * @example
30
32
  * ```ts
@@ -7,8 +7,8 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
7
7
  * allowance.
8
8
  *
9
9
  * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
10
- * GeneralAdapter1, Permit2, Midnight, MidnightBundles, and VaultExitBundlesV1 addresses when
11
- * configured.
10
+ * GeneralAdapter1, Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and
11
+ * BlueBundlesV1 addresses when configured.
12
12
  *
13
13
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
14
14
  * `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
@@ -20,13 +20,15 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
20
20
  * and token approval caps.
21
21
  * @param params.args.spendAmount - The amount the bundle will actually pull.
22
22
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
23
- * may be `MAX_UINT_160` for Permit2 prerequisites).
23
+ * may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
24
24
  * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
25
- * Permit2, Midnight, MidnightBundles, or VaultExitBundlesV1 for `chainId`.
25
+ * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for
26
+ * `chainId`.
26
27
  * @param params.allowances - The user's current allowance of `address` for `spender`.
27
28
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
28
29
  * followed by the new approval. Empty when no approval is needed.
29
30
  * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < spendAmount`.
31
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
30
32
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
31
33
  * @example
32
34
  * ```ts
@@ -25,6 +25,7 @@ interface GetTokenRequirementActionsParams {
25
25
  * @returns Bundler `Action`s needed to pull the token.
26
26
  * @throws {DepositAssetMismatchError} when the signed asset differs from `asset`.
27
27
  * @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
28
+ * @throws {UnexpectedRequirementSignatureError} when passed a BlueBundlesV1-only SignatureTransfer result.
28
29
  * @throws {Permit2ExpirationMissingError} when `action.type === "permit2"` but `args.expiration` is missing.
29
30
  * @example
30
31
  * ```ts
@@ -1,5 +1,5 @@
1
1
  import { isAddressEqual } from "viem";
2
- import { DepositAmountMismatchError, DepositAssetMismatchError, Permit2ExpirationMissingError, } from "../../types/index.js";
2
+ import { DepositAmountMismatchError, DepositAssetMismatchError, isPermit2SignatureTransferSignature, Permit2ExpirationMissingError, UnexpectedRequirementSignatureError, } from "../../types/index.js";
3
3
  /**
4
4
  * Encodes the bundler actions that pull the asset to `recipient`, optionally consuming a
5
5
  * pre-signed permit / permit2 requirement first.
@@ -18,6 +18,7 @@ import { DepositAmountMismatchError, DepositAssetMismatchError, Permit2Expiratio
18
18
  * @returns Bundler `Action`s needed to pull the token.
19
19
  * @throws {DepositAssetMismatchError} when the signed asset differs from `asset`.
20
20
  * @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
21
+ * @throws {UnexpectedRequirementSignatureError} when passed a BlueBundlesV1-only SignatureTransfer result.
21
22
  * @throws {Permit2ExpirationMissingError} when `action.type === "permit2"` but `args.expiration` is missing.
22
23
  * @example
23
24
  * ```ts
@@ -55,6 +56,9 @@ export const getTokenRequirementActions = ({ asset, amount, recipient, requireme
55
56
  },
56
57
  ];
57
58
  }
59
+ if (isPermit2SignatureTransferSignature(requirementSignature)) {
60
+ throw new UnexpectedRequirementSignatureError("permit2SignatureTransfer");
61
+ }
58
62
  if (!isAddressEqual(requirementSignature.args.asset, asset)) {
59
63
  throw new DepositAssetMismatchError(asset, requirementSignature.args.asset);
60
64
  }
@@ -1,21 +1,17 @@
1
- import { type Address, type Hex } from "viem";
1
+ import type { Address } from "viem";
2
2
  import { type PermitRequirementSignature } from "../../types/index.js";
3
- /** Permit tuple consumed by VaultExitBundlesV1. */
4
- export interface VaultExitBundlesV1PermitStruct {
5
- /** Vault-share allowance authorized by the permit. */
6
- readonly value: bigint;
7
- /** Vault permit nonce signed by the owner. */
8
- readonly nonce: bigint;
9
- /** Timestamp after which the permit is invalid. */
10
- readonly deadline: bigint;
11
- /** ECDSA recovery identifier, or zero for the empty-permit sentinel. */
12
- readonly v: number;
13
- /** ECDSA signature `r`, or zero for the empty-permit sentinel. */
14
- readonly r: Hex;
15
- /** ECDSA signature `s`, or zero for the empty-permit sentinel. */
16
- readonly s: Hex;
17
- }
18
- /** Parameters for {@link getVaultExitBundlesV1PermitStruct}. */
3
+ import { type BundleSharesPermit } from "../bundles/common.js";
4
+ /**
5
+ * Compatibility alias for the canonical {@link BundleSharesPermit} tuple consumed by VaultExitBundlesV1.
6
+ *
7
+ * @deprecated Use {@link BundleSharesPermit}.
8
+ */
9
+ export type VaultExitBundlesV1PermitStruct = BundleSharesPermit;
10
+ /**
11
+ * Parameters for {@link getVaultExitBundlesV1PermitStruct}.
12
+ *
13
+ * @deprecated Use the parameters of `getBundlesSharesPermit`.
14
+ */
19
15
  export interface GetVaultExitBundlesV1PermitStructParams {
20
16
  /** Vault share token authorized by the permit. */
21
17
  readonly vault: Address;
@@ -25,28 +21,24 @@ export interface GetVaultExitBundlesV1PermitStructParams {
25
21
  readonly requirementSignature?: PermitRequirementSignature;
26
22
  }
27
23
  /**
28
- * Returns the permit struct consumed by VaultExitBundlesV1 from an optional vault-share
29
- * requirement signature.
30
- *
31
- * Without a signature, returns the contract's empty-permit sentinel. With a signature, validates
32
- * the ERC-2612 kind and vault asset before splitting the serialized signature.
33
- * Owner, spender, deadline, nonce, and cryptographic validity are verified onchain by the vault.
24
+ * Compatibility wrapper for the former VaultExitBundlesV1-specific permit reshaper.
34
25
  *
35
26
  * @param params.vault - Vault share token authorized by the permit.
36
27
  * @param params.deadline - Bundle deadline used by the empty-permit sentinel.
37
- * @param params.requirementSignature - Optional signed bounded ERC-2612 requirement.
38
- * @returns The VaultExitBundlesV1 permit tuple.
39
- * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
28
+ * @param params.requirementSignature - Optional signed ERC-2612 vault-share requirement.
29
+ * @returns The shared bundles share-permit tuple.
30
+ * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement is incompatible.
31
+ * @deprecated Use `getBundlesSharesPermit`; this wrapper preserves the legacy error identity.
40
32
  * @example
41
33
  * ```ts
42
34
  * import { getVaultExitBundlesV1PermitStruct } from "@morpho-org/morpho-sdk";
35
+ * import { zeroAddress } from "viem";
43
36
  *
44
37
  * const permit = getVaultExitBundlesV1PermitStruct({
45
- * vault,
46
- * deadline,
47
- * requirementSignature,
38
+ * vault: zeroAddress,
39
+ * deadline: 1_900_000_000n,
48
40
  * });
49
- * // permit satisfies VaultExitBundlesV1PermitStruct
41
+ * // permit.value === 0n
50
42
  * ```
51
43
  */
52
44
  export declare const getVaultExitBundlesV1PermitStruct: (params: GetVaultExitBundlesV1PermitStructParams) => VaultExitBundlesV1PermitStruct;