@morpho-org/morpho-sdk 6.0.0-next.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 (205) hide show
  1. package/MIGRATION-v5-to-v6.md +206 -3
  2. package/README.md +81 -41
  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 +1 -1
  6. package/lib/cjs/actions/blue/borrow.js +1 -1
  7. package/lib/cjs/actions/blue/common.d.ts +6 -19
  8. package/lib/cjs/actions/blue/common.js +25 -138
  9. package/lib/cjs/actions/blue/refinance.d.ts +1 -1
  10. package/lib/cjs/actions/blue/refinance.js +1 -1
  11. package/lib/cjs/actions/blue/repay.d.ts +3 -3
  12. package/lib/cjs/actions/blue/repay.js +1 -1
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
  15. package/lib/cjs/actions/blue/supply.d.ts +3 -3
  16. package/lib/cjs/actions/blue/supply.js +1 -1
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
  18. package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
  21. package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
  22. package/lib/cjs/actions/blue/withdraw.js +1 -1
  23. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
  24. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
  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 +1 -0
  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/getUnusedPermit2Nonce.d.ts +1 -1
  40. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
  41. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
  42. package/lib/cjs/actions/requirements/blue/index.js +0 -1
  43. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
  44. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  45. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
  46. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
  47. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +10 -4
  48. package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
  49. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +13 -13
  50. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  51. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  52. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
  53. package/lib/cjs/actions/requirements/encode/index.js +1 -1
  54. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
  55. package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
  56. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
  57. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  58. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
  59. package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
  60. package/lib/cjs/actions/vaultV1/deposit.js +110 -109
  61. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
  62. package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
  63. package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
  64. package/lib/cjs/actions/vaultV1/redeem.js +56 -33
  65. package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
  66. package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
  67. package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
  68. package/lib/cjs/actions/vaultV2/deposit.js +111 -109
  69. package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
  70. package/lib/cjs/actions/vaultV2/redeem.js +56 -34
  71. package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
  72. package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
  73. package/lib/cjs/entities/blue/blue.d.ts +19 -19
  74. package/lib/cjs/entities/blue/blue.js +3 -1
  75. package/lib/cjs/entities/index.d.ts +1 -0
  76. package/lib/cjs/entities/index.js +15 -0
  77. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  78. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
  79. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +61 -65
  80. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  81. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
  82. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  83. package/lib/cjs/entities/requirements/index.js +17 -0
  84. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
  85. package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
  86. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
  87. package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
  88. package/lib/cjs/helpers/index.d.ts +2 -1
  89. package/lib/cjs/helpers/index.js +5 -1
  90. package/lib/cjs/helpers/referralFee.d.ts +21 -0
  91. package/lib/cjs/helpers/referralFee.js +35 -0
  92. package/lib/cjs/helpers/slippage.d.ts +90 -1
  93. package/lib/cjs/helpers/slippage.js +123 -0
  94. package/lib/cjs/helpers/validate.d.ts +2 -0
  95. package/lib/cjs/helpers/validate.js +12 -1
  96. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  97. package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
  98. package/lib/cjs/index.d.ts +1 -0
  99. package/lib/cjs/index.js +1 -0
  100. package/lib/cjs/types/action.d.ts +179 -70
  101. package/lib/cjs/types/action.js +12 -12
  102. package/lib/cjs/types/error.d.ts +62 -14
  103. package/lib/cjs/types/error.js +88 -22
  104. package/lib/esm/abis.d.ts +210 -0
  105. package/lib/esm/abis.js +140 -0
  106. package/lib/esm/actions/blue/borrow.d.ts +1 -1
  107. package/lib/esm/actions/blue/borrow.js +1 -1
  108. package/lib/esm/actions/blue/common.d.ts +6 -19
  109. package/lib/esm/actions/blue/common.js +27 -140
  110. package/lib/esm/actions/blue/refinance.d.ts +1 -1
  111. package/lib/esm/actions/blue/refinance.js +1 -1
  112. package/lib/esm/actions/blue/repay.d.ts +3 -3
  113. package/lib/esm/actions/blue/repay.js +1 -1
  114. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  115. package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
  116. package/lib/esm/actions/blue/supply.d.ts +3 -3
  117. package/lib/esm/actions/blue/supply.js +1 -1
  118. package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
  119. package/lib/esm/actions/blue/supplyCollateral.js +1 -1
  120. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  121. package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
  122. package/lib/esm/actions/blue/withdraw.d.ts +1 -1
  123. package/lib/esm/actions/blue/withdraw.js +1 -1
  124. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
  125. package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
  126. package/lib/esm/actions/bundles/common.d.ts +200 -0
  127. package/lib/esm/actions/bundles/common.js +457 -0
  128. package/lib/esm/actions/bundles/index.d.ts +3 -0
  129. package/lib/esm/actions/bundles/index.js +2 -0
  130. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  131. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
  132. package/lib/esm/actions/index.d.ts +1 -0
  133. package/lib/esm/actions/index.js +1 -0
  134. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  135. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  136. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  137. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  138. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  139. package/lib/esm/actions/midnight/takeLend.js +2 -2
  140. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +1 -1
  141. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
  142. package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
  143. package/lib/esm/actions/requirements/blue/index.js +0 -1
  144. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
  145. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  146. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
  147. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
  148. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +10 -4
  149. package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
  150. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +11 -11
  151. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  152. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  153. package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
  154. package/lib/esm/actions/requirements/encode/index.js +1 -1
  155. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
  156. package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
  157. package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
  158. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  159. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
  160. package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
  161. package/lib/esm/actions/vaultV1/deposit.js +112 -111
  162. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
  163. package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
  164. package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
  165. package/lib/esm/actions/vaultV1/redeem.js +56 -33
  166. package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
  167. package/lib/esm/actions/vaultV1/withdraw.js +86 -34
  168. package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
  169. package/lib/esm/actions/vaultV2/deposit.js +113 -111
  170. package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
  171. package/lib/esm/actions/vaultV2/redeem.js +56 -34
  172. package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
  173. package/lib/esm/actions/vaultV2/withdraw.js +86 -35
  174. package/lib/esm/entities/blue/blue.d.ts +19 -19
  175. package/lib/esm/entities/blue/blue.js +4 -2
  176. package/lib/esm/entities/index.d.ts +1 -0
  177. package/lib/esm/entities/index.js +1 -0
  178. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  179. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
  180. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +51 -55
  181. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  182. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
  183. package/lib/esm/entities/requirements/index.d.ts +1 -0
  184. package/lib/esm/entities/requirements/index.js +1 -0
  185. package/lib/esm/entities/vaultV1/vaultV1.d.ts +348 -98
  186. package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
  187. package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
  188. package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
  189. package/lib/esm/helpers/index.d.ts +2 -1
  190. package/lib/esm/helpers/index.js +2 -1
  191. package/lib/esm/helpers/referralFee.d.ts +21 -0
  192. package/lib/esm/helpers/referralFee.js +31 -0
  193. package/lib/esm/helpers/slippage.d.ts +90 -1
  194. package/lib/esm/helpers/slippage.js +122 -2
  195. package/lib/esm/helpers/validate.d.ts +2 -0
  196. package/lib/esm/helpers/validate.js +11 -1
  197. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  198. package/lib/esm/helpers/validateRequirementSpender.js +1 -0
  199. package/lib/esm/index.d.ts +1 -0
  200. package/lib/esm/index.js +1 -0
  201. package/lib/esm/types/action.d.ts +179 -70
  202. package/lib/esm/types/action.js +11 -11
  203. package/lib/esm/types/error.d.ts +62 -14
  204. package/lib/esm/types/error.js +80 -16
  205. package/package.json +3 -3
@@ -1,134 +1,135 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vaultV1Deposit = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
5
  const viem_1 = require("viem");
7
- const index_js_1 = require("../../bundler/index.js");
8
- const index_js_2 = require("../../helpers/index.js");
9
- const index_js_3 = require("../../types/index.js");
10
- const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
6
+ const abis_js_1 = require("../../abis.js");
7
+ const validate_js_1 = require("../../helpers/validate.js");
8
+ const index_js_1 = require("../../types/index.js");
9
+ const common_js_1 = require("../bundles/common.js");
11
10
  /**
12
- * Prepares a deposit transaction for a VaultV1 (MetaMorpho) contract.
11
+ * Encodes a Vault V1 deposit through the registered VaultBundlesV1 contract.
13
12
  *
14
- * Routed through bundler3 to atomically execute the asset transfer and vault deposit. The
15
- * `GeneralAdapter1` enforces `maxSharePrice` on-chain to prevent inflation attacks. Never bypass
16
- * the general adapter.
17
- *
18
- * When `nativeAmount > 0`, that amount of native ETH is sent as `msg.value` to the bundler3
19
- * multicall and wrapped into wNative via `GeneralAdapter1.wrapNative()`. The vault's underlying
20
- * asset must be the chain's wrapped native token.
21
- *
22
- * @param params.vault.chainId - The chain the vault lives on.
23
- * @param params.vault.address - The VaultV1 (MetaMorpho) address.
24
- * @param params.vault.asset - The vault's underlying ERC-20 asset.
25
- * @param params.args.amount - Amount of ERC-20 assets to deposit. At least one of `amount` or
26
- * `nativeAmount` must be positive. Defaults to `0n`.
27
- * @param params.args.maxSharePrice - Maximum acceptable share price (in RAY, slippage
28
- * protection enforced on-chain by `GeneralAdapter1`).
29
- * @param params.args.recipient - Address that receives the minted vault shares.
30
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
31
- * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
32
- * deposit. Requires the vault asset to be the chain's wNative.
33
- * @param params.metadata - Optional analytics metadata attached to the bundle.
34
- * @returns A deep-frozen `Transaction<VaultV1DepositAction>` with `to`, `value`, `data`, and the
35
- * typed `action` discriminator the simulation layer consumes.
36
- * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
37
- * @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, or when both `amount` and
38
- * `nativeAmount` resolve to zero.
39
- * @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
40
- * configured wNative.
41
- * @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
42
- * asset is not the chain's wNative.
43
- * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
44
- * `requirementSignature` is provided and the signed asset differs from `vault.asset`. The
45
- * signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
46
- * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
47
- * `requirementSignature` is provided and the signed amount differs from `args.amount`.
48
- * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
49
- * Permit2 requirement signature is missing its expiration.
13
+ * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
14
+ * @param params.vault.address - Vault V1 contract receiving the net deposit.
15
+ * @param params.vault.asset - Underlying ERC-20 asset; must be the chain's wNative for native funding.
16
+ * @param params.args.amount - Positive gross ERC-20 amount in asset base units, exclusive with `nativeAmount`.
17
+ * @param params.args.nativeAmount - Positive gross native amount in wei, exclusive with `amount` and
18
+ * `requirementSignature`; sent as `tx.value` and wrapped by VaultBundlesV1.
19
+ * @param params.args.maxSharePrice - Positive maximum asset base units per share base unit, scaled
20
+ * by RAY (1e27). Compute it for the net deposit after referral fees to bound slippage.
21
+ * @param params.args.userAddress - Permit owner and transaction sender; VaultBundlesV1 mints shares to this account.
22
+ * @param params.args.recipient - Unsupported; shares are always minted to the transaction sender.
23
+ * @param params.args.requirementSignature - Optional ERC-2612 or Permit2 SignatureTransfer signature
24
+ * for the gross amount, vault asset, `userAddress`, and VaultBundlesV1 spender.
25
+ * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
26
+ * The fee is rounded down and deducted from gross assets before depositing.
27
+ * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
28
+ * when `referralFeePct > 0n`.
29
+ * @param params.args.deadline - Positive uint256 Unix timestamp in seconds after which execution
30
+ * reverts. The caller must supply it; the builder chooses no default.
31
+ * @param params.metadata - Optional analytics metadata appended to the transaction calldata.
32
+ * @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
33
+ * @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
34
+ * @returns A deep-frozen `Transaction<VaultV1DepositAction>` targeting VaultBundlesV1, with
35
+ * `to`, `value`, `data`, and gross/fee/net deposit action metadata.
36
+ * @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
37
+ * @throws {NegativeInputError} when the selected funding amount or `referralFeePct` is negative.
38
+ * @throws {NonPositiveInputError} when funding, `maxSharePrice`, or `deadline` is not positive.
39
+ * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
40
+ * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
41
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD; it extends
42
+ * {@link InputExceedsMaxError}, so either class catches it.
43
+ * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
44
+ * @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit or a
45
+ * Permit2 AllowanceTransfer signature is supplied.
46
+ * @throws {InputExceedsMaxError} when funding, `maxSharePrice`, or `deadline` exceeds uint256.
47
+ * @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
48
+ * @throws {DepositAssetMismatchError} when the signed asset differs from the vault asset.
49
+ * @throws {DepositAmountMismatchError} when the signed amount differs from the gross funding amount.
50
+ * @throws {DepositSpenderMismatchError} when the signed spender is not VaultBundlesV1.
51
+ * @throws {BundlesRequirementSignatureMismatchError} when the signature deadline, nonce, or encoding is invalid.
52
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
53
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
50
54
  * @example
51
55
  * ```ts
56
+ * import { vaults } from "@morpho-org/morpho-test";
52
57
  * import { vaultV1Deposit } from "@morpho-org/morpho-sdk";
58
+ * import type { Address } from "viem";
59
+ * import { mainnet } from "viem/chains";
53
60
  *
54
- * const tx = vaultV1Deposit({
55
- * vault: { chainId: 1, address: vaultAddress, asset: USDC },
56
- * args: {
57
- * amount: 1_000_000n,
58
- * maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
59
- * recipient: depositor,
60
- * },
61
- * });
62
- * // tx satisfies Readonly<Transaction<VaultV1DepositAction>>
61
+ * export function buildSteakUsdcDeposit(
62
+ * userAddress: Address,
63
+ * maxSharePrice: bigint,
64
+ * deadline: bigint,
65
+ * ) {
66
+ * const vault = vaults[mainnet.id].steakUsdc;
67
+ * const tx = vaultV1Deposit({
68
+ * vault: { chainId: mainnet.id, address: vault.address, asset: vault.asset },
69
+ * args: { amount: 1_000_000n, maxSharePrice, userAddress, deadline },
70
+ * });
71
+ * // tx satisfies Readonly<Transaction<VaultV1DepositAction>>
72
+ * return tx;
73
+ * }
63
74
  * ```
64
75
  */
65
- const vaultV1Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args: { amount = 0n, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }) => {
66
- if (amount < 0n) {
67
- throw new index_js_3.NegativeInputError("amount", amount);
76
+ const vaultV1Deposit = (params) => {
77
+ const funding = (0, common_js_1.resolveBundlesFunding)(params.args);
78
+ if (params.args.maxSharePrice <= 0n) {
79
+ throw new index_js_1.NonPositiveInputError("maxSharePrice", params.args.maxSharePrice);
68
80
  }
69
- if (maxSharePrice <= 0n) {
70
- throw new index_js_3.NonPositiveInputError("maxSharePrice", maxSharePrice);
71
- }
72
- const actions = [];
73
- const { bundler3: { generalAdapter1, bundler3 }, wNative, } = (0, blue_sdk_1.getChainAddresses)(chainId);
74
- if (nativeAmount) {
75
- if (nativeAmount < 0n) {
76
- throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
77
- }
78
- if (!(0, morpho_ts_1.isDefined)(wNative)) {
79
- throw new index_js_3.ChainWNativeMissingError(chainId);
81
+ // Reject ABI overflow with SDK errors before calldata encoding.
82
+ (0, validate_js_1.validateUint256Field)(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
83
+ (0, validate_js_1.validateUint256Field)("maxSharePrice", params.args.maxSharePrice);
84
+ if (funding.value > 0n) {
85
+ // Reject native funding unless the vault accepts the chain's wrapped-native asset.
86
+ (0, validate_js_1.validateNativeVaultAsset)(params.vault.chainId, params.vault.asset);
87
+ if (params.args.requirementSignature != null) {
88
+ throw new index_js_1.UnexpectedRequirementSignatureError(params.args.requirementSignature.action.type);
80
89
  }
81
- if (!(0, viem_1.isAddressEqual)(asset, wNative)) {
82
- throw new index_js_3.NativeAmountOnNonWNativeVaultError(asset, wNative);
83
- }
84
- actions.push(
85
- // Transfers native token from Bundler3 to GeneralAdapter1 for wrapping.
86
- {
87
- type: "nativeTransfer",
88
- args: [bundler3, generalAdapter1, nativeAmount, false /* skipRevert */],
89
- }, {
90
- type: "wrapNative",
91
- args: [nativeAmount, generalAdapter1, false /* skipRevert */],
92
- });
93
- }
94
- if (amount > 0n) {
95
- actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
96
- asset,
97
- amount,
98
- recipient: generalAdapter1,
99
- requirementSignature,
100
- }));
101
90
  }
102
- const totalAssets = amount + (nativeAmount ?? 0n);
103
- if (totalAssets === 0n) {
104
- throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
105
- }
106
- actions.push({
107
- type: "erc4626Deposit",
108
- args: [
109
- vaultAddress,
110
- totalAssets,
111
- maxSharePrice,
112
- recipient,
113
- false /* skipRevert */,
114
- ],
91
+ const common = (0, common_js_1.normalizeBundlesCommonParams)(params.args);
92
+ const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
93
+ const netAssets = funding.assets - referralFeeAssets;
94
+ const spender = (0, morpho_ts_1.getChainAddress)(params.vault.chainId, "bundles.vaultBundlesV1");
95
+ const tokenPermit = (0, common_js_1.getBundlesTokenPermit)({
96
+ userAddress: params.args.userAddress,
97
+ token: params.vault.asset,
98
+ spender,
99
+ amount: funding.assets,
100
+ requirementSignature: params.args.requirementSignature,
115
101
  });
116
- let tx = index_js_1.BundlerAction.encodeBundle(chainId, actions);
117
- if (metadata) {
118
- tx = (0, index_js_2.addTransactionMetadata)(tx, metadata);
119
- }
120
- return (0, morpho_ts_1.deepFreeze)({
121
- ...tx,
102
+ return (0, common_js_1.finalizeVaultBundlesV1Transaction)({
103
+ chainId: params.vault.chainId,
104
+ value: funding.value,
105
+ data: (0, viem_1.encodeFunctionData)({
106
+ abi: abis_js_1.vaultBundlesV1Abi,
107
+ functionName: "vaultBundlesV1Deposit",
108
+ args: [
109
+ params.vault.address,
110
+ funding.assets,
111
+ params.args.maxSharePrice,
112
+ tokenPermit,
113
+ common.referralFeePct,
114
+ common.referralFeeRecipient,
115
+ common.deadline,
116
+ ],
117
+ }),
122
118
  action: {
123
119
  type: "vaultV1Deposit",
124
120
  args: {
125
- vault: vaultAddress,
126
- amount,
127
- maxSharePrice,
128
- recipient,
129
- nativeAmount,
121
+ vault: params.vault.address,
122
+ amount: funding.assets,
123
+ maxSharePrice: params.args.maxSharePrice,
124
+ nativeAmount: funding.value || undefined,
125
+ referralFeePct: common.referralFeePct,
126
+ referralFeeRecipient: common.referralFeeRecipient,
127
+ referralFeeAssets,
128
+ netAssets,
129
+ deadline: common.deadline,
130
130
  },
131
131
  },
132
+ metadata: params.metadata,
132
133
  });
133
134
  };
134
135
  exports.vaultV1Deposit = vaultV1Deposit;
@@ -1,85 +1,62 @@
1
1
  import { type Address } from "viem";
2
- import { type Metadata, type PermitRequirementSignature, type Transaction, type VaultV1MigrateToV2Action } from "../../types/index.js";
2
+ import { type Erc2612RequirementSignature, type Metadata, type Transaction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs } from "../../types/index.js";
3
3
  /** Parameters for {@link vaultV1MigrateToV2}. */
4
4
  export interface VaultV1MigrateToV2Params {
5
- vault: {
6
- chainId: number;
7
- address: Address;
8
- /** Underlying asset of the source V1 vault. */
9
- asset: Address;
5
+ readonly vault: {
6
+ readonly chainId: number;
7
+ readonly address: Address;
8
+ readonly asset: Address;
10
9
  };
11
- args: {
12
- targetVault: Address;
13
- /** Underlying asset of the target V2 vault. */
14
- targetAsset: Address;
15
- /** Number of V1 shares to migrate. */
16
- shares: bigint;
17
- /** Minimum acceptable share price for V1 redeem (slippage protection, in RAY). */
18
- minSharePriceVaultV1: bigint;
19
- /** Maximum acceptable share price for V2 deposit (inflation protection, in RAY). */
20
- maxSharePriceVaultV2: bigint;
21
- /** Receives the V2 vault shares. */
22
- recipient: Address;
23
- /** Pre-signed permit/permit2 approval for V1 share transfer. */
24
- requirementSignature?: PermitRequirementSignature;
10
+ readonly args: VaultV1MigrateToV2AmountArgs & {
11
+ readonly targetVault: Address;
12
+ readonly targetAsset: Address;
13
+ readonly maxSharePriceVaultV2: bigint;
14
+ readonly userAddress: Address;
15
+ readonly recipient?: never;
16
+ readonly minSharePriceVaultV1?: never;
17
+ readonly requirementSignature?: Erc2612RequirementSignature;
18
+ readonly referralFeePct?: bigint;
19
+ readonly referralFeeRecipient?: Address;
20
+ readonly deadline: bigint;
25
21
  };
26
- metadata?: Metadata;
22
+ readonly metadata?: Metadata;
27
23
  }
28
24
  /**
29
- * Prepares an atomic full-migration transaction from VaultV1 to VaultV2.
25
+ * Encodes an assets-or-shares Vault V1 to Vault V2 migration through VaultBundlesV1.
30
26
  *
31
- * Routed through bundler3: transfers V1 shares to `GeneralAdapter1` (via `erc20TransferFrom` or
32
- * permit/permit2), redeems them via `erc4626Redeem` (GA1 redeems its own shares — no allowance
33
- * check), then deposits the resulting assets into V2 via `erc4626Deposit`. All operations
34
- * execute atomically in a single transaction.
35
- *
36
- * Prerequisite: the user must either approve `GeneralAdapter1` to spend their V1 vault shares
37
- * (classic approve) or provide a pre-signed permit/permit2 via `requirementSignature`. Use
38
- * `getRequirements()` on the entity to resolve the appropriate approval.
39
- *
40
- * @param params.vault.chainId - The chain the source vault lives on (used to resolve bundler
41
- * addresses).
42
- * @param params.vault.address - The source VaultV1 (MetaMorpho) address.
43
- * @param params.vault.asset - The underlying asset of the source V1 vault.
44
- * @param params.args.targetVault - The target VaultV2 address.
45
- * @param params.args.targetAsset - The underlying asset of the target V2 vault. Must equal
46
- * `vault.asset`.
47
- * @param params.args.shares - Number of V1 shares to migrate.
48
- * @param params.args.minSharePriceVaultV1 - Minimum V1 share price in RAY (slippage protection
49
- * for the redeem leg).
50
- * @param params.args.maxSharePriceVaultV2 - Maximum V2 share price in RAY (inflation protection
51
- * for the deposit leg).
52
- * @param params.args.recipient - Address that receives the V2 vault shares.
53
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 for the V1 share
54
- * transfer.
55
- * @param params.metadata - Optional analytics metadata attached to the bundle.
56
- * @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
57
- * the typed `action` discriminator the simulation layer consumes.
58
- * @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
59
- * @throws {NonPositiveInputError} when `shares <= 0n` or `maxSharePriceVaultV2 <= 0n`.
60
- * @throws {NegativeInputError} when `minSharePriceVaultV1 < 0n`.
61
- * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
62
- * is provided and the signed asset differs from `vault.address` (the V1 share token).
63
- * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
64
- * is provided and the signed amount differs from `args.shares`.
65
- * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
66
- * signature is missing its expiration.
27
+ * @param params - Source/destination vaults, exclusive migration amount, fee, permit, and deadline.
28
+ * @returns A deep-frozen VaultBundlesV1 migration transaction.
29
+ * @throws {VaultAssetMismatchError} when source and destination assets differ.
30
+ * @throws {SameVaultMigrationError} when source and destination vaults are identical.
31
+ * @throws {AmountAndSharesExclusiveError} when both amount modes or neither are supplied.
32
+ * @throws {NonPositiveInputError} when the selected amount, destination share-price bound, or deadline is not positive.
33
+ * @throws {InputExceedsMaxError} when the selected amount, `maxSharePriceVaultV2`, 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 non-zero 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.
67
40
  * @example
68
41
  * ```ts
69
42
  * import { vaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
70
43
  *
71
44
  * const tx = vaultV1MigrateToV2({
72
- * vault: { chainId: 1, address: sourceVault, asset: USDC },
45
+ * vault: {
46
+ * chainId: 1,
47
+ * address: "0x0000000000000000000000000000000000000001",
48
+ * asset: "0x0000000000000000000000000000000000000003",
49
+ * },
73
50
  * args: {
74
- * targetVault,
75
- * targetAsset: USDC,
76
51
  * shares: 1_000_000n,
77
- * minSharePriceVaultV1: 0n, // disables redeem-leg slippage protection — production code should compute from source vault state + slippage tolerance
78
- * maxSharePriceVaultV2: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
79
- * recipient,
52
+ * targetVault: "0x0000000000000000000000000000000000000002",
53
+ * targetAsset: "0x0000000000000000000000000000000000000003",
54
+ * maxSharePriceVaultV2: 1_000_000_000_000_000_000_000_000_000n,
55
+ * userAddress: "0x0000000000000000000000000000000000000004",
56
+ * deadline: 1_900_000_000n,
80
57
  * },
81
58
  * });
82
- * // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
59
+ * // tx.action.type === "vaultV1MigrateToV2"
83
60
  * ```
84
61
  */
85
- export declare const vaultV1MigrateToV2: ({ vault: { chainId, address: sourceVault, asset: sourceAsset }, args: { targetVault, targetAsset, shares, minSharePriceVaultV1, maxSharePriceVaultV2, recipient, requirementSignature, }, metadata, }: VaultV1MigrateToV2Params) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
62
+ export declare const vaultV1MigrateToV2: (params: VaultV1MigrateToV2Params) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
@@ -1,136 +1,123 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vaultV1MigrateToV2 = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
5
  const viem_1 = require("viem");
7
- const index_js_1 = require("../../bundler/index.js");
8
- const index_js_2 = require("../../helpers/index.js");
9
- const index_js_3 = require("../../types/index.js");
10
- const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
6
+ const abis_js_1 = require("../../abis.js");
7
+ const validate_js_1 = require("../../helpers/validate.js");
8
+ const index_js_1 = require("../../types/index.js");
9
+ const common_js_1 = require("../bundles/common.js");
11
10
  /**
12
- * Prepares an atomic full-migration transaction from VaultV1 to VaultV2.
11
+ * Encodes an assets-or-shares Vault V1 to Vault V2 migration through VaultBundlesV1.
13
12
  *
14
- * Routed through bundler3: transfers V1 shares to `GeneralAdapter1` (via `erc20TransferFrom` or
15
- * permit/permit2), redeems them via `erc4626Redeem` (GA1 redeems its own shares — no allowance
16
- * check), then deposits the resulting assets into V2 via `erc4626Deposit`. All operations
17
- * execute atomically in a single transaction.
18
- *
19
- * Prerequisite: the user must either approve `GeneralAdapter1` to spend their V1 vault shares
20
- * (classic approve) or provide a pre-signed permit/permit2 via `requirementSignature`. Use
21
- * `getRequirements()` on the entity to resolve the appropriate approval.
22
- *
23
- * @param params.vault.chainId - The chain the source vault lives on (used to resolve bundler
24
- * addresses).
25
- * @param params.vault.address - The source VaultV1 (MetaMorpho) address.
26
- * @param params.vault.asset - The underlying asset of the source V1 vault.
27
- * @param params.args.targetVault - The target VaultV2 address.
28
- * @param params.args.targetAsset - The underlying asset of the target V2 vault. Must equal
29
- * `vault.asset`.
30
- * @param params.args.shares - Number of V1 shares to migrate.
31
- * @param params.args.minSharePriceVaultV1 - Minimum V1 share price in RAY (slippage protection
32
- * for the redeem leg).
33
- * @param params.args.maxSharePriceVaultV2 - Maximum V2 share price in RAY (inflation protection
34
- * for the deposit leg).
35
- * @param params.args.recipient - Address that receives the V2 vault shares.
36
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 for the V1 share
37
- * transfer.
38
- * @param params.metadata - Optional analytics metadata attached to the bundle.
39
- * @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
40
- * the typed `action` discriminator the simulation layer consumes.
41
- * @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
42
- * @throws {NonPositiveInputError} when `shares <= 0n` or `maxSharePriceVaultV2 <= 0n`.
43
- * @throws {NegativeInputError} when `minSharePriceVaultV1 < 0n`.
44
- * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
45
- * is provided and the signed asset differs from `vault.address` (the V1 share token).
46
- * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
47
- * is provided and the signed amount differs from `args.shares`.
48
- * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
49
- * signature is missing its expiration.
13
+ * @param params - Source/destination vaults, exclusive migration amount, fee, permit, and deadline.
14
+ * @returns A deep-frozen VaultBundlesV1 migration transaction.
15
+ * @throws {VaultAssetMismatchError} when source and destination assets differ.
16
+ * @throws {SameVaultMigrationError} when source and destination vaults are identical.
17
+ * @throws {AmountAndSharesExclusiveError} when both amount modes or neither are supplied.
18
+ * @throws {NonPositiveInputError} when the selected amount, destination share-price bound, or deadline is not positive.
19
+ * @throws {InputExceedsMaxError} when the selected amount, `maxSharePriceVaultV2`, or `deadline` exceeds uint256.
20
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
21
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
22
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
23
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
24
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
25
+ * @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
50
26
  * @example
51
27
  * ```ts
52
28
  * import { vaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
53
29
  *
54
30
  * const tx = vaultV1MigrateToV2({
55
- * vault: { chainId: 1, address: sourceVault, asset: USDC },
31
+ * vault: {
32
+ * chainId: 1,
33
+ * address: "0x0000000000000000000000000000000000000001",
34
+ * asset: "0x0000000000000000000000000000000000000003",
35
+ * },
56
36
  * args: {
57
- * targetVault,
58
- * targetAsset: USDC,
59
37
  * shares: 1_000_000n,
60
- * minSharePriceVaultV1: 0n, // disables redeem-leg slippage protection — production code should compute from source vault state + slippage tolerance
61
- * maxSharePriceVaultV2: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
62
- * recipient,
38
+ * targetVault: "0x0000000000000000000000000000000000000002",
39
+ * targetAsset: "0x0000000000000000000000000000000000000003",
40
+ * maxSharePriceVaultV2: 1_000_000_000_000_000_000_000_000_000n,
41
+ * userAddress: "0x0000000000000000000000000000000000000004",
42
+ * deadline: 1_900_000_000n,
63
43
  * },
64
44
  * });
65
- * // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
45
+ * // tx.action.type === "vaultV1MigrateToV2"
66
46
  * ```
67
47
  */
68
- const vaultV1MigrateToV2 = ({ vault: { chainId, address: sourceVault, asset: sourceAsset }, args: { targetVault, targetAsset, shares, minSharePriceVaultV1, maxSharePriceVaultV2, recipient, requirementSignature, }, metadata, }) => {
69
- // Both bundle legs use maxUint256: an asset mismatch leaves the redeemed
70
- // source asset stranded on GA1 while the user receives only dust shares.
71
- if (!(0, viem_1.isAddressEqual)(sourceAsset, targetAsset)) {
72
- throw new index_js_3.VaultAssetMismatchError(sourceAsset, targetAsset);
48
+ const vaultV1MigrateToV2 = (params) => {
49
+ if (!(0, viem_1.isAddressEqual)(params.vault.asset, params.args.targetAsset)) {
50
+ throw new index_js_1.VaultAssetMismatchError(params.vault.asset, params.args.targetAsset);
73
51
  }
74
- if (shares <= 0n) {
75
- throw new index_js_3.NonPositiveInputError("shares", shares);
52
+ if ((0, viem_1.isAddressEqual)(params.vault.address, params.args.targetVault)) {
53
+ throw new index_js_1.SameVaultMigrationError(params.vault.address);
76
54
  }
77
- if (minSharePriceVaultV1 < 0n) {
78
- throw new index_js_3.NegativeInputError("minSharePriceVaultV1", minSharePriceVaultV1);
55
+ const assets = "assets" in params.args ? params.args.assets : undefined;
56
+ const shares = "shares" in params.args ? params.args.shares : undefined;
57
+ if ((assets == null) === (shares == null)) {
58
+ throw new index_js_1.AmountAndSharesExclusiveError();
79
59
  }
80
- if (maxSharePriceVaultV2 <= 0n) {
81
- throw new index_js_3.NonPositiveInputError("maxSharePriceVaultV2", maxSharePriceVaultV2);
60
+ const selectedAmount = assets ?? shares ?? 0n;
61
+ if (selectedAmount <= 0n) {
62
+ throw new index_js_1.NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
82
63
  }
83
- const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
84
- const actions = [];
85
- // Transfer V1 shares from user to GA1.
86
- // With a signature: permit/permit2 + transferFrom for the signed amount.
87
- // Without a signature: use ERC-20 transferFrom for the specified shares amount.
88
- actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
89
- asset: sourceVault,
64
+ if (params.args.maxSharePriceVaultV2 <= 0n) {
65
+ throw new index_js_1.NonPositiveInputError("maxSharePriceVaultV2", params.args.maxSharePriceVaultV2);
66
+ }
67
+ // Reject ABI overflow with SDK errors before calldata encoding.
68
+ (0, validate_js_1.validateUint256Field)(assets != null ? "assets" : "shares", selectedAmount);
69
+ (0, validate_js_1.validateUint256Field)("maxSharePriceVaultV2", params.args.maxSharePriceVaultV2);
70
+ const common = (0, common_js_1.normalizeBundlesCommonParams)(params.args);
71
+ const spender = (0, morpho_ts_1.getChainAddress)(params.vault.chainId, "bundles.vaultBundlesV1");
72
+ const sharesPermit = (0, common_js_1.getBundlesSharesPermit)({
73
+ vault: params.vault.address,
74
+ deadline: common.deadline,
75
+ owner: params.args.userAddress,
76
+ spender,
90
77
  amount: shares,
91
- recipient: generalAdapter1,
92
- requirementSignature,
93
- }));
94
- // GA1 redeems its own shares (owner = GA1, no allowance check).
95
- actions.push({
96
- type: "erc4626Redeem",
97
- args: [
98
- sourceVault,
99
- viem_1.maxUint256,
100
- minSharePriceVaultV1,
101
- generalAdapter1,
102
- generalAdapter1,
103
- false /* skipRevert */,
104
- ],
105
- });
106
- // Deposit all resulting assets into V2.
107
- actions.push({
108
- type: "erc4626Deposit",
109
- args: [
110
- targetVault,
111
- viem_1.maxUint256,
112
- maxSharePriceVaultV2,
113
- recipient,
114
- false /* skipRevert */,
115
- ],
78
+ requirementSignature: params.args.requirementSignature,
116
79
  });
117
- let tx = index_js_1.BundlerAction.encodeBundle(chainId, actions);
118
- if (metadata) {
119
- tx = (0, index_js_2.addTransactionMetadata)(tx, metadata);
120
- }
121
- return (0, morpho_ts_1.deepFreeze)({
122
- ...tx,
80
+ const referralFeeAssets = assets == null
81
+ ? undefined
82
+ : (0, common_js_1.getBundlesReferralFeeAssets)(assets, common.referralFeePct);
83
+ return (0, common_js_1.finalizeVaultBundlesV1Transaction)({
84
+ chainId: params.vault.chainId,
85
+ value: 0n,
86
+ data: (0, viem_1.encodeFunctionData)({
87
+ abi: abis_js_1.vaultBundlesV1Abi,
88
+ functionName: "vaultBundlesV1Migrate",
89
+ args: [
90
+ params.vault.address,
91
+ params.args.targetVault,
92
+ assets ?? 0n,
93
+ shares ?? 0n,
94
+ params.args.maxSharePriceVaultV2,
95
+ sharesPermit,
96
+ common.referralFeePct,
97
+ common.referralFeeRecipient,
98
+ common.deadline,
99
+ ],
100
+ }),
123
101
  action: {
124
102
  type: "vaultV1MigrateToV2",
125
103
  args: {
126
- sourceVault,
127
- targetVault,
128
- shares,
129
- minSharePriceVaultV1,
130
- maxSharePriceVaultV2,
131
- recipient,
104
+ sourceVault: params.vault.address,
105
+ targetVault: params.args.targetVault,
106
+ assets: assets ?? 0n,
107
+ shares: shares ?? 0n,
108
+ maxSharePriceVaultV2: params.args.maxSharePriceVaultV2,
109
+ referralFeePct: common.referralFeePct,
110
+ referralFeeRecipient: common.referralFeeRecipient,
111
+ ...(assets != null && referralFeeAssets != null
112
+ ? {
113
+ referralFeeAssets,
114
+ netAssets: assets - referralFeeAssets,
115
+ }
116
+ : {}),
117
+ deadline: common.deadline,
132
118
  },
133
119
  },
120
+ metadata: params.metadata,
134
121
  });
135
122
  };
136
123
  exports.vaultV1MigrateToV2 = vaultV1MigrateToV2;