@morpho-org/morpho-sdk 5.2.0 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +99 -80
  97. package/lib/cjs/entities/index.d.ts +1 -0
  98. package/lib/cjs/entities/index.js +15 -0
  99. package/lib/cjs/entities/midnight/index.d.ts +2 -0
  100. package/lib/cjs/entities/midnight/index.js +18 -0
  101. package/lib/cjs/entities/midnight/midnight.d.ts +402 -0
  102. package/lib/cjs/entities/midnight/midnight.js +1036 -0
  103. package/lib/cjs/entities/midnight/types.d.ts +164 -0
  104. package/lib/cjs/entities/midnight/types.js +2 -0
  105. package/lib/cjs/entities/vaultV1/vaultV1.js +10 -17
  106. package/lib/cjs/entities/vaultV2/vaultV2.js +19 -21
  107. package/lib/cjs/errors.d.ts +1 -0
  108. package/lib/cjs/errors.js +17 -1
  109. package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
  110. package/lib/cjs/helpers/encodeDeallocation.js +2 -1
  111. package/lib/cjs/helpers/index.d.ts +4 -1
  112. package/lib/cjs/helpers/index.js +8 -1
  113. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +34 -0
  114. package/lib/cjs/helpers/signAndVerifyTypedData.js +58 -0
  115. package/lib/cjs/helpers/validate.d.ts +40 -1
  116. package/lib/cjs/helpers/validate.js +47 -5
  117. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
  118. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +32 -0
  119. package/lib/cjs/helpers/validateMidnightMarket.d.ts +10 -0
  120. package/lib/cjs/helpers/validateMidnightMarket.js +24 -0
  121. package/lib/cjs/helpers/validateOfferSides.d.ts +21 -0
  122. package/lib/cjs/helpers/validateOfferSides.js +36 -0
  123. package/lib/cjs/helpers/validateRequirementSpender.d.ts +29 -0
  124. package/lib/cjs/helpers/validateRequirementSpender.js +49 -0
  125. package/lib/cjs/helpers/validateTakeableOffers.d.ts +18 -0
  126. package/lib/cjs/helpers/validateTakeableOffers.js +35 -0
  127. package/lib/cjs/midnight-api.d.ts +1 -0
  128. package/lib/cjs/midnight-api.js +17 -0
  129. package/lib/cjs/types/action.d.ts +189 -23
  130. package/lib/cjs/types/action.js +27 -7
  131. package/lib/cjs/types/client.d.ts +3 -2
  132. package/lib/cjs/types/error.d.ts +288 -119
  133. package/lib/cjs/types/error.js +259 -180
  134. package/lib/cjs/utils.d.ts +1 -0
  135. package/lib/cjs/utils.js +12 -2
  136. package/lib/esm/abis.d.ts +1 -0
  137. package/lib/esm/abis.js +1 -0
  138. package/lib/esm/actions/blue/borrow.d.ts +3 -7
  139. package/lib/esm/actions/blue/borrow.js +6 -10
  140. package/lib/esm/actions/blue/buildReallocationActions.d.ts +3 -4
  141. package/lib/esm/actions/blue/buildReallocationActions.js +3 -4
  142. package/lib/esm/actions/blue/refinance.d.ts +4 -8
  143. package/lib/esm/actions/blue/refinance.js +11 -15
  144. package/lib/esm/actions/blue/repay.d.ts +2 -5
  145. package/lib/esm/actions/blue/repay.js +2 -5
  146. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -6
  147. package/lib/esm/actions/blue/repayWithdrawCollateral.js +5 -8
  148. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +2 -5
  149. package/lib/esm/actions/blue/resolveRepayFunding.js +16 -13
  150. package/lib/esm/actions/blue/supply.d.ts +2 -4
  151. package/lib/esm/actions/blue/supply.js +7 -9
  152. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -3
  153. package/lib/esm/actions/blue/supplyCollateral.js +6 -7
  154. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -9
  155. package/lib/esm/actions/blue/supplyCollateralBorrow.js +10 -15
  156. package/lib/esm/actions/blue/withdraw.d.ts +9 -7
  157. package/lib/esm/actions/blue/withdraw.js +19 -11
  158. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
  159. package/lib/esm/actions/blue/withdrawCollateral.js +3 -3
  160. package/lib/esm/actions/index.d.ts +2 -0
  161. package/lib/esm/actions/index.js +1 -0
  162. package/lib/esm/actions/midnight/authorization.d.ts +37 -0
  163. package/lib/esm/actions/midnight/authorization.js +65 -0
  164. package/lib/esm/actions/midnight/cancelOffer.d.ts +38 -0
  165. package/lib/esm/actions/midnight/cancelOffer.js +69 -0
  166. package/lib/esm/actions/midnight/index.d.ts +11 -0
  167. package/lib/esm/actions/midnight/index.js +11 -0
  168. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
  169. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +68 -0
  170. package/lib/esm/actions/midnight/redeem.d.ts +43 -0
  171. package/lib/esm/actions/midnight/redeem.js +75 -0
  172. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
  173. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +117 -0
  174. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
  175. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +55 -0
  176. package/lib/esm/actions/midnight/supplyCollateral.d.ts +45 -0
  177. package/lib/esm/actions/midnight/supplyCollateral.js +79 -0
  178. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
  179. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +124 -0
  180. package/lib/esm/actions/midnight/takeBorrow.d.ts +57 -0
  181. package/lib/esm/actions/midnight/takeBorrow.js +106 -0
  182. package/lib/esm/actions/midnight/takeLend.d.ts +57 -0
  183. package/lib/esm/actions/midnight/takeLend.js +106 -0
  184. package/lib/esm/actions/midnight/types.d.ts +39 -0
  185. package/lib/esm/actions/midnight/types.js +12 -0
  186. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
  187. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +6 -17
  188. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
  189. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +12 -16
  190. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
  191. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +12 -29
  192. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
  193. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
  194. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  195. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +10 -4
  196. package/lib/esm/actions/requirements/getRequirementsApproval.js +10 -4
  197. package/lib/esm/actions/requirements/index.d.ts +1 -0
  198. package/lib/esm/actions/requirements/index.js +1 -0
  199. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
  200. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +72 -0
  201. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
  202. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +74 -0
  203. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
  204. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +66 -0
  205. package/lib/esm/actions/requirements/midnight/index.d.ts +3 -0
  206. package/lib/esm/actions/requirements/midnight/index.js +3 -0
  207. package/lib/esm/actions/vaultV1/deposit.d.ts +3 -4
  208. package/lib/esm/actions/vaultV1/deposit.js +8 -9
  209. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -3
  210. package/lib/esm/actions/vaultV1/migrateToV2.js +6 -7
  211. package/lib/esm/actions/vaultV1/redeem.d.ts +1 -1
  212. package/lib/esm/actions/vaultV1/redeem.js +3 -3
  213. package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
  214. package/lib/esm/actions/vaultV1/withdraw.js +3 -3
  215. package/lib/esm/actions/vaultV2/deposit.d.ts +3 -4
  216. package/lib/esm/actions/vaultV2/deposit.js +8 -9
  217. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -3
  218. package/lib/esm/actions/vaultV2/forceRedeem.js +4 -5
  219. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  220. package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
  221. package/lib/esm/actions/vaultV2/redeem.d.ts +1 -1
  222. package/lib/esm/actions/vaultV2/redeem.js +3 -3
  223. package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
  224. package/lib/esm/actions/vaultV2/withdraw.js +3 -3
  225. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  226. package/lib/esm/client/morphoViemExtension.js +6 -3
  227. package/lib/esm/constants.d.ts +1 -0
  228. package/lib/esm/constants.js +1 -0
  229. package/lib/esm/entities/blue/blue.d.ts +5 -5
  230. package/lib/esm/entities/blue/blue.js +101 -82
  231. package/lib/esm/entities/index.d.ts +1 -0
  232. package/lib/esm/entities/index.js +1 -0
  233. package/lib/esm/entities/midnight/index.d.ts +2 -0
  234. package/lib/esm/entities/midnight/index.js +2 -0
  235. package/lib/esm/entities/midnight/midnight.d.ts +402 -0
  236. package/lib/esm/entities/midnight/midnight.js +1032 -0
  237. package/lib/esm/entities/midnight/types.d.ts +164 -0
  238. package/lib/esm/entities/midnight/types.js +1 -0
  239. package/lib/esm/entities/vaultV1/vaultV1.js +13 -20
  240. package/lib/esm/entities/vaultV2/vaultV2.js +9 -11
  241. package/lib/esm/errors.d.ts +1 -0
  242. package/lib/esm/errors.js +1 -0
  243. package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
  244. package/lib/esm/helpers/encodeDeallocation.js +3 -2
  245. package/lib/esm/helpers/index.d.ts +4 -1
  246. package/lib/esm/helpers/index.js +4 -1
  247. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +34 -0
  248. package/lib/esm/helpers/signAndVerifyTypedData.js +54 -0
  249. package/lib/esm/helpers/validate.d.ts +40 -1
  250. package/lib/esm/helpers/validate.js +46 -5
  251. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
  252. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +28 -0
  253. package/lib/esm/helpers/validateMidnightMarket.d.ts +10 -0
  254. package/lib/esm/helpers/validateMidnightMarket.js +20 -0
  255. package/lib/esm/helpers/validateOfferSides.d.ts +21 -0
  256. package/lib/esm/helpers/validateOfferSides.js +32 -0
  257. package/lib/esm/helpers/validateRequirementSpender.d.ts +29 -0
  258. package/lib/esm/helpers/validateRequirementSpender.js +45 -0
  259. package/lib/esm/helpers/validateTakeableOffers.d.ts +18 -0
  260. package/lib/esm/helpers/validateTakeableOffers.js +31 -0
  261. package/lib/esm/midnight-api.d.ts +1 -0
  262. package/lib/esm/midnight-api.js +1 -0
  263. package/lib/esm/types/action.d.ts +189 -23
  264. package/lib/esm/types/action.js +26 -7
  265. package/lib/esm/types/client.d.ts +3 -2
  266. package/lib/esm/types/error.d.ts +288 -119
  267. package/lib/esm/types/error.js +232 -154
  268. package/lib/esm/utils.d.ts +1 -0
  269. package/lib/esm/utils.js +1 -0
  270. package/package.json +11 -2
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  > **The abstraction layer that simplifies Morpho protocol**
11
11
 
12
- Build transactions for **VaultV1** (MetaMorpho), **VaultV2**, and **Blue** (Morpho Blue) on EVM-compatible chains.
12
+ Build transactions for **VaultV1** (MetaMorpho), **VaultV2**, **Blue** (Morpho Blue), and **Midnight** fixed-rate markets on EVM-compatible chains.
13
13
 
14
14
  ## Installation
15
15
 
@@ -40,12 +40,17 @@ pnpm add @morpho-org/morpho-sdk
40
40
  | | `withdrawCollateral` | Direct Morpho call | No bundler overhead. Validates position health after withdrawal. |
41
41
  | | `repayWithdrawCollateral` | Bundler (general adapter) | Atomic repay + withdraw. Bundle order matters: repay first, then withdraw. |
42
42
  | | `refinance` | Bundler (general adapter) | Atomic position migration to another market with the same loan + collateral tokens. Flash-collateral via the target's `onMorphoSupplyCollateral` callback: borrow target → repay source → withdraw source collateral. Requires GA1 auth. Supports target reallocations. |
43
+ | **Midnight** | `takeLend` / `takeBorrow` | MidnightBundles | Takes fixed-rate offers with ordered approval and authorization requirements. |
44
+ | | `supplyCollateralTakeBorrow` | MidnightBundles | Atomically supplies collateral and takes fixed-rate borrow liquidity. |
45
+ | | `makeLend` / `makeBorrow` | Midnight mempool | Builds, validates, signs or ratifies, and submits maker offer trees. |
46
+ | | `supplyCollateral` / `redeem` / `cancelOffer` | Direct Midnight call | Encodes direct collateral, credit, and offer-management operations. |
47
+ | | `repayWithdrawCollateral` | MidnightBundles | Atomically repays credit and withdraws collateral. |
43
48
 
44
49
  ### The `getRequirements` flow
45
50
 
46
51
  Every action that touches a user's tokens or positions returns two things:
47
52
 
48
- - `buildTx(signatures?)` — builds the final viem `Transaction` object. Takes an optional array of collected `RequirementSignature`s (permit / Permit2 and/or Morpho authorization).
53
+ - `buildTx(signatures?)` — builds the final viem `Transaction` object. Takes the collected signature results required by the flow, including permit / Permit2, Morpho authorization, or a Midnight offer-root signature.
49
54
  - `getRequirements()` — returns the list of on-chain pre-requisites that must be satisfied first.
50
55
 
51
56
  Typical requirements:
@@ -53,6 +58,7 @@ Typical requirements:
53
58
  - **ERC-20 approval** — the user must approve the bundler (or Morpho directly) to pull tokens. Returned as a standard `approve` transaction the consumer sends first.
54
59
  - **Permit / Permit2 signature** — off-chain approvals that go into `buildTx` in the `signatures` array, avoiding the extra approval tx. Enabled via `morphoViemExtension({ supportSignature: true })`.
55
60
  - **Morpho authorization** — `borrow`, `supplyCollateralBorrow`, and `repayWithdrawCollateral` require the user to authorize `GeneralAdapter1` on the Morpho contract once (`setAuthorization`). The SDK returns this as an extra transaction if it's missing.
61
+ - **Midnight authorization or ratification** — Midnight flows return the required operator authorization, Ecrecover offer-root signature, or SetterRatifier transaction before the final take or mempool submission.
56
62
 
57
63
  Usage pattern:
58
64
 
@@ -90,6 +96,10 @@ const tx = buildTx([permitSignature]);
90
96
  | | `supplyCollateralBorrow` | Bundler (general adapter) | Atomic supply + borrow. LLTV buffer prevents instant liquidation. Supports reallocations. |
91
97
  | | `withdraw` | Bundler (general adapter) | `morphoWithdraw` with `minSharePrice` slippage protection. Requires GA1 auth. Supports reallocations. |
92
98
  | | `refinance` | Bundler (general adapter) | Atomic position migration to another market sharing the same loan + collateral tokens. Requires GA1 auth. Supports reallocations. |
99
+ | **Midnight** | `takeLend` / `takeBorrow` | MidnightBundles | Takes fixed-rate offers with ordered approval and authorization requirements. |
100
+ | | `makeLend` / `makeBorrow` | Midnight mempool | Builds and submits validated maker offer trees. |
101
+ | | `supplyCollateral` / `redeem` / `cancelOffer` | Direct Midnight call | Encodes direct Midnight operations. |
102
+ | | `repayWithdrawCollateral` | MidnightBundles | Atomically repays credit and withdraws collateral. |
93
103
 
94
104
  ### VaultV2
95
105
 
@@ -513,6 +523,28 @@ const { buildTx, getRequirements } = market.supplyCollateralBorrow({
513
523
  });
514
524
  ```
515
525
 
526
+ ### Midnight
527
+
528
+ Midnight exposes fixed-rate market flows through a chain-scoped entity. Fetch market or
529
+ position state when required, resolve the ordered prerequisites, then build the final
530
+ transaction synchronously.
531
+
532
+ ```typescript
533
+ const midnight = client.morpho.midnight(8453);
534
+ const marketData = await midnight.getMarketData(marketId);
535
+ const output = midnight.takeLend({
536
+ accountAddress: lender,
537
+ marketData,
538
+ assets: 1_000_000n,
539
+ minUnits: 900_000n,
540
+ takeableOffers: quote.data.takeableOffers,
541
+ deadline,
542
+ });
543
+
544
+ const requirements = await output.getRequirements();
545
+ const tx = output.buildTx();
546
+ ```
547
+
516
548
  ### Architecture
517
549
 
518
550
  ```mermaid
@@ -522,6 +554,7 @@ graph LR
522
554
  MC -->|.vaultV1| MV1
523
555
  MC -->|.vaultV2| MV2
524
556
  MC -->|.blue| MM1
557
+ MC -->|.midnight| MN1
525
558
 
526
559
  subgraph VaultV1 Flow
527
560
  MV1[MorphoVaultV1]
@@ -570,6 +603,16 @@ graph LR
570
603
  B3 -.->|reallocateTo| PA[PublicAllocator]
571
604
  end
572
605
 
606
+ subgraph Midnight Flow
607
+ MN1[MorphoMidnight]
608
+ MN1 --> MNT[fixed-rate taker actions]
609
+ MN1 --> MNM[maker offer submission]
610
+ MN1 --> MNP[position actions]
611
+ MNT --> MNB[MidnightBundles]
612
+ MNM --> MNMP[Midnight mempool]
613
+ MNP --> MNC[Midnight / MidnightBundles]
614
+ end
615
+
573
616
 
574
617
  subgraph Shared
575
618
  REQ[getRequirements]
@@ -578,6 +621,7 @@ graph LR
578
621
  MV1 -.->|approval / permit| REQ
579
622
  MV2 -.->|approval / permit| REQ
580
623
  MM1 -.->|approval / permit / authorization| REQ
624
+ MN1 -.->|approval / authorization / root signature or ratification| REQ
581
625
 
582
626
  style B1 fill:#e8f5e9,stroke:#4caf50
583
627
  style B2 fill:#e8f5e9,stroke:#4caf50
package/lib/cjs/abis.d.ts 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 declare const bundler3Abi: readonly [{
5
6
  readonly type: "function";
package/lib/cjs/abis.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compoundV3MigrationAdapterAbi = exports.compoundV2MigrationAdapterAbi = exports.aaveV3OptimizerMigrationAdapterAbi = exports.aaveV3MigrationAdapterAbi = exports.aaveV2MigrationAdapterAbi = exports.erc20WrapperAdapterAbi = exports.paraswapAdapterAbi = exports.ethereumGeneralAdapter1Abi = exports.generalAdapter1Abi = exports.coreAdapterAbi = exports.bundler3Abi = exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2Abi = exports.vaultV1AdapterFactoryAbi = exports.vaultV1AdapterAbi = exports.publicAllocatorAbi = exports.preLiquidationFactoryAbi = exports.preLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.adaptiveCurveIrmAbi = exports.marketParamsAbi = void 0;
3
+ exports.compoundV3MigrationAdapterAbi = exports.compoundV2MigrationAdapterAbi = exports.aaveV3OptimizerMigrationAdapterAbi = exports.aaveV3MigrationAdapterAbi = exports.aaveV2MigrationAdapterAbi = exports.erc20WrapperAdapterAbi = exports.paraswapAdapterAbi = exports.ethereumGeneralAdapter1Abi = exports.generalAdapter1Abi = exports.coreAdapterAbi = exports.bundler3Abi = exports.setterRatifierAbi = exports.midnightBundlesAbi = exports.midnightAbi = exports.ecrecoverRatifierAbi = exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2Abi = exports.vaultV1AdapterFactoryAbi = exports.vaultV1AdapterAbi = exports.publicAllocatorAbi = exports.preLiquidationFactoryAbi = exports.preLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.adaptiveCurveIrmAbi = exports.marketParamsAbi = void 0;
4
4
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  Object.defineProperty(exports, "marketParamsAbi", { enumerable: true, get: function () { return blue_sdk_1.marketParamsAbi; } });
6
6
  var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
@@ -29,6 +29,11 @@ Object.defineProperty(exports, "vaultV2FactoryAbi", { enumerable: true, get: fun
29
29
  Object.defineProperty(exports, "whitelistControllerAggregatorV2Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.whitelistControllerAggregatorV2Abi; } });
30
30
  Object.defineProperty(exports, "wrappedBackedTokenAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wrappedBackedTokenAbi; } });
31
31
  Object.defineProperty(exports, "wstEthAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wstEthAbi; } });
32
+ var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
33
+ Object.defineProperty(exports, "ecrecoverRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverRatifierAbi; } });
34
+ Object.defineProperty(exports, "midnightAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightAbi; } });
35
+ Object.defineProperty(exports, "midnightBundlesAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightBundlesAbi; } });
36
+ Object.defineProperty(exports, "setterRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.setterRatifierAbi; } });
32
37
  /** ABI for the Bundler3 multicall contract. */
33
38
  exports.bundler3Abi = [
34
39
  {
@@ -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
@@ -30,15 +30,11 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
30
30
  * @param params.metadata - Optional analytics metadata attached to the bundle.
31
31
  * @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
32
32
  * typed `action` discriminator the simulation layer consumes.
33
- * @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
34
- * @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
35
- * allowed despite the class name).
36
- * @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
37
- * `reallocations` is non-empty and any `reallocation.fee < 0n`.
33
+ * @throws {NonPositiveInputError} when `amount <= 0n` or any reallocation withdrawal amount
34
+ * is non-positive.
35
+ * @throws {NegativeInputError} when `minSharePrice < 0n` or any reallocation fee is negative.
38
36
  * @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
39
37
  * `reallocation.withdrawals` is empty.
40
- * @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
41
- * `reallocation.withdrawals[i].amount <= 0n`.
42
38
  * @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
43
39
  * reallocation withdrawal references the target market.
44
40
  * @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
@@ -60,10 +56,10 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
60
56
  */
61
57
  const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
62
58
  if (amount <= 0n) {
63
- throw new index_js_3.NonPositiveBorrowAmountError(marketParams.id);
59
+ throw new index_js_3.NonPositiveInputError("amount", amount);
64
60
  }
65
61
  if (minSharePrice < 0n) {
66
- throw new index_js_3.NonPositiveMinBorrowSharePriceError(marketParams.id);
62
+ throw new index_js_3.NegativeInputError("minSharePrice", minSharePrice);
67
63
  }
68
64
  const actions = [];
69
65
  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.
@@ -8,15 +8,14 @@ const index_js_1 = require("../../helpers/index.js");
8
8
  * Validates the reallocations, then encodes each as a `reallocateTo` action against the target
9
9
  * market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
10
10
  * `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
11
- * consumed only by `blueBorrow` and `blueSupplyCollateralBorrow`; not re-exported on the
12
- * public surface.
11
+ * consumed by the Blue actions that accept reallocations; not re-exported on the public surface.
13
12
  *
14
13
  * @param reallocations - The vault reallocations to encode.
15
14
  * @param targetMarketParams - The target market params the freed liquidity is destined for.
16
15
  * @returns The encoded `reallocateTo` actions and the summed reallocation fee in native tokens.
17
- * @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
16
+ * @throws {NegativeInputError} when any reallocation fee is negative.
18
17
  * @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
19
- * @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
18
+ * @throws {NonPositiveInputError} when any withdrawal amount is non-positive.
20
19
  * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
21
20
  * @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
22
21
  * 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
@@ -62,18 +62,14 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
62
62
  * @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
63
63
  * @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
64
64
  * repay); in shares mode the entity passes both. Caller-facing mutual exclusivity is enforced at the entity layer.
65
- * @throws {ZeroCollateralAmountError} when `collateralAmount <= 0n`.
66
- * @throws {NonPositiveAssetAmountError} when `borrowAssets < 0n`.
67
- * @throws {NegativeBorrowSharesError} when `borrowShares < 0n`.
68
- * @throws {NonPositiveMinBorrowSharePriceError} when `minBorrowSharePrice < 0n`.
69
- * @throws {NegativeMaxRepaySharePriceError} when `maxRepaySharePrice < 0n`.
65
+ * @throws {NonPositiveInputError} when `collateralAmount <= 0n`, a repay leg has a non-positive
66
+ * `maxRepaySharePrice`, or any reallocation withdrawal amount is non-positive.
67
+ * @throws {NegativeInputError} when `borrowAssets`, `borrowShares`, `minBorrowSharePrice`,
68
+ * `maxRepaySharePrice`, or any reallocation fee is negative.
70
69
  * @throws {RefinanceSameMarketError} when source and target market ids are equal.
71
70
  * @throws {RefinanceTokenMismatchError} when source and target do not share both tokens.
72
71
  * @throws {RefinanceSharesMissingBorrowAssetsError} when `borrowShares > 0n` but `borrowAssets` is omitted or non-positive.
73
- * @throws {NonPositiveRepayMaxSharePriceError} when a repay leg is encoded and `maxRepaySharePrice <= 0n`.
74
- * @throws {NegativeReallocationFeeError} when any `reallocation.fee < 0n`.
75
72
  * @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
76
- * @throws {NonPositiveReallocationAmountError} when any `reallocation.withdrawals[i].amount <= 0n`.
77
73
  * @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references the target market.
78
74
  * @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly sorted by market id.
79
75
  * @example
@@ -97,19 +93,19 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
97
93
  */
98
94
  const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }) => {
99
95
  if (collateralAmount <= 0n) {
100
- throw new index_js_3.ZeroCollateralAmountError(sourceParams.id);
96
+ throw new index_js_3.NonPositiveInputError("collateralAmount", collateralAmount);
101
97
  }
102
98
  if (borrowAssets < 0n) {
103
- throw new index_js_3.NonPositiveAssetAmountError(sourceParams.loanToken);
99
+ throw new index_js_3.NegativeInputError("borrowAssets", borrowAssets);
104
100
  }
105
101
  if (borrowShares < 0n) {
106
- throw new index_js_3.NegativeBorrowSharesError(sourceParams.id);
102
+ throw new index_js_3.NegativeInputError("borrowShares", borrowShares);
107
103
  }
108
104
  if (minBorrowSharePrice < 0n) {
109
- throw new index_js_3.NonPositiveMinBorrowSharePriceError(targetParams.id);
105
+ throw new index_js_3.NegativeInputError("minBorrowSharePrice", minBorrowSharePrice);
110
106
  }
111
107
  if (maxRepaySharePrice < 0n) {
112
- throw new index_js_3.NegativeMaxRepaySharePriceError(sourceParams.id);
108
+ throw new index_js_3.NegativeInputError("maxRepaySharePrice", maxRepaySharePrice);
113
109
  }
114
110
  if (sourceParams.id === targetParams.id) {
115
111
  throw new index_js_3.RefinanceSameMarketError(sourceParams.id);
@@ -127,7 +123,7 @@ const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target
127
123
  }
128
124
  // A repay leg with maxRepaySharePrice = 0n always reverts; require a positive cap when debt is migrated.
129
125
  if (shouldMigrateBorrow && maxRepaySharePrice <= 0n) {
130
- throw new index_js_3.NonPositiveRepayMaxSharePriceError(sourceParams.id);
126
+ throw new index_js_3.NonPositiveInputError("maxRepaySharePrice", maxRepaySharePrice);
131
127
  }
132
128
  const callback = [];
133
129
  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.
@@ -42,14 +42,11 @@ const resolveRepayFunding_js_1 = require("./resolveRepayFunding.js");
42
42
  * @param params.metadata - Optional analytics metadata attached to the bundle.
43
43
  * @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value` (= `nativeAmount`),
44
44
  * `data`, and the typed `action` discriminator the simulation layer consumes.
45
- * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
46
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
45
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or the total funding is zero.
46
+ * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
47
47
  * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
48
48
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
49
49
  * `transferAmount !== amount + nativeAmount`.
50
- * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
51
- * and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
52
- * funding (`transferAmount + nativeAmount`) is `<= 0n`.
53
50
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
54
51
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
55
52
  * 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.
@@ -57,15 +57,12 @@ const resolveRepayFunding_js_1 = require("./resolveRepayFunding.js");
57
57
  * @param params.metadata - Optional analytics metadata attached to the bundle.
58
58
  * @returns A deep-frozen `Transaction<BlueRepayWithdrawCollateralAction>` with `to`,
59
59
  * `value` (= `nativeAmount`), `data`, and the typed `action` discriminator the simulation layer consumes.
60
- * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
61
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
60
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n`, the total funding is zero, or
61
+ * `withdrawAmount <= 0n`.
62
+ * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
62
63
  * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
63
64
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
64
65
  * `transferAmount !== amount + nativeAmount`.
65
- * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
66
- * and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
67
- * funding (`transferAmount + nativeAmount`) is `<= 0n`.
68
- * @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
69
66
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
70
67
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
71
68
  * the chain's wNative.
@@ -98,7 +95,7 @@ const blueRepayWithdrawCollateral = ({ market: { chainId, marketParams }, args,
98
95
  const { amount = 0n, shares = 0n, nativeAmount = 0n, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, authorizationSignature, } = args;
99
96
  const { isSharesMode, repayAssets, repayShares, erc20Amount } = (0, resolveRepayFunding_js_1.resolveRepayFunding)({ amount, shares, nativeAmount, transferAmount, maxSharePrice }, marketParams.id);
100
97
  if (withdrawAmount <= 0n) {
101
- throw new index_js_3.NonPositiveWithdrawCollateralAmountError(marketParams.id);
98
+ throw new index_js_3.NonPositiveInputError("withdrawAmount", withdrawAmount);
102
99
  }
103
100
  const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
104
101
  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`.
@@ -24,11 +24,8 @@ const index_js_1 = require("../../types/index.js");
24
24
  * @param marketId - Market id used to tag the thrown errors.
25
25
  * @returns `{ isSharesMode, repayAssets, repayShares, erc20Amount }` — the mode discriminator and the
26
26
  * amounts the repay builders assemble the bundle from.
27
- * @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
28
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
29
- * @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode and
30
- * the repaid assets are `<= 0n`, or when in shares mode and `transferAmount` is negative or the total
31
- * funding (`transferAmount + nativeAmount`) is `<= 0n`.
27
+ * @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or total repay funding is zero.
28
+ * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
32
29
  * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
33
30
  * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
34
31
  * `transferAmount !== amount + nativeAmount`.
@@ -36,13 +33,16 @@ const index_js_1 = require("../../types/index.js");
36
33
  */
37
34
  const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmount, maxSharePrice, }, marketId) => {
38
35
  if (maxSharePrice <= 0n) {
39
- throw new index_js_1.NonPositiveRepayMaxSharePriceError(marketId);
36
+ throw new index_js_1.NonPositiveInputError("maxSharePrice", maxSharePrice);
40
37
  }
41
38
  if (nativeAmount < 0n) {
42
- throw new index_js_1.NegativeNativeAmountError(nativeAmount);
39
+ throw new index_js_1.NegativeInputError("nativeAmount", nativeAmount);
43
40
  }
44
- if (amount < 0n || shares < 0n) {
45
- throw new index_js_1.NonPositiveRepayAmountError(marketId);
41
+ if (amount < 0n) {
42
+ throw new index_js_1.NegativeInputError("amount", amount);
43
+ }
44
+ if (shares < 0n) {
45
+ throw new index_js_1.NegativeInputError("shares", shares);
46
46
  }
47
47
  if (amount > 0n && shares > 0n) {
48
48
  throw new index_js_1.MutuallyExclusiveRepayAmountsError(marketId);
@@ -61,8 +61,11 @@ const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmount, max
61
61
  // ERC-20 (0 on a fully-native repay) and wraps `nativeAmount`; the bundle must
62
62
  // fund the repay with a non-negative transfer and a positive total.
63
63
  if (isSharesMode) {
64
- if (transferAmount < 0n || transferAmount + nativeAmount <= 0n) {
65
- throw new index_js_1.NonPositiveRepayAmountError(marketId);
64
+ if (transferAmount < 0n) {
65
+ throw new index_js_1.NegativeInputError("transferAmount", transferAmount);
66
+ }
67
+ if (transferAmount + nativeAmount <= 0n) {
68
+ throw new index_js_1.NonPositiveInputError("transferAmount + nativeAmount", transferAmount + nativeAmount);
66
69
  }
67
70
  }
68
71
  else {
@@ -74,7 +77,7 @@ const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmount, max
74
77
  });
75
78
  }
76
79
  if (repayAssets <= 0n) {
77
- throw new index_js_1.NonPositiveRepayAmountError(marketId);
80
+ throw new index_js_1.NonPositiveInputError("amount + nativeAmount", repayAssets);
78
81
  }
79
82
  }
80
83
  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.
@@ -29,10 +29,8 @@ const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
29
29
  * @param params.metadata - Optional analytics metadata attached to the bundle.
30
30
  * @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
31
31
  * typed `action` discriminator the simulation layer consumes.
32
- * @throws {NegativeSupplyAmountError} when `amount < 0n`.
33
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
34
- * @throws {ZeroSupplyAmountError} when both `amount` and `nativeAmount` resolve to zero.
35
- * @throws {NegativeSupplyMaxSharePriceError} when `maxSharePrice < 0n`.
32
+ * @throws {NegativeInputError} when `amount`, `nativeAmount`, or `maxSharePrice` is negative.
33
+ * @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
36
34
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
37
35
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
38
36
  * the chain's wNative.
@@ -57,17 +55,17 @@ const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
57
55
  */
58
56
  const blueSupply = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, maxSharePrice, requirementSignature, nativeAmount, }, metadata, }) => {
59
57
  if (amount < 0n) {
60
- throw new index_js_3.NegativeSupplyAmountError(marketParams.id);
58
+ throw new index_js_3.NegativeInputError("amount", amount);
61
59
  }
62
60
  if (nativeAmount !== undefined && nativeAmount < 0n) {
63
- throw new index_js_3.NegativeNativeAmountError(nativeAmount);
61
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
64
62
  }
65
63
  if (maxSharePrice < 0n) {
66
- throw new index_js_3.NegativeSupplyMaxSharePriceError(marketParams.id);
64
+ throw new index_js_3.NegativeInputError("maxSharePrice", maxSharePrice);
67
65
  }
68
66
  const totalAssets = amount + (nativeAmount ?? 0n);
69
67
  if (totalAssets === 0n) {
70
- throw new index_js_3.ZeroSupplyAmountError(marketParams.id);
68
+ throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
71
69
  }
72
70
  const actions = (0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
73
71
  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.
@@ -26,9 +26,8 @@ const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
26
26
  * @param params.metadata - Optional analytics metadata attached to the bundle.
27
27
  * @returns A deep-frozen `Transaction<BlueSupplyCollateralAction>` with `to`, `value`, `data`,
28
28
  * and the typed `action` discriminator the simulation layer consumes.
29
- * @throws {NonPositiveAssetAmountError} when `amount < 0n`.
30
- * @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
31
- * @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
29
+ * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
30
+ * @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
32
31
  * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
33
32
  * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
34
33
  * token is not the chain's wNative.
@@ -51,14 +50,14 @@ const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
51
50
  */
52
51
  const blueSupplyCollateral = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, requirementSignature, nativeAmount }, metadata, }) => {
53
52
  if (amount < 0n) {
54
- throw new index_js_3.NonPositiveAssetAmountError(marketParams.collateralToken);
53
+ throw new index_js_3.NegativeInputError("amount", amount);
55
54
  }
56
55
  if (nativeAmount !== undefined && nativeAmount < 0n) {
57
- throw new index_js_3.NegativeNativeAmountError(nativeAmount);
56
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
58
57
  }
59
58
  const totalCollateral = amount + (nativeAmount ?? 0n);
60
59
  if (totalCollateral === 0n) {
61
- throw new index_js_3.ZeroCollateralAmountError(marketParams.id);
60
+ throw new index_js_3.NonPositiveInputError("totalCollateral", totalCollateral);
62
61
  }
63
62
  const actions = (0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
64
63
  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