@morpho-org/morpho-sdk 10.0.0-next.0 → 10.0.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 (282) hide show
  1. package/README.md +104 -12
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +1 -5
  4. package/lib/cjs/actions/blue/common.js +4 -2
  5. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
  6. package/lib/cjs/actions/bundles/common.js +20 -14
  7. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -1
  8. package/lib/cjs/actions/midnight/cancelOffers.js +2 -1
  9. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
  10. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
  11. package/lib/cjs/actions/midnight/takeBorrow.js +2 -1
  12. package/lib/cjs/actions/midnight/takeLend.js +2 -1
  13. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
  14. package/lib/cjs/actions/midnight/takeWithdraw.js +2 -1
  15. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -11
  17. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  18. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  19. package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
  20. package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
  21. package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
  22. package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
  23. package/lib/cjs/blue/abis.d.ts +1 -1
  24. package/lib/cjs/blue/abis.js +1 -5
  25. package/lib/cjs/blue/entities.d.ts +4 -4
  26. package/lib/cjs/blue/entities.js +1 -3
  27. package/lib/cjs/blue/errors.d.ts +2 -2
  28. package/lib/cjs/blue/errors.js +1 -5
  29. package/lib/cjs/blue/fetch.d.ts +2 -2
  30. package/lib/cjs/blue/fetch.js +1 -3
  31. package/lib/cjs/blue/utils.d.ts +1 -1
  32. package/lib/cjs/blue/utils.js +1 -2
  33. package/lib/cjs/entities/blue/blue.js +8 -4
  34. package/lib/cjs/entities/index.d.ts +4 -4
  35. package/lib/cjs/entities/index.js +1 -3
  36. package/lib/cjs/entities/midnight/deadline.js +2 -1
  37. package/lib/cjs/entities/midnight/midnight.js +14 -7
  38. package/lib/cjs/entities/midnight/publication.js +73 -44
  39. package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
  40. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +9 -13
  41. package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
  42. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
  43. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
  44. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  45. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
  46. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  47. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
  48. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  49. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
  50. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  51. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
  52. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  53. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
  54. package/lib/cjs/entities/vaultV1/vaultV1.js +51 -181
  55. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  56. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
  57. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  58. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
  59. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +8 -34
  60. package/lib/cjs/entities/vaultV2/vaultV2.js +62 -429
  61. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +2 -3
  62. package/lib/cjs/entities/vaultV2BlueReallocationData.js +346 -234
  63. package/lib/cjs/errors.d.ts +4 -4
  64. package/lib/cjs/errors.js +6 -7
  65. package/lib/cjs/fetch.d.ts +2 -2
  66. package/lib/cjs/fetch.js +1 -3
  67. package/lib/cjs/helpers/deadShares.js +34 -19
  68. package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
  69. package/lib/cjs/helpers/metadata.js +12 -6
  70. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -5
  71. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +6 -3
  72. package/lib/cjs/helpers/utilization.js +10 -5
  73. package/lib/cjs/helpers/validate.js +12 -6
  74. package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
  75. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
  76. package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
  77. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +44 -22
  78. package/lib/cjs/helpers/validatePositiveInput.js +2 -1
  79. package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
  80. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +14 -7
  81. package/lib/cjs/index.d.ts +2 -2
  82. package/lib/cjs/index.js +10 -1
  83. package/lib/cjs/midnight/errors.d.ts +1 -2
  84. package/lib/cjs/midnight/errors.js +4 -5
  85. package/lib/cjs/transactionPlan/approval.js +12 -1
  86. package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
  87. package/lib/cjs/transactionPlan/deposit.js +139 -0
  88. package/lib/cjs/transactionPlan/error.d.ts +10 -8
  89. package/lib/cjs/transactionPlan/error.js +10 -8
  90. package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
  91. package/lib/cjs/transactionPlan/index.d.ts +18 -0
  92. package/lib/cjs/transactionPlan/index.js +23 -5
  93. package/lib/cjs/transactionPlan/intent.d.ts +3 -3
  94. package/lib/cjs/transactionPlan/intent.js +14 -7
  95. package/lib/cjs/transactionPlan/permit.d.ts +1 -1
  96. package/lib/cjs/transactionPlan/permit.js +86 -20
  97. package/lib/cjs/transactionPlan/plan.d.ts +16 -6
  98. package/lib/cjs/transactionPlan/plan.js +72 -22
  99. package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
  100. package/lib/cjs/transactionPlan/redeem.js +63 -0
  101. package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
  102. package/lib/cjs/transactionPlan/requirements.js +12 -6
  103. package/lib/cjs/transactionPlan/serde.d.ts +2 -2
  104. package/lib/cjs/transactionPlan/serde.js +41 -15
  105. package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
  106. package/lib/cjs/transactionPlan/shareSpending.js +50 -0
  107. package/lib/cjs/transactionPlan/types.d.ts +117 -11
  108. package/lib/cjs/transactionPlan/validateActions.js +11 -1
  109. package/lib/cjs/transactionPlan/validation.js +6 -3
  110. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
  111. package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
  112. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  113. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
  114. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  115. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
  116. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
  117. package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
  118. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  119. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
  120. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +14 -31
  121. package/lib/cjs/transactionPlan/vaultv2/deposit.js +15 -141
  122. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  123. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
  124. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  125. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
  126. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  127. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
  128. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
  129. package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
  130. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +14 -27
  131. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +17 -124
  132. package/lib/cjs/transactionPlan/version.js +2 -1
  133. package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
  134. package/lib/cjs/transactionPlan/withdraw.js +94 -0
  135. package/lib/cjs/types/action.js +16 -8
  136. package/lib/cjs/types/error.d.ts +8 -1
  137. package/lib/cjs/types/error.js +10 -1
  138. package/lib/cjs/utils.d.ts +2 -2
  139. package/lib/cjs/utils.js +2 -4
  140. package/lib/cjs/version.d.ts +1 -1
  141. package/lib/cjs/version.js +1 -1
  142. package/lib/esm/abis.d.ts +1 -1
  143. package/lib/esm/abis.js +1 -1
  144. package/lib/esm/actions/blue/common.js +4 -2
  145. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
  146. package/lib/esm/actions/bundles/common.js +20 -14
  147. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -1
  148. package/lib/esm/actions/midnight/cancelOffers.js +2 -1
  149. package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
  150. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
  151. package/lib/esm/actions/midnight/takeBorrow.js +2 -1
  152. package/lib/esm/actions/midnight/takeLend.js +2 -1
  153. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
  154. package/lib/esm/actions/midnight/takeWithdraw.js +2 -1
  155. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
  156. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +4 -13
  157. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  158. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  159. package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
  160. package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
  161. package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
  162. package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
  163. package/lib/esm/blue/abis.d.ts +1 -1
  164. package/lib/esm/blue/abis.js +1 -1
  165. package/lib/esm/blue/entities.d.ts +4 -4
  166. package/lib/esm/blue/entities.js +2 -2
  167. package/lib/esm/blue/errors.d.ts +2 -2
  168. package/lib/esm/blue/errors.js +2 -2
  169. package/lib/esm/blue/fetch.d.ts +2 -2
  170. package/lib/esm/blue/fetch.js +2 -2
  171. package/lib/esm/blue/utils.d.ts +1 -1
  172. package/lib/esm/blue/utils.js +1 -1
  173. package/lib/esm/entities/blue/blue.js +8 -4
  174. package/lib/esm/entities/index.d.ts +4 -4
  175. package/lib/esm/entities/index.js +2 -2
  176. package/lib/esm/entities/midnight/deadline.js +2 -1
  177. package/lib/esm/entities/midnight/midnight.js +14 -7
  178. package/lib/esm/entities/midnight/publication.js +73 -44
  179. package/lib/esm/entities/requirements/assertContractCode.js +4 -2
  180. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +10 -14
  181. package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
  182. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
  183. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
  184. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  185. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
  186. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  187. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
  188. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  189. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
  190. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  191. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
  192. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  193. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
  194. package/lib/esm/entities/vaultV1/vaultV1.js +57 -187
  195. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  196. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
  197. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  198. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
  199. package/lib/esm/entities/vaultV2/vaultV2.d.ts +8 -34
  200. package/lib/esm/entities/vaultV2/vaultV2.js +70 -437
  201. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +2 -3
  202. package/lib/esm/entities/vaultV2BlueReallocationData.js +346 -234
  203. package/lib/esm/errors.d.ts +4 -4
  204. package/lib/esm/errors.js +4 -4
  205. package/lib/esm/fetch.d.ts +2 -2
  206. package/lib/esm/fetch.js +2 -2
  207. package/lib/esm/helpers/deadShares.js +35 -20
  208. package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
  209. package/lib/esm/helpers/metadata.js +12 -6
  210. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -5
  211. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +6 -3
  212. package/lib/esm/helpers/utilization.js +10 -5
  213. package/lib/esm/helpers/validate.js +12 -6
  214. package/lib/esm/helpers/validateMidnightBounds.js +2 -1
  215. package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
  216. package/lib/esm/helpers/validateMidnightPublication.js +4 -2
  217. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +44 -22
  218. package/lib/esm/helpers/validatePositiveInput.js +2 -1
  219. package/lib/esm/helpers/validateTakeableOffers.js +2 -1
  220. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +14 -7
  221. package/lib/esm/index.d.ts +2 -2
  222. package/lib/esm/index.js +1 -1
  223. package/lib/esm/midnight/errors.d.ts +1 -2
  224. package/lib/esm/midnight/errors.js +1 -2
  225. package/lib/esm/transactionPlan/approval.js +13 -2
  226. package/lib/esm/transactionPlan/deposit.d.ts +22 -0
  227. package/lib/esm/transactionPlan/deposit.js +135 -0
  228. package/lib/esm/transactionPlan/error.d.ts +10 -8
  229. package/lib/esm/transactionPlan/error.js +10 -8
  230. package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
  231. package/lib/esm/transactionPlan/index.d.ts +18 -0
  232. package/lib/esm/transactionPlan/index.js +9 -0
  233. package/lib/esm/transactionPlan/intent.d.ts +3 -3
  234. package/lib/esm/transactionPlan/intent.js +14 -7
  235. package/lib/esm/transactionPlan/permit.d.ts +1 -1
  236. package/lib/esm/transactionPlan/permit.js +86 -20
  237. package/lib/esm/transactionPlan/plan.d.ts +16 -6
  238. package/lib/esm/transactionPlan/plan.js +68 -18
  239. package/lib/esm/transactionPlan/redeem.d.ts +18 -0
  240. package/lib/esm/transactionPlan/redeem.js +59 -0
  241. package/lib/esm/transactionPlan/requirements.d.ts +4 -3
  242. package/lib/esm/transactionPlan/requirements.js +12 -6
  243. package/lib/esm/transactionPlan/serde.d.ts +2 -2
  244. package/lib/esm/transactionPlan/serde.js +41 -15
  245. package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
  246. package/lib/esm/transactionPlan/shareSpending.js +47 -0
  247. package/lib/esm/transactionPlan/types.d.ts +117 -11
  248. package/lib/esm/transactionPlan/validateActions.js +11 -1
  249. package/lib/esm/transactionPlan/validation.js +6 -3
  250. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
  251. package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
  252. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  253. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
  254. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  255. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
  256. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
  257. package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
  258. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  259. package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
  260. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +14 -31
  261. package/lib/esm/transactionPlan/vaultv2/deposit.js +17 -142
  262. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  263. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
  264. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  265. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
  266. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  267. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
  268. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
  269. package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
  270. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +14 -27
  271. package/lib/esm/transactionPlan/vaultv2/withdraw.js +19 -125
  272. package/lib/esm/transactionPlan/version.js +2 -1
  273. package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
  274. package/lib/esm/transactionPlan/withdraw.js +90 -0
  275. package/lib/esm/types/action.js +16 -8
  276. package/lib/esm/types/error.d.ts +8 -1
  277. package/lib/esm/types/error.js +10 -1
  278. package/lib/esm/utils.d.ts +2 -2
  279. package/lib/esm/utils.js +2 -2
  280. package/lib/esm/version.d.ts +1 -1
  281. package/lib/esm/version.js +1 -1
  282. package/package.json +15 -15
@@ -0,0 +1,93 @@
1
+ import type { AccrualVault } from "@morpho-org/blue-sdk";
2
+ import type { Client } from "viem";
3
+ import type { Transaction, VaultV1DepositAction } from "../../types/index.js";
4
+ import { type DepositPlanParams } from "../deposit.js";
5
+ import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
6
+ /**
7
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
8
+ * Caller intent for a Vault V1 (MetaMorpho) deposit, mirroring the Actions API deposit inputs,
9
+ * plus the snapshot. The fields match `VaultV2DepositPlanParams` except for the snapshot type.
10
+ * @example
11
+ * ```ts
12
+ * import { vaults } from "@morpho-org/morpho-test";
13
+ * import type { VaultV1DepositPlanParams } from "@morpho-org/morpho-sdk";
14
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
15
+ * import { type Address, createPublicClient, http } from "viem";
16
+ * import { mainnet } from "viem/chains";
17
+ *
18
+ * export async function steakUsdcDepositParams(account: Address) {
19
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
20
+ * const vault = vaults[mainnet.id].steakUsdc.address;
21
+ * const params: VaultV1DepositPlanParams = {
22
+ * chainId: mainnet.id, account, assets: 1_000_000n,
23
+ * vault: await fetchAccrualVault(vault, client),
24
+ * };
25
+ * // params satisfies VaultV1DepositPlanParams
26
+ * return params;
27
+ * }
28
+ * ```
29
+ */
30
+ export interface VaultV1DepositPlanParams extends DepositPlanParams<AccrualVault> {
31
+ }
32
+ /**
33
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
34
+ * Prepares a Vault V1 (MetaMorpho) deposit plan through VaultBundlesV1 from caller intent and a
35
+ * vault snapshot, reading the token prerequisites directly. The built deposit matches the
36
+ * `vaultV1(...).deposit(...)` handle's `buildTx()` for the same inputs. The quote is fixed on the deposit step at preparation, so the returned plan is static:
37
+ * only signatures are added before building.
38
+ * @param client - Viem client for `params.chainId`, used for allowance and permit metadata reads only.
39
+ * @param params.vault - Caller-fetched AccrualVault snapshot used for the quote; its address identifies the vault.
40
+ * @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
41
+ * @param params.account - Non-zero account funding, signing and sending the deposit.
42
+ * @param params.assets - Positive gross deposit in asset base units, before referral fees.
43
+ * @param params.funding.type - Optional funding source: `"erc20"` (default) or `"native"`; native funding requires the vault asset to be wNative.
44
+ * @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
45
+ * @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
46
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
47
+ * @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
48
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
49
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
50
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
51
+ * @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
52
+ * @returns A plan with approvals, concrete signature requests and the deposit step.
53
+ * @throws {ZeroAccountError} when `account` is the zero address.
54
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
55
+ * @throws {NonPositiveInputError} when `expiresAt`, `assets`, net assets or previewed shares are not positive.
56
+ * @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
57
+ * @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
58
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
59
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
60
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
61
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
62
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
63
+ * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
64
+ * @throws {ChainIdMismatchError} when the client targets another chain.
65
+ * @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
66
+ * @see computeVaultMaxSharePrice for quote errors.
67
+ * @example
68
+ * ```ts
69
+ * import { vaults } from "@morpho-org/morpho-test";
70
+ * import { prepareVaultV1Deposit } from "@morpho-org/morpho-sdk";
71
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
72
+ * import { type Address, createPublicClient, http } from "viem";
73
+ * import { mainnet } from "viem/chains";
74
+ *
75
+ * export async function prepareSteakUsdcDeposit(account: Address) {
76
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
77
+ * const vault = vaults[mainnet.id].steakUsdc.address;
78
+ * const plan = await prepareVaultV1Deposit(client, {
79
+ * chainId: mainnet.id, account, assets: 1_000_000n, supportSignature: true,
80
+ * vault: await fetchAccrualVault(vault, client),
81
+ * now: (await client.getBlock()).timestamp,
82
+ * });
83
+ * // plan satisfies TransactionPlan: approval or permit request, then the vaultV1Deposit step.
84
+ * // Sign the pending requests, applySignatures, then build.
85
+ * return plan;
86
+ * }
87
+ * ```
88
+ */
89
+ export declare function prepareVaultV1Deposit(client: Client, params: VaultV1DepositPlanParams): Promise<TransactionPlan>;
90
+ /** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
91
+ export declare function buildVaultV1Deposit(action: Extract<Action, {
92
+ type: "vaultV1Deposit";
93
+ }>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV1DepositAction>>;
@@ -0,0 +1,90 @@
1
+ import { getChainAddress } from "@morpho-org/morpho-ts";
2
+ import { selectBundlesTokenRequirementSignature } from "../../actions/bundles/common.js";
3
+ import { vaultV1Deposit } from "../../actions/vaultV1/deposit.js";
4
+ import { prepareVaultDeposit } from "../deposit.js";
5
+ import { getVaultPermit } from "../permit.js";
6
+ /**
7
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
8
+ * Prepares a Vault V1 (MetaMorpho) deposit plan through VaultBundlesV1 from caller intent and a
9
+ * vault snapshot, reading the token prerequisites directly. The built deposit matches the
10
+ * `vaultV1(...).deposit(...)` handle's `buildTx()` for the same inputs. The quote is fixed on the deposit step at preparation, so the returned plan is static:
11
+ * only signatures are added before building.
12
+ * @param client - Viem client for `params.chainId`, used for allowance and permit metadata reads only.
13
+ * @param params.vault - Caller-fetched AccrualVault snapshot used for the quote; its address identifies the vault.
14
+ * @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
15
+ * @param params.account - Non-zero account funding, signing and sending the deposit.
16
+ * @param params.assets - Positive gross deposit in asset base units, before referral fees.
17
+ * @param params.funding.type - Optional funding source: `"erc20"` (default) or `"native"`; native funding requires the vault asset to be wNative.
18
+ * @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
19
+ * @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
20
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
21
+ * @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
22
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
23
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
24
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
25
+ * @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
26
+ * @returns A plan with approvals, concrete signature requests and the deposit step.
27
+ * @throws {ZeroAccountError} when `account` is the zero address.
28
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
29
+ * @throws {NonPositiveInputError} when `expiresAt`, `assets`, net assets or previewed shares are not positive.
30
+ * @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
31
+ * @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
32
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
33
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
34
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
35
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
36
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
37
+ * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
38
+ * @throws {ChainIdMismatchError} when the client targets another chain.
39
+ * @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
40
+ * @see computeVaultMaxSharePrice for quote errors.
41
+ * @example
42
+ * ```ts
43
+ * import { vaults } from "@morpho-org/morpho-test";
44
+ * import { prepareVaultV1Deposit } from "@morpho-org/morpho-sdk";
45
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
46
+ * import { type Address, createPublicClient, http } from "viem";
47
+ * import { mainnet } from "viem/chains";
48
+ *
49
+ * export async function prepareSteakUsdcDeposit(account: Address) {
50
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
51
+ * const vault = vaults[mainnet.id].steakUsdc.address;
52
+ * const plan = await prepareVaultV1Deposit(client, {
53
+ * chainId: mainnet.id, account, assets: 1_000_000n, supportSignature: true,
54
+ * vault: await fetchAccrualVault(vault, client),
55
+ * now: (await client.getBlock()).timestamp,
56
+ * });
57
+ * // plan satisfies TransactionPlan: approval or permit request, then the vaultV1Deposit step.
58
+ * // Sign the pending requests, applySignatures, then build.
59
+ * return plan;
60
+ * }
61
+ * ```
62
+ */
63
+ export async function prepareVaultV1Deposit(client, params) {
64
+ return prepareVaultDeposit(client, { ...params, type: "vaultV1Deposit" });
65
+ }
66
+ /** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
67
+ export function buildVaultV1Deposit(action, requests) {
68
+ const { asset, chainId, account, assets, nativeAssets, ...args } = action.inputs;
69
+ const signature = getVaultPermit(requests, {
70
+ id: action.signatureRequestIds.tokenPermit,
71
+ asset,
72
+ owner: account,
73
+ });
74
+ const requirementSignature = selectBundlesTokenRequirementSignature(signature ? [signature] : [], {
75
+ spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
76
+ amount: assets ?? nativeAssets,
77
+ deadline: action.inputs.deadline,
78
+ });
79
+ return vaultV1Deposit({
80
+ vault: { chainId, address: action.inputs.vault, asset },
81
+ args: {
82
+ ...args,
83
+ ...(nativeAssets === undefined
84
+ ? { amount: assets }
85
+ : { nativeAmount: nativeAssets }),
86
+ userAddress: account,
87
+ requirementSignature,
88
+ },
89
+ });
90
+ }
@@ -0,0 +1,96 @@
1
+ import type { AccrualVault, MarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Client } from "viem";
3
+ import { type ReferenceTimestampParams, type Transaction, type VaultV1InKindRedeemAction } from "../../types/index.js";
4
+ import { type IntentParams } from "../intent.js";
5
+ import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
6
+ /**
7
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
8
+ * Caller intent and snapshot for an asset-denominated Vault V1 in-kind exit.
9
+ * @example
10
+ * ```ts
11
+ * import type { VaultV1InKindRedeemPlanParams } from "@morpho-org/morpho-sdk";
12
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
13
+ * import { createPublicClient, http } from "viem";
14
+ * import { mainnet } from "viem/chains";
15
+ *
16
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
17
+ * const vaultAddress = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"; // Mainnet steakUSDC Vault V1.
18
+ * const vault = await fetchAccrualVault(vaultAddress, client);
19
+ * const marketParamsList = [...vault.allocations.values()]
20
+ * .filter(({ config, position }) => config.enabled && position.supplyShares > 0n)
21
+ * .map(({ position }) => position.market.params);
22
+ * const params: VaultV1InKindRedeemPlanParams = {
23
+ * chainId: mainnet.id, account: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
24
+ * vault, assets: 1_000_000n, marketParamsList,
25
+ * };
26
+ * // params satisfies VaultV1InKindRedeemPlanParams
27
+ * ```
28
+ */
29
+ export interface VaultV1InKindRedeemPlanParams extends Omit<IntentParams, "referralFee" | "deployless">, ReferenceTimestampParams {
30
+ readonly vault: AccrualVault;
31
+ /** Exact exit assets in underlying-token base units, not shares. */
32
+ readonly assets: bigint;
33
+ /** Ordered enabled markets with enough vault supply to cover the exit. */
34
+ readonly marketParamsList: readonly MarketParams[];
35
+ }
36
+ /**
37
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
38
+ * Prepares the stable Vault V1 in-kind exit through VaultExitBundlesV1.
39
+ * All market inputs are copied during preparation; building requires no client or further reads.
40
+ * Insufficient share allowance produces an unlimited direct approval or ERC-2612 permit, never Permit2.
41
+ * The asset-denominated exit has no on-chain share-price or max-shares bound; a price drop before
42
+ * inclusion can burn more shares than quoted.
43
+ * @param params.vault - Caller-fetched AccrualVault snapshot; its address identifies the vault.
44
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
45
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
46
+ * @param client - Viem client used for chain, code and requirement reads.
47
+ * @param params - Account, asset amount, ordered markets and caller-fetched vault snapshot.
48
+ * @returns A data-only plan with the exit and any share approval or signature request.
49
+ * @throws {ZeroAccountError} when `account` is the zero address.
50
+ * @throws {NonIntegerInputError} when `expiresAt` is not a safe integer.
51
+ * @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
52
+ * @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
53
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
54
+ * @throws {ChainIdMismatchError} when the client declares or its RPC serves another chain.
55
+ * @throws {EmptyMarketParamsListError} when no markets are supplied.
56
+ * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
57
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 or Morpho Blue is not registered on the chain.
58
+ * @throws {InKindRedeemCoverageError} when the ordered markets cannot cover `assets` without overusing an allocation.
59
+ * @throws {MissingContractCodeError} when VaultExitBundlesV1 or Morpho Blue has no deployed code.
60
+ * @throws {viem.BaseError} when a chain, code, allowance, nonce, balance or contract configuration read fails, or inputs cannot be ABI-encoded.
61
+ * @throws {VaultMorphoMismatchError} when the vault's `MORPHO` differs from the registered Morpho Blue contract.
62
+ * @throws {VaultIsBlueFeeRecipientError} when the vault is Morpho Blue's fee recipient, an unsupported configuration.
63
+ * @throws {InsufficientBlueBalanceForInKindRedeemError} when Morpho Blue's asset balance is below `assets`.
64
+ * @throws {UnsupportedPermitDomainExtensionsError} when a required share permit advertises unsupported EIP-5267 extensions.
65
+ * @throws {InvalidPermitDomainChainIdError} when a required share permit domain targets another chain or omits `chainId`.
66
+ * @throws {InvalidPermitDomainVerifyingContractError} when a required share permit domain targets another token or omits `verifyingContract`.
67
+ * @throws {MissingPermitDomainNameError} when a required share permit has neither an EIP-5267 domain nor a token name.
68
+ * @see computeVaultMaxShareAllowance for snapshot accrual and share-quote errors.
69
+ * @see MorphoVaultV1.inKindRedeem for snapshot and onchain preflight validation.
70
+ * @example
71
+ * ```ts
72
+ * import { prepareVaultV1InKindRedeem } from "@morpho-org/morpho-sdk";
73
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
74
+ * import { createPublicClient, http } from "viem";
75
+ * import { mainnet } from "viem/chains";
76
+ *
77
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
78
+ * const vaultAddress = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"; // Mainnet steakUSDC Vault V1.
79
+ * const vault = await fetchAccrualVault(vaultAddress, client);
80
+ * const marketParamsList = [...vault.allocations.values()]
81
+ * .filter(({ config, position }) => config.enabled && position.supplyShares > 0n)
82
+ * .map(({ position }) => position.market.params);
83
+ * const plan = await prepareVaultV1InKindRedeem(client, {
84
+ * chainId: mainnet.id, account: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
85
+ * vault, assets: 1_000_000n, marketParamsList,
86
+ * });
87
+ * // plan satisfies TransactionPlan: { version, chainId, account, expiresAt, steps, signatureRequests }
88
+ * ```
89
+ */
90
+ export declare function prepareVaultV1InKindRedeem(client: Client, params: VaultV1InKindRedeemPlanParams): Promise<TransactionPlan>;
91
+ /** @internal Encodes the fixed in-kind exit with its referenced permit. */
92
+ export declare function buildVaultV1InKindRedeem(action: Extract<Action, {
93
+ type: "vaultV1InKindRedeem";
94
+ }>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV1InKindRedeemAction>>;
95
+ /** @internal Validates the stored in-kind action and ordered market structs. */
96
+ export declare function validateInKindRedeemPlanAction(action: Record<string, unknown>, path: string): void;
@@ -0,0 +1,198 @@
1
+ import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
2
+ import { maxUint256 } from "viem";
3
+ import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
4
+ import { vaultV1InKindRedeem } from "../../actions/vaultV1/inKindRedeem.js";
5
+ import { getVaultV1InKindRedeemRequirements } from "../../entities/requirements/getVaultV1InKindRedeemRequirements.js";
6
+ import { computeVaultV1InKindRedeemQuote } from "../../entities/vaultV1/inKindRedeemQuote.js";
7
+ import { validateChainId } from "../../helpers/validate.js";
8
+ import { isRequirementApproval, UnsupportedRequirementSignatureError, } from "../../types/index.js";
9
+ import { resolveIntent } from "../intent.js";
10
+ import { getVaultPermit } from "../permit.js";
11
+ import { buildApprovalStep, buildPermitSignatureRequest, } from "../requirements.js";
12
+ import { getPlanObject, validatePlanFields } from "../validation.js";
13
+ /**
14
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
15
+ * Prepares the stable Vault V1 in-kind exit through VaultExitBundlesV1.
16
+ * All market inputs are copied during preparation; building requires no client or further reads.
17
+ * Insufficient share allowance produces an unlimited direct approval or ERC-2612 permit, never Permit2.
18
+ * The asset-denominated exit has no on-chain share-price or max-shares bound; a price drop before
19
+ * inclusion can burn more shares than quoted.
20
+ * @param params.vault - Caller-fetched AccrualVault snapshot; its address identifies the vault.
21
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
22
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
23
+ * @param client - Viem client used for chain, code and requirement reads.
24
+ * @param params - Account, asset amount, ordered markets and caller-fetched vault snapshot.
25
+ * @returns A data-only plan with the exit and any share approval or signature request.
26
+ * @throws {ZeroAccountError} when `account` is the zero address.
27
+ * @throws {NonIntegerInputError} when `expiresAt` is not a safe integer.
28
+ * @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
29
+ * @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
30
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
31
+ * @throws {ChainIdMismatchError} when the client declares or its RPC serves another chain.
32
+ * @throws {EmptyMarketParamsListError} when no markets are supplied.
33
+ * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
34
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 or Morpho Blue is not registered on the chain.
35
+ * @throws {InKindRedeemCoverageError} when the ordered markets cannot cover `assets` without overusing an allocation.
36
+ * @throws {MissingContractCodeError} when VaultExitBundlesV1 or Morpho Blue has no deployed code.
37
+ * @throws {viem.BaseError} when a chain, code, allowance, nonce, balance or contract configuration read fails, or inputs cannot be ABI-encoded.
38
+ * @throws {VaultMorphoMismatchError} when the vault's `MORPHO` differs from the registered Morpho Blue contract.
39
+ * @throws {VaultIsBlueFeeRecipientError} when the vault is Morpho Blue's fee recipient, an unsupported configuration.
40
+ * @throws {InsufficientBlueBalanceForInKindRedeemError} when Morpho Blue's asset balance is below `assets`.
41
+ * @throws {UnsupportedPermitDomainExtensionsError} when a required share permit advertises unsupported EIP-5267 extensions.
42
+ * @throws {InvalidPermitDomainChainIdError} when a required share permit domain targets another chain or omits `chainId`.
43
+ * @throws {InvalidPermitDomainVerifyingContractError} when a required share permit domain targets another token or omits `verifyingContract`.
44
+ * @throws {MissingPermitDomainNameError} when a required share permit has neither an EIP-5267 domain nor a token name.
45
+ * @see computeVaultMaxShareAllowance for snapshot accrual and share-quote errors.
46
+ * @see MorphoVaultV1.inKindRedeem for snapshot and onchain preflight validation.
47
+ * @example
48
+ * ```ts
49
+ * import { prepareVaultV1InKindRedeem } from "@morpho-org/morpho-sdk";
50
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
51
+ * import { createPublicClient, http } from "viem";
52
+ * import { mainnet } from "viem/chains";
53
+ *
54
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
55
+ * const vaultAddress = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"; // Mainnet steakUSDC Vault V1.
56
+ * const vault = await fetchAccrualVault(vaultAddress, client);
57
+ * const marketParamsList = [...vault.allocations.values()]
58
+ * .filter(({ config, position }) => config.enabled && position.supplyShares > 0n)
59
+ * .map(({ position }) => position.market.params);
60
+ * const plan = await prepareVaultV1InKindRedeem(client, {
61
+ * chainId: mainnet.id, account: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
62
+ * vault, assets: 1_000_000n, marketParamsList,
63
+ * });
64
+ * // plan satisfies TransactionPlan: { version, chainId, account, expiresAt, steps, signatureRequests }
65
+ * ```
66
+ */
67
+ export async function prepareVaultV1InKindRedeem(client, params) {
68
+ const { chainId, account, vault } = params;
69
+ const now = params.now ?? Time.timestamp();
70
+ const intent = resolveIntent(params, now);
71
+ validateChainId(client.chain?.id, chainId);
72
+ const quote = computeVaultV1InKindRedeemQuote({
73
+ vaultData: vault,
74
+ chainId,
75
+ deadline: intent.deadline,
76
+ now,
77
+ amount: params.assets,
78
+ marketParamsList: params.marketParamsList,
79
+ });
80
+ const inputs = vaultV1InKindRedeem({
81
+ vault: { chainId, address: vault.address },
82
+ args: {
83
+ amount: params.assets,
84
+ marketParamsList: quote.marketParamsListSnapshot,
85
+ userAddress: account,
86
+ deadline: quote.deadline,
87
+ },
88
+ }).action.args;
89
+ const requirements = await getVaultV1InKindRedeemRequirements(client, {
90
+ vaultData: vault,
91
+ vault: vault.address,
92
+ userAddress: account,
93
+ chainId,
94
+ deadline: quote.deadline,
95
+ requiredShareAllowance: quote.requiredShareAllowance,
96
+ supportSignature: intent.supportSignature,
97
+ now,
98
+ amount: params.assets,
99
+ });
100
+ const approvals = [];
101
+ const signatureRequests = [];
102
+ const id = "vaultV1InKindRedeem:tokenPermit";
103
+ for (const requirement of requirements) {
104
+ if (isRequirementApproval(requirement)) {
105
+ approvals.push(buildApprovalStep(requirement, {
106
+ id: "vaultV1InKindRedeem:approval",
107
+ chainId,
108
+ account,
109
+ denomination: "shares",
110
+ }));
111
+ }
112
+ else if (requirement.action.type === "permit") {
113
+ signatureRequests.push(buildPermitSignatureRequest({ action: requirement.action }, id));
114
+ }
115
+ else {
116
+ throw new UnsupportedRequirementSignatureError(requirement.action.type);
117
+ }
118
+ }
119
+ return deepFreeze(structuredClone({
120
+ version: 2,
121
+ chainId,
122
+ account,
123
+ expiresAt: intent.expiresAt,
124
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
125
+ steps: [
126
+ ...approvals,
127
+ {
128
+ id: "vaultV1InKindRedeem",
129
+ label: "Redeem vault shares in kind",
130
+ action: {
131
+ type: "vaultV1InKindRedeem",
132
+ inputs: {
133
+ chainId,
134
+ account,
135
+ vault: vault.address,
136
+ assets: inputs.amount,
137
+ deadline: inputs.deadline,
138
+ marketParamsList: inputs.marketParamsList,
139
+ },
140
+ signatureRequestIds: signatureRequests.length
141
+ ? { tokenPermit: id }
142
+ : {},
143
+ },
144
+ },
145
+ ],
146
+ signatureRequests,
147
+ }));
148
+ }
149
+ /** @internal Encodes the fixed in-kind exit with its referenced permit. */
150
+ export function buildVaultV1InKindRedeem(action, requests) {
151
+ const { chainId, account, vault, assets, ...args } = action.inputs;
152
+ const signature = getVaultPermit(requests, {
153
+ id: action.signatureRequestIds.tokenPermit,
154
+ asset: vault,
155
+ owner: account,
156
+ });
157
+ const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
158
+ spender: getChainAddress(chainId, "bundles.vaultExitBundlesV1"),
159
+ amount: maxUint256,
160
+ deadline: action.inputs.deadline,
161
+ });
162
+ return vaultV1InKindRedeem({
163
+ vault: { chainId, address: vault },
164
+ args: {
165
+ ...args,
166
+ amount: assets,
167
+ userAddress: account,
168
+ requirementSignature: permit,
169
+ },
170
+ });
171
+ }
172
+ /** @internal Validates the stored in-kind action and ordered market structs. */
173
+ export function validateInKindRedeemPlanAction(action, path) {
174
+ const inputs = getPlanObject(action.inputs, `${path}.inputs`);
175
+ validatePlanFields(inputs, {
176
+ path: `${path}.inputs`,
177
+ fields: {
178
+ vault: "address",
179
+ assets: "uint256 bigint",
180
+ deadline: "uint256 bigint",
181
+ marketParamsList: "array",
182
+ },
183
+ });
184
+ getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
185
+ for (const [index, value] of inputs.marketParamsList.entries()) {
186
+ const marketPath = `${path}.inputs.marketParamsList[${index}]`;
187
+ validatePlanFields(getPlanObject(value, marketPath), {
188
+ path: marketPath,
189
+ fields: {
190
+ loanToken: "address",
191
+ collateralToken: "address",
192
+ oracle: "address",
193
+ irm: "address",
194
+ lltv: "uint256 bigint",
195
+ },
196
+ });
197
+ }
198
+ }
@@ -0,0 +1,94 @@
1
+ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import { type Client } from "viem";
3
+ import { type ReferenceTimestampParams, type Transaction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs } from "../../types/index.js";
4
+ import { type IntentParams } from "../intent.js";
5
+ import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
6
+ /** @internal Validates the stored Vault V1 migration action's input shape. */
7
+ export declare function validateMigrateToV2PlanAction(action: Record<string, unknown>, path: string): void;
8
+ /**
9
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
10
+ * Caller intent for a Vault V1-to-V2 migration with caller-fetched accrual snapshots.
11
+ * Snapshots are used only at preparation and are never stored in the plan.
12
+ * @example
13
+ * ```ts
14
+ * import type { VaultV1MigrateToV2PlanParams } from "@morpho-org/morpho-sdk";
15
+ * import { fetchAccrualVault, fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
16
+ * import { createPublicClient, http } from "viem";
17
+ * import { mainnet } from "viem/chains";
18
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
19
+ * const sourceVault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
20
+ * const targetVault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
21
+ * const params: VaultV1MigrateToV2PlanParams = {
22
+ * chainId: 1, account: "0x0000000000000000000000000000000000000001",
23
+ * sourceVault: await fetchAccrualVault(sourceVault, client),
24
+ * targetVault: await fetchAccrualVaultV2(targetVault, client),
25
+ * shares: 1_000_000n, supportSignature: true,
26
+ * };
27
+ * ```
28
+ */
29
+ export type VaultV1MigrateToV2PlanParams = Omit<IntentParams, "deployless"> & ReferenceTimestampParams & VaultV1MigrateToV2AmountArgs & {
30
+ readonly sourceVault: AccrualVault;
31
+ readonly targetVault: AccrualVaultV2;
32
+ readonly slippageTolerance?: bigint;
33
+ };
34
+ /**
35
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
36
+ * Prepares a migration with fixed destination price and source share allowance quotes.
37
+ * @param client - Viem client for the intended chain, used for code, allowance and nonce reads.
38
+ * @param params.sourceVault - Caller-fetched AccrualVault source snapshot, including the source address and permit metadata.
39
+ * @param params.targetVault - Caller-fetched AccrualVaultV2 destination snapshot, including its address and quote data.
40
+ * @param params.chainId - Chain containing both vaults and the registered VaultBundlesV1 contract.
41
+ * @param params.account - Non-zero account approving or permitting shares and sending the migration.
42
+ * @param params.assets - Positive gross migration in asset base units, before referral fees; mutually exclusive with `shares`.
43
+ * @param params.shares - Positive source share amount to migrate; mutually exclusive with `assets`.
44
+ * @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
45
+ * @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
46
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance for the destination price and source share allowance quotes; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
47
+ * @param params.supportSignature - Optional unlimited ERC-2612 share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient. Vault V1 shares support ERC-2612; no Permit2 is used.
48
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
49
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
50
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
51
+ * @returns A static migration plan with any required source share approval or permit.
52
+ * @throws {VaultAssetMismatchError} If the vault assets differ.
53
+ * @throws {SameVaultMigrationError} If source and target are identical.
54
+ * @throws {AmountAndSharesExclusiveError} If both or neither amount is supplied.
55
+ * @throws {ZeroAccountError} when `account` is the zero address.
56
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
57
+ * @throws {NonPositiveInputError} when `expiresAt`, the selected amount, net migrated assets or previewed shares are not positive.
58
+ * @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
59
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or the selected amount exceeds uint256.
60
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
61
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
62
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
63
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
64
+ * @throws {ExpiredDeadlineError} If the expiry is not in the future.
65
+ * @throws {ChainIdMismatchError} If the client targets another chain.
66
+ * @throws {MissingContractCodeError} If VaultBundlesV1 is absent.
67
+ * @throws {MissingPermitDomainNameError} when share allowance is insufficient, signatures are enabled, and the snapshot has neither a permit domain nor a name.
68
+ * @throws {InvalidPermitDomainChainIdError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing chain ID.
69
+ * @throws {InvalidPermitDomainVerifyingContractError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing verifying contract.
70
+ * @throws {UnsupportedPermitDomainExtensionsError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain advertises extensions.
71
+ * @see computeVaultMaxSharePrice for quote errors.
72
+ * @example
73
+ * ```ts
74
+ * import { prepareVaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
75
+ * import { fetchAccrualVault, fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
76
+ * import { createPublicClient, http } from "viem";
77
+ * import { mainnet } from "viem/chains";
78
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
79
+ * const sourceVault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
80
+ * const targetVault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
81
+ * const plan = await prepareVaultV1MigrateToV2(client, {
82
+ * chainId: 1, account: "0x0000000000000000000000000000000000000001",
83
+ * sourceVault: await fetchAccrualVault(sourceVault, client),
84
+ * targetVault: await fetchAccrualVaultV2(targetVault, client),
85
+ * assets: 1_000_000n, supportSignature: true,
86
+ * });
87
+ * // Sign pending requests, verify and attach with applySignatures, then buildTransactions.
88
+ * ```
89
+ */
90
+ export declare function prepareVaultV1MigrateToV2(client: Client, params: VaultV1MigrateToV2PlanParams): Promise<TransactionPlan>;
91
+ /** @internal Maps stored maxSharePrice to the ABI maxSharePriceVaultV2 and encodes the source permit. */
92
+ export declare function buildVaultV1MigrateToV2(action: Extract<Action, {
93
+ type: "vaultV1MigrateToV2";
94
+ }>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV1MigrateToV2Action>>;