@morpho-org/morpho-sdk 7.1.0-next.1 → 8.2.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 (193) hide show
  1. package/MIGRATION-v7-to-v8.md +290 -0
  2. package/README.md +11 -6
  3. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
  4. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
  5. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +17 -71
  6. package/lib/cjs/actions/midnight/cancelAndMake.js +41 -29
  7. package/lib/cjs/actions/midnight/redeem.d.ts +8 -1
  8. package/lib/cjs/actions/midnight/redeem.js +18 -1
  9. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
  10. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +24 -2
  11. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +1 -0
  12. package/lib/cjs/actions/midnight/supplyCollateral.js +3 -0
  13. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
  14. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +49 -14
  15. package/lib/cjs/actions/midnight/takeBorrow.d.ts +18 -5
  16. package/lib/cjs/actions/midnight/takeBorrow.js +44 -12
  17. package/lib/cjs/actions/midnight/takeLend.d.ts +10 -5
  18. package/lib/cjs/actions/midnight/takeLend.js +27 -9
  19. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
  20. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +51 -27
  21. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +14 -5
  22. package/lib/cjs/actions/midnight/takeWithdraw.js +40 -9
  23. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -6
  25. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
  26. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +17 -6
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
  31. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
  32. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
  33. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
  35. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
  37. package/lib/cjs/actions/requirements/validateClientChainId.d.ts +26 -0
  38. package/lib/cjs/actions/requirements/validateClientChainId.js +34 -0
  39. package/lib/cjs/blue/errors.d.ts +1 -1
  40. package/lib/cjs/blue/errors.js +3 -1
  41. package/lib/cjs/blue/types.d.ts +1 -1
  42. package/lib/cjs/blue/utils.d.ts +1 -1
  43. package/lib/cjs/blue/utils.js +5 -1
  44. package/lib/cjs/entities/blue/blue.d.ts +109 -27
  45. package/lib/cjs/entities/blue/blue.js +103 -28
  46. package/lib/cjs/entities/index.d.ts +1 -1
  47. package/lib/cjs/entities/midnight/deadline.d.ts +15 -0
  48. package/lib/cjs/entities/midnight/deadline.js +24 -0
  49. package/lib/cjs/entities/midnight/midnight.d.ts +427 -72
  50. package/lib/cjs/entities/midnight/midnight.js +864 -186
  51. package/lib/cjs/entities/midnight/publication.d.ts +134 -0
  52. package/lib/cjs/entities/midnight/publication.js +404 -0
  53. package/lib/cjs/entities/midnight/types.d.ts +26 -5
  54. package/lib/cjs/entities/requirements/assertContractCode.d.ts +49 -0
  55. package/lib/cjs/entities/requirements/assertContractCode.js +79 -0
  56. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
  57. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +45 -18
  58. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
  59. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +5 -2
  60. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
  61. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  62. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +63 -11
  63. package/lib/cjs/entities/vaultV1/vaultV1.js +52 -15
  64. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +54 -12
  65. package/lib/cjs/entities/vaultV2/vaultV2.js +52 -15
  66. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +12 -6
  67. package/lib/cjs/entities/vaultV2BlueReallocationData.js +42 -14
  68. package/lib/cjs/errors.d.ts +1 -1
  69. package/lib/cjs/errors.js +4 -2
  70. package/lib/cjs/helpers/constant.d.ts +5 -0
  71. package/lib/cjs/helpers/constant.js +6 -1
  72. package/lib/cjs/helpers/index.d.ts +1 -1
  73. package/lib/cjs/helpers/index.js +2 -1
  74. package/lib/cjs/helpers/validate.d.ts +163 -8
  75. package/lib/cjs/helpers/validate.js +179 -8
  76. package/lib/cjs/helpers/validateMidnightBounds.d.ts +47 -0
  77. package/lib/cjs/helpers/validateMidnightBounds.js +79 -0
  78. package/lib/cjs/helpers/validateMidnightPublication.d.ts +12 -0
  79. package/lib/cjs/helpers/validateMidnightPublication.js +144 -0
  80. package/lib/cjs/helpers/validateMidnightReceiver.d.ts +29 -0
  81. package/lib/cjs/helpers/validateMidnightReceiver.js +84 -0
  82. package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
  83. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +231 -0
  84. package/lib/cjs/index.d.ts +1 -0
  85. package/lib/cjs/index.js +3 -0
  86. package/lib/cjs/types/error.d.ts +197 -4
  87. package/lib/cjs/types/error.js +265 -5
  88. package/lib/cjs/types/index.d.ts +1 -0
  89. package/lib/cjs/types/index.js +1 -0
  90. package/lib/cjs/types/midnightCancelAndMake.d.ts +70 -0
  91. package/lib/cjs/types/midnightCancelAndMake.js +2 -0
  92. package/lib/cjs/types/midnightPublicationError.d.ts +332 -0
  93. package/lib/cjs/types/midnightPublicationError.js +376 -0
  94. package/lib/cjs/types/sharedLiquidity.d.ts +12 -7
  95. package/lib/cjs/types.d.ts +1 -1
  96. package/lib/cjs/utils.d.ts +2 -1
  97. package/lib/cjs/utils.js +8 -2
  98. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
  99. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
  100. package/lib/esm/actions/midnight/cancelAndMake.d.ts +17 -71
  101. package/lib/esm/actions/midnight/cancelAndMake.js +42 -30
  102. package/lib/esm/actions/midnight/redeem.d.ts +8 -1
  103. package/lib/esm/actions/midnight/redeem.js +18 -1
  104. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
  105. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +24 -2
  106. package/lib/esm/actions/midnight/supplyCollateral.d.ts +1 -0
  107. package/lib/esm/actions/midnight/supplyCollateral.js +3 -0
  108. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
  109. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +52 -17
  110. package/lib/esm/actions/midnight/takeBorrow.d.ts +18 -5
  111. package/lib/esm/actions/midnight/takeBorrow.js +47 -15
  112. package/lib/esm/actions/midnight/takeLend.d.ts +10 -5
  113. package/lib/esm/actions/midnight/takeLend.js +27 -9
  114. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
  115. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +52 -28
  116. package/lib/esm/actions/midnight/takeWithdraw.d.ts +14 -5
  117. package/lib/esm/actions/midnight/takeWithdraw.js +41 -10
  118. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
  119. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +13 -8
  120. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
  121. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
  122. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
  123. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +17 -6
  124. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
  125. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
  126. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
  127. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
  128. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
  129. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
  130. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
  131. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
  132. package/lib/esm/actions/requirements/validateClientChainId.d.ts +26 -0
  133. package/lib/esm/actions/requirements/validateClientChainId.js +30 -0
  134. package/lib/esm/blue/errors.d.ts +1 -1
  135. package/lib/esm/blue/errors.js +1 -1
  136. package/lib/esm/blue/types.d.ts +1 -1
  137. package/lib/esm/blue/utils.d.ts +1 -1
  138. package/lib/esm/blue/utils.js +1 -1
  139. package/lib/esm/entities/blue/blue.d.ts +109 -27
  140. package/lib/esm/entities/blue/blue.js +104 -29
  141. package/lib/esm/entities/index.d.ts +1 -1
  142. package/lib/esm/entities/midnight/deadline.d.ts +15 -0
  143. package/lib/esm/entities/midnight/deadline.js +20 -0
  144. package/lib/esm/entities/midnight/midnight.d.ts +427 -72
  145. package/lib/esm/entities/midnight/midnight.js +865 -187
  146. package/lib/esm/entities/midnight/publication.d.ts +134 -0
  147. package/lib/esm/entities/midnight/publication.js +397 -0
  148. package/lib/esm/entities/midnight/types.d.ts +26 -5
  149. package/lib/esm/entities/requirements/assertContractCode.d.ts +49 -0
  150. package/lib/esm/entities/requirements/assertContractCode.js +74 -0
  151. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
  152. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +47 -20
  153. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
  154. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +5 -2
  155. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
  156. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  157. package/lib/esm/entities/vaultV1/vaultV1.d.ts +63 -11
  158. package/lib/esm/entities/vaultV1/vaultV1.js +53 -16
  159. package/lib/esm/entities/vaultV2/vaultV2.d.ts +54 -12
  160. package/lib/esm/entities/vaultV2/vaultV2.js +53 -16
  161. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +12 -6
  162. package/lib/esm/entities/vaultV2BlueReallocationData.js +42 -14
  163. package/lib/esm/errors.d.ts +1 -1
  164. package/lib/esm/errors.js +1 -1
  165. package/lib/esm/helpers/constant.d.ts +5 -0
  166. package/lib/esm/helpers/constant.js +5 -0
  167. package/lib/esm/helpers/index.d.ts +1 -1
  168. package/lib/esm/helpers/index.js +1 -1
  169. package/lib/esm/helpers/validate.d.ts +163 -8
  170. package/lib/esm/helpers/validate.js +177 -7
  171. package/lib/esm/helpers/validateMidnightBounds.d.ts +47 -0
  172. package/lib/esm/helpers/validateMidnightBounds.js +72 -0
  173. package/lib/esm/helpers/validateMidnightPublication.d.ts +12 -0
  174. package/lib/esm/helpers/validateMidnightPublication.js +139 -0
  175. package/lib/esm/helpers/validateMidnightReceiver.d.ts +29 -0
  176. package/lib/esm/helpers/validateMidnightReceiver.js +80 -0
  177. package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
  178. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +226 -0
  179. package/lib/esm/index.d.ts +1 -0
  180. package/lib/esm/index.js +1 -0
  181. package/lib/esm/types/error.d.ts +197 -4
  182. package/lib/esm/types/error.js +253 -2
  183. package/lib/esm/types/index.d.ts +1 -0
  184. package/lib/esm/types/index.js +1 -0
  185. package/lib/esm/types/midnightCancelAndMake.d.ts +70 -0
  186. package/lib/esm/types/midnightCancelAndMake.js +1 -0
  187. package/lib/esm/types/midnightPublicationError.d.ts +332 -0
  188. package/lib/esm/types/midnightPublicationError.js +359 -0
  189. package/lib/esm/types/sharedLiquidity.d.ts +12 -7
  190. package/lib/esm/types.d.ts +1 -1
  191. package/lib/esm/utils.d.ts +2 -1
  192. package/lib/esm/utils.js +2 -1
  193. package/package.json +7 -6
@@ -0,0 +1,134 @@
1
+ import { Market, MarketParams, type Offer, type Tree } from "@morpho-org/midnight-sdk";
2
+ import { type Address, type Client } from "viem";
3
+ /** @internal */
4
+ export declare const offerMarketParams: (offer: Offer) => MarketParams;
5
+ /** Onchain state used to validate one Midnight maker offer before publication.
6
+ *
7
+ * `market` supplies the market id for errors, the maturity used for Rate V1 sell-overflow timing,
8
+ * and the market input to `RateRatifierV1.isPriceAcceptable`.
9
+ *
10
+ * @internal
11
+ * @example
12
+ * ```ts
13
+ * const state: MidnightMakerOfferState = {
14
+ * consumed: 0n,
15
+ * tickSpacing: 4,
16
+ * continuousFee: 0n,
17
+ * credit: 0n,
18
+ * debt: 0n,
19
+ * market,
20
+ * lltvEnabled: [],
21
+ * liquidationCursorEnabled: [],
22
+ * oracleHasCode: [],
23
+ * };
24
+ * console.log(state.tickSpacing);
25
+ * ```
26
+ */
27
+ export interface MidnightMakerOfferState {
28
+ /** Units or assets already consumed from the offer group. */
29
+ readonly consumed: bigint;
30
+ /** Onchain tick spacing; zero means the market is not created. */
31
+ readonly tickSpacing: number;
32
+ /** Current market continuous fee. */
33
+ readonly continuousFee: bigint;
34
+ /** Maker's credit in this market. */
35
+ readonly credit: bigint;
36
+ /** Maker's debt in this market. */
37
+ readonly debt: bigint;
38
+ /** Market snapshot used for error market ids and Rate V1 maturity validation. */
39
+ readonly market: Market;
40
+ /** LLTV enablement results for uncreated-market collateral parameters. */
41
+ readonly lltvEnabled: readonly boolean[];
42
+ /** Liquidation-cursor enablement results for uncreated-market collateral parameters. */
43
+ readonly liquidationCursorEnabled: readonly boolean[];
44
+ /** Oracle-code results for uncreated-market collateral parameters. */
45
+ readonly oracleHasCode: readonly boolean[];
46
+ }
47
+ /**
48
+ * Rejects the first maker offer that cannot be filled at or after publication.
49
+ *
50
+ * Checks expiry, market maturity, group capacity, tick spacing, continuous fee,
51
+ * zero-price sells, Rate V1 reachability, reduce-only position state, and
52
+ * uncreated-market constraints in protocol order. Partial group consumption
53
+ * remains valid; every offer in that group shares its remaining cap.
54
+ *
55
+ * @internal
56
+ * @param params.tree - Price V1 or Rate V1 maker tree.
57
+ * @param params.states - Pinned onchain state corresponding to each tree offer.
58
+ * @param params.now - Timestamp from the same block as the state reads.
59
+ * @param params.marketCreationTime - Latest market creation time for uncreated markets; defaults to each offer's expiry.
60
+ * @returns Nothing when every offer can be published.
61
+ * @throws {MidnightOfferExpiredError} when expiry is not later than `now`.
62
+ * @throws {MidnightOfferExpiryAfterMaturityError} when expiry exceeds market maturity.
63
+ * @throws {MidnightOfferGroupConsumedError} when the group's remaining cap is zero.
64
+ * @throws {MidnightOfferTickSpacingError} when the tick is inaccessible.
65
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds the offer cap.
66
+ * @throws {MidnightOfferZeroPriceSellError} when a sell offer has tick zero.
67
+ * @throws {MidnightOfferRateBoundUnreachableError} when a Rate V1 bound cannot become fillable.
68
+ * @throws {MidnightOfferNoDebtError} when a reduce-only buy has no maker debt.
69
+ * @throws {MidnightOfferNoCreditError} when a reduce-only sell has no maker credit.
70
+ * @throws {MidnightMarketMaturityTooFarError} when an uncreated market's maturity is more than 100 years after the selected creation time.
71
+ * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market's LLTV is disabled.
72
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market's cursor is disabled.
73
+ * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
74
+ * @example
75
+ * ```ts
76
+ * validateMidnightMakerOfferStates({ tree, states, now: block.timestamp });
77
+ * ```
78
+ */
79
+ export declare function validateMidnightMakerOfferStates(params: {
80
+ readonly tree: Tree<"priceV1"> | Tree<"rateV1">;
81
+ readonly states: readonly MidnightMakerOfferState[];
82
+ readonly now: bigint;
83
+ readonly marketCreationTime?: "expiry" | "now";
84
+ }): void;
85
+ /**
86
+ * Reads pinned Midnight state for each offer, deduplicating markets and groups.
87
+ *
88
+ * The reader uses a single block for contract reads and returns that block's
89
+ * timestamp as `now`; oracle code checks use the same block number.
90
+ *
91
+ * @internal
92
+ * @param params.client - Viem client used for state reads.
93
+ * @param params.chainId - Chain whose Midnight deployment is read.
94
+ * @param params.tree - Maker tree whose offer state is fetched.
95
+ * @param params.blockNumber - Optional block to pin the reads to.
96
+ * @returns Per-offer states plus the timestamp of the pinned block.
97
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
98
+ * another chain than `params.chainId`.
99
+ * @throws {viem.BaseError} when block, multicall, or oracle-code reads fail.
100
+ * @example
101
+ * ```ts
102
+ * const { states, now } = await fetchMidnightMakerOfferStates({
103
+ * client,
104
+ * chainId: 8453,
105
+ * tree,
106
+ * });
107
+ * ```
108
+ */
109
+ export declare function fetchMidnightMakerOfferStates(params: {
110
+ readonly client: Client;
111
+ readonly chainId: number;
112
+ readonly tree: Tree<"priceV1"> | Tree<"rateV1">;
113
+ readonly blockNumber?: bigint;
114
+ }): Promise<{
115
+ readonly states: readonly MidnightMakerOfferState[];
116
+ readonly now: bigint;
117
+ }>;
118
+ /**
119
+ * Rejects offers with callbacks that the selected maker flow cannot execute.
120
+ *
121
+ * `supplyBlueMakeLend` is excluded because it binds a Blue buy callback itself.
122
+ *
123
+ * @internal
124
+ * @param offers - Offers to validate.
125
+ * @returns Nothing when every callback is the zero address.
126
+ * @throws {MidnightOfferCallbackNotSupportedError} when an offer callback is nonzero.
127
+ * @example
128
+ * ```ts
129
+ * validateMidnightMakerOfferCallbacks(tree.offers);
130
+ * ```
131
+ */
132
+ export declare function validateMidnightMakerOfferCallbacks(offers: readonly {
133
+ readonly callback: Address;
134
+ }[]): void;
@@ -0,0 +1,397 @@
1
+ import { DEFAULT_TICK_SPACING, Market, MarketParams, MarketUtils, midnightAbi, RateRatifierV1, } from "@morpho-org/midnight-sdk";
2
+ import { getChainAddress, MathLib } from "@morpho-org/morpho-ts";
3
+ import { maxUint256, zeroAddress } from "viem";
4
+ import { getBlock, getBlockNumber, getCode, multicall } from "viem/actions";
5
+ import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
6
+ import { MidnightMarketLiquidationCursorNotEnabledError, MidnightMarketLltvNotEnabledError, MidnightMarketMaturityTooFarError, MidnightMarketOracleWithoutCodeError, MidnightOfferCallbackNotSupportedError, MidnightOfferContinuousFeeCapBelowMarketFeeError, MidnightOfferExpiredError, MidnightOfferExpiryAfterMaturityError, MidnightOfferGroupConsumedError, MidnightOfferNoCreditError, MidnightOfferNoDebtError, MidnightOfferRateBoundUnreachableError, MidnightOfferTickSpacingError, MidnightOfferZeroPriceSellError, } from "../../types/midnightPublicationError.js";
7
+ // Midnight.sol `touchMarket` rejects markets maturing more than 100 years after creation.
8
+ const MAX_TIME_TO_MATURITY = 100n * 365n * 86400n;
9
+ /** @internal */
10
+ export const offerMarketParams = (offer) => "params" in offer.market ? offer.market.params : offer.market;
11
+ /**
12
+ * Rejects the first maker offer that cannot be filled at or after publication.
13
+ *
14
+ * Checks expiry, market maturity, group capacity, tick spacing, continuous fee,
15
+ * zero-price sells, Rate V1 reachability, reduce-only position state, and
16
+ * uncreated-market constraints in protocol order. Partial group consumption
17
+ * remains valid; every offer in that group shares its remaining cap.
18
+ *
19
+ * @internal
20
+ * @param params.tree - Price V1 or Rate V1 maker tree.
21
+ * @param params.states - Pinned onchain state corresponding to each tree offer.
22
+ * @param params.now - Timestamp from the same block as the state reads.
23
+ * @param params.marketCreationTime - Latest market creation time for uncreated markets; defaults to each offer's expiry.
24
+ * @returns Nothing when every offer can be published.
25
+ * @throws {MidnightOfferExpiredError} when expiry is not later than `now`.
26
+ * @throws {MidnightOfferExpiryAfterMaturityError} when expiry exceeds market maturity.
27
+ * @throws {MidnightOfferGroupConsumedError} when the group's remaining cap is zero.
28
+ * @throws {MidnightOfferTickSpacingError} when the tick is inaccessible.
29
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds the offer cap.
30
+ * @throws {MidnightOfferZeroPriceSellError} when a sell offer has tick zero.
31
+ * @throws {MidnightOfferRateBoundUnreachableError} when a Rate V1 bound cannot become fillable.
32
+ * @throws {MidnightOfferNoDebtError} when a reduce-only buy has no maker debt.
33
+ * @throws {MidnightOfferNoCreditError} when a reduce-only sell has no maker credit.
34
+ * @throws {MidnightMarketMaturityTooFarError} when an uncreated market's maturity is more than 100 years after the selected creation time.
35
+ * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market's LLTV is disabled.
36
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market's cursor is disabled.
37
+ * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
38
+ * @example
39
+ * ```ts
40
+ * validateMidnightMakerOfferStates({ tree, states, now: block.timestamp });
41
+ * ```
42
+ */
43
+ export function validateMidnightMakerOfferStates(params) {
44
+ const rateEntries = params.tree.type === "rateV1" ? params.tree.entries : [];
45
+ params.tree.offers.forEach((offer, index) => {
46
+ const state = params.states[index];
47
+ const expiry = BigInt(offer.expiry);
48
+ const offerMarket = offerMarketParams(offer);
49
+ const maturity = BigInt(offerMarket.maturity);
50
+ const marketId = state.market.id;
51
+ if (expiry <= params.now) {
52
+ throw new MidnightOfferExpiredError({
53
+ index,
54
+ expiry,
55
+ now: params.now,
56
+ });
57
+ }
58
+ if (expiry > maturity) {
59
+ throw new MidnightOfferExpiryAfterMaturityError({
60
+ index,
61
+ expiry,
62
+ maturity,
63
+ });
64
+ }
65
+ const capacity = BigInt(offer.maxAssets) > 0n
66
+ ? BigInt(offer.maxAssets)
67
+ : BigInt(offer.maxUnits);
68
+ if (state.consumed >= capacity) {
69
+ throw new MidnightOfferGroupConsumedError({
70
+ index,
71
+ group: offer.group,
72
+ consumed: state.consumed,
73
+ });
74
+ }
75
+ const tickSpacing = state.tickSpacing || Number(DEFAULT_TICK_SPACING);
76
+ if (BigInt(offer.tick) % BigInt(tickSpacing) !== 0n) {
77
+ throw new MidnightOfferTickSpacingError({
78
+ index,
79
+ tick: BigInt(offer.tick),
80
+ tickSpacing,
81
+ });
82
+ }
83
+ if (BigInt(offer.continuousFeeCap) < state.continuousFee) {
84
+ throw new MidnightOfferContinuousFeeCapBelowMarketFeeError({
85
+ index,
86
+ marketId,
87
+ continuousFeeCap: BigInt(offer.continuousFeeCap),
88
+ continuousFee: state.continuousFee,
89
+ });
90
+ }
91
+ if (!offer.buy && BigInt(offer.tick) === 0n) {
92
+ throw new MidnightOfferZeroPriceSellError({ index });
93
+ }
94
+ if (params.tree.type === "rateV1") {
95
+ const rate = BigInt(rateEntries[index].rate);
96
+ let timestamp = offer.buy
97
+ ? expiry
98
+ : MathLib.max(params.now, BigInt(offer.start));
99
+ if (!offer.buy && rate > 0n) {
100
+ const maxTimeToMaturity = (maxUint256 - MathLib.WAD * MathLib.WAD - MathLib.WAD + 1n) / rate;
101
+ const marketMaturity = state.market.params.maturity;
102
+ timestamp = MathLib.max(timestamp, marketMaturity - maxTimeToMaturity);
103
+ if (timestamp > expiry || timestamp > marketMaturity) {
104
+ throw new MidnightOfferRateBoundUnreachableError({
105
+ index,
106
+ rate,
107
+ tick: BigInt(offer.tick),
108
+ });
109
+ }
110
+ }
111
+ if (!RateRatifierV1.isPriceAcceptable({
112
+ offer: { ...offer, market: state.market },
113
+ rate,
114
+ timestamp,
115
+ })) {
116
+ throw new MidnightOfferRateBoundUnreachableError({
117
+ index,
118
+ rate,
119
+ tick: BigInt(offer.tick),
120
+ });
121
+ }
122
+ }
123
+ if (offer.reduceOnly && offer.buy && state.debt === 0n) {
124
+ throw new MidnightOfferNoDebtError({ index, marketId });
125
+ }
126
+ if (offer.reduceOnly && !offer.buy && state.credit === 0n) {
127
+ throw new MidnightOfferNoCreditError({ index, marketId });
128
+ }
129
+ if (state.tickSpacing === 0) {
130
+ const marketCreationTimestamp = params.marketCreationTime === "now" ? params.now : expiry;
131
+ const maxMaturity = marketCreationTimestamp + MAX_TIME_TO_MATURITY;
132
+ if (maturity > maxMaturity) {
133
+ throw new MidnightMarketMaturityTooFarError({
134
+ index,
135
+ maturity,
136
+ maxMaturity,
137
+ });
138
+ }
139
+ for (const [collateralIndex, collateral,] of offerMarket.collateralParams.entries()) {
140
+ if (!state.lltvEnabled[collateralIndex]) {
141
+ throw new MidnightMarketLltvNotEnabledError({
142
+ index,
143
+ lltv: BigInt(collateral.lltv),
144
+ });
145
+ }
146
+ if (!state.liquidationCursorEnabled[collateralIndex]) {
147
+ throw new MidnightMarketLiquidationCursorNotEnabledError({
148
+ index,
149
+ liquidationCursor: BigInt(collateral.liquidationCursor),
150
+ });
151
+ }
152
+ if (!state.oracleHasCode[collateralIndex]) {
153
+ throw new MidnightMarketOracleWithoutCodeError({
154
+ index,
155
+ oracle: collateral.oracle,
156
+ });
157
+ }
158
+ }
159
+ }
160
+ });
161
+ }
162
+ /**
163
+ * Reads pinned Midnight state for each offer, deduplicating markets and groups.
164
+ *
165
+ * The reader uses a single block for contract reads and returns that block's
166
+ * timestamp as `now`; oracle code checks use the same block number.
167
+ *
168
+ * @internal
169
+ * @param params.client - Viem client used for state reads.
170
+ * @param params.chainId - Chain whose Midnight deployment is read.
171
+ * @param params.tree - Maker tree whose offer state is fetched.
172
+ * @param params.blockNumber - Optional block to pin the reads to.
173
+ * @returns Per-offer states plus the timestamp of the pinned block.
174
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
175
+ * another chain than `params.chainId`.
176
+ * @throws {viem.BaseError} when block, multicall, or oracle-code reads fail.
177
+ * @example
178
+ * ```ts
179
+ * const { states, now } = await fetchMidnightMakerOfferStates({
180
+ * client,
181
+ * chainId: 8453,
182
+ * tree,
183
+ * });
184
+ * ```
185
+ */
186
+ export async function fetchMidnightMakerOfferStates(params) {
187
+ await validateClientChainId(params.client, params.chainId);
188
+ const blockNumber = params.blockNumber ?? (await getBlockNumber(params.client));
189
+ const block = await getBlock(params.client, { blockNumber });
190
+ const midnight = getChainAddress(params.chainId, "midnight");
191
+ const markets = [
192
+ ...new Map(params.tree.offers.map((offer) => {
193
+ const market = MarketParams.from(offerMarketParams(offer));
194
+ const id = MarketUtils.toId(market);
195
+ return [id.toLowerCase(), { id, market }];
196
+ })).values(),
197
+ ];
198
+ const groups = [
199
+ ...new Map(params.tree.offers.map((offer) => [
200
+ `${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`,
201
+ { maker: offer.maker, group: offer.group },
202
+ ])).values(),
203
+ ];
204
+ const owners = [
205
+ ...new Map(params.tree.offers.map((offer) => {
206
+ const id = MarketUtils.toId(offer.market);
207
+ return [
208
+ `${id.toLowerCase()}:${offer.maker.toLowerCase()}`,
209
+ { id, maker: offer.maker },
210
+ ];
211
+ })).values(),
212
+ ];
213
+ const collaterals = markets.flatMap(({ id, market }) => market.collateralParams.map((collateral, index) => ({
214
+ key: `${id.toLowerCase()}:${index}`,
215
+ collateral,
216
+ oracleKey: collateral.oracle.toLowerCase(),
217
+ })));
218
+ const defaultFeeTokens = [
219
+ ...new Map(markets.map(({ market }) => [
220
+ market.loanToken.toLowerCase(),
221
+ market.loanToken,
222
+ ])).values(),
223
+ ];
224
+ const [marketStates, consumedValues, creditValues, debtValues, defaultFees, lltvEnabledByCollateral, liquidationCursorEnabledByCollateral,] = await Promise.all([
225
+ multicall(params.client, {
226
+ contracts: markets.map(({ id }) => ({
227
+ address: midnight,
228
+ abi: midnightAbi,
229
+ functionName: "marketState",
230
+ args: [id],
231
+ })),
232
+ allowFailure: false,
233
+ blockNumber,
234
+ }),
235
+ multicall(params.client, {
236
+ contracts: groups.map(({ maker, group }) => ({
237
+ address: midnight,
238
+ abi: midnightAbi,
239
+ functionName: "consumed",
240
+ args: [maker, group],
241
+ })),
242
+ allowFailure: false,
243
+ blockNumber,
244
+ }),
245
+ multicall(params.client, {
246
+ contracts: owners.map(({ id, maker }) => ({
247
+ address: midnight,
248
+ abi: midnightAbi,
249
+ functionName: "credit",
250
+ args: [id, maker],
251
+ })),
252
+ allowFailure: false,
253
+ blockNumber,
254
+ }),
255
+ multicall(params.client, {
256
+ contracts: owners.map(({ id, maker }) => ({
257
+ address: midnight,
258
+ abi: midnightAbi,
259
+ functionName: "debt",
260
+ args: [id, maker],
261
+ })),
262
+ allowFailure: false,
263
+ blockNumber,
264
+ }),
265
+ multicall(params.client, {
266
+ contracts: defaultFeeTokens.map((loanToken) => ({
267
+ address: midnight,
268
+ abi: midnightAbi,
269
+ functionName: "defaultContinuousFee",
270
+ args: [loanToken],
271
+ })),
272
+ allowFailure: false,
273
+ blockNumber,
274
+ }),
275
+ multicall(params.client, {
276
+ contracts: collaterals.map(({ collateral }) => ({
277
+ address: midnight,
278
+ abi: midnightAbi,
279
+ functionName: "isLltvEnabled",
280
+ args: [collateral.lltv],
281
+ })),
282
+ allowFailure: false,
283
+ blockNumber,
284
+ }),
285
+ multicall(params.client, {
286
+ contracts: collaterals.map(({ collateral }) => ({
287
+ address: midnight,
288
+ abi: midnightAbi,
289
+ functionName: "isLiquidationCursorEnabled",
290
+ args: [collateral.liquidationCursor],
291
+ })),
292
+ allowFailure: false,
293
+ blockNumber,
294
+ }),
295
+ ]);
296
+ const defaultFeeByLoanToken = new Map(defaultFeeTokens.map((loanToken, index) => [
297
+ loanToken.toLowerCase(),
298
+ defaultFees[index],
299
+ ]));
300
+ const marketById = new Map(markets.map(({ id, market: marketParams }, index) => {
301
+ const [totalUnits, lossFactor, withdrawable, continuousFeeCredit, fee0, fee1, fee2, fee3, fee4, fee5, fee6, continuousFee, tickSpacing,] = marketStates[index];
302
+ const effectiveContinuousFee = tickSpacing === 0
303
+ ? defaultFeeByLoanToken.get(marketParams.loanToken.toLowerCase())
304
+ : continuousFee;
305
+ return [
306
+ id.toLowerCase(),
307
+ new Market({
308
+ params: marketParams,
309
+ totalUnits,
310
+ lossFactor,
311
+ withdrawable,
312
+ continuousFeeCredit,
313
+ settlementFeeCbps: [fee0, fee1, fee2, fee3, fee4, fee5, fee6],
314
+ continuousFee: effectiveContinuousFee,
315
+ tickSpacing,
316
+ }),
317
+ ];
318
+ }));
319
+ const consumedByGroup = new Map(groups.map(({ maker, group }, index) => [
320
+ `${maker.toLowerCase()}:${group.toLowerCase()}`,
321
+ consumedValues[index],
322
+ ]));
323
+ const positionByOwner = new Map(owners.map(({ id, maker }, index) => [
324
+ `${id.toLowerCase()}:${maker.toLowerCase()}`,
325
+ {
326
+ credit: creditValues[index],
327
+ debt: debtValues[index],
328
+ },
329
+ ]));
330
+ const collateralStateByKey = new Map(collaterals.map(({ key }, index) => [
331
+ key,
332
+ {
333
+ lltvEnabled: lltvEnabledByCollateral[index],
334
+ liquidationCursorEnabled: liquidationCursorEnabledByCollateral[index],
335
+ },
336
+ ]));
337
+ const collateralStateByMarket = new Map(markets.map(({ id, market }) => [
338
+ id.toLowerCase(),
339
+ market.collateralParams.map((_, index) => collateralStateByKey.get(`${id.toLowerCase()}:${index}`)),
340
+ ]));
341
+ const codeByOracle = new Map(await Promise.all([...new Set(collaterals.map(({ oracleKey }) => oracleKey))].map(async (oracleKey) => [
342
+ oracleKey,
343
+ await getCode(params.client, {
344
+ address: collaterals.find(({ oracleKey: key }) => key === oracleKey).collateral.oracle,
345
+ blockNumber,
346
+ }),
347
+ ])));
348
+ const states = params.tree.offers.map((offer) => {
349
+ const id = MarketUtils.toId(offer.market);
350
+ const market = marketById.get(id.toLowerCase());
351
+ const groupKey = `${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`;
352
+ const owner = positionByOwner.get(`${id.toLowerCase()}:${offer.maker.toLowerCase()}`);
353
+ const uncreated = market.tickSpacing === 0;
354
+ const collateralStates = uncreated
355
+ ? collateralStateByMarket.get(id.toLowerCase())
356
+ : [];
357
+ return {
358
+ consumed: consumedByGroup.get(groupKey),
359
+ tickSpacing: market.tickSpacing,
360
+ continuousFee: BigInt(market.continuousFee),
361
+ credit: owner.credit,
362
+ debt: owner.debt,
363
+ market,
364
+ lltvEnabled: collateralStates.map(({ lltvEnabled }) => lltvEnabled),
365
+ liquidationCursorEnabled: collateralStates.map(({ liquidationCursorEnabled }) => liquidationCursorEnabled),
366
+ oracleHasCode: uncreated
367
+ ? offerMarketParams(offer).collateralParams.map((collateral) => codeByOracle.get(collateral.oracle.toLowerCase()) !== undefined &&
368
+ codeByOracle.get(collateral.oracle.toLowerCase()) !== "0x")
369
+ : [],
370
+ };
371
+ });
372
+ return { states, now: block.timestamp };
373
+ }
374
+ /**
375
+ * Rejects offers with callbacks that the selected maker flow cannot execute.
376
+ *
377
+ * `supplyBlueMakeLend` is excluded because it binds a Blue buy callback itself.
378
+ *
379
+ * @internal
380
+ * @param offers - Offers to validate.
381
+ * @returns Nothing when every callback is the zero address.
382
+ * @throws {MidnightOfferCallbackNotSupportedError} when an offer callback is nonzero.
383
+ * @example
384
+ * ```ts
385
+ * validateMidnightMakerOfferCallbacks(tree.offers);
386
+ * ```
387
+ */
388
+ export function validateMidnightMakerOfferCallbacks(offers) {
389
+ offers.forEach((offer, index) => {
390
+ if (offer.callback !== zeroAddress) {
391
+ throw new MidnightOfferCallbackNotSupportedError({
392
+ index,
393
+ callback: offer.callback,
394
+ });
395
+ }
396
+ });
397
+ }
@@ -15,7 +15,12 @@ export type MidnightMakerTreeInput = PriceRatifierV1TreeCreateRequest | RateRati
15
15
  export interface GetOffersDataParams {
16
16
  readonly accountAddress: Address;
17
17
  readonly offers: MidnightMakerTreeInput;
18
- readonly validation?: OfferValidationParams;
18
+ /**
19
+ * Midnight mempool API request controls; omit or pass an object to validate the tree against the
20
+ * API; pass `false` to skip the API call (no HTTP request), e.g. for P2P offers on markets the
21
+ * router does not admit or on chains without a Midnight router. Local maker checks still run.
22
+ */
23
+ readonly validation?: OfferValidationParams | false;
19
24
  }
20
25
  /** Prepared Midnight maker-offer data with the payload derived from its tree. */
21
26
  export interface OffersData {
@@ -36,7 +41,12 @@ export interface MakeOffersParams {
36
41
  readonly cancellations?: readonly MidnightGroupCancellation[];
37
42
  /** Bundle execution deadline timestamp. Pass `maxUint256` explicitly for no expiry. */
38
43
  readonly deadline: bigint;
39
- readonly validation?: OfferValidationParams;
44
+ /**
45
+ * Midnight mempool API request controls; omit or pass an object to validate the tree against the
46
+ * API; pass `false` to skip the API call (no HTTP request), e.g. for P2P offers on markets the
47
+ * router does not admit or on chains without a Midnight router. Local maker checks still run.
48
+ */
49
+ readonly validation?: OfferValidationParams | false;
40
50
  }
41
51
  /** Parameters for a Midnight lend maker flow. */
42
52
  export interface MakeLendParams extends MakeOffersParams {
@@ -140,6 +150,17 @@ export interface MarketActionParams {
140
150
  readonly accountAddress: Address;
141
151
  readonly marketData: Market;
142
152
  }
153
+ /** Caller-supplied position snapshot and collateral prices for Midnight health checks. */
154
+ export interface MidnightPositionHealthParams {
155
+ /** Owner-bound snapshot returned by `getPositionData`. */
156
+ readonly positionData: AccrualPosition;
157
+ /** Values from `price()` on each `marketData.params.collateralParams[i].oracle`,
158
+ * indexed like `positionData.collateral` and scaled by `ORACLE_PRICE_SCALE`. An empty array is
159
+ * safe only when the SDK's conservative post-operation debt is zero, such as after a `full` repay,
160
+ * a repayment units target covering `positionData.debt`, or `minUnits`/`repay.assets` covering it.
161
+ */
162
+ readonly collateralPrices: readonly bigint[];
163
+ }
143
164
  /** Parameters for the Midnight take-lend taker flow. */
144
165
  export interface TakeLendParams extends MarketActionParams, MidnightReferralFeeParams {
145
166
  /** Loan assets paid with a unit floor, or units bought with a loan-asset cap. */
@@ -156,7 +177,7 @@ export interface TakeLendParams extends MarketActionParams, MidnightReferralFeeP
156
177
  readonly deadline: bigint;
157
178
  }
158
179
  /** Parameters for the Midnight take-borrow taker flow. */
159
- export interface TakeBorrowParams extends MarketActionParams, MidnightReferralFeeParams {
180
+ export interface TakeBorrowParams extends MarketActionParams, MidnightPositionHealthParams, MidnightReferralFeeParams {
160
181
  /** Loan assets received with a unit cap, or units sold with a loan-asset floor. */
161
182
  readonly target: MidnightSellTarget;
162
183
  /** Recipient of the borrowed loan assets. Defaults to `accountAddress`. */
@@ -186,7 +207,7 @@ export interface SupplyCollateralTakeBorrowParams extends TakeBorrowParams {
186
207
  readonly nativeAmount?: bigint;
187
208
  }
188
209
  /** Parameters for the Midnight offer-based repay-and-withdraw-collateral taker flow. */
189
- export interface TakeRepayWithdrawCollateralParams extends MarketActionParams, MidnightReferralFeeParams {
210
+ export interface TakeRepayWithdrawCollateralParams extends MarketActionParams, MidnightPositionHealthParams, MidnightReferralFeeParams {
190
211
  /** Loan assets paid with a unit floor, or debt units repaid with a loan-asset cap. `units: maxUint256` targets the whole debt; `assets` and `maxBuyerAssets` bound the loan assets pulled and must be below `maxUint256`. */
191
212
  readonly target: MidnightBuyTarget;
192
213
  /** Optional native ETH sent as `value`; the bundle wraps it into the chain's wNative and transfers
@@ -222,7 +243,7 @@ export interface RedeemParams {
222
243
  readonly units?: bigint;
223
244
  }
224
245
  /** Parameters for the Midnight repay-and-withdraw-collateral flow. */
225
- export interface RepayWithdrawCollateralParams extends MarketActionParams {
246
+ export interface RepayWithdrawCollateralParams extends MarketActionParams, MidnightPositionHealthParams {
226
247
  /** `{ type: "assets", assets }` repays exactly `assets` (`0n` only withdraws); `{ type: "full", maxBuyerAssets }` repays the whole debt at execution with a finite asset cap. */
227
248
  readonly repay: MidnightRepay;
228
249
  /** Optional native ETH sent as `value`; the bundle wraps it into the chain's wNative and transfers
@@ -0,0 +1,49 @@
1
+ import type { AddressLabel } from "@morpho-org/morpho-ts";
2
+ import type { Address, Client } from "viem";
3
+ /**
4
+ * Asserts that a configured contract address holds deployed code on the client's chain.
5
+ *
6
+ * A call to a code-less address succeeds on-chain as a no-op, so entity flows check each
7
+ * registered target before returning requirements. The `eth_getCode` read runs at the
8
+ * client's default block; transport failures propagate unwrapped because they are
9
+ * infrastructure failures, not configuration failures.
10
+ *
11
+ * @param client - Connected viem client used for the `eth_getCode` read.
12
+ * @param params - Assertion parameters.
13
+ * @param params.address - Contract address expected to hold code.
14
+ * @param params.chainId - Chain id the flow targets, reported on the error.
15
+ * @param params.role - Registry label naming the address's role in the flow.
16
+ * @returns Nothing when the address holds code.
17
+ * @throws {MissingContractCodeError} when the address has no deployed bytecode.
18
+ * @throws {viem.BaseError} when the `eth_getCode` read itself fails.
19
+ * @internal
20
+ */
21
+ export declare const assertContractCode: (client: Client, params: {
22
+ readonly address: Address;
23
+ readonly chainId: number;
24
+ readonly role: AddressLabel;
25
+ }) => Promise<void>;
26
+ /**
27
+ * Asserts that each distinct target in a flow's write-surface list holds code.
28
+ *
29
+ * One `eth_getCode` per distinct address runs before any other requirement read.
30
+ * A wrong-chain RPC reports no code at every target, so on the first
31
+ * {@link MissingContractCodeError} a single `eth_chainId` probe decides: a served
32
+ * chain mismatch surfaces as {@link ChainIdMismatchError} (never as missing
33
+ * code), a failed probe keeps the original missing-code error, and a matching
34
+ * chain rethrows it unchanged. Other assertion errors propagate unwrapped.
35
+ *
36
+ * @param client - Connected viem client used for the `eth_getCode` reads.
37
+ * @param chainId - Chain id the flow targets, reported on the errors.
38
+ * @param targets - Distinct-by-address targets to check, in reporting order.
39
+ * @returns Nothing when every target holds code.
40
+ * @throws {MissingContractCodeError} when a target has no deployed bytecode on
41
+ * the endpoint's chain.
42
+ * @throws {ChainIdMismatchError} when the endpoint serves another chain id.
43
+ * @throws {viem.BaseError} when an `eth_getCode` read itself fails.
44
+ * @internal
45
+ */
46
+ export declare const assertRegistryTargetsHaveCode: (client: Client, chainId: number, targets: readonly {
47
+ readonly role: AddressLabel;
48
+ readonly address: Address;
49
+ }[]) => Promise<void>;