@morpho-org/morpho-sdk 6.6.0 → 7.1.0-next.1

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 (195) hide show
  1. package/MIGRATION-v6-to-v7.md +297 -0
  2. package/README.md +26 -12
  3. package/lib/cjs/abis.d.ts +2 -2
  4. package/lib/cjs/abis.js +7 -2
  5. package/lib/cjs/actions/bundles/common.d.ts +9 -5
  6. package/lib/cjs/actions/bundles/common.js +22 -13
  7. package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
  8. package/lib/cjs/actions/midnight/authorization.js +3 -2
  9. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
  10. package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
  11. package/lib/cjs/actions/midnight/index.d.ts +3 -3
  12. package/lib/cjs/actions/midnight/index.js +3 -3
  13. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  14. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
  18. package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
  20. package/lib/cjs/actions/midnight/takeLend.js +111 -54
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
  25. package/lib/cjs/actions/midnight/types.d.ts +7 -26
  26. package/lib/cjs/actions/midnight/types.js +0 -13
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
  31. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
  32. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  33. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
  35. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  37. package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
  38. package/lib/cjs/actions/requirements/midnight/index.js +0 -1
  39. package/lib/cjs/blue/abis.d.ts +1 -1
  40. package/lib/cjs/blue/abis.js +5 -1
  41. package/lib/cjs/blue/entities.d.ts +4 -4
  42. package/lib/cjs/blue/entities.js +3 -1
  43. package/lib/cjs/blue/errors.d.ts +2 -2
  44. package/lib/cjs/blue/errors.js +5 -1
  45. package/lib/cjs/blue/fetch.d.ts +2 -2
  46. package/lib/cjs/blue/fetch.js +3 -1
  47. package/lib/cjs/blue/utils.d.ts +1 -1
  48. package/lib/cjs/blue/utils.js +2 -1
  49. package/lib/cjs/constants.d.ts +1 -1
  50. package/lib/cjs/constants.js +2 -1
  51. package/lib/cjs/entities/index.d.ts +6 -6
  52. package/lib/cjs/entities/index.js +3 -1
  53. package/lib/cjs/entities/midnight/midnight.d.ts +585 -108
  54. package/lib/cjs/entities/midnight/midnight.js +984 -509
  55. package/lib/cjs/entities/midnight/types.d.ts +142 -60
  56. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +3 -2
  57. package/lib/cjs/entities/vaultV1/vaultV1.js +32 -34
  58. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +37 -12
  59. package/lib/cjs/entities/vaultV2/vaultV2.js +68 -41
  60. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +5 -3
  61. package/lib/cjs/entities/vaultV2BlueReallocationData.js +9 -3
  62. package/lib/cjs/errors.d.ts +4 -4
  63. package/lib/cjs/errors.js +10 -5
  64. package/lib/cjs/fetch.d.ts +2 -2
  65. package/lib/cjs/fetch.js +3 -1
  66. package/lib/cjs/helpers/callback.d.ts +54 -0
  67. package/lib/cjs/helpers/callback.js +73 -0
  68. package/lib/cjs/helpers/constant.d.ts +2 -0
  69. package/lib/cjs/helpers/constant.js +3 -1
  70. package/lib/cjs/helpers/index.d.ts +3 -2
  71. package/lib/cjs/helpers/index.js +6 -1
  72. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
  73. package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
  74. package/lib/cjs/helpers/validate.d.ts +43 -2
  75. package/lib/cjs/helpers/validate.js +60 -3
  76. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  77. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
  78. package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
  79. package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
  80. package/lib/cjs/midnight/abis.d.ts +1 -1
  81. package/lib/cjs/midnight/abis.js +3 -2
  82. package/lib/cjs/midnight/errors.d.ts +2 -1
  83. package/lib/cjs/midnight/errors.js +5 -4
  84. package/lib/cjs/midnight/types.d.ts +1 -1
  85. package/lib/cjs/types/action.d.ts +219 -90
  86. package/lib/cjs/types/action.js +103 -20
  87. package/lib/cjs/types/error.d.ts +126 -40
  88. package/lib/cjs/types/error.js +154 -49
  89. package/lib/cjs/utils.d.ts +2 -2
  90. package/lib/cjs/utils.js +4 -2
  91. package/lib/esm/abis.d.ts +2 -2
  92. package/lib/esm/abis.js +2 -2
  93. package/lib/esm/actions/bundles/common.d.ts +9 -5
  94. package/lib/esm/actions/bundles/common.js +22 -13
  95. package/lib/esm/actions/midnight/authorization.d.ts +3 -2
  96. package/lib/esm/actions/midnight/authorization.js +3 -2
  97. package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
  98. package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
  99. package/lib/esm/actions/midnight/index.d.ts +3 -3
  100. package/lib/esm/actions/midnight/index.js +3 -3
  101. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  102. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
  103. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  104. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
  105. package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
  106. package/lib/esm/actions/midnight/takeBorrow.js +98 -57
  107. package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
  108. package/lib/esm/actions/midnight/takeLend.js +114 -57
  109. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  110. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
  111. package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
  112. package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
  113. package/lib/esm/actions/midnight/types.d.ts +7 -26
  114. package/lib/esm/actions/midnight/types.js +1 -12
  115. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  116. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  117. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  118. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
  119. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
  120. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
  121. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  122. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
  123. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  124. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  125. package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
  126. package/lib/esm/actions/requirements/midnight/index.js +0 -1
  127. package/lib/esm/blue/abis.d.ts +1 -1
  128. package/lib/esm/blue/abis.js +1 -1
  129. package/lib/esm/blue/entities.d.ts +4 -4
  130. package/lib/esm/blue/entities.js +2 -2
  131. package/lib/esm/blue/errors.d.ts +2 -2
  132. package/lib/esm/blue/errors.js +2 -2
  133. package/lib/esm/blue/fetch.d.ts +2 -2
  134. package/lib/esm/blue/fetch.js +2 -2
  135. package/lib/esm/blue/utils.d.ts +1 -1
  136. package/lib/esm/blue/utils.js +1 -1
  137. package/lib/esm/constants.d.ts +1 -1
  138. package/lib/esm/constants.js +1 -1
  139. package/lib/esm/entities/index.d.ts +6 -6
  140. package/lib/esm/entities/index.js +2 -2
  141. package/lib/esm/entities/midnight/midnight.d.ts +585 -108
  142. package/lib/esm/entities/midnight/midnight.js +990 -515
  143. package/lib/esm/entities/midnight/types.d.ts +142 -60
  144. package/lib/esm/entities/vaultV1/vaultV1.d.ts +3 -2
  145. package/lib/esm/entities/vaultV1/vaultV1.js +33 -35
  146. package/lib/esm/entities/vaultV2/vaultV2.d.ts +37 -12
  147. package/lib/esm/entities/vaultV2/vaultV2.js +69 -42
  148. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +5 -3
  149. package/lib/esm/entities/vaultV2BlueReallocationData.js +9 -3
  150. package/lib/esm/errors.d.ts +4 -4
  151. package/lib/esm/errors.js +4 -4
  152. package/lib/esm/fetch.d.ts +2 -2
  153. package/lib/esm/fetch.js +2 -2
  154. package/lib/esm/helpers/callback.d.ts +54 -0
  155. package/lib/esm/helpers/callback.js +68 -0
  156. package/lib/esm/helpers/constant.d.ts +2 -0
  157. package/lib/esm/helpers/constant.js +2 -0
  158. package/lib/esm/helpers/index.d.ts +3 -2
  159. package/lib/esm/helpers/index.js +3 -2
  160. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
  161. package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
  162. package/lib/esm/helpers/validate.d.ts +43 -2
  163. package/lib/esm/helpers/validate.js +58 -2
  164. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  165. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
  166. package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
  167. package/lib/esm/helpers/validateRequirementSpender.js +4 -5
  168. package/lib/esm/midnight/abis.d.ts +1 -1
  169. package/lib/esm/midnight/abis.js +1 -1
  170. package/lib/esm/midnight/errors.d.ts +2 -1
  171. package/lib/esm/midnight/errors.js +2 -1
  172. package/lib/esm/midnight/types.d.ts +1 -1
  173. package/lib/esm/types/action.d.ts +219 -90
  174. package/lib/esm/types/action.js +103 -19
  175. package/lib/esm/types/error.d.ts +126 -40
  176. package/lib/esm/types/error.js +135 -38
  177. package/lib/esm/utils.d.ts +2 -2
  178. package/lib/esm/utils.js +2 -2
  179. package/package.json +10 -10
  180. package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
  181. package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
  182. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  183. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
  184. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  185. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
  186. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  187. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
  188. package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
  189. package/lib/esm/actions/midnight/cancelOffer.js +0 -69
  190. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  191. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
  192. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  193. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
  194. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  195. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
@@ -2,7 +2,7 @@ import { AccrualVaultV2MorphoMarketV1AdapterV2, DEFAULT_SLIPPAGE_TOLERANCE, Mark
2
2
  import { erc2612Abi, fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
3
3
  import { _try, getChainAddress, Time } from "@morpho-org/morpho-ts";
4
4
  import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
5
- import { multicall } from "viem/actions";
5
+ import { readContract } from "viem/actions";
6
6
  import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
7
7
  import { encodeErc20Approval, encodeVaultSharesPermit, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2InKindRedeem, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
8
8
  import { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, MAX_SLIPPAGE_TOLERANCE, resolveVaultV2ForceWithdrawEligibility, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
@@ -14,6 +14,11 @@ import { getBundlesTokenRequirements } from "../requirements/index.js";
14
14
  // Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
15
15
  // accrual model stays well-defined inside it.
16
16
  const VAULT_V2_FEE_PROJECTION_HORIZON = Time.s.from.y(1n);
17
+ /**
18
+ * Midnight adapters revert vault-initiated `allocate` and `deallocate` (`SelfAllocationOnly`), so a
19
+ * vault routing liquidity through one accepts no deposit and serves exits from idle assets only.
20
+ */
21
+ const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
17
22
  /** Binds a viem client to a Vault V2 vault's action builders. */
18
23
  export class MorphoVaultV2 {
19
24
  client;
@@ -56,6 +61,13 @@ export class MorphoVaultV2 {
56
61
  // The native path must target the chain's registered wrapped-native asset.
57
62
  validateNativeVaultAsset(this.chainId, vaultAsset);
58
63
  }
64
+ if (isMidnightLiquidityAdapter(vaultData)) {
65
+ throw new InputExceedsMaxError({
66
+ field: funding.value > 0n ? "nativeAmount" : "amount",
67
+ value: funding.assets,
68
+ max: 0n,
69
+ });
70
+ }
59
71
  const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
60
72
  const maxSharePrice = computeVaultMaxSharePrice({
61
73
  vaultData,
@@ -133,6 +145,14 @@ export class MorphoVaultV2 {
133
145
  throw new NonPositiveInputError("amount", amount);
134
146
  // Reject values outside the ABI range before resolving any requirements.
135
147
  validateUint256Field("amount", amount);
148
+ if (isMidnightLiquidityAdapter(vaultData) &&
149
+ amount > vaultData.assetBalance) {
150
+ throw new InputExceedsMaxError({
151
+ field: "amount",
152
+ value: amount,
153
+ max: vaultData.assetBalance,
154
+ });
155
+ }
136
156
  const createdAt = Time.timestamp();
137
157
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
138
158
  if (deadline <= createdAt)
@@ -181,6 +201,7 @@ export class MorphoVaultV2 {
181
201
  const permit = selectBundlesSharesPermitSignature(signatures, {
182
202
  spender,
183
203
  amount: requiredShareAllowance,
204
+ maxAmount: maxShareAllowance,
184
205
  deadline,
185
206
  });
186
207
  return vaultV2Withdraw({
@@ -219,8 +240,20 @@ export class MorphoVaultV2 {
219
240
  const now = Time.timestamp();
220
241
  if (deadline <= now)
221
242
  throw new ExpiredDeadlineError(deadline, now);
243
+ const vaultData = await this.getData();
244
+ if (isMidnightLiquidityAdapter(vaultData)) {
245
+ // Onchain redeem accrues interest before converting shares to assets.
246
+ const { vault: accrued } = vaultData.accrueInterest(now);
247
+ if (accrued.toAssets(shares) > accrued.assetBalance) {
248
+ throw new InputExceedsMaxError({
249
+ field: "shares",
250
+ value: shares,
251
+ max: accrued.toShares(accrued.assetBalance),
252
+ });
253
+ }
254
+ }
222
255
  return getVaultBundlesSharesRequirements(this.client.viemClient, {
223
- vaultData: await this.getData(),
256
+ vaultData,
224
257
  version: "vaultV2",
225
258
  owner: userAddress,
226
259
  chainId: this.chainId,
@@ -358,29 +391,26 @@ export class MorphoVaultV2 {
358
391
  // after intermediate penalty share burns, so one standalone read is not execution-equivalent
359
392
  // either. Simulate the finalized transaction after authorization when gate compatibility
360
393
  // must be checked before submission.
361
- const [allowance, nonce, blueBalance] = await multicall(this.client.viemClient, {
362
- allowFailure: false,
363
- contracts: [
364
- {
365
- address: this.vault,
366
- abi: erc20Abi,
367
- functionName: "allowance",
368
- args: [userAddress, vaultExitBundlesV1],
369
- },
370
- {
371
- address: this.vault,
372
- abi: erc2612Abi,
373
- functionName: "nonces",
374
- args: [userAddress],
375
- },
376
- {
377
- address: vaultData.asset,
378
- abi: erc20Abi,
379
- functionName: "balanceOf",
380
- args: [blue],
381
- },
382
- ],
383
- });
394
+ const [allowance, nonce, blueBalance] = await Promise.all([
395
+ readContract(this.client.viemClient, {
396
+ address: this.vault,
397
+ abi: erc20Abi,
398
+ functionName: "allowance",
399
+ args: [userAddress, vaultExitBundlesV1],
400
+ }),
401
+ readContract(this.client.viemClient, {
402
+ address: this.vault,
403
+ abi: erc2612Abi,
404
+ functionName: "nonces",
405
+ args: [userAddress],
406
+ }),
407
+ readContract(this.client.viemClient, {
408
+ address: vaultData.asset,
409
+ abi: erc20Abi,
410
+ functionName: "balanceOf",
411
+ args: [blue],
412
+ }),
413
+ ]);
384
414
  if (blueBalance < peak) {
385
415
  throw new InsufficientBlueBalanceForInKindRedeemError({
386
416
  asset: vaultData.asset,
@@ -622,23 +652,20 @@ export class MorphoVaultV2 {
622
652
  // external code re-evaluated after each intermediate penalty burn, so neither is
623
653
  // execution-equivalent from a standalone read. Unlike in-kind redemption, this exit never
624
654
  // supplies into Morpho Blue, so no Blue token-balance check is needed.
625
- const [allowance, nonce] = await multicall(this.client.viemClient, {
626
- allowFailure: false,
627
- contracts: [
628
- {
629
- address: this.vault,
630
- abi: erc20Abi,
631
- functionName: "allowance",
632
- args: [userAddress, vaultExitBundlesV1],
633
- },
634
- {
635
- address: this.vault,
636
- abi: erc2612Abi,
637
- functionName: "nonces",
638
- args: [userAddress],
639
- },
640
- ],
641
- });
655
+ const [allowance, nonce] = await Promise.all([
656
+ readContract(this.client.viemClient, {
657
+ address: this.vault,
658
+ abi: erc20Abi,
659
+ functionName: "allowance",
660
+ args: [userAddress, vaultExitBundlesV1],
661
+ }),
662
+ readContract(this.client.viemClient, {
663
+ address: this.vault,
664
+ abi: erc2612Abi,
665
+ functionName: "nonces",
666
+ args: [userAddress],
667
+ }),
668
+ ]);
642
669
  if (allowance >= requiredShareAllowance)
643
670
  return [];
644
671
  if (this.client.options.supportSignature) {
@@ -39,8 +39,9 @@ export interface InputVaultV2BlueReallocationData {
39
39
  /**
40
40
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
41
41
  *
42
- * Constructor inputs are cloned. Every simulated reallocation returns a new
43
- * instance. Planning keeps the transaction-scoped `firstTotalAssets`
42
+ * Constructor inputs are cloned, except Midnight adapter snapshots: those are
43
+ * shared by reference and must be treated as read-only. Every simulated
44
+ * reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
44
45
  * denominator outside the durable snapshot while applying reallocations in
45
46
  * contract order. Penalty donations update simulated vault accounting but are
46
47
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -100,7 +101,8 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
100
101
  /**
101
102
  * Clones the complete simulation snapshot.
102
103
  *
103
- * @returns A deep clone of this simulation state.
104
+ * @returns A deep clone of this simulation state. Midnight adapter snapshots are
105
+ * shared by reference and must be treated as read-only.
104
106
  * @example
105
107
  * ```ts
106
108
  * import { markets } from "@morpho-org/morpho-test";
@@ -75,6 +75,10 @@ const cloneAccrualVault = (vault, markets) => new AccrualVault({
75
75
  position: clonePosition(position, markets),
76
76
  })));
77
77
  const cloneAdapter = (adapter, markets) => {
78
+ // BluePublicAllocator never moves Midnight liquidity, and reallocation never mutates a Midnight
79
+ // adapter, so its read-only snapshot is shared as-is.
80
+ if (adapter.type === "VaultV2MidnightAdapter")
81
+ return adapter;
78
82
  const base = {
79
83
  address: adapter.address,
80
84
  parentVault: adapter.parentVault,
@@ -122,8 +126,9 @@ const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
122
126
  /**
123
127
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
124
128
  *
125
- * Constructor inputs are cloned. Every simulated reallocation returns a new
126
- * instance. Planning keeps the transaction-scoped `firstTotalAssets`
129
+ * Constructor inputs are cloned, except Midnight adapter snapshots: those are
130
+ * shared by reference and must be treated as read-only. Every simulated
131
+ * reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
127
132
  * denominator outside the durable snapshot while applying reallocations in
128
133
  * contract order. Penalty donations update simulated vault accounting but are
129
134
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -245,7 +250,8 @@ export class VaultV2BlueReallocationData {
245
250
  /**
246
251
  * Clones the complete simulation snapshot.
247
252
  *
248
- * @returns A deep clone of this simulation state.
253
+ * @returns A deep clone of this simulation state. Midnight adapter snapshots are
254
+ * shared by reference and must be treated as read-only.
249
255
  * @example
250
256
  * ```ts
251
257
  * import { markets } from "@morpho-org/morpho-test";
@@ -1,7 +1,7 @@
1
- export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
1
+ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, InvalidVaultV2MidnightAdapterMarketsError as InvalidBlueVaultV2MidnightAdapterMarketsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnresolvedBlockNumberError as BlueUnresolvedBlockNumberError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
6
6
  export type { ErrorClass } from "@morpho-org/morpho-ts";
7
- export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
7
+ export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, InvalidPositionAccrualStateError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
package/lib/esm/errors.js CHANGED
@@ -1,6 +1,6 @@
1
- export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
1
+ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, InvalidVaultV2MidnightAdapterMarketsError as InvalidBlueVaultV2MidnightAdapterMarketsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
6
- export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnresolvedBlockNumberError as BlueUnresolvedBlockNumberError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
6
+ export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, InvalidPositionAccrualStateError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
@@ -1,6 +1,6 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  fetchPreLiquidationParams as fetchBluePreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
5
+ fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
6
6
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
package/lib/esm/fetch.js CHANGED
@@ -1,6 +1,6 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  fetchPreLiquidationParams as fetchBluePreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
5
+ fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
6
6
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
@@ -0,0 +1,54 @@
1
+ import { type InputMarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Address, type Hex } from "viem";
3
+ /**
4
+ * Computes the CREATE2 address of `owner`'s `BlueBuyCallback` for `salt`, as deployed or
5
+ * returned by the chain's `midnightBlueBuyCallbackFactory.createBlueBuyCallback(owner, salt)`.
6
+ *
7
+ * Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`.
8
+ *
9
+ * @param params.chainId - Chain whose `midnightBlueBuyCallbackFactory`, `midnight` and `blue` are used.
10
+ * @param params.owner - Callback owner, the maker.
11
+ * @param params.salt - Callback salt.
12
+ * @returns The callback address, whether or not it is deployed yet.
13
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
14
+ * @throws {UnknownAddressError} when the chain has no `midnightBlueBuyCallbackFactory`, `midnight` or `blue` deployment.
15
+ * @example
16
+ * ```ts
17
+ * import { getMidnightBlueBuyCallbackAddress } from "@morpho-org/morpho-sdk";
18
+ * import { ChainId } from "@morpho-org/morpho-ts";
19
+ * import { keccak256, toHex } from "viem";
20
+ * import type { Address } from "viem";
21
+ *
22
+ * const callbackFor = (maker: Address) =>
23
+ * getMidnightBlueBuyCallbackAddress({
24
+ * chainId: ChainId.EthMainnet,
25
+ * owner: maker,
26
+ * salt: keccak256(toHex("my-strategy")),
27
+ * });
28
+ * // `callbackFor(maker)` returns the maker's BlueBuyCallback address, deployed or not.
29
+ * ```
30
+ */
31
+ export declare const getMidnightBlueBuyCallbackAddress: ({ chainId, owner, salt, }: {
32
+ readonly chainId: number;
33
+ readonly owner: Address;
34
+ readonly salt: Hex;
35
+ }) => Address;
36
+ /**
37
+ * Returns the `callbackData` every `supplyBlueMakeLend` offer must carry: `abi.encode(blueMarket)`.
38
+ *
39
+ * @param blueMarket - Morpho Blue market encoded as the callback data.
40
+ * @returns The ABI-encoded Morpho Blue market parameters.
41
+ * @example
42
+ * ```ts
43
+ * import { getMidnightBlueBuyCallbackData } from "@morpho-org/morpho-sdk";
44
+ * import type { InputMarketParams as MarketParams } from "@morpho-org/blue-sdk";
45
+ * import type { Hex } from "viem";
46
+ *
47
+ * function getCallbackData(blueMarket: MarketParams) {
48
+ * const callbackData = getMidnightBlueBuyCallbackData(blueMarket);
49
+ * // callbackData satisfies Hex
50
+ * return callbackData;
51
+ * }
52
+ * ```
53
+ */
54
+ export declare const getMidnightBlueBuyCallbackData: (blueMarket: InputMarketParams) => Hex;
@@ -0,0 +1,68 @@
1
+ import { marketParamsAbi } from "@morpho-org/blue-sdk";
2
+ import { getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { concatHex, encodeAbiParameters, getContractAddress, } from "viem";
4
+ /**
5
+ * `BlueBuyCallback` creation bytecode from `morpho-org/midnight` commit
6
+ * `4603969e`, embedded in the `BlueBuyCallbackFactory` deployed on Ethereum, Base, Robinhood and Arc.
7
+ */
8
+ const blueBuyCallbackBytecode = "0x60e0806040523461012657606081611611803803809161001f828561012a565b8339810103126101265761003281610161565b9061004b604061004460208401610161565b9201610161565b908260805260a0528060c05260018060a01b031690813b15610126576040516207767560ed1b81526001600160a01b03909116600482015260016024820152905f908290604490829084905af1801561011b5761010b575b60405161149b9081610176823960805181818160b4015281816102fc0152818161078201528181610dfd0152611004015260a0518181816102210152610dc3015260c051818181610103015281816102650152818161067c015281816108660152610f5e0152f35b5f6101159161012a565b5f6100a3565b6040513d5f823e3d90fd5b5f80fd5b601f909101601f19168101906001600160401b0382119082101761014d57604052565b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036101265756fe6080806040526004361015610012575f80fd5b5f905f3560e01c908163117803e314610fe7575080631c0bb54d14610d585780631e686318146107ef5780638069218f1461043d578063affed0e014610420578063bc25cf7714610289578063c011ff6414610245578063dc400c12146102015763eecea00014610081575f80fd5b346101a15760403660031901126101a15761009a61107c565b9060243591821515908184036101fd576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633036101ee576040516332f256cf60e11b81523060048201526001600160a01b038281166024830152939485947f000000000000000000000000000000000000000000000000000000000000000016939091602081604481885afa9081156101e35786916101b4575b5015150361014a57505050f35b823b156101af576040516207767560ed1b81526001600160a01b03929092166004830152151560248201529082908290604490829084905af180156101a4576101905750f35b8161019a91611044565b6101a15780f35b80fd5b6040513d84823e3d90fd5b505050fd5b6101d6915060203d6020116101dc575b6101ce8183611044565b810190611358565b5f61013d565b503d6101c4565b6040513d88823e3d90fd5b6330cd747160e01b8352600483fd5b8280fd5b50346101a157806003193601126101a15760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346101a157806003193601126101a15760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346101a15760203660031901126101a1576102a361107c565b6040516370a0823160e01b81523060048201526001600160a01b03821691602082602481865afa9182156104155784926103dd575b50803b156103ce5760405163a9059cbb60e01b602082019081526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001660248301526044820184905285928392909190839061034881606481015b03601f198101835282611044565b51925af1610354611370565b90156103c65780519081159182156103ac575b50501561039d576040519081527f2ae72b44f59d038340fca5739135a1d51fc5ab720bb02d983e4c5ff4119ca7b860203392a380f35b630bc11c3f60e21b8352600483fd5b6103bf9250602080918301019101611358565b5f80610367565b602081519101fd5b633c11a9c560e21b8452600484fd5b9091506020813d60201161040d575b816103f960209383611044565b810103126104095751905f6102d8565b5f80fd5b3d91506103ec565b6040513d86823e3d90fd5b50346101a157806003193601126101a15760209054604051908152f35b503461040957366003190161010081126104095760a0136104095760405161046481611028565b61046c61107c565b8152602435906001600160a01b038216820361040957602081019182526044359182151583036104095760408201928352606082019160643583526084356080820190808252606060a3193601126104095742116107e05783515f54905f1982146107cc57600182015f55036107bd5760405160208101917f81d0284fb0e2cde18d0553b06189d6f7613c96a01bb5b5e7828eade6a0dcac9183526001600160a01b0384511660408301526001600160a01b038551166060830152865115156080830152855160a08301525160c082015260c0815261054c60e082611044565b51902060405160208101907f47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218825246604082015230606082015260608152610595608082611044565b5190209060405190602082019261190160f01b845260228301526042820152604281526105c3606282611044565b51902060a4359060ff82168092036104095760805f916020936040519182528482015260c435604082015260e435606082015282805260015afa1561073b576001600160a01b035f511680151591826107a9575b5081610776575b5015610767576106af91516040519081527fbae999fc435f6200224444d8535f1936f9abd69060fcaec680f690f1810ae36a60203392a280516040516332f256cf60e11b81523060048201526001600160a01b0391821660248201527f0000000000000000000000000000000000000000000000000000000000000000909116939092602090849081906044820190565b0381875afa92831561073b575f93610746575b5051151580921515036106d3578380f35b516001600160a01b031690823b15610409576040516207767560ed1b81526001600160a01b0392909216600483015215156024820152905f908290604490829084905af1801561073b57610728575b80808380f35b61073491505f90611044565b5f5f610722565b6040513d5f823e3d90fd5b61076091935060203d6020116101dc576101ce8183611044565b915f6106c2565b638baa579f60e01b5f5260045ffd5b90506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016145f61061e565b516001600160a01b0316811491505f610617565b633ab3447f60e11b5f5260045ffd5b634e487b7160e01b5f52601160045260245ffd5b630f05f5bf60e01b5f5260045ffd5b346104095760803660031901126104095760243567ffffffffffffffff8111610409576108209036906004016110a6565b50610829611066565b5060643567ffffffffffffffff81116104095761084d61085c91369060040161122a565b60208082518301019101611284565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169060a0812060405190632e3071cd60e11b8252600482015260c081602481865afa90811561073b575f91610ca8575b50608081016108ce6001600160801b038251164261134b565b9081151580610c92575b80610c7c575b610a82575b50506001600160801b03815116906001600160801b03604081602084015116920151169060a08420604051906349e2903160e11b82526004820152306024820152606081604481895afa90811561073b575f916109f9575b505160018401928385116107cc57620f424083018093116107cc576109766001600160a01b039361097160209661097c956113cc565b611470565b9461134b565b935116936024604051809681936370a0823160e01b835260048301525afa91821561073b575f926109c4575b6020935081811090821802186040519181811090821802188152f35b91506020833d6020116109f1575b816109df60209383611044565b810103126104095760209251916109a8565b3d91506109d2565b90506060813d606011610a7a575b81610a1460609383611044565b8101031261040957604051906060820182811067ffffffffffffffff821117610a6657610a5b91604091825280518452610a5060208201611337565b602085015201611337565b60408201528661093b565b634e487b7160e01b5f52604160045260245ffd5b3d9150610a07565b6060840151604051638c00bf6b60e01b8152906001600160a01b0316610aab60048301876112e6565b6001600160801b0385511660a483015260208501936001600160801b0385511660c48401526001600160801b0360408701948186511660e48601528160608901511661010486015251166101248401526020836101648160a08a01956001600160801b038751166101448301525afa92831561073b575f93610c46575b50610b8b6001600160801b0393610b85610b4f670de0b6b3a76400009487895116936113cc565b610b80671bc16d674ec80000610b6583806113cc565b046729a2241af62c0000610b7984836113cc565b04926113bf565b6113bf565b906113cc565b049282610ba3610b9a866113df565b8284511661139f565b16905281610bbc610bb3856113df565b8288511661139f565b16855251169081610bce575b506108e3565b670de0b6b3a764000091610be1916113cc565b04610bf6816001600160801b0385511661134b565b6001600160801b0383511691620f424083018093116107cc57600182018092116107cc57610c36610c3b926109716001600160801b0395610b9a946113cc565b6113df565b169052838080610bc8565b92506020833d602011610c74575b81610c6160209383611044565b8101031261040957915191610b8b610b28565b3d9150610c54565b506001600160a01b0360608501511615156108de565b506001600160801b0360408401511615156108d8565b905060c0813d60c011610d50575b81610cc360c09383611044565b81010312610409576040519060c0820182811067ffffffffffffffff821117610a6657610d459160a091604052610cf981611337565b8452610d0760208201611337565b6020850152610d1860408201611337565b6040850152610d2960608201611337565b6060850152610d3a60808201611337565b608085015201611337565b60a0820152836108b5565b3d9150610cb6565b346104095760e03660031901126104095760243567ffffffffffffffff811161040957610d899036906004016110a6565b60443560a435916001600160a01b0383168093036104095760c43567ffffffffffffffff811161040957610dc190369060040161122a565b7f0000000000000000000000000000000000000000000000000000000000000000936001600160a01b0385163303610fd8576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001603610fc95780602080610e3593518301019101611284565b60406001600160a01b038251169201916001600160a01b0383511603610fba5782610f17575b505160405163095ea7b360e01b602082019081526001600160a01b03948516602483015260448201939093525f938493921691908390610e9e816064810161033a565b51925af1610eaa611370565b90156103c6578051908115918215610efd575b505015610eee5760206040517f7f87788ea698181ea4d28d1576d0ba4fc92c0dbe5bf75b43692af2ce91dbaea28152f35b631f55ddd960e21b5f5260045ffd5b610f109250602080918301019101611358565b8180610ebd565b604051635c2bea4960e01b815290610f339060048301906112e6565b8260a48201525f60c48201523060e482015230610104820152604081610124815f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165af1801561073b5715610e5b57604090819392933d8311610fb3575b610fa48183611044565b81010312610409579083610e5b565b503d610f9a565b63effb039160e01b5f5260045ffd5b631ec6e83760e21b5f5260045ffd5b631e6a35c760e01b5f5260045ffd5b34610409575f366003190112610409576020906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b60a0810190811067ffffffffffffffff821117610a6657604052565b90601f8019910116810190811067ffffffffffffffff821117610a6657604052565b604435906001600160a01b038216820361040957565b600435906001600160a01b038216820361040957565b35906001600160a01b038216820361040957565b919091610100818403126104095760405190610100820182811067ffffffffffffffff821117610a66576040528193813583526110e560208301611092565b60208401526110f660408301611092565b6040840152606082013567ffffffffffffffff811161040957820181601f820112156104095780359067ffffffffffffffff8211610a66576040519261114260208460051b0185611044565b82845260208085019360071b8301019181831161040957602001925b8284106111a6575050505060e080926111a19260608601526080810135608086015260a081013560a086015261119660c08201611092565b60c086015201611092565b910152565b6080848303126104095760405190608082019082821067ffffffffffffffff831117610a66576080926020926040526111de87611092565b81528287013583820152604087013560408201526111fe60608801611092565b606082015281520193019261115e565b67ffffffffffffffff8111610a6657601f01601f191660200190565b81601f82011215610409578035906112418261120e565b9261124f6040519485611044565b8284526020838301011161040957815f926020809301838601378301015290565b51906001600160a01b038216820361040957565b908160a09103126104095760806040519161129e83611028565b6112a781611270565b83526112b560208201611270565b60208401526112c660408201611270565b60408401526112d760608201611270565b60608401520151608082015290565b608080916001600160a01b0381511684526001600160a01b0360208201511660208501526001600160a01b0360408201511660408501526001600160a01b0360608201511660608501520151910152565b51906001600160801b038216820361040957565b919082039182116107cc57565b90816020910312610409575180151581036104095790565b3d1561139a573d906113818261120e565b9161138f6040519384611044565b82523d5f602084013e565b606090565b906001600160801b03809116911601906001600160801b0382116107cc57565b919082018092116107cc57565b818102929181159184041417156107cc57565b6040516113ed604082611044565b6014815260208101907f6d61782075696e7431323820657863656564656400000000000000000000000082526001600160801b0383116114355750506001600160801b031690565b60449060405192839162461bcd60e51b8352602060048401525180918160248501528484015e5f828201840152601f01601f19168101030190fd5b811561147a570490565b634e487b7160e01b5f52601260045260245ffdfea164736f6c6343000822000a";
9
+ /**
10
+ * Computes the CREATE2 address of `owner`'s `BlueBuyCallback` for `salt`, as deployed or
11
+ * returned by the chain's `midnightBlueBuyCallbackFactory.createBlueBuyCallback(owner, salt)`.
12
+ *
13
+ * Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`.
14
+ *
15
+ * @param params.chainId - Chain whose `midnightBlueBuyCallbackFactory`, `midnight` and `blue` are used.
16
+ * @param params.owner - Callback owner, the maker.
17
+ * @param params.salt - Callback salt.
18
+ * @returns The callback address, whether or not it is deployed yet.
19
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
20
+ * @throws {UnknownAddressError} when the chain has no `midnightBlueBuyCallbackFactory`, `midnight` or `blue` deployment.
21
+ * @example
22
+ * ```ts
23
+ * import { getMidnightBlueBuyCallbackAddress } from "@morpho-org/morpho-sdk";
24
+ * import { ChainId } from "@morpho-org/morpho-ts";
25
+ * import { keccak256, toHex } from "viem";
26
+ * import type { Address } from "viem";
27
+ *
28
+ * const callbackFor = (maker: Address) =>
29
+ * getMidnightBlueBuyCallbackAddress({
30
+ * chainId: ChainId.EthMainnet,
31
+ * owner: maker,
32
+ * salt: keccak256(toHex("my-strategy")),
33
+ * });
34
+ * // `callbackFor(maker)` returns the maker's BlueBuyCallback address, deployed or not.
35
+ * ```
36
+ */
37
+ export const getMidnightBlueBuyCallbackAddress = ({ chainId, owner, salt, }) => getContractAddress({
38
+ opcode: "CREATE2",
39
+ from: getChainAddress(chainId, "midnightBlueBuyCallbackFactory"),
40
+ salt,
41
+ bytecode: concatHex([
42
+ blueBuyCallbackBytecode,
43
+ encodeAbiParameters([{ type: "address" }, { type: "address" }, { type: "address" }], [
44
+ owner,
45
+ getChainAddress(chainId, "midnight"),
46
+ getChainAddress(chainId, "blue"),
47
+ ]),
48
+ ]),
49
+ });
50
+ /**
51
+ * Returns the `callbackData` every `supplyBlueMakeLend` offer must carry: `abi.encode(blueMarket)`.
52
+ *
53
+ * @param blueMarket - Morpho Blue market encoded as the callback data.
54
+ * @returns The ABI-encoded Morpho Blue market parameters.
55
+ * @example
56
+ * ```ts
57
+ * import { getMidnightBlueBuyCallbackData } from "@morpho-org/morpho-sdk";
58
+ * import type { InputMarketParams as MarketParams } from "@morpho-org/blue-sdk";
59
+ * import type { Hex } from "viem";
60
+ *
61
+ * function getCallbackData(blueMarket: MarketParams) {
62
+ * const callbackData = getMidnightBlueBuyCallbackData(blueMarket);
63
+ * // callbackData satisfies Hex
64
+ * return callbackData;
65
+ * }
66
+ * ```
67
+ */
68
+ export const getMidnightBlueBuyCallbackData = (blueMarket) => encodeAbiParameters([marketParamsAbi], [blueMarket]);
@@ -1,4 +1,6 @@
1
1
  import { type Address } from "viem";
2
+ /** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
3
+ export declare const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
2
4
  /** Maximum slippage tolerance: 10% */
3
5
  export declare const MAX_SLIPPAGE_TOLERANCE: bigint;
4
6
  /** Default maximum Vault V2 reallocation penalty: zero. */
@@ -1,6 +1,8 @@
1
1
  import { ChainId, MathLib } from "@morpho-org/blue-sdk";
2
2
  import { Time } from "@morpho-org/morpho-ts";
3
3
  import { maxUint96 } from "viem";
4
+ /** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
5
+ export const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
4
6
  /** Maximum slippage tolerance: 10% */
5
7
  export const MAX_SLIPPAGE_TOLERANCE = MathLib.WAD / 10n;
6
8
  /** Default maximum Vault V2 reallocation penalty: zero. */
@@ -1,11 +1,12 @@
1
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
1
+ export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./constant.js";
2
3
  export { addTransactionMetadata } from "./metadata.js";
3
4
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
4
5
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
5
6
  export { grossFromNetAssets } from "./referralFee.js";
6
7
  export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
7
8
  export { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
8
- export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
+ export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateMidnightNativeAmount, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
10
  export { validateOfferSides } from "./validateOfferSides.js";
10
11
  export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
11
12
  export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
@@ -1,11 +1,12 @@
1
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
1
+ export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./constant.js";
2
3
  export { addTransactionMetadata } from "./metadata.js";
3
4
  export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
4
5
  export { previewVaultV2InKindRedeem, } from "./previewVaultV2InKindRedeem.js";
5
6
  export { grossFromNetAssets } from "./referralFee.js";
6
7
  export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
7
8
  export { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
8
- export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
+ export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateMidnightNativeAmount, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
10
  export { validateOfferSides } from "./validateOfferSides.js";
10
11
  export { validateRequirementSpender, } from "./validateRequirementSpender.js";
11
12
  export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
@@ -4,7 +4,7 @@ import type { Address, Hex, TypedDataDefinition, WalletClient } from "viem";
4
4
  * `userAddress`, and returns the signature.
5
5
  *
6
6
  * Use inside requirement `sign(...)` callbacks before converting a signature
7
- * into protocol calldata or mempool payload bytes. The verification step keeps
7
+ * into protocol calldata. The verification step keeps
8
8
  * wallet/account mismatches from reaching transaction builders.
9
9
  *
10
10
  * @param params - Signing and verification parameters.
@@ -22,8 +22,8 @@ import type { Address, Hex, TypedDataDefinition, WalletClient } from "viem";
22
22
  *
23
23
  * const signature = await signAndVerifyTypedData({
24
24
  * client: walletClient,
25
- * userAddress: maker,
26
- * typedData: offerRootTypedData,
25
+ * userAddress: user,
26
+ * typedData: permitTypedData,
27
27
  * });
28
28
  * ```
29
29
  */
@@ -7,7 +7,7 @@ import { validateChainId, validateUserAddress } from "./validate.js";
7
7
  * `userAddress`, and returns the signature.
8
8
  *
9
9
  * Use inside requirement `sign(...)` callbacks before converting a signature
10
- * into protocol calldata or mempool payload bytes. The verification step keeps
10
+ * into protocol calldata. The verification step keeps
11
11
  * wallet/account mismatches from reaching transaction builders.
12
12
  *
13
13
  * @param params - Signing and verification parameters.
@@ -25,8 +25,8 @@ import { validateChainId, validateUserAddress } from "./validate.js";
25
25
  *
26
26
  * const signature = await signAndVerifyTypedData({
27
27
  * client: walletClient,
28
- * userAddress: maker,
29
- * typedData: offerRootTypedData,
28
+ * userAddress: user,
29
+ * typedData: permitTypedData,
30
30
  * });
31
31
  * ```
32
32
  */
@@ -70,8 +70,7 @@ export declare const validateMidnightMarketChainId: (market: MidnightMarketInput
70
70
  * the provided user address.
71
71
  *
72
72
  * Used at `sign()` time by the shared `signAndVerifyTypedData` helper (which
73
- * backs the permit, Permit2, Blue authorization, and Midnight offer-root
74
- * signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
73
+ * backs the permit, Permit2, and Blue authorization signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
75
74
  * signer: the signing flow is
76
75
  * the only path where an account/address mismatch is a real security concern
77
76
  * (rather than just an integrator footgun).
@@ -163,6 +162,48 @@ export declare const validateChainId: (clientChainId: number | undefined, expect
163
162
  * @throws {NativeAmountOnNonWNativeAssetError} if the asset is not wNative.
164
163
  */
165
164
  export declare const validateNativeAsset: (chainId: number, asset: Address) => void;
165
+ /**
166
+ * Validates native ETH funding against the wNative tokens pulled by a MidnightBundlesV2 action.
167
+ *
168
+ * @param params.chainId - Chain used to resolve wNative.
169
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
170
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
171
+ * maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
172
+ * the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
173
+ * for the full pulled amount.
174
+ * @param params.pulls - Token pulls performed by the bundle action.
175
+ * @returns The transaction `value` and the `wrappedNative` contract argument.
176
+ * @throws {NegativeInputError} when `nativeAmount` is negative.
177
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
178
+ * @throws {NativeAmountOnNonWNativeAssetError} when pulls are non-empty and none use wNative.
179
+ * @throws {InputExceedsMaxError} when `nativeAmount` exceeds the maximum wNative pull, including
180
+ * when the call pulls none.
181
+ * @example
182
+ * ```ts
183
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
184
+ * import { validateMidnightNativeAmount } from "@morpho-org/morpho-sdk";
185
+ *
186
+ * const wNative = getChainAddress(8453, "wNative");
187
+ * const funding = validateMidnightNativeAmount({
188
+ * chainId: 8453,
189
+ * nativeAmount: 1_000n,
190
+ * pulls: [{ token: wNative, assets: 2_000n }],
191
+ * });
192
+ * funding.value; // 1_000n
193
+ * funding.wrappedNative; // wNative
194
+ * ```
195
+ */
196
+ export declare const validateMidnightNativeAmount: (params: {
197
+ readonly chainId: number;
198
+ readonly nativeAmount?: bigint;
199
+ readonly pulls: readonly {
200
+ readonly token: Address;
201
+ readonly assets: bigint;
202
+ }[];
203
+ }) => {
204
+ value: bigint;
205
+ wrappedNative: Address;
206
+ };
166
207
  /** @internal Validates native funding against a vault's wrapped-native asset. */
167
208
  export declare const validateNativeVaultAsset: (chainId: number, vaultAsset: Address) => void;
168
209
  /**