@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
@@ -2,7 +2,7 @@ import { type AccrualVaultV2, type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
5
- import { type ActionOutput, type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2InKindRedeemAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
5
+ import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type Deallocation, type MorphoClientType, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2InKindRedeemAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
6
6
  export interface VaultV2Actions {
7
7
  /**
8
8
  * Fetches the latest vault data.
@@ -14,67 +14,208 @@ export interface VaultV2Actions {
14
14
  */
15
15
  getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
16
16
  /**
17
- * Prepares a deposit transaction for the VaultV2 contract.
17
+ * Prepares a Vault V2 deposit through the registered VaultBundlesV1 contract.
18
18
  *
19
- * This function constructs the transaction data required to deposit a specified amount of assets into the vault.
20
- * Uses pre-fetched vault data for accurate calculations of slippage and asset address,
21
- * then returns the prepared deposit transaction and a function for retrieving all required approval transactions.
22
- * Bundler Integration: This flow uses the bundler to atomically execute the user's asset transfer and vault deposit in a single transaction for slippage protection.
19
+ * Uses the supplied vault snapshot to compute the deadline-accrued `maxSharePrice`.
20
+ * `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612 or
21
+ * Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
22
+ * always minted to the transaction sender, which must be `userAddress`.
23
+ * Concurrent requirement reads share the first caller's options; later calls refresh on-chain
24
+ * state using their own options. `buildTx()` accepts signatures from the latest completed read.
23
25
  *
24
- * @param {Object} params - The deposit parameters.
25
- * @param {bigint} [params.amount=0n] - Amount of ERC-20 assets to deposit. At least one of amount or nativeAmount must be provided.
26
- * @param {Address} params.userAddress - User address initiating the deposit.
27
- * @param {AccrualVaultV2} params.vaultData - Pre-fetched vault data with asset address and share conversion.
28
- * @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Optional slippage tolerance value. Default is 0.03%. Slippage tolerance must be less than 10%.
29
- * @param {bigint} [params.nativeAmount] - Amount of native token to wrap into wNative. Vault asset must be wNative.
30
- * @returns {Object} The result object.
31
- * @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
32
- * @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>} returns.getRequirements The function for retrieving all required approval transactions.
26
+ * @param params.userAddress - Account that funds, signs, submits, and receives the vault shares.
27
+ * @param params.vaultData - Pre-fetched Vault V2 snapshot used for asset and share conversion.
28
+ * @param params.amount - Optional gross ERC-20 assets; exclusive with `nativeAmount`.
29
+ * @param params.nativeAmount - Optional gross native assets; exclusive with `amount` and valid
30
+ * only for a wNative vault.
31
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to 0.03% and cannot
32
+ * exceed 10%.
33
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%, deducted before
34
+ * the vault deposit.
35
+ * @param params.referralFeeRecipient - Non-zero recipient required for a positive referral fee.
36
+ * @param params.deadline - Optional execution and permit deadline in Unix seconds; defaults to
37
+ * two hours from handle creation.
38
+ * @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
39
+ * transaction builder.
40
+ * @throws {ChainIdMismatchError} when the connected client targets another chain.
41
+ * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
42
+ * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
43
+ * @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
44
+ * @throws {NegativeInputError} when funding, slippage, the referral fee, or a Permit2 nonce is negative.
45
+ * @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
46
+ * @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
47
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
48
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
49
+ * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
50
+ * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
51
+ * @throws {MissingPermit2SignatureTransferNonceError} from `getRequirements()` when Permit2 is
52
+ * selected without an explicit nonce.
53
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
54
+ * explicit Permit2 nonce is consumed.
55
+ * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
56
+ * `getRequirements()` when the Permit2 nonce exceeds uint256.
57
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
58
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
59
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature was not produced for
60
+ * this prepared handle.
61
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
62
+ * @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the vault asset.
63
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when signature metadata is malformed.
64
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
65
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered.
66
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
67
+ * @example
68
+ * ```ts
69
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
70
+ * import { createPublicClient, http, type Address, zeroAddress } from "viem";
71
+ * import { mainnet } from "viem/chains";
72
+ *
73
+ * const keyrockUsdcVaultV2 =
74
+ * "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
75
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
76
+ * .extend(morphoViemExtension());
77
+ * const vault = client.morpho.vaultV2(keyrockUsdcVaultV2, mainnet.id);
78
+ * const vaultData = await vault.getData();
79
+ * const action = vault.deposit({
80
+ * amount: 1_000_000n,
81
+ * userAddress: zeroAddress,
82
+ * vaultData,
83
+ * });
84
+ * const requirements = await action.getRequirements(); // Satisfy these first.
85
+ * const tx = action.buildTx(); // For a client configured with supportSignature: false.
86
+ * // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
87
+ * ```
33
88
  */
34
89
  deposit: (params: {
35
- userAddress: Address;
36
- vaultData: AccrualVaultV2;
37
- slippageTolerance?: bigint;
38
- } & DepositAmountArgs) => {
39
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
40
- getRequirements: (params?: {
41
- useSimplePermit?: boolean;
42
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
43
- };
90
+ readonly userAddress: Address;
91
+ readonly vaultData: AccrualVaultV2;
92
+ readonly slippageTolerance?: bigint;
93
+ readonly referralFeePct?: bigint;
94
+ readonly referralFeeRecipient?: Address;
95
+ readonly deadline?: bigint;
96
+ } & BundlesFundingArgs) => ActionOutput<VaultV2DepositAction, readonly RequirementSignature[], BundlesTokenRequirementsOptions>;
44
97
  /**
45
- * Prepares a withdraw transaction for the VaultV2 contract.
98
+ * Prepares an exact-assets Vault V2 withdrawal through VaultBundlesV1.
46
99
  *
47
- * This function constructs the transaction data required to withdraw a specified amount of assets from the vault.
100
+ * Reads the vault accrual state on the first `getRequirements()` call, then reads the live
101
+ * vault-share allowance and, when a signature is needed, the permit nonce on each call.
102
+ * Captures the requested amount and owner at creation, so later changes to `params` do not
103
+ * change this handle's requirements or transaction.
48
104
  *
49
- * @param {Object} params - The withdraw parameters.
50
- * @param {bigint} params.amount - The amount of assets to withdraw.
51
- * @param {Address} params.userAddress - User address initiating the withdraw.
52
- * @returns {Object} The result object.
53
- * @returns {Readonly<Transaction<VaultV2WithdrawAction>>} returns.tx The prepared withdraw transaction.
105
+ * @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
106
+ * @param params.userAddress - Share owner that must sign and submit; receives the net assets.
107
+ * @param params.slippageTolerance - Optional WAD-scaled share-price loss tolerance applied to
108
+ * the share cap.
109
+ * Defaults to 0.03% and cannot exceed 10%.
110
+ * @param params.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero;
111
+ * rounded down and deducted from the gross withdrawn assets.
112
+ * @param params.referralFeeRecipient - Optional nonzero recipient required for a positive fee.
113
+ * @param params.deadline - Optional execution and share-permit deadline in Unix seconds;
114
+ * defaults to two hours from handle creation.
115
+ * @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
116
+ * which returns a deep-frozen `Transaction<VaultV2WithdrawAction>`. Requirements are empty
117
+ * when the allowance equals the cap; otherwise they contain an exact approval or, with
118
+ * signature support, an ERC-2612 request. The cap stays pinned to the first resolution while
119
+ * each call re-reads the allowance. Confirm the approval or pass its signed permit to `buildTx`.
120
+ * @throws {ChainIdMismatchError} when the connected client targets another chain.
121
+ * @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
122
+ * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
123
+ * at any `getRequirements()` call.
124
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
125
+ * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
126
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
127
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
128
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
129
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
130
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
131
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
132
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
133
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed,
134
+ * was not resolved for this handle, or has incompatible vault, owner, spender, amount,
135
+ * deadline, or nonce values.
136
+ * @throws {viem.BaseError} when a vault, allowance, or nonce read or transaction encoding fails.
137
+ * @example
138
+ * ```ts
139
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
140
+ * import { createPublicClient, http, type Address } from "viem";
141
+ * import { mainnet } from "viem/chains";
142
+ *
143
+ * export async function prepareUsdcWithdrawal(userAddress: Address) {
144
+ * const vaultAddress = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
145
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
146
+ * .extend(morphoViemExtension({ supportSignature: false }));
147
+ * const vault = client.morpho.vaultV2(vaultAddress, mainnet.id);
148
+ * const action = vault.withdraw({ amount: 1_000_000n, userAddress });
149
+ * const requirements = await action.getRequirements();
150
+ * // Send and confirm each approval before calling action.buildTx().
151
+ * // action.buildTx() returns Readonly<Transaction<VaultV2WithdrawAction>>.
152
+ * return { action, requirements }; // Prepared handle and its outstanding share approvals.
153
+ * }
154
+ * ```
54
155
  */
55
156
  withdraw: (params: {
56
- amount: bigint;
57
- userAddress: Address;
58
- }) => {
59
- buildTx: () => Readonly<Transaction<VaultV2WithdrawAction>>;
60
- };
157
+ readonly amount: bigint;
158
+ readonly userAddress: Address;
159
+ readonly slippageTolerance?: bigint;
160
+ readonly referralFeePct?: bigint;
161
+ readonly referralFeeRecipient?: Address;
162
+ readonly deadline?: bigint;
163
+ }) => ActionOutput<VaultV2WithdrawAction, readonly RequirementSignature[], undefined>;
61
164
  /**
62
- * Prepares a redeem transaction for the VaultV2 contract.
165
+ * Prepares an exact-shares Vault V2 redemption through VaultBundlesV1.
63
166
  *
64
- * This function constructs the transaction data required to redeem a specified amount of shares from the vault.
167
+ * Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
168
+ * The caller must satisfy the exact vault-share allowance returned by `getRequirements()` before
169
+ * `buildTx()`; every requirement resolution re-reads the live allowance and checks the deadline.
170
+ * `buildTx()` accepts permits from the latest completed requirement resolution.
65
171
  *
66
172
  * @param {Object} params - The redeem parameters.
67
- * @param {bigint} params.shares - The amount of shares to redeem.
68
- * @param {Address} params.userAddress - User address initiating the redeem.
69
- * @returns {Object} The result object.
70
- * @returns {Readonly<Transaction<VaultV2RedeemAction>>} returns.tx The prepared redeem transaction.
173
+ * @param {bigint} params.shares - Exact vault shares to burn.
174
+ * @param {Address} params.userAddress - Account that must sign and submit the transaction; VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`.
175
+ * @param {bigint} [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be below WAD.
176
+ * @param {Address} [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
177
+ * @param {bigint} [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
178
+ * @returns Lazy exact share-allowance requirements and a synchronous transaction builder.
179
+ * @throws {ChainIdMismatchError} when the client and entity target different chains.
180
+ * @throws {NonPositiveInputError} when `shares` is not positive.
181
+ * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
182
+ * requirement resolution.
183
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
184
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
185
+ * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
186
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
187
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
188
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance or nonce read fails.
189
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
190
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
191
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit does not match the
192
+ * resolved share cap, spender, owner, nonce, or deadline.
193
+ * @example
194
+ * ```ts
195
+ * import { isRequirementSignature } from "@morpho-org/morpho-sdk";
196
+ *
197
+ * const vault = client.morpho.vaultV2(vaultAddress, 1);
198
+ * const redemption = vault.redeem({ shares: 1_000_000n, userAddress });
199
+ * const signatures = [];
200
+ * for (const requirement of await redemption.getRequirements()) {
201
+ * if (isRequirementSignature(requirement)) {
202
+ * signatures.push(await requirement.sign(walletClient, userAddress));
203
+ * } else {
204
+ * const hash = await walletClient.sendTransaction(requirement);
205
+ * await client.waitForTransactionReceipt({ hash });
206
+ * }
207
+ * }
208
+ * const tx = redemption.buildTx(signatures);
209
+ * // tx satisfies Readonly<Transaction<VaultV2RedeemAction>>
210
+ * ```
71
211
  */
72
212
  redeem: (params: {
73
- shares: bigint;
74
- userAddress: Address;
75
- }) => {
76
- buildTx: () => Readonly<Transaction<VaultV2RedeemAction>>;
77
- };
213
+ readonly shares: bigint;
214
+ readonly userAddress: Address;
215
+ readonly referralFeePct?: bigint;
216
+ readonly referralFeeRecipient?: Address;
217
+ readonly deadline?: bigint;
218
+ }) => ActionOutput<VaultV2RedeemAction, readonly RequirementSignature[], undefined>;
78
219
  /**
79
220
  * Prepares an illiquid Vault V2 exit into idle assets and Morpho Blue supply positions.
80
221
  *
@@ -214,28 +355,40 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
214
355
  private readonly chainId;
215
356
  constructor(client: MorphoClientType, vault: Address, chainId: number);
216
357
  getData(parameters?: FetchParameters): Promise<AccrualVaultV2>;
217
- deposit({ amount, userAddress, vaultData, slippageTolerance, nativeAmount, }: {
218
- userAddress: Address;
219
- vaultData: AccrualVaultV2;
220
- slippageTolerance?: bigint;
221
- } & DepositAmountArgs): {
222
- getRequirements: (params?: {
223
- useSimplePermit?: boolean;
224
- }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
358
+ /** {@inheritDoc VaultV2Actions.deposit} */
359
+ deposit(params: {
360
+ readonly userAddress: Address;
361
+ readonly vaultData: AccrualVaultV2;
362
+ readonly slippageTolerance?: bigint;
363
+ readonly referralFeePct?: bigint;
364
+ readonly referralFeeRecipient?: Address;
365
+ readonly deadline?: bigint;
366
+ } & BundlesFundingArgs): Readonly<{
367
+ getRequirements: (requirementOptions?: BundlesTokenRequirementsOptions) => Promise<readonly ActionRequirement[]>;
225
368
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
226
- };
227
- withdraw({ amount, userAddress }: {
228
- amount: bigint;
229
- userAddress: Address;
230
- }): {
231
- buildTx: () => Readonly<Transaction<VaultV2WithdrawAction>>;
232
- };
233
- redeem({ shares, userAddress }: {
234
- shares: bigint;
235
- userAddress: Address;
236
- }): {
237
- buildTx: () => Readonly<Transaction<VaultV2RedeemAction>>;
238
- };
369
+ }>;
370
+ withdraw(params: {
371
+ readonly amount: bigint;
372
+ readonly userAddress: Address;
373
+ readonly slippageTolerance?: bigint;
374
+ readonly referralFeePct?: bigint;
375
+ readonly referralFeeRecipient?: Address;
376
+ readonly deadline?: bigint;
377
+ }): Readonly<{
378
+ getRequirements: () => Promise<readonly ActionRequirement[]>;
379
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2WithdrawAction>>;
380
+ }>;
381
+ /** {@inheritDoc VaultV2Actions.redeem} */
382
+ redeem(params: {
383
+ readonly shares: bigint;
384
+ readonly userAddress: Address;
385
+ readonly referralFeePct?: bigint;
386
+ readonly referralFeeRecipient?: Address;
387
+ readonly deadline?: bigint;
388
+ }): Readonly<{
389
+ getRequirements: () => Promise<readonly ActionRequirement[]>;
390
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2RedeemAction>>;
391
+ }>;
239
392
  /** {@inheritDoc VaultV2Actions.inKindRedeem} */
240
393
  inKindRedeem({ amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }: {
241
394
  readonly amount: bigint;