@morpho-org/morpho-sdk 10.3.1 → 10.4.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 (188) hide show
  1. package/README.md +169 -5
  2. package/lib/cjs/actions/midnight/redeem.d.ts +20 -3
  3. package/lib/cjs/actions/midnight/redeem.js +58 -1
  4. package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
  5. package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +41 -0
  6. package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -2
  7. package/lib/cjs/actions/midnight/withdrawCollateral.js +26 -1
  8. package/lib/cjs/helpers/callback.d.ts +3 -2
  9. package/lib/cjs/helpers/callback.js +4 -20
  10. package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
  11. package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.js +30 -0
  12. package/lib/cjs/helpers/parseMidnightMaker.d.ts +21 -0
  13. package/lib/cjs/helpers/parseMidnightMaker.js +41 -1
  14. package/lib/cjs/helpers/validate.d.ts +49 -1
  15. package/lib/cjs/helpers/validate.js +87 -1
  16. package/lib/cjs/helpers/validateMidnightPublication.d.ts +10 -0
  17. package/lib/cjs/helpers/validateMidnightPublication.js +18 -1
  18. package/lib/cjs/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
  19. package/lib/cjs/helpers/validateMidnightTakeableOfferFields.js +85 -0
  20. package/lib/cjs/index.d.ts +2 -2
  21. package/lib/cjs/index.js +23 -1
  22. package/lib/cjs/midnight/utils.d.ts +1 -1
  23. package/lib/cjs/midnight/utils.js +2 -1
  24. package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
  25. package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.js +264 -0
  26. package/lib/cjs/transactionPlan/error.d.ts +27 -0
  27. package/lib/cjs/transactionPlan/error.js +30 -1
  28. package/lib/cjs/transactionPlan/index.d.ts +40 -1
  29. package/lib/cjs/transactionPlan/index.js +46 -5
  30. package/lib/cjs/transactionPlan/midnight/authorization.d.ts +15 -0
  31. package/lib/cjs/transactionPlan/midnight/authorization.js +45 -0
  32. package/lib/cjs/transactionPlan/midnight/cancelOffers.d.ts +80 -0
  33. package/lib/cjs/transactionPlan/midnight/cancelOffers.js +125 -0
  34. package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +104 -0
  35. package/lib/cjs/transactionPlan/midnight/makeBorrow.js +126 -0
  36. package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +140 -0
  37. package/lib/cjs/transactionPlan/midnight/makeLend.js +176 -0
  38. package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +118 -0
  39. package/lib/cjs/transactionPlan/midnight/makeRepay.js +118 -0
  40. package/lib/cjs/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
  41. package/lib/cjs/transactionPlan/midnight/makeWithdraw.js +126 -0
  42. package/lib/cjs/transactionPlan/midnight/makerPublication.d.ts +55 -0
  43. package/lib/cjs/transactionPlan/midnight/makerPublication.js +315 -0
  44. package/lib/cjs/transactionPlan/midnight/market.d.ts +49 -0
  45. package/lib/cjs/transactionPlan/midnight/market.js +120 -0
  46. package/lib/cjs/transactionPlan/midnight/prepare.d.ts +244 -0
  47. package/lib/cjs/transactionPlan/midnight/prepare.js +547 -0
  48. package/lib/cjs/transactionPlan/midnight/publicationState.d.ts +24 -0
  49. package/lib/cjs/transactionPlan/midnight/publicationState.js +50 -0
  50. package/lib/cjs/transactionPlan/midnight/redeem.d.ts +102 -0
  51. package/lib/cjs/transactionPlan/midnight/redeem.js +170 -0
  52. package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
  53. package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.js +51 -0
  54. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
  55. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +328 -0
  56. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
  57. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +199 -0
  58. package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
  59. package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +190 -0
  60. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
  61. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +221 -0
  62. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
  63. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +179 -0
  64. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
  65. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +259 -0
  66. package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +304 -0
  67. package/lib/cjs/transactionPlan/midnight/takeBorrow.js +545 -0
  68. package/lib/cjs/transactionPlan/midnight/takeLend.d.ts +99 -0
  69. package/lib/cjs/transactionPlan/midnight/takeLend.js +263 -0
  70. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
  71. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +440 -0
  72. package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
  73. package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +240 -0
  74. package/lib/cjs/transactionPlan/midnight/validation.d.ts +22 -0
  75. package/lib/cjs/transactionPlan/midnight/validation.js +158 -0
  76. package/lib/cjs/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
  77. package/lib/cjs/transactionPlan/midnight/withdrawCollateral.js +228 -0
  78. package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
  79. package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.js +232 -0
  80. package/lib/cjs/transactionPlan/plan.d.ts +48 -14
  81. package/lib/cjs/transactionPlan/plan.js +103 -18
  82. package/lib/cjs/transactionPlan/requirements.d.ts +7 -4
  83. package/lib/cjs/transactionPlan/requirements.js +2 -2
  84. package/lib/cjs/transactionPlan/serde.d.ts +13 -2
  85. package/lib/cjs/transactionPlan/serde.js +68 -21
  86. package/lib/cjs/transactionPlan/types.d.ts +147 -0
  87. package/lib/cjs/transactionPlan/validateActions.d.ts +3 -1
  88. package/lib/cjs/transactionPlan/validateActions.js +31 -3
  89. package/lib/cjs/transactionPlan/validation.d.ts +1 -1
  90. package/lib/cjs/transactionPlan/validation.js +37 -1
  91. package/lib/cjs/types/error.d.ts +2 -0
  92. package/lib/cjs/types/error.js +2 -0
  93. package/lib/cjs/version.d.ts +1 -1
  94. package/lib/cjs/version.js +1 -1
  95. package/lib/esm/actions/midnight/redeem.d.ts +20 -3
  96. package/lib/esm/actions/midnight/redeem.js +56 -0
  97. package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
  98. package/lib/esm/actions/midnight/supplyCollateralWithNative.js +40 -0
  99. package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -2
  100. package/lib/esm/actions/midnight/withdrawCollateral.js +25 -1
  101. package/lib/esm/helpers/callback.d.ts +3 -2
  102. package/lib/esm/helpers/callback.js +5 -21
  103. package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
  104. package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.js +27 -0
  105. package/lib/esm/helpers/parseMidnightMaker.d.ts +21 -0
  106. package/lib/esm/helpers/parseMidnightMaker.js +40 -1
  107. package/lib/esm/helpers/validate.d.ts +49 -1
  108. package/lib/esm/helpers/validate.js +84 -1
  109. package/lib/esm/helpers/validateMidnightPublication.d.ts +10 -0
  110. package/lib/esm/helpers/validateMidnightPublication.js +16 -0
  111. package/lib/esm/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
  112. package/lib/esm/helpers/validateMidnightTakeableOfferFields.js +81 -0
  113. package/lib/esm/index.d.ts +2 -2
  114. package/lib/esm/index.js +1 -1
  115. package/lib/esm/midnight/utils.d.ts +1 -1
  116. package/lib/esm/midnight/utils.js +1 -1
  117. package/lib/esm/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
  118. package/lib/esm/transactionPlan/blue/withdrawBuyCallback.js +259 -0
  119. package/lib/esm/transactionPlan/error.d.ts +27 -0
  120. package/lib/esm/transactionPlan/error.js +28 -0
  121. package/lib/esm/transactionPlan/index.d.ts +40 -1
  122. package/lib/esm/transactionPlan/index.js +20 -1
  123. package/lib/esm/transactionPlan/midnight/authorization.d.ts +15 -0
  124. package/lib/esm/transactionPlan/midnight/authorization.js +40 -0
  125. package/lib/esm/transactionPlan/midnight/cancelOffers.d.ts +80 -0
  126. package/lib/esm/transactionPlan/midnight/cancelOffers.js +120 -0
  127. package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +104 -0
  128. package/lib/esm/transactionPlan/midnight/makeBorrow.js +123 -0
  129. package/lib/esm/transactionPlan/midnight/makeLend.d.ts +140 -0
  130. package/lib/esm/transactionPlan/midnight/makeLend.js +172 -0
  131. package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +118 -0
  132. package/lib/esm/transactionPlan/midnight/makeRepay.js +115 -0
  133. package/lib/esm/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
  134. package/lib/esm/transactionPlan/midnight/makeWithdraw.js +123 -0
  135. package/lib/esm/transactionPlan/midnight/makerPublication.d.ts +55 -0
  136. package/lib/esm/transactionPlan/midnight/makerPublication.js +310 -0
  137. package/lib/esm/transactionPlan/midnight/market.d.ts +49 -0
  138. package/lib/esm/transactionPlan/midnight/market.js +112 -0
  139. package/lib/esm/transactionPlan/midnight/prepare.d.ts +244 -0
  140. package/lib/esm/transactionPlan/midnight/prepare.js +536 -0
  141. package/lib/esm/transactionPlan/midnight/publicationState.d.ts +24 -0
  142. package/lib/esm/transactionPlan/midnight/publicationState.js +47 -0
  143. package/lib/esm/transactionPlan/midnight/redeem.d.ts +102 -0
  144. package/lib/esm/transactionPlan/midnight/redeem.js +165 -0
  145. package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
  146. package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.js +47 -0
  147. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
  148. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +323 -0
  149. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
  150. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +196 -0
  151. package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
  152. package/lib/esm/transactionPlan/midnight/supplyCollateral.js +185 -0
  153. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
  154. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +216 -0
  155. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
  156. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +176 -0
  157. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
  158. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +254 -0
  159. package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +304 -0
  160. package/lib/esm/transactionPlan/midnight/takeBorrow.js +539 -0
  161. package/lib/esm/transactionPlan/midnight/takeLend.d.ts +99 -0
  162. package/lib/esm/transactionPlan/midnight/takeLend.js +258 -0
  163. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
  164. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +435 -0
  165. package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
  166. package/lib/esm/transactionPlan/midnight/takeWithdraw.js +236 -0
  167. package/lib/esm/transactionPlan/midnight/validation.d.ts +22 -0
  168. package/lib/esm/transactionPlan/midnight/validation.js +151 -0
  169. package/lib/esm/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
  170. package/lib/esm/transactionPlan/midnight/withdrawCollateral.js +223 -0
  171. package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
  172. package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.js +227 -0
  173. package/lib/esm/transactionPlan/plan.d.ts +48 -14
  174. package/lib/esm/transactionPlan/plan.js +99 -14
  175. package/lib/esm/transactionPlan/requirements.d.ts +7 -4
  176. package/lib/esm/transactionPlan/requirements.js +2 -2
  177. package/lib/esm/transactionPlan/serde.d.ts +13 -2
  178. package/lib/esm/transactionPlan/serde.js +49 -2
  179. package/lib/esm/transactionPlan/types.d.ts +147 -0
  180. package/lib/esm/transactionPlan/validateActions.d.ts +3 -1
  181. package/lib/esm/transactionPlan/validateActions.js +31 -3
  182. package/lib/esm/transactionPlan/validation.d.ts +1 -1
  183. package/lib/esm/transactionPlan/validation.js +38 -2
  184. package/lib/esm/types/error.d.ts +2 -0
  185. package/lib/esm/types/error.js +2 -0
  186. package/lib/esm/version.d.ts +1 -1
  187. package/lib/esm/version.js +1 -1
  188. package/package.json +2 -2
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareMidnightMakeWithdraw = prepareMidnightMakeWithdraw;
4
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const authorization_js_1 = require("./authorization.js");
6
+ const makerPublication_js_1 = require("./makerPublication.js");
7
+ const prepare_js_1 = require("./prepare.js");
8
+ /**
9
+ * Prepares publication of resting reduce-only sell offers through MidnightBundlesV2.
10
+ * The bundle activates the PriceRatifierV1 or RateRatifierV1 root and can cancel old groups
11
+ * atomically. The maker must have current credit in each offer's market. Publication does not
12
+ * reduce that credit or transfer tokens. An eventual fill is a separate transaction.
13
+ *
14
+ * No token approval or signature is needed. The standalone bundle authorization (if needed)
15
+ * and the ratifier grant made by the bundle persist until revoked.
16
+ * Builds the offer tree and checks the offer-capped `expiresAt` first, then validates the
17
+ * publication with a plan-side copy of the entity `makeWithdraw` constructor, in its order, except
18
+ * that malformed cancellations are rejected before any state read, and a bundle deadline already
19
+ * reached at the pinned block is rejected before the mempool API call, which the entity flow does
20
+ * not check. So an
21
+ * input with several errors can fail on the tree or expiry here where the entity reports another
22
+ * error first. The chain and the bundle, Midnight and ratifier code are checked once, right before
23
+ * the first publication-state read.
24
+ *
25
+ * @param client - Plain viem client used to check network, deployments, offers and bundle authorization.
26
+ * @param params - Maker, caller-supplied tree or tree creation request, and optional cancellations.
27
+ * @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the first offer expiry minus one second.
28
+ * @returns A frozen plan that can be restored and built offline without the original tree.
29
+ * @throws {InvalidBigIntInputError} If a supplied non-null `now` or a cancellation ceiling is not a bigint;
30
+ * checked before any request.
31
+ * @throws {ZeroAccountError} If the submitting account is zero.
32
+ * @throws {InvalidTransactionPlanError} If the account is not an address, calldata origin exceeds 1 MiB,
33
+ * or a supplied non-null `cancellations` is not an array or has a non-object entry; checked
34
+ * before any request.
35
+ * @throws {InvalidCalldataOriginError} If the supplied calldata origin is not nonempty, even-length hex.
36
+ * @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
37
+ * @throws {NonPositiveInputError} If `expiresAt` is not positive.
38
+ * @throws {NegativeInputError} If a cancellation ceiling is negative.
39
+ * @throws {InvalidTreeError} If the offer tree is empty or invalid.
40
+ * @throws {InvalidTreeHeightError} If the tree exceeds the maximum height.
41
+ * @throws {InvalidMidnightOfferGroupError} If a tree request uses an invalid explicit group.
42
+ * @throws {InvalidMidnightRateRatifierV1RateError} If a Rate V1 tree request has a negative leaf rate.
43
+ * @throws {InvalidMidnightRateRatifierV1TickError} If a Rate V1 tree request has an offer tick below the ratifier's minimum.
44
+ * @throws {MidnightCalldataEncodingError} If the offer tree or bundle input cannot be ABI-encoded.
45
+ * @throws {MidnightOfferSideMismatchError} If an offer is not a sell offer.
46
+ * @throws {MidnightOfferNotReduceOnlyError} If an offer is not reduce-only.
47
+ * @throws {MidnightOfferNoCreditError} If the maker has no credit in an offer's market.
48
+ * @throws {MidnightOfferMakerMismatchError} If an offer names another maker.
49
+ * @throws {MidnightOfferSellerReceiverMismatchError} If an offer routes proceeds to someone other than the maker.
50
+ * @throws {MidnightOfferCallbackNotSupportedError} If an offer has a callback.
51
+ * @throws {MidnightOfferContinuousFeeCapError} If an offer sets a nonzero continuous fee cap.
52
+ * @throws {MidnightOfferRatifierMismatchError} If an offer names a different ratifier than the tree's route.
53
+ * @throws {InvalidMidnightHexInputError} If a cancellation group is not bytes32.
54
+ * @throws {DuplicateMidnightGroupCancellationError} If a group is cancelled more than once.
55
+ * @throws {MidnightReplacementGroupCancelledError} If a cancelled group appears in the new tree.
56
+ * @throws {InputExceedsMaxError} If explicit expiry is at or after the first offer expiry while every offer is still live at the reference time, or a cancellation ceiling exceeds uint128.
57
+ * @throws {ExpiredDeadlineError} If the resolved deadline is at or before the reference time or
58
+ * pinned block timestamp, or an offer has expired by the reference time but not at the pinned
59
+ * block; this skips API validation.
60
+ * @throws {MidnightOfferExpiredError} If an offer has expired at the pinned block.
61
+ * @throws {MidnightOfferExpiryAfterMaturityError} If an offer expiry exceeds its market maturity.
62
+ * @throws {MidnightOfferGroupConsumedError} If an offer group has no capacity remaining.
63
+ * @throws {MidnightOfferTickSpacingError} If an offer tick is not accessible in its market.
64
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} If the market fee exceeds an offer's cap.
65
+ * @throws {MidnightOfferZeroPriceSellError} If a sell offer has a zero tick.
66
+ * @throws {MidnightOfferRateBoundUnreachableError} If a Rate V1 offer cannot satisfy its rate bound.
67
+ * @throws {MidnightMarketMaturityTooFarError} If an uncreated market matures more than 100 years after the offer expires.
68
+ * @throws {MidnightMarketLltvNotEnabledError} If an uncreated market uses a disabled LLTV.
69
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} If an uncreated market uses a disabled liquidation cursor.
70
+ * @throws {MidnightMarketOracleWithoutCodeError} If an uncreated market's oracle has no code.
71
+ * @throws {MidnightOfferMarketChainMismatchError} If an offer's market uses another chain.
72
+ * @throws {MidnightOfferMarketAddressMismatchError} If an offer's market names another Midnight deployment.
73
+ * @throws {MidnightPayloadDecodeError} If the offers cannot be encoded in the publication payload,
74
+ * including when the encoded payload exceeds its size limit; split the offer tree.
75
+ * @throws {ChainIdMismatchError} If the configured or transport chain differs from `chainId`.
76
+ * @throws {UnsupportedChainIdError} If the chain has no address registry.
77
+ * @throws {UnknownAddressError} If a required deployment is not registered.
78
+ * @throws {MissingContractCodeError} If a registered write target has no code.
79
+ * @throws {MidnightMempoolValidationError} If optional API validation rejects the tree.
80
+ * @throws {MidnightApiError} If API validation returns a non-2xx response.
81
+ * @throws {InvalidMidnightApiResponseError} If the API returns malformed successful validation data.
82
+ * @throws {viem.BaseError} If a chain, deployment, pinned offer-state or authorization read fails.
83
+ * @example
84
+ * ```ts
85
+ * import { buildTransactions, prepareMidnightMakeWithdraw } from "@morpho-org/morpho-sdk";
86
+ * import { type Offer, Tree } from "@morpho-org/morpho-sdk/midnight/entities";
87
+ * import { type Address, createPublicClient, http } from "viem";
88
+ * import { base } from "viem/chains";
89
+ *
90
+ * async function buildExit(maker: Address, exitOffers: readonly Offer[]) {
91
+ * const client = createPublicClient({ chain: base, transport: http() });
92
+ * // Use the maker's proposed reduce-only sell offers naming the Base PriceRatifierV1.
93
+ * const offers = Tree.create({ type: "priceV1", entries: exitOffers.map(offer => ({ offer })) });
94
+ * const plan = await prepareMidnightMakeWithdraw(client, {
95
+ * chainId: base.id, account: maker, offers, now: (await client.getBlock()).timestamp,
96
+ * });
97
+ * // Simulate, then send in order from maker on Base.
98
+ * return buildTransactions(plan);
99
+ * }
100
+ * ```
101
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
102
+ */
103
+ async function prepareMidnightMakeWithdraw(client, params) {
104
+ const { chainId, account } = params;
105
+ const { inputs, calldataOrigin } = await (0, makerPublication_js_1.prepareMidnightMakerPublication)(client, { params, parse: prepare_js_1.parseMakeWithdrawParams });
106
+ const authorization = await (0, authorization_js_1.prepareMidnightBundleAuthorization)(client, {
107
+ chainId,
108
+ account,
109
+ });
110
+ return (0, morpho_ts_1.deepFreeze)({
111
+ version: 2,
112
+ chainId,
113
+ account,
114
+ expiresAt: Number(inputs.deadline),
115
+ ...(calldataOrigin && { calldataOrigin }),
116
+ steps: [
117
+ ...(authorization === undefined ? [] : [authorization]),
118
+ {
119
+ id: "midnightMakeWithdraw",
120
+ label: "Publish Midnight withdrawal offers",
121
+ action: { type: "midnightMakeWithdraw", inputs },
122
+ },
123
+ ],
124
+ signatureRequests: [],
125
+ });
126
+ }
@@ -0,0 +1,55 @@
1
+ import { type Client, type Hex } from "viem";
2
+ import { type ParsedMidnightCancelAndMake } from "../../actions/midnight/cancelAndMake.js";
3
+ import type { GetOffersDataParams, MakeOffersParams, OffersData } from "../../entities/midnight/types.js";
4
+ import { type IntentParams } from "../intent.js";
5
+ import type { Action } from "../types.js";
6
+ import type { MakerParamsContext } from "./prepare.js";
7
+ type MakerPublicationAction = Extract<Action, {
8
+ type: "midnightMakeBorrow" | "midnightMakeLend" | "midnightMakeRepay" | "midnightMakeWithdraw" | "midnightSupplyCollateralMakeBorrow" | "midnightSupplyBlueMakeLend";
9
+ }>;
10
+ type CollateralFunding = Pick<Extract<Action, {
11
+ type: "midnightSupplyCollateralMakeBorrow";
12
+ }>["inputs"], "collateral" | "nativeAssets">;
13
+ type BlueFunding = Pick<Extract<Action, {
14
+ type: "midnightSupplyBlueMakeLend";
15
+ }>["inputs"], "blueSupply" | "nativeAssets">;
16
+ type MidnightMakerPublicationInputs = Omit<MakerPublicationAction["inputs"], keyof CollateralFunding | keyof BlueFunding>;
17
+ /**
18
+ * Inputs shared by every resting Midnight maker publication plan.
19
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
20
+ */
21
+ export interface MidnightMakerPublicationPlanParams extends Pick<IntentParams, "chainId" | "account" | "calldataOrigin">, Pick<GetOffersDataParams, "offers" | "validation"> {
22
+ /** Optional groups to cancel atomically with publication; must not overlap the new tree. */
23
+ readonly cancellations?: MakerPublicationAction["inputs"]["cancellations"];
24
+ /** Unix seconds, strictly before every offer expiry. Defaults to the earlier of now + 2 hours and the earliest offer expiry minus one second. */
25
+ readonly expiresAt?: number;
26
+ /** Reference time in Unix seconds for plan expiry; defaults to the device clock. */
27
+ readonly now?: bigint;
28
+ }
29
+ /**
30
+ * @internal Resolves the plan intent and offer-capped deadline, then runs the operation's maker
31
+ * parse constructor with a chain check that also checks bundle, Midnight and ratifier code once,
32
+ * right before the first publication-state read, plus any operation-specific `codeRoles`. The
33
+ * constructor also rejects a deadline at or before the pinned block timestamp while every offer
34
+ * is live.
35
+ */
36
+ export declare function prepareMidnightMakerPublication<Parsed extends {
37
+ readonly action: ParsedMidnightCancelAndMake;
38
+ readonly data: OffersData;
39
+ }>(client: Client, { params, parse, codeRoles, }: {
40
+ readonly params: MidnightMakerPublicationPlanParams;
41
+ readonly codeRoles?: readonly ("blue" | "midnightBlueBuyCallbackFactory")[];
42
+ readonly parse: (raw: MakeOffersParams, context: MakerParamsContext) => Promise<Parsed>;
43
+ }): Promise<{
44
+ readonly parsed: Parsed;
45
+ readonly inputs: MidnightMakerPublicationInputs;
46
+ readonly calldataOrigin: Hex | undefined;
47
+ }>;
48
+ /** @internal Encodes a maker recipe's publication, cancellations and optional collateral or Blue funding. */
49
+ export declare function buildMidnightMakerPublication(action: MakerPublicationAction): Readonly<import("../../index.js").Transaction<import("../../index.js").MidnightCancelAndMakeAction>>;
50
+ /**
51
+ * @internal Checks stored publication shape and ABI bounds, not the authenticity of offer bytes.
52
+ * Every maker publication type shares this recipe, so the action type is not bound to the payload.
53
+ */
54
+ export declare function validateMidnightMakerPublicationPlanAction(action: Record<string, unknown>, path: string): void;
55
+ export {};
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareMidnightMakerPublication = prepareMidnightMakerPublication;
4
+ exports.buildMidnightMakerPublication = buildMidnightMakerPublication;
5
+ exports.validateMidnightMakerPublicationPlanAction = validateMidnightMakerPublicationPlanAction;
6
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
+ const viem_1 = require("viem");
8
+ const cancelAndMake_js_1 = require("../../actions/midnight/cancelAndMake.js");
9
+ const encode_js_1 = require("../../actions/midnight/encode.js");
10
+ const chainCheck_js_1 = require("../../actions/requirements/chainCheck.js");
11
+ const assertContractCode_js_1 = require("../../entities/requirements/assertContractCode.js");
12
+ const parseMidnightMaker_js_1 = require("../../helpers/parseMidnightMaker.js");
13
+ const validate_js_1 = require("../../helpers/validate.js");
14
+ const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
15
+ const error_js_1 = require("../../types/error.js");
16
+ const error_js_2 = require("../error.js");
17
+ const intent_js_1 = require("../intent.js");
18
+ const validation_js_1 = require("../validation.js");
19
+ const authorization_js_1 = require("./authorization.js");
20
+ const market_js_1 = require("./market.js");
21
+ const validation_js_2 = require("./validation.js");
22
+ const publicationKinds = {
23
+ midnightMakeBorrow: "borrow",
24
+ midnightMakeLend: "lend",
25
+ midnightMakeRepay: "repay",
26
+ midnightMakeWithdraw: "withdraw",
27
+ midnightSupplyCollateralMakeBorrow: "collateral-backed borrow",
28
+ midnightSupplyBlueMakeLend: "Blue-backed lend",
29
+ };
30
+ const ratifierRoles = {
31
+ priceV1: "priceRatifierV1",
32
+ rateV1: "rateRatifierV1",
33
+ };
34
+ /**
35
+ * @internal Resolves the plan intent and offer-capped deadline, then runs the operation's maker
36
+ * parse constructor with a chain check that also checks bundle, Midnight and ratifier code once,
37
+ * right before the first publication-state read, plus any operation-specific `codeRoles`. The
38
+ * constructor also rejects a deadline at or before the pinned block timestamp while every offer
39
+ * is live.
40
+ */
41
+ async function prepareMidnightMakerPublication(client, { params, parse, codeRoles = [], }) {
42
+ const { chainId, account } = params;
43
+ const now = params.now ?? morpho_ts_1.Time.timestamp();
44
+ (0, validate_js_1.validateReferenceTime)(now);
45
+ const intent = (0, intent_js_1.resolveIntent)({
46
+ account,
47
+ chainId,
48
+ expiresAt: params.expiresAt,
49
+ calldataOrigin: params.calldataOrigin,
50
+ }, now);
51
+ const tree = (0, parseMidnightMaker_js_1.parseMidnightMakerTree)({
52
+ offers: params.offers,
53
+ accountAddress: account,
54
+ });
55
+ // Conservative SDK cutoff: the core still fills an offer at its expiry second.
56
+ const offerDeadline = tree.offers.reduce((earliest, offer) => morpho_ts_1.MathLib.min(earliest, offer.expiry - 1n), intent.deadline);
57
+ // An offer expired at the reference time is reported by the pinned offer-state check, as in the entity.
58
+ const offerExpired = offerDeadline < now;
59
+ const deadline = offerExpired ? intent.deadline : offerDeadline;
60
+ if (params.expiresAt !== undefined && deadline < intent.deadline) {
61
+ throw new error_js_1.InputExceedsMaxError({
62
+ field: "expiresAt",
63
+ value: intent.deadline,
64
+ max: deadline,
65
+ });
66
+ }
67
+ const chainCheck = (0, chainCheck_js_1.createChainCheck)(client, chainId);
68
+ let preflightPassed = false;
69
+ const checkChainAndCode = async () => {
70
+ if (preflightPassed) {
71
+ return;
72
+ }
73
+ await chainCheck();
74
+ await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
75
+ "midnightBundlesV2",
76
+ "midnight",
77
+ ratifierRoles[tree.type],
78
+ ...codeRoles,
79
+ ].map((role) => ({ role, address: (0, morpho_ts_1.getChainAddress)(chainId, role) })), chainCheck);
80
+ preflightPassed = true;
81
+ };
82
+ const parsed = await parse({
83
+ accountAddress: account,
84
+ offers: tree,
85
+ cancellations: params.cancellations,
86
+ deadline,
87
+ now,
88
+ validation: params.validation,
89
+ }, {
90
+ client,
91
+ chainId,
92
+ chainCheck: checkChainAndCode,
93
+ // No plan can be returned for an expired offer, so stop once the pinned check passes.
94
+ ...(offerExpired && {
95
+ rejectAfterPinnedChecks: new error_js_1.ExpiredDeadlineError(offerDeadline, now),
96
+ }),
97
+ });
98
+ const { action, data } = parsed;
99
+ return {
100
+ parsed,
101
+ inputs: {
102
+ chainId,
103
+ account,
104
+ deadline: action.deadline,
105
+ cancellations: action.cancellations.map(({ group, maxConsumed }) => ({
106
+ group,
107
+ maxConsumed,
108
+ })),
109
+ root: data.tree.root,
110
+ ratifierType: data.ratifierType,
111
+ ratifier: data.ratifier,
112
+ groups: [...data.groups],
113
+ payload: data.payload,
114
+ },
115
+ calldataOrigin: intent.calldataOrigin,
116
+ };
117
+ }
118
+ function parseStoredMidnightMakerPublication({ type, inputs, }) {
119
+ const { chainId, account, deadline, ratifierType, ratifier, root, groups, payload, } = inputs;
120
+ (0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", account);
121
+ if (ratifierType !== "priceV1" && ratifierType !== "rateV1") {
122
+ throw new error_js_2.InvalidTransactionPlanError({
123
+ path: "inputs.ratifierType",
124
+ reason: "expected priceV1 or rateV1",
125
+ });
126
+ }
127
+ const registered = (0, morpho_ts_1.getChainAddress)(chainId, ratifierRoles[ratifierType]);
128
+ if (!(0, viem_1.isAddressEqual)(ratifier, registered)) {
129
+ throw new error_js_1.UnsupportedMidnightAuthorizationTargetError({
130
+ authorized: ratifier,
131
+ chainId,
132
+ supportedTargets: [registered],
133
+ });
134
+ }
135
+ const cancellations = inputs.cancellations.map(({ group, maxConsumed }) => ({
136
+ group,
137
+ maxConsumed,
138
+ }));
139
+ const publication = { ratifier, root, groups, payload };
140
+ if (type === "midnightSupplyCollateralMakeBorrow") {
141
+ const { collateral } = inputs;
142
+ if (collateral == null) {
143
+ throw missingFunding("collateral");
144
+ }
145
+ return (0, cancelAndMake_js_1.parseMidnightCancelAndMake)({
146
+ chainId,
147
+ deadline,
148
+ nativeAmount: inputs.nativeAssets,
149
+ cancellations,
150
+ publication: {
151
+ ...publication,
152
+ collateral: {
153
+ market: (0, market_js_1.storedMarketTuple)(collateral.market),
154
+ supplies: collateral.supplies.map(({ collateralIndex, assets }) => ({
155
+ collateralIndex,
156
+ assets,
157
+ })),
158
+ },
159
+ },
160
+ });
161
+ }
162
+ if (type === "midnightSupplyBlueMakeLend") {
163
+ const { blueSupply } = inputs;
164
+ if (blueSupply == null) {
165
+ throw missingFunding("blueSupply");
166
+ }
167
+ const { loanToken, collateralToken, oracle, irm, lltv } = blueSupply.market;
168
+ return (0, cancelAndMake_js_1.parseMidnightCancelAndMake)({
169
+ chainId,
170
+ deadline,
171
+ nativeAmount: inputs.nativeAssets,
172
+ cancellations,
173
+ publication: {
174
+ ...publication,
175
+ blueSupply: {
176
+ market: { loanToken, collateralToken, oracle, irm, lltv },
177
+ assets: blueSupply.assets,
178
+ callbackSalt: blueSupply.callbackSalt,
179
+ },
180
+ },
181
+ });
182
+ }
183
+ return (0, cancelAndMake_js_1.parseMidnightCancelAndMake)({
184
+ chainId,
185
+ deadline,
186
+ cancellations,
187
+ publication,
188
+ });
189
+ }
190
+ function missingFunding(field) {
191
+ return new error_js_2.InvalidTransactionPlanError({
192
+ path: `inputs.${field}`,
193
+ reason: "expected funding for the maker publication",
194
+ });
195
+ }
196
+ /** @internal Encodes a maker recipe's publication, cancellations and optional collateral or Blue funding. */
197
+ function buildMidnightMakerPublication(action) {
198
+ if (action.type === "midnightSupplyCollateralMakeBorrow" &&
199
+ action.inputs.collateral != null) {
200
+ (0, market_js_1.validateStoredCollateralOrder)(action.inputs.collateral.market.collateralParams, "$.inputs.collateral.market.collateralParams");
201
+ }
202
+ return (0, encode_js_1.encodeMidnightCancelAndMake)(parseStoredMidnightMakerPublication(action));
203
+ }
204
+ /**
205
+ * @internal Checks stored publication shape and ABI bounds, not the authenticity of offer bytes.
206
+ * Every maker publication type shares this recipe, so the action type is not bound to the payload.
207
+ */
208
+ function validateMidnightMakerPublicationPlanAction(action, path) {
209
+ (0, authorization_js_1.validateSignaturelessMidnightAction)(action, path);
210
+ const inputPath = `${path}.inputs`;
211
+ const inputs = (0, validation_js_1.getPlanObject)(action.inputs, inputPath);
212
+ (0, validation_js_1.validatePlanFields)(inputs, {
213
+ path: inputPath,
214
+ fields: {
215
+ ratifier: "address",
216
+ root: "bytes32",
217
+ groups: "array",
218
+ payload: "hex",
219
+ cancellations: "array",
220
+ deadline: "uint256 bigint",
221
+ },
222
+ });
223
+ if (inputs.ratifierType !== "priceV1" && inputs.ratifierType !== "rateV1") {
224
+ throw new error_js_2.InvalidTransactionPlanError({
225
+ path: `${inputPath}.ratifierType`,
226
+ reason: "expected priceV1 or rateV1",
227
+ });
228
+ }
229
+ for (const [index, group] of inputs.groups.entries()) {
230
+ (0, validation_js_1.validatePlanField)(group, {
231
+ path: `${inputPath}.groups[${index}]`,
232
+ type: "bytes32",
233
+ });
234
+ }
235
+ for (const [index, value] of inputs.cancellations.entries()) {
236
+ const cancellationPath = `${inputPath}.cancellations[${index}]`;
237
+ (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(value, cancellationPath), {
238
+ path: cancellationPath,
239
+ fields: { group: "bytes32", maxConsumed: "uint128 bigint" },
240
+ });
241
+ }
242
+ const publication = action;
243
+ // Validate only the persisted funding values that feed the parse constructor.
244
+ if (publication.type === "midnightSupplyCollateralMakeBorrow") {
245
+ validateStoredCollateralFunding(inputs, inputPath);
246
+ }
247
+ if (publication.type === "midnightSupplyBlueMakeLend") {
248
+ validateStoredBlueFunding(inputs, inputPath);
249
+ }
250
+ try {
251
+ // Reuse the action's clock-free parse checks; do not reconstruct the tree.
252
+ parseStoredMidnightMakerPublication(publication);
253
+ }
254
+ catch (cause) {
255
+ throw new error_js_2.InvalidTransactionPlanError({
256
+ path: inputPath,
257
+ reason: `expected a valid Midnight ${publicationKinds[publication.type]} publication`,
258
+ cause,
259
+ });
260
+ }
261
+ }
262
+ function validateStoredNativeAssets(inputs, inputPath) {
263
+ if (inputs.nativeAssets !== undefined) {
264
+ (0, validation_js_1.validatePlanField)(inputs.nativeAssets, {
265
+ path: `${inputPath}.nativeAssets`,
266
+ type: "uint256 bigint",
267
+ });
268
+ }
269
+ }
270
+ function validateStoredBlueFunding(inputs, inputPath) {
271
+ validateStoredNativeAssets(inputs, inputPath);
272
+ const path = `${inputPath}.blueSupply`;
273
+ const supply = (0, validation_js_1.getPlanObject)(inputs.blueSupply, path);
274
+ (0, validation_js_1.validatePlanFields)(supply, {
275
+ path,
276
+ fields: { assets: "uint128 bigint", callbackSalt: "bytes32" },
277
+ });
278
+ const marketPath = `${path}.market`;
279
+ (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(supply.market, marketPath), {
280
+ path: marketPath,
281
+ fields: {
282
+ loanToken: "address",
283
+ collateralToken: "address",
284
+ oracle: "address",
285
+ irm: "address",
286
+ lltv: "uint256 bigint",
287
+ },
288
+ });
289
+ }
290
+ function validateStoredCollateralFunding(inputs, inputPath) {
291
+ validateStoredNativeAssets(inputs, inputPath);
292
+ const path = `${inputPath}.collateral`;
293
+ const collateral = (0, validation_js_1.getPlanObject)(inputs.collateral, path);
294
+ const marketPath = `${path}.market`;
295
+ // Validate the market tuple before checking the order of its indexed tokens.
296
+ (0, validation_js_2.validateStoredMidnightMarket)(collateral.market, {
297
+ path: marketPath,
298
+ chainId: inputs.chainId,
299
+ });
300
+ const { market } = collateral;
301
+ (0, market_js_1.validateStoredCollateralOrder)(market.collateralParams, `${marketPath}.collateralParams`);
302
+ if (!Array.isArray(collateral.supplies)) {
303
+ throw new error_js_2.InvalidTransactionPlanError({
304
+ path: `${path}.supplies`,
305
+ reason: "expected an array",
306
+ });
307
+ }
308
+ for (const [index, supply] of collateral.supplies.entries()) {
309
+ const supplyPath = `${path}.supplies[${index}]`;
310
+ (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(supply, supplyPath), {
311
+ path: supplyPath,
312
+ fields: { collateralIndex: "uint256 bigint", assets: "uint128 bigint" },
313
+ });
314
+ }
315
+ }
@@ -0,0 +1,49 @@
1
+ import { type OfferStruct } from "@morpho-org/midnight-sdk";
2
+ import type { MidnightTakeableOffer } from "../../actions/midnight/types.js";
3
+ import type { MidnightCollateralTransfer } from "../../types/index.js";
4
+ /** @internal Projects a stored market and its collaterals onto the fields consumed by Midnight. */
5
+ export declare function storedMarketTuple({ chainId, midnight, loanToken, collateralParams, maturity, rcfThreshold, enterGate, liquidatorGate, }: OfferStruct["market"]): OfferStruct["market"];
6
+ /**
7
+ * @internal Rejects collateral that is not in strictly ascending token order. Midnight sorts the
8
+ * market's collateral, so a stored `collateralIndex` names the token it shows only in that order.
9
+ */
10
+ export declare function validateStoredCollateralOrder(collateralParams: OfferStruct["market"]["collateralParams"], path: string): void;
11
+ /** @internal Projects quote fills onto the fields consumed by Midnight. */
12
+ export declare function storedFills(takeableOffers: readonly MidnightTakeableOffer[]): {
13
+ units: bigint;
14
+ offer: {
15
+ market: import("@morpho-org/midnight-sdk").MarketParams;
16
+ buy: boolean;
17
+ maker: `0x${string}`;
18
+ start: bigint;
19
+ expiry: bigint;
20
+ tick: bigint;
21
+ group: `0x${string}`;
22
+ callback: `0x${string}`;
23
+ callbackData: `0x${string}`;
24
+ receiverIfMakerIsSeller: `0x${string}`;
25
+ ratifier: `0x${string}`;
26
+ reduceOnly: boolean;
27
+ maxUnits: bigint;
28
+ maxAssets: bigint;
29
+ continuousFeeCap: bigint;
30
+ };
31
+ ratifierData: `0x${string}`;
32
+ }[];
33
+ /**
34
+ * Rejects a supplied collateral price that is not a bigint before the health check converts it.
35
+ * Missing entries stay allowed: only the health check knows which prices it needs. @internal
36
+ */
37
+ export declare function validateCollateralPriceTypes(prices: readonly bigint[]): void;
38
+ /**
39
+ * @internal Rejects a collateral index that is not a bigint. Midnight's index lookup accepts a
40
+ * number, but a stored plan must hold a bigint to be restored.
41
+ */
42
+ export declare function validateCollateralIndexTypes(field: string, entries: readonly {
43
+ readonly collateralIndex: bigint;
44
+ }[]): void;
45
+ /**
46
+ * @internal Rejects collateral transfer inputs a parse constructor cannot read with a typed error:
47
+ * a list that is not an array, an entry that is not an object, or a non-bigint index or amount.
48
+ */
49
+ export declare function validateCollateralTransferInputs(field: string, entries: readonly MidnightCollateralTransfer[]): void;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.storedMarketTuple = storedMarketTuple;
4
+ exports.validateStoredCollateralOrder = validateStoredCollateralOrder;
5
+ exports.storedFills = storedFills;
6
+ exports.validateCollateralPriceTypes = validateCollateralPriceTypes;
7
+ exports.validateCollateralIndexTypes = validateCollateralIndexTypes;
8
+ exports.validateCollateralTransferInputs = validateCollateralTransferInputs;
9
+ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
10
+ const error_js_1 = require("../../types/error.js");
11
+ const error_js_2 = require("../error.js");
12
+ const validation_js_1 = require("../validation.js");
13
+ /** @internal Projects a stored market and its collaterals onto the fields consumed by Midnight. */
14
+ function storedMarketTuple({ chainId, midnight, loanToken, collateralParams, maturity, rcfThreshold, enterGate, liquidatorGate, }) {
15
+ return {
16
+ chainId,
17
+ midnight,
18
+ loanToken,
19
+ collateralParams: collateralParams.map(({ token, lltv, liquidationCursor, oracle }) => ({
20
+ token,
21
+ lltv,
22
+ liquidationCursor,
23
+ oracle,
24
+ })),
25
+ maturity,
26
+ rcfThreshold,
27
+ enterGate,
28
+ liquidatorGate,
29
+ };
30
+ }
31
+ /**
32
+ * @internal Rejects collateral that is not in strictly ascending token order. Midnight sorts the
33
+ * market's collateral, so a stored `collateralIndex` names the token it shows only in that order.
34
+ */
35
+ function validateStoredCollateralOrder(collateralParams, path) {
36
+ for (const [index, collateral] of collateralParams.entries()) {
37
+ const previous = collateralParams[index - 1];
38
+ if (previous &&
39
+ midnight_sdk_1.MarketUtils.compareCollateralTokens(previous, collateral) >= 0) {
40
+ throw new error_js_2.InvalidTransactionPlanError({
41
+ path,
42
+ reason: "expected collateral tokens in strictly ascending address order",
43
+ });
44
+ }
45
+ }
46
+ }
47
+ /** @internal Projects quote fills onto the fields consumed by Midnight. */
48
+ function storedFills(takeableOffers) {
49
+ return takeableOffers.map(({ units, offer, ratifierData }) => ({
50
+ units,
51
+ offer: {
52
+ market: storedMarketTuple(offer.market),
53
+ buy: offer.buy,
54
+ maker: offer.maker,
55
+ start: offer.start,
56
+ expiry: offer.expiry,
57
+ tick: offer.tick,
58
+ group: offer.group,
59
+ callback: offer.callback,
60
+ callbackData: offer.callbackData,
61
+ receiverIfMakerIsSeller: offer.receiverIfMakerIsSeller,
62
+ ratifier: offer.ratifier,
63
+ reduceOnly: offer.reduceOnly,
64
+ maxUnits: offer.maxUnits,
65
+ maxAssets: offer.maxAssets,
66
+ continuousFeeCap: offer.continuousFeeCap,
67
+ },
68
+ ratifierData,
69
+ }));
70
+ }
71
+ /**
72
+ * Rejects a supplied collateral price that is not a bigint before the health check converts it.
73
+ * Missing entries stay allowed: only the health check knows which prices it needs. @internal
74
+ */
75
+ function validateCollateralPriceTypes(prices) {
76
+ if (!Array.isArray(prices)) {
77
+ throw new error_js_2.InvalidTransactionPlanError({
78
+ path: "$.collateralPrices",
79
+ reason: "expected an array",
80
+ });
81
+ }
82
+ for (const [index, price] of prices.entries()) {
83
+ if (price !== undefined && typeof price !== "bigint") {
84
+ throw new error_js_1.InvalidBigIntInputError(`collateralPrices[${index}]`, price);
85
+ }
86
+ }
87
+ }
88
+ /**
89
+ * @internal Rejects a collateral index that is not a bigint. Midnight's index lookup accepts a
90
+ * number, but a stored plan must hold a bigint to be restored.
91
+ */
92
+ function validateCollateralIndexTypes(field, entries) {
93
+ for (const [index, { collateralIndex }] of entries.entries()) {
94
+ if (typeof collateralIndex !== "bigint") {
95
+ throw new error_js_1.InvalidBigIntInputError(`${field}[${index}].collateralIndex`, collateralIndex);
96
+ }
97
+ }
98
+ }
99
+ /**
100
+ * @internal Rejects collateral transfer inputs a parse constructor cannot read with a typed error:
101
+ * a list that is not an array, an entry that is not an object, or a non-bigint index or amount.
102
+ */
103
+ function validateCollateralTransferInputs(field, entries) {
104
+ if (!Array.isArray(entries)) {
105
+ throw new error_js_2.InvalidTransactionPlanError({
106
+ path: `$.${field}`,
107
+ reason: "expected an array",
108
+ });
109
+ }
110
+ for (const [index, entry] of entries.entries()) {
111
+ // Validation only; a hole or null entry would otherwise throw a native TypeError.
112
+ (0, validation_js_1.getPlanObject)(entry, `$.${field}[${index}]`);
113
+ }
114
+ validateCollateralIndexTypes(field, entries);
115
+ for (const [index, { assets }] of entries.entries()) {
116
+ if (typeof assets !== "bigint") {
117
+ throw new error_js_1.InvalidBigIntInputError(`${field}[${index}].assets`, assets);
118
+ }
119
+ }
120
+ }