@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,54 +1,105 @@
1
- import { vaultV2Abi } from "@morpho-org/blue-sdk-viem";
2
- import { deepFreeze } from "@morpho-org/morpho-ts";
1
+ import { getChainAddress } from "@morpho-org/morpho-ts";
3
2
  import { encodeFunctionData } from "viem";
4
- import { addTransactionMetadata } from "../../helpers/index.js";
3
+ import { vaultBundlesV1Abi } from "../../abis.js";
4
+ import { validateUint256Field } from "../../helpers/validate.js";
5
5
  import { NonPositiveInputError, } from "../../types/index.js";
6
+ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBundlesSharesPermit, normalizeBundlesCommonParams, } from "../bundles/common.js";
6
7
  /**
7
- * Prepares a withdraw transaction for a VaultV2 contract.
8
+ * Encodes an exact-assets Vault V2 withdrawal through VaultBundlesV1.
8
9
  *
9
- * Direct vault call — not routed through the bundler. Withdraw has no inflation-attack surface,
10
- * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
10
+ * This low-level builder does not bind `permit.value` to a share cap; use
11
+ * `MorphoVaultV2.withdraw().buildTx()` to validate it against the cap from `getRequirements()`.
11
12
  *
12
- * @param params.vault.address - The VaultV2 address.
13
- * @param params.args.amount - Amount of underlying assets to withdraw.
14
- * @param params.args.recipient - Address that receives the withdrawn assets.
15
- * @param params.args.onBehalf - Address whose shares are burned.
16
- * @param params.metadata - Optional analytics metadata attached to the transaction.
17
- * @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` with `to`, `value`, `data`, and the
18
- * typed `action` discriminator the simulation layer consumes.
19
- * @throws {NonPositiveInputError} when `amount <= 0n`.
13
+ * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
14
+ * @param params.vault.address - Vault V2 whose shares are burned for the withdrawal.
15
+ * @param params.args.amount - Positive gross withdrawal in underlying asset base units, before fees.
16
+ * @param params.args.userAddress - Share owner and transaction sender; receives the net withdrawn assets.
17
+ * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
18
+ * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
19
+ * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
20
+ * and the registered VaultBundlesV1 spender. Omit when the exact share allowance is already set.
21
+ * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
22
+ * The fee is rounded down and deducted from the gross withdrawn assets.
23
+ * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
24
+ * when `referralFeePct > 0n`.
25
+ * @param params.args.deadline - Required positive uint256 Unix timestamp in seconds after which
26
+ * execution reverts. This pure builder does not check the current time.
27
+ * @param params.metadata - Optional analytics metadata appended to the transaction calldata.
28
+ * @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
29
+ * @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
30
+ * @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` targeting VaultBundlesV1, with
31
+ * `to`, `value: 0n`, `data`, and gross/fee/net withdrawal action metadata.
32
+ * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
33
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
34
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
35
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
36
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
37
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
38
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
39
+ * @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
40
+ * @throws {viem.BaseError} when transaction encoding fails.
20
41
  * @example
21
42
  * ```ts
22
43
  * import { vaultV2Withdraw } from "@morpho-org/morpho-sdk";
44
+ * import type { Address } from "viem";
45
+ * import { mainnet } from "viem/chains";
23
46
  *
24
- * const tx = vaultV2Withdraw({
25
- * vault: { address: vaultAddress },
26
- * args: { amount: 500_000n, recipient, onBehalf },
27
- * });
28
- * // tx satisfies Readonly<Transaction<VaultV2WithdrawAction>>
47
+ * export function buildUsdcWithdrawal(userAddress: Address, deadline: bigint) {
48
+ * const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
49
+ * // Set the exact vault-share allowance before submitting; the entity API derives that cap.
50
+ * const tx = vaultV2Withdraw({
51
+ * vault: { chainId: mainnet.id, address: vault },
52
+ * args: { amount: 1_000_000n, userAddress, deadline },
53
+ * });
54
+ * // tx satisfies Readonly<Transaction<VaultV2WithdrawAction>>
55
+ * return tx;
56
+ * }
29
57
  * ```
30
58
  */
31
- export const vaultV2Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
32
- if (amount <= 0n) {
33
- throw new NonPositiveInputError("amount", amount);
59
+ export const vaultV2Withdraw = (params) => {
60
+ if (params.args.amount <= 0n) {
61
+ throw new NonPositiveInputError("amount", params.args.amount);
34
62
  }
35
- let tx = {
36
- to: vaultAddress,
63
+ // Validate the ABI bound before encoding to preserve the SDK's typed errors.
64
+ validateUint256Field("amount", params.args.amount);
65
+ const common = normalizeBundlesCommonParams(params.args);
66
+ const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
67
+ const sharesPermit = getBundlesSharesPermit({
68
+ vault: params.vault.address,
69
+ deadline: common.deadline,
70
+ owner: params.args.userAddress,
71
+ spender,
72
+ requirementSignature: params.args.requirementSignature,
73
+ });
74
+ const referralFeeAssets = getBundlesReferralFeeAssets(params.args.amount, common.referralFeePct);
75
+ return finalizeVaultBundlesV1Transaction({
76
+ chainId: params.vault.chainId,
77
+ value: 0n,
37
78
  data: encodeFunctionData({
38
- abi: vaultV2Abi,
39
- functionName: "withdraw",
40
- args: [amount, recipient, onBehalf],
79
+ abi: vaultBundlesV1Abi,
80
+ functionName: "vaultBundlesV1Withdraw",
81
+ args: [
82
+ params.vault.address,
83
+ params.args.amount,
84
+ 0n,
85
+ sharesPermit,
86
+ common.referralFeePct,
87
+ common.referralFeeRecipient,
88
+ common.deadline,
89
+ ],
41
90
  }),
42
- value: 0n,
43
- };
44
- if (metadata) {
45
- tx = addTransactionMetadata(tx, metadata);
46
- }
47
- return deepFreeze({
48
- ...tx,
49
91
  action: {
50
92
  type: "vaultV2Withdraw",
51
- args: { vault: vaultAddress, amount, recipient },
93
+ args: {
94
+ vault: params.vault.address,
95
+ amount: params.args.amount,
96
+ referralFeePct: common.referralFeePct,
97
+ referralFeeRecipient: common.referralFeeRecipient,
98
+ referralFeeAssets,
99
+ netAssets: params.args.amount - referralFeeAssets,
100
+ deadline: common.deadline,
101
+ },
52
102
  },
103
+ metadata: params.metadata,
53
104
  });
54
105
  };
@@ -655,8 +655,8 @@ export declare namespace BundlerAction {
655
655
  /**
656
656
  * Encodes a Vault V2 Blue Public Allocator market-to-market reallocation.
657
657
  *
658
- * @remarks Bundler3 must already hold the computed penalty assets. The
659
- * high-level Blue builders add the corresponding GeneralAdapter1 transfer.
658
+ * @remarks Bundler3 must already hold the computed penalty assets. Explicit low-level
659
+ * composition must add the corresponding GeneralAdapter1 transfer.
660
660
  *
661
661
  * @param chainId - Chain whose canonical Blue Public Allocator is called.
662
662
  * @param vault - Vault whose liquidity is reallocated.
@@ -720,8 +720,8 @@ export declare namespace BundlerAction {
720
720
  /**
721
721
  * Encodes a Vault V2 Blue Public Allocator allocation from vault idle liquidity.
722
722
  *
723
- * @remarks Bundler3 must already hold the computed penalty assets. The
724
- * high-level Blue builders add the corresponding GeneralAdapter1 transfer.
723
+ * @remarks Bundler3 must already hold the computed penalty assets. Explicit low-level
724
+ * composition must add the corresponding GeneralAdapter1 transfer.
725
725
  *
726
726
  * @param chainId - Chain whose canonical Blue Public Allocator is called.
727
727
  * @param vault - Vault whose idle liquidity is allocated.
@@ -1125,8 +1125,8 @@ export var BundlerAction;
1125
1125
  /**
1126
1126
  * Encodes a Vault V2 Blue Public Allocator market-to-market reallocation.
1127
1127
  *
1128
- * @remarks Bundler3 must already hold the computed penalty assets. The
1129
- * high-level Blue builders add the corresponding GeneralAdapter1 transfer.
1128
+ * @remarks Bundler3 must already hold the computed penalty assets. Explicit low-level
1129
+ * composition must add the corresponding GeneralAdapter1 transfer.
1130
1130
  *
1131
1131
  * @param chainId - Chain whose canonical Blue Public Allocator is called.
1132
1132
  * @param vault - Vault whose liquidity is reallocated.
@@ -1236,8 +1236,8 @@ export var BundlerAction;
1236
1236
  /**
1237
1237
  * Encodes a Vault V2 Blue Public Allocator allocation from vault idle liquidity.
1238
1238
  *
1239
- * @remarks Bundler3 must already hold the computed penalty assets. The
1240
- * high-level Blue builders add the corresponding GeneralAdapter1 transfer.
1239
+ * @remarks Bundler3 must already hold the computed penalty assets. Explicit low-level
1240
+ * composition must add the corresponding GeneralAdapter1 transfer.
1241
1241
  *
1242
1242
  * @param chainId - Chain whose canonical Blue Public Allocator is called.
1243
1243
  * @param vault - Vault whose idle liquidity is allocated.
@@ -12,7 +12,8 @@ import { type Metadata, type MorphoClientType } from "../types/index.js";
12
12
  * @param _options.metadata - Optional analytics metadata applied to every transaction the
13
13
  * `morpho` namespace builds.
14
14
  * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
15
- * permit / permit2. Defaults to `false` (classic approvals only).
15
+ * ERC-2612, Permit2 AllowanceTransfer or SignatureTransfer, and Morpho authorization.
16
+ * Defaults to `false` (standalone approvals and authorization calls only).
16
17
  * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
17
18
  * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
18
19
  * `client.morpho`.
@@ -52,7 +52,8 @@ function createMorphoNamespace(viemClient, options) {
52
52
  * @param _options.metadata - Optional analytics metadata applied to every transaction the
53
53
  * `morpho` namespace builds.
54
54
  * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
55
- * permit / permit2. Defaults to `false` (classic approvals only).
55
+ * ERC-2612, Permit2 AllowanceTransfer or SignatureTransfer, and Morpho authorization.
56
+ * Defaults to `false` (standalone approvals and authorization calls only).
56
57
  * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
57
58
  * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
58
59
  * `client.morpho`.