@morpho-org/morpho-sdk 5.2.0 → 5.3.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 (270) hide show
  1. package/README.md +46 -2
  2. package/lib/cjs/abis.d.ts +1 -0
  3. package/lib/cjs/abis.js +6 -1
  4. package/lib/cjs/actions/blue/borrow.d.ts +3 -7
  5. package/lib/cjs/actions/blue/borrow.js +5 -9
  6. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +3 -4
  7. package/lib/cjs/actions/blue/buildReallocationActions.js +3 -4
  8. package/lib/cjs/actions/blue/refinance.d.ts +4 -8
  9. package/lib/cjs/actions/blue/refinance.js +10 -14
  10. package/lib/cjs/actions/blue/repay.d.ts +2 -5
  11. package/lib/cjs/actions/blue/repay.js +2 -5
  12. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -6
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +4 -7
  14. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +2 -5
  15. package/lib/cjs/actions/blue/resolveRepayFunding.js +15 -12
  16. package/lib/cjs/actions/blue/supply.d.ts +2 -4
  17. package/lib/cjs/actions/blue/supply.js +6 -8
  18. package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -3
  19. package/lib/cjs/actions/blue/supplyCollateral.js +5 -6
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +4 -9
  21. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +9 -14
  22. package/lib/cjs/actions/blue/withdraw.d.ts +9 -7
  23. package/lib/cjs/actions/blue/withdraw.js +18 -10
  24. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
  25. package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
  26. package/lib/cjs/actions/index.d.ts +2 -0
  27. package/lib/cjs/actions/index.js +1 -0
  28. package/lib/cjs/actions/midnight/authorization.d.ts +37 -0
  29. package/lib/cjs/actions/midnight/authorization.js +69 -0
  30. package/lib/cjs/actions/midnight/cancelOffer.d.ts +38 -0
  31. package/lib/cjs/actions/midnight/cancelOffer.js +73 -0
  32. package/lib/cjs/actions/midnight/index.d.ts +11 -0
  33. package/lib/cjs/actions/midnight/index.js +27 -0
  34. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
  35. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +72 -0
  36. package/lib/cjs/actions/midnight/redeem.d.ts +43 -0
  37. package/lib/cjs/actions/midnight/redeem.js +79 -0
  38. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
  39. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +121 -0
  40. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
  41. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +59 -0
  42. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +45 -0
  43. package/lib/cjs/actions/midnight/supplyCollateral.js +83 -0
  44. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
  45. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -0
  46. package/lib/cjs/actions/midnight/takeBorrow.d.ts +57 -0
  47. package/lib/cjs/actions/midnight/takeBorrow.js +110 -0
  48. package/lib/cjs/actions/midnight/takeLend.d.ts +57 -0
  49. package/lib/cjs/actions/midnight/takeLend.js +110 -0
  50. package/lib/cjs/actions/midnight/types.d.ts +39 -0
  51. package/lib/cjs/actions/midnight/types.js +15 -0
  52. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
  53. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +5 -16
  54. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
  55. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +10 -14
  56. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
  57. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +11 -28
  58. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
  59. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
  60. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  61. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +10 -4
  62. package/lib/cjs/actions/requirements/getRequirementsApproval.js +10 -4
  63. package/lib/cjs/actions/requirements/index.d.ts +1 -0
  64. package/lib/cjs/actions/requirements/index.js +1 -0
  65. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
  66. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +76 -0
  67. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
  68. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +78 -0
  69. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
  70. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +70 -0
  71. package/lib/cjs/actions/requirements/midnight/index.d.ts +3 -0
  72. package/lib/cjs/actions/requirements/midnight/index.js +19 -0
  73. package/lib/cjs/actions/vaultV1/deposit.d.ts +3 -4
  74. package/lib/cjs/actions/vaultV1/deposit.js +7 -8
  75. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -3
  76. package/lib/cjs/actions/vaultV1/migrateToV2.js +5 -6
  77. package/lib/cjs/actions/vaultV1/redeem.d.ts +1 -1
  78. package/lib/cjs/actions/vaultV1/redeem.js +2 -2
  79. package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
  80. package/lib/cjs/actions/vaultV1/withdraw.js +2 -2
  81. package/lib/cjs/actions/vaultV2/deposit.d.ts +3 -4
  82. package/lib/cjs/actions/vaultV2/deposit.js +7 -8
  83. package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +2 -3
  84. package/lib/cjs/actions/vaultV2/forceRedeem.js +3 -4
  85. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
  86. package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -2
  87. package/lib/cjs/actions/vaultV2/redeem.d.ts +1 -1
  88. package/lib/cjs/actions/vaultV2/redeem.js +2 -2
  89. package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
  90. package/lib/cjs/actions/vaultV2/withdraw.js +2 -2
  91. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  92. package/lib/cjs/client/morphoViemExtension.js +5 -2
  93. package/lib/cjs/constants.d.ts +1 -0
  94. package/lib/cjs/constants.js +15 -1
  95. package/lib/cjs/entities/blue/blue.d.ts +5 -5
  96. package/lib/cjs/entities/blue/blue.js +93 -68
  97. package/lib/cjs/entities/index.d.ts +1 -0
  98. package/lib/cjs/entities/index.js +15 -0
  99. package/lib/cjs/entities/midnight/index.d.ts +2 -0
  100. package/lib/cjs/entities/midnight/index.js +18 -0
  101. package/lib/cjs/entities/midnight/midnight.d.ts +402 -0
  102. package/lib/cjs/entities/midnight/midnight.js +1036 -0
  103. package/lib/cjs/entities/midnight/types.d.ts +164 -0
  104. package/lib/cjs/entities/midnight/types.js +2 -0
  105. package/lib/cjs/entities/vaultV1/vaultV1.js +10 -17
  106. package/lib/cjs/entities/vaultV2/vaultV2.js +19 -21
  107. package/lib/cjs/errors.d.ts +1 -0
  108. package/lib/cjs/errors.js +17 -1
  109. package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
  110. package/lib/cjs/helpers/encodeDeallocation.js +2 -1
  111. package/lib/cjs/helpers/index.d.ts +4 -1
  112. package/lib/cjs/helpers/index.js +8 -1
  113. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +34 -0
  114. package/lib/cjs/helpers/signAndVerifyTypedData.js +58 -0
  115. package/lib/cjs/helpers/validate.d.ts +40 -1
  116. package/lib/cjs/helpers/validate.js +47 -5
  117. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
  118. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +32 -0
  119. package/lib/cjs/helpers/validateMidnightMarket.d.ts +10 -0
  120. package/lib/cjs/helpers/validateMidnightMarket.js +24 -0
  121. package/lib/cjs/helpers/validateOfferSides.d.ts +21 -0
  122. package/lib/cjs/helpers/validateOfferSides.js +36 -0
  123. package/lib/cjs/helpers/validateRequirementSpender.d.ts +29 -0
  124. package/lib/cjs/helpers/validateRequirementSpender.js +49 -0
  125. package/lib/cjs/helpers/validateTakeableOffers.d.ts +18 -0
  126. package/lib/cjs/helpers/validateTakeableOffers.js +35 -0
  127. package/lib/cjs/midnight-api.d.ts +1 -0
  128. package/lib/cjs/midnight-api.js +17 -0
  129. package/lib/cjs/types/action.d.ts +189 -23
  130. package/lib/cjs/types/action.js +27 -7
  131. package/lib/cjs/types/client.d.ts +3 -2
  132. package/lib/cjs/types/error.d.ts +288 -119
  133. package/lib/cjs/types/error.js +259 -180
  134. package/lib/cjs/utils.d.ts +1 -0
  135. package/lib/cjs/utils.js +12 -2
  136. package/lib/esm/abis.d.ts +1 -0
  137. package/lib/esm/abis.js +1 -0
  138. package/lib/esm/actions/blue/borrow.d.ts +3 -7
  139. package/lib/esm/actions/blue/borrow.js +6 -10
  140. package/lib/esm/actions/blue/buildReallocationActions.d.ts +3 -4
  141. package/lib/esm/actions/blue/buildReallocationActions.js +3 -4
  142. package/lib/esm/actions/blue/refinance.d.ts +4 -8
  143. package/lib/esm/actions/blue/refinance.js +11 -15
  144. package/lib/esm/actions/blue/repay.d.ts +2 -5
  145. package/lib/esm/actions/blue/repay.js +2 -5
  146. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -6
  147. package/lib/esm/actions/blue/repayWithdrawCollateral.js +5 -8
  148. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +2 -5
  149. package/lib/esm/actions/blue/resolveRepayFunding.js +16 -13
  150. package/lib/esm/actions/blue/supply.d.ts +2 -4
  151. package/lib/esm/actions/blue/supply.js +7 -9
  152. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -3
  153. package/lib/esm/actions/blue/supplyCollateral.js +6 -7
  154. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -9
  155. package/lib/esm/actions/blue/supplyCollateralBorrow.js +10 -15
  156. package/lib/esm/actions/blue/withdraw.d.ts +9 -7
  157. package/lib/esm/actions/blue/withdraw.js +19 -11
  158. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
  159. package/lib/esm/actions/blue/withdrawCollateral.js +3 -3
  160. package/lib/esm/actions/index.d.ts +2 -0
  161. package/lib/esm/actions/index.js +1 -0
  162. package/lib/esm/actions/midnight/authorization.d.ts +37 -0
  163. package/lib/esm/actions/midnight/authorization.js +65 -0
  164. package/lib/esm/actions/midnight/cancelOffer.d.ts +38 -0
  165. package/lib/esm/actions/midnight/cancelOffer.js +69 -0
  166. package/lib/esm/actions/midnight/index.d.ts +11 -0
  167. package/lib/esm/actions/midnight/index.js +11 -0
  168. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
  169. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +68 -0
  170. package/lib/esm/actions/midnight/redeem.d.ts +43 -0
  171. package/lib/esm/actions/midnight/redeem.js +75 -0
  172. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
  173. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +117 -0
  174. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
  175. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +55 -0
  176. package/lib/esm/actions/midnight/supplyCollateral.d.ts +45 -0
  177. package/lib/esm/actions/midnight/supplyCollateral.js +79 -0
  178. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
  179. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +124 -0
  180. package/lib/esm/actions/midnight/takeBorrow.d.ts +57 -0
  181. package/lib/esm/actions/midnight/takeBorrow.js +106 -0
  182. package/lib/esm/actions/midnight/takeLend.d.ts +57 -0
  183. package/lib/esm/actions/midnight/takeLend.js +106 -0
  184. package/lib/esm/actions/midnight/types.d.ts +39 -0
  185. package/lib/esm/actions/midnight/types.js +12 -0
  186. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
  187. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +6 -17
  188. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
  189. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +12 -16
  190. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
  191. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +12 -29
  192. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
  193. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
  194. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  195. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +10 -4
  196. package/lib/esm/actions/requirements/getRequirementsApproval.js +10 -4
  197. package/lib/esm/actions/requirements/index.d.ts +1 -0
  198. package/lib/esm/actions/requirements/index.js +1 -0
  199. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
  200. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +72 -0
  201. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
  202. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +74 -0
  203. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
  204. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +66 -0
  205. package/lib/esm/actions/requirements/midnight/index.d.ts +3 -0
  206. package/lib/esm/actions/requirements/midnight/index.js +3 -0
  207. package/lib/esm/actions/vaultV1/deposit.d.ts +3 -4
  208. package/lib/esm/actions/vaultV1/deposit.js +8 -9
  209. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -3
  210. package/lib/esm/actions/vaultV1/migrateToV2.js +6 -7
  211. package/lib/esm/actions/vaultV1/redeem.d.ts +1 -1
  212. package/lib/esm/actions/vaultV1/redeem.js +3 -3
  213. package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
  214. package/lib/esm/actions/vaultV1/withdraw.js +3 -3
  215. package/lib/esm/actions/vaultV2/deposit.d.ts +3 -4
  216. package/lib/esm/actions/vaultV2/deposit.js +8 -9
  217. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -3
  218. package/lib/esm/actions/vaultV2/forceRedeem.js +4 -5
  219. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  220. package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
  221. package/lib/esm/actions/vaultV2/redeem.d.ts +1 -1
  222. package/lib/esm/actions/vaultV2/redeem.js +3 -3
  223. package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
  224. package/lib/esm/actions/vaultV2/withdraw.js +3 -3
  225. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  226. package/lib/esm/client/morphoViemExtension.js +6 -3
  227. package/lib/esm/constants.d.ts +1 -0
  228. package/lib/esm/constants.js +1 -0
  229. package/lib/esm/entities/blue/blue.d.ts +5 -5
  230. package/lib/esm/entities/blue/blue.js +95 -70
  231. package/lib/esm/entities/index.d.ts +1 -0
  232. package/lib/esm/entities/index.js +1 -0
  233. package/lib/esm/entities/midnight/index.d.ts +2 -0
  234. package/lib/esm/entities/midnight/index.js +2 -0
  235. package/lib/esm/entities/midnight/midnight.d.ts +402 -0
  236. package/lib/esm/entities/midnight/midnight.js +1032 -0
  237. package/lib/esm/entities/midnight/types.d.ts +164 -0
  238. package/lib/esm/entities/midnight/types.js +1 -0
  239. package/lib/esm/entities/vaultV1/vaultV1.js +13 -20
  240. package/lib/esm/entities/vaultV2/vaultV2.js +9 -11
  241. package/lib/esm/errors.d.ts +1 -0
  242. package/lib/esm/errors.js +1 -0
  243. package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
  244. package/lib/esm/helpers/encodeDeallocation.js +3 -2
  245. package/lib/esm/helpers/index.d.ts +4 -1
  246. package/lib/esm/helpers/index.js +4 -1
  247. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +34 -0
  248. package/lib/esm/helpers/signAndVerifyTypedData.js +54 -0
  249. package/lib/esm/helpers/validate.d.ts +40 -1
  250. package/lib/esm/helpers/validate.js +46 -5
  251. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
  252. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +28 -0
  253. package/lib/esm/helpers/validateMidnightMarket.d.ts +10 -0
  254. package/lib/esm/helpers/validateMidnightMarket.js +20 -0
  255. package/lib/esm/helpers/validateOfferSides.d.ts +21 -0
  256. package/lib/esm/helpers/validateOfferSides.js +32 -0
  257. package/lib/esm/helpers/validateRequirementSpender.d.ts +29 -0
  258. package/lib/esm/helpers/validateRequirementSpender.js +45 -0
  259. package/lib/esm/helpers/validateTakeableOffers.d.ts +18 -0
  260. package/lib/esm/helpers/validateTakeableOffers.js +31 -0
  261. package/lib/esm/midnight-api.d.ts +1 -0
  262. package/lib/esm/midnight-api.js +1 -0
  263. package/lib/esm/types/action.d.ts +189 -23
  264. package/lib/esm/types/action.js +26 -7
  265. package/lib/esm/types/client.d.ts +3 -2
  266. package/lib/esm/types/error.d.ts +288 -119
  267. package/lib/esm/types/error.js +232 -154
  268. package/lib/esm/utils.d.ts +1 -0
  269. package/lib/esm/utils.js +1 -0
  270. package/package.json +12 -3
@@ -2,7 +2,11 @@ import { APPROVE_ONLY_ONCE_TOKENS } from "../../helpers/constant.js";
2
2
  import { ApprovalAmountLessThanSpendAmountError, } from "../../types/index.js";
3
3
  import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
4
4
  /**
5
- * Computes classic ERC-20 approval transactions for GeneralAdapter1 or Permit2, given the existing allowance.
5
+ * Computes classic ERC-20 approval transactions for a supported SDK spender, given the existing
6
+ * allowance.
7
+ *
8
+ * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
9
+ * GeneralAdapter1, Permit2, Midnight, and MidnightBundles addresses when configured.
6
10
  *
7
11
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
8
12
  * `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
@@ -10,16 +14,18 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
10
14
  * before re-approving.
11
15
  *
12
16
  * @param params.address - ERC-20 token address.
13
- * @param params.chainId - The chain the bundle targets.
17
+ * @param params.chainId - The chain the transaction targets, used to resolve supported spenders
18
+ * and token approval caps.
14
19
  * @param params.args.spendAmount - The amount the bundle will actually pull.
15
20
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
16
21
  * may be `MAX_UINT_160` for Permit2 prerequisites).
17
- * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1 or Permit2.
22
+ * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
23
+ * Permit2, Midnight, or MidnightBundles for `chainId`.
18
24
  * @param params.allowances - The user's current allowance of `address` for `spender`.
19
25
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
20
26
  * followed by the new approval. Empty when no approval is needed.
21
27
  * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < spendAmount`.
22
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or Permit2 for `chainId`.
28
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
23
29
  * @example
24
30
  * ```ts
25
31
  * import { getRequirementsApproval } from "@morpho-org/morpho-sdk";
@@ -2,3 +2,4 @@ export * from "./blue/index.js";
2
2
  export * from "./encode/index.js";
3
3
  export * from "./generalAdapter/index.js";
4
4
  export * from "./getRequirementsApproval.js";
5
+ export * from "./midnight/index.js";
@@ -2,3 +2,4 @@ export * from "./blue/index.js";
2
2
  export * from "./encode/index.js";
3
3
  export * from "./generalAdapter/index.js";
4
4
  export * from "./getRequirementsApproval.js";
5
+ export * from "./midnight/index.js";
@@ -0,0 +1,49 @@
1
+ import type { Address, Client } from "viem";
2
+ import { type ERC20ApprovalAction, type Transaction } from "../../../types/index.js";
3
+ /** Parameters for {@link getMidnightApprovalRequirements}. */
4
+ export interface GetMidnightApprovalRequirementsParams {
5
+ readonly viemClient: Client;
6
+ readonly chainId: number;
7
+ readonly token: Address;
8
+ readonly owner: Address;
9
+ readonly spender: Address;
10
+ readonly amount: bigint;
11
+ }
12
+ /**
13
+ * Resolves classic ERC20 approval requirements for a Midnight spender.
14
+ *
15
+ * Entity flows call this from `getRequirements()`. Direct low-level consumers
16
+ * should call it before encoding a Midnight action that lets `Midnight` or
17
+ * `MidnightBundles` pull ERC20 tokens from the user.
18
+ *
19
+ * @param params.viemClient - Viem client used to read ERC20 allowance.
20
+ * @param params.chainId - Chain id expected by the viem client.
21
+ * @param params.token - ERC20 token that may need approval.
22
+ * @param params.owner - Token owner.
23
+ * @param params.spender - Midnight spender that will pull tokens.
24
+ * @param params.amount - Token amount the spender must be able to pull.
25
+ * @returns Approval transactions required for `spender` to pull `amount`.
26
+ * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
27
+ * @throws {NegativeInputError} when `amount < 0n`.
28
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundles deployment.
29
+ * @example
30
+ * ```ts
31
+ * import {
32
+ * getMidnightApprovalRequirements,
33
+ * midnightTakeLend,
34
+ * } from "@morpho-org/morpho-sdk";
35
+ *
36
+ * const approvals = await getMidnightApprovalRequirements({
37
+ * viemClient: client,
38
+ * chainId: 8453,
39
+ * token: loanToken,
40
+ * owner: user,
41
+ * spender: midnightBundles,
42
+ * amount: 1_000_000n,
43
+ * });
44
+ * if (approvals.length === 0) {
45
+ * const tx = midnightTakeLend(takeParams);
46
+ * }
47
+ * ```
48
+ */
49
+ export declare const getMidnightApprovalRequirements: (params: GetMidnightApprovalRequirementsParams) => Promise<readonly Readonly<Transaction<ERC20ApprovalAction>>[]>;
@@ -0,0 +1,72 @@
1
+ import { erc20Abi } from "viem";
2
+ import { readContract } from "viem/actions";
3
+ import { validateChainId, validateRequirementSpender, } from "../../../helpers/index.js";
4
+ import { NegativeInputError, } from "../../../types/index.js";
5
+ import { getRequirementsApproval } from "../getRequirementsApproval.js";
6
+ /**
7
+ * Resolves classic ERC20 approval requirements for a Midnight spender.
8
+ *
9
+ * Entity flows call this from `getRequirements()`. Direct low-level consumers
10
+ * should call it before encoding a Midnight action that lets `Midnight` or
11
+ * `MidnightBundles` pull ERC20 tokens from the user.
12
+ *
13
+ * @param params.viemClient - Viem client used to read ERC20 allowance.
14
+ * @param params.chainId - Chain id expected by the viem client.
15
+ * @param params.token - ERC20 token that may need approval.
16
+ * @param params.owner - Token owner.
17
+ * @param params.spender - Midnight spender that will pull tokens.
18
+ * @param params.amount - Token amount the spender must be able to pull.
19
+ * @returns Approval transactions required for `spender` to pull `amount`.
20
+ * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
21
+ * @throws {NegativeInputError} when `amount < 0n`.
22
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundles deployment.
23
+ * @example
24
+ * ```ts
25
+ * import {
26
+ * getMidnightApprovalRequirements,
27
+ * midnightTakeLend,
28
+ * } from "@morpho-org/morpho-sdk";
29
+ *
30
+ * const approvals = await getMidnightApprovalRequirements({
31
+ * viemClient: client,
32
+ * chainId: 8453,
33
+ * token: loanToken,
34
+ * owner: user,
35
+ * spender: midnightBundles,
36
+ * amount: 1_000_000n,
37
+ * });
38
+ * if (approvals.length === 0) {
39
+ * const tx = midnightTakeLend(takeParams);
40
+ * }
41
+ * ```
42
+ */
43
+ export const getMidnightApprovalRequirements = async (params) => {
44
+ validateChainId(params.viemClient.chain?.id, params.chainId);
45
+ if (params.amount < 0n) {
46
+ throw new NegativeInputError("amount", params.amount);
47
+ }
48
+ // Validate the target even when no approval transaction needs to be encoded.
49
+ validateRequirementSpender({
50
+ chainId: params.chainId,
51
+ spender: params.spender,
52
+ allowed: ["midnight", "midnightBundles"],
53
+ });
54
+ if (params.amount === 0n)
55
+ return [];
56
+ const allowance = await readContract(params.viemClient, {
57
+ address: params.token,
58
+ abi: erc20Abi,
59
+ functionName: "allowance",
60
+ args: [params.owner, params.spender],
61
+ });
62
+ return getRequirementsApproval({
63
+ address: params.token,
64
+ chainId: params.chainId,
65
+ args: {
66
+ spender: params.spender,
67
+ spendAmount: params.amount,
68
+ approvalAmount: params.amount,
69
+ },
70
+ allowances: allowance,
71
+ });
72
+ };
@@ -0,0 +1,44 @@
1
+ import { type Address, type Client } from "viem";
2
+ import type { MidnightAuthorizationAction, Transaction } from "../../../types/index.js";
3
+ /** Parameters for {@link getMidnightAuthorizationRequirement}. */
4
+ export interface GetMidnightAuthorizationRequirementParams {
5
+ readonly viemClient: Client;
6
+ readonly chainId: number;
7
+ readonly owner: Address;
8
+ readonly authorized: Address;
9
+ }
10
+ /**
11
+ * Resolves the Midnight authorization transaction for a ratifier or bundle spender.
12
+ *
13
+ * Call before actions that rely on `Midnight.isAuthorized(owner, authorized)`,
14
+ * such as bundle takes or Ecrecover offer-root ratification. Entity flows call
15
+ * this from `getRequirements()` and omit the transaction when authorization is
16
+ * already set.
17
+ *
18
+ * @param params.viemClient - Viem client used to read `Midnight.isAuthorized`.
19
+ * @param params.chainId - Chain id expected by the viem client.
20
+ * @param params.owner - Account granting authorization.
21
+ * @param params.authorized - Spender or ratifier that needs authorization.
22
+ * @returns Authorization transaction, or `null` when already authorized.
23
+ * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
24
+ * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported bundle or ratifier address.
25
+ * @example
26
+ * ```ts
27
+ * import { getMidnightAuthorizationRequirement } from "@morpho-org/morpho-sdk";
28
+ *
29
+ * const tx = await getMidnightAuthorizationRequirement({
30
+ * viemClient: client,
31
+ * chainId: 8453,
32
+ * owner: user,
33
+ * authorized: midnightBundles,
34
+ * });
35
+ * if (tx) {
36
+ * await walletClient.sendTransaction({
37
+ * to: tx.to,
38
+ * data: tx.data,
39
+ * value: tx.value,
40
+ * });
41
+ * }
42
+ * ```
43
+ */
44
+ export declare const getMidnightAuthorizationRequirement: (params: GetMidnightAuthorizationRequirementParams) => Promise<Readonly<Transaction<MidnightAuthorizationAction>> | null>;
@@ -0,0 +1,74 @@
1
+ import { midnightAbi } from "@morpho-org/midnight-sdk";
2
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData } from "viem";
4
+ import { readContract } from "viem/actions";
5
+ import { validateChainId } from "../../../helpers/index.js";
6
+ import { validateMidnightAuthorizationTarget } from "../../../helpers/validateMidnightAuthorizationTarget.js";
7
+ /**
8
+ * Resolves the Midnight authorization transaction for a ratifier or bundle spender.
9
+ *
10
+ * Call before actions that rely on `Midnight.isAuthorized(owner, authorized)`,
11
+ * such as bundle takes or Ecrecover offer-root ratification. Entity flows call
12
+ * this from `getRequirements()` and omit the transaction when authorization is
13
+ * already set.
14
+ *
15
+ * @param params.viemClient - Viem client used to read `Midnight.isAuthorized`.
16
+ * @param params.chainId - Chain id expected by the viem client.
17
+ * @param params.owner - Account granting authorization.
18
+ * @param params.authorized - Spender or ratifier that needs authorization.
19
+ * @returns Authorization transaction, or `null` when already authorized.
20
+ * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
21
+ * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported bundle or ratifier address.
22
+ * @example
23
+ * ```ts
24
+ * import { getMidnightAuthorizationRequirement } from "@morpho-org/morpho-sdk";
25
+ *
26
+ * const tx = await getMidnightAuthorizationRequirement({
27
+ * viemClient: client,
28
+ * chainId: 8453,
29
+ * owner: user,
30
+ * authorized: midnightBundles,
31
+ * });
32
+ * if (tx) {
33
+ * await walletClient.sendTransaction({
34
+ * to: tx.to,
35
+ * data: tx.data,
36
+ * value: tx.value,
37
+ * });
38
+ * }
39
+ * ```
40
+ */
41
+ export const getMidnightAuthorizationRequirement = async (params) => {
42
+ validateChainId(params.viemClient.chain?.id, params.chainId);
43
+ // Reject unknown operators before reading authorization state.
44
+ validateMidnightAuthorizationTarget({
45
+ chainId: params.chainId,
46
+ authorized: params.authorized,
47
+ });
48
+ const midnight = getChainAddress(params.chainId, "midnight");
49
+ const isAuthorized = await readContract(params.viemClient, {
50
+ address: midnight,
51
+ abi: midnightAbi,
52
+ functionName: "isAuthorized",
53
+ args: [params.owner, params.authorized],
54
+ });
55
+ if (isAuthorized)
56
+ return null;
57
+ return deepFreeze({
58
+ to: midnight,
59
+ value: 0n,
60
+ data: encodeFunctionData({
61
+ abi: midnightAbi,
62
+ functionName: "setIsAuthorized",
63
+ args: [params.authorized, true, params.owner],
64
+ }),
65
+ action: {
66
+ type: "midnightAuthorization",
67
+ args: {
68
+ authorized: params.authorized,
69
+ isAuthorized: true,
70
+ onBehalf: params.owner,
71
+ },
72
+ },
73
+ });
74
+ };
@@ -0,0 +1,42 @@
1
+ import { type Address, type Client, type Hex } from "viem";
2
+ import type { SetterRatifierRatifyRootAction, Transaction } from "../../../types/index.js";
3
+ /** Parameters for {@link getSetterRatifierRatifyRootRequirement}. */
4
+ export interface GetSetterRatifierRatifyRootRequirementParams {
5
+ readonly viemClient: Client;
6
+ readonly chainId: number;
7
+ readonly maker: Address;
8
+ readonly root: Hex;
9
+ }
10
+ /**
11
+ * Resolves the SetterRatifier root approval transaction for a maker offer tree.
12
+ *
13
+ * Call after building a Setter-ratified tree and before encoding/submitting its
14
+ * payload. Entity make-offer flows call this from `getRequirements()` and omit
15
+ * the transaction when the maker has already approved the root.
16
+ *
17
+ * @param params.viemClient - Viem client used to read root approval state.
18
+ * @param params.chainId - Chain id expected by the viem client.
19
+ * @param params.maker - Maker whose root approval is checked.
20
+ * @param params.root - Offer-tree root that must be approved.
21
+ * @returns Ratify-root transaction, or `null` when the root is already ratified.
22
+ * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
23
+ * @example
24
+ * ```ts
25
+ * import { getSetterRatifierRatifyRootRequirement } from "@morpho-org/morpho-sdk";
26
+ *
27
+ * const tx = await getSetterRatifierRatifyRootRequirement({
28
+ * viemClient: client,
29
+ * chainId: 8453,
30
+ * maker: user,
31
+ * root,
32
+ * });
33
+ * if (tx) {
34
+ * await walletClient.sendTransaction({
35
+ * to: tx.to,
36
+ * data: tx.data,
37
+ * value: tx.value,
38
+ * });
39
+ * }
40
+ * ```
41
+ */
42
+ export declare const getSetterRatifierRatifyRootRequirement: (params: GetSetterRatifierRatifyRootRequirementParams) => Promise<Readonly<Transaction<SetterRatifierRatifyRootAction>> | null>;
@@ -0,0 +1,66 @@
1
+ import { setterRatifierAbi } from "@morpho-org/midnight-sdk";
2
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData } from "viem";
4
+ import { readContract } from "viem/actions";
5
+ import { validateChainId } from "../../../helpers/index.js";
6
+ /**
7
+ * Resolves the SetterRatifier root approval transaction for a maker offer tree.
8
+ *
9
+ * Call after building a Setter-ratified tree and before encoding/submitting its
10
+ * payload. Entity make-offer flows call this from `getRequirements()` and omit
11
+ * the transaction when the maker has already approved the root.
12
+ *
13
+ * @param params.viemClient - Viem client used to read root approval state.
14
+ * @param params.chainId - Chain id expected by the viem client.
15
+ * @param params.maker - Maker whose root approval is checked.
16
+ * @param params.root - Offer-tree root that must be approved.
17
+ * @returns Ratify-root transaction, or `null` when the root is already ratified.
18
+ * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
19
+ * @example
20
+ * ```ts
21
+ * import { getSetterRatifierRatifyRootRequirement } from "@morpho-org/morpho-sdk";
22
+ *
23
+ * const tx = await getSetterRatifierRatifyRootRequirement({
24
+ * viemClient: client,
25
+ * chainId: 8453,
26
+ * maker: user,
27
+ * root,
28
+ * });
29
+ * if (tx) {
30
+ * await walletClient.sendTransaction({
31
+ * to: tx.to,
32
+ * data: tx.data,
33
+ * value: tx.value,
34
+ * });
35
+ * }
36
+ * ```
37
+ */
38
+ export const getSetterRatifierRatifyRootRequirement = async (params) => {
39
+ validateChainId(params.viemClient.chain?.id, params.chainId);
40
+ const setterRatifier = getChainAddress(params.chainId, "setterRatifier");
41
+ const isRootRatified = await readContract(params.viemClient, {
42
+ address: setterRatifier,
43
+ abi: setterRatifierAbi,
44
+ functionName: "isRootRatified",
45
+ args: [params.maker, params.root],
46
+ });
47
+ if (isRootRatified)
48
+ return null;
49
+ return deepFreeze({
50
+ to: setterRatifier,
51
+ value: 0n,
52
+ data: encodeFunctionData({
53
+ abi: setterRatifierAbi,
54
+ functionName: "setIsRootRatified",
55
+ args: [params.maker, params.root, true],
56
+ }),
57
+ action: {
58
+ type: "setterRatifierRatifyRoot",
59
+ args: {
60
+ maker: params.maker,
61
+ root: params.root,
62
+ isRootRatified: true,
63
+ },
64
+ },
65
+ });
66
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./getMidnightApprovalRequirements.js";
2
+ export * from "./getMidnightAuthorizationRequirement.js";
3
+ export * from "./getSetterRatifierRatifyRootRequirement.js";
@@ -0,0 +1,3 @@
1
+ export * from "./getMidnightApprovalRequirements.js";
2
+ export * from "./getMidnightAuthorizationRequirement.js";
3
+ export * from "./getSetterRatifierRatifyRootRequirement.js";
@@ -39,9 +39,9 @@ export interface VaultV1DepositParams {
39
39
  * @param params.metadata - Optional analytics metadata attached to the bundle.
40
40
  * @returns A deep-frozen `Transaction<VaultV1DepositAction>` with `to`, `value`, `data`, and the
41
41
  * typed `action` discriminator the simulation layer consumes.
42
- * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
43
- * @throws {NonPositiveMaxSharePriceError} when `maxSharePrice <= 0n`.
44
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
42
+ * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
43
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, or when both `amount` and
44
+ * `nativeAmount` resolve to zero.
45
45
  * @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
46
46
  * configured wNative.
47
47
  * @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
@@ -53,7 +53,6 @@ export interface VaultV1DepositParams {
53
53
  * `requirementSignature` is provided and the signed amount differs from `args.amount`.
54
54
  * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
55
55
  * Permit2 requirement signature is missing its expiration.
56
- * @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
57
56
  * @example
58
57
  * ```ts
59
58
  * import { vaultV1Deposit } from "@morpho-org/morpho-sdk";
@@ -3,7 +3,7 @@ import { deepFreeze, isDefined } from "@morpho-org/morpho-ts";
3
3
  import { isAddressEqual } from "viem";
4
4
  import { BundlerAction } from "../../bundler/index.js";
5
5
  import { addTransactionMetadata } from "../../helpers/index.js";
6
- import { ChainWNativeMissingError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NonPositiveAssetAmountError, NonPositiveMaxSharePriceError, ZeroDepositAmountError, } from "../../types/index.js";
6
+ import { ChainWNativeMissingError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
7
7
  import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
8
8
  /**
9
9
  * Prepares a deposit transaction for a VaultV1 (MetaMorpho) contract.
@@ -30,9 +30,9 @@ import { getTokenRequirementActions } from "../signatures/getTokenRequirementAct
30
30
  * @param params.metadata - Optional analytics metadata attached to the bundle.
31
31
  * @returns A deep-frozen `Transaction<VaultV1DepositAction>` with `to`, `value`, `data`, and the
32
32
  * typed `action` discriminator the simulation layer consumes.
33
- * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
34
- * @throws {NonPositiveMaxSharePriceError} when `maxSharePrice <= 0n`.
35
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
33
+ * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
34
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, or when both `amount` and
35
+ * `nativeAmount` resolve to zero.
36
36
  * @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
37
37
  * configured wNative.
38
38
  * @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
@@ -44,7 +44,6 @@ import { getTokenRequirementActions } from "../signatures/getTokenRequirementAct
44
44
  * `requirementSignature` is provided and the signed amount differs from `args.amount`.
45
45
  * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
46
46
  * Permit2 requirement signature is missing its expiration.
47
- * @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
48
47
  * @example
49
48
  * ```ts
50
49
  * import { vaultV1Deposit } from "@morpho-org/morpho-sdk";
@@ -62,16 +61,16 @@ import { getTokenRequirementActions } from "../signatures/getTokenRequirementAct
62
61
  */
63
62
  export const vaultV1Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args: { amount = 0n, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }) => {
64
63
  if (amount < 0n) {
65
- throw new NonPositiveAssetAmountError(asset);
64
+ throw new NegativeInputError("amount", amount);
66
65
  }
67
66
  if (maxSharePrice <= 0n) {
68
- throw new NonPositiveMaxSharePriceError(vaultAddress);
67
+ throw new NonPositiveInputError("maxSharePrice", maxSharePrice);
69
68
  }
70
69
  const actions = [];
71
70
  const { bundler3: { generalAdapter1, bundler3 }, wNative, } = getChainAddresses(chainId);
72
71
  if (nativeAmount) {
73
72
  if (nativeAmount < 0n) {
74
- throw new NegativeNativeAmountError(nativeAmount);
73
+ throw new NegativeInputError("nativeAmount", nativeAmount);
75
74
  }
76
75
  if (!isDefined(wNative)) {
77
76
  throw new ChainWNativeMissingError(chainId);
@@ -99,7 +98,7 @@ export const vaultV1Deposit = ({ vault: { chainId, address: vaultAddress, asset
99
98
  }
100
99
  const totalAssets = amount + (nativeAmount ?? 0n);
101
100
  if (totalAssets === 0n) {
102
- throw new ZeroDepositAmountError(vaultAddress);
101
+ throw new NonPositiveInputError("totalAssets", totalAssets);
103
102
  }
104
103
  actions.push({
105
104
  type: "erc4626Deposit",
@@ -56,9 +56,8 @@ export interface VaultV1MigrateToV2Params {
56
56
  * @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
57
57
  * the typed `action` discriminator the simulation layer consumes.
58
58
  * @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
59
- * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
60
- * @throws {NegativeMinSharePriceError} when `minSharePriceVaultV1 < 0n`.
61
- * @throws {NonPositiveMaxSharePriceError} when `maxSharePriceVaultV2 <= 0n`.
59
+ * @throws {NonPositiveInputError} when `shares <= 0n` or `maxSharePriceVaultV2 <= 0n`.
60
+ * @throws {NegativeInputError} when `minSharePriceVaultV1 < 0n`.
62
61
  * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
63
62
  * is provided and the signed asset differs from `vault.address` (the V1 share token).
64
63
  * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
3
3
  import { isAddressEqual, maxUint256 } from "viem";
4
4
  import { BundlerAction } from "../../bundler/index.js";
5
5
  import { addTransactionMetadata } from "../../helpers/index.js";
6
- import { NegativeMinSharePriceError, NonPositiveMaxSharePriceError, NonPositiveSharesAmountError, VaultAssetMismatchError, } from "../../types/index.js";
6
+ import { NegativeInputError, NonPositiveInputError, VaultAssetMismatchError, } from "../../types/index.js";
7
7
  import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
8
8
  /**
9
9
  * Prepares an atomic full-migration transaction from VaultV1 to VaultV2.
@@ -36,9 +36,8 @@ import { getTokenRequirementActions } from "../signatures/getTokenRequirementAct
36
36
  * @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
37
37
  * the typed `action` discriminator the simulation layer consumes.
38
38
  * @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
39
- * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
40
- * @throws {NegativeMinSharePriceError} when `minSharePriceVaultV1 < 0n`.
41
- * @throws {NonPositiveMaxSharePriceError} when `maxSharePriceVaultV2 <= 0n`.
39
+ * @throws {NonPositiveInputError} when `shares <= 0n` or `maxSharePriceVaultV2 <= 0n`.
40
+ * @throws {NegativeInputError} when `minSharePriceVaultV1 < 0n`.
42
41
  * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
43
42
  * is provided and the signed asset differs from `vault.address` (the V1 share token).
44
43
  * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
@@ -70,13 +69,13 @@ export const vaultV1MigrateToV2 = ({ vault: { chainId, address: sourceVault, ass
70
69
  throw new VaultAssetMismatchError(sourceAsset, targetAsset);
71
70
  }
72
71
  if (shares <= 0n) {
73
- throw new NonPositiveSharesAmountError(sourceVault);
72
+ throw new NonPositiveInputError("shares", shares);
74
73
  }
75
74
  if (minSharePriceVaultV1 < 0n) {
76
- throw new NegativeMinSharePriceError(sourceVault);
75
+ throw new NegativeInputError("minSharePriceVaultV1", minSharePriceVaultV1);
77
76
  }
78
77
  if (maxSharePriceVaultV2 <= 0n) {
79
- throw new NonPositiveMaxSharePriceError(targetVault);
78
+ throw new NonPositiveInputError("maxSharePriceVaultV2", maxSharePriceVaultV2);
80
79
  }
81
80
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
82
81
  const actions = [];
@@ -24,7 +24,7 @@ export interface VaultV1RedeemParams {
24
24
  * @param params.metadata - Optional analytics metadata attached to the transaction.
25
25
  * @returns A deep-frozen `Transaction<VaultV1RedeemAction>` with `to`, `value`, `data`, and the
26
26
  * typed `action` discriminator the simulation layer consumes.
27
- * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
27
+ * @throws {NonPositiveInputError} when `shares <= 0n`.
28
28
  * @example
29
29
  * ```ts
30
30
  * import { vaultV1Redeem } from "@morpho-org/morpho-sdk";
@@ -2,7 +2,7 @@ import { metaMorphoAbi } from "@morpho-org/blue-sdk-viem";
2
2
  import { deepFreeze } from "@morpho-org/morpho-ts";
3
3
  import { encodeFunctionData } from "viem";
4
4
  import { addTransactionMetadata } from "../../helpers/index.js";
5
- import { NonPositiveSharesAmountError, } from "../../types/index.js";
5
+ import { NonPositiveInputError, } from "../../types/index.js";
6
6
  /**
7
7
  * Prepares a redeem transaction for a VaultV1 (MetaMorpho) contract.
8
8
  *
@@ -15,7 +15,7 @@ import { NonPositiveSharesAmountError, } from "../../types/index.js";
15
15
  * @param params.metadata - Optional analytics metadata attached to the transaction.
16
16
  * @returns A deep-frozen `Transaction<VaultV1RedeemAction>` with `to`, `value`, `data`, and the
17
17
  * typed `action` discriminator the simulation layer consumes.
18
- * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
18
+ * @throws {NonPositiveInputError} when `shares <= 0n`.
19
19
  * @example
20
20
  * ```ts
21
21
  * import { vaultV1Redeem } from "@morpho-org/morpho-sdk";
@@ -29,7 +29,7 @@ import { NonPositiveSharesAmountError, } from "../../types/index.js";
29
29
  */
30
30
  export const vaultV1Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
31
31
  if (shares <= 0n) {
32
- throw new NonPositiveSharesAmountError(vaultAddress);
32
+ throw new NonPositiveInputError("shares", shares);
33
33
  }
34
34
  let tx = {
35
35
  to: vaultAddress,
@@ -24,7 +24,7 @@ export interface VaultV1WithdrawParams {
24
24
  * @param params.metadata - Optional analytics metadata attached to the transaction.
25
25
  * @returns A deep-frozen `Transaction<VaultV1WithdrawAction>` with `to`, `value`, `data`, and the
26
26
  * typed `action` discriminator the simulation layer consumes.
27
- * @throws {NonPositiveAssetAmountError} when `amount <= 0n`.
27
+ * @throws {NonPositiveInputError} when `amount <= 0n`.
28
28
  * @example
29
29
  * ```ts
30
30
  * import { vaultV1Withdraw } from "@morpho-org/morpho-sdk";
@@ -2,7 +2,7 @@ import { metaMorphoAbi } from "@morpho-org/blue-sdk-viem";
2
2
  import { deepFreeze } from "@morpho-org/morpho-ts";
3
3
  import { encodeFunctionData } from "viem";
4
4
  import { addTransactionMetadata } from "../../helpers/index.js";
5
- import { NonPositiveAssetAmountError, } from "../../types/index.js";
5
+ import { NonPositiveInputError, } from "../../types/index.js";
6
6
  /**
7
7
  * Prepares a withdraw transaction for a VaultV1 (MetaMorpho) contract.
8
8
  *
@@ -15,7 +15,7 @@ import { NonPositiveAssetAmountError, } from "../../types/index.js";
15
15
  * @param params.metadata - Optional analytics metadata attached to the transaction.
16
16
  * @returns A deep-frozen `Transaction<VaultV1WithdrawAction>` with `to`, `value`, `data`, and the
17
17
  * typed `action` discriminator the simulation layer consumes.
18
- * @throws {NonPositiveAssetAmountError} when `amount <= 0n`.
18
+ * @throws {NonPositiveInputError} when `amount <= 0n`.
19
19
  * @example
20
20
  * ```ts
21
21
  * import { vaultV1Withdraw } from "@morpho-org/morpho-sdk";
@@ -29,7 +29,7 @@ import { NonPositiveAssetAmountError, } from "../../types/index.js";
29
29
  */
30
30
  export const vaultV1Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
31
31
  if (amount <= 0n) {
32
- throw new NonPositiveAssetAmountError(vaultAddress);
32
+ throw new NonPositiveInputError("amount", amount);
33
33
  }
34
34
  let tx = {
35
35
  to: vaultAddress,
@@ -39,9 +39,9 @@ export interface VaultV2DepositParams {
39
39
  * @param params.metadata - Optional analytics metadata attached to the bundle.
40
40
  * @returns A deep-frozen `Transaction<VaultV2DepositAction>` with `to`, `value`, `data`, and the
41
41
  * typed `action` discriminator the simulation layer consumes.
42
- * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
43
- * @throws {NonPositiveMaxSharePriceError} when `maxSharePrice <= 0n`.
44
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
42
+ * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
43
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, or when both `amount` and
44
+ * `nativeAmount` resolve to zero.
45
45
  * @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
46
46
  * configured wNative.
47
47
  * @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
@@ -53,7 +53,6 @@ export interface VaultV2DepositParams {
53
53
  * `requirementSignature` is provided and the signed amount differs from `args.amount`.
54
54
  * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
55
55
  * Permit2 requirement signature is missing its expiration.
56
- * @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
57
56
  * @example
58
57
  * ```ts
59
58
  * import { vaultV2Deposit } from "@morpho-org/morpho-sdk";