@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
@@ -74,12 +74,14 @@ export const validateMidnightSellTargetBounds = (params) => {
74
74
  */
75
75
  export const validateMidnightTakeFeasibility = (params) => {
76
76
  // The raw builder rejects an empty list with `EmptyMidnightTakeableOffersError`.
77
- if (params.takeableOffers.length === 0)
77
+ if (params.takeableOffers.length === 0) {
78
78
  return params.takeableOffers;
79
+ }
79
80
  const { marketData, now, deadline } = params;
80
81
  // The entity checked the deadline on an earlier clock read; recheck so the fee window is never empty.
81
- if (deadline <= now)
82
+ if (deadline <= now) {
82
83
  throw new ExpiredDeadlineError(deadline, now);
84
+ }
83
85
  const maturity = marketData.params.maturity;
84
86
  const marketFee = BigInt(marketData.continuousFee);
85
87
  // Reject buy fee and debt violations before evaluating settlement fees or offers.
@@ -130,12 +132,14 @@ export const validateMidnightTakeFeasibility = (params) => {
130
132
  /** Resolves a reduce-only buy's repay bound without changing target precedence. @internal */
131
133
  function resolveRepayTarget(target, { debt, referralFeePct, }) {
132
134
  if (target.type === "units") {
133
- if (target.units === maxUint256)
135
+ if (target.units === maxUint256) {
134
136
  return undefined;
137
+ }
135
138
  return { field: "target.units", value: target.units };
136
139
  }
137
- if (target.minUnits > debt)
140
+ if (target.minUnits > debt) {
138
141
  return { field: "target.minUnits", value: target.minUnits };
142
+ }
139
143
  return {
140
144
  field: "target.assets",
141
145
  value: netOfReferralFee(target.assets, referralFeePct),
@@ -143,8 +147,9 @@ function resolveRepayTarget(target, { debt, referralFeePct, }) {
143
147
  }
144
148
  /** Rejects excessive continuous fees and reduce-only buys exceeding debt. @internal */
145
149
  function assertMidnightBuyBounds(params, marketFee) {
146
- if (params.side !== "buy")
150
+ if (params.side !== "buy") {
147
151
  return;
152
+ }
148
153
  if (params.maxContinuousFee < marketFee) {
149
154
  throw new MidnightContinuousFeeAboveMaxError({
150
155
  maxContinuousFee: params.maxContinuousFee,
@@ -167,46 +172,61 @@ function assertMidnightBuyBounds(params, marketFee) {
167
172
  function getOfferPriceReason(params, { tickInRange, offerPrice, minFee, maxFee, }) {
168
173
  // The bundle converts every buy assets target price outside its per-offer catch.
169
174
  if (params.side === "buy" && params.target.type === "assets") {
170
- if (!tickInRange)
175
+ if (!tickInRange) {
171
176
  return "tickOutOfRange";
172
- if (offerPrice + maxFee === 0n)
177
+ }
178
+ if (offerPrice + maxFee === 0n) {
173
179
  return "zeroBuyerPrice";
174
- if (offerPrice + minFee > MathLib.WAD)
180
+ }
181
+ if (offerPrice + minFee > MathLib.WAD) {
175
182
  return "buyerPriceAboveOne";
183
+ }
176
184
  return undefined;
177
185
  }
178
186
  // Every sell converts a buy offer's price outside the catch too.
179
- if (params.side !== "sell")
187
+ if (params.side !== "sell") {
180
188
  return undefined;
181
- if (!tickInRange)
189
+ }
190
+ if (!tickInRange) {
182
191
  return "tickOutOfRange";
183
- if (offerPrice === 0n)
192
+ }
193
+ if (offerPrice === 0n) {
184
194
  return "zeroBuyerPrice";
195
+ }
185
196
  // An assets target also divides by the seller price, which is zero at the fee.
186
197
  if (offerPrice < minFee ||
187
- (params.target.type === "assets" && offerPrice === minFee))
198
+ (params.target.type === "assets" && offerPrice === minFee)) {
188
199
  return "priceBelowSettlementFee";
200
+ }
189
201
  return undefined;
190
202
  }
191
203
  /** Finds the first non-price condition preventing an offer from filling. @internal */
192
204
  function getOfferDeadReason({ units, offer }, { params, tickInRange, marketFee, sellableCredit, }) {
193
- if (units === 0n)
205
+ if (units === 0n) {
194
206
  return "zeroUnits";
195
- if (!tickInRange)
207
+ }
208
+ if (!tickInRange) {
196
209
  return "tickOutOfRange";
197
- if (offer.expiry < params.now)
210
+ }
211
+ if (offer.expiry < params.now) {
198
212
  return "expired";
199
- if (offer.start > params.deadline)
213
+ }
214
+ if (offer.start > params.deadline) {
200
215
  return "notStarted";
201
- if (isAddressEqual(offer.maker, params.accountAddress))
216
+ }
217
+ if (isAddressEqual(offer.maker, params.accountAddress)) {
202
218
  return "selfTake";
203
- if (offer.continuousFeeCap < marketFee)
219
+ }
220
+ if (offer.continuousFeeCap < marketFee) {
204
221
  return "continuousFeeCapBelowMarketFee";
222
+ }
205
223
  if (params.side === "sell" &&
206
- !isAddressEqual(offer.receiverIfMakerIsSeller, zeroAddress))
224
+ !isAddressEqual(offer.receiverIfMakerIsSeller, zeroAddress)) {
207
225
  return "receiverIfMakerIsSellerNotZero";
208
- if (sellableCredit === 0n)
226
+ }
227
+ if (sellableCredit === 0n) {
209
228
  return "marketMatured";
229
+ }
210
230
  return undefined;
211
231
  }
212
232
  /** Accumulates live offer capacity and preserves removal and error order. @internal */
@@ -224,8 +244,9 @@ function collectOfferCapacity(params, { minFee, maxFee, marketFee, sellableCredi
224
244
  minFee,
225
245
  maxFee,
226
246
  });
227
- if (priceReason)
247
+ if (priceReason) {
228
248
  removed.add(index);
249
+ }
229
250
  const reason = priceReason ??
230
251
  getOfferDeadReason({ units, offer }, {
231
252
  params,
@@ -246,8 +267,9 @@ function collectOfferCapacity(params, { minFee, maxFee, marketFee, sellableCredi
246
267
  function resolveRequiredUnits(params) {
247
268
  const { target, referralFeePct } = params;
248
269
  if (params.side === "sell") {
249
- if (target.type === "units")
270
+ if (target.type === "units") {
250
271
  return target.units;
272
+ }
251
273
  return grossFromNetAssets({ netAssets: target.assets, referralFeePct });
252
274
  }
253
275
  if (params.target.type === "units") {
@@ -9,6 +9,7 @@ import { NonPositiveInputError } from "../types/error.js";
9
9
  * @internal
10
10
  */
11
11
  export const validatePositiveInput = (field, value) => {
12
- if (value <= 0n)
12
+ if (value <= 0n) {
13
13
  throw new NonPositiveInputError(field, value);
14
+ }
14
15
  };
@@ -31,8 +31,9 @@ export const validateTakeableOffers = (params) => {
31
31
  actualMarket: actualMarketId,
32
32
  });
33
33
  }
34
- if (take.offer.buy)
34
+ if (take.offer.buy) {
35
35
  continue;
36
+ }
36
37
  // Reject a malformed address before viem compares it.
37
38
  validateMidnightAddress(`takeableOffers[${index}].offer.receiverIfMakerIsSeller`, take.offer.receiverIfMakerIsSeller);
38
39
  if (isAddressEqual(take.offer.receiverIfMakerIsSeller, zeroAddress)) {
@@ -175,8 +175,9 @@ export function computeVaultV2ForceWithdrawPlan(params) {
175
175
  // Guard the exported planner: a non-positive `exitAssets` would flow a negative through
176
176
  // `min(exitAssets, withdrawable)` and return a plan with negative amounts. The entity and preview
177
177
  // reject it upstream; this protects direct importers of the advertised helper.
178
- if (exitAssets <= 0n)
178
+ if (exitAssets <= 0n) {
179
179
  throw new NonPositiveInputError("exitAssets", exitAssets);
180
+ }
180
181
  const penalty = vaultData.forceDeallocatePenalties[adapter.address] ?? 0n;
181
182
  const idleAssets = vaultData.assetBalance;
182
183
  // `min(adapterPosition, marketLiquidity)` per market, on interest-accrued market state — the
@@ -215,14 +216,17 @@ export function computeVaultV2ForceWithdrawPlan(params) {
215
216
  let penaltyLegs = 0;
216
217
  let remaining = assetsToDeallocate;
217
218
  for (const available of nonEmpty.toSorted((a, b) => {
218
- if (a === b)
219
+ if (a === b) {
219
220
  return 0;
220
- if (a > b)
221
+ }
222
+ if (a > b) {
221
223
  return 1;
224
+ }
222
225
  return -1;
223
226
  })) {
224
- if (remaining <= 0n)
227
+ if (remaining <= 0n) {
225
228
  break;
229
+ }
226
230
  penaltyLegs += 1;
227
231
  remaining -= MathLib.min(available, remaining);
228
232
  }
@@ -421,8 +425,9 @@ function summarizeMarketCoverage(availableByMarket, liquidityMarketId) {
421
425
  let coveredAssets = 0n;
422
426
  const nonEmpty = [];
423
427
  for (const available of availableByMarket.values()) {
424
- if (available <= 0n)
428
+ if (available <= 0n) {
425
429
  continue;
430
+ }
426
431
  coveredAssets += available;
427
432
  nonEmpty.push(available);
428
433
  }
@@ -432,10 +437,12 @@ function summarizeMarketCoverage(availableByMarket, liquidityMarketId) {
432
437
  // ceiling for callers using it to cap an input.
433
438
  let saturatedCoveredAssets = 0n;
434
439
  for (const [marketId, available] of availableByMarket) {
435
- if (marketId === liquidityMarketId)
440
+ if (marketId === liquidityMarketId) {
436
441
  continue;
437
- if (available > 0n)
442
+ }
443
+ if (available > 0n) {
438
444
  saturatedCoveredAssets += available;
445
+ }
439
446
  }
440
447
  return { coveredAssets, nonEmpty, saturatedCoveredAssets };
441
448
  }
@@ -3,7 +3,7 @@ export { validateClientChainId } from "./actions/requirements/validateClientChai
3
3
  export * from "./client/index.js";
4
4
  export * from "./entities/requirements/index.js";
5
5
  export * from "./helpers/index.js";
6
- export type { Action, Funding, IntentParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV2DepositPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
7
- export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV2Deposit, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
6
+ export type { Action, Funding, IntentParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV1DepositPlanParams, VaultV1InKindRedeemPlanParams, VaultV1MigrateToV2PlanParams, VaultV1RedeemPlanParams, VaultV1WithdrawPlanParams, VaultV2DepositPlanParams, VaultV2ForceRedeemPlanParams, VaultV2ForceWithdrawPlanParams, VaultV2InKindRedeemPlanParams, VaultV2RedeemPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
7
+ export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
8
8
  export * from "./types/index.js";
9
9
  export { version } from "./version.js";
package/lib/esm/index.js CHANGED
@@ -3,6 +3,6 @@ export { validateClientChainId } from "./actions/requirements/validateClientChai
3
3
  export * from "./client/index.js";
4
4
  export * from "./entities/requirements/index.js";
5
5
  export * from "./helpers/index.js";
6
- export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV2Deposit, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
6
+ export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
7
7
  export * from "./types/index.js";
8
8
  export { version } from "./version.js";
@@ -1,2 +1 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
- export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
@@ -1,2 +1 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
- export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
@@ -1,4 +1,5 @@
1
- import { getPlanObject, validatePlanFields } from "./validation.js";
1
+ import { InvalidTransactionPlanError } from "./error.js";
2
+ import { getPlanObject, validatePlanField, validatePlanFields, } from "./validation.js";
2
3
  /** @internal Validates the stored ERC-20 approval action's input shape. */
3
4
  export function validateApprovalPlanAction(action, path) {
4
5
  const inputs = getPlanObject(action.inputs, `${path}.inputs`);
@@ -7,7 +8,17 @@ export function validateApprovalPlanAction(action, path) {
7
8
  fields: {
8
9
  token: "address",
9
10
  spender: "address",
10
- amount: "uint256 bigint",
11
11
  },
12
12
  });
13
+ if ((inputs.assets === undefined) === (inputs.shares === undefined)) {
14
+ throw new InvalidTransactionPlanError({
15
+ path: `${path}.inputs`,
16
+ reason: "expected exactly one of assets or shares",
17
+ });
18
+ }
19
+ const field = inputs.assets === undefined ? "shares" : "assets";
20
+ validatePlanField(inputs[field], {
21
+ path: `${path}.inputs.${field}`,
22
+ type: "uint256 bigint",
23
+ });
13
24
  }
@@ -0,0 +1,22 @@
1
+ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import type { Client } from "viem";
3
+ import { type ReferenceTimestampParams } from "../types/index.js";
4
+ import { type Funding, type IntentParams } from "./intent.js";
5
+ import type { TransactionPlan } from "./types.js";
6
+ /** @internal Validates the stored Vault V1 or V2 deposit action's input shape. */
7
+ export declare function validateDepositPlanAction(action: Record<string, unknown>, path: string): void;
8
+ /** @internal Shared caller intent for a snapshot-quoted vault deposit. */
9
+ export interface DepositPlanParams<TSnapshot extends AccrualVault | AccrualVaultV2> extends IntentParams, ReferenceTimestampParams {
10
+ /** WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE`. */
11
+ readonly slippageTolerance?: bigint;
12
+ /** Caller-fetched accrual snapshot; only derived inputs are stored in the plan. */
13
+ readonly vault: TSnapshot;
14
+ /** Gross assets the account pays, before the referral fee. */
15
+ readonly assets: bigint;
16
+ /** Defaults to `{ type: "erc20" }`. */
17
+ readonly funding?: Funding;
18
+ }
19
+ /** @internal Prepares a deposit using its vault action and caller-supplied snapshot type. */
20
+ export declare function prepareVaultDeposit<TSnapshot extends AccrualVault | AccrualVaultV2>(client: Client, params: DepositPlanParams<TSnapshot> & {
21
+ readonly type: "vaultV1Deposit" | "vaultV2Deposit";
22
+ }): Promise<TransactionPlan>;
@@ -0,0 +1,135 @@
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, } from "@morpho-org/blue-sdk";
2
+ import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
3
+ import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, } from "../actions/bundles/common.js";
4
+ import { validateClientChainId } from "../actions/requirements/validateClientChainId.js";
5
+ import { assertRegistryTargetsHaveCode } from "../entities/requirements/assertContractCode.js";
6
+ import { computeVaultMaxSharePrice } from "../helpers/index.js";
7
+ import { validateNativeVaultAsset, validateSlippageTolerance, validateUint256Field, } from "../helpers/validate.js";
8
+ import { NonPositiveInputError, } from "../types/index.js";
9
+ import { InvalidTransactionPlanError } from "./error.js";
10
+ import { resolveIntent } from "./intent.js";
11
+ import { buildApprovalStep, buildPermitSignatureRequest, getTokenRequirements, } from "./requirements.js";
12
+ import { validatePlanField, validatePlanFields, validateVaultPlanAction, } from "./validation.js";
13
+ /** @internal Validates the stored Vault V1 or V2 deposit action's input shape. */
14
+ export function validateDepositPlanAction(action, path) {
15
+ const inputs = validateVaultPlanAction(action, path);
16
+ validatePlanFields(inputs, {
17
+ path: `${path}.inputs`,
18
+ fields: { asset: "address", maxSharePrice: "uint256 bigint" },
19
+ });
20
+ if ((inputs.assets === undefined) === (inputs.nativeAssets === undefined)) {
21
+ throw new InvalidTransactionPlanError({
22
+ path: `${path}.inputs`,
23
+ reason: "expected exactly one of assets or nativeAssets",
24
+ });
25
+ }
26
+ const field = inputs.assets === undefined ? "nativeAssets" : "assets";
27
+ validatePlanField(inputs[field], {
28
+ path: `${path}.inputs.${field}`,
29
+ type: "uint256 bigint",
30
+ });
31
+ }
32
+ function resolveDepositInputs(params, now) {
33
+ const { vault, chainId, assets } = params;
34
+ const intent = resolveIntent(params, now);
35
+ const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
36
+ validateSlippageTolerance(slippageTolerance);
37
+ const native = (params.funding ?? { type: "erc20" }).type === "native";
38
+ if (assets <= 0n) {
39
+ throw new NonPositiveInputError("assets", assets);
40
+ }
41
+ // Reject amounts that cannot be encoded as uint256 before making RPC requests.
42
+ validateUint256Field("assets", assets);
43
+ const common = normalizeBundlesCommonParams({
44
+ deadline: intent.deadline,
45
+ referralFeePct: intent.referralFeePct,
46
+ referralFeeRecipient: intent.referralFeeRecipient,
47
+ });
48
+ const { asset } = vault;
49
+ // Native funding must target the chain's wrapped-native vault asset.
50
+ if (native) {
51
+ validateNativeVaultAsset(chainId, asset);
52
+ }
53
+ // The quote depends only on the snapshot and the intent, so it is fixed before any read.
54
+ const maxSharePrice = computeVaultMaxSharePrice({
55
+ vaultData: vault,
56
+ deadline: intent.deadline,
57
+ assets: assets - getBundlesReferralFeeAssets(assets, common.referralFeePct),
58
+ slippageTolerance,
59
+ });
60
+ return { intent, native, common, asset, maxSharePrice };
61
+ }
62
+ /** @internal Prepares a deposit using its vault action and caller-supplied snapshot type. */
63
+ export async function prepareVaultDeposit(client, params) {
64
+ const { chainId, account, assets } = params;
65
+ const vault = params.vault.address;
66
+ const now = params.now ?? Time.timestamp();
67
+ const { intent, native, common, asset, maxSharePrice } = resolveDepositInputs(params, now);
68
+ const spender = getChainAddress(chainId, "bundles.vaultBundlesV1");
69
+ const [requirements] = await Promise.all([
70
+ validateClientChainId(client, chainId).then(() => native
71
+ ? []
72
+ : getTokenRequirements(client, {
73
+ token: asset,
74
+ spender,
75
+ amount: assets,
76
+ owner: account,
77
+ chainId,
78
+ deadline: intent.deadline,
79
+ now,
80
+ supportSignature: intent.supportSignature,
81
+ deployless: intent.deployless,
82
+ })),
83
+ assertRegistryTargetsHaveCode(client, chainId, [
84
+ { role: "bundles.vaultBundlesV1", address: spender },
85
+ ]),
86
+ ]);
87
+ const approvals = [];
88
+ const signatureRequests = [];
89
+ const tokenPermitRequestId = `${params.type}:tokenPermit`;
90
+ for (const requirement of requirements) {
91
+ if ("sign" in requirement) {
92
+ signatureRequests.push(buildPermitSignatureRequest(requirement, tokenPermitRequestId));
93
+ }
94
+ else {
95
+ approvals.push(buildApprovalStep(requirement, {
96
+ id: approvals.length === 0
97
+ ? `${params.type}:approval`
98
+ : `${params.type}:approval:${approvals.length + 1}`,
99
+ chainId,
100
+ account,
101
+ denomination: "assets",
102
+ }));
103
+ }
104
+ }
105
+ return deepFreeze(structuredClone({
106
+ version: 2,
107
+ account,
108
+ chainId,
109
+ expiresAt: intent.expiresAt,
110
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
111
+ steps: [
112
+ ...approvals,
113
+ {
114
+ id: params.type,
115
+ label: "Deposit into vault",
116
+ action: {
117
+ type: params.type,
118
+ inputs: {
119
+ chainId,
120
+ account,
121
+ vault,
122
+ asset,
123
+ maxSharePrice,
124
+ ...(native ? { nativeAssets: assets } : { assets }),
125
+ ...common,
126
+ },
127
+ signatureRequestIds: signatureRequests.length > 0
128
+ ? { tokenPermit: tokenPermitRequestId }
129
+ : {},
130
+ },
131
+ },
132
+ ],
133
+ signatureRequests,
134
+ }));
135
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Address } from "viem";
2
2
  /**
3
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
3
4
  * Thrown when an operation's account is the zero address.
4
5
  * @example
5
6
  * ```ts
@@ -7,7 +8,6 @@ import type { Address } from "viem";
7
8
  * import { zeroAddress } from "viem";
8
9
  * const error = new ZeroAccountError(zeroAddress);
9
10
  * ```
10
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
11
11
  */
12
12
  export declare class ZeroAccountError extends Error {
13
13
  readonly account: Address;
@@ -15,8 +15,8 @@ export declare class ZeroAccountError extends Error {
15
15
  constructor(account: Address);
16
16
  }
17
17
  /**
18
- * A stored plan uses a format version this SDK cannot interpret.
19
18
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
19
+ * A stored plan uses a format version this SDK cannot interpret.
20
20
  */
21
21
  export declare class UnsupportedTransactionPlanVersionError extends Error {
22
22
  readonly version: number;
@@ -32,8 +32,8 @@ export declare class UnsupportedTransactionPlanVersionError extends Error {
32
32
  constructor(version: number);
33
33
  }
34
34
  /**
35
- * A selected plan step names an action this SDK cannot build.
36
35
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
36
+ * A selected plan step names an action this SDK cannot build.
37
37
  */
38
38
  export declare class UnsupportedTransactionPlanActionError extends Error {
39
39
  readonly actionType: string;
@@ -49,8 +49,8 @@ export declare class UnsupportedTransactionPlanActionError extends Error {
49
49
  constructor(actionType: string);
50
50
  }
51
51
  /**
52
- * Restored plan data has an invalid shape or inconsistent references.
53
52
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
53
+ * Restored plan data has an invalid shape or inconsistent references.
54
54
  */
55
55
  export declare class InvalidTransactionPlanError extends Error {
56
56
  /** JSON path of the first rejected value. */
@@ -73,11 +73,13 @@ export declare class InvalidTransactionPlanError extends Error {
73
73
  });
74
74
  }
75
75
  /**
76
- * A step references a signature request that is absent or has no signature yet.
77
76
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
77
+ * A step references a signature request that is absent or has no signature yet.
78
78
  */
79
79
  export declare class IncompleteTransactionPlanError extends Error {
80
80
  readonly id: string;
81
+ /** The missing dependency is a signature request. */
82
+ readonly kind = "signature";
81
83
  /**
82
84
  * Identifies the signature request needed to build the transaction.
83
85
  * @param id - Plan-local signature request ID.
@@ -90,8 +92,8 @@ export declare class IncompleteTransactionPlanError extends Error {
90
92
  constructor(id: string);
91
93
  }
92
94
  /**
93
- * A plan's signature request disagrees with its referencing action or has no reference.
94
95
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
96
+ * A plan's signature request disagrees with its referencing action or has no reference.
95
97
  */
96
98
  export declare class TransactionPlanSignatureMismatchError extends Error {
97
99
  readonly id: string;
@@ -108,8 +110,8 @@ export declare class TransactionPlanSignatureMismatchError extends Error {
108
110
  constructor(id: string, field: string);
109
111
  }
110
112
  /**
111
- * `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
112
113
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
114
+ * `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
113
115
  */
114
116
  export declare class InvalidCalldataOriginError extends Error {
115
117
  readonly calldataOrigin: string;
@@ -125,8 +127,8 @@ export declare class InvalidCalldataOriginError extends Error {
125
127
  constructor(calldataOrigin: string);
126
128
  }
127
129
  /**
128
- * A number input that must be an integer is fractional, infinite or not a number.
129
130
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
131
+ * A number input that must be an integer is fractional, infinite or not a number.
130
132
  */
131
133
  export declare class NonIntegerInputError extends Error {
132
134
  readonly field: string;
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
2
3
  * Thrown when an operation's account is the zero address.
3
4
  * @example
4
5
  * ```ts
@@ -6,7 +7,6 @@
6
7
  * import { zeroAddress } from "viem";
7
8
  * const error = new ZeroAccountError(zeroAddress);
8
9
  * ```
9
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
10
10
  */
11
11
  export class ZeroAccountError extends Error {
12
12
  account;
@@ -18,8 +18,8 @@ export class ZeroAccountError extends Error {
18
18
  }
19
19
  }
20
20
  /**
21
- * A stored plan uses a format version this SDK cannot interpret.
22
21
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
22
+ * A stored plan uses a format version this SDK cannot interpret.
23
23
  */
24
24
  export class UnsupportedTransactionPlanVersionError extends Error {
25
25
  version;
@@ -39,8 +39,8 @@ export class UnsupportedTransactionPlanVersionError extends Error {
39
39
  }
40
40
  }
41
41
  /**
42
- * A selected plan step names an action this SDK cannot build.
43
42
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
43
+ * A selected plan step names an action this SDK cannot build.
44
44
  */
45
45
  export class UnsupportedTransactionPlanActionError extends Error {
46
46
  actionType;
@@ -60,8 +60,8 @@ export class UnsupportedTransactionPlanActionError extends Error {
60
60
  }
61
61
  }
62
62
  /**
63
- * Restored plan data has an invalid shape or inconsistent references.
64
63
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
64
+ * Restored plan data has an invalid shape or inconsistent references.
65
65
  */
66
66
  export class InvalidTransactionPlanError extends Error {
67
67
  /** JSON path of the first rejected value. */
@@ -85,11 +85,13 @@ export class InvalidTransactionPlanError extends Error {
85
85
  }
86
86
  }
87
87
  /**
88
- * A step references a signature request that is absent or has no signature yet.
89
88
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
89
+ * A step references a signature request that is absent or has no signature yet.
90
90
  */
91
91
  export class IncompleteTransactionPlanError extends Error {
92
92
  id;
93
+ /** The missing dependency is a signature request. */
94
+ kind = "signature";
93
95
  /**
94
96
  * Identifies the signature request needed to build the transaction.
95
97
  * @param id - Plan-local signature request ID.
@@ -106,8 +108,8 @@ export class IncompleteTransactionPlanError extends Error {
106
108
  }
107
109
  }
108
110
  /**
109
- * A plan's signature request disagrees with its referencing action or has no reference.
110
111
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
112
+ * A plan's signature request disagrees with its referencing action or has no reference.
111
113
  */
112
114
  export class TransactionPlanSignatureMismatchError extends Error {
113
115
  id;
@@ -129,8 +131,8 @@ export class TransactionPlanSignatureMismatchError extends Error {
129
131
  }
130
132
  }
131
133
  /**
132
- * `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
133
134
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
135
+ * `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
134
136
  */
135
137
  export class InvalidCalldataOriginError extends Error {
136
138
  calldataOrigin;
@@ -150,8 +152,8 @@ export class InvalidCalldataOriginError extends Error {
150
152
  }
151
153
  }
152
154
  /**
153
- * A number input that must be an integer is fractional, infinite or not a number.
154
155
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
156
+ * A number input that must be an integer is fractional, infinite or not a number.
155
157
  */
156
158
  export class NonIntegerInputError extends Error {
157
159
  field;
@@ -9,7 +9,8 @@ import { getErc2612Permit } from "../entities/requirements/getErc2612Permit.js";
9
9
  */
10
10
  export async function getTokenPermit(client, params) {
11
11
  const { dai } = getChainAddresses(params.chainId);
12
- if (isDefined(dai) && isAddressEqual(params.token, dai))
12
+ if (isDefined(dai) && isAddressEqual(params.token, dai)) {
13
13
  return undefined;
14
+ }
14
15
  return getErc2612Permit(client, params);
15
16
  }
@@ -3,7 +3,25 @@ export type { Funding, IntentParams, ReferralFee, } from "./intent.js";
3
3
  export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
4
4
  export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
5
5
  export type { Action, SignatureRequest, Step, TransactionPlan, } from "./types.js";
6
+ export type { VaultV1DepositPlanParams } from "./vaultv1/deposit.js";
7
+ export { prepareVaultV1Deposit } from "./vaultv1/deposit.js";
8
+ export type { VaultV1InKindRedeemPlanParams } from "./vaultv1/inKindRedeem.js";
9
+ export { prepareVaultV1InKindRedeem } from "./vaultv1/inKindRedeem.js";
10
+ export type { VaultV1MigrateToV2PlanParams } from "./vaultv1/migrateToV2.js";
11
+ export { prepareVaultV1MigrateToV2 } from "./vaultv1/migrateToV2.js";
12
+ export type { VaultV1RedeemPlanParams } from "./vaultv1/redeem.js";
13
+ export { prepareVaultV1Redeem } from "./vaultv1/redeem.js";
14
+ export type { VaultV1WithdrawPlanParams } from "./vaultv1/withdraw.js";
15
+ export { prepareVaultV1Withdraw } from "./vaultv1/withdraw.js";
6
16
  export type { VaultV2DepositPlanParams } from "./vaultv2/deposit.js";
7
17
  export { prepareVaultV2Deposit } from "./vaultv2/deposit.js";
18
+ export type { VaultV2ForceRedeemPlanParams } from "./vaultv2/forceRedeem.js";
19
+ export { prepareVaultV2ForceRedeem } from "./vaultv2/forceRedeem.js";
20
+ export type { VaultV2ForceWithdrawPlanParams } from "./vaultv2/forceWithdraw.js";
21
+ export { prepareVaultV2ForceWithdraw } from "./vaultv2/forceWithdraw.js";
22
+ export type { VaultV2InKindRedeemPlanParams } from "./vaultv2/inKindRedeem.js";
23
+ export { prepareVaultV2InKindRedeem } from "./vaultv2/inKindRedeem.js";
24
+ export type { VaultV2RedeemPlanParams } from "./vaultv2/redeem.js";
25
+ export { prepareVaultV2Redeem } from "./vaultv2/redeem.js";
8
26
  export type { VaultV2WithdrawPlanParams } from "./vaultv2/withdraw.js";
9
27
  export { prepareVaultV2Withdraw } from "./vaultv2/withdraw.js";