@morpho-org/morpho-sdk 9.1.0-next.0 → 9.1.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 (126) hide show
  1. package/README.md +3 -1
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +1 -5
  4. package/lib/cjs/actions/blue/borrow.d.ts +1 -0
  5. package/lib/cjs/actions/blue/borrow.js +1 -0
  6. package/lib/cjs/actions/blue/refinance.d.ts +1 -0
  7. package/lib/cjs/actions/blue/refinance.js +3 -0
  8. package/lib/cjs/actions/blue/repay.d.ts +1 -0
  9. package/lib/cjs/actions/blue/repay.js +1 -0
  10. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  11. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -0
  12. package/lib/cjs/actions/blue/supply.d.ts +1 -0
  13. package/lib/cjs/actions/blue/supply.js +2 -0
  14. package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -0
  15. package/lib/cjs/actions/blue/supplyCollateral.js +1 -0
  16. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  17. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +2 -0
  18. package/lib/cjs/actions/blue/withdraw.d.ts +1 -0
  19. package/lib/cjs/actions/blue/withdraw.js +2 -0
  20. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -0
  21. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -0
  22. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
  23. package/lib/cjs/actions/midnight/takeLend.js +1 -0
  24. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  25. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  26. package/lib/cjs/blue/abis.d.ts +1 -1
  27. package/lib/cjs/blue/abis.js +1 -5
  28. package/lib/cjs/blue/entities.d.ts +4 -4
  29. package/lib/cjs/blue/entities.js +1 -3
  30. package/lib/cjs/blue/errors.d.ts +2 -2
  31. package/lib/cjs/blue/errors.js +2 -5
  32. package/lib/cjs/blue/fetch.d.ts +2 -2
  33. package/lib/cjs/blue/fetch.js +1 -3
  34. package/lib/cjs/blue/utils.d.ts +1 -1
  35. package/lib/cjs/blue/utils.js +1 -2
  36. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  37. package/lib/cjs/client/morphoViemExtension.js +1 -7
  38. package/lib/cjs/entities/blue/blue.d.ts +43 -7
  39. package/lib/cjs/entities/blue/blue.js +27 -3
  40. package/lib/cjs/entities/index.d.ts +4 -4
  41. package/lib/cjs/entities/index.js +1 -3
  42. package/lib/cjs/entities/midnight/midnight.d.ts +7 -5
  43. package/lib/cjs/entities/midnight/midnight.js +7 -5
  44. package/lib/cjs/entities/midnight/types.d.ts +8 -1
  45. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +12 -34
  46. package/lib/cjs/entities/vaultV2/vaultV2.js +9 -38
  47. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +43 -18
  48. package/lib/cjs/entities/vaultV2BlueReallocationData.js +210 -79
  49. package/lib/cjs/errors.d.ts +4 -4
  50. package/lib/cjs/errors.js +6 -10
  51. package/lib/cjs/fetch.d.ts +2 -2
  52. package/lib/cjs/fetch.js +1 -3
  53. package/lib/cjs/helpers/validate.d.ts +11 -1
  54. package/lib/cjs/helpers/validate.js +17 -1
  55. package/lib/cjs/helpers/validateTakeableOffers.d.ts +4 -2
  56. package/lib/cjs/helpers/validateTakeableOffers.js +12 -1
  57. package/lib/cjs/midnight/errors.d.ts +1 -2
  58. package/lib/cjs/midnight/errors.js +4 -5
  59. package/lib/cjs/types/error.d.ts +6 -0
  60. package/lib/cjs/types/error.js +9 -1
  61. package/lib/cjs/types/sharedLiquidity.d.ts +27 -11
  62. package/lib/cjs/utils.d.ts +2 -2
  63. package/lib/cjs/utils.js +2 -4
  64. package/lib/esm/abis.d.ts +1 -1
  65. package/lib/esm/abis.js +1 -1
  66. package/lib/esm/actions/blue/borrow.d.ts +1 -0
  67. package/lib/esm/actions/blue/borrow.js +1 -0
  68. package/lib/esm/actions/blue/refinance.d.ts +1 -0
  69. package/lib/esm/actions/blue/refinance.js +4 -1
  70. package/lib/esm/actions/blue/repay.d.ts +1 -0
  71. package/lib/esm/actions/blue/repay.js +1 -0
  72. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  73. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -1
  74. package/lib/esm/actions/blue/supply.d.ts +1 -0
  75. package/lib/esm/actions/blue/supply.js +3 -1
  76. package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -0
  77. package/lib/esm/actions/blue/supplyCollateral.js +1 -0
  78. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  79. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -1
  80. package/lib/esm/actions/blue/withdraw.d.ts +1 -0
  81. package/lib/esm/actions/blue/withdraw.js +3 -1
  82. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -0
  83. package/lib/esm/actions/blue/withdrawCollateral.js +1 -0
  84. package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
  85. package/lib/esm/actions/midnight/takeLend.js +1 -0
  86. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  87. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  88. package/lib/esm/blue/abis.d.ts +1 -1
  89. package/lib/esm/blue/abis.js +1 -1
  90. package/lib/esm/blue/entities.d.ts +4 -4
  91. package/lib/esm/blue/entities.js +2 -2
  92. package/lib/esm/blue/errors.d.ts +2 -2
  93. package/lib/esm/blue/errors.js +2 -2
  94. package/lib/esm/blue/fetch.d.ts +2 -2
  95. package/lib/esm/blue/fetch.js +2 -2
  96. package/lib/esm/blue/utils.d.ts +1 -1
  97. package/lib/esm/blue/utils.js +1 -1
  98. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  99. package/lib/esm/client/morphoViemExtension.js +1 -7
  100. package/lib/esm/entities/blue/blue.d.ts +43 -7
  101. package/lib/esm/entities/blue/blue.js +27 -3
  102. package/lib/esm/entities/index.d.ts +4 -4
  103. package/lib/esm/entities/index.js +2 -2
  104. package/lib/esm/entities/midnight/midnight.d.ts +7 -5
  105. package/lib/esm/entities/midnight/midnight.js +7 -5
  106. package/lib/esm/entities/midnight/types.d.ts +8 -1
  107. package/lib/esm/entities/vaultV2/vaultV2.d.ts +12 -34
  108. package/lib/esm/entities/vaultV2/vaultV2.js +10 -39
  109. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +43 -18
  110. package/lib/esm/entities/vaultV2BlueReallocationData.js +211 -80
  111. package/lib/esm/errors.d.ts +4 -4
  112. package/lib/esm/errors.js +4 -4
  113. package/lib/esm/fetch.d.ts +2 -2
  114. package/lib/esm/fetch.js +2 -2
  115. package/lib/esm/helpers/validate.d.ts +11 -1
  116. package/lib/esm/helpers/validate.js +15 -0
  117. package/lib/esm/helpers/validateTakeableOffers.d.ts +4 -2
  118. package/lib/esm/helpers/validateTakeableOffers.js +13 -2
  119. package/lib/esm/midnight/errors.d.ts +1 -2
  120. package/lib/esm/midnight/errors.js +1 -2
  121. package/lib/esm/types/error.d.ts +6 -0
  122. package/lib/esm/types/error.js +7 -0
  123. package/lib/esm/types/sharedLiquidity.d.ts +27 -11
  124. package/lib/esm/utils.d.ts +2 -2
  125. package/lib/esm/utils.js +2 -2
  126. package/package.json +6 -6
@@ -9,6 +9,10 @@ type VaultV2BlueReallocationsParams = {
9
9
  readonly operation?: {
10
10
  readonly type: "borrow" | "withdraw";
11
11
  readonly amount: bigint;
12
+ } | {
13
+ readonly type: "refinance";
14
+ readonly amount: bigint;
15
+ readonly referralFeePct?: bigint;
12
16
  };
13
17
  };
14
18
  };
@@ -764,7 +768,7 @@ export interface BlueActions {
764
768
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
765
769
  * @throws {UnsupportedBlueMarketIrmError} when positive source or destination debt requires an unsupported IRM projection.
766
770
  * @throws {MissingAccrualPositionError} when either position snapshot is absent at runtime.
767
- * @throws {MarketIdMismatchError} when a position snapshot belongs to another market.
771
+ * @throws {MarketIdMismatchError} when `destination.marketParams.id` does not hash from its tuple fields, or a position snapshot belongs to another market.
768
772
  * @throws {AccrualPositionUserMismatchError} when a position snapshot belongs to another user.
769
773
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
770
774
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
@@ -842,10 +846,13 @@ export interface BlueActions {
842
846
  *
843
847
  * Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
844
848
  * vault's BluePublicAllocator permissions and allocation caps at one block.
849
+ * The snapshot keeps the fetched block's timestamp as its default planning time.
845
850
  *
846
851
  * @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
847
852
  * @param params.block.number - Block number used for every RPC read.
848
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
853
+ * @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
854
+ * planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
855
+ * `lastUpdate`. An explicit `options.timestamp` is used as given.
849
856
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
850
857
  * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
851
858
  * chain via `eth_chainId`.
@@ -878,14 +885,23 @@ export interface BlueActions {
878
885
  * persist across every leg of a plan. Operation plans keep
879
886
  * `allocatorCapHeadroom` (1% of the cap by default) free under each target
880
887
  * BluePublicAllocator cap unless the operation shortfall needs it.
888
+ * For `refinance`, compute the plan on the destination-market handle (for
889
+ * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
890
+ * source-market handle. Pass the source position's `borrowAssets` accrued to
891
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
892
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
893
+ * The planner includes the referral fee and its own planned allocator-leg
894
+ * penalties in destination debt. Refinance never uses vaults with a 100%
895
+ * penalty.
881
896
  *
882
897
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
883
898
  * @param params.options - Optional allocator discovery controls and operation to support.
884
899
  * @returns Action-ready reallocations and their post-simulation state.
885
900
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
886
901
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
887
- * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
902
+ * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
888
903
  * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
904
+ * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
889
905
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
890
906
  * @throws {UnknownReallocationMarketError} when a required market is absent.
891
907
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -895,7 +911,7 @@ export interface BlueActions {
895
911
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
896
912
  * @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
897
913
  * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
898
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
914
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall and, for refinance, its planned allocator penalties.
899
915
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
900
916
  * @example
901
917
  * ```ts
@@ -915,6 +931,14 @@ export declare class MorphoBlue implements BlueActions {
915
931
  private readonly client;
916
932
  readonly marketParams: MarketParams;
917
933
  private readonly chainId;
934
+ /**
935
+ * Binds `client` to the market described by `marketParams` on `chainId`.
936
+ *
937
+ * @param client - Morpho client used for reads and requirement lookups.
938
+ * @param marketParams - Market params whose `id` must hash from their five tuple fields.
939
+ * @param chainId - Chain the market lives on.
940
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
941
+ */
918
942
  constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
919
943
  private validateDeadline;
920
944
  private validateWriteCommon;
@@ -1059,10 +1083,13 @@ export declare class MorphoBlue implements BlueActions {
1059
1083
  *
1060
1084
  * Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
1061
1085
  * vault's BluePublicAllocator permissions and allocation caps at one block.
1086
+ * The snapshot keeps the fetched block's timestamp as its default planning time.
1062
1087
  *
1063
1088
  * @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
1064
1089
  * @param params.block.number - Block number used for every RPC read.
1065
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
1090
+ * @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
1091
+ * planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
1092
+ * `lastUpdate`. An explicit `options.timestamp` is used as given.
1066
1093
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
1067
1094
  * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
1068
1095
  * chain via `eth_chainId`.
@@ -1114,14 +1141,23 @@ export declare class MorphoBlue implements BlueActions {
1114
1141
  * persist across every leg of a plan. Operation plans keep
1115
1142
  * `allocatorCapHeadroom` (1% of the cap by default) free under each target
1116
1143
  * BluePublicAllocator cap unless the operation shortfall needs it.
1144
+ * For `refinance`, compute the plan on the destination-market handle (for
1145
+ * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
1146
+ * source-market handle. Pass the source position's `borrowAssets` accrued to
1147
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
1148
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
1149
+ * The planner includes the referral fee and its own planned allocator-leg
1150
+ * penalties in destination debt. Refinance never uses vaults with a 100%
1151
+ * penalty.
1117
1152
  *
1118
1153
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
1119
1154
  * @param params.options - Optional allocator discovery controls and operation to support.
1120
1155
  * @returns Action-ready reallocations and their post-simulation state.
1121
1156
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
1122
1157
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1123
- * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
1158
+ * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
1124
1159
  * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
1160
+ * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
1125
1161
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
1126
1162
  * @throws {UnknownReallocationMarketError} when a required market is absent.
1127
1163
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1131,7 +1167,7 @@ export declare class MorphoBlue implements BlueActions {
1131
1167
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
1132
1168
  * @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
1133
1169
  * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
1134
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
1170
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall and, for refinance, its planned allocator penalties.
1135
1171
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
1136
1172
  * @example
1137
1173
  * ```ts
@@ -9,6 +9,7 @@ const common_js_1 = require("../../actions/blue/common.js");
9
9
  const index_js_1 = require("../../actions/index.js");
10
10
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
11
11
  const index_js_2 = require("../../helpers/index.js");
12
+ const validate_js_1 = require("../../helpers/validate.js");
12
13
  const index_js_3 = require("../../types/index.js");
13
14
  const assertContractCode_js_1 = require("../requirements/assertContractCode.js");
14
15
  const index_js_4 = require("../requirements/index.js");
@@ -18,11 +19,20 @@ class MorphoBlue {
18
19
  client;
19
20
  marketParams;
20
21
  chainId;
22
+ /**
23
+ * Binds `client` to the market described by `marketParams` on `chainId`.
24
+ *
25
+ * @param client - Morpho client used for reads and requirement lookups.
26
+ * @param marketParams - Market params whose `id` must hash from their five tuple fields.
27
+ * @param chainId - Chain the market lives on.
28
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
29
+ */
21
30
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
22
31
  constructor(client, marketParams, chainId) {
23
32
  this.client = client;
24
33
  this.marketParams = marketParams;
25
34
  this.chainId = chainId;
35
+ (0, validate_js_1.validateMarketParamsId)(marketParams);
26
36
  }
27
37
  validateDeadline(deadline, now = morpho_ts_1.Time.timestamp()) {
28
38
  if (deadline <= now) {
@@ -640,6 +650,7 @@ class MorphoBlue {
640
650
  refinance(params) {
641
651
  const { userAddress, positionData, destination, deadline, referralFeeRecipient, } = params;
642
652
  this.validateWriteCommon(params);
653
+ (0, validate_js_1.validateMarketParamsId)(destination.marketParams);
643
654
  // `validateWriteCommon` returns void, so default an omitted `referralFeePct` to `0n`
644
655
  // here, matching the pure action's normalization.
645
656
  const referralFeePct = params.referralFeePct ?? 0n;
@@ -723,10 +734,13 @@ class MorphoBlue {
723
734
  *
724
735
  * Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
725
736
  * vault's BluePublicAllocator permissions and allocation caps at one block.
737
+ * The snapshot keeps the fetched block's timestamp as its default planning time.
726
738
  *
727
739
  * @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
728
740
  * @param params.block.number - Block number used for every RPC read.
729
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
741
+ * @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
742
+ * planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
743
+ * `lastUpdate`. An explicit `options.timestamp` is used as given.
730
744
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
731
745
  * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
732
746
  * chain via `eth_chainId`.
@@ -782,6 +796,7 @@ class MorphoBlue {
782
796
  ]);
783
797
  return new vaultV2BlueReallocationData_js_1.VaultV2BlueReallocationData({
784
798
  chainId: this.chainId,
799
+ timestamp: block.timestamp,
785
800
  markets: { [targetMarket.id]: targetMarket },
786
801
  vaults: Object.fromEntries(vaultEntries.map(({ vault }) => [vault.address, vault])),
787
802
  allocations: Object.fromEntries(vaultEntries.map(({ publicAllocatorData, vault }) => [
@@ -812,14 +827,23 @@ class MorphoBlue {
812
827
  * persist across every leg of a plan. Operation plans keep
813
828
  * `allocatorCapHeadroom` (1% of the cap by default) free under each target
814
829
  * BluePublicAllocator cap unless the operation shortfall needs it.
830
+ * For `refinance`, compute the plan on the destination-market handle (for
831
+ * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
832
+ * source-market handle. Pass the source position's `borrowAssets` accrued to
833
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
834
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
835
+ * The planner includes the referral fee and its own planned allocator-leg
836
+ * penalties in destination debt. Refinance never uses vaults with a 100%
837
+ * penalty.
815
838
  *
816
839
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
817
840
  * @param params.options - Optional allocator discovery controls and operation to support.
818
841
  * @returns Action-ready reallocations and their post-simulation state.
819
842
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
820
843
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
821
- * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
844
+ * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
822
845
  * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
846
+ * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
823
847
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
824
848
  * @throws {UnknownReallocationMarketError} when a required market is absent.
825
849
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -829,7 +853,7 @@ class MorphoBlue {
829
853
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
830
854
  * @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
831
855
  * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
832
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
856
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall and, for refinance, its planned allocator penalties.
833
857
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
834
858
  * @example
835
859
  * ```ts
@@ -1,13 +1,13 @@
1
- export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MidnightAdapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
1
+ export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  IPreLiquidationParams as IBluePreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MidnightAdapter, IVaultV2MidnightAdapterAccrualMarket, IVaultV2MidnightAdapterCollateralParams, IVaultV2MidnightAdapterMarket, IVaultV2MidnightAdapterMarketData, IVaultV2MidnightAdapterMarketState, IVaultV2MidnightAdapterPosition, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultV2MidnightAdapterAccrualMarket, VaultV2MidnightAdapterMarketData, } from "@morpho-org/blue-sdk";
6
- export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
5
+ IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
6
+ export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
7
7
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
8
8
  PreLiquidationParams as BluePreLiquidationParams,
9
9
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
10
- PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MidnightAdapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
10
+ PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
11
11
  export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnapshot, BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, EcrecoverTreeCreateRequest as MidnightEcrecoverTreeCreateRequest, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, PriceRatifierV1TreeCreateRequest as MidnightPriceRatifierV1TreeCreateRequest, RateRatifierV1TreeCreateRequest as MidnightRateRatifierV1TreeCreateRequest, RatifierKind as MidnightRatifierKind, RatifierTreeInput as MidnightRatifierTreeInput, RatifierTypes as MidnightRatifierTypes, SetterTreeCreateRequest as MidnightSetterTreeCreateRequest, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeCreateRequest as MidnightTreeCreateRequest, TreeData as MidnightTreeData, TreeDescriptor as MidnightTreeDescriptor, TreeEntry as MidnightTreeEntry, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, TreeSnapshot as MidnightTreeSnapshot, TypedRatifierTreeInput as MidnightTypedRatifierTreeInput, TypedTreeMempoolValidateParams as MidnightTypedTreeMempoolValidateParams, } from "@morpho-org/midnight-sdk";
12
12
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
13
13
  export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
@@ -14,12 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.VaultV2BlueReallocationData = exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.MorphoMidnight = exports.MorphoBlue = exports.MidnightTree = exports.MidnightPosition = exports.MidnightOffer = exports.MidnightMarketParams = exports.MidnightMarket = exports.MidnightGroup = exports.MidnightAccrualPosition = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2MidnightAdapter = exports.VaultV2BluePublicAllocatorConfig = exports.VaultV2BlueMarketPublicAllocatorConfig = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.BlueUser = exports.Token = exports.BluePreLiquidationPosition = exports.BluePreLiquidationParams = exports.BluePosition = exports.BlueMarketParams = exports.BlueMarket = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2MidnightAdapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.BlueAccrualPosition = void 0;
17
+ exports.VaultV2BlueReallocationData = exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.MorphoMidnight = exports.MorphoBlue = exports.MidnightTree = exports.MidnightPosition = exports.MidnightOffer = exports.MidnightMarketParams = exports.MidnightMarket = exports.MidnightGroup = exports.MidnightAccrualPosition = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2BluePublicAllocatorConfig = exports.VaultV2BlueMarketPublicAllocatorConfig = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.BlueUser = exports.Token = exports.BluePreLiquidationPosition = exports.BluePreLiquidationParams = exports.BluePosition = exports.BlueMarketParams = exports.BlueMarket = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.BlueAccrualPosition = void 0;
18
18
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
19
19
  Object.defineProperty(exports, "BlueAccrualPosition", { enumerable: true, get: function () { return blue_sdk_1.AccrualPosition; } });
20
20
  Object.defineProperty(exports, "AccrualVault", { enumerable: true, get: function () { return blue_sdk_1.AccrualVault; } });
21
21
  Object.defineProperty(exports, "AccrualVaultV2", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2; } });
22
- Object.defineProperty(exports, "AccrualVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MidnightAdapter; } });
23
22
  Object.defineProperty(exports, "AccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter; } });
24
23
  Object.defineProperty(exports, "AccrualVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2; } });
25
24
  Object.defineProperty(exports, "AccrualVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter; } });
@@ -47,7 +46,6 @@ Object.defineProperty(exports, "VaultV2", { enumerable: true, get: function () {
47
46
  Object.defineProperty(exports, "VaultV2Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Adapter; } });
48
47
  Object.defineProperty(exports, "VaultV2BlueMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BlueMarketPublicAllocatorConfig; } });
49
48
  Object.defineProperty(exports, "VaultV2BluePublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BluePublicAllocatorConfig; } });
50
- Object.defineProperty(exports, "VaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MidnightAdapter; } });
51
49
  Object.defineProperty(exports, "VaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1Adapter; } });
52
50
  Object.defineProperty(exports, "VaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1AdapterV2; } });
53
51
  Object.defineProperty(exports, "VaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoVaultV1Adapter; } });
@@ -197,6 +197,7 @@ export declare class MorphoMidnight {
197
197
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
198
198
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
199
199
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
200
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
200
201
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
201
202
  * @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
202
203
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
@@ -552,6 +553,7 @@ export declare class MorphoMidnight {
552
553
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
553
554
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
554
555
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
556
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
555
557
  * @throws {ExpiredDeadlineError} when `deadline` has expired.
556
558
  * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
557
559
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
@@ -636,14 +638,14 @@ export declare class MorphoMidnight {
636
638
  * for a new publication. Calls the Midnight mempool validation API while preparing the tree;
637
639
  * `validation: false` skips that call.
638
640
  *
639
- * @param params - Maker, lend-side offers, loan reserve, cancellations, and deadline.
641
+ * @param params - Maker, lend-side offers, `loanAssets` and `reservedLoanAssets` allowance thresholds, cancellations, and deadline.
640
642
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
641
643
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
642
644
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
643
645
  * @param params.deadline - Bundle execution deadline timestamp.
644
646
  * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
645
647
  * @param params.loanToken - Loan token shared by every offer market.
646
- * @param params.loanAssets - New loan reserve assigned to the published groups.
648
+ * @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
647
649
  * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups, excluding groups in `cancellations`.
648
650
  * @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
649
651
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
@@ -946,7 +948,7 @@ export declare class MorphoMidnight {
946
948
  *
947
949
  * Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
948
950
  * Loan assets are pulled by Midnight when the offers fill, not during publication.
949
- * The loan reserve uses the same approval sizing as `makeLend`.
951
+ * `loanAssets` is only the allowance threshold `getRequirements()` checks, as in `makeLend`; the signed offer caps bound fills.
950
952
  * A partially consumed offer group remains publishable with its shared remaining cap reduced.
951
953
  * No repay offer can be live after market maturity; late borrowers should repay directly with
952
954
  * {@link MorphoMidnight.repayWithdrawCollateral}.
@@ -954,14 +956,14 @@ export declare class MorphoMidnight {
954
956
  * Every offer must already have `buy = true` and `reduceOnly = true`.
955
957
  * The supplied tree, group caps and prices are preserved; no separate root signature is needed.
956
958
  *
957
- * @param params - Maker, reduce-only offers, optional cancellations, loan reserve, and deadline.
959
+ * @param params - Maker, reduce-only offers, optional cancellations, `loanAssets` and `reservedLoanAssets` allowance thresholds, and deadline.
958
960
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
959
961
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
960
962
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
961
963
  * @param params.deadline - Bundle execution deadline timestamp.
962
964
  * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
963
965
  * @param params.loanToken - Loan token shared by every offer market.
964
- * @param params.loanAssets - New loan reserve assigned to the published groups.
966
+ * @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
965
967
  * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
966
968
  * @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
967
969
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
@@ -342,6 +342,7 @@ class MorphoMidnight {
342
342
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
343
343
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
344
344
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
345
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
345
346
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
346
347
  * @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
347
348
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
@@ -930,6 +931,7 @@ class MorphoMidnight {
930
931
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
931
932
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
932
933
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
934
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
933
935
  * @throws {ExpiredDeadlineError} when `deadline` has expired.
934
936
  * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
935
937
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
@@ -1154,14 +1156,14 @@ class MorphoMidnight {
1154
1156
  * for a new publication. Calls the Midnight mempool validation API while preparing the tree;
1155
1157
  * `validation: false` skips that call.
1156
1158
  *
1157
- * @param params - Maker, lend-side offers, loan reserve, cancellations, and deadline.
1159
+ * @param params - Maker, lend-side offers, `loanAssets` and `reservedLoanAssets` allowance thresholds, cancellations, and deadline.
1158
1160
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
1159
1161
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
1160
1162
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
1161
1163
  * @param params.deadline - Bundle execution deadline timestamp.
1162
1164
  * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
1163
1165
  * @param params.loanToken - Loan token shared by every offer market.
1164
- * @param params.loanAssets - New loan reserve assigned to the published groups.
1166
+ * @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
1165
1167
  * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups, excluding groups in `cancellations`.
1166
1168
  * @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
1167
1169
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
@@ -1680,7 +1682,7 @@ class MorphoMidnight {
1680
1682
  *
1681
1683
  * Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
1682
1684
  * Loan assets are pulled by Midnight when the offers fill, not during publication.
1683
- * The loan reserve uses the same approval sizing as `makeLend`.
1685
+ * `loanAssets` is only the allowance threshold `getRequirements()` checks, as in `makeLend`; the signed offer caps bound fills.
1684
1686
  * A partially consumed offer group remains publishable with its shared remaining cap reduced.
1685
1687
  * No repay offer can be live after market maturity; late borrowers should repay directly with
1686
1688
  * {@link MorphoMidnight.repayWithdrawCollateral}.
@@ -1688,14 +1690,14 @@ class MorphoMidnight {
1688
1690
  * Every offer must already have `buy = true` and `reduceOnly = true`.
1689
1691
  * The supplied tree, group caps and prices are preserved; no separate root signature is needed.
1690
1692
  *
1691
- * @param params - Maker, reduce-only offers, optional cancellations, loan reserve, and deadline.
1693
+ * @param params - Maker, reduce-only offers, optional cancellations, `loanAssets` and `reservedLoanAssets` allowance thresholds, and deadline.
1692
1694
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
1693
1695
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
1694
1696
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
1695
1697
  * @param params.deadline - Bundle execution deadline timestamp.
1696
1698
  * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
1697
1699
  * @param params.loanToken - Loan token shared by every offer market.
1698
- * @param params.loanAssets - New loan reserve assigned to the published groups.
1700
+ * @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
1699
1701
  * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
1700
1702
  * @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
1701
1703
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
@@ -51,7 +51,14 @@ export interface MakeOffersParams {
51
51
  /** Parameters for a Midnight lend maker flow. */
52
52
  export interface MakeLendParams extends MakeOffersParams {
53
53
  readonly loanToken: Address;
54
- /** New group loan reserve. For grouped OCA offers, pass the group reserve once instead of summing every leg. */
54
+ /**
55
+ * Minimum Midnight loan-token allowance, together with `reservedLoanAssets`, that `getRequirements()` checks.
56
+ * When the allowance is lower, it returns an unlimited approval (`maxUint256`, capped per token by `MAX_TOKEN_APPROVALS`).
57
+ * Not checked against the offers: their signed `maxAssets`/`maxUnits` caps, the maker's balance and the
58
+ * allowance bound what takers can fill, so size those caps to what you mean to lend
59
+ * (`maxAssets` counts loan assets, `maxUnits` counts position units).
60
+ * For grouped OCA offers, pass the group amount once instead of summing every leg.
61
+ */
55
62
  readonly loanAssets: bigint;
56
63
  /** Existing loan assets reserved across the maker's other open groups, including consumed amounts when available. Leave out groups listed in `cancellations`; this transaction cancels them. */
57
64
  readonly reservedLoanAssets?: bigint;
@@ -1,4 +1,4 @@
1
- import { type AccrualVaultV2, type MarketParams } from "@morpho-org/blue-sdk";
1
+ import { type AccrualVaultV2, MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
@@ -69,9 +69,8 @@ export interface VaultV2Actions {
69
69
  * owner is consumed and none was passed explicitly.
70
70
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
71
71
  * explicit Permit2 nonce is consumed.
72
- * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, when the vault's
73
- * liquidity adapter is a Midnight adapter (it cannot receive vault allocations, so no deposit
74
- * fits and `max` is `0n`), or from `getRequirements()` when the Permit2 nonce exceeds uint256.
72
+ * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
73
+ * `getRequirements()` when the Permit2 nonce exceeds uint256.
75
74
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
76
75
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
77
76
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -153,9 +152,7 @@ export interface VaultV2Actions {
153
152
  * @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
154
153
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
155
154
  * at any `getRequirements()` call.
156
- * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation,
157
- * or when the vault's liquidity adapter is a Midnight adapter and `amount` exceeds the vault's
158
- * idle assets.
155
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
159
156
  * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
160
157
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
161
158
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
@@ -221,24 +218,7 @@ export interface VaultV2Actions {
221
218
  * @throws {NonPositiveInputError} when `shares` is not positive.
222
219
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
223
220
  * requirement resolution.
224
- * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256, or from
225
- * `getRequirements()` when the vault's liquidity adapter is a Midnight adapter and `shares`
226
- * are worth more than the vault's idle assets.
227
- * @throws {UnknownBlueFactory} from `getRequirements()` when the configured chain has no VaultV2 factory.
228
- * @throws {UnknownBlueOfFactory} from `getRequirements()` when the vault is not a VaultV2 from the
229
- * configured factory.
230
- * @throws {UnsupportedBlueVaultV2AdapterError} from `getRequirements()` when the vault or one of its
231
- * adapters uses an unsupported adapter class.
232
- * @throws {UnsupportedBlueMarketIrmError} from `getRequirements()` when the vault's liquidity adapter
233
- * is a Midnight adapter and accrual projects an underlying market with positive debt that uses an
234
- * unsupported IRM.
235
- * @throws {UnknownBlueMarketAllocationError} from `getRequirements()` when the vault's liquidity
236
- * adapter is a Midnight adapter and accrual meets a nested Vault V1 withdraw queue market without
237
- * allocation data.
238
- * @throws {InvalidMidnightPositionLossFactorError} from `getRequirements()` when the vault's liquidity
239
- * adapter is a Midnight adapter and accrual meets a market loss factor below a position's.
240
- * @throws {InvalidMidnightPositionAccrualStateError} from `getRequirements()` when the vault's
241
- * liquidity adapter is a Midnight adapter and accrual meets invalid Midnight position inputs.
221
+ * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
242
222
  * @throws {NegativeInputError} when `referralFeePct` is negative.
243
223
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
244
224
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
@@ -246,7 +226,7 @@ export interface VaultV2Actions {
246
226
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
247
227
  * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
248
228
  * contract has no code at its registered address.
249
- * @throws {viem.BaseError} from `getRequirements()` when a vault-state, allowance, nonce, `eth_chainId`, or
229
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, `eth_chainId`, or
250
230
  * `eth_getCode` read fails.
251
231
  * @throws {UnknownTokenError} from `getRequirements()` when the share token fetched by
252
232
  * `getData()` has unusable decimals.
@@ -324,11 +304,9 @@ export interface VaultV2Actions {
324
304
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
325
305
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
326
306
  * requirement resolution.
327
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter, including
328
- * a vault that mixes Blue and Midnight adapters.
307
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
329
308
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
330
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
331
- * including a Midnight adapter.
309
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
332
310
  * @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
333
311
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
334
312
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -453,11 +431,9 @@ export interface VaultV2Actions {
453
431
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
454
432
  * requirement resolution.
455
433
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
456
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter,
457
- * including a vault that mixes Blue and Midnight adapters.
434
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
458
435
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
459
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
460
- * including a Midnight adapter.
436
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
461
437
  * @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
462
438
  * another adapter.
463
439
  * @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
@@ -528,6 +504,8 @@ export interface VaultV2Actions {
528
504
  * This is the share-based counterpart to forceWithdraw, useful for maximum withdrawal scenarios
529
505
  * where specifying an exact asset amount is impractical.
530
506
  *
507
+ * Inputs are copied when the handle is created, so later changes to them are not encoded.
508
+ *
531
509
  * The total assets passed to forceDeallocate calls must be greater than or equal to the
532
510
  * asset-equivalent of the redeemed shares. The caller should apply a buffer on the deallocated
533
511
  * amounts to account for share-price drift between submission and execution.
@@ -18,11 +18,6 @@ const index_js_4 = require("../requirements/index.js");
18
18
  // Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
19
19
  // accrual model stays well-defined inside it.
20
20
  const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
21
- /**
22
- * Midnight adapters revert vault-initiated `allocate` and `deallocate` (`SelfAllocationOnly`), so a
23
- * vault routing liquidity through one accepts no deposit and serves exits from idle assets only.
24
- */
25
- const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
26
21
  /** Binds a viem client to a Vault V2 vault's action builders. */
27
22
  class MorphoVaultV2 {
28
23
  client;
@@ -86,13 +81,6 @@ class MorphoVaultV2 {
86
81
  // The native path must target the chain's registered wrapped-native asset.
87
82
  (0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
88
83
  }
89
- if (isMidnightLiquidityAdapter(vaultData)) {
90
- throw new index_js_3.InputExceedsMaxError({
91
- field: funding.value > 0n ? "nativeAmount" : "amount",
92
- value: funding.assets,
93
- max: 0n,
94
- });
95
- }
96
84
  const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
97
85
  const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
98
86
  vaultData,
@@ -176,14 +164,6 @@ class MorphoVaultV2 {
176
164
  throw new index_js_3.NonPositiveInputError("amount", amount);
177
165
  // Reject values outside the ABI range before resolving any requirements.
178
166
  (0, validate_js_1.validateUint256Field)("amount", amount);
179
- if (isMidnightLiquidityAdapter(vaultData) &&
180
- amount > vaultData.assetBalance) {
181
- throw new index_js_3.InputExceedsMaxError({
182
- field: "amount",
183
- value: amount,
184
- max: vaultData.assetBalance,
185
- });
186
- }
187
167
  const createdAt = morpho_ts_1.Time.timestamp();
188
168
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
189
169
  if (deadline <= createdAt)
@@ -264,20 +244,8 @@ class MorphoVaultV2 {
264
244
  if (deadline <= now)
265
245
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
266
246
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
267
- const vaultData = await this.getData();
268
- if (isMidnightLiquidityAdapter(vaultData)) {
269
- // Onchain redeem accrues interest before converting shares to assets.
270
- const { vault: accrued } = vaultData.accrueInterest(now);
271
- if (accrued.toAssets(shares) > accrued.assetBalance) {
272
- throw new index_js_3.InputExceedsMaxError({
273
- field: "shares",
274
- value: shares,
275
- max: accrued.toShares(accrued.assetBalance),
276
- });
277
- }
278
- }
279
247
  return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
280
- vaultData,
248
+ vaultData: await this.getData(),
281
249
  version: "vaultV2",
282
250
  owner: userAddress,
283
251
  chainId: this.chainId,
@@ -729,15 +697,18 @@ class MorphoVaultV2 {
729
697
  }
730
698
  forceRedeem({ deallocations, redeem, userAddress, }) {
731
699
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
700
+ const shares = redeem.shares;
701
+ const deallocationsSnapshot = deallocations.map(({ adapter, marketParams, amount }) => ({
702
+ adapter,
703
+ amount,
704
+ ...(marketParams && { marketParams: new blue_sdk_1.MarketParams(marketParams) }),
705
+ }));
732
706
  return {
733
707
  buildTx: () => (0, index_js_1.vaultV2ForceRedeem)({
734
708
  vault: { address: this.vault },
735
709
  args: {
736
- deallocations,
737
- redeem: {
738
- shares: redeem.shares,
739
- recipient: userAddress,
740
- },
710
+ deallocations: deallocationsSnapshot,
711
+ redeem: { shares, recipient: userAddress },
741
712
  onBehalf: userAddress,
742
713
  },
743
714
  metadata: this.client.options.metadata,