@morpho-org/morpho-sdk 5.1.2 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/README.md +46 -2
  2. package/lib/cjs/abis.d.ts +1 -0
  3. package/lib/cjs/abis.js +6 -1
  4. package/lib/cjs/actions/blue/borrow.d.ts +3 -7
  5. package/lib/cjs/actions/blue/borrow.js +5 -9
  6. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +3 -4
  7. package/lib/cjs/actions/blue/buildReallocationActions.js +3 -4
  8. package/lib/cjs/actions/blue/refinance.d.ts +4 -8
  9. package/lib/cjs/actions/blue/refinance.js +10 -14
  10. package/lib/cjs/actions/blue/repay.d.ts +2 -5
  11. package/lib/cjs/actions/blue/repay.js +2 -5
  12. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -6
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +4 -7
  14. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +2 -5
  15. package/lib/cjs/actions/blue/resolveRepayFunding.js +15 -12
  16. package/lib/cjs/actions/blue/supply.d.ts +2 -4
  17. package/lib/cjs/actions/blue/supply.js +6 -8
  18. package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -3
  19. package/lib/cjs/actions/blue/supplyCollateral.js +5 -6
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +4 -9
  21. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +9 -14
  22. package/lib/cjs/actions/blue/withdraw.d.ts +9 -7
  23. package/lib/cjs/actions/blue/withdraw.js +18 -10
  24. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
  25. package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
  26. package/lib/cjs/actions/index.d.ts +2 -0
  27. package/lib/cjs/actions/index.js +1 -0
  28. package/lib/cjs/actions/midnight/authorization.d.ts +37 -0
  29. package/lib/cjs/actions/midnight/authorization.js +69 -0
  30. package/lib/cjs/actions/midnight/cancelOffer.d.ts +38 -0
  31. package/lib/cjs/actions/midnight/cancelOffer.js +73 -0
  32. package/lib/cjs/actions/midnight/index.d.ts +11 -0
  33. package/lib/cjs/actions/midnight/index.js +27 -0
  34. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
  35. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +72 -0
  36. package/lib/cjs/actions/midnight/redeem.d.ts +43 -0
  37. package/lib/cjs/actions/midnight/redeem.js +79 -0
  38. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
  39. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +121 -0
  40. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
  41. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +59 -0
  42. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +45 -0
  43. package/lib/cjs/actions/midnight/supplyCollateral.js +83 -0
  44. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
  45. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -0
  46. package/lib/cjs/actions/midnight/takeBorrow.d.ts +57 -0
  47. package/lib/cjs/actions/midnight/takeBorrow.js +110 -0
  48. package/lib/cjs/actions/midnight/takeLend.d.ts +57 -0
  49. package/lib/cjs/actions/midnight/takeLend.js +110 -0
  50. package/lib/cjs/actions/midnight/types.d.ts +39 -0
  51. package/lib/cjs/actions/midnight/types.js +15 -0
  52. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
  53. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +5 -16
  54. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
  55. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +10 -14
  56. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
  57. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +11 -28
  58. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
  59. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
  60. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  61. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +10 -4
  62. package/lib/cjs/actions/requirements/getRequirementsApproval.js +10 -4
  63. package/lib/cjs/actions/requirements/index.d.ts +1 -0
  64. package/lib/cjs/actions/requirements/index.js +1 -0
  65. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
  66. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +76 -0
  67. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
  68. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +78 -0
  69. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
  70. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +70 -0
  71. package/lib/cjs/actions/requirements/midnight/index.d.ts +3 -0
  72. package/lib/cjs/actions/requirements/midnight/index.js +19 -0
  73. package/lib/cjs/actions/vaultV1/deposit.d.ts +3 -4
  74. package/lib/cjs/actions/vaultV1/deposit.js +7 -8
  75. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -3
  76. package/lib/cjs/actions/vaultV1/migrateToV2.js +5 -6
  77. package/lib/cjs/actions/vaultV1/redeem.d.ts +1 -1
  78. package/lib/cjs/actions/vaultV1/redeem.js +2 -2
  79. package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
  80. package/lib/cjs/actions/vaultV1/withdraw.js +2 -2
  81. package/lib/cjs/actions/vaultV2/deposit.d.ts +3 -4
  82. package/lib/cjs/actions/vaultV2/deposit.js +7 -8
  83. package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +2 -3
  84. package/lib/cjs/actions/vaultV2/forceRedeem.js +3 -4
  85. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
  86. package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -2
  87. package/lib/cjs/actions/vaultV2/redeem.d.ts +1 -1
  88. package/lib/cjs/actions/vaultV2/redeem.js +2 -2
  89. package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
  90. package/lib/cjs/actions/vaultV2/withdraw.js +2 -2
  91. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  92. package/lib/cjs/client/morphoViemExtension.js +5 -2
  93. package/lib/cjs/constants.d.ts +1 -0
  94. package/lib/cjs/constants.js +15 -1
  95. package/lib/cjs/entities/blue/blue.d.ts +5 -5
  96. package/lib/cjs/entities/blue/blue.js +105 -86
  97. package/lib/cjs/entities/index.d.ts +1 -0
  98. package/lib/cjs/entities/index.js +15 -0
  99. package/lib/cjs/entities/midnight/index.d.ts +2 -0
  100. package/lib/cjs/entities/midnight/index.js +18 -0
  101. package/lib/cjs/entities/midnight/midnight.d.ts +402 -0
  102. package/lib/cjs/entities/midnight/midnight.js +1036 -0
  103. package/lib/cjs/entities/midnight/types.d.ts +164 -0
  104. package/lib/cjs/entities/midnight/types.js +2 -0
  105. package/lib/cjs/entities/vaultV1/vaultV1.js +10 -17
  106. package/lib/cjs/entities/vaultV2/vaultV2.js +19 -21
  107. package/lib/cjs/errors.d.ts +1 -0
  108. package/lib/cjs/errors.js +17 -1
  109. package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
  110. package/lib/cjs/helpers/encodeDeallocation.js +2 -1
  111. package/lib/cjs/helpers/index.d.ts +4 -1
  112. package/lib/cjs/helpers/index.js +8 -1
  113. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +34 -0
  114. package/lib/cjs/helpers/signAndVerifyTypedData.js +58 -0
  115. package/lib/cjs/helpers/validate.d.ts +40 -1
  116. package/lib/cjs/helpers/validate.js +47 -5
  117. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
  118. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +32 -0
  119. package/lib/cjs/helpers/validateMidnightMarket.d.ts +10 -0
  120. package/lib/cjs/helpers/validateMidnightMarket.js +24 -0
  121. package/lib/cjs/helpers/validateOfferSides.d.ts +21 -0
  122. package/lib/cjs/helpers/validateOfferSides.js +36 -0
  123. package/lib/cjs/helpers/validateRequirementSpender.d.ts +29 -0
  124. package/lib/cjs/helpers/validateRequirementSpender.js +49 -0
  125. package/lib/cjs/helpers/validateTakeableOffers.d.ts +18 -0
  126. package/lib/cjs/helpers/validateTakeableOffers.js +35 -0
  127. package/lib/cjs/midnight-api.d.ts +1 -0
  128. package/lib/cjs/midnight-api.js +17 -0
  129. package/lib/cjs/types/action.d.ts +189 -23
  130. package/lib/cjs/types/action.js +27 -7
  131. package/lib/cjs/types/client.d.ts +3 -2
  132. package/lib/cjs/types/error.d.ts +288 -114
  133. package/lib/cjs/types/error.js +259 -175
  134. package/lib/cjs/utils.d.ts +1 -0
  135. package/lib/cjs/utils.js +12 -2
  136. package/lib/esm/abis.d.ts +1 -0
  137. package/lib/esm/abis.js +1 -0
  138. package/lib/esm/actions/blue/borrow.d.ts +3 -7
  139. package/lib/esm/actions/blue/borrow.js +6 -10
  140. package/lib/esm/actions/blue/buildReallocationActions.d.ts +3 -4
  141. package/lib/esm/actions/blue/buildReallocationActions.js +3 -4
  142. package/lib/esm/actions/blue/refinance.d.ts +4 -8
  143. package/lib/esm/actions/blue/refinance.js +11 -15
  144. package/lib/esm/actions/blue/repay.d.ts +2 -5
  145. package/lib/esm/actions/blue/repay.js +2 -5
  146. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -6
  147. package/lib/esm/actions/blue/repayWithdrawCollateral.js +5 -8
  148. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +2 -5
  149. package/lib/esm/actions/blue/resolveRepayFunding.js +16 -13
  150. package/lib/esm/actions/blue/supply.d.ts +2 -4
  151. package/lib/esm/actions/blue/supply.js +7 -9
  152. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -3
  153. package/lib/esm/actions/blue/supplyCollateral.js +6 -7
  154. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -9
  155. package/lib/esm/actions/blue/supplyCollateralBorrow.js +10 -15
  156. package/lib/esm/actions/blue/withdraw.d.ts +9 -7
  157. package/lib/esm/actions/blue/withdraw.js +19 -11
  158. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
  159. package/lib/esm/actions/blue/withdrawCollateral.js +3 -3
  160. package/lib/esm/actions/index.d.ts +2 -0
  161. package/lib/esm/actions/index.js +1 -0
  162. package/lib/esm/actions/midnight/authorization.d.ts +37 -0
  163. package/lib/esm/actions/midnight/authorization.js +65 -0
  164. package/lib/esm/actions/midnight/cancelOffer.d.ts +38 -0
  165. package/lib/esm/actions/midnight/cancelOffer.js +69 -0
  166. package/lib/esm/actions/midnight/index.d.ts +11 -0
  167. package/lib/esm/actions/midnight/index.js +11 -0
  168. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
  169. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +68 -0
  170. package/lib/esm/actions/midnight/redeem.d.ts +43 -0
  171. package/lib/esm/actions/midnight/redeem.js +75 -0
  172. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
  173. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +117 -0
  174. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
  175. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +55 -0
  176. package/lib/esm/actions/midnight/supplyCollateral.d.ts +45 -0
  177. package/lib/esm/actions/midnight/supplyCollateral.js +79 -0
  178. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
  179. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +124 -0
  180. package/lib/esm/actions/midnight/takeBorrow.d.ts +57 -0
  181. package/lib/esm/actions/midnight/takeBorrow.js +106 -0
  182. package/lib/esm/actions/midnight/takeLend.d.ts +57 -0
  183. package/lib/esm/actions/midnight/takeLend.js +106 -0
  184. package/lib/esm/actions/midnight/types.d.ts +39 -0
  185. package/lib/esm/actions/midnight/types.js +12 -0
  186. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
  187. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +6 -17
  188. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
  189. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +12 -16
  190. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
  191. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +12 -29
  192. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
  193. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
  194. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  195. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +10 -4
  196. package/lib/esm/actions/requirements/getRequirementsApproval.js +10 -4
  197. package/lib/esm/actions/requirements/index.d.ts +1 -0
  198. package/lib/esm/actions/requirements/index.js +1 -0
  199. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
  200. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +72 -0
  201. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
  202. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +74 -0
  203. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
  204. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +66 -0
  205. package/lib/esm/actions/requirements/midnight/index.d.ts +3 -0
  206. package/lib/esm/actions/requirements/midnight/index.js +3 -0
  207. package/lib/esm/actions/vaultV1/deposit.d.ts +3 -4
  208. package/lib/esm/actions/vaultV1/deposit.js +8 -9
  209. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -3
  210. package/lib/esm/actions/vaultV1/migrateToV2.js +6 -7
  211. package/lib/esm/actions/vaultV1/redeem.d.ts +1 -1
  212. package/lib/esm/actions/vaultV1/redeem.js +3 -3
  213. package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
  214. package/lib/esm/actions/vaultV1/withdraw.js +3 -3
  215. package/lib/esm/actions/vaultV2/deposit.d.ts +3 -4
  216. package/lib/esm/actions/vaultV2/deposit.js +8 -9
  217. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -3
  218. package/lib/esm/actions/vaultV2/forceRedeem.js +4 -5
  219. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  220. package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
  221. package/lib/esm/actions/vaultV2/redeem.d.ts +1 -1
  222. package/lib/esm/actions/vaultV2/redeem.js +3 -3
  223. package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
  224. package/lib/esm/actions/vaultV2/withdraw.js +3 -3
  225. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  226. package/lib/esm/client/morphoViemExtension.js +6 -3
  227. package/lib/esm/constants.d.ts +1 -0
  228. package/lib/esm/constants.js +1 -0
  229. package/lib/esm/entities/blue/blue.d.ts +5 -5
  230. package/lib/esm/entities/blue/blue.js +107 -88
  231. package/lib/esm/entities/index.d.ts +1 -0
  232. package/lib/esm/entities/index.js +1 -0
  233. package/lib/esm/entities/midnight/index.d.ts +2 -0
  234. package/lib/esm/entities/midnight/index.js +2 -0
  235. package/lib/esm/entities/midnight/midnight.d.ts +402 -0
  236. package/lib/esm/entities/midnight/midnight.js +1032 -0
  237. package/lib/esm/entities/midnight/types.d.ts +164 -0
  238. package/lib/esm/entities/midnight/types.js +1 -0
  239. package/lib/esm/entities/vaultV1/vaultV1.js +13 -20
  240. package/lib/esm/entities/vaultV2/vaultV2.js +9 -11
  241. package/lib/esm/errors.d.ts +1 -0
  242. package/lib/esm/errors.js +1 -0
  243. package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
  244. package/lib/esm/helpers/encodeDeallocation.js +3 -2
  245. package/lib/esm/helpers/index.d.ts +4 -1
  246. package/lib/esm/helpers/index.js +4 -1
  247. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +34 -0
  248. package/lib/esm/helpers/signAndVerifyTypedData.js +54 -0
  249. package/lib/esm/helpers/validate.d.ts +40 -1
  250. package/lib/esm/helpers/validate.js +46 -5
  251. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
  252. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +28 -0
  253. package/lib/esm/helpers/validateMidnightMarket.d.ts +10 -0
  254. package/lib/esm/helpers/validateMidnightMarket.js +20 -0
  255. package/lib/esm/helpers/validateOfferSides.d.ts +21 -0
  256. package/lib/esm/helpers/validateOfferSides.js +32 -0
  257. package/lib/esm/helpers/validateRequirementSpender.d.ts +29 -0
  258. package/lib/esm/helpers/validateRequirementSpender.js +45 -0
  259. package/lib/esm/helpers/validateTakeableOffers.d.ts +18 -0
  260. package/lib/esm/helpers/validateTakeableOffers.js +31 -0
  261. package/lib/esm/midnight-api.d.ts +1 -0
  262. package/lib/esm/midnight-api.js +1 -0
  263. package/lib/esm/types/action.d.ts +189 -23
  264. package/lib/esm/types/action.js +26 -7
  265. package/lib/esm/types/client.d.ts +3 -2
  266. package/lib/esm/types/error.d.ts +288 -114
  267. package/lib/esm/types/error.js +232 -149
  268. package/lib/esm/utils.d.ts +1 -0
  269. package/lib/esm/utils.js +1 -0
  270. package/package.json +13 -4
@@ -0,0 +1,28 @@
1
+ import { getChainAddresses } from "@morpho-org/morpho-ts";
2
+ import { isAddressEqual } from "viem";
3
+ import { UnsupportedMidnightAuthorizationTargetError } from "../types/index.js";
4
+ /**
5
+ * Validates that a Midnight authorization grant targets a supported protocol operator.
6
+ *
7
+ * @param params - Authorization target validation parameters.
8
+ * @param params.chainId - Chain id used to resolve supported Midnight operators.
9
+ * @param params.authorized - Operator address receiving authorization.
10
+ * @returns Nothing after the operator matches MidnightBundles or a supported ratifier.
11
+ * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported operator.
12
+ * @internal
13
+ */
14
+ export const validateMidnightAuthorizationTarget = (params) => {
15
+ const { midnightBundles, ecrecoverRatifier, setterRatifier } = getChainAddresses(params.chainId);
16
+ const supportedTargets = [
17
+ midnightBundles,
18
+ ecrecoverRatifier,
19
+ setterRatifier,
20
+ ].filter((target) => target != null);
21
+ if (!supportedTargets.some((supported) => isAddressEqual(params.authorized, supported))) {
22
+ throw new UnsupportedMidnightAuthorizationTargetError({
23
+ authorized: params.authorized,
24
+ chainId: params.chainId,
25
+ supportedTargets,
26
+ });
27
+ }
28
+ };
@@ -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,20 @@
1
+ import { getChainAddress } from "@morpho-org/morpho-ts";
2
+ import { isAddressEqual } from "viem";
3
+ import { MidnightMarketAddressMismatchError } from "../types/index.js";
4
+ import { validateChainId } from "./validate.js";
5
+ /**
6
+ * Validates that a Midnight market belongs to the configured chain deployment.
7
+ *
8
+ * @internal
9
+ */
10
+ export const validateMidnightMarket = (params) => {
11
+ const market = "params" in params.market ? params.market.params : params.market;
12
+ validateChainId(Number(market.chainId), params.chainId);
13
+ const expectedMidnight = getChainAddress(params.chainId, "midnight");
14
+ if (!isAddressEqual(market.midnight, expectedMidnight)) {
15
+ throw new MidnightMarketAddressMismatchError({
16
+ expectedMidnight,
17
+ actualMidnight: market.midnight,
18
+ });
19
+ }
20
+ };
@@ -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,32 @@
1
+ import { MidnightOfferSideMismatchError } from "../types/index.js";
2
+ /**
3
+ * Validates that Midnight offers match a named flow's maker side.
4
+ *
5
+ * Use before encoding a side-specific Midnight action: make-lend and
6
+ * take-borrow consume buy offers (`expectedBuy: true`), while make-borrow and
7
+ * take-lend consume sell offers (`expectedBuy: false`).
8
+ *
9
+ * @param offers - Offers to validate.
10
+ * @param expectedBuy - Expected maker side for every offer.
11
+ * @returns Nothing after every offer has the expected maker side.
12
+ * @throws {MidnightOfferSideMismatchError} when any offer side differs from `expectedBuy`.
13
+ * @example
14
+ * ```ts
15
+ * import { validateOfferSides } from "@morpho-org/morpho-sdk";
16
+ *
17
+ * validateOfferSides([{ buy: false }, { buy: false }], false);
18
+ * ```
19
+ */
20
+ export const validateOfferSides = (offers, expectedBuy) => {
21
+ let index = 0;
22
+ for (const offer of offers) {
23
+ if (offer.buy !== expectedBuy) {
24
+ throw new MidnightOfferSideMismatchError({
25
+ index,
26
+ expectedBuy,
27
+ actualBuy: offer.buy,
28
+ });
29
+ }
30
+ index += 1;
31
+ }
32
+ };
@@ -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,45 @@
1
+ import { getChainAddresses } from "@morpho-org/blue-sdk";
2
+ import { isAddressEqual } from "viem";
3
+ import { UnsupportedErc20ApprovalSpenderError } from "../types/index.js";
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 const validateRequirementSpender = (params) => {
26
+ const { permit2, midnight, midnightBundles, bundler3: { generalAdapter1 }, } = getChainAddresses(params.chainId);
27
+ const addresses = {
28
+ generalAdapter1,
29
+ permit2,
30
+ midnight,
31
+ midnightBundles,
32
+ };
33
+ const supportedSpenders = params.allowed.map((key) => addresses[key]);
34
+ if (!supportedSpenders.some((supported) => supported != null && isAddressEqual(params.spender, supported))) {
35
+ throw new UnsupportedErc20ApprovalSpenderError({
36
+ spender: params.spender,
37
+ chainId: params.chainId,
38
+ generalAdapter1,
39
+ permit2,
40
+ midnight,
41
+ midnightBundles,
42
+ supportedSpenders,
43
+ });
44
+ }
45
+ };
@@ -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,31 @@
1
+ import { MarketUtils, } from "@morpho-org/midnight-sdk";
2
+ import { EmptyMidnightTakeableOffersError, MidnightTakeableOfferMarketMismatchError, } from "../types/index.js";
3
+ import { validateOfferSides } from "./validateOfferSides.js";
4
+ /**
5
+ * Validates the pure invariants shared by Midnight take entity and action layers.
6
+ *
7
+ * @param params - Selected market, takeable offers, and expected maker side.
8
+ * @returns The selected market id.
9
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
10
+ * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
11
+ * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
12
+ * @internal
13
+ */
14
+ export const validateTakeableOffers = (params) => {
15
+ if (params.takeableOffers.length === 0) {
16
+ throw new EmptyMidnightTakeableOffersError();
17
+ }
18
+ const marketId = MarketUtils.toId(params.market);
19
+ validateOfferSides(params.takeableOffers.map((take) => take.offer), params.expectedBuy);
20
+ for (const [index, take] of params.takeableOffers.entries()) {
21
+ const actualMarketId = MarketUtils.toId(take.offer.market);
22
+ if (actualMarketId.toLowerCase() !== marketId.toLowerCase()) {
23
+ throw new MidnightTakeableOfferMarketMismatchError({
24
+ index,
25
+ expectedMarket: marketId,
26
+ actualMarket: actualMarketId,
27
+ });
28
+ }
29
+ }
30
+ return marketId;
31
+ };
@@ -0,0 +1 @@
1
+ export * from "@morpho-org/midnight-sdk/api";
@@ -0,0 +1 @@
1
+ export * from "@morpho-org/midnight-sdk/api";
@@ -234,7 +234,99 @@ export interface BlueAuthorizationAction extends BaseAction<"blueAuthorization",
234
234
  isAuthorized: boolean;
235
235
  }> {
236
236
  }
237
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | BlueAuthorizationAction;
237
+ /** Metadata for a Midnight authorization prerequisite transaction. */
238
+ export interface MidnightAuthorizationAction extends BaseAction<"midnightAuthorization", {
239
+ readonly authorized: Address;
240
+ readonly isAuthorized: boolean;
241
+ readonly onBehalf: Address;
242
+ }> {
243
+ }
244
+ /** Metadata for a SetterRatifier ratify-root prerequisite transaction. */
245
+ export interface SetterRatifierRatifyRootAction extends BaseAction<"setterRatifierRatifyRoot", {
246
+ readonly maker: Address;
247
+ readonly root: Hex;
248
+ readonly isRootRatified: boolean;
249
+ }> {
250
+ }
251
+ /** Metadata for a Midnight bundle that lends into fixed-rate offers. */
252
+ export interface MidnightTakeLendAction extends BaseAction<"midnightTakeLend", {
253
+ readonly market: Hex;
254
+ readonly assets: bigint;
255
+ readonly minUnits: bigint;
256
+ readonly taker: Address;
257
+ readonly takeableOffers: number;
258
+ readonly deadline: bigint;
259
+ }> {
260
+ }
261
+ /** Metadata for a Midnight bundle that borrows from fixed-rate offers. */
262
+ export interface MidnightTakeBorrowAction extends BaseAction<"midnightTakeBorrow", {
263
+ readonly market: Hex;
264
+ readonly loanAssets: bigint;
265
+ readonly maxUnits: bigint;
266
+ readonly taker: Address;
267
+ readonly receiver: Address;
268
+ readonly collateralSupplies: number;
269
+ readonly takeableOffers: number;
270
+ readonly deadline: bigint;
271
+ }> {
272
+ }
273
+ /** Metadata for a Midnight bundle that supplies collateral and borrows from fixed-rate offers. */
274
+ export interface MidnightSupplyCollateralTakeBorrowAction extends BaseAction<"midnightSupplyCollateralTakeBorrow", {
275
+ readonly market: Hex;
276
+ readonly collateralAssets: bigint;
277
+ readonly loanAssets: bigint;
278
+ readonly maxUnits: bigint;
279
+ readonly taker: Address;
280
+ readonly receiver: Address;
281
+ readonly collateralSupplies: number;
282
+ readonly takeableOffers: number;
283
+ readonly deadline: bigint;
284
+ }> {
285
+ }
286
+ /** Metadata for a direct Midnight collateral-supply transaction. */
287
+ export interface MidnightSupplyCollateralAction extends BaseAction<"midnightSupplyCollateral", {
288
+ readonly market: Hex;
289
+ readonly collateralIndex: bigint;
290
+ readonly assets: bigint;
291
+ readonly onBehalf: Address;
292
+ }> {
293
+ }
294
+ /** Metadata for a Midnight mempool payload submission. */
295
+ export interface MempoolSubmitOffersAction extends BaseAction<"mempoolSubmitOffers", {
296
+ readonly groups: readonly Hex[];
297
+ readonly root: Hex;
298
+ readonly maker: Address;
299
+ readonly ratifier: Address;
300
+ readonly ratifierType: "ecrecover" | "setter";
301
+ readonly offers: number;
302
+ }> {
303
+ }
304
+ /** Metadata for a direct Midnight credit redemption transaction. */
305
+ export interface MidnightRedeemAction extends BaseAction<"midnightRedeem", {
306
+ readonly market: Hex;
307
+ readonly units: bigint;
308
+ readonly onBehalf: Address;
309
+ readonly receiver: Address;
310
+ }> {
311
+ }
312
+ /** Metadata for a Midnight bundle that repays credit and/or withdraws collateral. */
313
+ export interface MidnightRepayWithdrawCollateralAction extends BaseAction<"midnightRepayWithdrawCollateral", {
314
+ readonly market: Hex;
315
+ readonly repayAssets: bigint;
316
+ readonly collateralWithdrawals: number;
317
+ readonly onBehalf: Address;
318
+ readonly collateralReceiver: Address;
319
+ readonly deadline: bigint;
320
+ }> {
321
+ }
322
+ /** Metadata for a direct Midnight offer-cancellation transaction. */
323
+ export interface MidnightCancelOfferAction extends BaseAction<"midnightCancelOffer", {
324
+ readonly group: Hex;
325
+ readonly amount: bigint;
326
+ readonly onBehalf: Address;
327
+ }> {
328
+ }
329
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | SetterRatifierRatifyRootAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MempoolSubmitOffersAction | MidnightRedeemAction | MidnightRepayWithdrawCollateralAction | MidnightCancelOfferAction;
238
330
  export interface Transaction<TAction extends BaseAction = TransactionAction> {
239
331
  readonly to: Address;
240
332
  readonly value: bigint;
@@ -291,17 +383,12 @@ export interface AuthorizationSignatureArgs {
291
383
  /** EIP-712 signature over the Morpho `Authorization` typed data. */
292
384
  signature: Hex;
293
385
  }
294
- /**
295
- * A signable approval / authorization requirement. `sign()` returns the matching
296
- * {@link RequirementSignature}; `action` describes the requirement without signing.
297
- *
298
- * Generic over the signature it produces so permit encoders narrow to
299
- * {@link PermitRequirementSignature} and the authorization encoder to
300
- * {@link AuthorizationRequirementSignature}; the default keeps the broad union for mixed arrays.
301
- */
302
- export interface Requirement<TSignature extends RequirementSignature = RequirementSignature> {
303
- sign: (client: WalletClient, userAddress: Address) => Promise<TSignature>;
304
- action: TSignature["action"];
386
+ /** Signed and encoded Ecrecover offer-root payload used by Midnight maker flows. */
387
+ export interface MidnightOfferRootSignatureArgs {
388
+ readonly owner: Address;
389
+ readonly root: Hex;
390
+ readonly signature: Hex;
391
+ readonly payload: Hex;
305
392
  }
306
393
  export interface PermitAction extends BaseAction<"permit", {
307
394
  spender: Address;
@@ -326,6 +413,17 @@ export interface AuthorizationAction extends BaseAction<"authorization", {
326
413
  deadline: bigint;
327
414
  }> {
328
415
  }
416
+ /** Metadata for a Midnight offer-root signature request. */
417
+ export interface MidnightOfferRootSignatureAction extends BaseAction<"midnightOfferRootSignature", {
418
+ readonly root: Hex;
419
+ readonly ratifier: Address;
420
+ readonly offers: number;
421
+ }> {
422
+ }
423
+ /** Action metadata supported by signature requirements. */
424
+ export type SignatureRequirementAction = PermitAction | Permit2Action | AuthorizationAction | MidnightOfferRootSignatureAction;
425
+ /** Argument payloads returned by signature requirements. */
426
+ export type RequirementSignatureArgs = PermitArgs | Permit2Args | AuthorizationSignatureArgs | MidnightOfferRootSignatureArgs;
329
427
  /** A signed ERC-2612 permit or Permit2 approval requirement. */
330
428
  export interface PermitRequirementSignature {
331
429
  args: PermitArgs | Permit2Args;
@@ -336,18 +434,74 @@ export interface AuthorizationRequirementSignature {
336
434
  args: AuthorizationSignatureArgs;
337
435
  action: AuthorizationAction;
338
436
  }
437
+ /** A signed Midnight Ecrecover offer-root requirement. */
438
+ export interface MidnightOfferRootSignature {
439
+ readonly args: MidnightOfferRootSignatureArgs;
440
+ readonly action: MidnightOfferRootSignatureAction;
441
+ }
339
442
  /**
340
443
  * The deep-frozen output of `Requirement.sign()`. Discriminated on `action.type`:
341
- * `"permit"` / `"permit2"` carry token-approval args, `"authorization"` carries the signed
342
- * Morpho authorization. Narrow with {@link isPermitSignature} / {@link isAuthorizationSignature}.
444
+ * `"permit"` / `"permit2"` carry Bundler3 token-approval args, `"authorization"` carries the
445
+ * signed Morpho authorization, and Midnight adds `"midnightOfferRootSignature"`.
343
446
  */
344
- export type RequirementSignature = PermitRequirementSignature | AuthorizationRequirementSignature;
447
+ export type RequirementSignature<TAction extends SignatureRequirementAction | undefined = undefined, TArgs extends RequirementSignatureArgs | undefined = undefined> = TAction extends SignatureRequirementAction ? TArgs extends RequirementSignatureArgs ? {
448
+ args: TArgs;
449
+ action: TAction;
450
+ } : never : PermitRequirementSignature | AuthorizationRequirementSignature | MidnightOfferRootSignature;
451
+ type RequirementResult<TSignatureOrAction extends RequirementSignature | SignatureRequirementAction, TArgs extends RequirementSignatureArgs | undefined> = TSignatureOrAction extends SignatureRequirementAction ? RequirementSignature<TSignatureOrAction, Extract<TArgs, RequirementSignatureArgs>> : Extract<TSignatureOrAction, RequirementSignature>;
452
+ /**
453
+ * A signable approval / authorization requirement. `sign()` returns the matching
454
+ * {@link RequirementSignature}; `action` describes the requirement without signing.
455
+ *
456
+ * Generic over the signature it produces so permit encoders narrow to
457
+ * {@link PermitRequirementSignature} and the authorization encoder to
458
+ * {@link AuthorizationRequirementSignature}; the two-parameter form is kept for
459
+ * Midnight action requirements that are parameterized by action and args.
460
+ */
461
+ export interface Requirement<TSignatureOrAction extends RequirementSignature | SignatureRequirementAction = RequirementSignature, TArgs extends RequirementSignatureArgs | undefined = undefined> {
462
+ sign: (client: WalletClient, userAddress: Address) => Promise<RequirementResult<TSignatureOrAction, TArgs>>;
463
+ action: RequirementResult<TSignatureOrAction, TArgs>["action"];
464
+ }
345
465
  /** Bundler3 token signature requirement. */
346
466
  export type Bundler3TokenSignatureRequirement = Requirement<PermitRequirementSignature>;
467
+ /** Midnight Ecrecover offer-root signature requirement. */
468
+ export type MidnightOfferRootRequirement = Requirement<MidnightOfferRootSignatureAction, MidnightOfferRootSignatureArgs>;
469
+ /** Permit or Permit2 token signature requirement. */
470
+ export type TokenSignatureRequirement = Bundler3TokenSignatureRequirement;
471
+ /** Bundler3 token signature result. */
472
+ export type Bundler3TokenRequirementSignature = PermitRequirementSignature;
473
+ /** Permit or Permit2 token signature result. */
474
+ export type TokenRequirementSignature = Bundler3TokenRequirementSignature;
475
+ /** Any signature result returned by an action-output signature requirement. */
476
+ export type AnyRequirementSignature = TokenRequirementSignature | AuthorizationRequirementSignature | MidnightOfferRootSignature;
477
+ /** Any signature requirement returned by an entity action output. */
478
+ export type SignatureRequirement = TokenSignatureRequirement | MidnightOfferRootRequirement | Requirement<AuthorizationRequirementSignature>;
479
+ /** Call action metadata that can appear as an action prerequisite. */
480
+ export type CallRequirementAction = ERC20ApprovalAction | BlueAuthorizationAction | MidnightAuthorizationAction | SetterRatifierRatifyRootAction | MidnightSupplyCollateralAction;
481
+ /** Onchain call prerequisite returned by action-output `getRequirements()`. */
482
+ export type CallRequirement = Readonly<Transaction<CallRequirementAction>>;
483
+ /** Onchain call or signature prerequisite returned by an entity action output. */
484
+ export type ActionRequirement = CallRequirement | SignatureRequirement;
485
+ /** Optional controls used while resolving action prerequisites. */
486
+ interface ActionRequirementsParams {
487
+ /**
488
+ * Prefer the ERC-2612 simple-permit path when the SDK detects support.
489
+ * Leave unset or set to `false` to force the Permit2/classic approval fallback when
490
+ * a token is known to be incompatible despite passing the SDK's shallow nonce probe.
491
+ */
492
+ readonly useSimplePermit?: boolean;
493
+ }
494
+ /** Lazy entity result exposing prerequisite resolution and synchronous transaction building. */
495
+ export interface ActionOutput<TAction extends BaseAction = TransactionAction, TSignatures = RequirementSignature, TRequirementsParams = ActionRequirementsParams> {
496
+ readonly buildTx: (signatures?: TSignatures) => Readonly<Transaction<TAction>>;
497
+ readonly getRequirements: (params?: TRequirementsParams) => Promise<readonly ActionRequirement[]>;
498
+ }
347
499
  export declare function isRequirementApproval(requirement: unknown): requirement is Transaction<ERC20ApprovalAction>;
348
- /** Checks whether an action requirement is a Blue authorization transaction. */
500
+ /** Checks whether an action requirement is a Blue authorization call. */
349
501
  export declare function isRequirementBlueAuthorization(requirement: unknown): requirement is Transaction<BlueAuthorizationAction>;
350
- export declare function isRequirementSignature<T extends RequirementSignature = RequirementSignature>(requirement: Transaction<ERC20ApprovalAction> | Transaction<BlueAuthorizationAction> | Requirement<T> | undefined): requirement is Requirement<T>;
502
+ export declare function isRequirementSignature<T extends RequirementSignature = RequirementSignature>(requirement: CallRequirement | Requirement<T> | undefined): requirement is Requirement<T>;
503
+ export declare function isRequirementSignature(requirement: CallRequirement | Requirement | undefined): requirement is Requirement;
504
+ export declare function isRequirementSignature(requirement: ActionRequirement | undefined): requirement is SignatureRequirement;
351
505
  /**
352
506
  * Narrows a {@link RequirementSignature} to a permit / Permit2 token-approval signature.
353
507
  *
@@ -362,26 +516,36 @@ export declare function isPermitSignature(signature: RequirementSignature): sign
362
516
  * @returns `true` when `signature.action.type` is `"authorization"`.
363
517
  */
364
518
  export declare function isAuthorizationSignature(signature: RequirementSignature): signature is AuthorizationRequirementSignature;
365
- /** The typed permit / authorization slots a bundled path consumes, split from a `buildTx` array. */
519
+ /**
520
+ * Narrows a {@link RequirementSignature} to a Midnight offer-root signature.
521
+ *
522
+ * @param signature - The signed requirement to test.
523
+ * @returns `true` when `signature.action.type` is `"midnightOfferRootSignature"`.
524
+ */
525
+ export declare function isMidnightOfferRootSignature(signature: RequirementSignature): signature is MidnightOfferRootSignature;
526
+ /** The typed requirement-signature slots a transaction builder consumes, split from a `buildTx` array. */
366
527
  export interface SelectedRequirementSignatures {
367
528
  /** The single permit / Permit2 signature, when present. */
368
529
  permit?: PermitRequirementSignature;
369
530
  /** The single Morpho authorization signature, when present. */
370
531
  authorization?: AuthorizationRequirementSignature;
532
+ /** The single Midnight offer-root signature, when present. */
533
+ midnightOfferRoot?: MidnightOfferRootSignature;
371
534
  }
372
535
  /**
373
- * Splits a `buildTx` signature array into its typed permit / authorization slots, rejecting
536
+ * Splits a `buildTx` signature array into its typed requirement-signature slots, rejecting
374
537
  * ambiguous or unexpected input so a path never silently consumes the wrong signature.
375
538
  *
376
- * A bundled path consumes at most one permit and one authorization signature. Passing several of
377
- * the same kind, or a kind the path does not consume, is rejected with a typed error rather than
378
- * silently dropping the extras — the latter could otherwise leave a required authorization or
379
- * permit unsigned (and the bundle reverting on-chain) or apply the wrong signature.
539
+ * A bundled path consumes at most one signature of each accepted kind. Passing several of the same
540
+ * kind, or a kind the path does not consume, is rejected with a typed error rather than silently
541
+ * dropping the extras — the latter could otherwise leave a required authorization or permit
542
+ * unsigned (and the bundle reverting on-chain) or apply the wrong signature.
380
543
  *
381
544
  * @param signatures - The signatures passed to `buildTx`.
382
545
  * @param accepts - Which signature kinds this operation consumes.
383
546
  * @param accepts.permit - Whether a permit / Permit2 signature is consumed.
384
547
  * @param accepts.authorization - Whether a Morpho authorization signature is consumed.
548
+ * @param accepts.midnightOfferRoot - Whether a Midnight offer-root signature is consumed.
385
549
  * @returns The single permit and/or authorization signature, when present.
386
550
  * @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
387
551
  * @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
@@ -398,4 +562,6 @@ export interface SelectedRequirementSignatures {
398
562
  export declare function selectRequirementSignatures(signatures: readonly RequirementSignature[] | undefined, accepts: {
399
563
  permit?: boolean;
400
564
  authorization?: boolean;
565
+ midnightOfferRoot?: boolean;
401
566
  }): SelectedRequirementSignatures;
567
+ export {};
@@ -11,7 +11,7 @@ export function isRequirementApproval(requirement) {
11
11
  "type" in requirement.action &&
12
12
  requirement.action.type === "erc20Approval");
13
13
  }
14
- /** Checks whether an action requirement is a Blue authorization transaction. */
14
+ /** Checks whether an action requirement is a Blue authorization call. */
15
15
  export function isRequirementBlueAuthorization(requirement) {
16
16
  return (typeof requirement === "object" &&
17
17
  requirement !== null &&
@@ -50,18 +50,28 @@ export function isAuthorizationSignature(signature) {
50
50
  return signature.action.type === "authorization";
51
51
  }
52
52
  /**
53
- * Splits a `buildTx` signature array into its typed permit / authorization slots, rejecting
53
+ * Narrows a {@link RequirementSignature} to a Midnight offer-root signature.
54
+ *
55
+ * @param signature - The signed requirement to test.
56
+ * @returns `true` when `signature.action.type` is `"midnightOfferRootSignature"`.
57
+ */
58
+ export function isMidnightOfferRootSignature(signature) {
59
+ return signature.action.type === "midnightOfferRootSignature";
60
+ }
61
+ /**
62
+ * Splits a `buildTx` signature array into its typed requirement-signature slots, rejecting
54
63
  * ambiguous or unexpected input so a path never silently consumes the wrong signature.
55
64
  *
56
- * A bundled path consumes at most one permit and one authorization signature. Passing several of
57
- * the same kind, or a kind the path does not consume, is rejected with a typed error rather than
58
- * silently dropping the extras — the latter could otherwise leave a required authorization or
59
- * permit unsigned (and the bundle reverting on-chain) or apply the wrong signature.
65
+ * A bundled path consumes at most one signature of each accepted kind. Passing several of the same
66
+ * kind, or a kind the path does not consume, is rejected with a typed error rather than silently
67
+ * dropping the extras — the latter could otherwise leave a required authorization or permit
68
+ * unsigned (and the bundle reverting on-chain) or apply the wrong signature.
60
69
  *
61
70
  * @param signatures - The signatures passed to `buildTx`.
62
71
  * @param accepts - Which signature kinds this operation consumes.
63
72
  * @param accepts.permit - Whether a permit / Permit2 signature is consumed.
64
73
  * @param accepts.authorization - Whether a Morpho authorization signature is consumed.
74
+ * @param accepts.midnightOfferRoot - Whether a Midnight offer-root signature is consumed.
65
75
  * @returns The single permit and/or authorization signature, when present.
66
76
  * @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
67
77
  * @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
@@ -80,13 +90,22 @@ export function selectRequirementSignatures(signatures, accepts) {
80
90
  return {};
81
91
  const permits = signatures.filter(isPermitSignature);
82
92
  const authorizations = signatures.filter(isAuthorizationSignature);
93
+ const midnightOfferRoots = signatures.filter(isMidnightOfferRootSignature);
83
94
  if (!accepts.permit && permits.length > 0)
84
95
  throw new UnexpectedRequirementSignatureError("permit");
85
96
  if (!accepts.authorization && authorizations.length > 0)
86
97
  throw new UnexpectedRequirementSignatureError("authorization");
98
+ if (!accepts.midnightOfferRoot && midnightOfferRoots.length > 0)
99
+ throw new UnexpectedRequirementSignatureError("midnightOfferRootSignature");
87
100
  if (permits.length > 1)
88
101
  throw new AmbiguousRequirementSignaturesError("permit", permits.length);
89
102
  if (authorizations.length > 1)
90
103
  throw new AmbiguousRequirementSignaturesError("authorization", authorizations.length);
91
- return { permit: permits[0], authorization: authorizations[0] };
104
+ if (midnightOfferRoots.length > 1)
105
+ throw new AmbiguousRequirementSignaturesError("midnightOfferRootSignature", midnightOfferRoots.length);
106
+ return {
107
+ permit: permits[0],
108
+ authorization: authorizations[0],
109
+ midnightOfferRoot: midnightOfferRoots[0],
110
+ };
92
111
  }
@@ -1,11 +1,11 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address, Client } from "viem";
3
- import type { BlueActions, VaultV1Actions, VaultV2Actions } from "../actions/index.js";
3
+ import type { BlueActions, MidnightActions, VaultV1Actions, VaultV2Actions } from "../actions/index.js";
4
4
  import type { Metadata } from "./index.js";
5
5
  /**
6
6
  * Structural contract the `morpho` namespace satisfies — the object exposed under `client.morpho`
7
7
  * once a viem client is extended with {@link morphoViemExtension}. Carries the viem client, the
8
- * resolved options bag, and the three entity-factory methods the SDK exposes.
8
+ * resolved options bag, and the four entity-factory methods the SDK exposes.
9
9
  */
10
10
  export interface MorphoClientType {
11
11
  readonly viemClient: Client;
@@ -17,4 +17,5 @@ export interface MorphoClientType {
17
17
  vaultV1: (vault: Address, chainId: number) => VaultV1Actions;
18
18
  vaultV2: (vault: Address, chainId: number) => VaultV2Actions;
19
19
  blue: (marketParams: MarketParams, chainId: number) => BlueActions;
20
+ midnight: (chainId: number) => MidnightActions;
20
21
  }