@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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.MetaMorphoAction = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getAuthorizationTypedData = exports.decodeBytes32String = exports.VaultV2Utils = exports.VaultV2MidnightAdapterUtils = exports.VaultV2BluePublicAllocatorConfigUtils = exports.VaultV2BlueMarketPublicAllocatorConfigUtils = exports.VaultUtils = exports.SharesMath = exports.MathLib = exports.MarketUtils = exports.getDefaultPreLiquidationParams = exports.defaultPreLiquidationParamsRegistry = exports.CapacityLimitReason = exports.AdaptiveCurveIrmLib = void 0;
3
+ exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.MetaMorphoAction = exports.isUndecodableResultError = exports.isTransportError = exports.isContractRevertError = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getAuthorizationTypedData = exports.decodeBytes32String = exports.catchRevertOnly = exports.VaultV2Utils = exports.VaultV2MidnightAdapterUtils = exports.VaultV2BluePublicAllocatorConfigUtils = exports.VaultV2BlueMarketPublicAllocatorConfigUtils = exports.VaultUtils = exports.SharesMath = exports.MathLib = exports.MarketUtils = exports.getDefaultPreLiquidationParams = exports.defaultPreLiquidationParamsRegistry = exports.CapacityLimitReason = exports.AdaptiveCurveIrmLib = void 0;
4
4
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  Object.defineProperty(exports, "AdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
6
6
  Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
@@ -17,11 +17,15 @@ Object.defineProperty(exports, "VaultV2BluePublicAllocatorConfigUtils", { enumer
17
17
  Object.defineProperty(exports, "VaultV2MidnightAdapterUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MidnightAdapterUtils; } });
18
18
  Object.defineProperty(exports, "VaultV2Utils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Utils; } });
19
19
  var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
20
+ Object.defineProperty(exports, "catchRevertOnly", { enumerable: true, get: function () { return blue_sdk_viem_1.catchRevertOnly; } });
20
21
  Object.defineProperty(exports, "decodeBytes32String", { enumerable: true, get: function () { return blue_sdk_viem_1.decodeBytes32String; } });
21
22
  Object.defineProperty(exports, "getAuthorizationTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getAuthorizationTypedData; } });
22
23
  Object.defineProperty(exports, "getPermit2PermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermit2PermitTypedData; } });
23
24
  Object.defineProperty(exports, "getPermit2TransferFromTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermit2TransferFromTypedData; } });
24
25
  Object.defineProperty(exports, "getPermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermitTypedData; } });
26
+ Object.defineProperty(exports, "isContractRevertError", { enumerable: true, get: function () { return blue_sdk_viem_1.isContractRevertError; } });
27
+ Object.defineProperty(exports, "isTransportError", { enumerable: true, get: function () { return blue_sdk_viem_1.isTransportError; } });
28
+ Object.defineProperty(exports, "isUndecodableResultError", { enumerable: true, get: function () { return blue_sdk_viem_1.isUndecodableResultError; } });
25
29
  Object.defineProperty(exports, "MetaMorphoAction", { enumerable: true, get: function () { return blue_sdk_viem_1.MetaMorphoAction; } });
26
30
  Object.defineProperty(exports, "optionalBoolean", { enumerable: true, get: function () { return blue_sdk_viem_1.optionalBoolean; } });
27
31
  Object.defineProperty(exports, "readContractRestructured", { enumerable: true, get: function () { return blue_sdk_viem_1.readContractRestructured; } });
@@ -31,7 +31,8 @@ export interface BlueActions {
31
31
  *
32
32
  * @param parameters - Optional fetch parameters (block number, state overrides).
33
33
  * @returns Market state including total supply/borrow assets and shares.
34
- * @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
34
+ * @throws {ChainIdMismatchError} when the connected client declares another chain or none, or its RPC reports another chain via `eth_chainId`.
35
+ * @throws {viem.BaseError} when the `eth_chainId` request or a state read fails.
35
36
  * @example
36
37
  * ```ts
37
38
  * import { markets } from "@morpho-org/morpho-test";
@@ -52,7 +53,8 @@ export interface BlueActions {
52
53
  * @param userAddress - The user whose position to fetch.
53
54
  * @param parameters - Optional fetch parameters (block number, state overrides).
54
55
  * @returns Accrual position with health metrics (maxBorrowAssets, ltv, isHealthy).
55
- * @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
56
+ * @throws {ChainIdMismatchError} when the connected client declares another chain or none, or its RPC reports another chain via `eth_chainId`.
57
+ * @throws {viem.BaseError} when the `eth_chainId` request or a state read fails.
56
58
  * @example
57
59
  * ```ts
58
60
  * import { markets } from "@morpho-org/morpho-test";
@@ -81,7 +83,8 @@ export interface BlueActions {
81
83
  * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
82
84
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
83
85
  * @returns Lazy token prerequisite resolution and a synchronous deep-frozen transaction.
84
- * @throws {ChainIdMismatchError} when the client targets another chain.
86
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
87
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
85
88
  * @throws {ExpiredDeadlineError} when the deadline is stale.
86
89
  * @throws {NonPositiveInputError} when `collateralAssets` is not positive.
87
90
  * @throws {NegativeInputError} when collateral, native funding, or the referral fee is negative.
@@ -101,7 +104,14 @@ export interface BlueActions {
101
104
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
102
105
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
103
106
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
104
- * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
107
+ * @throws {UnknownTokenError} from `getRequirements()` when the funded token's `decimals()` is unusable.
108
+ * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
109
+ * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
110
+ * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
111
+ * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
112
+ * contract has no code at its registered address.
113
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata
114
+ * read or `eth_chainId` request fails.
105
115
  * @example
106
116
  * ```ts
107
117
  * import { markets } from "@morpho-org/morpho-test";
@@ -132,9 +142,11 @@ export interface BlueActions {
132
142
  /**
133
143
  * Prepares a direct BlueBundlesV1 loan-asset supply.
134
144
  *
135
- * `getRequirements()` reads only the loan-token allowance and selected ERC-2612 or Permit2
136
- * nonce state. Direct approvals and ERC-2612 name BlueBundlesV1 as spender; Permit2 keeps its
137
- * ERC-20 approval on canonical Permit2. Native funding is exclusive and skips token requirements.
145
+ * `getRequirements()` first checks that BlueBundlesV1, Blue and, for ERC-20 funding with
146
+ * signatures enabled, Permit2 hold code at their registered addresses, then reads the loan-token
147
+ * allowance and selected ERC-2612 or Permit2 nonce state. Direct approvals and ERC-2612 name
148
+ * BlueBundlesV1 as spender; Permit2 keeps its ERC-20 approval on canonical Permit2. Native
149
+ * funding is exclusive and skips token requirements (the code check still runs).
138
150
  * The referral fee is deducted from the gross `assets` supplied. This route exposes no
139
151
  * share-price bound or `slippageTolerance`.
140
152
  *
@@ -145,7 +157,8 @@ export interface BlueActions {
145
157
  * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
146
158
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
147
159
  * @returns Lazy prerequisite resolution and a synchronous deep-frozen transaction builder.
148
- * @throws {ChainIdMismatchError} when the client targets another chain.
160
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
161
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
149
162
  * @throws {ExpiredDeadlineError} when the deadline is not in the future at creation or requirement resolution.
150
163
  * @throws {NonPositiveInputError} when `assets` is not positive.
151
164
  * @throws {NegativeInputError} when native funding or the referral fee is negative, or from `getRequirements()` when an explicit `permit2Nonce` is negative.
@@ -166,7 +179,14 @@ export interface BlueActions {
166
179
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
167
180
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
168
181
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
169
- * @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, or token metadata read fails.
182
+ * @throws {UnknownTokenError} from `getRequirements()` when the funded token's `decimals()` is unusable.
183
+ * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
184
+ * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
185
+ * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
186
+ * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
187
+ * contract has no code at its registered address.
188
+ * @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, or token
189
+ * metadata read or `eth_chainId` request fails.
170
190
  * @example
171
191
  * ```ts
172
192
  * import { markets } from "@morpho-org/morpho-test";
@@ -213,7 +233,8 @@ export interface BlueActions {
213
233
  * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
214
234
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
215
235
  * @returns Lazy authorization resolution and a synchronous deep-frozen transaction builder.
216
- * @throws {ChainIdMismatchError} when the client targets another chain.
236
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
237
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
217
238
  * @throws {ExpiredDeadlineError} when the deadline is stale.
218
239
  * @throws {MissingAccrualPositionError} when no position snapshot is provided at runtime.
219
240
  * @throws {MarketIdMismatchError} when `positionData` belongs to another market.
@@ -237,7 +258,10 @@ export interface BlueActions {
237
258
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
238
259
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
239
260
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
240
- * @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
261
+ * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
262
+ * contract has no code at its registered address.
263
+ * @throws {viem.BaseError} from `getRequirements()` when an authorization read or
264
+ * `eth_chainId` request fails.
241
265
  * @example
242
266
  * ```ts
243
267
  * import { AccrualPosition } from "@morpho-org/blue-sdk";
@@ -288,7 +312,8 @@ export interface BlueActions {
288
312
  * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
289
313
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
290
314
  * @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction.
291
- * @throws {ChainIdMismatchError} when the client targets another chain.
315
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
316
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
292
317
  * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
293
318
  * @throws {ExpiredDeadlineError} when the deadline is stale.
294
319
  * @throws {MissingAccrualPositionError} when no position snapshot is provided.
@@ -312,7 +337,10 @@ export interface BlueActions {
312
337
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
313
338
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
314
339
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
315
- * @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
340
+ * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
341
+ * contract has no code at its registered address.
342
+ * @throws {viem.BaseError} from `getRequirements()` when an authorization read or
343
+ * `eth_chainId` request fails.
316
344
  * @example
317
345
  * ```ts
318
346
  * import { AccrualPosition } from "@morpho-org/blue-sdk";
@@ -364,7 +392,8 @@ export interface BlueActions {
364
392
  * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
365
393
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
366
394
  * @returns Lazy token prerequisite resolution and a synchronous deep-frozen transaction.
367
- * @throws {ChainIdMismatchError} when the client targets another chain.
395
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
396
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
368
397
  * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
369
398
  * @throws {ExpiredDeadlineError} when the deadline is stale.
370
399
  * @throws {MissingAccrualPositionError} when no position snapshot is provided.
@@ -394,7 +423,14 @@ export interface BlueActions {
394
423
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
395
424
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
396
425
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
397
- * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
426
+ * @throws {UnknownTokenError} from `getRequirements()` when the funded token's `decimals()` is unusable.
427
+ * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
428
+ * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
429
+ * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
430
+ * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
431
+ * contract has no code at its registered address.
432
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, token metadata,
433
+ * or `eth_chainId` read fails.
398
434
  * @example
399
435
  * ```ts
400
436
  * import { AccrualPosition } from "@morpho-org/blue-sdk";
@@ -449,7 +485,8 @@ export interface BlueActions {
449
485
  * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
450
486
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
451
487
  * @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction.
452
- * @throws {ChainIdMismatchError} when the client targets another chain.
488
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
489
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
453
490
  * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
454
491
  * @throws {ExpiredDeadlineError} when the deadline is stale.
455
492
  * @throws {MissingAccrualPositionError} when no position snapshot is provided.
@@ -468,7 +505,10 @@ export interface BlueActions {
468
505
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
469
506
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
470
507
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
471
- * @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
508
+ * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
509
+ * contract has no code at its registered address.
510
+ * @throws {viem.BaseError} from `getRequirements()` when an authorization read or
511
+ * `eth_chainId` request fails.
472
512
  * @example
473
513
  * ```ts
474
514
  * import { AccrualPosition } from "@morpho-org/blue-sdk";
@@ -526,7 +566,8 @@ export interface BlueActions {
526
566
  * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
527
567
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
528
568
  * @returns Lazy funding/authorization resolution and a synchronous deep-frozen transaction builder.
529
- * @throws {ChainIdMismatchError} when the client targets another chain.
569
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
570
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
530
571
  * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
531
572
  * @throws {MissingAccrualPositionError} when no position snapshot is provided at runtime.
532
573
  * @throws {MarketIdMismatchError} when `positionData` belongs to another market.
@@ -559,7 +600,14 @@ export interface BlueActions {
559
600
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
560
601
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
561
602
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
562
- * @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, token metadata, or authorization read fails.
603
+ * @throws {UnknownTokenError} from `getRequirements()` when the funded token's `decimals()` is unusable.
604
+ * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
605
+ * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
606
+ * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
607
+ * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
608
+ * contract has no code at its registered address.
609
+ * @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, token
610
+ * metadata, authorization, or `eth_chainId` read fails.
563
611
  * @example
564
612
  * ```ts
565
613
  * import { AccrualPosition } from "@morpho-org/blue-sdk";
@@ -625,7 +673,8 @@ export interface BlueActions {
625
673
  * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
626
674
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
627
675
  * @returns Lazy funding/authorization resolution and a synchronous deep-frozen transaction builder.
628
- * @throws {ChainIdMismatchError} when the client targets another chain.
676
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
677
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
629
678
  * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
630
679
  * @throws {MissingAccrualPositionError} when a borrow has no position snapshot.
631
680
  * @throws {MarketIdMismatchError} when `positionData` belongs to another market.
@@ -658,7 +707,14 @@ export interface BlueActions {
658
707
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
659
708
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
660
709
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
661
- * @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, token metadata, or authorization read fails.
710
+ * @throws {UnknownTokenError} from `getRequirements()` when the funded token's `decimals()` is unusable.
711
+ * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
712
+ * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
713
+ * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
714
+ * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
715
+ * contract has no code at its registered address.
716
+ * @throws {viem.BaseError} from `getRequirements()` when a required allowance, nonce, token
717
+ * metadata, authorization, or `eth_chainId` read fails.
662
718
  * @example
663
719
  * ```ts
664
720
  * import { markets } from "@morpho-org/morpho-test";
@@ -714,7 +770,8 @@ export interface BlueActions {
714
770
  * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
715
771
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
716
772
  * @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction builder.
717
- * @throws {ChainIdMismatchError} when the client targets another chain.
773
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
774
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
718
775
  * @throws {UnsupportedBlueMarketIrmError} when positive source or destination debt requires an unsupported IRM projection.
719
776
  * @throws {MissingAccrualPositionError} when either position snapshot is absent at runtime.
720
777
  * @throws {MarketIdMismatchError} when a position snapshot belongs to another market.
@@ -740,7 +797,10 @@ export interface BlueActions {
740
797
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when authorization cannot be encoded safely.
741
798
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
742
799
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
743
- * @throws {viem.BaseError} from `getRequirements()` when authorization reads fail.
800
+ * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
801
+ * contract has no code at its registered address.
802
+ * @throws {viem.BaseError} from `getRequirements()` when an authorization read or
803
+ * `eth_chainId` request fails.
744
804
  * @example
745
805
  * ```ts
746
806
  * import { AccrualPosition } from "@morpho-org/blue-sdk";
@@ -797,13 +857,19 @@ export interface BlueActions {
797
857
  * @param params.block.number - Block number used for every RPC read.
798
858
  * @param params.block.timestamp - Timestamp corresponding to the fetched block.
799
859
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
800
- * @throws {ChainIdMismatchError} when the client chain does not match this market.
860
+ * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
861
+ * chain via `eth_chainId`.
801
862
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
802
863
  * @throws {UnknownAddressError} when the chain has no BluePublicAllocator deployment.
803
864
  * @throws {UnknownBlueFactory} when the chain has no Vault V2 factory.
804
865
  * @throws {UnknownBlueOfFactory} when a requested address is not a Vault V2 from that factory.
805
866
  * @throws {UnsupportedBlueVaultV2AdapterError} when a vault contains an unsupported adapter.
806
- * @throws {viem.BaseError} when an RPC or contract read fails with no fallback left.
867
+ * @throws {UnknownTokenError} when a vault's share token has unusable decimals.
868
+ * @throws {MalformedTokenMetadataError} when the share token's `eip712Domain()` or
869
+ * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
870
+ * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
871
+ * @throws {viem.BaseError} when the `eth_chainId` request fails or a later RPC or contract read
872
+ * fails with no fallback left.
807
873
  */
808
874
  getVaultV2BlueReallocationData: (params: {
809
875
  vaultAddresses: readonly Address[];
@@ -862,6 +928,16 @@ export declare class MorphoBlue implements BlueActions {
862
928
  constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
863
929
  private validateDeadline;
864
930
  private validateWriteCommon;
931
+ /**
932
+ * Asserts that every registry contract this flow's transaction targets or names as
933
+ * spender/authorized operator holds code, with one `eth_getCode` per distinct address
934
+ * before any other requirement read. Blue write flows probe `eth_chainId` only after a target
935
+ * has no code and report a chain mismatch when the RPC serves another chain.
936
+ *
937
+ * @param params.erc20Funding - Whether the flow resolves an ERC-20 funding leg, which
938
+ * may name canonical Permit2 when signatures are supported.
939
+ */
940
+ private assertWriteTargets;
865
941
  private getMaxLtv;
866
942
  private getBlueBundlesV1QuoteTimestamp;
867
943
  private getTokenRequirements;
@@ -998,13 +1074,19 @@ export declare class MorphoBlue implements BlueActions {
998
1074
  * @param params.block.number - Block number used for every RPC read.
999
1075
  * @param params.block.timestamp - Timestamp corresponding to the fetched block.
1000
1076
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
1001
- * @throws {ChainIdMismatchError} when the client chain does not match this market.
1077
+ * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
1078
+ * chain via `eth_chainId`.
1002
1079
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
1003
1080
  * @throws {UnknownAddressError} when the chain has no BluePublicAllocator deployment.
1004
1081
  * @throws {UnknownBlueFactory} when the chain has no Vault V2 factory.
1005
1082
  * @throws {UnknownBlueOfFactory} when a requested address is not a Vault V2 from that factory.
1006
1083
  * @throws {UnsupportedBlueVaultV2AdapterError} when a vault contains an unsupported adapter.
1007
- * @throws {viem.BaseError} when an RPC or contract read fails with no fallback left.
1084
+ * @throws {UnknownTokenError} when a vault's share token has unusable decimals.
1085
+ * @throws {MalformedTokenMetadataError} when the share token's `eip712Domain()` or
1086
+ * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
1087
+ * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
1088
+ * @throws {viem.BaseError} when the `eth_chainId` request fails or a later RPC or contract read
1089
+ * fails with no fallback left.
1008
1090
  * @example
1009
1091
  * ```ts
1010
1092
  * import { markets } from "@morpho-org/morpho-test";
@@ -7,8 +7,10 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
8
  const common_js_1 = require("../../actions/blue/common.js");
9
9
  const index_js_1 = require("../../actions/index.js");
10
+ const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
10
11
  const index_js_2 = require("../../helpers/index.js");
11
12
  const index_js_3 = require("../../types/index.js");
13
+ const assertContractCode_js_1 = require("../requirements/assertContractCode.js");
12
14
  const index_js_4 = require("../requirements/index.js");
13
15
  const vaultV2BlueReallocationData_js_1 = require("../vaultV2BlueReallocationData.js");
14
16
  /** Binds a viem client to a Morpho Blue market's action builders. */
@@ -22,10 +24,9 @@ class MorphoBlue {
22
24
  this.marketParams = marketParams;
23
25
  this.chainId = chainId;
24
26
  }
25
- validateDeadline(deadline) {
26
- const timestamp = morpho_ts_1.Time.timestamp();
27
- if (deadline <= timestamp) {
28
- throw new index_js_3.ExpiredDeadlineError(deadline, timestamp);
27
+ validateDeadline(deadline, now = morpho_ts_1.Time.timestamp()) {
28
+ if (deadline <= now) {
29
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
29
30
  }
30
31
  }
31
32
  validateWriteCommon(params) {
@@ -43,6 +44,30 @@ class MorphoBlue {
43
44
  referralFeeRecipient: params.referralFeeRecipient,
44
45
  });
45
46
  }
47
+ /**
48
+ * Asserts that every registry contract this flow's transaction targets or names as
49
+ * spender/authorized operator holds code, with one `eth_getCode` per distinct address
50
+ * before any other requirement read. Blue write flows probe `eth_chainId` only after a target
51
+ * has no code and report a chain mismatch when the RPC serves another chain.
52
+ *
53
+ * @param params.erc20Funding - Whether the flow resolves an ERC-20 funding leg, which
54
+ * may name canonical Permit2 when signatures are supported.
55
+ */
56
+ async assertWriteTargets(params) {
57
+ const targets = [
58
+ {
59
+ role: "bundles.blueBundlesV1",
60
+ address: (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.blueBundlesV1"),
61
+ },
62
+ { role: "blue", address: (0, morpho_ts_1.getChainAddress)(this.chainId, "blue") },
63
+ ];
64
+ if (params?.erc20Funding && this.client.options.supportSignature) {
65
+ const permit2 = (0, morpho_ts_1.getChainAddresses)(this.chainId).permit2;
66
+ if (permit2 != null)
67
+ targets.push({ role: "permit2", address: permit2 });
68
+ }
69
+ await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(this.client.viemClient, this.chainId, targets);
70
+ }
46
71
  getMaxLtv(marketParams = this.marketParams) {
47
72
  return blue_sdk_1.MathLib.zeroFloorSub(marketParams.lltv, index_js_2.DEFAULT_LLTV_BUFFER);
48
73
  }
@@ -50,7 +75,7 @@ class MorphoBlue {
50
75
  return blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
51
76
  }
52
77
  async getTokenRequirements(params) {
53
- this.validateDeadline(params.deadline);
78
+ this.validateDeadline(params.deadline, params.now);
54
79
  return (0, index_js_4.getBundlesTokenRequirements)(this.client.viemClient, {
55
80
  token: params.token,
56
81
  spender: (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.blueBundlesV1"),
@@ -63,10 +88,11 @@ class MorphoBlue {
63
88
  useSimplePermit: params.useSimplePermit,
64
89
  permit2Nonce: params.permit2Nonce,
65
90
  approvalAmount: params.approvalAmount,
91
+ now: params.now,
66
92
  });
67
93
  }
68
94
  async getAuthorizationRequirements(params) {
69
- this.validateDeadline(params.deadline);
95
+ this.validateDeadline(params.deadline, params.now);
70
96
  const requirement = await (0, index_js_1.getBlueAuthorizationRequirement)({
71
97
  viemClient: this.client.viemClient,
72
98
  chainId: this.chainId,
@@ -74,18 +100,19 @@ class MorphoBlue {
74
100
  supportSignature: this.client.options.supportSignature,
75
101
  authorized: (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.blueBundlesV1"),
76
102
  deadline: params.deadline,
103
+ now: params.now,
77
104
  });
78
105
  return requirement == null ? [] : [requirement];
79
106
  }
80
107
  async getMarketData(parameters) {
81
- (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
108
+ await (0, validateClientChainId_js_1.validateClientChainId)(this.client.viemClient, this.chainId);
82
109
  return (0, blue_sdk_viem_1.fetchMarket)(this.marketParams.id, this.client.viemClient, {
83
110
  ...parameters,
84
111
  deployless: this.client.options.supportDeployless,
85
112
  });
86
113
  }
87
114
  async getPositionData(userAddress, parameters) {
88
- (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
115
+ await (0, validateClientChainId_js_1.validateClientChainId)(this.client.viemClient, this.chainId);
89
116
  return (0, blue_sdk_viem_1.fetchAccrualPosition)(userAddress, this.marketParams.id, this.client.viemClient, {
90
117
  ...parameters,
91
118
  deployless: this.client.options.supportDeployless,
@@ -105,17 +132,23 @@ class MorphoBlue {
105
132
  });
106
133
  return {
107
134
  getRequirements: (requirementsParams) => {
108
- this.validateDeadline(deadline);
109
- if (nativeValue > 0n)
110
- return Promise.resolve([]);
111
- return this.getTokenRequirements({
112
- token: this.marketParams.loanToken,
113
- amount: assets,
114
- userAddress,
115
- deadline,
116
- useSimplePermit: requirementsParams?.useSimplePermit,
117
- permit2Nonce: requirementsParams?.permit2Nonce,
118
- approvalAmount: requirementsParams?.approvalAmount,
135
+ const now = morpho_ts_1.Time.timestamp();
136
+ this.validateDeadline(deadline, now);
137
+ return this.assertWriteTargets({
138
+ erc20Funding: nativeValue === 0n,
139
+ }).then(() => {
140
+ if (nativeValue > 0n)
141
+ return [];
142
+ return this.getTokenRequirements({
143
+ token: this.marketParams.loanToken,
144
+ amount: assets,
145
+ userAddress,
146
+ deadline,
147
+ now,
148
+ useSimplePermit: requirementsParams?.useSimplePermit,
149
+ permit2Nonce: requirementsParams?.permit2Nonce,
150
+ approvalAmount: requirementsParams?.approvalAmount,
151
+ });
119
152
  });
120
153
  },
121
154
  buildTx: (signatures) => {
@@ -189,7 +222,16 @@ class MorphoBlue {
189
222
  });
190
223
  }
191
224
  return {
192
- getRequirements: () => this.getAuthorizationRequirements({ userAddress, deadline }),
225
+ getRequirements: async () => {
226
+ const now = morpho_ts_1.Time.timestamp();
227
+ this.validateDeadline(deadline, now);
228
+ await this.assertWriteTargets();
229
+ return this.getAuthorizationRequirements({
230
+ userAddress,
231
+ deadline,
232
+ now,
233
+ });
234
+ },
193
235
  buildTx: (signatures) => {
194
236
  const { authorization } = (0, common_js_1.selectBlueBundlesV1RequirementSignatures)(signatures, {
195
237
  authorization: true,
@@ -433,7 +475,11 @@ class MorphoBlue {
433
475
  }
434
476
  return {
435
477
  getRequirements: async (requirementsParams) => {
436
- this.validateDeadline(deadline);
478
+ const now = morpho_ts_1.Time.timestamp();
479
+ this.validateDeadline(deadline, now);
480
+ await this.assertWriteTargets({
481
+ erc20Funding: hasRepay && nativeValue === 0n,
482
+ });
437
483
  const [tokenRequirements, authorizationRequirements] = await Promise.all([
438
484
  hasRepay && nativeValue === 0n
439
485
  ? this.getTokenRequirements({
@@ -442,12 +488,17 @@ class MorphoBlue {
442
488
  approvalAmount: requirementsParams?.approvalAmount,
443
489
  userAddress,
444
490
  deadline,
491
+ now,
445
492
  useSimplePermit: requirementsParams?.useSimplePermit,
446
493
  permit2Nonce: requirementsParams?.permit2Nonce,
447
494
  })
448
495
  : Promise.resolve([]),
449
496
  collateralAssets > 0n
450
- ? this.getAuthorizationRequirements({ userAddress, deadline })
497
+ ? this.getAuthorizationRequirements({
498
+ userAddress,
499
+ deadline,
500
+ now,
501
+ })
451
502
  : Promise.resolve([]),
452
503
  ]);
453
504
  return [...tokenRequirements, ...authorizationRequirements];
@@ -536,7 +587,11 @@ class MorphoBlue {
536
587
  });
537
588
  return {
538
589
  getRequirements: async (requirementsParams) => {
539
- this.validateDeadline(deadline);
590
+ const now = morpho_ts_1.Time.timestamp();
591
+ this.validateDeadline(deadline, now);
592
+ await this.assertWriteTargets({
593
+ erc20Funding: collateralAssets > 0n && nativeValue === 0n,
594
+ });
540
595
  const [tokenRequirements, authorizationRequirements] = await Promise.all([
541
596
  collateralAssets > 0n && nativeValue === 0n
542
597
  ? this.getTokenRequirements({
@@ -545,12 +600,17 @@ class MorphoBlue {
545
600
  approvalAmount: requirementsParams?.approvalAmount,
546
601
  userAddress,
547
602
  deadline,
603
+ now,
548
604
  useSimplePermit: requirementsParams?.useSimplePermit,
549
605
  permit2Nonce: requirementsParams?.permit2Nonce,
550
606
  })
551
607
  : Promise.resolve([]),
552
608
  borrowAssets > 0n
553
- ? this.getAuthorizationRequirements({ userAddress, deadline })
609
+ ? this.getAuthorizationRequirements({
610
+ userAddress,
611
+ deadline,
612
+ now,
613
+ })
554
614
  : Promise.resolve([]),
555
615
  ]);
556
616
  return [...tokenRequirements, ...authorizationRequirements];
@@ -628,7 +688,16 @@ class MorphoBlue {
628
688
  lltv: destination.marketParams.lltv,
629
689
  });
630
690
  return {
631
- getRequirements: () => this.getAuthorizationRequirements({ userAddress, deadline }),
691
+ getRequirements: async () => {
692
+ const now = morpho_ts_1.Time.timestamp();
693
+ this.validateDeadline(deadline, now);
694
+ await this.assertWriteTargets();
695
+ return this.getAuthorizationRequirements({
696
+ userAddress,
697
+ deadline,
698
+ now,
699
+ });
700
+ },
632
701
  buildTx: (signatures) => {
633
702
  const { authorization } = (0, common_js_1.selectBlueBundlesV1RequirementSignatures)(signatures, {
634
703
  authorization: true,
@@ -663,13 +732,19 @@ class MorphoBlue {
663
732
  * @param params.block.number - Block number used for every RPC read.
664
733
  * @param params.block.timestamp - Timestamp corresponding to the fetched block.
665
734
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
666
- * @throws {ChainIdMismatchError} when the client chain does not match this market.
735
+ * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
736
+ * chain via `eth_chainId`.
667
737
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
668
738
  * @throws {UnknownAddressError} when the chain has no BluePublicAllocator deployment.
669
739
  * @throws {UnknownBlueFactory} when the chain has no Vault V2 factory.
670
740
  * @throws {UnknownBlueOfFactory} when a requested address is not a Vault V2 from that factory.
671
741
  * @throws {UnsupportedBlueVaultV2AdapterError} when a vault contains an unsupported adapter.
672
- * @throws {viem.BaseError} when an RPC or contract read fails with no fallback left.
742
+ * @throws {UnknownTokenError} when a vault's share token has unusable decimals.
743
+ * @throws {MalformedTokenMetadataError} when the share token's `eip712Domain()` or
744
+ * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
745
+ * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
746
+ * @throws {viem.BaseError} when the `eth_chainId` request fails or a later RPC or contract read
747
+ * fails with no fallback left.
673
748
  * @example
674
749
  * ```ts
675
750
  * import { markets } from "@morpho-org/morpho-test";
@@ -691,7 +766,7 @@ class MorphoBlue {
691
766
  * ```
692
767
  */
693
768
  async getVaultV2BlueReallocationData({ vaultAddresses, block, }) {
694
- (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
769
+ await (0, validateClientChainId_js_1.validateClientChainId)(this.client.viemClient, this.chainId);
695
770
  const client = this.client.viemClient;
696
771
  const fetchParams = {
697
772
  blockNumber: block.number,
@@ -12,7 +12,7 @@ export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnap
12
12
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
13
13
  export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
14
14
  export { MorphoBlue } from "./blue/index.js";
15
- export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, } from "./midnight/index.js";
15
+ export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, MidnightPositionHealthParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, } from "./midnight/index.js";
16
16
  export { type MidnightActionOutput, type MidnightActions, type MidnightRequirementsParams, MorphoMidnight, } from "./midnight/index.js";
17
17
  export * from "./requirements/index.js";
18
18
  export { MorphoVaultV1 } from "./vaultV1/index.js";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Rejects a Midnight bundle deadline that is not strictly after `now`.
3
+ *
4
+ * Midnight bundles revert with `DeadlinePassed()` once the deadline has passed, so a deadline at
5
+ * or before `now` builds a transaction that cannot succeed. `maxUint256` still means
6
+ * "no expiry". The check uses the local clock (`Time.timestamp()`), not chain time. Transaction
7
+ * builders stay clock-free and only check the deadline's `uint256` shape.
8
+ *
9
+ * @param deadline - Bundle execution deadline timestamp, in seconds.
10
+ * @param now - Reference timestamp, in seconds. Defaults to `Time.timestamp()`.
11
+ * @returns Nothing when `deadline` is after `now`.
12
+ * @throws {ExpiredDeadlineError} when `deadline` is at or before `now`.
13
+ * @internal
14
+ */
15
+ export declare const validateMidnightDeadline: (deadline: bigint, now?: bigint) => void;