@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
@@ -38,14 +38,14 @@ class MorphoBlue {
38
38
  supply({ amount = 0n, userAddress, nativeAmount, marketData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, }) {
39
39
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
40
40
  if (amount < 0n) {
41
- throw new index_js_3.NegativeSupplyAmountError(this.marketParams.id);
41
+ throw new index_js_3.NegativeInputError("amount", amount);
42
42
  }
43
43
  if (nativeAmount !== undefined && nativeAmount < 0n) {
44
- throw new index_js_3.NegativeNativeAmountError(nativeAmount);
44
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
45
45
  }
46
46
  const totalAssets = amount + (nativeAmount ?? 0n);
47
47
  if (totalAssets === 0n) {
48
- throw new index_js_3.ZeroSupplyAmountError(this.marketParams.id);
48
+ throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
49
49
  }
50
50
  if (marketData.id !== this.marketParams.id) {
51
51
  throw new index_js_3.MarketIdMismatchError(marketData.id, this.marketParams.id);
@@ -100,10 +100,19 @@ class MorphoBlue {
100
100
  if (assets !== 0n && shares !== 0n) {
101
101
  throw new index_js_3.MutuallyExclusiveWithdrawAmountsError(this.marketParams.id);
102
102
  }
103
- if (assets < 0n || shares < 0n || (assets === 0n && shares === 0n)) {
104
- throw new index_js_3.NonPositiveWithdrawAmountError(this.marketParams.id);
103
+ if (assets < 0n) {
104
+ throw new index_js_3.NegativeInputError("assets", assets);
105
+ }
106
+ if (shares < 0n) {
107
+ throw new index_js_3.NegativeInputError("shares", shares);
108
+ }
109
+ if (assets === 0n && shares === 0n) {
110
+ throw new index_js_3.NonPositiveInputError("assets or shares", 0n);
105
111
  }
106
112
  (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
113
+ if (reallocations) {
114
+ (0, index_js_2.validateReallocations)(reallocations, this.marketParams.id);
115
+ }
107
116
  if (!positionData) {
108
117
  throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
109
118
  }
@@ -164,14 +173,14 @@ class MorphoBlue {
164
173
  supplyCollateral({ amount = 0n, userAddress, nativeAmount, }) {
165
174
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
166
175
  if (amount < 0n) {
167
- throw new index_js_3.NonPositiveAssetAmountError(this.marketParams.collateralToken);
176
+ throw new index_js_3.NegativeInputError("amount", amount);
168
177
  }
169
178
  if (nativeAmount !== undefined && nativeAmount < 0n) {
170
- throw new index_js_3.NegativeNativeAmountError(nativeAmount);
179
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
171
180
  }
172
181
  const totalCollateral = amount + (nativeAmount ?? 0n);
173
182
  if (totalCollateral === 0n) {
174
- throw new index_js_3.ZeroCollateralAmountError(this.marketParams.id);
183
+ throw new index_js_3.NonPositiveInputError("totalCollateral", totalCollateral);
175
184
  }
176
185
  if (nativeAmount !== undefined && nativeAmount > 0n) {
177
186
  (0, index_js_2.validateNativeAsset)(this.chainId, this.marketParams.collateralToken);
@@ -208,9 +217,12 @@ class MorphoBlue {
208
217
  borrow({ amount, userAddress, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
209
218
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
210
219
  if (amount <= 0n) {
211
- throw new index_js_3.NonPositiveBorrowAmountError(this.marketParams.id);
220
+ throw new index_js_3.NonPositiveInputError("amount", amount);
212
221
  }
213
222
  (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
223
+ if (reallocations) {
224
+ (0, index_js_2.validateReallocations)(reallocations, this.marketParams.id);
225
+ }
214
226
  if (!positionData) {
215
227
  throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
216
228
  }
@@ -265,12 +277,30 @@ class MorphoBlue {
265
277
  repay(params) {
266
278
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
267
279
  const { userAddress, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = params;
268
- if ("amount" in params && "shares" in params) {
269
- throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
270
- }
271
280
  const nativeAmount = params.nativeAmount ?? 0n;
272
281
  if (nativeAmount < 0n) {
273
- throw new index_js_3.NegativeNativeAmountError(nativeAmount);
282
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
283
+ }
284
+ const amount = ("amount" in params ? params.amount : undefined) ?? 0n;
285
+ const shares = ("shares" in params ? params.shares : undefined) ?? 0n;
286
+ if (amount < 0n) {
287
+ throw new index_js_3.NegativeInputError("amount", amount);
288
+ }
289
+ if (shares < 0n) {
290
+ throw new index_js_3.NegativeInputError("shares", shares);
291
+ }
292
+ if (amount > 0n && shares > 0n) {
293
+ throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
294
+ }
295
+ if ("shares" in params) {
296
+ if (shares === 0n) {
297
+ throw new index_js_3.NonPositiveInputError("shares", shares);
298
+ }
299
+ }
300
+ else {
301
+ if (amount + nativeAmount <= 0n) {
302
+ throw new index_js_3.NonPositiveInputError("amount + nativeAmount", amount + nativeAmount);
303
+ }
274
304
  }
275
305
  (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
276
306
  if (!positionData) {
@@ -287,12 +317,11 @@ class MorphoBlue {
287
317
  let repayAssets;
288
318
  let repayShares;
289
319
  let erc20Amount;
290
- let marketForRepay;
320
+ // Forward-accrue (2h) before deriving `maxSharePrice` (both modes): on-chain `morphoRepay` accrues `lastUpdate → execution`, so an un-accrued bound reverts on quiet markets.
321
+ const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
322
+ morpho_ts_1.Time.s.from.h(2n);
323
+ const marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
291
324
  if ("shares" in params) {
292
- const shares = params.shares;
293
- if (shares <= 0n) {
294
- throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
295
- }
296
325
  (0, index_js_2.validateRepayShares)({
297
326
  positionData,
298
327
  repayShares: shares,
@@ -300,11 +329,6 @@ class MorphoBlue {
300
329
  });
301
330
  repayAssets = 0n;
302
331
  repayShares = shares;
303
- // 2h forward accrual upper-bounds the on-chain repay price; bundle
304
- // skims residual back to the receiver.
305
- const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
306
- morpho_ts_1.Time.s.from.h(2n);
307
- marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
308
332
  const borrowAssets = marketForRepay.toBorrowAssets(shares, "Up");
309
333
  // Native funds the transfer first; the ERC-20 pulled is the remainder.
310
334
  // When native covers the full (2h-forward-accrued, rounded-up) borrow
@@ -315,17 +339,7 @@ class MorphoBlue {
315
339
  }
316
340
  else {
317
341
  // Assets mode is additive, like supply: repaid = amount + nativeAmount.
318
- const amount = params.amount ?? 0n;
319
- // Reject a negative ERC-20 amount before it can be masked by nativeAmount
320
- // in the sum below (a negative amount would otherwise yield a negative
321
- // erc20Amount and a negative approval in getRequirements).
322
- if (amount < 0n) {
323
- throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
324
- }
325
342
  repayAssets = amount + nativeAmount;
326
- if (repayAssets <= 0n) {
327
- throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
328
- }
329
343
  (0, index_js_2.validateRepayAmount)({
330
344
  positionData,
331
345
  repayAssets,
@@ -333,7 +347,6 @@ class MorphoBlue {
333
347
  });
334
348
  repayShares = 0n;
335
349
  erc20Amount = amount;
336
- marketForRepay = positionData.market;
337
350
  }
338
351
  const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
339
352
  repayAssets,
@@ -393,7 +406,7 @@ class MorphoBlue {
393
406
  withdrawCollateral({ userAddress, amount, positionData, }) {
394
407
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
395
408
  if (amount <= 0n) {
396
- throw new index_js_3.NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
409
+ throw new index_js_3.NonPositiveInputError("amount", amount);
397
410
  }
398
411
  if (!positionData) {
399
412
  throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
@@ -434,15 +447,33 @@ class MorphoBlue {
434
447
  repayWithdrawCollateral(params) {
435
448
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
436
449
  const { userAddress, withdrawAmount, positionData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = params;
437
- if ("amount" in params && "shares" in params) {
438
- throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
439
- }
440
450
  const nativeAmount = params.nativeAmount ?? 0n;
441
451
  if (nativeAmount < 0n) {
442
- throw new index_js_3.NegativeNativeAmountError(nativeAmount);
452
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
453
+ }
454
+ const amount = ("amount" in params ? params.amount : undefined) ?? 0n;
455
+ const shares = ("shares" in params ? params.shares : undefined) ?? 0n;
456
+ if (amount < 0n) {
457
+ throw new index_js_3.NegativeInputError("amount", amount);
458
+ }
459
+ if (shares < 0n) {
460
+ throw new index_js_3.NegativeInputError("shares", shares);
461
+ }
462
+ if (amount > 0n && shares > 0n) {
463
+ throw new index_js_3.MutuallyExclusiveRepayAmountsError(this.marketParams.id);
464
+ }
465
+ if ("shares" in params) {
466
+ if (shares === 0n) {
467
+ throw new index_js_3.NonPositiveInputError("shares", shares);
468
+ }
469
+ }
470
+ else {
471
+ if (amount + nativeAmount <= 0n) {
472
+ throw new index_js_3.NonPositiveInputError("amount + nativeAmount", amount + nativeAmount);
473
+ }
443
474
  }
444
475
  if (withdrawAmount <= 0n) {
445
- throw new index_js_3.NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
476
+ throw new index_js_3.NonPositiveInputError("withdrawAmount", withdrawAmount);
446
477
  }
447
478
  (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
448
479
  if (!positionData) {
@@ -459,16 +490,11 @@ class MorphoBlue {
459
490
  let repayAssets;
460
491
  let repayShares;
461
492
  let erc20Amount;
462
- let marketForRepay;
463
- // 2h forward accrual upper-bounds the on-chain repay price (shares
464
- // mode) and the post-repay health check; bundle skims residual back.
493
+ // Forward-accrue (2h) for `maxSharePrice` (both modes) and the post-repay health check: on-chain `morphoRepay` accrues `lastUpdate → execution`, so an un-accrued bound reverts on quiet markets.
465
494
  const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
466
495
  morpho_ts_1.Time.s.from.h(2n);
496
+ const marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
467
497
  if ("shares" in params) {
468
- const shares = params.shares;
469
- if (shares <= 0n) {
470
- throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
471
- }
472
498
  (0, index_js_2.validateRepayShares)({
473
499
  positionData,
474
500
  repayShares: shares,
@@ -476,7 +502,6 @@ class MorphoBlue {
476
502
  });
477
503
  repayAssets = 0n;
478
504
  repayShares = shares;
479
- marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
480
505
  const borrowAssets = marketForRepay.toBorrowAssets(shares, "Up");
481
506
  // Native funds the transfer first; the ERC-20 pulled is the remainder.
482
507
  // When native covers the full (2h-forward-accrued, rounded-up) borrow
@@ -487,17 +512,7 @@ class MorphoBlue {
487
512
  }
488
513
  else {
489
514
  // Assets mode is additive, like supply: repaid = amount + nativeAmount.
490
- const amount = params.amount ?? 0n;
491
- // Reject a negative ERC-20 amount before it can be masked by nativeAmount
492
- // in the sum below (a negative amount would otherwise yield a negative
493
- // erc20Amount and a negative approval in getRequirements).
494
- if (amount < 0n) {
495
- throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
496
- }
497
515
  repayAssets = amount + nativeAmount;
498
- if (repayAssets <= 0n) {
499
- throw new index_js_3.NonPositiveRepayAmountError(this.marketParams.id);
500
- }
501
516
  (0, index_js_2.validateRepayAmount)({
502
517
  positionData,
503
518
  repayAssets,
@@ -505,7 +520,6 @@ class MorphoBlue {
505
520
  });
506
521
  repayShares = 0n;
507
522
  erc20Amount = amount;
508
- marketForRepay = positionData.market;
509
523
  }
510
524
  if (withdrawAmount > positionData.collateral) {
511
525
  throw new index_js_3.WithdrawExceedsCollateralError({
@@ -590,13 +604,21 @@ class MorphoBlue {
590
604
  supplyCollateralBorrow({ amount = 0n, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
591
605
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
592
606
  if (amount < 0n) {
593
- throw new index_js_3.NonPositiveAssetAmountError(this.marketParams.collateralToken);
607
+ throw new index_js_3.NegativeInputError("amount", amount);
594
608
  }
595
609
  if (nativeAmount !== undefined && nativeAmount < 0n) {
596
- throw new index_js_3.NegativeNativeAmountError(nativeAmount);
610
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
597
611
  }
598
612
  if (borrowAmount <= 0n) {
599
- throw new index_js_3.NonPositiveBorrowAmountError(this.marketParams.id);
613
+ throw new index_js_3.NonPositiveInputError("borrowAmount", borrowAmount);
614
+ }
615
+ const totalCollateral = amount + (nativeAmount ?? 0n);
616
+ if (totalCollateral === 0n) {
617
+ throw new index_js_3.NonPositiveInputError("totalCollateral", totalCollateral);
618
+ }
619
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
620
+ if (reallocations) {
621
+ (0, index_js_2.validateReallocations)(reallocations, this.marketParams.id);
600
622
  }
601
623
  if (!positionData) {
602
624
  throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
@@ -606,11 +628,6 @@ class MorphoBlue {
606
628
  expectedMarketId: this.marketParams.id,
607
629
  expectedUser: userAddress,
608
630
  });
609
- const totalCollateral = amount + (nativeAmount ?? 0n);
610
- if (totalCollateral === 0n) {
611
- throw new index_js_3.ZeroCollateralAmountError(this.marketParams.id);
612
- }
613
- (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
614
631
  if (nativeAmount !== undefined && nativeAmount > 0n) {
615
632
  (0, index_js_2.validateNativeAsset)(this.chainId, this.marketParams.collateralToken);
616
633
  }
@@ -673,7 +690,21 @@ class MorphoBlue {
673
690
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
674
691
  (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
675
692
  if (collateralAmount <= 0n) {
676
- throw new index_js_3.ZeroCollateralAmountError(this.marketParams.id);
693
+ throw new index_js_3.NonPositiveInputError("collateralAmount", collateralAmount);
694
+ }
695
+ const requestedAssets = borrowAssets ?? 0n;
696
+ const requestedShares = borrowShares ?? 0n;
697
+ if (requestedAssets < 0n) {
698
+ throw new index_js_3.NegativeInputError("borrowAssets", requestedAssets);
699
+ }
700
+ if (requestedShares < 0n) {
701
+ throw new index_js_3.NegativeInputError("borrowShares", requestedShares);
702
+ }
703
+ if (requestedAssets > 0n && requestedShares > 0n) {
704
+ throw new index_js_3.BorrowAmountAndSharesExclusiveError(this.marketParams.id);
705
+ }
706
+ if (targetReallocations) {
707
+ (0, index_js_2.validateReallocations)(targetReallocations, target.marketParams.id);
677
708
  }
678
709
  if (!positionData) {
679
710
  throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
@@ -695,18 +726,6 @@ class MorphoBlue {
695
726
  expectedMarketId: target.marketParams.id,
696
727
  expectedUser: userAddress,
697
728
  });
698
- const requestedAssets = borrowAssets ?? 0n;
699
- const requestedShares = borrowShares ?? 0n;
700
- // Reject negative debt up front; otherwise it slips past the `> 0n` mode checks and only fails at buildTx().
701
- if (requestedAssets < 0n) {
702
- throw new index_js_3.NonPositiveAssetAmountError(this.marketParams.loanToken);
703
- }
704
- if (requestedShares < 0n) {
705
- throw new index_js_3.NegativeBorrowSharesError(this.marketParams.id);
706
- }
707
- if (requestedAssets > 0n && requestedShares > 0n) {
708
- throw new index_js_3.BorrowAmountAndSharesExclusiveError(this.marketParams.id);
709
- }
710
729
  const sharesMode = requestedShares > 0n;
711
730
  const shouldMigrateBorrow = requestedAssets > 0n || sharesMode;
712
731
  if (collateralAmount > positionData.collateral) {
@@ -1,6 +1,7 @@
1
1
  export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition, IPreLiquidationParams, IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
2
2
  export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position, PreLiquidationParams, PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
3
3
  export { MorphoBlue } from "./blue/index.js";
4
+ export * from "./midnight/index.js";
4
5
  export { type InputReallocationData, ReallocationData, } from "./reallocationData.js";
5
6
  export { MorphoVaultV1 } from "./vaultV1/index.js";
6
7
  export { MorphoVaultV2 } from "./vaultV2/index.js";
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.ReallocationData = exports.MorphoBlue = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketPublicAllocatorConfig = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.User = exports.Token = exports.PreLiquidationPosition = exports.PreLiquidationParams = exports.Position = exports.MarketParams = exports.Market = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.AccrualPosition = void 0;
4
18
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
@@ -35,6 +49,7 @@ Object.defineProperty(exports, "VaultV2MorphoVaultV1Adapter", { enumerable: true
35
49
  Object.defineProperty(exports, "WrappedToken", { enumerable: true, get: function () { return blue_sdk_1.WrappedToken; } });
36
50
  var index_js_1 = require("./blue/index.js");
37
51
  Object.defineProperty(exports, "MorphoBlue", { enumerable: true, get: function () { return index_js_1.MorphoBlue; } });
52
+ __exportStar(require("./midnight/index.js"), exports);
38
53
  var reallocationData_js_1 = require("./reallocationData.js");
39
54
  Object.defineProperty(exports, "ReallocationData", { enumerable: true, get: function () { return reallocationData_js_1.ReallocationData; } });
40
55
  var index_js_2 = require("./vaultV1/index.js");
@@ -0,0 +1,2 @@
1
+ export * from "./midnight.js";
2
+ export * from "./types.js";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./midnight.js"), exports);
18
+ __exportStar(require("./types.js"), exports);