@morpho-org/morpho-sdk 9.7.0 → 10.0.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 (185) hide show
  1. package/MIGRATION-v9-to-v10.md +114 -0
  2. package/README.md +5 -1
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +5 -1
  5. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
  7. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
  8. package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
  9. package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
  10. package/lib/cjs/actions/midnight/cancelOffers.js +107 -0
  11. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  12. package/lib/cjs/actions/midnight/index.js +1 -0
  13. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  14. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
  15. package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
  16. package/lib/cjs/actions/midnight/takeBorrow.js +1 -1
  17. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
  18. package/lib/cjs/actions/midnight/takeLend.js +1 -1
  19. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  20. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
  21. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
  22. package/lib/cjs/actions/midnight/takeWithdraw.js +1 -1
  23. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  25. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  26. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
  31. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  32. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  33. package/lib/cjs/blue/abis.d.ts +1 -1
  34. package/lib/cjs/blue/abis.js +5 -1
  35. package/lib/cjs/blue/entities.d.ts +4 -4
  36. package/lib/cjs/blue/entities.js +3 -1
  37. package/lib/cjs/blue/errors.d.ts +2 -2
  38. package/lib/cjs/blue/errors.js +5 -1
  39. package/lib/cjs/blue/fetch.d.ts +2 -2
  40. package/lib/cjs/blue/fetch.js +3 -1
  41. package/lib/cjs/blue/utils.d.ts +1 -1
  42. package/lib/cjs/blue/utils.js +2 -1
  43. package/lib/cjs/entities/blue/blue.d.ts +34 -28
  44. package/lib/cjs/entities/blue/blue.js +99 -73
  45. package/lib/cjs/entities/index.d.ts +4 -4
  46. package/lib/cjs/entities/index.js +3 -1
  47. package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
  48. package/lib/cjs/entities/midnight/deadline.js +2 -2
  49. package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
  50. package/lib/cjs/entities/midnight/midnight.js +144 -131
  51. package/lib/cjs/entities/midnight/publication.d.ts +2 -0
  52. package/lib/cjs/entities/midnight/publication.js +126 -100
  53. package/lib/cjs/entities/midnight/types.d.ts +4 -4
  54. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  55. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +17 -17
  56. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
  57. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
  58. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
  59. package/lib/cjs/entities/vaultV1/vaultV1.js +83 -57
  60. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +50 -24
  61. package/lib/cjs/entities/vaultV2/vaultV2.js +166 -90
  62. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +17 -2
  63. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1410 -806
  64. package/lib/cjs/errors.d.ts +4 -4
  65. package/lib/cjs/errors.js +7 -5
  66. package/lib/cjs/fetch.d.ts +2 -2
  67. package/lib/cjs/fetch.js +3 -1
  68. package/lib/cjs/helpers/deadShares.js +55 -34
  69. package/lib/cjs/helpers/metadata.d.ts +14 -2
  70. package/lib/cjs/helpers/metadata.js +39 -4
  71. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +34 -22
  72. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +7 -1
  73. package/lib/cjs/helpers/validate.js +76 -61
  74. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +154 -103
  75. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +31 -20
  76. package/lib/cjs/index.d.ts +1 -0
  77. package/lib/cjs/index.js +3 -1
  78. package/lib/cjs/midnight/errors.d.ts +2 -1
  79. package/lib/cjs/midnight/errors.js +5 -4
  80. package/lib/cjs/transactionPlan/plan.js +6 -3
  81. package/lib/cjs/transactionPlan/serde.js +7 -7
  82. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +6 -4
  83. package/lib/cjs/transactionPlan/vaultv2/deposit.js +5 -3
  84. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +6 -4
  85. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +5 -3
  86. package/lib/cjs/types/action.d.ts +26 -2
  87. package/lib/cjs/types/action.js +1 -1
  88. package/lib/cjs/types/error.js +11 -5
  89. package/lib/cjs/types/metadata.d.ts +12 -2
  90. package/lib/cjs/utils.d.ts +2 -2
  91. package/lib/cjs/utils.js +4 -2
  92. package/lib/cjs/version.d.ts +2 -0
  93. package/lib/cjs/version.js +6 -0
  94. package/lib/esm/abis.d.ts +1 -1
  95. package/lib/esm/abis.js +1 -1
  96. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  97. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
  98. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
  99. package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
  100. package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
  101. package/lib/esm/actions/midnight/cancelOffers.js +103 -0
  102. package/lib/esm/actions/midnight/index.d.ts +1 -0
  103. package/lib/esm/actions/midnight/index.js +1 -0
  104. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  105. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
  106. package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
  107. package/lib/esm/actions/midnight/takeBorrow.js +1 -1
  108. package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
  109. package/lib/esm/actions/midnight/takeLend.js +1 -1
  110. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  111. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
  112. package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
  113. package/lib/esm/actions/midnight/takeWithdraw.js +1 -1
  114. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  115. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  116. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  117. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  118. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  119. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
  120. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  121. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
  122. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  123. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  124. package/lib/esm/blue/abis.d.ts +1 -1
  125. package/lib/esm/blue/abis.js +1 -1
  126. package/lib/esm/blue/entities.d.ts +4 -4
  127. package/lib/esm/blue/entities.js +2 -2
  128. package/lib/esm/blue/errors.d.ts +2 -2
  129. package/lib/esm/blue/errors.js +2 -2
  130. package/lib/esm/blue/fetch.d.ts +2 -2
  131. package/lib/esm/blue/fetch.js +2 -2
  132. package/lib/esm/blue/utils.d.ts +1 -1
  133. package/lib/esm/blue/utils.js +1 -1
  134. package/lib/esm/entities/blue/blue.d.ts +34 -28
  135. package/lib/esm/entities/blue/blue.js +99 -73
  136. package/lib/esm/entities/index.d.ts +4 -4
  137. package/lib/esm/entities/index.js +2 -2
  138. package/lib/esm/entities/midnight/deadline.d.ts +2 -2
  139. package/lib/esm/entities/midnight/deadline.js +2 -2
  140. package/lib/esm/entities/midnight/midnight.d.ts +49 -51
  141. package/lib/esm/entities/midnight/midnight.js +145 -132
  142. package/lib/esm/entities/midnight/publication.d.ts +2 -0
  143. package/lib/esm/entities/midnight/publication.js +126 -100
  144. package/lib/esm/entities/midnight/types.d.ts +4 -4
  145. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  146. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +17 -17
  147. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
  148. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
  149. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
  150. package/lib/esm/entities/vaultV1/vaultV1.js +83 -57
  151. package/lib/esm/entities/vaultV2/vaultV2.d.ts +50 -24
  152. package/lib/esm/entities/vaultV2/vaultV2.js +166 -90
  153. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +17 -2
  154. package/lib/esm/entities/vaultV2BlueReallocationData.js +1410 -806
  155. package/lib/esm/errors.d.ts +4 -4
  156. package/lib/esm/errors.js +4 -4
  157. package/lib/esm/fetch.d.ts +2 -2
  158. package/lib/esm/fetch.js +2 -2
  159. package/lib/esm/helpers/deadShares.js +56 -35
  160. package/lib/esm/helpers/metadata.d.ts +14 -2
  161. package/lib/esm/helpers/metadata.js +38 -4
  162. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +34 -22
  163. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +7 -1
  164. package/lib/esm/helpers/validate.js +76 -61
  165. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +153 -102
  166. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +31 -20
  167. package/lib/esm/index.d.ts +1 -0
  168. package/lib/esm/index.js +1 -0
  169. package/lib/esm/midnight/errors.d.ts +2 -1
  170. package/lib/esm/midnight/errors.js +2 -1
  171. package/lib/esm/transactionPlan/plan.js +6 -3
  172. package/lib/esm/transactionPlan/serde.js +7 -7
  173. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +6 -4
  174. package/lib/esm/transactionPlan/vaultv2/deposit.js +5 -3
  175. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +6 -4
  176. package/lib/esm/transactionPlan/vaultv2/withdraw.js +5 -3
  177. package/lib/esm/types/action.d.ts +26 -2
  178. package/lib/esm/types/action.js +1 -1
  179. package/lib/esm/types/error.js +11 -5
  180. package/lib/esm/types/metadata.d.ts +12 -2
  181. package/lib/esm/utils.d.ts +2 -2
  182. package/lib/esm/utils.js +2 -2
  183. package/lib/esm/version.d.ts +2 -0
  184. package/lib/esm/version.js +3 -0
  185. package/package.json +8 -7
@@ -1,7 +1,7 @@
1
1
  import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { type Address } from "viem";
3
3
  import type { FetchParameters } from "../../types/data.js";
4
- import { type ActionOutput, type ActionRequirement, type AssetsOrSharesArgs, type BlueBorrowAction, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawBuyCallbackAction, type BlueWithdrawCollateralAction, type MorphoClientType, type RequirementSignature, type VaultV2BluePublicAllocatorOptions, type VaultV2BlueReallocation } from "../../types/index.js";
4
+ import { type ActionOutput, type ActionRequirement, type AssetsOrSharesArgs, type BlueBorrowAction, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawBuyCallbackAction, type BlueWithdrawCollateralAction, type MorphoClientType, type ReferenceTimestampParams, type RequirementSignature, type VaultV2BluePublicAllocatorOptions, type VaultV2BlueReallocation } from "../../types/index.js";
5
5
  import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
6
6
  type VaultV2BlueReallocationsParams = {
7
7
  readonly reallocationData: VaultV2BlueReallocationData;
@@ -138,7 +138,7 @@ export interface BlueActions {
138
138
  readonly deadline: bigint;
139
139
  readonly referralFeePct?: bigint;
140
140
  readonly referralFeeRecipient?: Address;
141
- }) => ActionOutput<BlueSupplyCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
141
+ } & ReferenceTimestampParams) => ActionOutput<BlueSupplyCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
142
142
  /**
143
143
  * Prepares a direct BlueBundlesV1 loan-asset supply.
144
144
  *
@@ -202,7 +202,8 @@ export interface BlueActions {
202
202
  * userAddress,
203
203
  * marketData: await market.getMarketData(),
204
204
  * assets: 1_000_000n,
205
- * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
205
+ * now: (await client.getBlock()).timestamp,
206
+ * deadline: (await client.getBlock()).timestamp + 3_600n,
206
207
  * });
207
208
  * const requirements = await action.getRequirements();
208
209
  * const tx = action.buildTx();
@@ -218,7 +219,7 @@ export interface BlueActions {
218
219
  readonly deadline: bigint;
219
220
  readonly referralFeePct?: bigint;
220
221
  readonly referralFeeRecipient?: Address;
221
- }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
222
+ } & ReferenceTimestampParams): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
222
223
  /**
223
224
  * @deprecated Pass `marketData` from `getMarketData()`; the snapshot-free overload is removed in the next major.
224
225
  */
@@ -229,7 +230,7 @@ export interface BlueActions {
229
230
  readonly deadline: bigint;
230
231
  readonly referralFeePct?: bigint;
231
232
  readonly referralFeeRecipient?: Address;
232
- }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
233
+ } & ReferenceTimestampParams): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
233
234
  };
234
235
  /**
235
236
  * Prepares a direct BlueBundlesV1 loan-asset withdrawal by assets or shares.
@@ -297,7 +298,8 @@ export interface BlueActions {
297
298
  * userAddress,
298
299
  * positionData,
299
300
  * shares: 1n,
300
- * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
301
+ * now: (await client.getBlock()).timestamp,
302
+ * deadline: (await client.getBlock()).timestamp + 3_600n,
301
303
  * });
302
304
  * const requirements = await action.getRequirements();
303
305
  * const tx = action.buildTx();
@@ -311,7 +313,7 @@ export interface BlueActions {
311
313
  readonly deadline: bigint;
312
314
  readonly referralFeePct?: bigint;
313
315
  readonly referralFeeRecipient?: Address;
314
- } & AssetsOrSharesArgs) => ActionOutput<BlueWithdrawAction, readonly RequirementSignature[], undefined>;
316
+ } & ReferenceTimestampParams & AssetsOrSharesArgs) => ActionOutput<BlueWithdrawAction, readonly RequirementSignature[], undefined>;
315
317
  /**
316
318
  * Prepares a direct Morpho Blue withdrawal of a BlueBuyCallback's whole supply position to its
317
319
  * owner.
@@ -381,7 +383,7 @@ export interface BlueActions {
381
383
  readonly userAddress: Address;
382
384
  readonly callbackAddress: Address;
383
385
  readonly positionData: AccrualPosition;
384
- }) => ActionOutput<BlueWithdrawBuyCallbackAction, undefined, undefined>;
386
+ } & ReferenceTimestampParams) => ActionOutput<BlueWithdrawBuyCallbackAction, undefined, undefined>;
385
387
  /**
386
388
  * Prepares a direct BlueBundlesV1 loan-asset borrow.
387
389
  *
@@ -460,7 +462,7 @@ export interface BlueActions {
460
462
  readonly deadline: bigint;
461
463
  readonly referralFeePct?: bigint;
462
464
  readonly referralFeeRecipient?: Address;
463
- }) => ActionOutput<BlueBorrowAction, readonly RequirementSignature[], undefined>;
465
+ } & ReferenceTimestampParams) => ActionOutput<BlueBorrowAction, readonly RequirementSignature[], undefined>;
464
466
  /**
465
467
  * Prepares a direct BlueBundlesV1 loan-asset repayment.
466
468
  *
@@ -545,7 +547,7 @@ export interface BlueActions {
545
547
  readonly deadline: bigint;
546
548
  readonly referralFeePct?: bigint;
547
549
  readonly referralFeeRecipient?: Address;
548
- } & ({
550
+ } & ReferenceTimestampParams & ({
549
551
  readonly repayAssets: bigint;
550
552
  readonly repayShares?: never;
551
553
  } | {
@@ -623,7 +625,7 @@ export interface BlueActions {
623
625
  readonly deadline: bigint;
624
626
  readonly referralFeePct?: bigint;
625
627
  readonly referralFeeRecipient?: Address;
626
- }) => ActionOutput<BlueWithdrawCollateralAction, readonly RequirementSignature[], undefined>;
628
+ } & ReferenceTimestampParams) => ActionOutput<BlueWithdrawCollateralAction, readonly RequirementSignature[], undefined>;
627
629
  /**
628
630
  * Prepares a direct BlueBundlesV1 repay, collateral withdrawal, or atomic combination.
629
631
  *
@@ -706,7 +708,8 @@ export interface BlueActions {
706
708
  * positionData,
707
709
  * repayShares: maxUint256,
708
710
  * collateralAssets: 1n,
709
- * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
711
+ * now: (await client.getBlock()).timestamp,
712
+ * deadline: (await client.getBlock()).timestamp + 3_600n,
710
713
  * });
711
714
  * const requirements = await action.getRequirements(); // Satisfy these first.
712
715
  * const tx = action.buildTx(); // For a client configured with supportSignature: false.
@@ -721,7 +724,7 @@ export interface BlueActions {
721
724
  readonly deadline: bigint;
722
725
  readonly referralFeePct?: bigint;
723
726
  readonly referralFeeRecipient?: Address;
724
- } & ({
727
+ } & ReferenceTimestampParams & ({
725
728
  readonly repayAssets: bigint;
726
729
  readonly repayShares?: never;
727
730
  } | {
@@ -807,7 +810,8 @@ export interface BlueActions {
807
810
  * positionData,
808
811
  * collateralAssets: 100_000_000n,
809
812
  * borrowAssets: 1_000_000n,
810
- * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
813
+ * now: (await client.getBlock()).timestamp,
814
+ * deadline: (await client.getBlock()).timestamp + 3_600n,
811
815
  * });
812
816
  * const requirements = await action.getRequirements(); // Satisfy these first.
813
817
  * const tx = action.buildTx(); // For a client configured with supportSignature: false.
@@ -824,7 +828,7 @@ export interface BlueActions {
824
828
  readonly deadline: bigint;
825
829
  readonly referralFeePct?: bigint;
826
830
  readonly referralFeeRecipient?: Address;
827
- }) => ActionOutput<BlueSupplyCollateralBorrowAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
831
+ } & ReferenceTimestampParams) => ActionOutput<BlueSupplyCollateralBorrowAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
828
832
  /**
829
833
  * Prepares a direct BlueBundlesV1 full borrow-position migration.
830
834
  *
@@ -903,7 +907,8 @@ export interface BlueActions {
903
907
  * userAddress,
904
908
  * positionData: source,
905
909
  * destination: { marketParams: destinationParams, positionData: destination },
906
- * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
910
+ * now: (await client.getBlock()).timestamp,
911
+ * deadline: (await client.getBlock()).timestamp + 3_600n,
907
912
  * });
908
913
  * const requirements = await action.getRequirements(); // Satisfy these first.
909
914
  * const tx = action.buildTx(); // For a client configured with supportSignature: false.
@@ -921,7 +926,7 @@ export interface BlueActions {
921
926
  readonly deadline: bigint;
922
927
  readonly referralFeePct?: bigint;
923
928
  readonly referralFeeRecipient?: Address;
924
- }) => ActionOutput<BlueRefinanceAction, readonly RequirementSignature[], undefined>;
929
+ } & ReferenceTimestampParams) => ActionOutput<BlueRefinanceAction, readonly RequirementSignature[], undefined>;
925
930
  /**
926
931
  * Fetches Vault V2 BluePublicAllocator state for this target market.
927
932
  *
@@ -1044,6 +1049,7 @@ export declare class MorphoBlue implements BlueActions {
1044
1049
  private assertWriteTargets;
1045
1050
  private getMaxLtv;
1046
1051
  private getBlueBundlesV1QuoteTimestamp;
1052
+ private quoteRepay;
1047
1053
  private getTokenRequirements;
1048
1054
  private getAuthorizationRequirements;
1049
1055
  getMarketData(parameters?: FetchParameters): Promise<Market>;
@@ -1057,7 +1063,7 @@ export declare class MorphoBlue implements BlueActions {
1057
1063
  readonly deadline: bigint;
1058
1064
  readonly referralFeePct?: bigint;
1059
1065
  readonly referralFeeRecipient?: Address;
1060
- }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
1066
+ } & ReferenceTimestampParams): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
1061
1067
  /**
1062
1068
  * @deprecated Pass `marketData` from `getMarketData()`; the snapshot-free overload is removed in the next major.
1063
1069
  */
@@ -1068,7 +1074,7 @@ export declare class MorphoBlue implements BlueActions {
1068
1074
  readonly deadline: bigint;
1069
1075
  readonly referralFeePct?: bigint;
1070
1076
  readonly referralFeeRecipient?: Address;
1071
- }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
1077
+ } & ReferenceTimestampParams): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
1072
1078
  /** {@inheritDoc BlueActions.withdraw} */
1073
1079
  withdraw(params: {
1074
1080
  readonly userAddress: Address;
@@ -1077,7 +1083,7 @@ export declare class MorphoBlue implements BlueActions {
1077
1083
  readonly deadline: bigint;
1078
1084
  readonly referralFeePct?: bigint;
1079
1085
  readonly referralFeeRecipient?: Address;
1080
- } & AssetsOrSharesArgs): {
1086
+ } & ReferenceTimestampParams & AssetsOrSharesArgs): {
1081
1087
  getRequirements: () => Promise<readonly ActionRequirement[]>;
1082
1088
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueWithdrawAction>>;
1083
1089
  };
@@ -1086,7 +1092,7 @@ export declare class MorphoBlue implements BlueActions {
1086
1092
  readonly userAddress: Address;
1087
1093
  readonly callbackAddress: Address;
1088
1094
  readonly positionData: AccrualPosition;
1089
- }): ActionOutput<BlueWithdrawBuyCallbackAction, undefined, undefined>;
1095
+ } & ReferenceTimestampParams): ActionOutput<BlueWithdrawBuyCallbackAction, undefined, undefined>;
1090
1096
  /** {@inheritDoc BlueActions.supplyCollateral} */
1091
1097
  supplyCollateral(params: {
1092
1098
  readonly userAddress: Address;
@@ -1095,7 +1101,7 @@ export declare class MorphoBlue implements BlueActions {
1095
1101
  readonly deadline: bigint;
1096
1102
  readonly referralFeePct?: bigint;
1097
1103
  readonly referralFeeRecipient?: Address;
1098
- }): ActionOutput<BlueSupplyCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
1104
+ } & ReferenceTimestampParams): ActionOutput<BlueSupplyCollateralAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
1099
1105
  /** {@inheritDoc BlueActions.borrow} */
1100
1106
  borrow(params: {
1101
1107
  readonly userAddress: Address;
@@ -1105,7 +1111,7 @@ export declare class MorphoBlue implements BlueActions {
1105
1111
  readonly deadline: bigint;
1106
1112
  readonly referralFeePct?: bigint;
1107
1113
  readonly referralFeeRecipient?: Address;
1108
- }): ActionOutput<BlueBorrowAction, readonly RequirementSignature[], undefined>;
1114
+ } & ReferenceTimestampParams): ActionOutput<BlueBorrowAction, readonly RequirementSignature[], undefined>;
1109
1115
  /** {@inheritDoc BlueActions.repay} */
1110
1116
  repay(params: {
1111
1117
  readonly userAddress: Address;
@@ -1114,7 +1120,7 @@ export declare class MorphoBlue implements BlueActions {
1114
1120
  readonly deadline: bigint;
1115
1121
  readonly referralFeePct?: bigint;
1116
1122
  readonly referralFeeRecipient?: Address;
1117
- } & ({
1123
+ } & ReferenceTimestampParams & ({
1118
1124
  readonly repayAssets: bigint;
1119
1125
  readonly repayShares?: never;
1120
1126
  } | {
@@ -1129,7 +1135,7 @@ export declare class MorphoBlue implements BlueActions {
1129
1135
  readonly deadline: bigint;
1130
1136
  readonly referralFeePct?: bigint;
1131
1137
  readonly referralFeeRecipient?: Address;
1132
- }): ActionOutput<BlueWithdrawCollateralAction, readonly RequirementSignature[], undefined>;
1138
+ } & ReferenceTimestampParams): ActionOutput<BlueWithdrawCollateralAction, readonly RequirementSignature[], undefined>;
1133
1139
  /** {@inheritDoc BlueActions.repayWithdrawCollateral} */
1134
1140
  repayWithdrawCollateral(params: {
1135
1141
  readonly userAddress: Address;
@@ -1139,7 +1145,7 @@ export declare class MorphoBlue implements BlueActions {
1139
1145
  readonly deadline: bigint;
1140
1146
  readonly referralFeePct?: bigint;
1141
1147
  readonly referralFeeRecipient?: Address;
1142
- } & ({
1148
+ } & ReferenceTimestampParams & ({
1143
1149
  readonly repayAssets: bigint;
1144
1150
  readonly repayShares?: never;
1145
1151
  } | {
@@ -1163,7 +1169,7 @@ export declare class MorphoBlue implements BlueActions {
1163
1169
  readonly deadline: bigint;
1164
1170
  readonly referralFeePct?: bigint;
1165
1171
  readonly referralFeeRecipient?: Address;
1166
- }): {
1172
+ } & ReferenceTimestampParams): {
1167
1173
  getRequirements: (requirementsParams?: BlueTokenRequirementsParams) => Promise<readonly ActionRequirement[]>;
1168
1174
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueSupplyCollateralBorrowAction>>;
1169
1175
  };
@@ -1179,7 +1185,7 @@ export declare class MorphoBlue implements BlueActions {
1179
1185
  readonly deadline: bigint;
1180
1186
  readonly referralFeePct?: bigint;
1181
1187
  readonly referralFeeRecipient?: Address;
1182
- }): {
1188
+ } & ReferenceTimestampParams): {
1183
1189
  getRequirements: () => Promise<readonly ActionRequirement[]>;
1184
1190
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<BlueRefinanceAction>>;
1185
1191
  };
@@ -11,6 +11,7 @@ const common_js_1 = require("../../actions/blue/common.js");
11
11
  const index_js_1 = require("../../actions/index.js");
12
12
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
13
13
  const index_js_2 = require("../../helpers/index.js");
14
+ const metadata_js_1 = require("../../helpers/metadata.js");
14
15
  const validate_js_1 = require("../../helpers/validate.js");
15
16
  const index_js_3 = require("../../types/index.js");
16
17
  const assertContractCode_js_1 = require("../requirements/assertContractCode.js");
@@ -41,9 +42,9 @@ class MorphoBlue {
41
42
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
42
43
  }
43
44
  }
44
- validateWriteCommon(params) {
45
+ validateWriteCommon(params, now) {
45
46
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
46
- this.validateDeadline(params.deadline);
47
+ this.validateDeadline(params.deadline, now);
47
48
  // Resolve at handle creation so unsupported deployments fail before any RPC prerequisite work.
48
49
  (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.blueBundlesV1");
49
50
  // Validate the referral inputs eagerly; the normalized result is intentionally discarded here
@@ -75,8 +76,43 @@ class MorphoBlue {
75
76
  getMaxLtv(marketParams = this.marketParams) {
76
77
  return blue_sdk_1.MathLib.zeroFloorSub(marketParams.lltv, index_js_2.DEFAULT_LLTV_BUFFER);
77
78
  }
78
- getBlueBundlesV1QuoteTimestamp(lastUpdate) {
79
- return blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
79
+ getBlueBundlesV1QuoteTimestamp(lastUpdate, now = morpho_ts_1.Time.timestamp()) {
80
+ return blue_sdk_1.MathLib.max(now, lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
81
+ }
82
+ quoteRepay({ positionData, repayAssets, repayShares, deadline, now, }) {
83
+ const saturatedRepay = repayShares === viem_1.maxUint256;
84
+ const simulatedRepayShares = saturatedRepay
85
+ ? positionData.borrowShares
86
+ : repayShares;
87
+ if (repayAssets > 0n) {
88
+ (0, index_js_2.validateRepayAmount)({
89
+ positionData,
90
+ repayAssets,
91
+ marketId: this.marketParams.id,
92
+ });
93
+ }
94
+ else if (repayShares > 0n && !saturatedRepay) {
95
+ (0, index_js_2.validateRepayShares)({
96
+ positionData,
97
+ repayShares,
98
+ marketId: this.marketParams.id,
99
+ });
100
+ }
101
+ const quoteHorizon = this.getBlueBundlesV1QuoteTimestamp(positionData.market.lastUpdate, now);
102
+ if (repayShares > 0n && deadline > quoteHorizon) {
103
+ throw new index_js_3.InputExceedsMaxError({
104
+ field: "deadline",
105
+ value: deadline,
106
+ max: quoteHorizon,
107
+ });
108
+ }
109
+ const accrualTimestamp = repayShares > 0n ? deadline : quoteHorizon;
110
+ const accruedPosition = positionData.accrueInterest(accrualTimestamp);
111
+ let expectedRepayAssets = repayAssets;
112
+ if (repayAssets <= 0n && repayShares > 0n) {
113
+ expectedRepayAssets = accruedPosition.market.toBorrowAssets(simulatedRepayShares, "Up");
114
+ }
115
+ return { simulatedRepayShares, accruedPosition, expectedRepayAssets };
80
116
  }
81
117
  async getTokenRequirements(params) {
82
118
  this.validateDeadline(params.deadline, params.now);
@@ -121,8 +157,11 @@ class MorphoBlue {
121
157
  });
122
158
  }
123
159
  supply(params) {
160
+ const suppliedNow = params.now;
161
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
124
162
  const { userAddress, assets, nativeAmount, deadline, referralFeePct, referralFeeRecipient, } = params;
125
- this.validateWriteCommon(params);
163
+ const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
164
+ this.validateWriteCommon(params, createdAt);
126
165
  if (assets <= 0n)
127
166
  throw new index_js_3.NonPositiveInputError("assets", assets);
128
167
  const nativeValue = (0, common_js_1.validateBlueBundlesV1NativeFunding)({
@@ -138,7 +177,7 @@ class MorphoBlue {
138
177
  }
139
178
  return {
140
179
  getRequirements: (requirementsParams) => {
141
- const now = morpho_ts_1.Time.timestamp();
180
+ const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
142
181
  this.validateDeadline(deadline, now);
143
182
  return this.assertWriteTargets().then(() => {
144
183
  if (nativeValue > 0n)
@@ -168,15 +207,18 @@ class MorphoBlue {
168
207
  referralFeeRecipient,
169
208
  requirementSignature: token,
170
209
  },
171
- metadata: this.client.options.metadata,
210
+ metadata,
172
211
  });
173
212
  },
174
213
  };
175
214
  }
176
215
  /** {@inheritDoc BlueActions.withdraw} */
177
216
  withdraw(params) {
217
+ const suppliedNow = params.now;
218
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
178
219
  const { userAddress, positionData, deadline, referralFeePct, referralFeeRecipient, } = params;
179
- this.validateWriteCommon(params);
220
+ const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
221
+ this.validateWriteCommon(params, createdAt);
180
222
  const assets = ("assets" in params ? params.assets : undefined) ?? 0n;
181
223
  const shares = ("shares" in params ? params.shares : undefined) ?? 0n;
182
224
  if (assets < 0n)
@@ -197,20 +239,13 @@ class MorphoBlue {
197
239
  expectedMarketId: this.marketParams.id,
198
240
  expectedUser: userAddress,
199
241
  });
200
- if (shares > 0n) {
201
- (0, index_js_2.validateWithdrawShares)({
202
- positionData,
203
- withdrawShares: shares,
204
- marketId: this.marketParams.id,
205
- });
206
- }
207
- else {
208
- (0, index_js_2.validateWithdrawAmount)({
209
- positionData,
210
- withdrawAssets: assets,
211
- marketId: this.marketParams.id,
212
- });
213
- }
242
+ const validateWithdrawal = shares > 0n ? index_js_2.validateWithdrawShares : index_js_2.validateWithdrawAmount;
243
+ validateWithdrawal({
244
+ positionData,
245
+ withdrawShares: shares,
246
+ withdrawAssets: assets,
247
+ marketId: this.marketParams.id,
248
+ });
214
249
  const reallocations = [...(params.reallocations ?? [])];
215
250
  // Validate the exact PublicAllocations mapping before requirement reads.
216
251
  const publicAllocations = (0, common_js_1.getBlueBundlesV1PublicAllocations)(reallocations, this.marketParams);
@@ -225,7 +260,7 @@ class MorphoBlue {
225
260
  }
226
261
  return {
227
262
  getRequirements: async () => {
228
- const now = morpho_ts_1.Time.timestamp();
263
+ const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
229
264
  this.validateDeadline(deadline, now);
230
265
  await this.assertWriteTargets();
231
266
  return this.getAuthorizationRequirements({
@@ -250,13 +285,14 @@ class MorphoBlue {
250
285
  referralFeeRecipient,
251
286
  authorizationSignature: authorization,
252
287
  },
253
- metadata: this.client.options.metadata,
288
+ metadata,
254
289
  });
255
290
  },
256
291
  };
257
292
  }
258
293
  /** {@inheritDoc BlueActions.withdrawBuyCallback} */
259
294
  withdrawBuyCallback(params) {
295
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
260
296
  const { userAddress, callbackAddress, positionData } = params;
261
297
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
262
298
  if (positionData == null) {
@@ -288,7 +324,7 @@ class MorphoBlue {
288
324
  const tx = (0, index_js_1.blueWithdrawBuyCallback)({
289
325
  market: { chainId: this.chainId, marketParams: this.marketParams },
290
326
  args: { callbackAddress, userAddress, shares },
291
- metadata: this.client.options.metadata,
327
+ metadata,
292
328
  });
293
329
  return {
294
330
  getRequirements: async () => {
@@ -341,8 +377,10 @@ class MorphoBlue {
341
377
  }
342
378
  /** {@inheritDoc BlueActions.supplyCollateral} */
343
379
  supplyCollateral(params) {
380
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
344
381
  const { userAddress, collateralAssets, nativeAmount, deadline, referralFeePct, referralFeeRecipient, } = params;
345
382
  const combinedAction = this.supplyCollateralBorrow({
383
+ now: params.now,
346
384
  userAddress,
347
385
  collateralAssets,
348
386
  borrowAssets: 0n,
@@ -368,16 +406,18 @@ class MorphoBlue {
368
406
  referralFeeRecipient,
369
407
  requirementSignature: token,
370
408
  },
371
- metadata: this.client.options.metadata,
409
+ metadata,
372
410
  });
373
411
  },
374
412
  };
375
413
  }
376
414
  /** {@inheritDoc BlueActions.borrow} */
377
415
  borrow(params) {
416
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
378
417
  const { userAddress, borrowAssets, positionData, reallocations, deadline, referralFeePct, referralFeeRecipient, } = params;
379
418
  const normalizedReallocations = [...(reallocations ?? [])];
380
419
  const combinedAction = this.supplyCollateralBorrow({
420
+ now: params.now,
381
421
  userAddress,
382
422
  collateralAssets: 0n,
383
423
  borrowAssets,
@@ -403,13 +443,14 @@ class MorphoBlue {
403
443
  referralFeeRecipient,
404
444
  authorizationSignature: authorization,
405
445
  },
406
- metadata: this.client.options.metadata,
446
+ metadata,
407
447
  });
408
448
  },
409
449
  };
410
450
  }
411
451
  /** {@inheritDoc BlueActions.repay} */
412
452
  repay(params) {
453
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
413
454
  const combinedAction = this.repayWithdrawCollateral({
414
455
  ...params,
415
456
  collateralAssets: 0n,
@@ -435,15 +476,17 @@ class MorphoBlue {
435
476
  referralFeeRecipient,
436
477
  requirementSignature: token,
437
478
  },
438
- metadata: this.client.options.metadata,
479
+ metadata,
439
480
  });
440
481
  },
441
482
  };
442
483
  }
443
484
  /** {@inheritDoc BlueActions.withdrawCollateral} */
444
485
  withdrawCollateral(params) {
486
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
445
487
  const { userAddress, positionData, collateralAssets, deadline, referralFeePct, referralFeeRecipient, } = params;
446
488
  const combinedAction = this.repayWithdrawCollateral({
489
+ now: params.now,
447
490
  userAddress,
448
491
  positionData,
449
492
  repayAssets: 0n,
@@ -469,15 +512,18 @@ class MorphoBlue {
469
512
  referralFeeRecipient: combinedArgs.referralFeeRecipient,
470
513
  authorizationSignature: authorization,
471
514
  },
472
- metadata: this.client.options.metadata,
515
+ metadata,
473
516
  });
474
517
  },
475
518
  };
476
519
  }
477
520
  /** {@inheritDoc BlueActions.repayWithdrawCollateral} */
478
521
  repayWithdrawCollateral(params) {
522
+ const suppliedNow = params.now;
523
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
479
524
  const { userAddress, positionData, collateralAssets, nativeAmount, deadline, referralFeeRecipient, } = params;
480
- this.validateWriteCommon(params);
525
+ const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
526
+ this.validateWriteCommon(params, createdAt);
481
527
  // `validateWriteCommon` returns void, so default an omitted `referralFeePct` to `0n`
482
528
  // here, matching the pure action's normalization.
483
529
  const referralFeePct = params.referralFeePct ?? 0n;
@@ -507,39 +553,13 @@ class MorphoBlue {
507
553
  expectedMarketId: this.marketParams.id,
508
554
  expectedUser: userAddress,
509
555
  });
510
- const saturatedRepay = repayShares === viem_1.maxUint256;
511
- const simulatedRepayShares = saturatedRepay
512
- ? positionData.borrowShares
513
- : repayShares;
514
- if (repayAssets > 0n) {
515
- (0, index_js_2.validateRepayAmount)({
516
- positionData,
517
- repayAssets,
518
- marketId: this.marketParams.id,
519
- });
520
- }
521
- else if (repayShares > 0n && !saturatedRepay) {
522
- (0, index_js_2.validateRepayShares)({
523
- positionData,
524
- repayShares,
525
- marketId: this.marketParams.id,
526
- });
527
- }
528
- const quoteHorizon = this.getBlueBundlesV1QuoteTimestamp(positionData.market.lastUpdate);
529
- if (repayShares > 0n && deadline > quoteHorizon) {
530
- throw new index_js_3.InputExceedsMaxError({
531
- field: "deadline",
532
- value: deadline,
533
- max: quoteHorizon,
534
- });
535
- }
536
- const accrualTimestamp = repayShares > 0n ? deadline : quoteHorizon;
537
- const accruedPosition = positionData.accrueInterest(accrualTimestamp);
538
- const expectedRepayAssets = repayAssets > 0n
539
- ? repayAssets
540
- : hasRepay
541
- ? accruedPosition.market.toBorrowAssets(simulatedRepayShares, "Up")
542
- : 0n;
556
+ const { simulatedRepayShares, accruedPosition, expectedRepayAssets } = this.quoteRepay({
557
+ positionData,
558
+ repayAssets,
559
+ repayShares,
560
+ deadline,
561
+ now: createdAt,
562
+ });
543
563
  const referralFeeAssets = (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(expectedRepayAssets, referralFeePct);
544
564
  const maxRepayAssets = expectedRepayAssets + referralFeeAssets;
545
565
  const nativeValue = (0, common_js_1.validateBlueBundlesV1NativeFunding)({
@@ -561,7 +581,7 @@ class MorphoBlue {
561
581
  }
562
582
  return {
563
583
  getRequirements: async (requirementsParams) => {
564
- const now = morpho_ts_1.Time.timestamp();
584
+ const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
565
585
  this.validateDeadline(deadline, now);
566
586
  await this.assertWriteTargets();
567
587
  const [tokenRequirements, authorizationRequirements] = await Promise.all([
@@ -612,15 +632,18 @@ class MorphoBlue {
612
632
  requirementSignature: token,
613
633
  authorizationSignature: authorization,
614
634
  },
615
- metadata: this.client.options.metadata,
635
+ metadata,
616
636
  });
617
637
  },
618
638
  };
619
639
  }
620
640
  /** {@inheritDoc BlueActions.supplyCollateralBorrow} */
621
641
  supplyCollateralBorrow(params) {
642
+ const suppliedNow = params.now;
643
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
622
644
  const { userAddress, collateralAssets, borrowAssets, positionData, nativeAmount, deadline, referralFeePct, referralFeeRecipient, } = params;
623
- this.validateWriteCommon(params);
645
+ const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
646
+ this.validateWriteCommon(params, createdAt);
624
647
  if (collateralAssets < 0n) {
625
648
  throw new index_js_3.NegativeInputError("collateralAssets", collateralAssets);
626
649
  }
@@ -654,7 +677,7 @@ class MorphoBlue {
654
677
  expectedUser: userAddress,
655
678
  });
656
679
  (0, index_js_2.validatePositionHealth)({
657
- positionData: positionData.accrueInterest(this.getBlueBundlesV1QuoteTimestamp(positionData.market.lastUpdate)),
680
+ positionData: positionData.accrueInterest(this.getBlueBundlesV1QuoteTimestamp(positionData.market.lastUpdate, createdAt)),
658
681
  additionalCollateral: collateralAssets,
659
682
  borrowAmount: borrowAssets,
660
683
  marketId: this.marketParams.id,
@@ -669,7 +692,7 @@ class MorphoBlue {
669
692
  });
670
693
  return {
671
694
  getRequirements: async (requirementsParams) => {
672
- const now = morpho_ts_1.Time.timestamp();
695
+ const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
673
696
  this.validateDeadline(deadline, now);
674
697
  await this.assertWriteTargets();
675
698
  const [tokenRequirements, authorizationRequirements] = await Promise.all([
@@ -713,15 +736,18 @@ class MorphoBlue {
713
736
  requirementSignature: token,
714
737
  authorizationSignature: authorization,
715
738
  },
716
- metadata: this.client.options.metadata,
739
+ metadata,
717
740
  });
718
741
  },
719
742
  };
720
743
  }
721
744
  /** {@inheritDoc BlueActions.refinance} */
722
745
  refinance(params) {
746
+ const suppliedNow = params.now;
747
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
723
748
  const { userAddress, positionData, destination, deadline, referralFeeRecipient, } = params;
724
- this.validateWriteCommon(params);
749
+ const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
750
+ this.validateWriteCommon(params, createdAt);
725
751
  (0, validate_js_1.validateMarketParamsId)(destination.marketParams);
726
752
  // `validateWriteCommon` returns void, so default an omitted `referralFeePct` to `0n`
727
753
  // here, matching the pure action's normalization.
@@ -755,7 +781,7 @@ class MorphoBlue {
755
781
  const reallocations = [...(params.reallocations ?? [])];
756
782
  const publicAllocations = (0, common_js_1.getBlueBundlesV1PublicAllocations)(reallocations, destination.marketParams);
757
783
  const penaltyAssets = (0, common_js_1.getBlueBundlesV1PenaltyAssets)(publicAllocations);
758
- const accrualTimestamp = this.getBlueBundlesV1QuoteTimestamp(blue_sdk_1.MathLib.max(positionData.market.lastUpdate, destination.positionData.market.lastUpdate));
784
+ const accrualTimestamp = this.getBlueBundlesV1QuoteTimestamp(blue_sdk_1.MathLib.max(positionData.market.lastUpdate, destination.positionData.market.lastUpdate), createdAt);
759
785
  const accruedSourcePosition = positionData.accrueInterest(accrualTimestamp);
760
786
  const accruedDestinationPosition = destination.positionData.accrueInterest(accrualTimestamp);
761
787
  const referralFeeAssets = (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(accruedSourcePosition.borrowAssets, referralFeePct);
@@ -768,7 +794,7 @@ class MorphoBlue {
768
794
  });
769
795
  return {
770
796
  getRequirements: async () => {
771
- const now = morpho_ts_1.Time.timestamp();
797
+ const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
772
798
  this.validateDeadline(deadline, now);
773
799
  await this.assertWriteTargets();
774
800
  return this.getAuthorizationRequirements({
@@ -796,7 +822,7 @@ class MorphoBlue {
796
822
  referralFeeRecipient,
797
823
  authorizationSignature: authorization,
798
824
  },
799
- metadata: this.client.options.metadata,
825
+ metadata,
800
826
  });
801
827
  },
802
828
  };