@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
@@ -78,12 +78,14 @@ exports.validateMidnightSellTargetBounds = validateMidnightSellTargetBounds;
78
78
  */
79
79
  const validateMidnightTakeFeasibility = (params) => {
80
80
  // The raw builder rejects an empty list with `EmptyMidnightTakeableOffersError`.
81
- if (params.takeableOffers.length === 0)
81
+ if (params.takeableOffers.length === 0) {
82
82
  return params.takeableOffers;
83
+ }
83
84
  const { marketData, now, deadline } = params;
84
85
  // The entity checked the deadline on an earlier clock read; recheck so the fee window is never empty.
85
- if (deadline <= now)
86
+ if (deadline <= now) {
86
87
  throw new index_js_1.ExpiredDeadlineError(deadline, now);
88
+ }
87
89
  const maturity = marketData.params.maturity;
88
90
  const marketFee = BigInt(marketData.continuousFee);
89
91
  // Reject buy fee and debt violations before evaluating settlement fees or offers.
@@ -135,12 +137,14 @@ exports.validateMidnightTakeFeasibility = validateMidnightTakeFeasibility;
135
137
  /** Resolves a reduce-only buy's repay bound without changing target precedence. @internal */
136
138
  function resolveRepayTarget(target, { debt, referralFeePct, }) {
137
139
  if (target.type === "units") {
138
- if (target.units === viem_1.maxUint256)
140
+ if (target.units === viem_1.maxUint256) {
139
141
  return undefined;
142
+ }
140
143
  return { field: "target.units", value: target.units };
141
144
  }
142
- if (target.minUnits > debt)
145
+ if (target.minUnits > debt) {
143
146
  return { field: "target.minUnits", value: target.minUnits };
147
+ }
144
148
  return {
145
149
  field: "target.assets",
146
150
  value: netOfReferralFee(target.assets, referralFeePct),
@@ -148,8 +152,9 @@ function resolveRepayTarget(target, { debt, referralFeePct, }) {
148
152
  }
149
153
  /** Rejects excessive continuous fees and reduce-only buys exceeding debt. @internal */
150
154
  function assertMidnightBuyBounds(params, marketFee) {
151
- if (params.side !== "buy")
155
+ if (params.side !== "buy") {
152
156
  return;
157
+ }
153
158
  if (params.maxContinuousFee < marketFee) {
154
159
  throw new index_js_1.MidnightContinuousFeeAboveMaxError({
155
160
  maxContinuousFee: params.maxContinuousFee,
@@ -172,46 +177,61 @@ function assertMidnightBuyBounds(params, marketFee) {
172
177
  function getOfferPriceReason(params, { tickInRange, offerPrice, minFee, maxFee, }) {
173
178
  // The bundle converts every buy assets target price outside its per-offer catch.
174
179
  if (params.side === "buy" && params.target.type === "assets") {
175
- if (!tickInRange)
180
+ if (!tickInRange) {
176
181
  return "tickOutOfRange";
177
- if (offerPrice + maxFee === 0n)
182
+ }
183
+ if (offerPrice + maxFee === 0n) {
178
184
  return "zeroBuyerPrice";
179
- if (offerPrice + minFee > blue_sdk_1.MathLib.WAD)
185
+ }
186
+ if (offerPrice + minFee > blue_sdk_1.MathLib.WAD) {
180
187
  return "buyerPriceAboveOne";
188
+ }
181
189
  return undefined;
182
190
  }
183
191
  // Every sell converts a buy offer's price outside the catch too.
184
- if (params.side !== "sell")
192
+ if (params.side !== "sell") {
185
193
  return undefined;
186
- if (!tickInRange)
194
+ }
195
+ if (!tickInRange) {
187
196
  return "tickOutOfRange";
188
- if (offerPrice === 0n)
197
+ }
198
+ if (offerPrice === 0n) {
189
199
  return "zeroBuyerPrice";
200
+ }
190
201
  // An assets target also divides by the seller price, which is zero at the fee.
191
202
  if (offerPrice < minFee ||
192
- (params.target.type === "assets" && offerPrice === minFee))
203
+ (params.target.type === "assets" && offerPrice === minFee)) {
193
204
  return "priceBelowSettlementFee";
205
+ }
194
206
  return undefined;
195
207
  }
196
208
  /** Finds the first non-price condition preventing an offer from filling. @internal */
197
209
  function getOfferDeadReason({ units, offer }, { params, tickInRange, marketFee, sellableCredit, }) {
198
- if (units === 0n)
210
+ if (units === 0n) {
199
211
  return "zeroUnits";
200
- if (!tickInRange)
212
+ }
213
+ if (!tickInRange) {
201
214
  return "tickOutOfRange";
202
- if (offer.expiry < params.now)
215
+ }
216
+ if (offer.expiry < params.now) {
203
217
  return "expired";
204
- if (offer.start > params.deadline)
218
+ }
219
+ if (offer.start > params.deadline) {
205
220
  return "notStarted";
206
- if ((0, viem_1.isAddressEqual)(offer.maker, params.accountAddress))
221
+ }
222
+ if ((0, viem_1.isAddressEqual)(offer.maker, params.accountAddress)) {
207
223
  return "selfTake";
208
- if (offer.continuousFeeCap < marketFee)
224
+ }
225
+ if (offer.continuousFeeCap < marketFee) {
209
226
  return "continuousFeeCapBelowMarketFee";
227
+ }
210
228
  if (params.side === "sell" &&
211
- !(0, viem_1.isAddressEqual)(offer.receiverIfMakerIsSeller, viem_1.zeroAddress))
229
+ !(0, viem_1.isAddressEqual)(offer.receiverIfMakerIsSeller, viem_1.zeroAddress)) {
212
230
  return "receiverIfMakerIsSellerNotZero";
213
- if (sellableCredit === 0n)
231
+ }
232
+ if (sellableCredit === 0n) {
214
233
  return "marketMatured";
234
+ }
215
235
  return undefined;
216
236
  }
217
237
  /** Accumulates live offer capacity and preserves removal and error order. @internal */
@@ -229,8 +249,9 @@ function collectOfferCapacity(params, { minFee, maxFee, marketFee, sellableCredi
229
249
  minFee,
230
250
  maxFee,
231
251
  });
232
- if (priceReason)
252
+ if (priceReason) {
233
253
  removed.add(index);
254
+ }
234
255
  const reason = priceReason ??
235
256
  getOfferDeadReason({ units, offer }, {
236
257
  params,
@@ -251,8 +272,9 @@ function collectOfferCapacity(params, { minFee, maxFee, marketFee, sellableCredi
251
272
  function resolveRequiredUnits(params) {
252
273
  const { target, referralFeePct } = params;
253
274
  if (params.side === "sell") {
254
- if (target.type === "units")
275
+ if (target.type === "units") {
255
276
  return target.units;
277
+ }
256
278
  return (0, referralFee_js_1.grossFromNetAssets)({ netAssets: target.assets, referralFeePct });
257
279
  }
258
280
  if (params.target.type === "units") {
@@ -12,7 +12,8 @@ const error_js_1 = require("../types/error.js");
12
12
  * @internal
13
13
  */
14
14
  const validatePositiveInput = (field, value) => {
15
- if (value <= 0n)
15
+ if (value <= 0n) {
16
16
  throw new error_js_1.NonPositiveInputError(field, value);
17
+ }
17
18
  };
18
19
  exports.validatePositiveInput = validatePositiveInput;
@@ -34,8 +34,9 @@ const validateTakeableOffers = (params) => {
34
34
  actualMarket: actualMarketId,
35
35
  });
36
36
  }
37
- if (take.offer.buy)
37
+ if (take.offer.buy) {
38
38
  continue;
39
+ }
39
40
  // Reject a malformed address before viem compares it.
40
41
  (0, validateMidnightAccount_js_1.validateMidnightAddress)(`takeableOffers[${index}].offer.receiverIfMakerIsSeller`, take.offer.receiverIfMakerIsSeller);
41
42
  if ((0, viem_1.isAddressEqual)(take.offer.receiverIfMakerIsSeller, viem_1.zeroAddress)) {
@@ -182,8 +182,9 @@ function computeVaultV2ForceWithdrawPlan(params) {
182
182
  // Guard the exported planner: a non-positive `exitAssets` would flow a negative through
183
183
  // `min(exitAssets, withdrawable)` and return a plan with negative amounts. The entity and preview
184
184
  // reject it upstream; this protects direct importers of the advertised helper.
185
- if (exitAssets <= 0n)
185
+ if (exitAssets <= 0n) {
186
186
  throw new index_js_1.NonPositiveInputError("exitAssets", exitAssets);
187
+ }
187
188
  const penalty = vaultData.forceDeallocatePenalties[adapter.address] ?? 0n;
188
189
  const idleAssets = vaultData.assetBalance;
189
190
  // `min(adapterPosition, marketLiquidity)` per market, on interest-accrued market state — the
@@ -222,14 +223,17 @@ function computeVaultV2ForceWithdrawPlan(params) {
222
223
  let penaltyLegs = 0;
223
224
  let remaining = assetsToDeallocate;
224
225
  for (const available of nonEmpty.toSorted((a, b) => {
225
- if (a === b)
226
+ if (a === b) {
226
227
  return 0;
227
- if (a > b)
228
+ }
229
+ if (a > b) {
228
230
  return 1;
231
+ }
229
232
  return -1;
230
233
  })) {
231
- if (remaining <= 0n)
234
+ if (remaining <= 0n) {
232
235
  break;
236
+ }
233
237
  penaltyLegs += 1;
234
238
  remaining -= blue_sdk_1.MathLib.min(available, remaining);
235
239
  }
@@ -428,8 +432,9 @@ function summarizeMarketCoverage(availableByMarket, liquidityMarketId) {
428
432
  let coveredAssets = 0n;
429
433
  const nonEmpty = [];
430
434
  for (const available of availableByMarket.values()) {
431
- if (available <= 0n)
435
+ if (available <= 0n) {
432
436
  continue;
437
+ }
433
438
  coveredAssets += available;
434
439
  nonEmpty.push(available);
435
440
  }
@@ -439,10 +444,12 @@ function summarizeMarketCoverage(availableByMarket, liquidityMarketId) {
439
444
  // ceiling for callers using it to cap an input.
440
445
  let saturatedCoveredAssets = 0n;
441
446
  for (const [marketId, available] of availableByMarket) {
442
- if (marketId === liquidityMarketId)
447
+ if (marketId === liquidityMarketId) {
443
448
  continue;
444
- if (available > 0n)
449
+ }
450
+ if (available > 0n) {
445
451
  saturatedCoveredAssets += available;
452
+ }
446
453
  }
447
454
  return { coveredAssets, nonEmpty, saturatedCoveredAssets };
448
455
  }
@@ -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/cjs/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.version = exports.ZeroAccountError = exports.UnsupportedTransactionPlanVersionError = exports.UnsupportedTransactionPlanActionError = exports.TransactionPlanSignatureMismatchError = exports.serializeTransactionPlan = exports.prepareVaultV2Withdraw = exports.prepareVaultV2Deposit = exports.parseTransactionPlan = exports.NonIntegerInputError = exports.InvalidTransactionPlanError = exports.InvalidCalldataOriginError = exports.IncompleteTransactionPlanError = exports.getPendingSignatureRequests = exports.buildTransactions = exports.buildTransaction = exports.applySignatures = exports.validateClientChainId = void 0;
17
+ exports.version = exports.ZeroAccountError = exports.UnsupportedTransactionPlanVersionError = exports.UnsupportedTransactionPlanActionError = exports.TransactionPlanSignatureMismatchError = exports.serializeTransactionPlan = exports.prepareVaultV2Withdraw = exports.prepareVaultV2Redeem = exports.prepareVaultV2InKindRedeem = exports.prepareVaultV2ForceWithdraw = exports.prepareVaultV2ForceRedeem = exports.prepareVaultV2Deposit = exports.prepareVaultV1Withdraw = exports.prepareVaultV1Redeem = exports.prepareVaultV1MigrateToV2 = exports.prepareVaultV1InKindRedeem = exports.prepareVaultV1Deposit = exports.parseTransactionPlan = exports.NonIntegerInputError = exports.InvalidTransactionPlanError = exports.InvalidCalldataOriginError = exports.IncompleteTransactionPlanError = exports.getPendingSignatureRequests = exports.buildTransactions = exports.buildTransaction = exports.applySignatures = exports.validateClientChainId = void 0;
18
18
  __exportStar(require("./actions/index.js"), exports);
19
19
  var validateClientChainId_js_1 = require("./actions/requirements/validateClientChainId.js");
20
20
  Object.defineProperty(exports, "validateClientChainId", { enumerable: true, get: function () { return validateClientChainId_js_1.validateClientChainId; } });
@@ -31,7 +31,16 @@ Object.defineProperty(exports, "InvalidCalldataOriginError", { enumerable: true,
31
31
  Object.defineProperty(exports, "InvalidTransactionPlanError", { enumerable: true, get: function () { return index_js_1.InvalidTransactionPlanError; } });
32
32
  Object.defineProperty(exports, "NonIntegerInputError", { enumerable: true, get: function () { return index_js_1.NonIntegerInputError; } });
33
33
  Object.defineProperty(exports, "parseTransactionPlan", { enumerable: true, get: function () { return index_js_1.parseTransactionPlan; } });
34
+ Object.defineProperty(exports, "prepareVaultV1Deposit", { enumerable: true, get: function () { return index_js_1.prepareVaultV1Deposit; } });
35
+ Object.defineProperty(exports, "prepareVaultV1InKindRedeem", { enumerable: true, get: function () { return index_js_1.prepareVaultV1InKindRedeem; } });
36
+ Object.defineProperty(exports, "prepareVaultV1MigrateToV2", { enumerable: true, get: function () { return index_js_1.prepareVaultV1MigrateToV2; } });
37
+ Object.defineProperty(exports, "prepareVaultV1Redeem", { enumerable: true, get: function () { return index_js_1.prepareVaultV1Redeem; } });
38
+ Object.defineProperty(exports, "prepareVaultV1Withdraw", { enumerable: true, get: function () { return index_js_1.prepareVaultV1Withdraw; } });
34
39
  Object.defineProperty(exports, "prepareVaultV2Deposit", { enumerable: true, get: function () { return index_js_1.prepareVaultV2Deposit; } });
40
+ Object.defineProperty(exports, "prepareVaultV2ForceRedeem", { enumerable: true, get: function () { return index_js_1.prepareVaultV2ForceRedeem; } });
41
+ Object.defineProperty(exports, "prepareVaultV2ForceWithdraw", { enumerable: true, get: function () { return index_js_1.prepareVaultV2ForceWithdraw; } });
42
+ Object.defineProperty(exports, "prepareVaultV2InKindRedeem", { enumerable: true, get: function () { return index_js_1.prepareVaultV2InKindRedeem; } });
43
+ Object.defineProperty(exports, "prepareVaultV2Redeem", { enumerable: true, get: function () { return index_js_1.prepareVaultV2Redeem; } });
35
44
  Object.defineProperty(exports, "prepareVaultV2Withdraw", { enumerable: true, get: function () { return index_js_1.prepareVaultV2Withdraw; } });
36
45
  Object.defineProperty(exports, "serializeTransactionPlan", { enumerable: true, get: function () { return index_js_1.serializeTransactionPlan; } });
37
46
  Object.defineProperty(exports, "TransactionPlanSignatureMismatchError", { enumerable: true, get: function () { return index_js_1.TransactionPlanSignatureMismatchError; } });
@@ -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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.InvalidEcrecoverSignatureError = exports.ChainIdMismatchError = void 0;
3
+ exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.InvalidEcrecoverSignatureError = exports.ChainIdMismatchError = void 0;
4
4
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  Object.defineProperty(exports, "ChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
6
6
  Object.defineProperty(exports, "InvalidEcrecoverSignatureError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureError; } });
@@ -10,6 +10,9 @@ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerabl
10
10
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
11
11
  Object.defineProperty(exports, "InvalidOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
12
12
  Object.defineProperty(exports, "InvalidOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
13
+ Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
14
+ Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
15
+ Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
13
16
  Object.defineProperty(exports, "InvalidRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
14
17
  Object.defineProperty(exports, "InvalidRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
15
18
  Object.defineProperty(exports, "InvalidRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -27,7 +30,3 @@ Object.defineProperty(exports, "RatifierV1TakerNotAllowedError", { enumerable: t
27
30
  Object.defineProperty(exports, "SettlementFeeExceedsPriceError", { enumerable: true, get: function () { return midnight_sdk_1.SettlementFeeExceedsPriceError; } });
28
31
  Object.defineProperty(exports, "TickOutOfRangeError", { enumerable: true, get: function () { return midnight_sdk_1.TickOutOfRangeError; } });
29
32
  Object.defineProperty(exports, "UnknownCollateralIndexError", { enumerable: true, get: function () { return midnight_sdk_1.UnknownCollateralIndexError; } });
30
- var morpho_ts_1 = require("@morpho-org/morpho-ts");
31
- Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
32
- Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
33
- Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateApprovalPlanAction = validateApprovalPlanAction;
4
+ const error_js_1 = require("./error.js");
4
5
  const validation_js_1 = require("./validation.js");
5
6
  /** @internal Validates the stored ERC-20 approval action's input shape. */
6
7
  function validateApprovalPlanAction(action, path) {
@@ -10,7 +11,17 @@ function validateApprovalPlanAction(action, path) {
10
11
  fields: {
11
12
  token: "address",
12
13
  spender: "address",
13
- amount: "uint256 bigint",
14
14
  },
15
15
  });
16
+ if ((inputs.assets === undefined) === (inputs.shares === undefined)) {
17
+ throw new error_js_1.InvalidTransactionPlanError({
18
+ path: `${path}.inputs`,
19
+ reason: "expected exactly one of assets or shares",
20
+ });
21
+ }
22
+ const field = inputs.assets === undefined ? "shares" : "assets";
23
+ (0, validation_js_1.validatePlanField)(inputs[field], {
24
+ path: `${path}.inputs.${field}`,
25
+ type: "uint256 bigint",
26
+ });
16
27
  }
@@ -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,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateDepositPlanAction = validateDepositPlanAction;
4
+ exports.prepareVaultDeposit = prepareVaultDeposit;
5
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
6
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
+ const common_js_1 = require("../actions/bundles/common.js");
8
+ const validateClientChainId_js_1 = require("../actions/requirements/validateClientChainId.js");
9
+ const assertContractCode_js_1 = require("../entities/requirements/assertContractCode.js");
10
+ const index_js_1 = require("../helpers/index.js");
11
+ const validate_js_1 = require("../helpers/validate.js");
12
+ const index_js_2 = require("../types/index.js");
13
+ const error_js_1 = require("./error.js");
14
+ const intent_js_1 = require("./intent.js");
15
+ const requirements_js_1 = require("./requirements.js");
16
+ const validation_js_1 = require("./validation.js");
17
+ /** @internal Validates the stored Vault V1 or V2 deposit action's input shape. */
18
+ function validateDepositPlanAction(action, path) {
19
+ const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
20
+ (0, validation_js_1.validatePlanFields)(inputs, {
21
+ path: `${path}.inputs`,
22
+ fields: { asset: "address", maxSharePrice: "uint256 bigint" },
23
+ });
24
+ if ((inputs.assets === undefined) === (inputs.nativeAssets === undefined)) {
25
+ throw new error_js_1.InvalidTransactionPlanError({
26
+ path: `${path}.inputs`,
27
+ reason: "expected exactly one of assets or nativeAssets",
28
+ });
29
+ }
30
+ const field = inputs.assets === undefined ? "nativeAssets" : "assets";
31
+ (0, validation_js_1.validatePlanField)(inputs[field], {
32
+ path: `${path}.inputs.${field}`,
33
+ type: "uint256 bigint",
34
+ });
35
+ }
36
+ function resolveDepositInputs(params, now) {
37
+ const { vault, chainId, assets } = params;
38
+ const intent = (0, intent_js_1.resolveIntent)(params, now);
39
+ const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
40
+ (0, validate_js_1.validateSlippageTolerance)(slippageTolerance);
41
+ const native = (params.funding ?? { type: "erc20" }).type === "native";
42
+ if (assets <= 0n) {
43
+ throw new index_js_2.NonPositiveInputError("assets", assets);
44
+ }
45
+ // Reject amounts that cannot be encoded as uint256 before making RPC requests.
46
+ (0, validate_js_1.validateUint256Field)("assets", assets);
47
+ const common = (0, common_js_1.normalizeBundlesCommonParams)({
48
+ deadline: intent.deadline,
49
+ referralFeePct: intent.referralFeePct,
50
+ referralFeeRecipient: intent.referralFeeRecipient,
51
+ });
52
+ const { asset } = vault;
53
+ // Native funding must target the chain's wrapped-native vault asset.
54
+ if (native) {
55
+ (0, validate_js_1.validateNativeVaultAsset)(chainId, asset);
56
+ }
57
+ // The quote depends only on the snapshot and the intent, so it is fixed before any read.
58
+ const maxSharePrice = (0, index_js_1.computeVaultMaxSharePrice)({
59
+ vaultData: vault,
60
+ deadline: intent.deadline,
61
+ assets: assets - (0, common_js_1.getBundlesReferralFeeAssets)(assets, common.referralFeePct),
62
+ slippageTolerance,
63
+ });
64
+ return { intent, native, common, asset, maxSharePrice };
65
+ }
66
+ /** @internal Prepares a deposit using its vault action and caller-supplied snapshot type. */
67
+ async function prepareVaultDeposit(client, params) {
68
+ const { chainId, account, assets } = params;
69
+ const vault = params.vault.address;
70
+ const now = params.now ?? morpho_ts_1.Time.timestamp();
71
+ const { intent, native, common, asset, maxSharePrice } = resolveDepositInputs(params, now);
72
+ const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
73
+ const [requirements] = await Promise.all([
74
+ (0, validateClientChainId_js_1.validateClientChainId)(client, chainId).then(() => native
75
+ ? []
76
+ : (0, requirements_js_1.getTokenRequirements)(client, {
77
+ token: asset,
78
+ spender,
79
+ amount: assets,
80
+ owner: account,
81
+ chainId,
82
+ deadline: intent.deadline,
83
+ now,
84
+ supportSignature: intent.supportSignature,
85
+ deployless: intent.deployless,
86
+ })),
87
+ (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
88
+ { role: "bundles.vaultBundlesV1", address: spender },
89
+ ]),
90
+ ]);
91
+ const approvals = [];
92
+ const signatureRequests = [];
93
+ const tokenPermitRequestId = `${params.type}:tokenPermit`;
94
+ for (const requirement of requirements) {
95
+ if ("sign" in requirement) {
96
+ signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)(requirement, tokenPermitRequestId));
97
+ }
98
+ else {
99
+ approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
100
+ id: approvals.length === 0
101
+ ? `${params.type}:approval`
102
+ : `${params.type}:approval:${approvals.length + 1}`,
103
+ chainId,
104
+ account,
105
+ denomination: "assets",
106
+ }));
107
+ }
108
+ }
109
+ return (0, morpho_ts_1.deepFreeze)(structuredClone({
110
+ version: 2,
111
+ account,
112
+ chainId,
113
+ expiresAt: intent.expiresAt,
114
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
115
+ steps: [
116
+ ...approvals,
117
+ {
118
+ id: params.type,
119
+ label: "Deposit into vault",
120
+ action: {
121
+ type: params.type,
122
+ inputs: {
123
+ chainId,
124
+ account,
125
+ vault,
126
+ asset,
127
+ maxSharePrice,
128
+ ...(native ? { nativeAssets: assets } : { assets }),
129
+ ...common,
130
+ },
131
+ signatureRequestIds: signatureRequests.length > 0
132
+ ? { tokenPermit: tokenPermitRequestId }
133
+ : {},
134
+ },
135
+ },
136
+ ],
137
+ signatureRequests,
138
+ }));
139
+ }
@@ -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;