@morpho-org/morpho-sdk 5.1.2 → 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 +105 -86
  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 -114
  133. package/lib/cjs/types/error.js +259 -175
  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 +107 -88
  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 -114
  267. package/lib/esm/types/error.js +232 -149
  268. package/lib/esm/utils.d.ts +1 -0
  269. package/lib/esm/utils.js +1 -0
  270. package/package.json +13 -4
@@ -1,7 +1,11 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
2
  import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js";
3
3
  /**
4
- * Computes classic ERC-20 approval transactions for GeneralAdapter1 or Permit2, given the existing allowance.
4
+ * Computes classic ERC-20 approval transactions for a supported SDK spender, given the existing
5
+ * allowance.
6
+ *
7
+ * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
8
+ * GeneralAdapter1, Permit2, Midnight, and MidnightBundles addresses when configured.
5
9
  *
6
10
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
7
11
  * `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
@@ -9,16 +13,18 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
9
13
  * before re-approving.
10
14
  *
11
15
  * @param params.address - ERC-20 token address.
12
- * @param params.chainId - The chain the bundle targets.
16
+ * @param params.chainId - The chain the transaction targets, used to resolve supported spenders
17
+ * and token approval caps.
13
18
  * @param params.args.spendAmount - The amount the bundle will actually pull.
14
19
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
15
20
  * may be `MAX_UINT_160` for Permit2 prerequisites).
16
- * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1 or Permit2.
21
+ * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
22
+ * Permit2, Midnight, or MidnightBundles for `chainId`.
17
23
  * @param params.allowances - The user's current allowance of `address` for `spender`.
18
24
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
19
25
  * followed by the new approval. Empty when no approval is needed.
20
26
  * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < spendAmount`.
21
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or Permit2 for `chainId`.
27
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
22
28
  * @example
23
29
  * ```ts
24
30
  * import { getRequirementsApproval } from "@morpho-org/morpho-sdk";
@@ -5,7 +5,11 @@ const constant_js_1 = require("../../helpers/constant.js");
5
5
  const index_js_1 = require("../../types/index.js");
6
6
  const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
7
7
  /**
8
- * Computes classic ERC-20 approval transactions for GeneralAdapter1 or Permit2, given the existing allowance.
8
+ * Computes classic ERC-20 approval transactions for a supported SDK spender, given the existing
9
+ * allowance.
10
+ *
11
+ * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
12
+ * GeneralAdapter1, Permit2, Midnight, and MidnightBundles addresses when configured.
9
13
  *
10
14
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
11
15
  * `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
@@ -13,16 +17,18 @@ const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
13
17
  * before re-approving.
14
18
  *
15
19
  * @param params.address - ERC-20 token address.
16
- * @param params.chainId - The chain the bundle targets.
20
+ * @param params.chainId - The chain the transaction targets, used to resolve supported spenders
21
+ * and token approval caps.
17
22
  * @param params.args.spendAmount - The amount the bundle will actually pull.
18
23
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
19
24
  * may be `MAX_UINT_160` for Permit2 prerequisites).
20
- * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1 or Permit2.
25
+ * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
26
+ * Permit2, Midnight, or MidnightBundles for `chainId`.
21
27
  * @param params.allowances - The user's current allowance of `address` for `spender`.
22
28
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
23
29
  * followed by the new approval. Empty when no approval is needed.
24
30
  * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < spendAmount`.
25
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or Permit2 for `chainId`.
31
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
26
32
  * @example
27
33
  * ```ts
28
34
  * 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";
@@ -18,3 +18,4 @@ __exportStar(require("./blue/index.js"), exports);
18
18
  __exportStar(require("./encode/index.js"), exports);
19
19
  __exportStar(require("./generalAdapter/index.js"), exports);
20
20
  __exportStar(require("./getRequirementsApproval.js"), exports);
21
+ __exportStar(require("./midnight/index.js"), exports);
@@ -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,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMidnightApprovalRequirements = void 0;
4
+ const viem_1 = require("viem");
5
+ const actions_1 = require("viem/actions");
6
+ const index_js_1 = require("../../../helpers/index.js");
7
+ const index_js_2 = require("../../../types/index.js");
8
+ const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
9
+ /**
10
+ * Resolves classic ERC20 approval requirements for a Midnight spender.
11
+ *
12
+ * Entity flows call this from `getRequirements()`. Direct low-level consumers
13
+ * should call it before encoding a Midnight action that lets `Midnight` or
14
+ * `MidnightBundles` pull ERC20 tokens from the user.
15
+ *
16
+ * @param params.viemClient - Viem client used to read ERC20 allowance.
17
+ * @param params.chainId - Chain id expected by the viem client.
18
+ * @param params.token - ERC20 token that may need approval.
19
+ * @param params.owner - Token owner.
20
+ * @param params.spender - Midnight spender that will pull tokens.
21
+ * @param params.amount - Token amount the spender must be able to pull.
22
+ * @returns Approval transactions required for `spender` to pull `amount`.
23
+ * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
24
+ * @throws {NegativeInputError} when `amount < 0n`.
25
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundles deployment.
26
+ * @example
27
+ * ```ts
28
+ * import {
29
+ * getMidnightApprovalRequirements,
30
+ * midnightTakeLend,
31
+ * } from "@morpho-org/morpho-sdk";
32
+ *
33
+ * const approvals = await getMidnightApprovalRequirements({
34
+ * viemClient: client,
35
+ * chainId: 8453,
36
+ * token: loanToken,
37
+ * owner: user,
38
+ * spender: midnightBundles,
39
+ * amount: 1_000_000n,
40
+ * });
41
+ * if (approvals.length === 0) {
42
+ * const tx = midnightTakeLend(takeParams);
43
+ * }
44
+ * ```
45
+ */
46
+ const getMidnightApprovalRequirements = async (params) => {
47
+ (0, index_js_1.validateChainId)(params.viemClient.chain?.id, params.chainId);
48
+ if (params.amount < 0n) {
49
+ throw new index_js_2.NegativeInputError("amount", params.amount);
50
+ }
51
+ // Validate the target even when no approval transaction needs to be encoded.
52
+ (0, index_js_1.validateRequirementSpender)({
53
+ chainId: params.chainId,
54
+ spender: params.spender,
55
+ allowed: ["midnight", "midnightBundles"],
56
+ });
57
+ if (params.amount === 0n)
58
+ return [];
59
+ const allowance = await (0, actions_1.readContract)(params.viemClient, {
60
+ address: params.token,
61
+ abi: viem_1.erc20Abi,
62
+ functionName: "allowance",
63
+ args: [params.owner, params.spender],
64
+ });
65
+ return (0, getRequirementsApproval_js_1.getRequirementsApproval)({
66
+ address: params.token,
67
+ chainId: params.chainId,
68
+ args: {
69
+ spender: params.spender,
70
+ spendAmount: params.amount,
71
+ approvalAmount: params.amount,
72
+ },
73
+ allowances: allowance,
74
+ });
75
+ };
76
+ exports.getMidnightApprovalRequirements = getMidnightApprovalRequirements;
@@ -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,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMidnightAuthorizationRequirement = void 0;
4
+ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const actions_1 = require("viem/actions");
8
+ const index_js_1 = require("../../../helpers/index.js");
9
+ const validateMidnightAuthorizationTarget_js_1 = require("../../../helpers/validateMidnightAuthorizationTarget.js");
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
+ const getMidnightAuthorizationRequirement = async (params) => {
45
+ (0, index_js_1.validateChainId)(params.viemClient.chain?.id, params.chainId);
46
+ // Reject unknown operators before reading authorization state.
47
+ (0, validateMidnightAuthorizationTarget_js_1.validateMidnightAuthorizationTarget)({
48
+ chainId: params.chainId,
49
+ authorized: params.authorized,
50
+ });
51
+ const midnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
52
+ const isAuthorized = await (0, actions_1.readContract)(params.viemClient, {
53
+ address: midnight,
54
+ abi: midnight_sdk_1.midnightAbi,
55
+ functionName: "isAuthorized",
56
+ args: [params.owner, params.authorized],
57
+ });
58
+ if (isAuthorized)
59
+ return null;
60
+ return (0, morpho_ts_1.deepFreeze)({
61
+ to: midnight,
62
+ value: 0n,
63
+ data: (0, viem_1.encodeFunctionData)({
64
+ abi: midnight_sdk_1.midnightAbi,
65
+ functionName: "setIsAuthorized",
66
+ args: [params.authorized, true, params.owner],
67
+ }),
68
+ action: {
69
+ type: "midnightAuthorization",
70
+ args: {
71
+ authorized: params.authorized,
72
+ isAuthorized: true,
73
+ onBehalf: params.owner,
74
+ },
75
+ },
76
+ });
77
+ };
78
+ exports.getMidnightAuthorizationRequirement = getMidnightAuthorizationRequirement;
@@ -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,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSetterRatifierRatifyRootRequirement = void 0;
4
+ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const actions_1 = require("viem/actions");
8
+ const index_js_1 = require("../../../helpers/index.js");
9
+ /**
10
+ * Resolves the SetterRatifier root approval transaction for a maker offer tree.
11
+ *
12
+ * Call after building a Setter-ratified tree and before encoding/submitting its
13
+ * payload. Entity make-offer flows call this from `getRequirements()` and omit
14
+ * the transaction when the maker has already approved the root.
15
+ *
16
+ * @param params.viemClient - Viem client used to read root approval state.
17
+ * @param params.chainId - Chain id expected by the viem client.
18
+ * @param params.maker - Maker whose root approval is checked.
19
+ * @param params.root - Offer-tree root that must be approved.
20
+ * @returns Ratify-root transaction, or `null` when the root is already ratified.
21
+ * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
22
+ * @example
23
+ * ```ts
24
+ * import { getSetterRatifierRatifyRootRequirement } from "@morpho-org/morpho-sdk";
25
+ *
26
+ * const tx = await getSetterRatifierRatifyRootRequirement({
27
+ * viemClient: client,
28
+ * chainId: 8453,
29
+ * maker: user,
30
+ * root,
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
+ const getSetterRatifierRatifyRootRequirement = async (params) => {
42
+ (0, index_js_1.validateChainId)(params.viemClient.chain?.id, params.chainId);
43
+ const setterRatifier = (0, morpho_ts_1.getChainAddress)(params.chainId, "setterRatifier");
44
+ const isRootRatified = await (0, actions_1.readContract)(params.viemClient, {
45
+ address: setterRatifier,
46
+ abi: midnight_sdk_1.setterRatifierAbi,
47
+ functionName: "isRootRatified",
48
+ args: [params.maker, params.root],
49
+ });
50
+ if (isRootRatified)
51
+ return null;
52
+ return (0, morpho_ts_1.deepFreeze)({
53
+ to: setterRatifier,
54
+ value: 0n,
55
+ data: (0, viem_1.encodeFunctionData)({
56
+ abi: midnight_sdk_1.setterRatifierAbi,
57
+ functionName: "setIsRootRatified",
58
+ args: [params.maker, params.root, true],
59
+ }),
60
+ action: {
61
+ type: "setterRatifierRatifyRoot",
62
+ args: {
63
+ maker: params.maker,
64
+ root: params.root,
65
+ isRootRatified: true,
66
+ },
67
+ },
68
+ });
69
+ };
70
+ exports.getSetterRatifierRatifyRootRequirement = getSetterRatifierRatifyRootRequirement;
@@ -0,0 +1,3 @@
1
+ export * from "./getMidnightApprovalRequirements.js";
2
+ export * from "./getMidnightAuthorizationRequirement.js";
3
+ export * from "./getSetterRatifierRatifyRootRequirement.js";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./getMidnightApprovalRequirements.js"), exports);
18
+ __exportStar(require("./getMidnightAuthorizationRequirement.js"), exports);
19
+ __exportStar(require("./getSetterRatifierRatifyRootRequirement.js"), exports);
@@ -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";
@@ -33,9 +33,9 @@ const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequireme
33
33
  * @param params.metadata - Optional analytics metadata attached to the bundle.
34
34
  * @returns A deep-frozen `Transaction<VaultV1DepositAction>` with `to`, `value`, `data`, and the
35
35
  * typed `action` discriminator the simulation layer consumes.
36
- * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
37
- * @throws {NonPositiveMaxSharePriceError} when `maxSharePrice <= 0n`.
38
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
36
+ * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
37
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, or when both `amount` and
38
+ * `nativeAmount` resolve to zero.
39
39
  * @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
40
40
  * configured wNative.
41
41
  * @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
@@ -47,7 +47,6 @@ const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequireme
47
47
  * `requirementSignature` is provided and the signed amount differs from `args.amount`.
48
48
  * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
49
49
  * Permit2 requirement signature is missing its expiration.
50
- * @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
51
50
  * @example
52
51
  * ```ts
53
52
  * import { vaultV1Deposit } from "@morpho-org/morpho-sdk";
@@ -65,16 +64,16 @@ const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequireme
65
64
  */
66
65
  const vaultV1Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args: { amount = 0n, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }) => {
67
66
  if (amount < 0n) {
68
- throw new index_js_3.NonPositiveAssetAmountError(asset);
67
+ throw new index_js_3.NegativeInputError("amount", amount);
69
68
  }
70
69
  if (maxSharePrice <= 0n) {
71
- throw new index_js_3.NonPositiveMaxSharePriceError(vaultAddress);
70
+ throw new index_js_3.NonPositiveInputError("maxSharePrice", maxSharePrice);
72
71
  }
73
72
  const actions = [];
74
73
  const { bundler3: { generalAdapter1, bundler3 }, wNative, } = (0, blue_sdk_1.getChainAddresses)(chainId);
75
74
  if (nativeAmount) {
76
75
  if (nativeAmount < 0n) {
77
- throw new index_js_3.NegativeNativeAmountError(nativeAmount);
76
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
78
77
  }
79
78
  if (!(0, morpho_ts_1.isDefined)(wNative)) {
80
79
  throw new index_js_3.ChainWNativeMissingError(chainId);
@@ -102,7 +101,7 @@ const vaultV1Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args
102
101
  }
103
102
  const totalAssets = amount + (nativeAmount ?? 0n);
104
103
  if (totalAssets === 0n) {
105
- throw new index_js_3.ZeroDepositAmountError(vaultAddress);
104
+ throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
106
105
  }
107
106
  actions.push({
108
107
  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`
@@ -39,9 +39,8 @@ const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequireme
39
39
  * @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
40
40
  * the typed `action` discriminator the simulation layer consumes.
41
41
  * @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
42
- * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
43
- * @throws {NegativeMinSharePriceError} when `minSharePriceVaultV1 < 0n`.
44
- * @throws {NonPositiveMaxSharePriceError} when `maxSharePriceVaultV2 <= 0n`.
42
+ * @throws {NonPositiveInputError} when `shares <= 0n` or `maxSharePriceVaultV2 <= 0n`.
43
+ * @throws {NegativeInputError} when `minSharePriceVaultV1 < 0n`.
45
44
  * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
46
45
  * is provided and the signed asset differs from `vault.address` (the V1 share token).
47
46
  * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
@@ -73,13 +72,13 @@ const vaultV1MigrateToV2 = ({ vault: { chainId, address: sourceVault, asset: sou
73
72
  throw new index_js_3.VaultAssetMismatchError(sourceAsset, targetAsset);
74
73
  }
75
74
  if (shares <= 0n) {
76
- throw new index_js_3.NonPositiveSharesAmountError(sourceVault);
75
+ throw new index_js_3.NonPositiveInputError("shares", shares);
77
76
  }
78
77
  if (minSharePriceVaultV1 < 0n) {
79
- throw new index_js_3.NegativeMinSharePriceError(sourceVault);
78
+ throw new index_js_3.NegativeInputError("minSharePriceVaultV1", minSharePriceVaultV1);
80
79
  }
81
80
  if (maxSharePriceVaultV2 <= 0n) {
82
- throw new index_js_3.NonPositiveMaxSharePriceError(targetVault);
81
+ throw new index_js_3.NonPositiveInputError("maxSharePriceVaultV2", maxSharePriceVaultV2);
83
82
  }
84
83
  const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
85
84
  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";
@@ -18,7 +18,7 @@ const index_js_2 = require("../../types/index.js");
18
18
  * @param params.metadata - Optional analytics metadata attached to the transaction.
19
19
  * @returns A deep-frozen `Transaction<VaultV1RedeemAction>` with `to`, `value`, `data`, and the
20
20
  * typed `action` discriminator the simulation layer consumes.
21
- * @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
21
+ * @throws {NonPositiveInputError} when `shares <= 0n`.
22
22
  * @example
23
23
  * ```ts
24
24
  * import { vaultV1Redeem } from "@morpho-org/morpho-sdk";
@@ -32,7 +32,7 @@ const index_js_2 = require("../../types/index.js");
32
32
  */
33
33
  const vaultV1Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
34
34
  if (shares <= 0n) {
35
- throw new index_js_2.NonPositiveSharesAmountError(vaultAddress);
35
+ throw new index_js_2.NonPositiveInputError("shares", shares);
36
36
  }
37
37
  let tx = {
38
38
  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";
@@ -18,7 +18,7 @@ const index_js_2 = require("../../types/index.js");
18
18
  * @param params.metadata - Optional analytics metadata attached to the transaction.
19
19
  * @returns A deep-frozen `Transaction<VaultV1WithdrawAction>` with `to`, `value`, `data`, and the
20
20
  * typed `action` discriminator the simulation layer consumes.
21
- * @throws {NonPositiveAssetAmountError} when `amount <= 0n`.
21
+ * @throws {NonPositiveInputError} when `amount <= 0n`.
22
22
  * @example
23
23
  * ```ts
24
24
  * import { vaultV1Withdraw } from "@morpho-org/morpho-sdk";
@@ -32,7 +32,7 @@ const index_js_2 = require("../../types/index.js");
32
32
  */
33
33
  const vaultV1Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
34
34
  if (amount <= 0n) {
35
- throw new index_js_2.NonPositiveAssetAmountError(vaultAddress);
35
+ throw new index_js_2.NonPositiveInputError("amount", amount);
36
36
  }
37
37
  let tx = {
38
38
  to: vaultAddress,