@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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.compareMarketIds = void 0;
3
+ exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.compareMarketIds = void 0;
4
4
  exports.validateUserAddress = validateUserAddress;
5
5
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
@@ -18,6 +18,25 @@ const compareMarketIds = (idA, idB) => {
18
18
  return 0;
19
19
  };
20
20
  exports.compareMarketIds = compareMarketIds;
21
+ /**
22
+ * Validates that a raw or hydrated Midnight market belongs to the expected chain.
23
+ *
24
+ * @param market - Midnight market params or hydrated market state.
25
+ * @param chainId - Expected EIP-155 chain id.
26
+ * @returns Nothing when the market belongs to `chainId`.
27
+ * @throws {ChainIdMismatchError} when the market belongs to another chain.
28
+ * @example
29
+ * ```ts
30
+ * import { validateMidnightMarketChainId } from "@morpho-org/morpho-sdk";
31
+ *
32
+ * validateMidnightMarketChainId(marketParams, 8453);
33
+ * ```
34
+ */
35
+ const validateMidnightMarketChainId = (market, chainId) => {
36
+ const marketParams = "params" in market ? market.params : market;
37
+ (0, exports.validateChainId)(Number(marketParams.chainId), chainId);
38
+ };
39
+ exports.validateMidnightMarketChainId = validateMidnightMarketChainId;
21
40
  /**
22
41
  * Asserts that the client has a connected account AND that it matches
23
42
  * the provided user address.
@@ -224,11 +243,25 @@ exports.validateRepayShares = validateRepayShares;
224
243
  *
225
244
  * @param reallocations - The reallocations to validate.
226
245
  * @param targetMarketId - The ID of the operation's target market. No withdrawal may reference this market.
246
+ * @returns Nothing when every reallocation is valid.
247
+ * @throws {NegativeInputError} when a reallocation fee is negative.
248
+ * @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
249
+ * @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
250
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
251
+ * @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
252
+ * @example
253
+ * ```ts
254
+ * import type { MarketId } from "@morpho-org/blue-sdk";
255
+ * import { validateReallocations } from "@morpho-org/morpho-sdk";
256
+ * import { zeroHash } from "viem";
257
+ *
258
+ * const result: void = validateReallocations([], zeroHash as MarketId);
259
+ * ```
227
260
  */
228
261
  const validateReallocations = (reallocations, targetMarketId) => {
229
262
  for (const r of reallocations) {
230
263
  if (r.fee < 0n) {
231
- throw new index_js_1.NegativeReallocationFeeError(r.vault);
264
+ throw new index_js_1.NegativeInputError("reallocation.fee", r.fee);
232
265
  }
233
266
  if (r.withdrawals.length === 0) {
234
267
  throw new index_js_1.EmptyReallocationWithdrawalsError(r.vault);
@@ -236,7 +269,7 @@ const validateReallocations = (reallocations, targetMarketId) => {
236
269
  let prevId;
237
270
  for (const w of r.withdrawals) {
238
271
  if (w.amount <= 0n) {
239
- throw new index_js_1.NonPositiveReallocationAmountError(r.vault, w.marketParams.id);
272
+ throw new index_js_1.NonPositiveInputError(`reallocation.withdrawals[${w.marketParams.id}].amount`, w.amount);
240
273
  }
241
274
  if (w.marketParams.id === targetMarketId) {
242
275
  throw new index_js_1.ReallocationWithdrawalOnTargetMarketError(r.vault, w.marketParams.id);
@@ -253,14 +286,23 @@ exports.validateReallocations = validateReallocations;
253
286
  /**
254
287
  * Validates that a slippage tolerance is within an acceptable range.
255
288
  *
256
- * Throws {@link NegativeSlippageToleranceError} if negative.
289
+ * Throws {@link NegativeInputError} if negative.
257
290
  * Throws {@link ExcessiveSlippageToleranceError} if greater than {@link MAX_SLIPPAGE_TOLERANCE}.
258
291
  *
259
292
  * @param slippageTolerance - The slippage tolerance in WAD.
293
+ * @returns Nothing when the slippage tolerance is valid.
294
+ * @throws {NegativeInputError} when `slippageTolerance < 0n`.
295
+ * @throws {ExcessiveSlippageToleranceError} when the tolerance exceeds the SDK maximum.
296
+ * @example
297
+ * ```ts
298
+ * import { validateSlippageTolerance } from "@morpho-org/morpho-sdk";
299
+ *
300
+ * const result: void = validateSlippageTolerance(5_000000000000000n);
301
+ * ```
260
302
  */
261
303
  const validateSlippageTolerance = (slippageTolerance) => {
262
304
  if (slippageTolerance < 0n) {
263
- throw new index_js_1.NegativeSlippageToleranceError(slippageTolerance);
305
+ throw new index_js_1.NegativeInputError("slippageTolerance", slippageTolerance);
264
306
  }
265
307
  if (slippageTolerance > constant_js_1.MAX_SLIPPAGE_TOLERANCE) {
266
308
  throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
@@ -0,0 +1,15 @@
1
+ import { type Address } from "viem";
2
+ /**
3
+ * Validates that a Midnight authorization grant targets a supported protocol operator.
4
+ *
5
+ * @param params - Authorization target validation parameters.
6
+ * @param params.chainId - Chain id used to resolve supported Midnight operators.
7
+ * @param params.authorized - Operator address receiving authorization.
8
+ * @returns Nothing after the operator matches MidnightBundles or a supported ratifier.
9
+ * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported operator.
10
+ * @internal
11
+ */
12
+ export declare const validateMidnightAuthorizationTarget: (params: {
13
+ readonly chainId: number;
14
+ readonly authorized: Address;
15
+ }) => void;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateMidnightAuthorizationTarget = void 0;
4
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const viem_1 = require("viem");
6
+ const index_js_1 = require("../types/index.js");
7
+ /**
8
+ * Validates that a Midnight authorization grant targets a supported protocol operator.
9
+ *
10
+ * @param params - Authorization target validation parameters.
11
+ * @param params.chainId - Chain id used to resolve supported Midnight operators.
12
+ * @param params.authorized - Operator address receiving authorization.
13
+ * @returns Nothing after the operator matches MidnightBundles or a supported ratifier.
14
+ * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported operator.
15
+ * @internal
16
+ */
17
+ const validateMidnightAuthorizationTarget = (params) => {
18
+ const { midnightBundles, ecrecoverRatifier, setterRatifier } = (0, morpho_ts_1.getChainAddresses)(params.chainId);
19
+ const supportedTargets = [
20
+ midnightBundles,
21
+ ecrecoverRatifier,
22
+ setterRatifier,
23
+ ].filter((target) => target != null);
24
+ if (!supportedTargets.some((supported) => (0, viem_1.isAddressEqual)(params.authorized, supported))) {
25
+ throw new index_js_1.UnsupportedMidnightAuthorizationTargetError({
26
+ authorized: params.authorized,
27
+ chainId: params.chainId,
28
+ supportedTargets,
29
+ });
30
+ }
31
+ };
32
+ exports.validateMidnightAuthorizationTarget = validateMidnightAuthorizationTarget;
@@ -0,0 +1,10 @@
1
+ import type { MarketInput } from "@morpho-org/midnight-sdk";
2
+ /**
3
+ * Validates that a Midnight market belongs to the configured chain deployment.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare const validateMidnightMarket: (params: {
8
+ readonly market: MarketInput;
9
+ readonly chainId: number;
10
+ }) => void;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateMidnightMarket = void 0;
4
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const viem_1 = require("viem");
6
+ const index_js_1 = require("../types/index.js");
7
+ const validate_js_1 = require("./validate.js");
8
+ /**
9
+ * Validates that a Midnight market belongs to the configured chain deployment.
10
+ *
11
+ * @internal
12
+ */
13
+ const validateMidnightMarket = (params) => {
14
+ const market = "params" in params.market ? params.market.params : params.market;
15
+ (0, validate_js_1.validateChainId)(Number(market.chainId), params.chainId);
16
+ const expectedMidnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
17
+ if (!(0, viem_1.isAddressEqual)(market.midnight, expectedMidnight)) {
18
+ throw new index_js_1.MidnightMarketAddressMismatchError({
19
+ expectedMidnight,
20
+ actualMidnight: market.midnight,
21
+ });
22
+ }
23
+ };
24
+ exports.validateMidnightMarket = validateMidnightMarket;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Validates that Midnight offers match a named flow's maker side.
3
+ *
4
+ * Use before encoding a side-specific Midnight action: make-lend and
5
+ * take-borrow consume buy offers (`expectedBuy: true`), while make-borrow and
6
+ * take-lend consume sell offers (`expectedBuy: false`).
7
+ *
8
+ * @param offers - Offers to validate.
9
+ * @param expectedBuy - Expected maker side for every offer.
10
+ * @returns Nothing after every offer has the expected maker side.
11
+ * @throws {MidnightOfferSideMismatchError} when any offer side differs from `expectedBuy`.
12
+ * @example
13
+ * ```ts
14
+ * import { validateOfferSides } from "@morpho-org/morpho-sdk";
15
+ *
16
+ * validateOfferSides([{ buy: false }, { buy: false }], false);
17
+ * ```
18
+ */
19
+ export declare const validateOfferSides: (offers: Iterable<{
20
+ readonly buy: boolean;
21
+ }>, expectedBuy: boolean) => void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateOfferSides = void 0;
4
+ const index_js_1 = require("../types/index.js");
5
+ /**
6
+ * Validates that Midnight offers match a named flow's maker side.
7
+ *
8
+ * Use before encoding a side-specific Midnight action: make-lend and
9
+ * take-borrow consume buy offers (`expectedBuy: true`), while make-borrow and
10
+ * take-lend consume sell offers (`expectedBuy: false`).
11
+ *
12
+ * @param offers - Offers to validate.
13
+ * @param expectedBuy - Expected maker side for every offer.
14
+ * @returns Nothing after every offer has the expected maker side.
15
+ * @throws {MidnightOfferSideMismatchError} when any offer side differs from `expectedBuy`.
16
+ * @example
17
+ * ```ts
18
+ * import { validateOfferSides } from "@morpho-org/morpho-sdk";
19
+ *
20
+ * validateOfferSides([{ buy: false }, { buy: false }], false);
21
+ * ```
22
+ */
23
+ const validateOfferSides = (offers, expectedBuy) => {
24
+ let index = 0;
25
+ for (const offer of offers) {
26
+ if (offer.buy !== expectedBuy) {
27
+ throw new index_js_1.MidnightOfferSideMismatchError({
28
+ index,
29
+ expectedBuy,
30
+ actualBuy: offer.buy,
31
+ });
32
+ }
33
+ index += 1;
34
+ }
35
+ };
36
+ exports.validateOfferSides = validateOfferSides;
@@ -0,0 +1,29 @@
1
+ import { type Address } from "@morpho-org/blue-sdk";
2
+ /** Supported spender slots that can be validated against the chain address registry. */
3
+ export type RequirementSpenderKey = "generalAdapter1" | "permit2" | "midnight" | "midnightBundles";
4
+ /**
5
+ * Validates that a requirement encoder spender matches one of the allowed chain addresses.
6
+ *
7
+ * @param params - Spender validation parameters.
8
+ * @param params.chainId - Chain id used to resolve supported spender addresses.
9
+ * @param params.spender - Spender address to validate.
10
+ * @param params.allowed - Allowed registry slots for this requirement.
11
+ * @returns Nothing after the spender matches an allowed chain address.
12
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` does not match any allowed slot.
13
+ * @example
14
+ * ```ts
15
+ * import { validateRequirementSpender } from "@morpho-org/morpho-sdk";
16
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
17
+ *
18
+ * validateRequirementSpender({
19
+ * chainId: 8453,
20
+ * spender: getChainAddress(8453, "midnightBundles"),
21
+ * allowed: ["midnightBundles"],
22
+ * });
23
+ * ```
24
+ */
25
+ export declare const validateRequirementSpender: (params: {
26
+ readonly chainId: number;
27
+ readonly spender: Address;
28
+ readonly allowed: readonly RequirementSpenderKey[];
29
+ }) => void;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRequirementSpender = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const viem_1 = require("viem");
6
+ const index_js_1 = require("../types/index.js");
7
+ /**
8
+ * Validates that a requirement encoder spender matches one of the allowed chain addresses.
9
+ *
10
+ * @param params - Spender validation parameters.
11
+ * @param params.chainId - Chain id used to resolve supported spender addresses.
12
+ * @param params.spender - Spender address to validate.
13
+ * @param params.allowed - Allowed registry slots for this requirement.
14
+ * @returns Nothing after the spender matches an allowed chain address.
15
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` does not match any allowed slot.
16
+ * @example
17
+ * ```ts
18
+ * import { validateRequirementSpender } from "@morpho-org/morpho-sdk";
19
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
20
+ *
21
+ * validateRequirementSpender({
22
+ * chainId: 8453,
23
+ * spender: getChainAddress(8453, "midnightBundles"),
24
+ * allowed: ["midnightBundles"],
25
+ * });
26
+ * ```
27
+ */
28
+ const validateRequirementSpender = (params) => {
29
+ const { permit2, midnight, midnightBundles, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
30
+ const addresses = {
31
+ generalAdapter1,
32
+ permit2,
33
+ midnight,
34
+ midnightBundles,
35
+ };
36
+ const supportedSpenders = params.allowed.map((key) => addresses[key]);
37
+ if (!supportedSpenders.some((supported) => supported != null && (0, viem_1.isAddressEqual)(params.spender, supported))) {
38
+ throw new index_js_1.UnsupportedErc20ApprovalSpenderError({
39
+ spender: params.spender,
40
+ chainId: params.chainId,
41
+ generalAdapter1,
42
+ permit2,
43
+ midnight,
44
+ midnightBundles,
45
+ supportedSpenders,
46
+ });
47
+ }
48
+ };
49
+ exports.validateRequirementSpender = validateRequirementSpender;
@@ -0,0 +1,18 @@
1
+ import { type MarketInput, type OfferStruct } from "@morpho-org/midnight-sdk";
2
+ /**
3
+ * Validates the pure invariants shared by Midnight take entity and action layers.
4
+ *
5
+ * @param params - Selected market, takeable offers, and expected maker side.
6
+ * @returns The selected market id.
7
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
8
+ * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
9
+ * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
10
+ * @internal
11
+ */
12
+ export declare const validateTakeableOffers: (params: {
13
+ readonly market: MarketInput;
14
+ readonly takeableOffers: readonly {
15
+ readonly offer: Pick<OfferStruct, "buy" | "market">;
16
+ }[];
17
+ readonly expectedBuy: boolean;
18
+ }) => `0x${string}`;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateTakeableOffers = void 0;
4
+ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
+ const index_js_1 = require("../types/index.js");
6
+ const validateOfferSides_js_1 = require("./validateOfferSides.js");
7
+ /**
8
+ * Validates the pure invariants shared by Midnight take entity and action layers.
9
+ *
10
+ * @param params - Selected market, takeable offers, and expected maker side.
11
+ * @returns The selected market id.
12
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
13
+ * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
14
+ * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
15
+ * @internal
16
+ */
17
+ const validateTakeableOffers = (params) => {
18
+ if (params.takeableOffers.length === 0) {
19
+ throw new index_js_1.EmptyMidnightTakeableOffersError();
20
+ }
21
+ const marketId = midnight_sdk_1.MarketUtils.toId(params.market);
22
+ (0, validateOfferSides_js_1.validateOfferSides)(params.takeableOffers.map((take) => take.offer), params.expectedBuy);
23
+ for (const [index, take] of params.takeableOffers.entries()) {
24
+ const actualMarketId = midnight_sdk_1.MarketUtils.toId(take.offer.market);
25
+ if (actualMarketId.toLowerCase() !== marketId.toLowerCase()) {
26
+ throw new index_js_1.MidnightTakeableOfferMarketMismatchError({
27
+ index,
28
+ expectedMarket: marketId,
29
+ actualMarket: actualMarketId,
30
+ });
31
+ }
32
+ }
33
+ return marketId;
34
+ };
35
+ exports.validateTakeableOffers = validateTakeableOffers;
@@ -0,0 +1 @@
1
+ export * from "@morpho-org/midnight-sdk/api";
@@ -0,0 +1,17 @@
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("@morpho-org/midnight-sdk/api"), exports);