@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
package/lib/esm/abis.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { marketParamsAbi } from "@morpho-org/blue-sdk";
2
2
  export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi, preLiquidationAbi, preLiquidationFactoryAbi, publicAllocatorAbi, vaultV1AdapterAbi, vaultV1AdapterFactoryAbi, vaultV2Abi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
3
+ export { ecrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
3
4
  /** ABI for the Bundler3 multicall contract. */
4
5
  export const bundler3Abi = [
5
6
  {
@@ -48,15 +48,11 @@ export interface BlueBorrowParams {
48
48
  * @param params.metadata - Optional analytics metadata attached to the bundle.
49
49
  * @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
50
50
  * typed `action` discriminator the simulation layer consumes.
51
- * @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
52
- * @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
53
- * allowed despite the class name).
54
- * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
55
- * `reallocations` is non-empty and any `reallocation.fee < 0n`.
51
+ * @throws {NonPositiveInputError} when `amount <= 0n` or any reallocation withdrawal amount
52
+ * is non-positive.
53
+ * @throws {NegativeInputError} when `minSharePrice < 0n` or any reallocation fee is negative.
56
54
  * @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
57
55
  * `reallocation.withdrawals` is empty.
58
- * @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
59
- * `reallocation.withdrawals[i].amount <= 0n`.
60
56
  * @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
61
57
  * reallocation withdrawal references the target market.
62
58
  * @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
@@ -1,7 +1,7 @@
1
1
  import { deepFreeze } from "@morpho-org/morpho-ts";
2
2
  import { BundlerAction } from "../../bundler/index.js";
3
3
  import { addTransactionMetadata } from "../../helpers/index.js";
4
- import { NonPositiveBorrowAmountError, NonPositiveMinBorrowSharePriceError, } from "../../types/index.js";
4
+ import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
5
5
  import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
6
6
  import { buildReallocationActions } from "./buildReallocationActions.js";
7
7
  /**
@@ -27,15 +27,11 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
27
27
  * @param params.metadata - Optional analytics metadata attached to the bundle.
28
28
  * @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
29
29
  * typed `action` discriminator the simulation layer consumes.
30
- * @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
31
- * @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
32
- * allowed despite the class name).
33
- * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
34
- * `reallocations` is non-empty and any `reallocation.fee < 0n`.
30
+ * @throws {NonPositiveInputError} when `amount <= 0n` or any reallocation withdrawal amount
31
+ * is non-positive.
32
+ * @throws {NegativeInputError} when `minSharePrice < 0n` or any reallocation fee is negative.
35
33
  * @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
36
34
  * `reallocation.withdrawals` is empty.
37
- * @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
38
- * `reallocation.withdrawals[i].amount <= 0n`.
39
35
  * @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
40
36
  * reallocation withdrawal references the target market.
41
37
  * @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
@@ -57,10 +53,10 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
57
53
  */
58
54
  export const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
59
55
  if (amount <= 0n) {
60
- throw new NonPositiveBorrowAmountError(marketParams.id);
56
+ throw new NonPositiveInputError("amount", amount);
61
57
  }
62
58
  if (minSharePrice < 0n) {
63
- throw new NonPositiveMinBorrowSharePriceError(marketParams.id);
59
+ throw new NegativeInputError("minSharePrice", minSharePrice);
64
60
  }
65
61
  const actions = [];
66
62
  let reallocationFee = 0n;
@@ -7,15 +7,14 @@ import type { VaultReallocation } from "../../types/index.js";
7
7
  * Validates the reallocations, then encodes each as a `reallocateTo` action against the target
8
8
  * market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
9
9
  * `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
10
- * consumed only by `blueBorrow` and `blueSupplyCollateralBorrow`; not re-exported on the
11
- * public surface.
10
+ * consumed by the Blue actions that accept reallocations; not re-exported on the public surface.
12
11
  *
13
12
  * @param reallocations - The vault reallocations to encode.
14
13
  * @param targetMarketParams - The target market params the freed liquidity is destined for.
15
14
  * @returns The encoded `reallocateTo` actions and the summed reallocation fee in native tokens.
16
- * @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
15
+ * @throws {NegativeInputError} when any reallocation fee is negative.
17
16
  * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
18
- * @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
17
+ * @throws {NonPositiveInputError} when any withdrawal amount is non-positive.
19
18
  * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
20
19
  * @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
21
20
  * strictly sorted by market id.
@@ -5,15 +5,14 @@ import { validateReallocations } from "../../helpers/index.js";
5
5
  * Validates the reallocations, then encodes each as a `reallocateTo` action against the target
6
6
  * market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
7
7
  * `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
8
- * consumed only by `blueBorrow` and `blueSupplyCollateralBorrow`; not re-exported on the
9
- * public surface.
8
+ * consumed by the Blue actions that accept reallocations; not re-exported on the public surface.
10
9
  *
11
10
  * @param reallocations - The vault reallocations to encode.
12
11
  * @param targetMarketParams - The target market params the freed liquidity is destined for.
13
12
  * @returns The encoded `reallocateTo` actions and the summed reallocation fee in native tokens.
14
- * @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
13
+ * @throws {NegativeInputError} when any reallocation fee is negative.
15
14
  * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
16
- * @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
15
+ * @throws {NonPositiveInputError} when any withdrawal amount is non-positive.
17
16
  * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
18
17
  * @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
19
18
  * strictly sorted by market id.
@@ -91,18 +91,14 @@ export interface BlueRefinanceParams {
91
91
  * @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
92
92
  * @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
93
93
  * repay); in shares mode the entity passes both. Caller-facing mutual exclusivity is enforced at the entity layer.
94
- * @throws {ZeroCollateralAmountError} when `collateralAmount <= 0n`.
95
- * @throws {NonPositiveAssetAmountError} when `borrowAssets < 0n`.
96
- * @throws {NegativeBorrowSharesError} when `borrowShares < 0n`.
97
- * @throws {NonPositiveMinBorrowSharePriceError} when `minBorrowSharePrice < 0n`.
98
- * @throws {NegativeMaxRepaySharePriceError} when `maxRepaySharePrice < 0n`.
94
+ * @throws {NonPositiveInputError} when `collateralAmount <= 0n`, a repay leg has a non-positive
95
+ * `maxRepaySharePrice`, or any reallocation withdrawal amount is non-positive.
96
+ * @throws {NegativeInputError} when `borrowAssets`, `borrowShares`, `minBorrowSharePrice`,
97
+ * `maxRepaySharePrice`, or any reallocation fee is negative.
99
98
  * @throws {RefinanceSameMarketError} when source and target market ids are equal.
100
99
  * @throws {RefinanceTokenMismatchError} when source and target do not share both tokens.
101
100
  * @throws {RefinanceSharesMissingBorrowAssetsError} when `borrowShares > 0n` but `borrowAssets` is omitted or non-positive.
102
- * @throws {NonPositiveRepayMaxSharePriceError} when a repay leg is encoded and `maxRepaySharePrice <= 0n`.
103
- * @throws {NegativeReallocationFeeError} when any `reallocation.fee < 0n`.
104
101
  * @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
105
- * @throws {NonPositiveReallocationAmountError} when any `reallocation.withdrawals[i].amount <= 0n`.
106
102
  * @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references the target market.
107
103
  * @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly sorted by market id.
108
104
  * @example
@@ -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 { NegativeBorrowSharesError, NegativeMaxRepaySharePriceError, NonPositiveAssetAmountError, NonPositiveMinBorrowSharePriceError, NonPositiveRepayMaxSharePriceError, RefinanceSameMarketError, RefinanceSharesMissingBorrowAssetsError, RefinanceTokenMismatchError, ZeroCollateralAmountError, } from "../../types/index.js";
6
+ import { NegativeInputError, NonPositiveInputError, RefinanceSameMarketError, RefinanceSharesMissingBorrowAssetsError, RefinanceTokenMismatchError, } from "../../types/index.js";
7
7
  import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
8
8
  import { buildReallocationActions } from "./buildReallocationActions.js";
9
9
  /**
@@ -59,18 +59,14 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
59
59
  * @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
60
60
  * @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
61
61
  * repay); in shares mode the entity passes both. Caller-facing mutual exclusivity is enforced at the entity layer.
62
- * @throws {ZeroCollateralAmountError} when `collateralAmount <= 0n`.
63
- * @throws {NonPositiveAssetAmountError} when `borrowAssets < 0n`.
64
- * @throws {NegativeBorrowSharesError} when `borrowShares < 0n`.
65
- * @throws {NonPositiveMinBorrowSharePriceError} when `minBorrowSharePrice < 0n`.
66
- * @throws {NegativeMaxRepaySharePriceError} when `maxRepaySharePrice < 0n`.
62
+ * @throws {NonPositiveInputError} when `collateralAmount <= 0n`, a repay leg has a non-positive
63
+ * `maxRepaySharePrice`, or any reallocation withdrawal amount is non-positive.
64
+ * @throws {NegativeInputError} when `borrowAssets`, `borrowShares`, `minBorrowSharePrice`,
65
+ * `maxRepaySharePrice`, or any reallocation fee is negative.
67
66
  * @throws {RefinanceSameMarketError} when source and target market ids are equal.
68
67
  * @throws {RefinanceTokenMismatchError} when source and target do not share both tokens.
69
68
  * @throws {RefinanceSharesMissingBorrowAssetsError} when `borrowShares > 0n` but `borrowAssets` is omitted or non-positive.
70
- * @throws {NonPositiveRepayMaxSharePriceError} when a repay leg is encoded and `maxRepaySharePrice <= 0n`.
71
- * @throws {NegativeReallocationFeeError} when any `reallocation.fee < 0n`.
72
69
  * @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
73
- * @throws {NonPositiveReallocationAmountError} when any `reallocation.withdrawals[i].amount <= 0n`.
74
70
  * @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references the target market.
75
71
  * @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly sorted by market id.
76
72
  * @example
@@ -94,19 +90,19 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
94
90
  */
95
91
  export const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }) => {
96
92
  if (collateralAmount <= 0n) {
97
- throw new ZeroCollateralAmountError(sourceParams.id);
93
+ throw new NonPositiveInputError("collateralAmount", collateralAmount);
98
94
  }
99
95
  if (borrowAssets < 0n) {
100
- throw new NonPositiveAssetAmountError(sourceParams.loanToken);
96
+ throw new NegativeInputError("borrowAssets", borrowAssets);
101
97
  }
102
98
  if (borrowShares < 0n) {
103
- throw new NegativeBorrowSharesError(sourceParams.id);
99
+ throw new NegativeInputError("borrowShares", borrowShares);
104
100
  }
105
101
  if (minBorrowSharePrice < 0n) {
106
- throw new NonPositiveMinBorrowSharePriceError(targetParams.id);
102
+ throw new NegativeInputError("minBorrowSharePrice", minBorrowSharePrice);
107
103
  }
108
104
  if (maxRepaySharePrice < 0n) {
109
- throw new NegativeMaxRepaySharePriceError(sourceParams.id);
105
+ throw new NegativeInputError("maxRepaySharePrice", maxRepaySharePrice);
110
106
  }
111
107
  if (sourceParams.id === targetParams.id) {
112
108
  throw new RefinanceSameMarketError(sourceParams.id);
@@ -124,7 +120,7 @@ export const blueRefinance = ({ source: { chainId, marketParams: sourceParams },
124
120
  }
125
121
  // A repay leg with maxRepaySharePrice = 0n always reverts; require a positive cap when debt is migrated.
126
122
  if (shouldMigrateBorrow && maxRepaySharePrice <= 0n) {
127
- throw new NonPositiveRepayMaxSharePriceError(sourceParams.id);
123
+ throw new NonPositiveInputError("maxRepaySharePrice", maxRepaySharePrice);
128
124
  }
129
125
  const callback = [];
130
126
  if (shouldMigrateBorrow) {
@@ -53,14 +53,11 @@ export interface BlueRepayParams {
53
53
  * @param params.metadata - Optional analytics metadata attached to the bundle.
54
54
  * @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value` (= `nativeAmount`),
55
55
  * `data`, and the typed `action` discriminator the simulation layer consumes.
56
- * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
57
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
56
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or the total funding is zero.
57
+ * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
58
58
  * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
59
59
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
60
60
  * `transferAmount !== amount + nativeAmount`.
61
- * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
62
- * and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
63
- * funding (`transferAmount + nativeAmount`) is `<= 0n`.
64
61
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
65
62
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
66
63
  * the chain's wNative.
@@ -39,14 +39,11 @@ import { resolveRepayFunding } from "./resolveRepayFunding.js";
39
39
  * @param params.metadata - Optional analytics metadata attached to the bundle.
40
40
  * @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value` (= `nativeAmount`),
41
41
  * `data`, and the typed `action` discriminator the simulation layer consumes.
42
- * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
43
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
42
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or the total funding is zero.
43
+ * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
44
44
  * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
45
45
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
46
46
  * `transferAmount !== amount + nativeAmount`.
47
- * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
48
- * and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
49
- * funding (`transferAmount + nativeAmount`) is `<= 0n`.
50
47
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
51
48
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
52
49
  * the chain's wNative.
@@ -74,15 +74,12 @@ export interface BlueRepayWithdrawCollateralParams {
74
74
  * @param params.metadata - Optional analytics metadata attached to the bundle.
75
75
  * @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
76
76
  * `value` (= `nativeAmount`), `data`, and the typed `action` discriminator the simulation layer consumes.
77
- * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
78
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
77
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, the total funding is zero, or
78
+ * `withdrawAmount <= 0n`.
79
+ * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
79
80
  * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
80
81
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
81
82
  * `transferAmount !== amount + nativeAmount`.
82
- * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
83
- * and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
84
- * funding (`transferAmount + nativeAmount`) is `<= 0n`.
85
- * @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
86
83
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
87
84
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
88
85
  * the chain's wNative.
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
3
3
  import { maxUint256 } from "viem";
4
4
  import { BundlerAction } from "../../bundler/index.js";
5
5
  import { addTransactionMetadata } from "../../helpers/index.js";
6
- import { NonPositiveWithdrawCollateralAmountError, } from "../../types/index.js";
6
+ import { NonPositiveInputError, } from "../../types/index.js";
7
7
  import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
8
8
  import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
9
9
  import { resolveRepayFunding } from "./resolveRepayFunding.js";
@@ -54,15 +54,12 @@ import { resolveRepayFunding } from "./resolveRepayFunding.js";
54
54
  * @param params.metadata - Optional analytics metadata attached to the bundle.
55
55
  * @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
56
56
  * `value` (= `nativeAmount`), `data`, and the typed `action` discriminator the simulation layer consumes.
57
- * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
58
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
57
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, the total funding is zero, or
58
+ * `withdrawAmount <= 0n`.
59
+ * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
59
60
  * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
60
61
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
61
62
  * `transferAmount !== amount + nativeAmount`.
62
- * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
63
- * and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
64
- * funding (`transferAmount + nativeAmount`) is `<= 0n`.
65
- * @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
66
63
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
67
64
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
68
65
  * the chain's wNative.
@@ -95,7 +92,7 @@ export const blueRepayWithdrawCollateral = ({ market: { chainId, marketParams },
95
92
  const { amount = 0n, shares = 0n, nativeAmount = 0n, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, authorizationSignature, } = args;
96
93
  const { isSharesMode, repayAssets, repayShares, erc20Amount } = resolveRepayFunding({ amount, shares, nativeAmount, transferAmount, maxSharePrice }, marketParams.id);
97
94
  if (withdrawAmount <= 0n) {
98
- throw new NonPositiveWithdrawCollateralAmountError(marketParams.id);
95
+ throw new NonPositiveInputError("withdrawAmount", withdrawAmount);
99
96
  }
100
97
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
101
98
  const actions = [];
@@ -56,11 +56,8 @@ export interface RepayFunding {
56
56
  * @param marketId - Market id used to tag the thrown errors.
57
57
  * @returns `{ isSharesMode, repayAssets, repayShares, erc20Amount }` — the mode discriminator and the
58
58
  * amounts the repay builders assemble the bundle from.
59
- * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
60
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
61
- * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode and
62
- * the repaid assets are `<= 0n`, or when in shares mode and `transferAmount` is negative or the total
63
- * funding (`transferAmount + nativeAmount`) is `<= 0n`.
59
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or total repay funding is zero.
60
+ * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
64
61
  * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
65
62
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
66
63
  * `transferAmount !== amount + nativeAmount`.
@@ -1,4 +1,4 @@
1
- import { MutuallyExclusiveRepayAmountsError, NegativeNativeAmountError, NonPositiveRepayAmountError, NonPositiveRepayMaxSharePriceError, TransferAmountNotEqualToAssetsError, } from "../../types/index.js";
1
+ import { MutuallyExclusiveRepayAmountsError, NegativeInputError, NonPositiveInputError, TransferAmountNotEqualToAssetsError, } from "../../types/index.js";
2
2
  /**
3
3
  * Resolves and validates the repay funding envelope shared by `blueRepay` and
4
4
  * `blueRepayWithdrawCollateral`.
@@ -21,11 +21,8 @@ import { MutuallyExclusiveRepayAmountsError, NegativeNativeAmountError, NonPosit
21
21
  * @param marketId - Market id used to tag the thrown errors.
22
22
  * @returns `{ isSharesMode, repayAssets, repayShares, erc20Amount }` — the mode discriminator and the
23
23
  * amounts the repay builders assemble the bundle from.
24
- * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
25
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
26
- * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode and
27
- * the repaid assets are `<= 0n`, or when in shares mode and `transferAmount` is negative or the total
28
- * funding (`transferAmount + nativeAmount`) is `<= 0n`.
24
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or total repay funding is zero.
25
+ * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
29
26
  * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
30
27
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
31
28
  * `transferAmount !== amount + nativeAmount`.
@@ -33,13 +30,16 @@ import { MutuallyExclusiveRepayAmountsError, NegativeNativeAmountError, NonPosit
33
30
  */
34
31
  export const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmount, maxSharePrice, }, marketId) => {
35
32
  if (maxSharePrice <= 0n) {
36
- throw new NonPositiveRepayMaxSharePriceError(marketId);
33
+ throw new NonPositiveInputError("maxSharePrice", maxSharePrice);
37
34
  }
38
35
  if (nativeAmount < 0n) {
39
- throw new NegativeNativeAmountError(nativeAmount);
36
+ throw new NegativeInputError("nativeAmount", nativeAmount);
40
37
  }
41
- if (amount < 0n || shares < 0n) {
42
- throw new NonPositiveRepayAmountError(marketId);
38
+ if (amount < 0n) {
39
+ throw new NegativeInputError("amount", amount);
40
+ }
41
+ if (shares < 0n) {
42
+ throw new NegativeInputError("shares", shares);
43
43
  }
44
44
  if (amount > 0n && shares > 0n) {
45
45
  throw new MutuallyExclusiveRepayAmountsError(marketId);
@@ -58,8 +58,11 @@ export const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmou
58
58
  // ERC-20 (0 on a fully-native repay) and wraps `nativeAmount`; the bundle must
59
59
  // fund the repay with a non-negative transfer and a positive total.
60
60
  if (isSharesMode) {
61
- if (transferAmount < 0n || transferAmount + nativeAmount <= 0n) {
62
- throw new NonPositiveRepayAmountError(marketId);
61
+ if (transferAmount < 0n) {
62
+ throw new NegativeInputError("transferAmount", transferAmount);
63
+ }
64
+ if (transferAmount + nativeAmount <= 0n) {
65
+ throw new NonPositiveInputError("transferAmount + nativeAmount", transferAmount + nativeAmount);
63
66
  }
64
67
  }
65
68
  else {
@@ -71,7 +74,7 @@ export const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmou
71
74
  });
72
75
  }
73
76
  if (repayAssets <= 0n) {
74
- throw new NonPositiveRepayAmountError(marketId);
77
+ throw new NonPositiveInputError("amount + nativeAmount", repayAssets);
75
78
  }
76
79
  }
77
80
  return { isSharesMode, repayAssets, repayShares, erc20Amount };
@@ -40,10 +40,8 @@ export interface BlueSupplyParams {
40
40
  * @param params.metadata - Optional analytics metadata attached to the bundle.
41
41
  * @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
42
42
  * typed `action` discriminator the simulation layer consumes.
43
- * @throws {NegativeSupplyAmountError} when `amount < 0n`.
44
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
45
- * @throws {ZeroSupplyAmountError} when both `amount` and `nativeAmount` resolve to zero.
46
- * @throws {NegativeSupplyMaxSharePriceError} when `maxSharePrice < 0n`.
43
+ * @throws {NegativeInputError} when `amount`, `nativeAmount`, or `maxSharePrice` is negative.
44
+ * @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
47
45
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
48
46
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
49
47
  * the chain's wNative.
@@ -1,7 +1,7 @@
1
1
  import { deepFreeze } from "@morpho-org/morpho-ts";
2
2
  import { BundlerAction } from "../../bundler/index.js";
3
3
  import { addTransactionMetadata } from "../../helpers/index.js";
4
- import { NegativeNativeAmountError, NegativeSupplyAmountError, NegativeSupplyMaxSharePriceError, ZeroSupplyAmountError, } from "../../types/index.js";
4
+ import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
5
5
  import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
6
6
  /**
7
7
  * Prepares a loan-asset supply transaction for a Morpho Blue market.
@@ -26,10 +26,8 @@ import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
26
26
  * @param params.metadata - Optional analytics metadata attached to the bundle.
27
27
  * @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
28
28
  * typed `action` discriminator the simulation layer consumes.
29
- * @throws {NegativeSupplyAmountError} when `amount < 0n`.
30
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
31
- * @throws {ZeroSupplyAmountError} when both `amount` and `nativeAmount` resolve to zero.
32
- * @throws {NegativeSupplyMaxSharePriceError} when `maxSharePrice < 0n`.
29
+ * @throws {NegativeInputError} when `amount`, `nativeAmount`, or `maxSharePrice` is negative.
30
+ * @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
33
31
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
34
32
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
35
33
  * the chain's wNative.
@@ -54,17 +52,17 @@ import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
54
52
  */
55
53
  export const blueSupply = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, maxSharePrice, requirementSignature, nativeAmount, }, metadata, }) => {
56
54
  if (amount < 0n) {
57
- throw new NegativeSupplyAmountError(marketParams.id);
55
+ throw new NegativeInputError("amount", amount);
58
56
  }
59
57
  if (nativeAmount !== undefined && nativeAmount < 0n) {
60
- throw new NegativeNativeAmountError(nativeAmount);
58
+ throw new NegativeInputError("nativeAmount", nativeAmount);
61
59
  }
62
60
  if (maxSharePrice < 0n) {
63
- throw new NegativeSupplyMaxSharePriceError(marketParams.id);
61
+ throw new NegativeInputError("maxSharePrice", maxSharePrice);
64
62
  }
65
63
  const totalAssets = amount + (nativeAmount ?? 0n);
66
64
  if (totalAssets === 0n) {
67
- throw new ZeroSupplyAmountError(marketParams.id);
65
+ throw new NonPositiveInputError("totalAssets", totalAssets);
68
66
  }
69
67
  const actions = buildAssetFundingActions({
70
68
  chainId,
@@ -35,9 +35,8 @@ export interface BlueSupplyCollateralParams {
35
35
  * @param params.metadata - Optional analytics metadata attached to the bundle.
36
36
  * @returns A deep-frozen `Transaction<BlueSupplyCollateralAction>` with `to`, `value`, `data`,
37
37
  * and the typed `action` discriminator the simulation layer consumes.
38
- * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
39
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
40
- * @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
38
+ * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
39
+ * @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
41
40
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
42
41
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
43
42
  * token is not the chain's wNative.
@@ -1,7 +1,7 @@
1
1
  import { deepFreeze } from "@morpho-org/morpho-ts";
2
2
  import { BundlerAction } from "../../bundler/index.js";
3
3
  import { addTransactionMetadata } from "../../helpers/index.js";
4
- import { NegativeNativeAmountError, NonPositiveAssetAmountError, ZeroCollateralAmountError, } from "../../types/index.js";
4
+ import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
5
5
  import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
6
6
  /**
7
7
  * Prepares a supply-collateral transaction for a Morpho Blue market.
@@ -23,9 +23,8 @@ import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
23
23
  * @param params.metadata - Optional analytics metadata attached to the bundle.
24
24
  * @returns A deep-frozen `Transaction<BlueSupplyCollateralAction>` with `to`, `value`, `data`,
25
25
  * and the typed `action` discriminator the simulation layer consumes.
26
- * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
27
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
28
- * @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
26
+ * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
27
+ * @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
29
28
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
30
29
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
31
30
  * token is not the chain's wNative.
@@ -48,14 +47,14 @@ import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
48
47
  */
49
48
  export const blueSupplyCollateral = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, requirementSignature, nativeAmount }, metadata, }) => {
50
49
  if (amount < 0n) {
51
- throw new NonPositiveAssetAmountError(marketParams.collateralToken);
50
+ throw new NegativeInputError("amount", amount);
52
51
  }
53
52
  if (nativeAmount !== undefined && nativeAmount < 0n) {
54
- throw new NegativeNativeAmountError(nativeAmount);
53
+ throw new NegativeInputError("nativeAmount", nativeAmount);
55
54
  }
56
55
  const totalCollateral = amount + (nativeAmount ?? 0n);
57
56
  if (totalCollateral === 0n) {
58
- throw new ZeroCollateralAmountError(marketParams.id);
57
+ throw new NonPositiveInputError("totalCollateral", totalCollateral);
59
58
  }
60
59
  const actions = buildAssetFundingActions({
61
60
  chainId,
@@ -61,11 +61,10 @@ export interface BlueSupplyCollateralBorrowParams {
61
61
  * @param params.metadata - Optional analytics metadata attached to the bundle.
62
62
  * @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
63
63
  * `data`, and the typed `action` discriminator the simulation layer consumes.
64
- * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
65
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
66
- * @throws {NonPositiveBorrowAmountError} when `borrowAmount <= 0n`.
67
- * @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n`.
68
- * @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
64
+ * @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, or any reallocation
65
+ * fee is negative.
66
+ * @throws {NonPositiveInputError} when `borrowAmount <= 0n`, both collateral amounts resolve to
67
+ * zero, or any reallocation withdrawal amount is non-positive.
69
68
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
70
69
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
71
70
  * token is not the chain's wNative.
@@ -75,12 +74,8 @@ export interface BlueSupplyCollateralBorrowParams {
75
74
  * is provided and the signed amount differs from `args.amount`.
76
75
  * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
77
76
  * signature is missing its expiration.
78
- * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
79
- * `reallocations` is non-empty and any `reallocation.fee < 0n`.
80
77
  * @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
81
78
  * `reallocation.withdrawals` is empty.
82
- * @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
83
- * `reallocation.withdrawals[i].amount <= 0n`.
84
79
  * @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
85
80
  * reallocation withdrawal references the target market.
86
81
  * @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
@@ -1,7 +1,7 @@
1
1
  import { deepFreeze } from "@morpho-org/morpho-ts";
2
2
  import { BundlerAction } from "../../bundler/index.js";
3
3
  import { addTransactionMetadata } from "../../helpers/index.js";
4
- import { NegativeNativeAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveMinBorrowSharePriceError, ZeroCollateralAmountError, } from "../../types/index.js";
4
+ import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
5
5
  import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
6
6
  import { buildAssetFundingActions } from "./buildAssetFundingActions.js";
7
7
  import { buildReallocationActions } from "./buildReallocationActions.js";
@@ -37,11 +37,10 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
37
37
  * @param params.metadata - Optional analytics metadata attached to the bundle.
38
38
  * @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
39
39
  * `data`, and the typed `action` discriminator the simulation layer consumes.
40
- * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
41
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
42
- * @throws {NonPositiveBorrowAmountError} when `borrowAmount <= 0n`.
43
- * @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n`.
44
- * @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
40
+ * @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, or any reallocation
41
+ * fee is negative.
42
+ * @throws {NonPositiveInputError} when `borrowAmount <= 0n`, both collateral amounts resolve to
43
+ * zero, or any reallocation withdrawal amount is non-positive.
45
44
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
46
45
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
47
46
  * token is not the chain's wNative.
@@ -51,12 +50,8 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
51
50
  * is provided and the signed amount differs from `args.amount`.
52
51
  * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
53
52
  * signature is missing its expiration.
54
- * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
55
- * `reallocations` is non-empty and any `reallocation.fee < 0n`.
56
53
  * @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
57
54
  * `reallocation.withdrawals` is empty.
58
- * @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
59
- * `reallocation.withdrawals[i].amount <= 0n`.
60
55
  * @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
61
56
  * reallocation withdrawal references the target market.
62
57
  * @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
@@ -80,20 +75,20 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
80
75
  */
81
76
  export const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, authorizationSignature, }, metadata, }) => {
82
77
  if (amount < 0n) {
83
- throw new NonPositiveAssetAmountError(marketParams.collateralToken);
78
+ throw new NegativeInputError("amount", amount);
84
79
  }
85
80
  if (nativeAmount !== undefined && nativeAmount < 0n) {
86
- throw new NegativeNativeAmountError(nativeAmount);
81
+ throw new NegativeInputError("nativeAmount", nativeAmount);
87
82
  }
88
83
  if (borrowAmount <= 0n) {
89
- throw new NonPositiveBorrowAmountError(marketParams.id);
84
+ throw new NonPositiveInputError("borrowAmount", borrowAmount);
90
85
  }
91
86
  if (minSharePrice < 0n) {
92
- throw new NonPositiveMinBorrowSharePriceError(marketParams.id);
87
+ throw new NegativeInputError("minSharePrice", minSharePrice);
93
88
  }
94
89
  const totalCollateral = amount + (nativeAmount ?? 0n);
95
90
  if (totalCollateral === 0n) {
96
- throw new ZeroCollateralAmountError(marketParams.id);
91
+ throw new NonPositiveInputError("totalCollateral", totalCollateral);
97
92
  }
98
93
  const actions = [];
99
94
  if (authorizationSignature) {
@@ -64,14 +64,16 @@ export interface BlueWithdrawParams {
64
64
  * @param params.metadata - Optional analytics metadata attached to the bundle.
65
65
  * @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
66
66
  * the typed `action` discriminator the simulation layer consumes.
67
- * @throws {NonPositiveWithdrawAmountError} when both `assets` and `shares` are zero, or either is negative.
67
+ * @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, or any reallocation fee
68
+ * is negative.
69
+ * @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
70
+ * withdrawal amount is non-positive.
68
71
  * @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
69
- * @throws {NegativeWithdrawMinSharePriceError} when `minSharePrice < 0n` (zero is allowed despite
70
- * the class name — pattern preserved for symmetry with `blueBorrow`).
71
- * @throws Reallocation errors from `buildReallocationActions` when `reallocations` is malformed
72
- * (see its JSDoc: `NegativeReallocationFeeError`, `EmptyReallocationWithdrawalsError`,
73
- * `NonPositiveReallocationAmountError`, `ReallocationWithdrawalOnTargetMarketError`,
74
- * `UnsortedReallocationWithdrawalsError`).
72
+ * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
73
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
74
+ * the target market.
75
+ * @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
76
+ * sorted by market id.
75
77
  * @example
76
78
  * ```ts
77
79
  * import { blueWithdraw } from "@morpho-org/morpho-sdk";