@morpho-org/morpho-sdk 9.8.0 → 10.0.0

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 (303) hide show
  1. package/MIGRATION-v9-to-v10.md +114 -0
  2. package/README.md +109 -13
  3. package/lib/cjs/actions/blue/common.js +4 -2
  4. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
  5. package/lib/cjs/actions/bundles/common.js +20 -14
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  7. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
  8. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
  9. package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
  10. package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
  11. package/lib/cjs/actions/midnight/cancelOffers.js +108 -0
  12. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  13. package/lib/cjs/actions/midnight/index.js +1 -0
  14. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
  18. package/lib/cjs/actions/midnight/takeBorrow.js +3 -2
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
  20. package/lib/cjs/actions/midnight/takeLend.js +3 -2
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +3 -2
  25. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
  26. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  27. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  28. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  29. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  31. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +5 -13
  34. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  35. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  36. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  37. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  38. package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
  39. package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
  40. package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
  41. package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
  42. package/lib/cjs/entities/blue/blue.d.ts +34 -28
  43. package/lib/cjs/entities/blue/blue.js +107 -77
  44. package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
  45. package/lib/cjs/entities/midnight/deadline.js +4 -3
  46. package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
  47. package/lib/cjs/entities/midnight/midnight.js +158 -138
  48. package/lib/cjs/entities/midnight/publication.d.ts +2 -0
  49. package/lib/cjs/entities/midnight/publication.js +193 -138
  50. package/lib/cjs/entities/midnight/types.d.ts +4 -4
  51. package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
  52. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  53. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +24 -28
  54. package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
  55. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
  56. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  57. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  58. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
  59. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  60. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
  61. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  62. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
  63. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  64. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
  65. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  66. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
  67. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
  68. package/lib/cjs/entities/vaultV1/vaultV1.js +90 -194
  69. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  70. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
  71. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  72. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
  73. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -16
  74. package/lib/cjs/entities/vaultV2/vaultV2.js +94 -385
  75. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +14 -0
  76. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1599 -883
  77. package/lib/cjs/errors.d.ts +1 -1
  78. package/lib/cjs/errors.js +2 -1
  79. package/lib/cjs/helpers/deadShares.js +83 -47
  80. package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
  81. package/lib/cjs/helpers/metadata.d.ts +14 -2
  82. package/lib/cjs/helpers/metadata.js +49 -8
  83. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +44 -27
  84. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +11 -2
  85. package/lib/cjs/helpers/utilization.js +10 -5
  86. package/lib/cjs/helpers/validate.js +88 -67
  87. package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
  88. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
  89. package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
  90. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +177 -104
  91. package/lib/cjs/helpers/validatePositiveInput.js +2 -1
  92. package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
  93. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +40 -22
  94. package/lib/cjs/index.d.ts +2 -2
  95. package/lib/cjs/index.js +10 -1
  96. package/lib/cjs/transactionPlan/approval.js +12 -1
  97. package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
  98. package/lib/cjs/transactionPlan/deposit.js +139 -0
  99. package/lib/cjs/transactionPlan/error.d.ts +10 -8
  100. package/lib/cjs/transactionPlan/error.js +10 -8
  101. package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
  102. package/lib/cjs/transactionPlan/index.d.ts +18 -0
  103. package/lib/cjs/transactionPlan/index.js +23 -5
  104. package/lib/cjs/transactionPlan/intent.d.ts +3 -3
  105. package/lib/cjs/transactionPlan/intent.js +14 -7
  106. package/lib/cjs/transactionPlan/permit.d.ts +1 -1
  107. package/lib/cjs/transactionPlan/permit.js +86 -20
  108. package/lib/cjs/transactionPlan/plan.d.ts +16 -6
  109. package/lib/cjs/transactionPlan/plan.js +77 -24
  110. package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
  111. package/lib/cjs/transactionPlan/redeem.js +63 -0
  112. package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
  113. package/lib/cjs/transactionPlan/requirements.js +12 -6
  114. package/lib/cjs/transactionPlan/serde.d.ts +2 -2
  115. package/lib/cjs/transactionPlan/serde.js +45 -19
  116. package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
  117. package/lib/cjs/transactionPlan/shareSpending.js +50 -0
  118. package/lib/cjs/transactionPlan/types.d.ts +117 -11
  119. package/lib/cjs/transactionPlan/validateActions.js +11 -1
  120. package/lib/cjs/transactionPlan/validation.js +6 -3
  121. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
  122. package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
  123. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  124. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
  125. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  126. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
  127. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
  128. package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
  129. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  130. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
  131. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +18 -33
  132. package/lib/cjs/transactionPlan/vaultv2/deposit.js +19 -143
  133. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  134. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
  135. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  136. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
  137. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  138. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
  139. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
  140. package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
  141. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +18 -29
  142. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +21 -126
  143. package/lib/cjs/transactionPlan/version.js +2 -1
  144. package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
  145. package/lib/cjs/transactionPlan/withdraw.js +94 -0
  146. package/lib/cjs/types/action.d.ts +26 -2
  147. package/lib/cjs/types/action.js +17 -9
  148. package/lib/cjs/types/error.d.ts +8 -1
  149. package/lib/cjs/types/error.js +21 -6
  150. package/lib/cjs/types/metadata.d.ts +12 -2
  151. package/lib/cjs/version.d.ts +1 -1
  152. package/lib/cjs/version.js +1 -1
  153. package/lib/esm/actions/blue/common.js +4 -2
  154. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
  155. package/lib/esm/actions/bundles/common.js +20 -14
  156. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  157. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
  158. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
  159. package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
  160. package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
  161. package/lib/esm/actions/midnight/cancelOffers.js +104 -0
  162. package/lib/esm/actions/midnight/index.d.ts +1 -0
  163. package/lib/esm/actions/midnight/index.js +1 -0
  164. package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
  165. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  166. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
  167. package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
  168. package/lib/esm/actions/midnight/takeBorrow.js +3 -2
  169. package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
  170. package/lib/esm/actions/midnight/takeLend.js +3 -2
  171. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  172. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
  173. package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
  174. package/lib/esm/actions/midnight/takeWithdraw.js +3 -2
  175. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
  176. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  177. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  178. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  179. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  180. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  181. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
  182. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  183. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +7 -15
  184. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  185. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  186. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  187. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  188. package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
  189. package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
  190. package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
  191. package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
  192. package/lib/esm/entities/blue/blue.d.ts +34 -28
  193. package/lib/esm/entities/blue/blue.js +107 -77
  194. package/lib/esm/entities/midnight/deadline.d.ts +2 -2
  195. package/lib/esm/entities/midnight/deadline.js +4 -3
  196. package/lib/esm/entities/midnight/midnight.d.ts +49 -51
  197. package/lib/esm/entities/midnight/midnight.js +159 -139
  198. package/lib/esm/entities/midnight/publication.d.ts +2 -0
  199. package/lib/esm/entities/midnight/publication.js +193 -138
  200. package/lib/esm/entities/midnight/types.d.ts +4 -4
  201. package/lib/esm/entities/requirements/assertContractCode.js +4 -2
  202. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  203. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +25 -29
  204. package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
  205. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
  206. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  207. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  208. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
  209. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  210. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
  211. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  212. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
  213. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  214. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
  215. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  216. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
  217. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
  218. package/lib/esm/entities/vaultV1/vaultV1.js +96 -200
  219. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  220. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
  221. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  222. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
  223. package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -16
  224. package/lib/esm/entities/vaultV2/vaultV2.js +102 -393
  225. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +14 -0
  226. package/lib/esm/entities/vaultV2BlueReallocationData.js +1599 -883
  227. package/lib/esm/errors.d.ts +1 -1
  228. package/lib/esm/errors.js +1 -1
  229. package/lib/esm/helpers/deadShares.js +83 -47
  230. package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
  231. package/lib/esm/helpers/metadata.d.ts +14 -2
  232. package/lib/esm/helpers/metadata.js +48 -8
  233. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +44 -27
  234. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +11 -2
  235. package/lib/esm/helpers/utilization.js +10 -5
  236. package/lib/esm/helpers/validate.js +88 -67
  237. package/lib/esm/helpers/validateMidnightBounds.js +2 -1
  238. package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
  239. package/lib/esm/helpers/validateMidnightPublication.js +4 -2
  240. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +176 -103
  241. package/lib/esm/helpers/validatePositiveInput.js +2 -1
  242. package/lib/esm/helpers/validateTakeableOffers.js +2 -1
  243. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +40 -22
  244. package/lib/esm/index.d.ts +2 -2
  245. package/lib/esm/index.js +1 -1
  246. package/lib/esm/transactionPlan/approval.js +13 -2
  247. package/lib/esm/transactionPlan/deposit.d.ts +22 -0
  248. package/lib/esm/transactionPlan/deposit.js +135 -0
  249. package/lib/esm/transactionPlan/error.d.ts +10 -8
  250. package/lib/esm/transactionPlan/error.js +10 -8
  251. package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
  252. package/lib/esm/transactionPlan/index.d.ts +18 -0
  253. package/lib/esm/transactionPlan/index.js +9 -0
  254. package/lib/esm/transactionPlan/intent.d.ts +3 -3
  255. package/lib/esm/transactionPlan/intent.js +14 -7
  256. package/lib/esm/transactionPlan/permit.d.ts +1 -1
  257. package/lib/esm/transactionPlan/permit.js +86 -20
  258. package/lib/esm/transactionPlan/plan.d.ts +16 -6
  259. package/lib/esm/transactionPlan/plan.js +73 -20
  260. package/lib/esm/transactionPlan/redeem.d.ts +18 -0
  261. package/lib/esm/transactionPlan/redeem.js +59 -0
  262. package/lib/esm/transactionPlan/requirements.d.ts +4 -3
  263. package/lib/esm/transactionPlan/requirements.js +12 -6
  264. package/lib/esm/transactionPlan/serde.d.ts +2 -2
  265. package/lib/esm/transactionPlan/serde.js +45 -19
  266. package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
  267. package/lib/esm/transactionPlan/shareSpending.js +47 -0
  268. package/lib/esm/transactionPlan/types.d.ts +117 -11
  269. package/lib/esm/transactionPlan/validateActions.js +11 -1
  270. package/lib/esm/transactionPlan/validation.js +6 -3
  271. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
  272. package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
  273. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  274. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
  275. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  276. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
  277. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
  278. package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
  279. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  280. package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
  281. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +18 -33
  282. package/lib/esm/transactionPlan/vaultv2/deposit.js +21 -144
  283. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  284. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
  285. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  286. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
  287. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  288. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
  289. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
  290. package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
  291. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +18 -29
  292. package/lib/esm/transactionPlan/vaultv2/withdraw.js +23 -127
  293. package/lib/esm/transactionPlan/version.js +2 -1
  294. package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
  295. package/lib/esm/transactionPlan/withdraw.js +90 -0
  296. package/lib/esm/types/action.d.ts +26 -2
  297. package/lib/esm/types/action.js +17 -9
  298. package/lib/esm/types/error.d.ts +8 -1
  299. package/lib/esm/types/error.js +21 -6
  300. package/lib/esm/types/metadata.d.ts +12 -2
  301. package/lib/esm/version.d.ts +1 -1
  302. package/lib/esm/version.js +1 -1
  303. package/package.json +15 -14
@@ -3,13 +3,14 @@ import { fetchMarket as fetchBlueMarket } from "@morpho-org/blue-sdk-viem";
3
3
  import { fetchAccrualPosition, fetchMarket, MarketParams, MarketUtils, Payload, PriceRatifierV1, RateRatifierV1, Tree, } from "@morpho-org/midnight-sdk";
4
4
  import { _try, getChainAddress, Time } from "@morpho-org/morpho-ts";
5
5
  import { isAddress, isAddressEqual, maxUint256, zeroAddress, } from "viem";
6
- import { midnightCancelAndMake, midnightRedeem, midnightRepayWithdrawCollateral, midnightSupplyCollateral, midnightSupplyCollateralBatch, midnightSupplyCollateralTakeBorrow, midnightTakeBorrow, midnightTakeLend, midnightTakeRepayWithdrawCollateral, midnightTakeWithdraw, midnightWithdrawCollateral, midnightWithdrawCollateralBatch, } from "../../actions/midnight/index.js";
6
+ import { midnightCancelAndMake, midnightCancelOffers, midnightRedeem, midnightRepayWithdrawCollateral, midnightSupplyCollateral, midnightSupplyCollateralBatch, midnightSupplyCollateralTakeBorrow, midnightTakeBorrow, midnightTakeLend, midnightTakeRepayWithdrawCollateral, midnightTakeWithdraw, midnightWithdrawCollateral, midnightWithdrawCollateralBatch, } from "../../actions/midnight/index.js";
7
7
  import { getMidnightApprovalRequirements, getMidnightAuthorizationRequirement, } from "../../actions/requirements/index.js";
8
8
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
9
9
  import { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "../../helpers/callback.js";
10
10
  import { MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS } from "../../helpers/constant.js";
11
11
  import { encodeMidnightMarketId, wrapMidnightEncoding, } from "../../helpers/encodeMidnightCalldata.js";
12
12
  import { getMidnightMaxSafeDebt, validateChainId, } from "../../helpers/index.js";
13
+ import { resolveTransactionMetadata } from "../../helpers/metadata.js";
13
14
  import { validateMidnightAccount, validateMidnightAddress, } from "../../helpers/validateMidnightAccount.js";
14
15
  import { validateMidnightUint128Field } from "../../helpers/validateMidnightBounds.js";
15
16
  import { validateMidnightCollateralBatch } from "../../helpers/validateMidnightCollateralBatch.js";
@@ -30,8 +31,7 @@ const validatePositionBinding = (params) => {
30
31
  throw new AccrualPositionUserMismatchError(params.positionData.user, params.accountAddress);
31
32
  }
32
33
  };
33
- const validateTakeDeadlineWindow = (deadline) => {
34
- const now = Time.timestamp();
34
+ const validateTakeDeadlineWindow = (deadline, now = Time.timestamp()) => {
35
35
  // Throws when the deadline is at or before now.
36
36
  validateMidnightDeadline(deadline, now);
37
37
  const maxDeadline = now + MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS;
@@ -40,17 +40,20 @@ const validateTakeDeadlineWindow = (deadline) => {
40
40
  }
41
41
  };
42
42
  const assertNonNegativeAmount = (label, amount) => {
43
- if (amount < 0n)
43
+ if (amount < 0n) {
44
44
  throw new NegativeInputError(label, amount);
45
+ }
45
46
  };
46
47
  const assertPositiveAmount = (label, amount) => {
47
- if (amount <= 0n)
48
+ if (amount <= 0n) {
48
49
  throw new NonPositiveInputError(label, amount);
50
+ }
49
51
  };
50
52
  const rejectReduceOnlyOffers = (offers) => {
51
53
  offers.forEach((offer, index) => {
52
- if (offer.reduceOnly)
54
+ if (offer.reduceOnly) {
53
55
  throw new MidnightOfferReduceOnlyError({ index });
56
+ }
54
57
  });
55
58
  };
56
59
  const getOffersDataInternal = async ({ client, chainId, params, marketCreationTime = "expiry", }) => {
@@ -147,6 +150,29 @@ const getOffersDataInternal = async ({ client, chainId, params, marketCreationTi
147
150
  payload: await Payload.encode(items),
148
151
  };
149
152
  };
153
+ const getPostWithdrawalCollateral = (params) => {
154
+ const market = params.marketData.params;
155
+ const collateralWithdrawals = params.collateralWithdrawals ?? [];
156
+ const postCollateral = Array.from({ length: market.collateralParams.length }, (_, index) => params.positionData.collateral[index] ?? 0n);
157
+ let withdrawAmount = 0n;
158
+ for (const withdrawal of collateralWithdrawals) {
159
+ // Reject unconfigured collateral indexes before updating postCollateral.
160
+ MarketUtils.getCollateralByIndex(market, withdrawal.collateralIndex);
161
+ const index = Number(withdrawal.collateralIndex);
162
+ const available = postCollateral[index] ?? 0n;
163
+ const amount = withdrawal.assets === maxUint256 ? available : withdrawal.assets;
164
+ if (amount > available) {
165
+ throw new WithdrawExceedsCollateralError({
166
+ withdrawAmount: amount,
167
+ available,
168
+ market: params.marketData.id,
169
+ });
170
+ }
171
+ postCollateral[index] = available - amount;
172
+ withdrawAmount += amount;
173
+ }
174
+ return { postCollateral, withdrawAmount };
175
+ };
150
176
  const validateMarketData = (market, chainId) => {
151
177
  // Reject snapshots from another chain deployment before exposing requirements.
152
178
  validateMidnightMarket({ market, chainId });
@@ -361,15 +387,18 @@ export class MorphoMidnight {
361
387
  * target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
362
388
  * takeableOffers: quote.data.takeableOffers,
363
389
  * maxContinuousFee: maxUint256,
364
- * deadline: Time.timestamp() + 600n,
390
+ * now: (await client.getBlock()).timestamp,
391
+ * deadline: (await client.getBlock()).timestamp + 600n,
365
392
  * });
366
393
  * ```
367
394
  */
368
395
  takeLend(params) {
396
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
369
397
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
370
398
  // Reject the zero account before preparing anything for it.
371
399
  validateMidnightAccount("accountAddress", params.accountAddress);
372
- validateTakeDeadlineWindow(params.deadline);
400
+ const now = params.now ?? Time.timestamp();
401
+ validateTakeDeadlineWindow(params.deadline, now);
373
402
  const market = params.marketData.params;
374
403
  const rawParams = {
375
404
  chainId: this.chainId,
@@ -381,7 +410,7 @@ export class MorphoMidnight {
381
410
  deadline: params.deadline,
382
411
  referralFeePct: params.referralFeePct,
383
412
  referralFeeRecipient: params.referralFeeRecipient,
384
- metadata: this.client.options.metadata,
413
+ metadata,
385
414
  };
386
415
  let tx = midnightTakeLend(rawParams);
387
416
  const takeableOffers = validateMidnightTakeFeasibility({
@@ -389,7 +418,7 @@ export class MorphoMidnight {
389
418
  takeableOffers: params.takeableOffers,
390
419
  accountAddress: params.accountAddress,
391
420
  marketData: params.marketData,
392
- now: Time.timestamp(),
421
+ now: params.now ?? Time.timestamp(),
393
422
  deadline: params.deadline,
394
423
  referralFeePct: tx.action.args.referralFeePct,
395
424
  fallbackUnits: 0n,
@@ -508,15 +537,18 @@ export class MorphoMidnight {
508
537
  * collateralPrices,
509
538
  * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
510
539
  * takeableOffers: quote.data.takeableOffers,
511
- * deadline: Time.timestamp() + 600n,
540
+ * now: (await client.getBlock()).timestamp,
541
+ * deadline: (await client.getBlock()).timestamp + 600n,
512
542
  * });
513
543
  * ```
514
544
  */
515
545
  takeBorrow(params) {
546
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
516
547
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
517
548
  // Reject the zero account before preparing anything for it.
518
549
  validateMidnightAccount("accountAddress", params.accountAddress);
519
- validateTakeDeadlineWindow(params.deadline);
550
+ const now = params.now ?? Time.timestamp();
551
+ validateTakeDeadlineWindow(params.deadline, now);
520
552
  const rawParams = {
521
553
  chainId: this.chainId,
522
554
  market: params.marketData.params,
@@ -526,7 +558,7 @@ export class MorphoMidnight {
526
558
  deadline: params.deadline,
527
559
  referralFeePct: params.referralFeePct,
528
560
  referralFeeRecipient: params.referralFeeRecipient,
529
- metadata: this.client.options.metadata,
561
+ metadata,
530
562
  };
531
563
  let tx = midnightTakeBorrow(rawParams);
532
564
  validatePositionBinding({
@@ -548,7 +580,6 @@ export class MorphoMidnight {
548
580
  throw new BorrowExceedsSafeLtvError(requestedUnits, MathLib.zeroFloorSub(maxSafeDebt, params.positionData.debt));
549
581
  }
550
582
  }
551
- const now = Time.timestamp();
552
583
  const takeableOffers = validateMidnightTakeFeasibility({
553
584
  side: "sell",
554
585
  takeableOffers: params.takeableOffers,
@@ -635,15 +666,18 @@ export class MorphoMidnight {
635
666
  * marketData,
636
667
  * target: { type: "units", units: credit, minSellerAssets: 990_000n },
637
668
  * takeableOffers: quote.data.takeableOffers,
638
- * deadline: Time.timestamp() + 600n,
669
+ * now: (await client.getBlock()).timestamp,
670
+ * deadline: (await client.getBlock()).timestamp + 600n,
639
671
  * });
640
672
  * ```
641
673
  */
642
674
  takeWithdraw(params) {
675
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
643
676
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
644
677
  // Reject the zero account before preparing anything for it.
645
678
  validateMidnightAccount("accountAddress", params.accountAddress);
646
- validateTakeDeadlineWindow(params.deadline);
679
+ const now = params.now ?? Time.timestamp();
680
+ validateTakeDeadlineWindow(params.deadline, now);
647
681
  const rawParams = {
648
682
  chainId: this.chainId,
649
683
  market: params.marketData.params,
@@ -653,7 +687,7 @@ export class MorphoMidnight {
653
687
  deadline: params.deadline,
654
688
  referralFeePct: params.referralFeePct,
655
689
  referralFeeRecipient: params.referralFeeRecipient,
656
- metadata: this.client.options.metadata,
690
+ metadata,
657
691
  };
658
692
  let tx = midnightTakeWithdraw(rawParams);
659
693
  const takeableOffers = validateMidnightTakeFeasibility({
@@ -661,7 +695,7 @@ export class MorphoMidnight {
661
695
  takeableOffers: params.takeableOffers,
662
696
  accountAddress: params.accountAddress,
663
697
  marketData: params.marketData,
664
- now: Time.timestamp(),
698
+ now: params.now ?? Time.timestamp(),
665
699
  deadline: params.deadline,
666
700
  referralFeePct: tx.action.args.referralFeePct,
667
701
  // The bundle redeems credit first, up to the market's withdrawable liquidity.
@@ -768,15 +802,18 @@ export class MorphoMidnight {
768
802
  * collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
769
803
  * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
770
804
  * takeableOffers: quote.data.takeableOffers,
771
- * deadline: Time.timestamp() + 600n,
805
+ * now: (await client.getBlock()).timestamp,
806
+ * deadline: (await client.getBlock()).timestamp + 600n,
772
807
  * });
773
808
  * ```
774
809
  */
775
810
  supplyCollateralTakeBorrow(params) {
811
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
776
812
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
777
813
  // Reject the zero account before preparing anything for it.
778
814
  validateMidnightAccount("accountAddress", params.accountAddress);
779
- validateTakeDeadlineWindow(params.deadline);
815
+ const now = params.now ?? Time.timestamp();
816
+ validateTakeDeadlineWindow(params.deadline, now);
780
817
  const market = params.marketData.params;
781
818
  const rawParams = {
782
819
  chainId: this.chainId,
@@ -789,7 +826,7 @@ export class MorphoMidnight {
789
826
  deadline: params.deadline,
790
827
  referralFeePct: params.referralFeePct,
791
828
  referralFeeRecipient: params.referralFeeRecipient,
792
- metadata: this.client.options.metadata,
829
+ metadata,
793
830
  };
794
831
  let tx = midnightSupplyCollateralTakeBorrow(rawParams);
795
832
  validatePositionBinding({
@@ -818,7 +855,6 @@ export class MorphoMidnight {
818
855
  throw new BorrowExceedsSafeLtvError(requestedUnits, MathLib.zeroFloorSub(maxSafeDebt, params.positionData.debt));
819
856
  }
820
857
  }
821
- const now = Time.timestamp();
822
858
  const takeableOffers = validateMidnightTakeFeasibility({
823
859
  side: "sell",
824
860
  takeableOffers: params.takeableOffers,
@@ -962,15 +998,18 @@ export class MorphoMidnight {
962
998
  * repayEnabled: true,
963
999
  * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
964
1000
  * maxContinuousFee: maxUint256,
965
- * deadline: Time.timestamp() + 600n,
1001
+ * now: (await client.getBlock()).timestamp,
1002
+ * deadline: (await client.getBlock()).timestamp + 600n,
966
1003
  * });
967
1004
  * ```
968
1005
  */
969
1006
  takeRepayWithdrawCollateral(params) {
1007
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
970
1008
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
971
1009
  // Reject the zero account before preparing anything for it.
972
1010
  validateMidnightAccount("accountAddress", params.accountAddress);
973
- validateTakeDeadlineWindow(params.deadline);
1011
+ const now = params.now ?? Time.timestamp();
1012
+ validateTakeDeadlineWindow(params.deadline, now);
974
1013
  const market = params.marketData.params;
975
1014
  const rawParams = {
976
1015
  chainId: this.chainId,
@@ -985,7 +1024,7 @@ export class MorphoMidnight {
985
1024
  deadline: params.deadline,
986
1025
  referralFeePct: params.referralFeePct,
987
1026
  referralFeeRecipient: params.referralFeeRecipient,
988
- metadata: this.client.options.metadata,
1027
+ metadata,
989
1028
  };
990
1029
  let tx = midnightTakeRepayWithdrawCollateral(rawParams);
991
1030
  validatePositionBinding({
@@ -994,24 +1033,7 @@ export class MorphoMidnight {
994
1033
  marketData: params.marketData,
995
1034
  });
996
1035
  const collateralWithdrawals = params.collateralWithdrawals ?? [];
997
- const postCollateral = Array.from({ length: market.collateralParams.length }, (_, index) => params.positionData.collateral[index] ?? 0n);
998
- let withdrawAmount = 0n;
999
- for (const withdrawal of collateralWithdrawals) {
1000
- // Reject unconfigured collateral indexes before updating postCollateral.
1001
- MarketUtils.getCollateralByIndex(market, withdrawal.collateralIndex);
1002
- const index = Number(withdrawal.collateralIndex);
1003
- const available = postCollateral[index] ?? 0n;
1004
- const amount = withdrawal.assets === maxUint256 ? available : withdrawal.assets;
1005
- if (amount > available) {
1006
- throw new WithdrawExceedsCollateralError({
1007
- withdrawAmount: amount,
1008
- available,
1009
- market: params.marketData.id,
1010
- });
1011
- }
1012
- postCollateral[index] = available - amount;
1013
- withdrawAmount += amount;
1014
- }
1036
+ const { postCollateral, withdrawAmount } = getPostWithdrawalCollateral(params);
1015
1037
  const debtReduction = params.target.type === "units"
1016
1038
  ? params.target.units
1017
1039
  : params.target.minUnits;
@@ -1037,7 +1059,7 @@ export class MorphoMidnight {
1037
1059
  takeableOffers: params.takeableOffers,
1038
1060
  accountAddress: params.accountAddress,
1039
1061
  marketData: params.marketData,
1040
- now: Time.timestamp(),
1062
+ now: params.now ?? Time.timestamp(),
1041
1063
  deadline: params.deadline,
1042
1064
  referralFeePct: tx.action.args.referralFeePct,
1043
1065
  // With repayEnabled the bundle repays the unfilled debt directly, at par.
@@ -1117,6 +1139,7 @@ export class MorphoMidnight {
1117
1139
  * ```
1118
1140
  */
1119
1141
  withdrawCollateral(params) {
1142
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
1120
1143
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
1121
1144
  // Reject invalid owners before preparing the direct call.
1122
1145
  validateMidnightAccount("accountAddress", params.accountAddress);
@@ -1135,7 +1158,7 @@ export class MorphoMidnight {
1135
1158
  assets,
1136
1159
  onBehalf: params.accountAddress,
1137
1160
  receiver: params.receiver ?? params.accountAddress,
1138
- metadata: this.client.options.metadata,
1161
+ metadata,
1139
1162
  });
1140
1163
  if (assets > available) {
1141
1164
  throw new WithdrawExceedsCollateralError({
@@ -1208,6 +1231,7 @@ export class MorphoMidnight {
1208
1231
  * ```
1209
1232
  */
1210
1233
  withdrawCollateralBatch(params) {
1234
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
1211
1235
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
1212
1236
  // Reject invalid owners before preparing the direct call.
1213
1237
  validateMidnightAccount("accountAddress", params.accountAddress);
@@ -1231,12 +1255,12 @@ export class MorphoMidnight {
1231
1255
  collateralWithdrawals,
1232
1256
  onBehalf: params.accountAddress,
1233
1257
  receiver: params.receiver ?? params.accountAddress,
1234
- metadata: this.client.options.metadata,
1258
+ metadata,
1235
1259
  });
1236
1260
  const collateral = Array.from({ length: params.marketData.params.collateralParams.length }, (_, i) => params.positionData.collateral[i] ?? 0n);
1237
1261
  for (const { collateralIndex, assets } of collateralWithdrawals) {
1238
1262
  const index = Number(collateralIndex);
1239
- const available = collateral[index];
1263
+ const available = collateral[index] ?? 0n;
1240
1264
  if (assets > available) {
1241
1265
  throw new WithdrawExceedsCollateralError({
1242
1266
  withdrawAmount: assets,
@@ -1300,6 +1324,7 @@ export class MorphoMidnight {
1300
1324
  * ```
1301
1325
  */
1302
1326
  supplyCollateral(params) {
1327
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
1303
1328
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
1304
1329
  // Reject a malformed account here; the builder rejects the zero account.
1305
1330
  validateMidnightAddress("accountAddress", params.accountAddress);
@@ -1332,7 +1357,7 @@ export class MorphoMidnight {
1332
1357
  collateralIndex,
1333
1358
  assets: params.collateralAssets,
1334
1359
  onBehalf: params.accountAddress,
1335
- metadata: this.client.options.metadata,
1360
+ metadata,
1336
1361
  }),
1337
1362
  };
1338
1363
  }
@@ -1364,6 +1389,7 @@ export class MorphoMidnight {
1364
1389
  * ```
1365
1390
  */
1366
1391
  supplyCollateralBatch(params) {
1392
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
1367
1393
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
1368
1394
  // Reject malformed accounts before resolving token requirements.
1369
1395
  validateMidnightAddress("accountAddress", params.accountAddress);
@@ -1405,7 +1431,7 @@ export class MorphoMidnight {
1405
1431
  market: params.marketData.params,
1406
1432
  collateralSupplies: params.collateralSupplies.map(({ collateralIndex, assets }) => ({ collateralIndex, assets })),
1407
1433
  onBehalf: params.accountAddress,
1408
- metadata: this.client.options.metadata,
1434
+ metadata,
1409
1435
  }),
1410
1436
  };
1411
1437
  }
@@ -1465,7 +1491,7 @@ export class MorphoMidnight {
1465
1491
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1466
1492
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1467
1493
  * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
1468
- * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
1494
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
1469
1495
  * @example
1470
1496
  * ```ts
1471
1497
  * const output = await midnight.makeLend({
@@ -1483,7 +1509,8 @@ export class MorphoMidnight {
1483
1509
  // Reject the zero account before preparing anything for it.
1484
1510
  validateMidnightAccount("accountAddress", params.accountAddress);
1485
1511
  // Fails before any API read or build when the deadline has already passed.
1486
- validateMidnightDeadline(params.deadline);
1512
+ const now = params.now ?? Time.timestamp();
1513
+ validateMidnightDeadline(params.deadline, now);
1487
1514
  const tree = wrapMidnightEncoding("offers", () => Tree.from(params.offers));
1488
1515
  rejectReduceOnlyOffers(tree.offers);
1489
1516
  return this.prepareLendOffers({ ...params, offers: tree });
@@ -1539,7 +1566,7 @@ export class MorphoMidnight {
1539
1566
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
1540
1567
  * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
1541
1568
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
1542
- * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
1569
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
1543
1570
  * @example
1544
1571
  * ```ts
1545
1572
  * const output = await midnight.makeBorrow({
@@ -1554,7 +1581,8 @@ export class MorphoMidnight {
1554
1581
  // Reject the zero account before preparing anything for it.
1555
1582
  validateMidnightAccount("accountAddress", params.accountAddress);
1556
1583
  // Fails before any API read or build when the deadline has already passed.
1557
- validateMidnightDeadline(params.deadline);
1584
+ const now = params.now ?? Time.timestamp();
1585
+ validateMidnightDeadline(params.deadline, now);
1558
1586
  const tree = wrapMidnightEncoding("offers", () => Tree.from(params.offers));
1559
1587
  rejectReduceOnlyOffers(tree.offers);
1560
1588
  return this.prepareBorrowOffers({ ...params, offers: tree });
@@ -1563,6 +1591,7 @@ export class MorphoMidnight {
1563
1591
  * Prepares lend-side offers for publication.
1564
1592
  */
1565
1593
  async prepareLendOffers(params) {
1594
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
1566
1595
  // Reject a malformed address before viem compares offer markets with it.
1567
1596
  validateMidnightAddress("loanToken", params.loanToken);
1568
1597
  assertPositiveAmount("loanAssets", params.loanAssets);
@@ -1589,7 +1618,7 @@ export class MorphoMidnight {
1589
1618
  chainId: this.chainId,
1590
1619
  cancellations: params.cancellations ?? [],
1591
1620
  deadline: params.deadline,
1592
- metadata: this.client.options.metadata,
1621
+ metadata,
1593
1622
  publication: {
1594
1623
  ratifier: data.ratifier,
1595
1624
  root: data.tree.root,
@@ -1705,7 +1734,7 @@ export class MorphoMidnight {
1705
1734
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
1706
1735
  * @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
1707
1736
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
1708
- * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
1737
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
1709
1738
  * @example
1710
1739
  * ```ts
1711
1740
  * const callback = getMidnightBlueBuyCallbackAddress({ chainId, owner: maker, salt: callbackSalt });
@@ -1724,6 +1753,8 @@ export class MorphoMidnight {
1724
1753
  * ```
1725
1754
  */
1726
1755
  async supplyBlueMakeLend(params) {
1756
+ const suppliedNow = params.now;
1757
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
1727
1758
  // Reject the zero account before preparing anything for it.
1728
1759
  validateMidnightAccount("accountAddress", params.accountAddress);
1729
1760
  // Reject wrong-sized salts before callback derivation pads them or any read occurs.
@@ -1735,7 +1766,8 @@ export class MorphoMidnight {
1735
1766
  rejectReduceOnlyOffers(tree.offers);
1736
1767
  await validateClientChainId(this.client.viemClient, this.chainId);
1737
1768
  // Fails before any API read or build when the deadline has already passed.
1738
- validateMidnightDeadline(params.deadline);
1769
+ const now = suppliedNow ?? Time.timestamp();
1770
+ validateMidnightDeadline(params.deadline, now);
1739
1771
  const { callbackSalt } = params;
1740
1772
  // Encode the whole Blue market first so a malformed field fails typed, before the RPC read.
1741
1773
  const callbackData = wrapMidnightEncoding("blueMarket", () => getMidnightBlueBuyCallbackData(params.blueMarket));
@@ -1755,7 +1787,7 @@ export class MorphoMidnight {
1755
1787
  deployless: this.client.options.supportDeployless,
1756
1788
  }),
1757
1789
  ]);
1758
- const market = _try(() => fetched.accrueInterest(MathLib.max(Time.timestamp(), fetched.lastUpdate)), UnsupportedMarketIrmError) ?? fetched;
1790
+ const market = _try(() => fetched.accrueInterest(MathLib.max(suppliedNow ?? Time.timestamp(), fetched.lastUpdate)), UnsupportedMarketIrmError) ?? fetched;
1759
1791
  if (market.totalSupplyShares === 0n) {
1760
1792
  throw new EmptyBlueParkingMarketError({ marketId: blueMarketId });
1761
1793
  }
@@ -1805,7 +1837,7 @@ export class MorphoMidnight {
1805
1837
  nativeAmount: params.nativeAmount,
1806
1838
  cancellations: params.cancellations ?? [],
1807
1839
  deadline: params.deadline,
1808
- metadata: this.client.options.metadata,
1840
+ metadata,
1809
1841
  });
1810
1842
  return {
1811
1843
  groups: data.groups,
@@ -1830,6 +1862,7 @@ export class MorphoMidnight {
1830
1862
  * Prepares borrow-side offers for publication.
1831
1863
  */
1832
1864
  async prepareBorrowOffers(params) {
1865
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
1833
1866
  const tree = wrapMidnightEncoding("offers", () => Tree.from(params.offers));
1834
1867
  validateOfferSides(tree.offers, false);
1835
1868
  validateMidnightMakerOfferCallbacks(tree.offers);
@@ -1842,7 +1875,7 @@ export class MorphoMidnight {
1842
1875
  chainId: this.chainId,
1843
1876
  cancellations: params.cancellations ?? [],
1844
1877
  deadline: params.deadline,
1845
- metadata: this.client.options.metadata,
1878
+ metadata,
1846
1879
  publication: {
1847
1880
  ratifier: data.ratifier,
1848
1881
  root: data.tree.root,
@@ -1912,7 +1945,7 @@ export class MorphoMidnight {
1912
1945
  * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
1913
1946
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
1914
1947
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
1915
- * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
1948
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
1916
1949
  * @example
1917
1950
  * ```ts
1918
1951
  * const output = await midnight.makeWithdraw({
@@ -1929,13 +1962,15 @@ export class MorphoMidnight {
1929
1962
  // Reject the zero account before preparing anything for it.
1930
1963
  validateMidnightAccount("accountAddress", params.accountAddress);
1931
1964
  // Fails before any API read or build when the deadline has already passed.
1932
- validateMidnightDeadline(params.deadline);
1965
+ const now = params.now ?? Time.timestamp();
1966
+ validateMidnightDeadline(params.deadline, now);
1933
1967
  const tree = wrapMidnightEncoding("offers", () => Tree.from(params.offers));
1934
1968
  // Reject the wrong exit intent before calling the mempool validation API.
1935
1969
  validateOfferSides(tree.offers, false);
1936
1970
  for (const [index, offer] of tree.offers.entries()) {
1937
- if (!offer.reduceOnly)
1971
+ if (!offer.reduceOnly) {
1938
1972
  throw new MidnightOfferNotReduceOnlyError({ index });
1973
+ }
1939
1974
  }
1940
1975
  return this.prepareBorrowOffers({ ...params, offers: tree });
1941
1976
  }
@@ -2000,7 +2035,7 @@ export class MorphoMidnight {
2000
2035
  * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
2001
2036
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
2002
2037
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
2003
- * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
2038
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
2004
2039
  * @example
2005
2040
  * ```ts
2006
2041
  * const output = await midnight.makeRepay({
@@ -2019,13 +2054,15 @@ export class MorphoMidnight {
2019
2054
  // Reject the zero account before preparing anything for it.
2020
2055
  validateMidnightAccount("accountAddress", params.accountAddress);
2021
2056
  // Fails before any API read or build when the deadline has already passed.
2022
- validateMidnightDeadline(params.deadline);
2057
+ const now = params.now ?? Time.timestamp();
2058
+ validateMidnightDeadline(params.deadline, now);
2023
2059
  const tree = wrapMidnightEncoding("offers", () => Tree.from(params.offers));
2024
2060
  // Reject the wrong exit intent before calling the mempool validation API.
2025
2061
  validateOfferSides(tree.offers, true);
2026
2062
  for (const [index, offer] of tree.offers.entries()) {
2027
- if (!offer.reduceOnly)
2063
+ if (!offer.reduceOnly) {
2028
2064
  throw new MidnightOfferNotReduceOnlyError({ index });
2065
+ }
2029
2066
  }
2030
2067
  return this.prepareLendOffers({ ...params, offers: tree });
2031
2068
  }
@@ -2097,7 +2134,7 @@ export class MorphoMidnight {
2097
2134
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
2098
2135
  * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
2099
2136
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
2100
- * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
2137
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
2101
2138
  * @example
2102
2139
  * ```ts
2103
2140
  * const output = await midnight.supplyCollateralMakeBorrow({
@@ -2112,11 +2149,13 @@ export class MorphoMidnight {
2112
2149
  * ```
2113
2150
  */
2114
2151
  async supplyCollateralMakeBorrow(params) {
2152
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
2115
2153
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
2116
2154
  // Reject the zero account before preparing anything for it.
2117
2155
  validateMidnightAccount("accountAddress", params.accountAddress);
2118
2156
  // Fails before any API read or build when the deadline has already passed.
2119
- validateMidnightDeadline(params.deadline);
2157
+ const now = params.now ?? Time.timestamp();
2158
+ validateMidnightDeadline(params.deadline, now);
2120
2159
  const market = params.collateral.market instanceof MarketParams
2121
2160
  ? params.collateral.market
2122
2161
  : MarketParams.from(params.collateral.market);
@@ -2142,7 +2181,7 @@ export class MorphoMidnight {
2142
2181
  nativeAmount: params.nativeAmount,
2143
2182
  cancellations: params.cancellations ?? [],
2144
2183
  deadline: params.deadline,
2145
- metadata: this.client.options.metadata,
2184
+ metadata,
2146
2185
  publication: {
2147
2186
  ratifier: data.ratifier,
2148
2187
  root: data.tree.root,
@@ -2228,14 +2267,16 @@ export class MorphoMidnight {
2228
2267
  * ```
2229
2268
  */
2230
2269
  redeem(params) {
2270
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
2231
2271
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
2232
2272
  // Reject a malformed account here; the builder rejects the zero account.
2233
2273
  validateMidnightAddress("accountAddress", params.accountAddress);
2234
2274
  if (!params.positionData) {
2235
2275
  throw new MissingAccrualPositionError();
2236
2276
  }
2237
- if (params.positionData.user != null)
2277
+ if (params.positionData.user != null) {
2238
2278
  validateMidnightAddress("positionData.user", params.positionData.user);
2279
+ }
2239
2280
  if (params.positionData.user == null ||
2240
2281
  !isAddressEqual(params.positionData.user, params.accountAddress)) {
2241
2282
  throw new AccrualPositionUserMismatchError(params.positionData.user ?? "unbound", params.accountAddress);
@@ -2244,13 +2285,15 @@ export class MorphoMidnight {
2244
2285
  validateMarketData(market, this.chainId);
2245
2286
  // Apply realized losses and continuous fees the way `Midnight._updatePosition` does before a
2246
2287
  // withdrawal; never accrue to before the snapshot's `lastAccrual`.
2247
- const accrued = params.positionData.accrueInterest(MathLib.max(Time.timestamp(), params.positionData.lastAccrual));
2288
+ const now = params.now ?? Time.timestamp();
2289
+ const accrued = params.positionData.accrueInterest(MathLib.max(now, params.positionData.lastAccrual));
2248
2290
  const units = params.units ?? accrued.faceValue;
2249
2291
  if (params.units !== undefined && units <= 0n) {
2250
2292
  throw new NonPositiveInputError("units", units);
2251
2293
  }
2252
- if (units <= 0n)
2294
+ if (units <= 0n) {
2253
2295
  throw new NoMidnightCreditToRedeemError(market.id);
2296
+ }
2254
2297
  validateMidnightUint128Field("units", units);
2255
2298
  if (accrued.credit < units) {
2256
2299
  throw new MidnightRedeemExceedsCreditError({
@@ -2273,7 +2316,7 @@ export class MorphoMidnight {
2273
2316
  units,
2274
2317
  onBehalf: params.accountAddress,
2275
2318
  receiver: params.receiver,
2276
- metadata: this.client.options.metadata,
2319
+ metadata,
2277
2320
  });
2278
2321
  return {
2279
2322
  getRequirements: async () => [],
@@ -2338,7 +2381,7 @@ export class MorphoMidnight {
2338
2381
  * during this method call, before the lazy output is returned.
2339
2382
  * @throws {MidnightContractReceiverError} when `collateralReceiver` is a Midnight protocol
2340
2383
  * contract or a market token contract.
2341
- * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
2384
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
2342
2385
  * @example
2343
2386
  * ```ts
2344
2387
  * // Close the position: repay all debt, withdraw all collateral.
@@ -2354,11 +2397,13 @@ export class MorphoMidnight {
2354
2397
  * ```
2355
2398
  */
2356
2399
  repayWithdrawCollateral(params) {
2400
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
2357
2401
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
2358
2402
  // Reject the zero account before preparing anything for it.
2359
2403
  validateMidnightAccount("accountAddress", params.accountAddress);
2360
2404
  // Fails before any API read or build when the deadline has already passed.
2361
- validateMidnightDeadline(params.deadline);
2405
+ const now = params.now ?? Time.timestamp();
2406
+ validateMidnightDeadline(params.deadline, now);
2362
2407
  const market = params.marketData.params;
2363
2408
  const tx = midnightRepayWithdrawCollateral({
2364
2409
  chainId: this.chainId,
@@ -2368,7 +2413,7 @@ export class MorphoMidnight {
2368
2413
  collateralWithdrawals: params.collateralWithdrawals ?? [],
2369
2414
  collateralReceiver: params.collateralReceiver ?? params.accountAddress,
2370
2415
  deadline: params.deadline,
2371
- metadata: this.client.options.metadata,
2416
+ metadata,
2372
2417
  });
2373
2418
  validatePositionBinding({
2374
2419
  positionData: params.positionData,
@@ -2376,24 +2421,7 @@ export class MorphoMidnight {
2376
2421
  marketData: params.marketData,
2377
2422
  });
2378
2423
  const collateralWithdrawals = params.collateralWithdrawals ?? [];
2379
- const postCollateral = Array.from({ length: market.collateralParams.length }, (_, index) => params.positionData.collateral[index] ?? 0n);
2380
- let withdrawAmount = 0n;
2381
- for (const withdrawal of collateralWithdrawals) {
2382
- // Reject unconfigured collateral indexes before updating postCollateral.
2383
- MarketUtils.getCollateralByIndex(market, withdrawal.collateralIndex);
2384
- const index = Number(withdrawal.collateralIndex);
2385
- const available = postCollateral[index] ?? 0n;
2386
- const amount = withdrawal.assets === maxUint256 ? available : withdrawal.assets;
2387
- if (amount > available) {
2388
- throw new WithdrawExceedsCollateralError({
2389
- withdrawAmount: amount,
2390
- available,
2391
- market: params.marketData.id,
2392
- });
2393
- }
2394
- postCollateral[index] = available - amount;
2395
- withdrawAmount += amount;
2396
- }
2424
+ const { postCollateral, withdrawAmount } = getPostWithdrawalCollateral(params);
2397
2425
  // The bundle must fill the whole assets target and the direct repay is capped at the debt, so a repay above it reverts `OutOfOffers()`.
2398
2426
  if (params.repay.type === "assets" &&
2399
2427
  params.repay.assets > params.positionData.debt) {
@@ -2411,11 +2439,11 @@ export class MorphoMidnight {
2411
2439
  limit: params.positionData.debt,
2412
2440
  });
2413
2441
  }
2414
- const postDebt = params.repay.type === "full"
2415
- ? 0n
2416
- : params.positionData.debt > params.repay.assets
2417
- ? params.positionData.debt - params.repay.assets
2418
- : 0n;
2442
+ let postDebt = 0n;
2443
+ if (params.repay.type !== "full" &&
2444
+ params.positionData.debt > params.repay.assets) {
2445
+ postDebt = params.positionData.debt - params.repay.assets;
2446
+ }
2419
2447
  if (collateralWithdrawals.length > 0 && postDebt > 0n) {
2420
2448
  const maxSafeDebt = getMidnightMaxSafeDebt({
2421
2449
  market: params.marketData,
@@ -2452,42 +2480,37 @@ export class MorphoMidnight {
2452
2480
  };
2453
2481
  }
2454
2482
  /**
2455
- * Prepares guarded cancellation of several maker offer groups through `MidnightBundlesV2`.
2483
+ * Prepares a full cancellation of one or more maker offer groups as a direct call to Midnight.
2456
2484
  *
2457
- * The transaction reverts as a whole when any group's consumption exceeds its
2458
- * `maxConsumed` ceiling, so fills landing before execution never leave a partial cancel.
2485
+ * One group builds a bare `setConsumed(group, maxUint128, accountAddress)`. Two or more groups
2486
+ * build one Midnight `multicall` of such calls, in list order, which cancels every group or
2487
+ * none. Only the single-group transaction is matchable by a wallet policy that allows
2488
+ * `setConsumed` by method name; cancel one group per transaction when the signer's policy names
2489
+ * `setConsumed`.
2459
2490
  *
2460
- * @param params - Maker account, groups with consumption ceilings, and deadline.
2461
- * @param params.accountAddress - Maker that must send the transaction. It is used only to check
2462
- * the maker's Midnight authorization of `MidnightBundlesV2`; the bundle cancels the groups of
2463
- * `msg.sender`. A transaction sent from another account that has also authorized
2464
- * `MidnightBundlesV2` does not revert: it cancels that account's groups and leaves the maker's
2465
- * offers fillable.
2466
- * @param params.cancellations - Offer groups and the largest consumption accepted for each.
2467
- * To cancel unconditionally, set `maxConsumed` to `maxUint128`; the contract treats
2468
- * `type(uint128).max` as no limit.
2469
- * Cancellation is per group: it does not unratify roots or revoke
2470
- * `MidnightBundlesV2` or ratifier authorization.
2471
- * @param params.deadline - Bundle execution deadline timestamp.
2472
- * @returns Lazy Midnight authorization requirement for `MidnightBundlesV2` and a synchronous transaction builder.
2473
- * @throws {ChainIdMismatchError} when the client targets another chain, or from
2474
- * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
2475
- * @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as an out-of-range integer.
2476
- * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
2477
- * RPC read fails.
2478
- * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
2479
- * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
2480
- * @throws {EmptyMidnightGroupCancellationsError} when no groups are provided.
2491
+ * Nothing is required before sending: no Midnight authorization, approval, signature or
2492
+ * deadline. Cancellation is per group and always full; it does not unratify roots or revoke
2493
+ * authorizations, and cancelling a group again succeeds.
2494
+ *
2495
+ * @param params - Maker account and the offer groups to cancel.
2496
+ * @param params.accountAddress - Maker whose groups are cancelled. The maker, or an operator it
2497
+ * authorized on Midnight, must send the transaction; a transaction from any other account
2498
+ * reverts `Unauthorized()` and changes no group.
2499
+ * @param params.groups - Nonempty list of distinct 32-byte offer groups to cancel.
2500
+ * @param params.now - Optional reference timestamp used to resolve `metadata.timestamp: true`.
2501
+ * @returns A handle whose `getRequirements()` resolves to an empty list without reading the
2502
+ * chain, and whose synchronous `buildTx()` returns the transaction targeting `Midnight`.
2503
+ * @throws {ChainIdMismatchError} when the client targets another chain.
2481
2504
  * @throws {MidnightInvalidAccountAddressError} when `accountAddress` is malformed or zero.
2482
- * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
2505
+ * @throws {EmptyMidnightGroupCancellationsError} when no groups are provided.
2506
+ * @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
2483
2507
  * @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
2484
- * @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
2485
- * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
2486
- * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
2508
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
2509
+ * @throws {UnknownAddressError} when the chain has no `midnight` deployment.
2487
2510
  * @example
2488
2511
  * ```ts
2489
2512
  * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
2490
- * import { createPublicClient, http, maxUint256, type Address, type Hex } from "viem";
2513
+ * import { createPublicClient, http, type Address, type Hex } from "viem";
2491
2514
  * import { base } from "viem/chains";
2492
2515
  *
2493
2516
  * declare const maker: Address;
@@ -2496,30 +2519,27 @@ export class MorphoMidnight {
2496
2519
  * morphoViemExtension(),
2497
2520
  * );
2498
2521
  * const midnight = client.morpho.midnight(base.id);
2499
- * const output = midnight.cancelOffers({
2500
- * accountAddress: maker,
2501
- * cancellations: [{ group, maxConsumed: 0n }],
2502
- * deadline: maxUint256,
2503
- * });
2522
+ * const output = midnight.cancelOffers({ accountAddress: maker, groups: [group] });
2523
+ * await output.getRequirements(); // => []
2524
+ * const tx = output.buildTx(); // calldata: setConsumed(group, maxUint128, maker)
2504
2525
  * ```
2505
2526
  */
2506
2527
  cancelOffers(params) {
2528
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
2507
2529
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
2508
2530
  const { accountAddress } = params;
2509
2531
  if (!isAddress(accountAddress) ||
2510
2532
  isAddressEqual(accountAddress, zeroAddress)) {
2511
2533
  throw new MidnightInvalidAccountAddressError(accountAddress);
2512
2534
  }
2513
- // Fails before any API read or build when the deadline has already passed.
2514
- validateMidnightDeadline(params.deadline);
2515
- const tx = midnightCancelAndMake({
2535
+ const tx = midnightCancelOffers({
2516
2536
  chainId: this.chainId,
2517
- cancellations: params.cancellations,
2518
- deadline: params.deadline,
2519
- metadata: this.client.options.metadata,
2537
+ groups: params.groups,
2538
+ onBehalf: accountAddress,
2539
+ metadata,
2520
2540
  });
2521
2541
  return {
2522
- getRequirements: () => this.getBundlesV2AuthorizationRequirements(accountAddress),
2542
+ getRequirements: async () => [],
2523
2543
  buildTx: () => tx,
2524
2544
  };
2525
2545
  }