@morpho-org/morpho-sdk 5.2.0 → 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 +93 -68
  97. package/lib/cjs/entities/index.d.ts +1 -0
  98. package/lib/cjs/entities/index.js +15 -0
  99. package/lib/cjs/entities/midnight/index.d.ts +2 -0
  100. package/lib/cjs/entities/midnight/index.js +18 -0
  101. package/lib/cjs/entities/midnight/midnight.d.ts +402 -0
  102. package/lib/cjs/entities/midnight/midnight.js +1036 -0
  103. package/lib/cjs/entities/midnight/types.d.ts +164 -0
  104. package/lib/cjs/entities/midnight/types.js +2 -0
  105. package/lib/cjs/entities/vaultV1/vaultV1.js +10 -17
  106. package/lib/cjs/entities/vaultV2/vaultV2.js +19 -21
  107. package/lib/cjs/errors.d.ts +1 -0
  108. package/lib/cjs/errors.js +17 -1
  109. package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
  110. package/lib/cjs/helpers/encodeDeallocation.js +2 -1
  111. package/lib/cjs/helpers/index.d.ts +4 -1
  112. package/lib/cjs/helpers/index.js +8 -1
  113. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +34 -0
  114. package/lib/cjs/helpers/signAndVerifyTypedData.js +58 -0
  115. package/lib/cjs/helpers/validate.d.ts +40 -1
  116. package/lib/cjs/helpers/validate.js +47 -5
  117. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
  118. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +32 -0
  119. package/lib/cjs/helpers/validateMidnightMarket.d.ts +10 -0
  120. package/lib/cjs/helpers/validateMidnightMarket.js +24 -0
  121. package/lib/cjs/helpers/validateOfferSides.d.ts +21 -0
  122. package/lib/cjs/helpers/validateOfferSides.js +36 -0
  123. package/lib/cjs/helpers/validateRequirementSpender.d.ts +29 -0
  124. package/lib/cjs/helpers/validateRequirementSpender.js +49 -0
  125. package/lib/cjs/helpers/validateTakeableOffers.d.ts +18 -0
  126. package/lib/cjs/helpers/validateTakeableOffers.js +35 -0
  127. package/lib/cjs/midnight-api.d.ts +1 -0
  128. package/lib/cjs/midnight-api.js +17 -0
  129. package/lib/cjs/types/action.d.ts +189 -23
  130. package/lib/cjs/types/action.js +27 -7
  131. package/lib/cjs/types/client.d.ts +3 -2
  132. package/lib/cjs/types/error.d.ts +288 -119
  133. package/lib/cjs/types/error.js +259 -180
  134. package/lib/cjs/utils.d.ts +1 -0
  135. package/lib/cjs/utils.js +12 -2
  136. package/lib/esm/abis.d.ts +1 -0
  137. package/lib/esm/abis.js +1 -0
  138. package/lib/esm/actions/blue/borrow.d.ts +3 -7
  139. package/lib/esm/actions/blue/borrow.js +6 -10
  140. package/lib/esm/actions/blue/buildReallocationActions.d.ts +3 -4
  141. package/lib/esm/actions/blue/buildReallocationActions.js +3 -4
  142. package/lib/esm/actions/blue/refinance.d.ts +4 -8
  143. package/lib/esm/actions/blue/refinance.js +11 -15
  144. package/lib/esm/actions/blue/repay.d.ts +2 -5
  145. package/lib/esm/actions/blue/repay.js +2 -5
  146. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -6
  147. package/lib/esm/actions/blue/repayWithdrawCollateral.js +5 -8
  148. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +2 -5
  149. package/lib/esm/actions/blue/resolveRepayFunding.js +16 -13
  150. package/lib/esm/actions/blue/supply.d.ts +2 -4
  151. package/lib/esm/actions/blue/supply.js +7 -9
  152. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -3
  153. package/lib/esm/actions/blue/supplyCollateral.js +6 -7
  154. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -9
  155. package/lib/esm/actions/blue/supplyCollateralBorrow.js +10 -15
  156. package/lib/esm/actions/blue/withdraw.d.ts +9 -7
  157. package/lib/esm/actions/blue/withdraw.js +19 -11
  158. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
  159. package/lib/esm/actions/blue/withdrawCollateral.js +3 -3
  160. package/lib/esm/actions/index.d.ts +2 -0
  161. package/lib/esm/actions/index.js +1 -0
  162. package/lib/esm/actions/midnight/authorization.d.ts +37 -0
  163. package/lib/esm/actions/midnight/authorization.js +65 -0
  164. package/lib/esm/actions/midnight/cancelOffer.d.ts +38 -0
  165. package/lib/esm/actions/midnight/cancelOffer.js +69 -0
  166. package/lib/esm/actions/midnight/index.d.ts +11 -0
  167. package/lib/esm/actions/midnight/index.js +11 -0
  168. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
  169. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +68 -0
  170. package/lib/esm/actions/midnight/redeem.d.ts +43 -0
  171. package/lib/esm/actions/midnight/redeem.js +75 -0
  172. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
  173. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +117 -0
  174. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
  175. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +55 -0
  176. package/lib/esm/actions/midnight/supplyCollateral.d.ts +45 -0
  177. package/lib/esm/actions/midnight/supplyCollateral.js +79 -0
  178. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
  179. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +124 -0
  180. package/lib/esm/actions/midnight/takeBorrow.d.ts +57 -0
  181. package/lib/esm/actions/midnight/takeBorrow.js +106 -0
  182. package/lib/esm/actions/midnight/takeLend.d.ts +57 -0
  183. package/lib/esm/actions/midnight/takeLend.js +106 -0
  184. package/lib/esm/actions/midnight/types.d.ts +39 -0
  185. package/lib/esm/actions/midnight/types.js +12 -0
  186. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
  187. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +6 -17
  188. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
  189. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +12 -16
  190. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
  191. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +12 -29
  192. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
  193. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
  194. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  195. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +10 -4
  196. package/lib/esm/actions/requirements/getRequirementsApproval.js +10 -4
  197. package/lib/esm/actions/requirements/index.d.ts +1 -0
  198. package/lib/esm/actions/requirements/index.js +1 -0
  199. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
  200. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +72 -0
  201. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
  202. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +74 -0
  203. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
  204. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +66 -0
  205. package/lib/esm/actions/requirements/midnight/index.d.ts +3 -0
  206. package/lib/esm/actions/requirements/midnight/index.js +3 -0
  207. package/lib/esm/actions/vaultV1/deposit.d.ts +3 -4
  208. package/lib/esm/actions/vaultV1/deposit.js +8 -9
  209. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -3
  210. package/lib/esm/actions/vaultV1/migrateToV2.js +6 -7
  211. package/lib/esm/actions/vaultV1/redeem.d.ts +1 -1
  212. package/lib/esm/actions/vaultV1/redeem.js +3 -3
  213. package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
  214. package/lib/esm/actions/vaultV1/withdraw.js +3 -3
  215. package/lib/esm/actions/vaultV2/deposit.d.ts +3 -4
  216. package/lib/esm/actions/vaultV2/deposit.js +8 -9
  217. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -3
  218. package/lib/esm/actions/vaultV2/forceRedeem.js +4 -5
  219. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  220. package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
  221. package/lib/esm/actions/vaultV2/redeem.d.ts +1 -1
  222. package/lib/esm/actions/vaultV2/redeem.js +3 -3
  223. package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
  224. package/lib/esm/actions/vaultV2/withdraw.js +3 -3
  225. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  226. package/lib/esm/client/morphoViemExtension.js +6 -3
  227. package/lib/esm/constants.d.ts +1 -0
  228. package/lib/esm/constants.js +1 -0
  229. package/lib/esm/entities/blue/blue.d.ts +5 -5
  230. package/lib/esm/entities/blue/blue.js +95 -70
  231. package/lib/esm/entities/index.d.ts +1 -0
  232. package/lib/esm/entities/index.js +1 -0
  233. package/lib/esm/entities/midnight/index.d.ts +2 -0
  234. package/lib/esm/entities/midnight/index.js +2 -0
  235. package/lib/esm/entities/midnight/midnight.d.ts +402 -0
  236. package/lib/esm/entities/midnight/midnight.js +1032 -0
  237. package/lib/esm/entities/midnight/types.d.ts +164 -0
  238. package/lib/esm/entities/midnight/types.js +1 -0
  239. package/lib/esm/entities/vaultV1/vaultV1.js +13 -20
  240. package/lib/esm/entities/vaultV2/vaultV2.js +9 -11
  241. package/lib/esm/errors.d.ts +1 -0
  242. package/lib/esm/errors.js +1 -0
  243. package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
  244. package/lib/esm/helpers/encodeDeallocation.js +3 -2
  245. package/lib/esm/helpers/index.d.ts +4 -1
  246. package/lib/esm/helpers/index.js +4 -1
  247. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +34 -0
  248. package/lib/esm/helpers/signAndVerifyTypedData.js +54 -0
  249. package/lib/esm/helpers/validate.d.ts +40 -1
  250. package/lib/esm/helpers/validate.js +46 -5
  251. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
  252. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +28 -0
  253. package/lib/esm/helpers/validateMidnightMarket.d.ts +10 -0
  254. package/lib/esm/helpers/validateMidnightMarket.js +20 -0
  255. package/lib/esm/helpers/validateOfferSides.d.ts +21 -0
  256. package/lib/esm/helpers/validateOfferSides.js +32 -0
  257. package/lib/esm/helpers/validateRequirementSpender.d.ts +29 -0
  258. package/lib/esm/helpers/validateRequirementSpender.js +45 -0
  259. package/lib/esm/helpers/validateTakeableOffers.d.ts +18 -0
  260. package/lib/esm/helpers/validateTakeableOffers.js +31 -0
  261. package/lib/esm/midnight-api.d.ts +1 -0
  262. package/lib/esm/midnight-api.js +1 -0
  263. package/lib/esm/types/action.d.ts +189 -23
  264. package/lib/esm/types/action.js +26 -7
  265. package/lib/esm/types/client.d.ts +3 -2
  266. package/lib/esm/types/error.d.ts +288 -119
  267. package/lib/esm/types/error.js +232 -154
  268. package/lib/esm/utils.d.ts +1 -0
  269. package/lib/esm/utils.js +1 -0
  270. package/package.json +12 -3
@@ -0,0 +1,164 @@
1
+ import type { AccrualPosition, Market, MarketInput, MidnightFetchParams, Tree, TreeInput, TreeMempoolValidateParams } from "@morpho-org/midnight-sdk";
2
+ import type { Address, Hex } from "viem";
3
+ import type { MidnightTakeableOffer } from "../../actions/midnight/types.js";
4
+ import type { ActionOutput, BaseAction, MempoolSubmitOffersAction, MidnightOfferRootSignature } from "../../types/action.js";
5
+ /** Optional Midnight API validation controls for make-offer flows. */
6
+ export type OfferValidationParams = Omit<TreeMempoolValidateParams, "chainId">;
7
+ /** Parameters for building and validating Midnight offer data. */
8
+ export interface GetOffersDataParams {
9
+ readonly accountAddress: Address;
10
+ readonly offers: TreeInput;
11
+ readonly validation?: OfferValidationParams;
12
+ }
13
+ interface OffersDataBase {
14
+ readonly accountAddress: Address;
15
+ readonly groups: readonly Hex[];
16
+ readonly tree: Tree;
17
+ readonly ratifier: Address;
18
+ }
19
+ /** Prepared Midnight maker-offer data discriminated by its ratifier execution path. */
20
+ export type OffersData = (OffersDataBase & {
21
+ readonly ratifierType: "ecrecover";
22
+ readonly setterPayload?: never;
23
+ }) | (OffersDataBase & {
24
+ readonly ratifierType: "setter";
25
+ readonly setterPayload: Hex;
26
+ });
27
+ /** Parameters shared by Midnight maker-offer flows. */
28
+ export interface MakeOffersParams {
29
+ readonly accountAddress: Address;
30
+ readonly offers: TreeInput;
31
+ readonly validation?: OfferValidationParams;
32
+ }
33
+ /** Parameters for the Midnight make-lend maker flow. */
34
+ export interface MakeLendParams extends MakeOffersParams {
35
+ readonly loanToken: Address;
36
+ /** New group loan reserve. For grouped OCA offers, pass the group reserve once instead of summing every leg. */
37
+ readonly loanAssets: bigint;
38
+ /** Existing loan assets reserved across the maker's other open groups, including consumed amounts when available. */
39
+ readonly reservedLoanAssets?: bigint;
40
+ }
41
+ /** Parameters for the Midnight supply-collateral-and-make-borrow maker flow. */
42
+ export interface SupplyCollateralMakeBorrowParams extends MakeOffersParams {
43
+ readonly market: MarketInput;
44
+ /** Collateral supplied before offer submission and the new group collateral reserve counted once for grouped offers. */
45
+ readonly collateralAssets: bigint;
46
+ /** Existing collateral assets reserved across the maker's other open groups, including consumed amounts when available. */
47
+ readonly reservedCollateralAssets?: bigint;
48
+ readonly collateralIndex?: bigint;
49
+ }
50
+ /** Signatures accepted by Midnight action-output transaction builders. */
51
+ export type MidnightActionSignatures = MidnightOfferRootSignature | readonly MidnightOfferRootSignature[];
52
+ /**
53
+ * Lazy Midnight entity result with async requirements and sync transaction building.
54
+ *
55
+ * Call `getRequirements()` first to collect approvals, authorizations, or
56
+ * signatures. Once those are handled, pass any requirement signatures to
57
+ * `buildTx`; the transaction builder itself performs no fetching or signing.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const output = midnight.takeLend(params);
62
+ * const requirements = await output.getRequirements();
63
+ * for (const requirement of requirements) {
64
+ * if (!("sign" in requirement)) {
65
+ * await walletClient.sendTransaction({
66
+ * to: requirement.to,
67
+ * data: requirement.data,
68
+ * value: requirement.value,
69
+ * });
70
+ * }
71
+ * }
72
+ * const tx = output.buildTx();
73
+ * ```
74
+ */
75
+ export type MidnightActionOutput<TAction extends BaseAction, TSignatures = undefined> = ActionOutput<TAction, TSignatures, undefined>;
76
+ /**
77
+ * Output returned by maker-offer flows after offer-tree preparation.
78
+ *
79
+ * Use `groups` and `root` for review UI, call `getRequirements()` to collect
80
+ * ratifier approval or signature requirements, then call `buildTx(signatures)`
81
+ * to publish the encoded payload to the Midnight mempool.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const output = await midnight.makeLend(params);
86
+ * console.log(output.root, output.groups);
87
+ * const requirements = await output.getRequirements();
88
+ * const signatures = [];
89
+ * for (const requirement of requirements) {
90
+ * if ("sign" in requirement) {
91
+ * signatures.push(await requirement.sign(walletClient, maker));
92
+ * } else {
93
+ * await walletClient.sendTransaction({
94
+ * to: requirement.to,
95
+ * data: requirement.data,
96
+ * value: requirement.value,
97
+ * });
98
+ * }
99
+ * }
100
+ * const tx = output.buildTx(signatures);
101
+ * ```
102
+ */
103
+ export interface MakeOffersOutput extends MidnightActionOutput<MempoolSubmitOffersAction, MidnightActionSignatures> {
104
+ readonly groups: readonly Hex[];
105
+ readonly root: Hex;
106
+ readonly ratifierType: "ecrecover" | "setter";
107
+ }
108
+ /** Parameters shared by Midnight market action flows. */
109
+ export interface MarketActionParams {
110
+ readonly accountAddress: Address;
111
+ readonly marketData: Market;
112
+ }
113
+ /** Parameters for the Midnight take-lend taker flow. */
114
+ export interface TakeLendParams extends MarketActionParams {
115
+ readonly assets: bigint;
116
+ readonly minUnits: bigint;
117
+ readonly takeableOffers: readonly MidnightTakeableOffer[];
118
+ /** Bundle execution deadline timestamp. Pass `maxUint256` explicitly for no expiry. */
119
+ readonly deadline: bigint;
120
+ }
121
+ /** Parameters for the Midnight take-borrow taker flow. */
122
+ export interface TakeBorrowParams extends MarketActionParams {
123
+ readonly loanAssets: bigint;
124
+ readonly maxUnits: bigint;
125
+ readonly takeableOffers: readonly MidnightTakeableOffer[];
126
+ /** Bundle execution deadline timestamp. Pass `maxUint256` explicitly for no expiry. */
127
+ readonly deadline: bigint;
128
+ }
129
+ /** Parameters for the Midnight supply-collateral-and-take-borrow taker flow. */
130
+ export interface SupplyCollateralTakeBorrowParams extends TakeBorrowParams {
131
+ readonly collateralAssets: bigint;
132
+ readonly collateralIndex?: bigint;
133
+ }
134
+ /** Parameters for the Midnight supply-collateral flow. */
135
+ export interface SupplyCollateralParams extends MarketActionParams {
136
+ readonly collateralAssets: bigint;
137
+ /** Existing collateral assets reserved across the maker's open groups, including consumed amounts when available. */
138
+ readonly reservedCollateralAssets?: bigint;
139
+ readonly collateralIndex?: bigint;
140
+ }
141
+ /** Parameters for the Midnight redeem flow. */
142
+ export interface RedeemParams {
143
+ readonly accountAddress: Address;
144
+ /** Owner-bound snapshot returned by `getPositionData`; manually constructed ownerless snapshots are rejected. */
145
+ readonly positionData: AccrualPosition;
146
+ readonly receiver?: Address;
147
+ readonly units?: bigint;
148
+ }
149
+ /** Parameters for the Midnight repay-and-withdraw-collateral flow. */
150
+ export interface RepayWithdrawCollateralParams extends MarketActionParams {
151
+ readonly repayAssets: bigint;
152
+ readonly withdrawCollateralAssets: bigint;
153
+ readonly collateralIndex?: bigint;
154
+ /** Bundle execution deadline timestamp. Pass `maxUint256` explicitly for no expiry. */
155
+ readonly deadline: bigint;
156
+ }
157
+ /** Parameters for fetching a Midnight user position with market data. */
158
+ export interface GetPositionDataParams {
159
+ readonly marketId: Hex;
160
+ readonly accountAddress: Address;
161
+ /** Optional fetch controls. Pass an externally fetched block number to coordinate this snapshot with other reads. */
162
+ readonly parameters?: MidnightFetchParams;
163
+ }
164
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -38,10 +38,10 @@ class MorphoVaultV1 {
38
38
  throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
39
39
  }
40
40
  if (amount < 0n) {
41
- throw new index_js_3.NonPositiveAssetAmountError(this.vault);
41
+ throw new index_js_3.NegativeInputError("amount", amount);
42
42
  }
43
43
  if (nativeAmount && nativeAmount < 0n) {
44
- throw new index_js_3.NegativeNativeAmountError(nativeAmount);
44
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
45
45
  }
46
46
  let wNative;
47
47
  if (nativeAmount) {
@@ -50,21 +50,19 @@ class MorphoVaultV1 {
50
50
  throw new index_js_3.ChainWNativeMissingError(this.chainId);
51
51
  }
52
52
  }
53
- if (slippageTolerance < 0n) {
54
- throw new index_js_3.NegativeSlippageToleranceError(slippageTolerance);
55
- }
56
- if (slippageTolerance > constant_js_1.MAX_SLIPPAGE_TOLERANCE) {
57
- throw new index_js_3.ExcessiveSlippageToleranceError(slippageTolerance);
58
- }
53
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
59
54
  if (nativeAmount && wNative) {
60
55
  if (!(0, viem_1.isAddressEqual)(vaultData.asset, wNative)) {
61
56
  throw new index_js_3.NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
62
57
  }
63
58
  }
64
59
  const totalAssets = amount + (nativeAmount ?? 0n);
60
+ if (totalAssets === 0n) {
61
+ throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
62
+ }
65
63
  const shares = vaultData.toShares(totalAssets);
66
64
  if (shares <= 0n) {
67
- throw new index_js_3.NonPositiveSharesAmountError(this.vault);
65
+ throw new index_js_3.NonPositiveInputError("shares", shares);
68
66
  }
69
67
  const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
70
68
  return {
@@ -142,14 +140,9 @@ class MorphoVaultV1 {
142
140
  throw new index_js_3.VaultAssetMismatchError(sourceVault.asset, targetVault.asset);
143
141
  }
144
142
  if (shares <= 0n) {
145
- throw new index_js_3.NonPositiveSharesAmountError(this.vault);
146
- }
147
- if (slippageTolerance < 0n) {
148
- throw new index_js_3.NegativeSlippageToleranceError(slippageTolerance);
149
- }
150
- if (slippageTolerance > constant_js_1.MAX_SLIPPAGE_TOLERANCE) {
151
- throw new index_js_3.ExcessiveSlippageToleranceError(slippageTolerance);
143
+ throw new index_js_3.NonPositiveInputError("shares", shares);
152
144
  }
145
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
153
146
  // Compute minSharePriceVaultV1 for V1 redeem (slippage downward)
154
147
  const v1RefAssets = sourceVault.toAssets(shares);
155
148
  const minSharePriceVaultV1 = blue_sdk_1.MathLib.mulDivDown(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), shares);
@@ -159,7 +152,7 @@ class MorphoVaultV1 {
159
152
  const { vault: accruedTargetVault } = targetVault.accrueInterest(targetAccrualTimestamp);
160
153
  const v2RefShares = accruedTargetVault.toShares(v1RefAssets);
161
154
  if (v2RefShares <= 0n) {
162
- throw new index_js_3.NonPositiveSharesAmountError(targetVault.address);
155
+ throw new index_js_3.NonPositiveInputError("targetVaultShares", v2RefShares);
163
156
  }
164
157
  const maxSharePriceVaultV2 = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), v2RefShares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
165
158
  return {
@@ -6,8 +6,8 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
8
  const index_js_1 = require("../../actions/index.js");
9
- const constant_js_1 = require("../../helpers/constant.js");
10
- const index_js_2 = require("../../types/index.js");
9
+ const index_js_2 = require("../../helpers/index.js");
10
+ const index_js_3 = require("../../types/index.js");
11
11
  class MorphoVaultV2 {
12
12
  client;
13
13
  vault;
@@ -21,7 +21,7 @@ class MorphoVaultV2 {
21
21
  async getData(parameters) {
22
22
  if (this.client.viemClient.chain?.id &&
23
23
  this.client.viemClient.chain?.id !== this.chainId) {
24
- throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
24
+ throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
25
25
  }
26
26
  return (0, blue_sdk_viem_1.fetchAccrualVaultV2)(this.vault, this.client.viemClient, {
27
27
  ...parameters,
@@ -31,43 +31,41 @@ class MorphoVaultV2 {
31
31
  }
32
32
  deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
33
33
  if (this.client.viemClient.chain?.id !== this.chainId) {
34
- throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
34
+ throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
35
35
  }
36
36
  if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
37
- throw new index_js_2.VaultAddressMismatchError(this.vault, vaultData.address);
37
+ throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
38
38
  }
39
39
  if (amount < 0n) {
40
- throw new index_js_2.NonPositiveAssetAmountError(this.vault);
40
+ throw new index_js_3.NegativeInputError("amount", amount);
41
41
  }
42
42
  if (nativeAmount && nativeAmount < 0n) {
43
- throw new index_js_2.NegativeNativeAmountError(nativeAmount);
43
+ throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
44
44
  }
45
45
  let wNative;
46
46
  if (nativeAmount) {
47
47
  ({ wNative } = (0, blue_sdk_1.getChainAddresses)(this.chainId));
48
48
  if (!wNative) {
49
- throw new index_js_2.ChainWNativeMissingError(this.chainId);
49
+ throw new index_js_3.ChainWNativeMissingError(this.chainId);
50
50
  }
51
51
  }
52
- if (slippageTolerance < 0n) {
53
- throw new index_js_2.NegativeSlippageToleranceError(slippageTolerance);
54
- }
55
- if (slippageTolerance > constant_js_1.MAX_SLIPPAGE_TOLERANCE) {
56
- throw new index_js_2.ExcessiveSlippageToleranceError(slippageTolerance);
57
- }
52
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
58
53
  if (nativeAmount && wNative) {
59
54
  if (!(0, viem_1.isAddressEqual)(vaultData.asset, wNative)) {
60
- throw new index_js_2.NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
55
+ throw new index_js_3.NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
61
56
  }
62
57
  }
63
58
  const totalAssets = amount + (nativeAmount ?? 0n);
59
+ if (totalAssets === 0n) {
60
+ throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
61
+ }
64
62
  // Accrue interest forward to bound the on-chain share price at execution.
65
63
  // Mirrors blue repay's 2h forward-accrual buffer.
66
64
  const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), vaultData.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
67
65
  const { vault: accruedVault } = vaultData.accrueInterest(accrualTimestamp);
68
66
  const shares = accruedVault.toShares(totalAssets);
69
67
  if (shares <= 0n) {
70
- throw new index_js_2.NonPositiveSharesAmountError(this.vault);
68
+ throw new index_js_3.NonPositiveInputError("shares", shares);
71
69
  }
72
70
  const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), blue_sdk_1.MathLib.RAY * 100n);
73
71
  return {
@@ -83,7 +81,7 @@ class MorphoVaultV2 {
83
81
  },
84
82
  }),
85
83
  buildTx: (signatures) => {
86
- const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, {
84
+ const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
87
85
  permit: true,
88
86
  });
89
87
  return (0, index_js_1.vaultV2Deposit)({
@@ -106,7 +104,7 @@ class MorphoVaultV2 {
106
104
  }
107
105
  withdraw({ amount, userAddress }) {
108
106
  if (this.client.viemClient.chain?.id !== this.chainId) {
109
- throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
107
+ throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
110
108
  }
111
109
  return {
112
110
  buildTx: () => (0, index_js_1.vaultV2Withdraw)({
@@ -122,7 +120,7 @@ class MorphoVaultV2 {
122
120
  }
123
121
  redeem({ shares, userAddress }) {
124
122
  if (this.client.viemClient.chain?.id !== this.chainId) {
125
- throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
123
+ throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
126
124
  }
127
125
  return {
128
126
  buildTx: () => (0, index_js_1.vaultV2Redeem)({
@@ -138,7 +136,7 @@ class MorphoVaultV2 {
138
136
  }
139
137
  forceWithdraw({ deallocations, withdraw, userAddress, }) {
140
138
  if (this.client.viemClient.chain?.id !== this.chainId) {
141
- throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
139
+ throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
142
140
  }
143
141
  return {
144
142
  buildTx: () => (0, index_js_1.vaultV2ForceWithdraw)({
@@ -157,7 +155,7 @@ class MorphoVaultV2 {
157
155
  }
158
156
  forceRedeem({ deallocations, redeem, userAddress, }) {
159
157
  if (this.client.viemClient.chain?.id !== this.chainId) {
160
- throw new index_js_2.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
158
+ throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
161
159
  }
162
160
  return {
163
161
  buildTx: () => (0, index_js_1.vaultV2ForceRedeem)({
@@ -1,3 +1,4 @@
1
1
  export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
2
+ export { InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, MidnightApiError, MidnightMempoolValidationError, PriceGreaterThanOneError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
3
  export type { ErrorClass } from "@morpho-org/morpho-ts";
3
4
  export { _try } from "@morpho-org/morpho-ts";
package/lib/cjs/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._try = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownOfFactory = exports.UnknownMarketParamsError = exports.UnknownFactory = exports.UnknownDataError = exports.UnknownAddressError = exports.InvalidMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
3
+ exports._try = exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.PriceGreaterThanOneError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownOfFactory = exports.UnknownMarketParamsError = exports.UnknownFactory = exports.UnknownDataError = exports.UnknownAddressError = exports.InvalidMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
4
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
6
6
  Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
@@ -17,5 +17,21 @@ Object.defineProperty(exports, "UnsupportedChainIdError", { enumerable: true, ge
17
17
  Object.defineProperty(exports, "UnsupportedPreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
18
18
  Object.defineProperty(exports, "UnsupportedVaultV2AdapterError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedVaultV2AdapterError; } });
19
19
  Object.defineProperty(exports, "VaultV2Errors", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Errors; } });
20
+ var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
21
+ Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
22
+ Object.defineProperty(exports, "InvalidOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
23
+ Object.defineProperty(exports, "InvalidOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
24
+ Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
25
+ Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
26
+ Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
27
+ Object.defineProperty(exports, "InvalidTickSpacingError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidTickSpacingError; } });
28
+ Object.defineProperty(exports, "InvalidTreeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidTreeError; } });
29
+ Object.defineProperty(exports, "InvalidTreeHeightError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidTreeHeightError; } });
30
+ Object.defineProperty(exports, "MidnightApiError", { enumerable: true, get: function () { return midnight_sdk_1.MidnightApiError; } });
31
+ Object.defineProperty(exports, "MidnightMempoolValidationError", { enumerable: true, get: function () { return midnight_sdk_1.MidnightMempoolValidationError; } });
32
+ Object.defineProperty(exports, "PriceGreaterThanOneError", { enumerable: true, get: function () { return midnight_sdk_1.PriceGreaterThanOneError; } });
33
+ Object.defineProperty(exports, "SettlementFeeExceedsPriceError", { enumerable: true, get: function () { return midnight_sdk_1.SettlementFeeExceedsPriceError; } });
34
+ Object.defineProperty(exports, "TickOutOfRangeError", { enumerable: true, get: function () { return midnight_sdk_1.TickOutOfRangeError; } });
35
+ Object.defineProperty(exports, "UnknownCollateralIndexError", { enumerable: true, get: function () { return midnight_sdk_1.UnknownCollateralIndexError; } });
20
36
  var morpho_ts_1 = require("@morpho-org/morpho-ts");
21
37
  Object.defineProperty(exports, "_try", { enumerable: true, get: function () { return morpho_ts_1._try; } });
@@ -6,5 +6,6 @@ import { type Deallocation } from "../types/index.js";
6
6
  * @param deallocation - A deallocation entry.
7
7
  * @param onBehalf - The address from which the penalty is taken (share owner).
8
8
  * @returns The ABI-encoded calldata for `VaultV2.forceDeallocate`.
9
+ * @throws {NonPositiveInputError} when `deallocation.amount <= 0n`.
9
10
  */
10
11
  export declare function encodeForceDeallocateCall(deallocation: Deallocation, onBehalf: Address): Hex;
@@ -23,10 +23,11 @@ function encodeDeallocateData(deallocation) {
23
23
  * @param deallocation - A deallocation entry.
24
24
  * @param onBehalf - The address from which the penalty is taken (share owner).
25
25
  * @returns The ABI-encoded calldata for `VaultV2.forceDeallocate`.
26
+ * @throws {NonPositiveInputError} when `deallocation.amount <= 0n`.
26
27
  */
27
28
  function encodeForceDeallocateCall(deallocation, onBehalf) {
28
29
  if (deallocation.amount <= 0n) {
29
- throw new index_js_1.NonPositiveAssetAmountError(deallocation.adapter);
30
+ throw new index_js_1.NonPositiveInputError(`deallocation[${deallocation.adapter}].amount`, deallocation.amount);
30
31
  }
31
32
  const data = encodeDeallocateData(deallocation);
32
33
  return (0, viem_1.encodeFunctionData)({
@@ -1,5 +1,8 @@
1
1
  export { computeReallocations } from "./computeReallocations.js";
2
2
  export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
3
3
  export { addTransactionMetadata } from "./metadata.js";
4
+ export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
4
5
  export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, } from "./slippage.js";
5
- export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
6
+ export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
7
+ export { validateOfferSides } from "./validateOfferSides.js";
8
+ export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinWithdrawSharePrice = exports.computeMinBorrowSharePrice = exports.computeMaxSupplySharePrice = exports.computeMaxRepaySharePrice = exports.addTransactionMetadata = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.computeReallocations = void 0;
3
+ exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinWithdrawSharePrice = exports.computeMinBorrowSharePrice = exports.computeMaxSupplySharePrice = exports.computeMaxRepaySharePrice = exports.signAndVerifyTypedData = exports.addTransactionMetadata = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.computeReallocations = void 0;
4
4
  var computeReallocations_js_1 = require("./computeReallocations.js");
5
5
  Object.defineProperty(exports, "computeReallocations", { enumerable: true, get: function () { return computeReallocations_js_1.computeReallocations; } });
6
6
  var constant_js_1 = require("./constant.js");
@@ -13,6 +13,8 @@ Object.defineProperty(exports, "MAX_SLIPPAGE_TOLERANCE", { enumerable: true, get
13
13
  Object.defineProperty(exports, "MAX_TOKEN_APPROVALS", { enumerable: true, get: function () { return constant_js_1.MAX_TOKEN_APPROVALS; } });
14
14
  var metadata_js_1 = require("./metadata.js");
15
15
  Object.defineProperty(exports, "addTransactionMetadata", { enumerable: true, get: function () { return metadata_js_1.addTransactionMetadata; } });
16
+ var signAndVerifyTypedData_js_1 = require("./signAndVerifyTypedData.js");
17
+ Object.defineProperty(exports, "signAndVerifyTypedData", { enumerable: true, get: function () { return signAndVerifyTypedData_js_1.signAndVerifyTypedData; } });
16
18
  var slippage_js_1 = require("./slippage.js");
17
19
  Object.defineProperty(exports, "computeMaxRepaySharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMaxRepaySharePrice; } });
18
20
  Object.defineProperty(exports, "computeMaxSupplySharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMaxSupplySharePrice; } });
@@ -21,6 +23,7 @@ Object.defineProperty(exports, "computeMinWithdrawSharePrice", { enumerable: tru
21
23
  var validate_js_1 = require("./validate.js");
22
24
  Object.defineProperty(exports, "validateAccrualPosition", { enumerable: true, get: function () { return validate_js_1.validateAccrualPosition; } });
23
25
  Object.defineProperty(exports, "validateChainId", { enumerable: true, get: function () { return validate_js_1.validateChainId; } });
26
+ Object.defineProperty(exports, "validateMidnightMarketChainId", { enumerable: true, get: function () { return validate_js_1.validateMidnightMarketChainId; } });
24
27
  Object.defineProperty(exports, "validateNativeAsset", { enumerable: true, get: function () { return validate_js_1.validateNativeAsset; } });
25
28
  Object.defineProperty(exports, "validatePositionHealth", { enumerable: true, get: function () { return validate_js_1.validatePositionHealth; } });
26
29
  Object.defineProperty(exports, "validatePositionHealthAfterWithdraw", { enumerable: true, get: function () { return validate_js_1.validatePositionHealthAfterWithdraw; } });
@@ -31,3 +34,7 @@ Object.defineProperty(exports, "validateSlippageTolerance", { enumerable: true,
31
34
  Object.defineProperty(exports, "validateUserAddress", { enumerable: true, get: function () { return validate_js_1.validateUserAddress; } });
32
35
  Object.defineProperty(exports, "validateWithdrawAmount", { enumerable: true, get: function () { return validate_js_1.validateWithdrawAmount; } });
33
36
  Object.defineProperty(exports, "validateWithdrawShares", { enumerable: true, get: function () { return validate_js_1.validateWithdrawShares; } });
37
+ var validateOfferSides_js_1 = require("./validateOfferSides.js");
38
+ Object.defineProperty(exports, "validateOfferSides", { enumerable: true, get: function () { return validateOfferSides_js_1.validateOfferSides; } });
39
+ var validateRequirementSpender_js_1 = require("./validateRequirementSpender.js");
40
+ Object.defineProperty(exports, "validateRequirementSpender", { enumerable: true, get: function () { return validateRequirementSpender_js_1.validateRequirementSpender; } });
@@ -0,0 +1,34 @@
1
+ import type { Address, Hex, TypedDataDefinition, WalletClient } from "viem";
2
+ /**
3
+ * Signs EIP-712 typed data with a wallet client, verifies that the produced signature recovers
4
+ * `userAddress`, and returns the signature.
5
+ *
6
+ * Use inside requirement `sign(...)` callbacks before converting a signature
7
+ * into protocol calldata or mempool payload bytes. The verification step keeps
8
+ * wallet/account mismatches from reaching transaction builders.
9
+ *
10
+ * @param params - Signing and verification parameters.
11
+ * @param params.client - Wallet client used to sign the typed data.
12
+ * @param params.userAddress - Address expected to own the produced signature.
13
+ * @param params.typedData - EIP-712 typed data to sign and verify.
14
+ * @returns The verified EIP-712 signature.
15
+ * @throws {MissingClientPropertyError} when the wallet client has no account address.
16
+ * @throws {AddressMismatchError} when the wallet client account differs from `userAddress`.
17
+ * @throws {ChainIdMismatchError} when the wallet client targets a different chain than the typed-data domain.
18
+ * @throws {InvalidSignatureError} when the signature does not recover to `userAddress`.
19
+ * @example
20
+ * ```ts
21
+ * import { signAndVerifyTypedData } from "@morpho-org/morpho-sdk";
22
+ *
23
+ * const signature = await signAndVerifyTypedData({
24
+ * client: walletClient,
25
+ * userAddress: maker,
26
+ * typedData: offerRootTypedData,
27
+ * });
28
+ * ```
29
+ */
30
+ export declare const signAndVerifyTypedData: (params: {
31
+ readonly client: WalletClient;
32
+ readonly userAddress: Address;
33
+ readonly typedData: TypedDataDefinition<Record<string, unknown>, string>;
34
+ }) => Promise<Hex>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signAndVerifyTypedData = void 0;
4
+ const viem_1 = require("viem");
5
+ const actions_1 = require("viem/actions");
6
+ const index_js_1 = require("../types/index.js");
7
+ const validate_js_1 = require("./validate.js");
8
+ /**
9
+ * Signs EIP-712 typed data with a wallet client, verifies that the produced signature recovers
10
+ * `userAddress`, and returns the signature.
11
+ *
12
+ * Use inside requirement `sign(...)` callbacks before converting a signature
13
+ * into protocol calldata or mempool payload bytes. The verification step keeps
14
+ * wallet/account mismatches from reaching transaction builders.
15
+ *
16
+ * @param params - Signing and verification parameters.
17
+ * @param params.client - Wallet client used to sign the typed data.
18
+ * @param params.userAddress - Address expected to own the produced signature.
19
+ * @param params.typedData - EIP-712 typed data to sign and verify.
20
+ * @returns The verified EIP-712 signature.
21
+ * @throws {MissingClientPropertyError} when the wallet client has no account address.
22
+ * @throws {AddressMismatchError} when the wallet client account differs from `userAddress`.
23
+ * @throws {ChainIdMismatchError} when the wallet client targets a different chain than the typed-data domain.
24
+ * @throws {InvalidSignatureError} when the signature does not recover to `userAddress`.
25
+ * @example
26
+ * ```ts
27
+ * import { signAndVerifyTypedData } from "@morpho-org/morpho-sdk";
28
+ *
29
+ * const signature = await signAndVerifyTypedData({
30
+ * client: walletClient,
31
+ * userAddress: maker,
32
+ * typedData: offerRootTypedData,
33
+ * });
34
+ * ```
35
+ */
36
+ const signAndVerifyTypedData = async (params) => {
37
+ const { client, userAddress, typedData } = params;
38
+ const account = client.account;
39
+ (0, validate_js_1.validateUserAddress)(account?.address, userAddress);
40
+ const typedDataChainId = typedData.domain?.chainId;
41
+ if (typedDataChainId != null) {
42
+ (0, validate_js_1.validateChainId)(client.chain?.id, Number(typedDataChainId));
43
+ }
44
+ const signature = await (0, actions_1.signTypedData)(client, {
45
+ ...typedData,
46
+ account,
47
+ });
48
+ const isValid = await (0, viem_1.verifyTypedData)({
49
+ ...typedData,
50
+ address: userAddress,
51
+ signature,
52
+ });
53
+ if (!isValid) {
54
+ throw new index_js_1.InvalidSignatureError();
55
+ }
56
+ return signature;
57
+ };
58
+ exports.signAndVerifyTypedData = signAndVerifyTypedData;
@@ -1,8 +1,24 @@
1
1
  import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
2
+ import type { MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk";
2
3
  import { type Address } from "viem";
3
4
  import { type VaultReallocation } from "../types/index.js";
4
5
  /** @internal */
5
6
  export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => 1 | 0 | -1;
7
+ /**
8
+ * Validates that a raw or hydrated Midnight market belongs to the expected chain.
9
+ *
10
+ * @param market - Midnight market params or hydrated market state.
11
+ * @param chainId - Expected EIP-155 chain id.
12
+ * @returns Nothing when the market belongs to `chainId`.
13
+ * @throws {ChainIdMismatchError} when the market belongs to another chain.
14
+ * @example
15
+ * ```ts
16
+ * import { validateMidnightMarketChainId } from "@morpho-org/morpho-sdk";
17
+ *
18
+ * validateMidnightMarketChainId(marketParams, 8453);
19
+ * ```
20
+ */
21
+ export declare const validateMidnightMarketChainId: (market: MidnightMarketInput, chainId: number) => void;
6
22
  /**
7
23
  * Asserts that the client has a connected account AND that it matches
8
24
  * the provided user address.
@@ -134,15 +150,38 @@ export declare const validateRepayShares: (params: {
134
150
  *
135
151
  * @param reallocations - The reallocations to validate.
136
152
  * @param targetMarketId - The ID of the operation's target market. No withdrawal may reference this market.
153
+ * @returns Nothing when every reallocation is valid.
154
+ * @throws {NegativeInputError} when a reallocation fee is negative.
155
+ * @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
156
+ * @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
157
+ * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
158
+ * @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
159
+ * @example
160
+ * ```ts
161
+ * import type { MarketId } from "@morpho-org/blue-sdk";
162
+ * import { validateReallocations } from "@morpho-org/morpho-sdk";
163
+ * import { zeroHash } from "viem";
164
+ *
165
+ * const result: void = validateReallocations([], zeroHash as MarketId);
166
+ * ```
137
167
  */
138
168
  export declare const validateReallocations: (reallocations: readonly VaultReallocation[], targetMarketId: MarketId) => void;
139
169
  /**
140
170
  * Validates that a slippage tolerance is within an acceptable range.
141
171
  *
142
- * Throws {@link NegativeSlippageToleranceError} if negative.
172
+ * Throws {@link NegativeInputError} if negative.
143
173
  * Throws {@link ExcessiveSlippageToleranceError} if greater than {@link MAX_SLIPPAGE_TOLERANCE}.
144
174
  *
145
175
  * @param slippageTolerance - The slippage tolerance in WAD.
176
+ * @returns Nothing when the slippage tolerance is valid.
177
+ * @throws {NegativeInputError} when `slippageTolerance < 0n`.
178
+ * @throws {ExcessiveSlippageToleranceError} when the tolerance exceeds the SDK maximum.
179
+ * @example
180
+ * ```ts
181
+ * import { validateSlippageTolerance } from "@morpho-org/morpho-sdk";
182
+ *
183
+ * const result: void = validateSlippageTolerance(5_000000000000000n);
184
+ * ```
146
185
  */
147
186
  export declare const validateSlippageTolerance: (slippageTolerance: bigint) => void;
148
187
  /**