@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,117 @@
1
+ import { MarketUtils, midnightBundlesAbi, } from "@morpho-org/midnight-sdk";
2
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData, zeroAddress } from "viem";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
6
+ import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
7
+ import { PermitKind } from "./types.js";
8
+ /**
9
+ * Encodes a Midnight bundle that repays debt, withdraws collateral, or both.
10
+ *
11
+ * Prefer `client.morpho.midnight(chainId).repayWithdrawCollateral(...)` in app
12
+ * flows so loan-token approval and Midnight authorization requirements are
13
+ * resolved first. Use this low-level builder only when those requirements and
14
+ * collateral-index checks are already handled by the caller.
15
+ *
16
+ * @param params.chainId - Chain id used to resolve `MidnightBundles`.
17
+ * @param params.market - Midnight market whose position is updated.
18
+ * @param params.repayAssets - Loan assets repaid; may be zero when only withdrawing collateral.
19
+ * @param params.withdrawCollateralAssets - Collateral assets withdrawn; may be zero when only repaying.
20
+ * @param params.onBehalf - Position owner.
21
+ * @param params.collateralIndex - Optional collateral index for withdrawal; defaults to `0n`.
22
+ * @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
23
+ * @param params.metadata - Optional analytics metadata appended to calldata.
24
+ * @returns A deep-frozen `Transaction<MidnightRepayWithdrawCollateralAction>` targeting `MidnightBundles`.
25
+ * @throws {NegativeInputError} when any amount, collateral index, or deadline is negative.
26
+ * @throws {NonPositiveInputError} when both repay and withdrawal amounts are zero.
27
+ * @throws {ChainIdMismatchError} when the market targets another chain.
28
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
29
+ * @throws {UnknownCollateralIndexError} when a positive withdrawal targets an unconfigured collateral index.
30
+ * @example
31
+ * ```ts
32
+ * import { maxUint256 } from "viem";
33
+ * import { midnightRepayWithdrawCollateral } from "@morpho-org/morpho-sdk";
34
+ *
35
+ * const tx = midnightRepayWithdrawCollateral({
36
+ * chainId: 8453,
37
+ * market: marketData.params,
38
+ * repayAssets: 1_000_000n,
39
+ * withdrawCollateralAssets: 0n,
40
+ * onBehalf: user,
41
+ * deadline: maxUint256,
42
+ * });
43
+ * ```
44
+ */
45
+ export const midnightRepayWithdrawCollateral = (params) => {
46
+ if (params.repayAssets < 0n) {
47
+ throw new NegativeInputError("repayAssets", params.repayAssets);
48
+ }
49
+ if (params.withdrawCollateralAssets < 0n) {
50
+ throw new NegativeInputError("withdrawCollateralAssets", params.withdrawCollateralAssets);
51
+ }
52
+ if (params.deadline < 0n) {
53
+ throw new NegativeInputError("deadline", params.deadline);
54
+ }
55
+ const collateralWithdrawals = params.withdrawCollateralAssets > 0n
56
+ ? [
57
+ {
58
+ collateralIndex: params.collateralIndex ?? 0n,
59
+ assets: params.withdrawCollateralAssets,
60
+ },
61
+ ]
62
+ : [];
63
+ for (const [index, withdrawal] of collateralWithdrawals.entries()) {
64
+ if (withdrawal.collateralIndex < 0n) {
65
+ throw new NegativeInputError(`collateralWithdrawals[${index}].collateralIndex`, withdrawal.collateralIndex);
66
+ }
67
+ }
68
+ if (params.repayAssets === 0n &&
69
+ collateralWithdrawals.every((withdrawal) => withdrawal.assets === 0n)) {
70
+ throw new NonPositiveInputError("repay or withdraw amount", 0n);
71
+ }
72
+ // Reject markets from another chain deployment before encoding the bundle.
73
+ validateMidnightMarket({ market: params.market, chainId: params.chainId });
74
+ const marketId = MarketUtils.toId(params.market);
75
+ const market = MarketUtils.toStruct(params.market);
76
+ for (const withdrawal of collateralWithdrawals) {
77
+ // Validate that every withdrawal targets a configured collateral.
78
+ MarketUtils.getCollateralByIndex(market, withdrawal.collateralIndex);
79
+ }
80
+ const midnightBundles = getChainAddress(params.chainId, "midnightBundles");
81
+ let tx = {
82
+ to: midnightBundles,
83
+ value: 0n,
84
+ data: encodeFunctionData({
85
+ abi: midnightBundlesAbi,
86
+ functionName: "midnightBundlesV1RepayAndWithdrawCollateral",
87
+ args: [
88
+ market,
89
+ params.repayAssets,
90
+ params.onBehalf,
91
+ { kind: PermitKind.None, data: "0x" },
92
+ collateralWithdrawals,
93
+ params.onBehalf,
94
+ 0n,
95
+ zeroAddress,
96
+ params.deadline,
97
+ ],
98
+ }),
99
+ };
100
+ if (params.metadata) {
101
+ tx = addTransactionMetadata(tx, params.metadata);
102
+ }
103
+ return deepFreeze({
104
+ ...tx,
105
+ action: {
106
+ type: "midnightRepayWithdrawCollateral",
107
+ args: {
108
+ market: marketId,
109
+ repayAssets: params.repayAssets,
110
+ collateralWithdrawals: collateralWithdrawals.length,
111
+ onBehalf: params.onBehalf,
112
+ collateralReceiver: params.onBehalf,
113
+ deadline: params.deadline,
114
+ },
115
+ },
116
+ });
117
+ };
@@ -0,0 +1,40 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import type { Metadata, SetterRatifierRatifyRootAction, Transaction } from "../../types/index.js";
3
+ /** Parameters for {@link setterRatifierRatifyRoot}. */
4
+ export interface SetterRatifierRatifyRootParams {
5
+ /** Chain id used to resolve the SetterRatifier deployment. */
6
+ readonly chainId: number;
7
+ /** Maker whose offer-tree root is being ratified. */
8
+ readonly maker: Address;
9
+ /** Offer-tree root to ratify or unratify. */
10
+ readonly root: Hex;
11
+ /** Whether the root should be ratified. Defaults to `true`. */
12
+ readonly isRootRatified?: boolean;
13
+ /** Optional metadata appended to the transaction calldata. */
14
+ readonly metadata?: Metadata;
15
+ }
16
+ /**
17
+ * Encodes a SetterRatifier root-ratification transaction.
18
+ *
19
+ * Use this after building a Setter-ratified offer tree and before submitting
20
+ * its mempool payload. Entity make-offer flows expose the same transaction
21
+ * through `getRequirements()` when the root is not already approved.
22
+ *
23
+ * @param params.chainId - Chain id used to resolve `SetterRatifier`.
24
+ * @param params.maker - Maker whose root approval is updated.
25
+ * @param params.root - Offer-tree root to approve or revoke.
26
+ * @param params.isRootRatified - Optional target state; defaults to `true`.
27
+ * @param params.metadata - Optional analytics metadata appended to calldata.
28
+ * @returns A deep-frozen `Transaction<SetterRatifierRatifyRootAction>` targeting `SetterRatifier`.
29
+ * @example
30
+ * ```ts
31
+ * import { setterRatifierRatifyRoot } from "@morpho-org/morpho-sdk";
32
+ *
33
+ * const tx = setterRatifierRatifyRoot({
34
+ * chainId: 8453,
35
+ * maker,
36
+ * root,
37
+ * });
38
+ * ```
39
+ */
40
+ export declare const setterRatifierRatifyRoot: (params: SetterRatifierRatifyRootParams) => Readonly<Transaction<SetterRatifierRatifyRootAction>>;
@@ -0,0 +1,55 @@
1
+ import { setterRatifierAbi } from "@morpho-org/midnight-sdk";
2
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData } from "viem";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ /**
6
+ * Encodes a SetterRatifier root-ratification transaction.
7
+ *
8
+ * Use this after building a Setter-ratified offer tree and before submitting
9
+ * its mempool payload. Entity make-offer flows expose the same transaction
10
+ * through `getRequirements()` when the root is not already approved.
11
+ *
12
+ * @param params.chainId - Chain id used to resolve `SetterRatifier`.
13
+ * @param params.maker - Maker whose root approval is updated.
14
+ * @param params.root - Offer-tree root to approve or revoke.
15
+ * @param params.isRootRatified - Optional target state; defaults to `true`.
16
+ * @param params.metadata - Optional analytics metadata appended to calldata.
17
+ * @returns A deep-frozen `Transaction<SetterRatifierRatifyRootAction>` targeting `SetterRatifier`.
18
+ * @example
19
+ * ```ts
20
+ * import { setterRatifierRatifyRoot } from "@morpho-org/morpho-sdk";
21
+ *
22
+ * const tx = setterRatifierRatifyRoot({
23
+ * chainId: 8453,
24
+ * maker,
25
+ * root,
26
+ * });
27
+ * ```
28
+ */
29
+ export const setterRatifierRatifyRoot = (params) => {
30
+ const isRootRatified = params.isRootRatified ?? true;
31
+ const setterRatifier = getChainAddress(params.chainId, "setterRatifier");
32
+ let tx = {
33
+ to: setterRatifier,
34
+ value: 0n,
35
+ data: encodeFunctionData({
36
+ abi: setterRatifierAbi,
37
+ functionName: "setIsRootRatified",
38
+ args: [params.maker, params.root, isRootRatified],
39
+ }),
40
+ };
41
+ if (params.metadata) {
42
+ tx = addTransactionMetadata(tx, params.metadata);
43
+ }
44
+ return deepFreeze({
45
+ ...tx,
46
+ action: {
47
+ type: "setterRatifierRatifyRoot",
48
+ args: {
49
+ maker: params.maker,
50
+ root: params.root,
51
+ isRootRatified,
52
+ },
53
+ },
54
+ });
55
+ };
@@ -0,0 +1,45 @@
1
+ import { type MarketInput } from "@morpho-org/midnight-sdk";
2
+ import { type Address } from "viem";
3
+ import { type Metadata, type MidnightSupplyCollateralAction, type Transaction } from "../../types/index.js";
4
+ /** Parameters for encoding a direct Midnight collateral supply. */
5
+ export interface MidnightSupplyCollateralParams {
6
+ readonly chainId: number;
7
+ readonly market: MarketInput;
8
+ readonly collateralIndex?: bigint;
9
+ readonly assets: bigint;
10
+ readonly onBehalf: Address;
11
+ readonly metadata?: Metadata;
12
+ }
13
+ /**
14
+ * Encodes a direct Midnight collateral supply.
15
+ *
16
+ * Use this low-level builder when a flow already knows the market, collateral
17
+ * index, and approval state. App flows should usually call
18
+ * `client.morpho.midnight(chainId).supplyCollateral(...)`, which resolves the
19
+ * ERC20 approval requirement before exposing `buildTx`.
20
+ *
21
+ * @param params.chainId - Chain id used to resolve `Midnight`.
22
+ * @param params.market - Midnight market receiving collateral.
23
+ * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
24
+ * @param params.assets - Collateral assets to supply.
25
+ * @param params.onBehalf - Account whose collateral balance increases.
26
+ * @param params.metadata - Optional analytics metadata appended to calldata.
27
+ * @returns A deep-frozen `Transaction<MidnightSupplyCollateralAction>` targeting `Midnight`.
28
+ * @throws {NonPositiveInputError} when `assets <= 0n`.
29
+ * @throws {ChainIdMismatchError} when the market targets another chain.
30
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
31
+ * @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
32
+ * @example
33
+ * ```ts
34
+ * import { midnightSupplyCollateral } from "@morpho-org/morpho-sdk";
35
+ *
36
+ * const tx = midnightSupplyCollateral({
37
+ * chainId: 8453,
38
+ * market: marketData.params,
39
+ * collateralIndex: 0n,
40
+ * assets: 2_000_000n,
41
+ * onBehalf: user,
42
+ * });
43
+ * ```
44
+ */
45
+ export declare const midnightSupplyCollateral: (params: MidnightSupplyCollateralParams) => Readonly<Transaction<MidnightSupplyCollateralAction>>;
@@ -0,0 +1,79 @@
1
+ import { MarketUtils, midnightAbi, } from "@morpho-org/midnight-sdk";
2
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData } from "viem";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
6
+ import { NonPositiveInputError, } from "../../types/index.js";
7
+ /**
8
+ * Encodes a direct Midnight collateral supply.
9
+ *
10
+ * Use this low-level builder when a flow already knows the market, collateral
11
+ * index, and approval state. App flows should usually call
12
+ * `client.morpho.midnight(chainId).supplyCollateral(...)`, which resolves the
13
+ * ERC20 approval requirement before exposing `buildTx`.
14
+ *
15
+ * @param params.chainId - Chain id used to resolve `Midnight`.
16
+ * @param params.market - Midnight market receiving collateral.
17
+ * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
18
+ * @param params.assets - Collateral assets to supply.
19
+ * @param params.onBehalf - Account whose collateral balance increases.
20
+ * @param params.metadata - Optional analytics metadata appended to calldata.
21
+ * @returns A deep-frozen `Transaction<MidnightSupplyCollateralAction>` targeting `Midnight`.
22
+ * @throws {NonPositiveInputError} when `assets <= 0n`.
23
+ * @throws {ChainIdMismatchError} when the market targets another chain.
24
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
25
+ * @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
26
+ * @example
27
+ * ```ts
28
+ * import { midnightSupplyCollateral } from "@morpho-org/morpho-sdk";
29
+ *
30
+ * const tx = midnightSupplyCollateral({
31
+ * chainId: 8453,
32
+ * market: marketData.params,
33
+ * collateralIndex: 0n,
34
+ * assets: 2_000_000n,
35
+ * onBehalf: user,
36
+ * });
37
+ * ```
38
+ */
39
+ export const midnightSupplyCollateral = (params) => {
40
+ if (params.assets <= 0n) {
41
+ throw new NonPositiveInputError("assets", params.assets);
42
+ }
43
+ // Reject markets from another chain deployment before encoding the call.
44
+ validateMidnightMarket({ market: params.market, chainId: params.chainId });
45
+ const marketId = MarketUtils.toId(params.market);
46
+ const midnight = getChainAddress(params.chainId, "midnight");
47
+ const collateralIndex = params.collateralIndex ?? 0n;
48
+ // Validate that the supplied collateral index is configured before encoding.
49
+ MarketUtils.getCollateralByIndex(params.market, collateralIndex);
50
+ let tx = {
51
+ to: midnight,
52
+ value: 0n,
53
+ data: encodeFunctionData({
54
+ abi: midnightAbi,
55
+ functionName: "supplyCollateral",
56
+ args: [
57
+ MarketUtils.toStruct(params.market),
58
+ collateralIndex,
59
+ params.assets,
60
+ params.onBehalf,
61
+ ],
62
+ }),
63
+ };
64
+ if (params.metadata) {
65
+ tx = addTransactionMetadata(tx, params.metadata);
66
+ }
67
+ return deepFreeze({
68
+ ...tx,
69
+ action: {
70
+ type: "midnightSupplyCollateral",
71
+ args: {
72
+ market: marketId,
73
+ collateralIndex,
74
+ assets: params.assets,
75
+ onBehalf: params.onBehalf,
76
+ },
77
+ },
78
+ });
79
+ };
@@ -0,0 +1,51 @@
1
+ import { type MidnightSupplyCollateralTakeBorrowAction, type Transaction } from "../../types/index.js";
2
+ import type { MidnightTakeBorrowParams } from "./takeBorrow.js";
3
+ /** Parameters for encoding a collateral supply followed by a Midnight borrow take. */
4
+ export interface MidnightSupplyCollateralTakeBorrowParams extends MidnightTakeBorrowParams {
5
+ readonly collateralAssets: bigint;
6
+ readonly collateralIndex?: bigint;
7
+ }
8
+ /**
9
+ * Encodes a Midnight bundle that supplies collateral and borrows in one call.
10
+ *
11
+ * Prefer `client.morpho.midnight(chainId).supplyCollateralTakeBorrow(...)` in
12
+ * app flows so collateral approval and Midnight authorization requirements are
13
+ * resolved before building the bundle. Use this low-level builder only after
14
+ * market data and API takeable offers are already available.
15
+ *
16
+ * @param params.chainId - Chain id used to resolve `MidnightBundles`.
17
+ * @param params.market - Midnight market traded by every takeable offer.
18
+ * @param params.loanAssets - Loan assets the borrower receives.
19
+ * @param params.maxUnits - Maximum debt units accepted from the bundle quote.
20
+ * @param params.taker - Borrower address executing the bundle.
21
+ * @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
22
+ * @param params.takeableOffers - ABI-ready lend-side offers returned by the Midnight API.
23
+ * @param params.collateralAssets - Collateral assets supplied before taking offers.
24
+ * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
25
+ * @returns A deep-frozen `Transaction<MidnightSupplyCollateralTakeBorrowAction>` targeting `MidnightBundles`.
26
+ * @throws {NonPositiveInputError} when collateral assets, loan assets, or `maxUnits` are non-positive.
27
+ * @throws {NegativeInputError} when `deadline` is negative.
28
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
29
+ * @throws {MidnightOfferSideMismatchError} when any offer is not lend-side.
30
+ * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
31
+ * @throws {ChainIdMismatchError} when the market targets another chain.
32
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
33
+ * @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
34
+ * @example
35
+ * ```ts
36
+ * import { maxUint256 } from "viem";
37
+ * import { midnightSupplyCollateralTakeBorrow } from "@morpho-org/morpho-sdk";
38
+ *
39
+ * const tx = midnightSupplyCollateralTakeBorrow({
40
+ * chainId: 8453,
41
+ * market: marketData.params,
42
+ * collateralAssets: 2_000_000n,
43
+ * loanAssets: BigInt(quote.data.availableAssets),
44
+ * maxUnits: BigInt(quote.data.availableUnits),
45
+ * taker: borrower,
46
+ * takeableOffers: quote.data.takeableOffers,
47
+ * deadline: maxUint256,
48
+ * });
49
+ * ```
50
+ */
51
+ export declare const midnightSupplyCollateralTakeBorrow: (params: MidnightSupplyCollateralTakeBorrowParams) => Readonly<Transaction<MidnightSupplyCollateralTakeBorrowAction>>;
@@ -0,0 +1,124 @@
1
+ import { MarketUtils, midnightBundlesAbi } from "@morpho-org/midnight-sdk";
2
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData, maxUint256, zeroAddress } from "viem";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
6
+ import { validateTakeableOffers } from "../../helpers/validateTakeableOffers.js";
7
+ import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
8
+ import { PermitKind } from "./types.js";
9
+ /**
10
+ * Encodes a Midnight bundle that supplies collateral and borrows in one call.
11
+ *
12
+ * Prefer `client.morpho.midnight(chainId).supplyCollateralTakeBorrow(...)` in
13
+ * app flows so collateral approval and Midnight authorization requirements are
14
+ * resolved before building the bundle. Use this low-level builder only after
15
+ * market data and API takeable offers are already available.
16
+ *
17
+ * @param params.chainId - Chain id used to resolve `MidnightBundles`.
18
+ * @param params.market - Midnight market traded by every takeable offer.
19
+ * @param params.loanAssets - Loan assets the borrower receives.
20
+ * @param params.maxUnits - Maximum debt units accepted from the bundle quote.
21
+ * @param params.taker - Borrower address executing the bundle.
22
+ * @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
23
+ * @param params.takeableOffers - ABI-ready lend-side offers returned by the Midnight API.
24
+ * @param params.collateralAssets - Collateral assets supplied before taking offers.
25
+ * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
26
+ * @returns A deep-frozen `Transaction<MidnightSupplyCollateralTakeBorrowAction>` targeting `MidnightBundles`.
27
+ * @throws {NonPositiveInputError} when collateral assets, loan assets, or `maxUnits` are non-positive.
28
+ * @throws {NegativeInputError} when `deadline` is negative.
29
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
30
+ * @throws {MidnightOfferSideMismatchError} when any offer is not lend-side.
31
+ * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
32
+ * @throws {ChainIdMismatchError} when the market targets another chain.
33
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
34
+ * @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
35
+ * @example
36
+ * ```ts
37
+ * import { maxUint256 } from "viem";
38
+ * import { midnightSupplyCollateralTakeBorrow } from "@morpho-org/morpho-sdk";
39
+ *
40
+ * const tx = midnightSupplyCollateralTakeBorrow({
41
+ * chainId: 8453,
42
+ * market: marketData.params,
43
+ * collateralAssets: 2_000_000n,
44
+ * loanAssets: BigInt(quote.data.availableAssets),
45
+ * maxUnits: BigInt(quote.data.availableUnits),
46
+ * taker: borrower,
47
+ * takeableOffers: quote.data.takeableOffers,
48
+ * deadline: maxUint256,
49
+ * });
50
+ * ```
51
+ */
52
+ export const midnightSupplyCollateralTakeBorrow = (params) => {
53
+ if (params.collateralAssets <= 0n) {
54
+ throw new NonPositiveInputError("collateralAssets", params.collateralAssets);
55
+ }
56
+ if (params.loanAssets <= 0n) {
57
+ throw new NonPositiveInputError("loanAssets", params.loanAssets);
58
+ }
59
+ if (params.maxUnits <= 0n) {
60
+ throw new NonPositiveInputError("maxUnits", params.maxUnits);
61
+ }
62
+ if (params.deadline < 0n) {
63
+ throw new NegativeInputError("deadline", params.deadline);
64
+ }
65
+ // Reject markets from another chain deployment before encoding the bundle.
66
+ validateMidnightMarket({ market: params.market, chainId: params.chainId });
67
+ const marketId = validateTakeableOffers({
68
+ market: params.market,
69
+ takeableOffers: params.takeableOffers,
70
+ expectedBuy: true,
71
+ });
72
+ const midnightBundles = getChainAddress(params.chainId, "midnightBundles");
73
+ const collateralIndex = params.collateralIndex ?? 0n;
74
+ // Validate that the collateral index is configured before encoding the bundle.
75
+ MarketUtils.getCollateralByIndex(params.market, collateralIndex);
76
+ const collateralSupplies = [
77
+ {
78
+ collateralIndex,
79
+ assets: params.collateralAssets,
80
+ permit: { kind: PermitKind.None, data: "0x" },
81
+ },
82
+ ];
83
+ let tx = {
84
+ to: midnightBundles,
85
+ value: 0n,
86
+ data: encodeFunctionData({
87
+ abi: midnightBundlesAbi,
88
+ functionName: "midnightBundlesV1SupplyCollateralAndSellWithAssetsTarget",
89
+ args: [
90
+ params.loanAssets,
91
+ params.maxUnits,
92
+ params.taker,
93
+ false,
94
+ params.taker,
95
+ collateralSupplies,
96
+ params.takeableOffers,
97
+ 0n,
98
+ zeroAddress,
99
+ maxUint256,
100
+ params.deadline,
101
+ ],
102
+ }),
103
+ };
104
+ if (params.metadata) {
105
+ tx = addTransactionMetadata(tx, params.metadata);
106
+ }
107
+ return deepFreeze({
108
+ ...tx,
109
+ action: {
110
+ type: "midnightSupplyCollateralTakeBorrow",
111
+ args: {
112
+ market: marketId,
113
+ collateralAssets: params.collateralAssets,
114
+ loanAssets: params.loanAssets,
115
+ maxUnits: params.maxUnits,
116
+ taker: params.taker,
117
+ receiver: params.taker,
118
+ collateralSupplies: collateralSupplies.length,
119
+ takeableOffers: params.takeableOffers.length,
120
+ deadline: params.deadline,
121
+ },
122
+ },
123
+ });
124
+ };
@@ -0,0 +1,57 @@
1
+ import { type MarketInput } from "@morpho-org/midnight-sdk";
2
+ import { type Address } from "viem";
3
+ import { type Metadata, type MidnightTakeBorrowAction, type Transaction } from "../../types/index.js";
4
+ import type { MidnightTakeableOffer } from "./types.js";
5
+ /** Parameters for encoding a Midnight borrow take from already selected offers. */
6
+ export interface MidnightTakeBorrowParams {
7
+ readonly chainId: number;
8
+ readonly market: MarketInput;
9
+ readonly loanAssets: bigint;
10
+ readonly maxUnits: bigint;
11
+ readonly taker: Address;
12
+ /** Bundle execution deadline timestamp. Pass `maxUint256` explicitly for no expiry. */
13
+ readonly deadline: bigint;
14
+ readonly takeableOffers: readonly MidnightTakeableOffer[];
15
+ readonly metadata?: Metadata;
16
+ }
17
+ /**
18
+ * Encodes a Midnight bundle that borrows loan assets by taking lend-side offers.
19
+ *
20
+ * Prefer `client.morpho.midnight(chainId).takeBorrow(...)` in app flows so
21
+ * authorization requirements are resolved first. Use this low-level builder
22
+ * only after the Midnight API has returned takeable offers and the caller has
23
+ * already handled prerequisites.
24
+ *
25
+ * @param params.chainId - Chain id used to resolve `MidnightBundles`.
26
+ * @param params.market - Midnight market traded by every takeable offer.
27
+ * @param params.loanAssets - Loan assets the borrower receives.
28
+ * @param params.maxUnits - Maximum debt units accepted from the bundle quote.
29
+ * @param params.taker - Borrower address executing the bundle.
30
+ * @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
31
+ * @param params.takeableOffers - ABI-ready lend-side offers returned by the Midnight API.
32
+ * @param params.metadata - Optional analytics metadata appended to calldata.
33
+ * @returns A deep-frozen `Transaction<MidnightTakeBorrowAction>` targeting `MidnightBundles`.
34
+ * @throws {NonPositiveInputError} when `loanAssets` or `maxUnits` is non-positive.
35
+ * @throws {NegativeInputError} when `deadline` is negative.
36
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
37
+ * @throws {MidnightOfferSideMismatchError} when any offer is not lend-side.
38
+ * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
39
+ * @throws {ChainIdMismatchError} when the market targets another chain.
40
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
41
+ * @example
42
+ * ```ts
43
+ * import { maxUint256 } from "viem";
44
+ * import { midnightTakeBorrow } from "@morpho-org/morpho-sdk";
45
+ *
46
+ * const tx = midnightTakeBorrow({
47
+ * chainId: 8453,
48
+ * market: marketData.params,
49
+ * loanAssets: BigInt(quote.data.availableAssets),
50
+ * maxUnits: BigInt(quote.data.availableUnits),
51
+ * taker: borrower,
52
+ * takeableOffers: quote.data.takeableOffers,
53
+ * deadline: maxUint256,
54
+ * });
55
+ * ```
56
+ */
57
+ export declare const midnightTakeBorrow: (params: MidnightTakeBorrowParams) => Readonly<Transaction<MidnightTakeBorrowAction>>;