@morpho-org/morpho-sdk 8.3.0 → 9.1.0-next.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 (203) hide show
  1. package/MIGRATION-v8-to-v9.md +54 -0
  2. package/README.md +13 -7
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +5 -1
  5. package/lib/cjs/actions/bundles/common.d.ts +4 -7
  6. package/lib/cjs/actions/bundles/common.js +8 -14
  7. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
  8. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -8
  9. package/lib/cjs/actions/midnight/authorization.d.ts +3 -1
  10. package/lib/cjs/actions/midnight/authorization.js +11 -1
  11. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -0
  12. package/lib/cjs/actions/midnight/cancelAndMake.js +10 -2
  13. package/lib/cjs/actions/midnight/redeem.d.ts +3 -1
  14. package/lib/cjs/actions/midnight/redeem.js +9 -3
  15. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
  16. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +7 -3
  17. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +4 -1
  18. package/lib/cjs/actions/midnight/supplyCollateral.js +10 -3
  19. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
  20. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +9 -3
  21. package/lib/cjs/actions/midnight/takeBorrow.d.ts +3 -1
  22. package/lib/cjs/actions/midnight/takeBorrow.js +9 -3
  23. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
  24. package/lib/cjs/actions/midnight/takeLend.js +7 -2
  25. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  26. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +8 -2
  27. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +3 -1
  28. package/lib/cjs/actions/midnight/takeWithdraw.js +10 -3
  29. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
  30. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +5 -7
  31. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +7 -11
  32. package/lib/cjs/actions/requirements/getRequirementsApproval.js +8 -15
  33. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +11 -8
  35. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
  37. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -1
  38. package/lib/cjs/actions/vaultV1/inKindRedeem.js +1 -1
  39. package/lib/cjs/actions/vaultV1/withdraw.d.ts +4 -4
  40. package/lib/cjs/actions/vaultV1/withdraw.js +4 -4
  41. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
  42. package/lib/cjs/actions/vaultV2/forceWithdraw.js +1 -1
  43. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -1
  44. package/lib/cjs/actions/vaultV2/inKindRedeem.js +1 -1
  45. package/lib/cjs/actions/vaultV2/withdraw.d.ts +4 -4
  46. package/lib/cjs/actions/vaultV2/withdraw.js +4 -4
  47. package/lib/cjs/blue/abis.d.ts +1 -1
  48. package/lib/cjs/blue/abis.js +5 -1
  49. package/lib/cjs/blue/entities.d.ts +4 -4
  50. package/lib/cjs/blue/entities.js +3 -1
  51. package/lib/cjs/blue/errors.d.ts +2 -2
  52. package/lib/cjs/blue/errors.js +5 -1
  53. package/lib/cjs/blue/fetch.d.ts +2 -2
  54. package/lib/cjs/blue/fetch.js +3 -1
  55. package/lib/cjs/blue/utils.d.ts +1 -1
  56. package/lib/cjs/blue/utils.js +2 -1
  57. package/lib/cjs/entities/blue/blue.d.ts +2 -12
  58. package/lib/cjs/entities/blue/blue.js +0 -4
  59. package/lib/cjs/entities/index.d.ts +4 -4
  60. package/lib/cjs/entities/index.js +3 -1
  61. package/lib/cjs/entities/midnight/midnight.d.ts +63 -18
  62. package/lib/cjs/entities/midnight/midnight.js +138 -53
  63. package/lib/cjs/entities/midnight/types.d.ts +3 -10
  64. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
  65. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +0 -7
  66. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
  67. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -20
  68. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +40 -37
  69. package/lib/cjs/entities/vaultV1/vaultV1.js +5 -34
  70. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +69 -43
  71. package/lib/cjs/entities/vaultV2/vaultV2.js +41 -35
  72. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +5 -3
  73. package/lib/cjs/entities/vaultV2BlueReallocationData.js +9 -3
  74. package/lib/cjs/errors.d.ts +4 -4
  75. package/lib/cjs/errors.js +10 -5
  76. package/lib/cjs/fetch.d.ts +2 -2
  77. package/lib/cjs/fetch.js +3 -1
  78. package/lib/cjs/helpers/encodeMidnightCalldata.d.ts +48 -0
  79. package/lib/cjs/helpers/encodeMidnightCalldata.js +74 -0
  80. package/lib/cjs/helpers/slippage.d.ts +9 -25
  81. package/lib/cjs/helpers/slippage.js +10 -27
  82. package/lib/cjs/helpers/validate.d.ts +1 -0
  83. package/lib/cjs/helpers/validate.js +5 -0
  84. package/lib/cjs/helpers/validateMidnightAccount.d.ts +34 -0
  85. package/lib/cjs/helpers/validateMidnightAccount.js +47 -0
  86. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
  87. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +4 -0
  88. package/lib/cjs/helpers/validateMidnightMarket.d.ts +2 -0
  89. package/lib/cjs/helpers/validateMidnightMarket.js +5 -0
  90. package/lib/cjs/helpers/validateMidnightPublication.d.ts +11 -0
  91. package/lib/cjs/helpers/validateMidnightPublication.js +12 -1
  92. package/lib/cjs/helpers/validateMidnightReceiver.d.ts +1 -0
  93. package/lib/cjs/helpers/validateMidnightReceiver.js +8 -0
  94. package/lib/cjs/helpers/validateTakeableOffers.d.ts +2 -1
  95. package/lib/cjs/helpers/validateTakeableOffers.js +4 -3
  96. package/lib/cjs/midnight/errors.d.ts +2 -1
  97. package/lib/cjs/midnight/errors.js +5 -4
  98. package/lib/cjs/types/action.d.ts +3 -1
  99. package/lib/cjs/types/error.d.ts +60 -6
  100. package/lib/cjs/types/error.js +143 -11
  101. package/lib/cjs/utils.d.ts +2 -2
  102. package/lib/cjs/utils.js +4 -2
  103. package/lib/esm/abis.d.ts +1 -1
  104. package/lib/esm/abis.js +1 -1
  105. package/lib/esm/actions/bundles/common.d.ts +4 -7
  106. package/lib/esm/actions/bundles/common.js +8 -14
  107. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
  108. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -9
  109. package/lib/esm/actions/midnight/authorization.d.ts +3 -1
  110. package/lib/esm/actions/midnight/authorization.js +12 -2
  111. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -0
  112. package/lib/esm/actions/midnight/cancelAndMake.js +11 -3
  113. package/lib/esm/actions/midnight/redeem.d.ts +3 -1
  114. package/lib/esm/actions/midnight/redeem.js +10 -4
  115. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
  116. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +8 -4
  117. package/lib/esm/actions/midnight/supplyCollateral.d.ts +4 -1
  118. package/lib/esm/actions/midnight/supplyCollateral.js +11 -4
  119. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
  120. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +10 -4
  121. package/lib/esm/actions/midnight/takeBorrow.d.ts +3 -1
  122. package/lib/esm/actions/midnight/takeBorrow.js +10 -4
  123. package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
  124. package/lib/esm/actions/midnight/takeLend.js +8 -3
  125. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  126. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +9 -3
  127. package/lib/esm/actions/midnight/takeWithdraw.d.ts +3 -1
  128. package/lib/esm/actions/midnight/takeWithdraw.js +11 -4
  129. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
  130. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -8
  131. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +7 -11
  132. package/lib/esm/actions/requirements/getRequirementsApproval.js +9 -16
  133. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
  134. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +12 -9
  135. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
  136. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
  137. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -1
  138. package/lib/esm/actions/vaultV1/inKindRedeem.js +1 -1
  139. package/lib/esm/actions/vaultV1/withdraw.d.ts +4 -4
  140. package/lib/esm/actions/vaultV1/withdraw.js +4 -4
  141. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  142. package/lib/esm/actions/vaultV2/forceWithdraw.js +1 -1
  143. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -1
  144. package/lib/esm/actions/vaultV2/inKindRedeem.js +1 -1
  145. package/lib/esm/actions/vaultV2/withdraw.d.ts +4 -4
  146. package/lib/esm/actions/vaultV2/withdraw.js +4 -4
  147. package/lib/esm/blue/abis.d.ts +1 -1
  148. package/lib/esm/blue/abis.js +1 -1
  149. package/lib/esm/blue/entities.d.ts +4 -4
  150. package/lib/esm/blue/entities.js +2 -2
  151. package/lib/esm/blue/errors.d.ts +2 -2
  152. package/lib/esm/blue/errors.js +2 -2
  153. package/lib/esm/blue/fetch.d.ts +2 -2
  154. package/lib/esm/blue/fetch.js +2 -2
  155. package/lib/esm/blue/utils.d.ts +1 -1
  156. package/lib/esm/blue/utils.js +1 -1
  157. package/lib/esm/entities/blue/blue.d.ts +2 -12
  158. package/lib/esm/entities/blue/blue.js +0 -4
  159. package/lib/esm/entities/index.d.ts +4 -4
  160. package/lib/esm/entities/index.js +2 -2
  161. package/lib/esm/entities/midnight/midnight.d.ts +63 -18
  162. package/lib/esm/entities/midnight/midnight.js +139 -54
  163. package/lib/esm/entities/midnight/types.d.ts +3 -10
  164. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
  165. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +1 -8
  166. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
  167. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +9 -21
  168. package/lib/esm/entities/vaultV1/vaultV1.d.ts +40 -37
  169. package/lib/esm/entities/vaultV1/vaultV1.js +6 -35
  170. package/lib/esm/entities/vaultV2/vaultV2.d.ts +69 -43
  171. package/lib/esm/entities/vaultV2/vaultV2.js +41 -35
  172. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +5 -3
  173. package/lib/esm/entities/vaultV2BlueReallocationData.js +9 -3
  174. package/lib/esm/errors.d.ts +4 -4
  175. package/lib/esm/errors.js +4 -4
  176. package/lib/esm/fetch.d.ts +2 -2
  177. package/lib/esm/fetch.js +2 -2
  178. package/lib/esm/helpers/encodeMidnightCalldata.d.ts +48 -0
  179. package/lib/esm/helpers/encodeMidnightCalldata.js +69 -0
  180. package/lib/esm/helpers/slippage.d.ts +9 -25
  181. package/lib/esm/helpers/slippage.js +9 -25
  182. package/lib/esm/helpers/validate.d.ts +1 -0
  183. package/lib/esm/helpers/validate.js +5 -0
  184. package/lib/esm/helpers/validateMidnightAccount.d.ts +34 -0
  185. package/lib/esm/helpers/validateMidnightAccount.js +43 -0
  186. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
  187. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +4 -0
  188. package/lib/esm/helpers/validateMidnightMarket.d.ts +2 -0
  189. package/lib/esm/helpers/validateMidnightMarket.js +5 -0
  190. package/lib/esm/helpers/validateMidnightPublication.d.ts +11 -0
  191. package/lib/esm/helpers/validateMidnightPublication.js +10 -0
  192. package/lib/esm/helpers/validateMidnightReceiver.d.ts +1 -0
  193. package/lib/esm/helpers/validateMidnightReceiver.js +8 -0
  194. package/lib/esm/helpers/validateTakeableOffers.d.ts +2 -1
  195. package/lib/esm/helpers/validateTakeableOffers.js +4 -3
  196. package/lib/esm/midnight/errors.d.ts +2 -1
  197. package/lib/esm/midnight/errors.js +2 -1
  198. package/lib/esm/types/action.d.ts +3 -1
  199. package/lib/esm/types/error.d.ts +60 -6
  200. package/lib/esm/types/error.js +138 -7
  201. package/lib/esm/utils.d.ts +2 -2
  202. package/lib/esm/utils.js +2 -2
  203. package/package.json +8 -7
@@ -0,0 +1,48 @@
1
+ import { type MarketInput } from "@morpho-org/midnight-sdk";
2
+ import { type Abi, type ContractFunctionName, type EncodeFunctionDataParameters, type EncodeFunctionDataReturnType } from "viem";
3
+ /**
4
+ * `encodeFunctionData` for Midnight builders that reports invalid inputs as a typed SDK error.
5
+ *
6
+ * @internal
7
+ * @param parameters - viem `encodeFunctionData` parameters.
8
+ * @returns The encoded calldata.
9
+ * @throws {MidnightCalldataEncodingError} when viem cannot encode an argument.
10
+ * @example
11
+ * ```ts
12
+ * import { midnightAbi } from "@morpho-org/midnight-sdk";
13
+ *
14
+ * const data = encodeMidnightCalldata({
15
+ * abi: midnightAbi,
16
+ * functionName: "setIsAuthorized",
17
+ * args: [operator, true, owner],
18
+ * });
19
+ * ```
20
+ */
21
+ export declare function encodeMidnightCalldata<const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi> | undefined = undefined>(parameters: EncodeFunctionDataParameters<abi, functionName>): EncodeFunctionDataReturnType;
22
+ /**
23
+ * Runs a Midnight ABI encoding step and reports a viem encoding failure as a typed SDK error.
24
+ *
25
+ * @internal
26
+ * @param name - Name of the encoded value, reported as the error's `input`.
27
+ * @param encode - Encoding step, such as hashing a market or an offer tree.
28
+ * @returns The encoding step's result.
29
+ * @throws {MidnightCalldataEncodingError} when `encode` throws a viem error.
30
+ * @example
31
+ * ```ts
32
+ * const tree = wrapMidnightEncoding("offers", () => Tree.from(offers));
33
+ * ```
34
+ */
35
+ export declare function wrapMidnightEncoding<T>(name: string, encode: () => T): T;
36
+ /**
37
+ * `MarketUtils.toId` for Midnight builders that reports an unencodable market as a typed SDK error.
38
+ *
39
+ * @internal
40
+ * @param market - Midnight market whose struct is ABI-encoded and hashed.
41
+ * @returns The market id.
42
+ * @throws {MidnightCalldataEncodingError} when viem cannot encode a market field.
43
+ * @example
44
+ * ```ts
45
+ * const marketId = encodeMidnightMarketId(market);
46
+ * ```
47
+ */
48
+ export declare function encodeMidnightMarketId(market: MarketInput): `0x${string}`;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeMidnightCalldata = encodeMidnightCalldata;
4
+ exports.wrapMidnightEncoding = wrapMidnightEncoding;
5
+ exports.encodeMidnightMarketId = encodeMidnightMarketId;
6
+ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
7
+ const viem_1 = require("viem");
8
+ const index_js_1 = require("../types/index.js");
9
+ /**
10
+ * `encodeFunctionData` for Midnight builders that reports invalid inputs as a typed SDK error.
11
+ *
12
+ * @internal
13
+ * @param parameters - viem `encodeFunctionData` parameters.
14
+ * @returns The encoded calldata.
15
+ * @throws {MidnightCalldataEncodingError} when viem cannot encode an argument.
16
+ * @example
17
+ * ```ts
18
+ * import { midnightAbi } from "@morpho-org/midnight-sdk";
19
+ *
20
+ * const data = encodeMidnightCalldata({
21
+ * abi: midnightAbi,
22
+ * functionName: "setIsAuthorized",
23
+ * args: [operator, true, owner],
24
+ * });
25
+ * ```
26
+ */
27
+ function encodeMidnightCalldata(parameters) {
28
+ try {
29
+ return (0, viem_1.encodeFunctionData)(parameters);
30
+ }
31
+ catch (error) {
32
+ if (!(error instanceof viem_1.BaseError))
33
+ throw error;
34
+ throw new index_js_1.MidnightCalldataEncodingError(String(parameters.functionName), error);
35
+ }
36
+ }
37
+ /**
38
+ * Runs a Midnight ABI encoding step and reports a viem encoding failure as a typed SDK error.
39
+ *
40
+ * @internal
41
+ * @param name - Name of the encoded value, reported as the error's `input`.
42
+ * @param encode - Encoding step, such as hashing a market or an offer tree.
43
+ * @returns The encoding step's result.
44
+ * @throws {MidnightCalldataEncodingError} when `encode` throws a viem error.
45
+ * @example
46
+ * ```ts
47
+ * const tree = wrapMidnightEncoding("offers", () => Tree.from(offers));
48
+ * ```
49
+ */
50
+ function wrapMidnightEncoding(name, encode) {
51
+ try {
52
+ return encode();
53
+ }
54
+ catch (error) {
55
+ if (!(error instanceof viem_1.BaseError))
56
+ throw error;
57
+ throw new index_js_1.MidnightCalldataEncodingError(name, error);
58
+ }
59
+ }
60
+ /**
61
+ * `MarketUtils.toId` for Midnight builders that reports an unencodable market as a typed SDK error.
62
+ *
63
+ * @internal
64
+ * @param market - Midnight market whose struct is ABI-encoded and hashed.
65
+ * @returns The market id.
66
+ * @throws {MidnightCalldataEncodingError} when viem cannot encode a market field.
67
+ * @example
68
+ * ```ts
69
+ * const marketId = encodeMidnightMarketId(market);
70
+ * ```
71
+ */
72
+ function encodeMidnightMarketId(market) {
73
+ return wrapMidnightEncoding("marketId", () => midnight_sdk_1.MarketUtils.toId(market));
74
+ }
@@ -92,19 +92,22 @@ export declare const computeVaultMaxSharePrice: (params: {
92
92
  readonly slippageTolerance: bigint;
93
93
  }) => bigint;
94
94
  /**
95
- * Computes the exact vault-share authorization cap for an asset-denominated exit.
95
+ * Computes the minimum vault-share allowance required for an asset-denominated exit.
96
96
  *
97
- * The cap covers both the current and deadline-accrued preview. Vault V2 and MetaMorpho 1.0 divide
98
- * by `1 - slippageTolerance`, rounding up, to cover a share-price decline before inclusion;
97
+ * The requirement covers both the current and deadline-accrued preview. Vault V2 and MetaMorpho 1.0
98
+ * divide by `1 - slippageTolerance`, rounding up, to cover a share-price decline before inclusion;
99
99
  * MetaMorpho 1.1's `lostAssets` clamp keeps that preview upper-bounded without widening it.
100
100
  *
101
+ * "Max" refers to the most shares the exit is expected to burn at the tolerated price, which is
102
+ * the minimum allowance the SDK requires.
103
+ *
101
104
  * @param params - Vault snapshot, execution deadline, asset amount, and WAD-scaled slippage.
102
105
  * @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
103
106
  * @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
104
107
  * @param params.assets - Assets withdrawn from the vault, in the underlying token's smallest unit.
105
108
  * @param params.slippageTolerance - Accepted share-price decline as a WAD-scaled fraction (`1e18` = 100%).
106
- * @returns The maximum shares the prepared operation may burn.
107
- * @throws {NonPositiveInputError} when `assets` or the computed share cap is not positive.
109
+ * @returns The minimum share allowance required by the prepared exit.
110
+ * @throws {NonPositiveInputError} when `assets` or the computed required share amount is not positive.
108
111
  * @throws {NegativeInputError} when `slippageTolerance` is negative.
109
112
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
110
113
  * @example
@@ -126,7 +129,7 @@ export declare const computeVaultMaxSharePrice: (params: {
126
129
  * assets: 1_000_000n,
127
130
  * slippageTolerance: 500_000_000_000_000n,
128
131
  * });
129
- * // shares is the exact allowance or permit value for the prepared exit.
132
+ * // shares is the minimum required allowance for the prepared exit.
130
133
  * ```
131
134
  */
132
135
  export declare const computeVaultMaxShareAllowance: (params: {
@@ -135,22 +138,3 @@ export declare const computeVaultMaxShareAllowance: (params: {
135
138
  readonly assets: bigint;
136
139
  readonly slippageTolerance: bigint;
137
140
  }) => bigint;
138
- /**
139
- * Computes the largest live share allowance a re-prepared asset-mode exit accepts without a reset.
140
- *
141
- * A Safe approval can execute after the caller re-prepared the exit from a fresher snapshot, whose
142
- * cap is slightly lower. Allowances in `[requiredShareAllowance, ceiling]` are kept, so the burn may
143
- * exceed the current cap by at most one more slippage tolerance.
144
- *
145
- * @internal
146
- *
147
- * @param params.requiredShareAllowance - Cap from {@link computeVaultMaxShareAllowance}.
148
- * @param params.slippageTolerance - WAD-scaled slippage used to derive that cap.
149
- * @returns `requiredShareAllowance / (1 - slippageTolerance)`, rounded down.
150
- * @throws {NegativeInputError} when `slippageTolerance` is negative.
151
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
152
- */
153
- export declare const computeVaultShareAllowanceCeiling: (params: {
154
- readonly requiredShareAllowance: bigint;
155
- readonly slippageTolerance: bigint;
156
- }) => bigint;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computeVaultShareAllowanceCeiling = exports.computeVaultMaxShareAllowance = exports.computeVaultMaxSharePrice = void 0;
3
+ exports.computeVaultMaxShareAllowance = exports.computeVaultMaxSharePrice = void 0;
4
4
  exports.computeMinForceWithdrawSharePrice = computeMinForceWithdrawSharePrice;
5
5
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  const index_js_1 = require("../types/index.js");
@@ -134,19 +134,22 @@ const computeVaultMaxSharePrice = (params) => {
134
134
  };
135
135
  exports.computeVaultMaxSharePrice = computeVaultMaxSharePrice;
136
136
  /**
137
- * Computes the exact vault-share authorization cap for an asset-denominated exit.
137
+ * Computes the minimum vault-share allowance required for an asset-denominated exit.
138
138
  *
139
- * The cap covers both the current and deadline-accrued preview. Vault V2 and MetaMorpho 1.0 divide
140
- * by `1 - slippageTolerance`, rounding up, to cover a share-price decline before inclusion;
139
+ * The requirement covers both the current and deadline-accrued preview. Vault V2 and MetaMorpho 1.0
140
+ * divide by `1 - slippageTolerance`, rounding up, to cover a share-price decline before inclusion;
141
141
  * MetaMorpho 1.1's `lostAssets` clamp keeps that preview upper-bounded without widening it.
142
142
  *
143
+ * "Max" refers to the most shares the exit is expected to burn at the tolerated price, which is
144
+ * the minimum allowance the SDK requires.
145
+ *
143
146
  * @param params - Vault snapshot, execution deadline, asset amount, and WAD-scaled slippage.
144
147
  * @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
145
148
  * @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
146
149
  * @param params.assets - Assets withdrawn from the vault, in the underlying token's smallest unit.
147
150
  * @param params.slippageTolerance - Accepted share-price decline as a WAD-scaled fraction (`1e18` = 100%).
148
- * @returns The maximum shares the prepared operation may burn.
149
- * @throws {NonPositiveInputError} when `assets` or the computed share cap is not positive.
151
+ * @returns The minimum share allowance required by the prepared exit.
152
+ * @throws {NonPositiveInputError} when `assets` or the computed required share amount is not positive.
150
153
  * @throws {NegativeInputError} when `slippageTolerance` is negative.
151
154
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
152
155
  * @example
@@ -168,7 +171,7 @@ exports.computeVaultMaxSharePrice = computeVaultMaxSharePrice;
168
171
  * assets: 1_000_000n,
169
172
  * slippageTolerance: 500_000_000_000_000n,
170
173
  * });
171
- * // shares is the exact allowance or permit value for the prepared exit.
174
+ * // shares is the minimum required allowance for the prepared exit.
172
175
  * ```
173
176
  */
174
177
  const computeVaultMaxShareAllowance = (params) => {
@@ -192,23 +195,3 @@ const computeVaultMaxShareAllowance = (params) => {
192
195
  : previewedShares;
193
196
  };
194
197
  exports.computeVaultMaxShareAllowance = computeVaultMaxShareAllowance;
195
- /**
196
- * Computes the largest live share allowance a re-prepared asset-mode exit accepts without a reset.
197
- *
198
- * A Safe approval can execute after the caller re-prepared the exit from a fresher snapshot, whose
199
- * cap is slightly lower. Allowances in `[requiredShareAllowance, ceiling]` are kept, so the burn may
200
- * exceed the current cap by at most one more slippage tolerance.
201
- *
202
- * @internal
203
- *
204
- * @param params.requiredShareAllowance - Cap from {@link computeVaultMaxShareAllowance}.
205
- * @param params.slippageTolerance - WAD-scaled slippage used to derive that cap.
206
- * @returns `requiredShareAllowance / (1 - slippageTolerance)`, rounded down.
207
- * @throws {NegativeInputError} when `slippageTolerance` is negative.
208
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
209
- */
210
- const computeVaultShareAllowanceCeiling = (params) => {
211
- (0, validate_js_1.validateSlippageTolerance)(params.slippageTolerance);
212
- return blue_sdk_1.MathLib.wDivDown(params.requiredShareAllowance, blue_sdk_1.MathLib.WAD - params.slippageTolerance);
213
- };
214
- exports.computeVaultShareAllowanceCeiling = computeVaultShareAllowanceCeiling;
@@ -284,6 +284,7 @@ export declare const validateNativeAsset: (chainId: number, asset: Address) => v
284
284
  * @returns The transaction `value` and the `wrappedNative` contract argument.
285
285
  * @throws {NegativeInputError} when `nativeAmount` is negative.
286
286
  * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
287
+ * @throws {MidnightCalldataEncodingError} when a pulled `token` is not a 20-byte hex address.
287
288
  * @throws {NativeAmountOnNonWNativeAssetError} when pulls are non-empty and none use wNative.
288
289
  * @throws {InputExceedsMaxError} when `nativeAmount` exceeds the maximum wNative pull, including
289
290
  * when the call pulls none.
@@ -8,6 +8,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
8
8
  const viem_1 = require("viem");
9
9
  const index_js_1 = require("../types/index.js");
10
10
  const constant_js_1 = require("./constant.js");
11
+ const validateMidnightAccount_js_1 = require("./validateMidnightAccount.js");
11
12
  /** @internal */
12
13
  const compareMarketIds = (idA, idB) => {
13
14
  const normalizedIdA = idA.toLowerCase();
@@ -379,6 +380,7 @@ exports.validateNativeAsset = validateNativeAsset;
379
380
  * @returns The transaction `value` and the `wrappedNative` contract argument.
380
381
  * @throws {NegativeInputError} when `nativeAmount` is negative.
381
382
  * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
383
+ * @throws {MidnightCalldataEncodingError} when a pulled `token` is not a 20-byte hex address.
382
384
  * @throws {NativeAmountOnNonWNativeAssetError} when pulls are non-empty and none use wNative.
383
385
  * @throws {InputExceedsMaxError} when `nativeAmount` exceeds the maximum wNative pull, including
384
386
  * when the call pulls none.
@@ -409,6 +411,9 @@ const validateMidnightNativeAmount = (params) => {
409
411
  if (!(0, morpho_ts_1.isDefined)(wNative)) {
410
412
  throw new index_js_1.ChainWNativeMissingError(chainId);
411
413
  }
414
+ // Reject a malformed address before viem compares it with wNative.
415
+ for (const pull of pulls)
416
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)("token", pull.token);
412
417
  const wNativePulled = pulls.reduce((total, pull) => (0, viem_1.isAddressEqual)(pull.token, wNative) ? total + pull.assets : total, 0n);
413
418
  const firstPull = pulls[0];
414
419
  if (firstPull && !pulls.some((pull) => (0, viem_1.isAddressEqual)(pull.token, wNative))) {
@@ -0,0 +1,34 @@
1
+ import { type Address } from "viem";
2
+ import { MidnightZeroAccountError } from "../types/index.js";
3
+ /**
4
+ * Rejects the zero address as the account a Midnight flow prepares or encodes for.
5
+ *
6
+ * @internal
7
+ * @param field - Account field name reported by the error.
8
+ * @param account - Account to validate.
9
+ * @returns Nothing; returns normally when `account` is a well-formed non-zero address.
10
+ * @throws {MidnightCalldataEncodingError} when `account` is not a 20-byte hex address with a valid
11
+ * checksum when mixed-case.
12
+ * @throws {MidnightZeroAccountError} when `account` is the zero address.
13
+ * @example
14
+ * ```ts
15
+ * validateMidnightAccount("accountAddress", "0x0000000000000000000000000000000000000001");
16
+ * ```
17
+ */
18
+ export declare function validateMidnightAccount(field: MidnightZeroAccountError["field"], account: Address): void;
19
+ /**
20
+ * Rejects a malformed address before a Midnight builder compares or encodes it, so callers get the
21
+ * typed encoding error instead of viem's `InvalidAddressError`.
22
+ *
23
+ * @internal
24
+ * @param field - Input name reported as the error's `input`, such as `"receiver"`.
25
+ * @param address - Address to validate.
26
+ * @returns Nothing; returns normally for a 20-byte hex address with a valid checksum when mixed-case.
27
+ * @throws {MidnightCalldataEncodingError} when `address` is not a 20-byte hex address with a valid
28
+ * checksum when mixed-case.
29
+ * @example
30
+ * ```ts
31
+ * validateMidnightAddress("receiver", "0x0000000000000000000000000000000000000001");
32
+ * ```
33
+ */
34
+ export declare function validateMidnightAddress(field: string, address: Address): void;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateMidnightAccount = validateMidnightAccount;
4
+ exports.validateMidnightAddress = validateMidnightAddress;
5
+ const viem_1 = require("viem");
6
+ const index_js_1 = require("../types/index.js");
7
+ /**
8
+ * Rejects the zero address as the account a Midnight flow prepares or encodes for.
9
+ *
10
+ * @internal
11
+ * @param field - Account field name reported by the error.
12
+ * @param account - Account to validate.
13
+ * @returns Nothing; returns normally when `account` is a well-formed non-zero address.
14
+ * @throws {MidnightCalldataEncodingError} when `account` is not a 20-byte hex address with a valid
15
+ * checksum when mixed-case.
16
+ * @throws {MidnightZeroAccountError} when `account` is the zero address.
17
+ * @example
18
+ * ```ts
19
+ * validateMidnightAccount("accountAddress", "0x0000000000000000000000000000000000000001");
20
+ * ```
21
+ */
22
+ function validateMidnightAccount(field, account) {
23
+ validateMidnightAddress(field, account);
24
+ if ((0, viem_1.isAddressEqual)(account, viem_1.zeroAddress)) {
25
+ throw new index_js_1.MidnightZeroAccountError(field);
26
+ }
27
+ }
28
+ /**
29
+ * Rejects a malformed address before a Midnight builder compares or encodes it, so callers get the
30
+ * typed encoding error instead of viem's `InvalidAddressError`.
31
+ *
32
+ * @internal
33
+ * @param field - Input name reported as the error's `input`, such as `"receiver"`.
34
+ * @param address - Address to validate.
35
+ * @returns Nothing; returns normally for a 20-byte hex address with a valid checksum when mixed-case.
36
+ * @throws {MidnightCalldataEncodingError} when `address` is not a 20-byte hex address with a valid
37
+ * checksum when mixed-case.
38
+ * @example
39
+ * ```ts
40
+ * validateMidnightAddress("receiver", "0x0000000000000000000000000000000000000001");
41
+ * ```
42
+ */
43
+ function validateMidnightAddress(field, address) {
44
+ if (!(0, viem_1.isAddress)(address)) {
45
+ throw new index_js_1.MidnightCalldataEncodingError(field, new viem_1.InvalidAddressError({ address }));
46
+ }
47
+ }
@@ -6,6 +6,7 @@ import { type Address } from "viem";
6
6
  * @param params.chainId - Chain id used to resolve supported Midnight operators.
7
7
  * @param params.authorized - Operator address receiving authorization.
8
8
  * @returns Nothing after the operator matches MidnightBundlesV2.
9
+ * @throws {MidnightCalldataEncodingError} when `authorized` is not a 20-byte hex address.
9
10
  * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported operator.
10
11
  * @internal
11
12
  */
@@ -4,6 +4,7 @@ exports.validateMidnightAuthorizationTarget = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const viem_1 = require("viem");
6
6
  const index_js_1 = require("../types/index.js");
7
+ const validateMidnightAccount_js_1 = require("./validateMidnightAccount.js");
7
8
  /**
8
9
  * Validates that a Midnight authorization grant targets a supported protocol operator.
9
10
  *
@@ -11,10 +12,13 @@ const index_js_1 = require("../types/index.js");
11
12
  * @param params.chainId - Chain id used to resolve supported Midnight operators.
12
13
  * @param params.authorized - Operator address receiving authorization.
13
14
  * @returns Nothing after the operator matches MidnightBundlesV2.
15
+ * @throws {MidnightCalldataEncodingError} when `authorized` is not a 20-byte hex address.
14
16
  * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported operator.
15
17
  * @internal
16
18
  */
17
19
  const validateMidnightAuthorizationTarget = (params) => {
20
+ // Reject a malformed address before viem compares it.
21
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)("authorized", params.authorized);
18
22
  const { midnightBundlesV2 } = (0, morpho_ts_1.getChainAddresses)(params.chainId);
19
23
  const supportedTargets = midnightBundlesV2 == null ? [] : [midnightBundlesV2];
20
24
  if (!supportedTargets.some((supported) => (0, viem_1.isAddressEqual)(params.authorized, supported))) {
@@ -2,6 +2,8 @@ import type { MarketInput } from "@morpho-org/midnight-sdk";
2
2
  /**
3
3
  * Validates that a Midnight market belongs to the configured chain deployment.
4
4
  *
5
+ * @throws {MidnightCalldataEncodingError} when `market.midnight` is not a 20-byte hex address.
6
+ *
5
7
  * @internal
6
8
  */
7
9
  export declare const validateMidnightMarket: (params: {
@@ -5,14 +5,19 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const viem_1 = require("viem");
6
6
  const index_js_1 = require("../types/index.js");
7
7
  const validate_js_1 = require("./validate.js");
8
+ const validateMidnightAccount_js_1 = require("./validateMidnightAccount.js");
8
9
  /**
9
10
  * Validates that a Midnight market belongs to the configured chain deployment.
10
11
  *
12
+ * @throws {MidnightCalldataEncodingError} when `market.midnight` is not a 20-byte hex address.
13
+ *
11
14
  * @internal
12
15
  */
13
16
  const validateMidnightMarket = (params) => {
14
17
  const market = "params" in params.market ? params.market.params : params.market;
15
18
  (0, validate_js_1.validateChainId)(Number(market.chainId), params.chainId);
19
+ // Reject a malformed address before viem compares it.
20
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)("market.midnight", market.midnight);
16
21
  const expectedMidnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
17
22
  if (!(0, viem_1.isAddressEqual)(market.midnight, expectedMidnight)) {
18
23
  throw new index_js_1.MidnightMarketAddressMismatchError({
@@ -1,3 +1,4 @@
1
+ import { type Hex } from "viem";
1
2
  import type { MidnightCancelAndMakeParams } from "../types/midnightCancelAndMake.js";
2
3
  /** @internal */
3
4
  export declare const snapshotMidnightCancelAndMakeParams: (params: MidnightCancelAndMakeParams) => MidnightCancelAndMakeParams;
@@ -10,3 +11,13 @@ export declare const snapshotMidnightCancelAndMakeParams: (params: MidnightCance
10
11
  * callback salt, or root-signature `r`/`s` is not 32-byte hex, or payload is malformed or oversized.
11
12
  */
12
13
  export declare const validateMidnightPublication: (params: MidnightCancelAndMakeParams) => void;
14
+ /**
15
+ * @internal
16
+ * Rejects a value that is not exactly 32 bytes of hex before a Midnight flow derives or encodes
17
+ * from it.
18
+ *
19
+ * @param field - Input name reported by the error.
20
+ * @param value - Fixed-length bytes value to validate.
21
+ * @throws {InvalidMidnightHexInputError} when `value` is not exactly 32 bytes of hex.
22
+ */
23
+ export declare const validateMidnightBytes32: (field: string, value: Hex) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateMidnightPublication = exports.snapshotMidnightCancelAndMakeParams = void 0;
3
+ exports.validateMidnightBytes32 = exports.validateMidnightPublication = exports.snapshotMidnightCancelAndMakeParams = void 0;
4
4
  const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  const viem_1 = require("viem");
6
6
  const index_js_1 = require("../types/index.js");
@@ -110,6 +110,17 @@ const validateMidnightPublication = (params) => {
110
110
  });
111
111
  };
112
112
  exports.validateMidnightPublication = validateMidnightPublication;
113
+ /**
114
+ * @internal
115
+ * Rejects a value that is not exactly 32 bytes of hex before a Midnight flow derives or encodes
116
+ * from it.
117
+ *
118
+ * @param field - Input name reported by the error.
119
+ * @param value - Fixed-length bytes value to validate.
120
+ * @throws {InvalidMidnightHexInputError} when `value` is not exactly 32 bytes of hex.
121
+ */
122
+ const validateMidnightBytes32 = (field, value) => validateHexInput(value, field, { exactBytes: 32 });
123
+ exports.validateMidnightBytes32 = validateMidnightBytes32;
113
124
  // biome-ignore lint/complexity/useMaxParams: Keep value, field, and size explicit.
114
125
  const validateHexInput = (value, field, size) => {
115
126
  if (!(0, viem_1.isHex)(value)) {
@@ -12,6 +12,7 @@ import { type Address } from "viem";
12
12
  * @param params.market - Midnight market whose token contracts are also rejected.
13
13
  * @param params.field - Receiver field being validated, reported on the thrown error.
14
14
  * @param params.receiver - Receiver address to check.
15
+ * @throws {MidnightCalldataEncodingError} when the receiver or a market token address is malformed.
15
16
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
16
17
  * @throws {MidnightZeroReceiverError} when `receiver` is the zero address and `field` is not
17
18
  * `"referralFeeRecipient"`.
@@ -4,6 +4,7 @@ exports.validateMidnightReceiver = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const viem_1 = require("viem");
6
6
  const index_js_1 = require("../types/index.js");
7
+ const validateMidnightAccount_js_1 = require("./validateMidnightAccount.js");
7
8
  /** Registry keys of the Midnight protocol contracts that cannot forward received assets. */
8
9
  const MIDNIGHT_CONTRACT_KEYS = [
9
10
  "midnight",
@@ -28,6 +29,7 @@ const MIDNIGHT_CONTRACT_KEYS = [
28
29
  * @param params.market - Midnight market whose token contracts are also rejected.
29
30
  * @param params.field - Receiver field being validated, reported on the thrown error.
30
31
  * @param params.receiver - Receiver address to check.
32
+ * @throws {MidnightCalldataEncodingError} when the receiver or a market token address is malformed.
31
33
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
32
34
  * @throws {MidnightZeroReceiverError} when `receiver` is the zero address and `field` is not
33
35
  * `"referralFeeRecipient"`.
@@ -40,6 +42,12 @@ const MIDNIGHT_CONTRACT_KEYS = [
40
42
  const validateMidnightReceiver = (params) => {
41
43
  const { field, receiver } = params;
42
44
  const market = "params" in params.market ? params.market.params : params.market;
45
+ // Validate addresses before comparing them so malformed values stay a typed SDK error.
46
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)(field, receiver);
47
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)("market.loanToken", market.loanToken);
48
+ for (const [index, { token }] of market.collateralParams.entries()) {
49
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)(`market.collateralParams[${index}].token`, token);
50
+ }
43
51
  if ((0, viem_1.isAddressEqual)(receiver, viem_1.zeroAddress)) {
44
52
  if (field === "referralFeeRecipient") {
45
53
  throw new index_js_1.ReferralFeeRecipientMissingError();
@@ -1,4 +1,4 @@
1
- import { type MarketInput, type OfferStruct } from "@morpho-org/midnight-sdk";
1
+ import type { MarketInput, OfferStruct } from "@morpho-org/midnight-sdk";
2
2
  /**
3
3
  * Validates the pure invariants shared by Midnight take entity and action layers.
4
4
  *
@@ -7,6 +7,7 @@ import { type MarketInput, type OfferStruct } from "@morpho-org/midnight-sdk";
7
7
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
8
8
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
9
9
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
10
+ * @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
10
11
  * @internal
11
12
  */
12
13
  export declare const validateTakeableOffers: (params: {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateTakeableOffers = void 0;
4
- const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
4
  const index_js_1 = require("../types/index.js");
5
+ const encodeMidnightCalldata_js_1 = require("./encodeMidnightCalldata.js");
6
6
  const validateOfferSides_js_1 = require("./validateOfferSides.js");
7
7
  /**
8
8
  * Validates the pure invariants shared by Midnight take entity and action layers.
@@ -12,16 +12,17 @@ const validateOfferSides_js_1 = require("./validateOfferSides.js");
12
12
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
13
13
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
14
14
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
15
+ * @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
15
16
  * @internal
16
17
  */
17
18
  const validateTakeableOffers = (params) => {
18
19
  if (params.takeableOffers.length === 0) {
19
20
  throw new index_js_1.EmptyMidnightTakeableOffersError();
20
21
  }
21
- const marketId = midnight_sdk_1.MarketUtils.toId(params.market);
22
+ const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(params.market);
22
23
  (0, validateOfferSides_js_1.validateOfferSides)(params.takeableOffers.map((take) => take.offer), params.expectedBuy);
23
24
  for (const [index, take] of params.takeableOffers.entries()) {
24
- const actualMarketId = midnight_sdk_1.MarketUtils.toId(take.offer.market);
25
+ const actualMarketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(take.offer.market);
25
26
  if (actualMarketId.toLowerCase() !== marketId.toLowerCase()) {
26
27
  throw new index_js_1.MidnightTakeableOfferMarketMismatchError({
27
28
  index,
@@ -1 +1,2 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
+ export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.ChainIdMismatchError = void 0;
3
+ exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.ChainIdMismatchError = void 0;
4
4
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  Object.defineProperty(exports, "ChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
6
6
  Object.defineProperty(exports, "InvalidEcrecoverSignatureVError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureVError; } });
@@ -9,9 +9,6 @@ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerabl
9
9
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
10
10
  Object.defineProperty(exports, "InvalidOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
11
11
  Object.defineProperty(exports, "InvalidOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
12
- Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
13
- Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
14
- Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
15
12
  Object.defineProperty(exports, "InvalidRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
16
13
  Object.defineProperty(exports, "InvalidRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
17
14
  Object.defineProperty(exports, "InvalidRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -29,3 +26,7 @@ Object.defineProperty(exports, "RatifierV1TakerNotAllowedError", { enumerable: t
29
26
  Object.defineProperty(exports, "SettlementFeeExceedsPriceError", { enumerable: true, get: function () { return midnight_sdk_1.SettlementFeeExceedsPriceError; } });
30
27
  Object.defineProperty(exports, "TickOutOfRangeError", { enumerable: true, get: function () { return midnight_sdk_1.TickOutOfRangeError; } });
31
28
  Object.defineProperty(exports, "UnknownCollateralIndexError", { enumerable: true, get: function () { return midnight_sdk_1.UnknownCollateralIndexError; } });
29
+ var morpho_ts_1 = require("@morpho-org/morpho-ts");
30
+ Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
31
+ Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
32
+ Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
@@ -37,7 +37,7 @@ export type MidnightBuyTarget = {
37
37
  */
38
38
  export type MidnightSellTarget = {
39
39
  readonly type: "assets";
40
- /** Loan assets received before the referral fee. */
40
+ /** Exact loan assets paid to `receiver`; any referral fee is sold on top of this amount. */
41
41
  readonly assets: bigint;
42
42
  readonly maxUnits: bigint;
43
43
  } | {
@@ -491,6 +491,8 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
491
491
  readonly cancellations: readonly MidnightGroupCancellation[];
492
492
  readonly collateralSupplies: readonly MidnightCollateralTransfer[];
493
493
  readonly blueSupply?: MidnightBlueSupply;
494
+ /** Native ETH wrapped into wNative to fund this bundle. */
495
+ readonly nativeAmount?: bigint;
494
496
  readonly deadline: bigint;
495
497
  }> {
496
498
  }