@morpho-org/morpho-sdk 5.4.1 → 5.6.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 (140) hide show
  1. package/README.md +23 -7
  2. package/lib/cjs/abis.d.ts +314 -1
  3. package/lib/cjs/abis.js +169 -1
  4. package/lib/cjs/actions/blue/borrow.d.ts +21 -15
  5. package/lib/cjs/actions/blue/borrow.js +25 -18
  6. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +1 -1
  7. package/lib/cjs/actions/blue/buildAssetFundingActions.js +1 -1
  8. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +62 -19
  9. package/lib/cjs/actions/blue/buildReallocationActions.js +123 -27
  10. package/lib/cjs/actions/blue/refinance.d.ts +14 -7
  11. package/lib/cjs/actions/blue/refinance.js +18 -10
  12. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +28 -19
  13. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +39 -23
  14. package/lib/cjs/actions/blue/withdraw.d.ts +20 -13
  15. package/lib/cjs/actions/blue/withdraw.js +23 -18
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  17. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +9 -2
  18. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
  19. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +131 -0
  20. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  21. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  22. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
  23. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -3
  24. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
  25. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +91 -0
  26. package/lib/cjs/actions/signatures/index.d.ts +1 -0
  27. package/lib/cjs/actions/signatures/index.js +1 -0
  28. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +54 -0
  29. package/lib/cjs/actions/vaultV1/inKindRedeem.js +96 -0
  30. package/lib/cjs/actions/vaultV1/index.d.ts +1 -0
  31. package/lib/cjs/actions/vaultV1/index.js +1 -0
  32. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +56 -0
  33. package/lib/cjs/actions/vaultV2/inKindRedeem.js +97 -0
  34. package/lib/cjs/actions/vaultV2/index.d.ts +1 -0
  35. package/lib/cjs/actions/vaultV2/index.js +1 -0
  36. package/lib/cjs/bundler/actions.d.ts +118 -2
  37. package/lib/cjs/bundler/actions.js +212 -6
  38. package/lib/cjs/bundler/types.d.ts +20 -0
  39. package/lib/cjs/constants.d.ts +1 -1
  40. package/lib/cjs/constants.js +3 -1
  41. package/lib/cjs/entities/blue/blue.d.ts +365 -76
  42. package/lib/cjs/entities/blue/blue.js +285 -52
  43. package/lib/cjs/entities/index.d.ts +2 -1
  44. package/lib/cjs/entities/index.js +6 -3
  45. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +82 -4
  46. package/lib/cjs/entities/vaultV1/vaultV1.js +164 -0
  47. package/lib/cjs/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +41 -17
  48. package/lib/cjs/entities/{reallocationData.js → vaultV1ReallocationData.js} +30 -18
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +89 -3
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +181 -0
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +511 -0
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1311 -0
  53. package/lib/{esm/helpers/computeReallocations.d.ts → cjs/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  54. package/lib/cjs/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +27 -13
  55. package/lib/cjs/helpers/constant.d.ts +5 -3
  56. package/lib/cjs/helpers/constant.js +6 -4
  57. package/lib/cjs/helpers/index.d.ts +3 -2
  58. package/lib/cjs/helpers/index.js +8 -3
  59. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
  60. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +73 -0
  61. package/lib/cjs/helpers/validate.d.ts +31 -15
  62. package/lib/cjs/helpers/validate.js +140 -27
  63. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  64. package/lib/cjs/helpers/validateRequirementSpender.js +2 -1
  65. package/lib/cjs/types/action.d.ts +33 -1
  66. package/lib/cjs/types/error.d.ts +363 -5
  67. package/lib/cjs/types/error.js +455 -6
  68. package/lib/cjs/types/sharedLiquidity.d.ts +72 -8
  69. package/lib/cjs/utils.d.ts +2 -2
  70. package/lib/cjs/utils.js +6 -4
  71. package/lib/esm/abis.d.ts +314 -1
  72. package/lib/esm/abis.js +167 -1
  73. package/lib/esm/actions/blue/borrow.d.ts +21 -15
  74. package/lib/esm/actions/blue/borrow.js +26 -19
  75. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +1 -1
  76. package/lib/esm/actions/blue/buildAssetFundingActions.js +1 -1
  77. package/lib/esm/actions/blue/buildReallocationActions.d.ts +62 -19
  78. package/lib/esm/actions/blue/buildReallocationActions.js +119 -25
  79. package/lib/esm/actions/blue/refinance.d.ts +14 -7
  80. package/lib/esm/actions/blue/refinance.js +19 -11
  81. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +28 -19
  82. package/lib/esm/actions/blue/supplyCollateralBorrow.js +40 -24
  83. package/lib/esm/actions/blue/withdraw.d.ts +20 -13
  84. package/lib/esm/actions/blue/withdraw.js +24 -19
  85. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  86. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -2
  87. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
  88. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +127 -0
  89. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  90. package/lib/esm/actions/requirements/encode/index.js +1 -0
  91. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
  92. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -3
  93. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
  94. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +87 -0
  95. package/lib/esm/actions/signatures/index.d.ts +1 -0
  96. package/lib/esm/actions/signatures/index.js +1 -0
  97. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +54 -0
  98. package/lib/esm/actions/vaultV1/inKindRedeem.js +92 -0
  99. package/lib/esm/actions/vaultV1/index.d.ts +1 -0
  100. package/lib/esm/actions/vaultV1/index.js +1 -0
  101. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +56 -0
  102. package/lib/esm/actions/vaultV2/inKindRedeem.js +93 -0
  103. package/lib/esm/actions/vaultV2/index.d.ts +1 -0
  104. package/lib/esm/actions/vaultV2/index.js +1 -0
  105. package/lib/esm/bundler/actions.d.ts +118 -2
  106. package/lib/esm/bundler/actions.js +215 -9
  107. package/lib/esm/bundler/types.d.ts +20 -0
  108. package/lib/esm/constants.d.ts +1 -1
  109. package/lib/esm/constants.js +1 -1
  110. package/lib/esm/entities/blue/blue.d.ts +362 -73
  111. package/lib/esm/entities/blue/blue.js +288 -55
  112. package/lib/esm/entities/index.d.ts +2 -1
  113. package/lib/esm/entities/index.js +2 -1
  114. package/lib/esm/entities/vaultV1/vaultV1.d.ts +80 -2
  115. package/lib/esm/entities/vaultV1/vaultV1.js +170 -6
  116. package/lib/esm/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +41 -17
  117. package/lib/esm/entities/{reallocationData.js → vaultV1ReallocationData.js} +33 -16
  118. package/lib/esm/entities/vaultV2/vaultV2.d.ts +88 -2
  119. package/lib/esm/entities/vaultV2/vaultV2.js +187 -6
  120. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +511 -0
  121. package/lib/esm/entities/vaultV2BlueReallocationData.js +1307 -0
  122. package/lib/{cjs/helpers/computeReallocations.d.ts → esm/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  123. package/lib/esm/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +25 -11
  124. package/lib/esm/helpers/constant.d.ts +5 -3
  125. package/lib/esm/helpers/constant.js +5 -3
  126. package/lib/esm/helpers/index.d.ts +3 -2
  127. package/lib/esm/helpers/index.js +3 -2
  128. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
  129. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +70 -0
  130. package/lib/esm/helpers/validate.d.ts +31 -15
  131. package/lib/esm/helpers/validate.js +141 -30
  132. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  133. package/lib/esm/helpers/validateRequirementSpender.js +2 -1
  134. package/lib/esm/types/action.d.ts +33 -1
  135. package/lib/esm/types/error.d.ts +363 -5
  136. package/lib/esm/types/error.js +428 -4
  137. package/lib/esm/types/sharedLiquidity.d.ts +72 -8
  138. package/lib/esm/utils.d.ts +2 -2
  139. package/lib/esm/utils.js +2 -2
  140. package/package.json +9 -11
@@ -1,8 +1,31 @@
1
1
  import { 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 AssetsOrSharesArgs, type BlueAuthorizationAction, type BlueBorrowAction, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawCollateralAction, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
5
- import { ReallocationData } from "../reallocationData.js";
4
+ import { type AssetsOrSharesArgs, type BlueAuthorizationAction, type BlueBorrowAction, type BlueReallocationPlan, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawCollateralAction, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultV1Reallocation, type VaultV2BluePublicAllocatorOptions, type VaultV2BlueReallocation } from "../../types/index.js";
5
+ import { VaultV1ReallocationData } from "../vaultV1ReallocationData.js";
6
+ import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
7
+ type VaultV1ReallocationsParams = {
8
+ readonly reallocationData: VaultV1ReallocationData;
9
+ readonly options?: ReallocationComputeOptions;
10
+ } & ({
11
+ readonly operation: "borrow" | "withdraw";
12
+ readonly amount: bigint;
13
+ readonly borrowAmount?: never;
14
+ } | {
15
+ /** @deprecated Pass `{ operation: "borrow", amount }` instead. */
16
+ readonly borrowAmount: bigint;
17
+ readonly operation?: never;
18
+ readonly amount?: never;
19
+ });
20
+ type VaultV2BlueReallocationsParams = {
21
+ readonly reallocationData: VaultV2BlueReallocationData;
22
+ readonly options?: VaultV2BluePublicAllocatorOptions & {
23
+ readonly operation?: {
24
+ readonly type: "borrow" | "withdraw";
25
+ readonly amount: bigint;
26
+ };
27
+ };
28
+ };
6
29
  export interface BlueActions {
7
30
  /**
8
31
  * Fetches the latest market data with accrued interest.
@@ -80,28 +103,35 @@ export interface BlueActions {
80
103
  *
81
104
  * Computes `minSharePrice` from market supply state and `slippageTolerance`.
82
105
  *
83
- * When `reallocations` is provided, `reallocateTo` actions are prepended to the bundle,
84
- * moving liquidity from other markets via the PublicAllocator before withdrawing — used to
85
- * unblock withdraws that exceed on-market liquidity.
106
+ * When `reallocations` is provided, its homogeneous V1 or V2 actions are
107
+ * prepended to move liquidity before withdrawing. V1 fees add
108
+ * to the transaction value; V2 penalties are paid in the loan token.
86
109
  *
87
- * `getRequirements` returns `morpho.setAuthorization(generalAdapter1, true)` if GA1 is not
88
- * yet authorized on Morpho (returns `[]` when already authorized), since the bundler calls
89
- * `withdraw(...,onBehalf=user,...)`.
110
+ * `getRequirements` returns the loan-token approval needed for V2 penalties
111
+ * and `morpho.setAuthorization(generalAdapter1, true)` when GA1 is not yet
112
+ * authorized on Morpho.
90
113
  *
91
114
  * **Stale `positionData` may cause unexpected supply share calculations.**
92
115
  *
93
116
  * @param params - Withdraw parameters including pre-fetched `positionData`.
94
117
  * @returns Object with `buildTx` and `getRequirements`.
118
+ * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
119
+ * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
120
+ * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
121
+ * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
122
+ * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
123
+ * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
124
+ * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
95
125
  */
96
126
  withdraw: (params: {
97
127
  userAddress: Address;
98
128
  receiver?: Address;
99
129
  positionData: AccrualPosition;
100
130
  slippageTolerance?: bigint;
101
- reallocations?: readonly VaultReallocation[];
131
+ reallocations?: BlueReallocationPlan;
102
132
  } & AssetsOrSharesArgs) => {
103
133
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueWithdrawAction>>;
104
- getRequirements: () => Promise<(Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
134
+ getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
105
135
  };
106
136
  /**
107
137
  * Prepares a borrow transaction.
@@ -110,26 +140,34 @@ export interface BlueActions {
110
140
  * Validates position health with LLTV buffer (0.5%) using the pre-fetched `positionData`.
111
141
  * Computes `minSharePrice` from market borrow state and `slippageTolerance`.
112
142
  *
113
- * When `reallocations` is provided, `reallocateTo` actions are prepended to the bundle,
114
- * moving liquidity from other markets via the PublicAllocator before borrowing.
143
+ * When `reallocations` is provided, its homogeneous V1 or V2 actions are
144
+ * prepended before borrowing. V1 fees add to the transaction
145
+ * value; V2 penalties are paid in the loan token.
115
146
  *
116
- * `getRequirements` returns `morpho.setAuthorization(generalAdapter1, true)` if not yet authorized,
117
- * since borrowing through bundler3 requires GeneralAdapter1 authorization on Morpho.
147
+ * `getRequirements` returns the loan-token approval needed for V2 penalties
148
+ * and Morpho authorization for GeneralAdapter1 when needed.
118
149
  *
119
150
  * **Stale `positionData` may cause unexpected health.**
120
151
  *
121
152
  * @param params - Borrow parameters including pre-fetched `positionData` for health validation.
122
153
  * @returns Object with `buildTx` and `getRequirements`.
154
+ * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
155
+ * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
156
+ * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
157
+ * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
158
+ * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
159
+ * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
160
+ * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
123
161
  */
124
162
  borrow: (params: {
125
163
  userAddress: Address;
126
164
  amount: bigint;
127
165
  positionData: AccrualPosition;
128
166
  slippageTolerance?: bigint;
129
- reallocations?: readonly VaultReallocation[];
167
+ reallocations?: BlueReallocationPlan;
130
168
  }) => {
131
169
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueBorrowAction>>;
132
- getRequirements: () => Promise<(Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
170
+ getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
133
171
  };
134
172
  /**
135
173
  * Prepares a repay transaction.
@@ -224,24 +262,33 @@ export interface BlueActions {
224
262
  * Routed through the bundler. Validates position health with LLTV buffer
225
263
  * to prevent instant liquidation on new positions near the LLTV threshold.
226
264
  *
227
- * When `reallocations` is provided, `reallocateTo` actions are prepended before
228
- * `morphoBorrow` in the bundle.
265
+ * When `reallocations` is provided, its homogeneous V1 or V2 actions run
266
+ * between the collateral supply and `morphoBorrow`. V1 fees add
267
+ * to the transaction value; V2 penalties are paid in the loan token.
229
268
  *
230
269
  * `getRequirements` returns in parallel:
231
270
  * - ERC20 approval or permit for collateral token (to GeneralAdapter1).
271
+ * - Classic ERC20 approval for any V2 loan-token penalties.
232
272
  * - `morpho.setAuthorization(generalAdapter1, true)` if adapter is not yet authorized.
233
273
  *
234
274
  * **Stale `positionData` may cause unexpected health.**
235
275
  *
236
276
  * @param params - Combined parameters including pre-fetched `positionData` for health validation.
237
277
  * @returns Object with `buildTx` and `getRequirements`.
278
+ * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
279
+ * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
280
+ * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
281
+ * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
282
+ * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
283
+ * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
284
+ * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
238
285
  */
239
286
  supplyCollateralBorrow: (params: {
240
287
  userAddress: Address;
241
288
  positionData: AccrualPosition;
242
289
  borrowAmount: bigint;
243
290
  slippageTolerance?: bigint;
244
- reallocations?: readonly VaultReallocation[];
291
+ reallocations?: BlueReallocationPlan;
245
292
  } & DepositAmountArgs) => {
246
293
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
247
294
  getRequirements: (params?: {
@@ -261,9 +308,12 @@ export interface BlueActions {
261
308
  * both the residual source and the aggregate target position stay within LLTV − buffer. Both
262
309
  * markets are forward-accrued to `now`; in shares mode the target borrow is overshot by
263
310
  * `slippageTolerance` and the callback sweeps the residual.
311
+ * A homogeneous V1 or V2 target reallocation plan runs first; V1 fees add
312
+ * to the transaction value and V2 penalties are paid
313
+ * in the loan token.
264
314
  *
265
- * `getRequirements` returns `morpho.setAuthorization(generalAdapter1, true)` when GA1 is not yet
266
- * authorized (a single global authorization covers both markets).
315
+ * `getRequirements` returns the loan-token approval needed for V2 penalties
316
+ * and Morpho authorization for GeneralAdapter1 when needed.
267
317
  *
268
318
  * @param params.userAddress - Position owner on both markets.
269
319
  * @param params.positionData - Pre-fetched source-market accrual position.
@@ -273,8 +323,15 @@ export interface BlueActions {
273
323
  * @param params.borrowAssets - Loan assets to repay on source; exclusive with `borrowShares`.
274
324
  * @param params.borrowShares - Borrow shares to repay on source; exclusive with `borrowAssets`.
275
325
  * @param params.slippageTolerance - WAD slippage tolerance. Defaults to `DEFAULT_SLIPPAGE_TOLERANCE`.
276
- * @param params.targetReallocations - PublicAllocator reallocations into the target market.
326
+ * @param params.targetReallocations - Homogeneous Vault V1 or Vault V2 reallocations into the target market.
277
327
  * @returns Object with `buildTx` and `getRequirements`.
328
+ * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
329
+ * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
330
+ * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
331
+ * @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
332
+ * @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
333
+ * @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
334
+ * @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
278
335
  */
279
336
  refinance: (params: {
280
337
  userAddress: Address;
@@ -287,13 +344,13 @@ export interface BlueActions {
287
344
  borrowAssets?: bigint;
288
345
  borrowShares?: bigint;
289
346
  slippageTolerance?: bigint;
290
- targetReallocations?: readonly VaultReallocation[];
347
+ targetReallocations?: BlueReallocationPlan;
291
348
  }) => {
292
349
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
293
- getRequirements: () => Promise<(Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
350
+ getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>> | Requirement)[]>;
294
351
  };
295
352
  /**
296
- * Fetches all on-chain data needed to construct a {@link ReallocationData}
353
+ * Fetches all on-chain data needed to construct a {@link VaultV1ReallocationData}
297
354
  * for computing vault reallocations via the public allocator.
298
355
  *
299
356
  * The target market is refetched internally at `block.number` so the
@@ -302,16 +359,33 @@ export interface BlueActions {
302
359
  * inject unnecessary `reallocateTo` actions (and their PublicAllocator
303
360
  * fees) into the resulting bundle.
304
361
  *
305
- * The returned reallocation data can be passed to {@link getReallocations}
306
- * to compute the `VaultReallocation[]` array for `borrow()` or
362
+ * The returned reallocation data can be passed to {@link getVaultV1Reallocations}
363
+ * to compute the `VaultV1Reallocation[]` array for `borrow()` or
307
364
  * `supplyCollateralBorrow()`.
308
365
  *
309
366
  * **Stale data reverts on-chain (fail-safe).**
310
367
  *
311
368
  * @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
312
369
  * @param params.block - The block to fetch data at (number and timestamp).
313
- * @returns A ReallocationData instance populated with all required data.
370
+ * @returns A VaultV1ReallocationData instance populated with all required data.
371
+ * @throws {ChainIdMismatchError} when the client chain does not match this market.
372
+ */
373
+ getVaultV1ReallocationData: (params: {
374
+ vaultAddresses: readonly Address[];
375
+ block: {
376
+ readonly number: bigint;
377
+ readonly timestamp: bigint;
378
+ };
379
+ }) => Promise<VaultV1ReallocationData>;
380
+ /**
381
+ * Fetches Vault V1 PublicAllocator state using the deprecated unversioned name.
382
+ *
383
+ * @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
384
+ * @param params.block.number - Block number used for every RPC read.
385
+ * @param params.block.timestamp - Timestamp corresponding to the fetched block.
386
+ * @returns A `VaultV1ReallocationData` snapshot populated from one block.
314
387
  * @throws {ChainIdMismatchError} when the client chain does not match this market.
388
+ * @deprecated Use {@link getVaultV1ReallocationData} instead.
315
389
  */
316
390
  getReallocationData: (params: {
317
391
  vaultAddresses: readonly Address[];
@@ -319,9 +393,34 @@ export interface BlueActions {
319
393
  readonly number: bigint;
320
394
  readonly timestamp: bigint;
321
395
  };
322
- }) => Promise<ReallocationData>;
396
+ }) => Promise<VaultV1ReallocationData>;
323
397
  /**
324
- * Computes vault reallocations for a borrow or withdraw on this market.
398
+ * Fetches Vault V2 BluePublicAllocator state for this target market.
399
+ *
400
+ * Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
401
+ * vault's BluePublicAllocator permissions and allocation caps at one block.
402
+ *
403
+ * @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
404
+ * @param params.block.number - Block number used for every RPC read.
405
+ * @param params.block.timestamp - Timestamp corresponding to the fetched block.
406
+ * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
407
+ * @throws {ChainIdMismatchError} when the client chain does not match this market.
408
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
409
+ * @throws {UnknownAddressError} when the chain has no BluePublicAllocator deployment.
410
+ * @throws {UnknownFactory} when the chain has no Vault V2 factory.
411
+ * @throws {UnknownOfFactory} when a requested address is not a Vault V2 from that factory.
412
+ * @throws {UnsupportedVaultV2AdapterError} when a vault contains an unsupported adapter.
413
+ * @throws {viem.BaseError} when an RPC or contract read fails with no fallback left.
414
+ */
415
+ getVaultV2BlueReallocationData: (params: {
416
+ vaultAddresses: readonly Address[];
417
+ block: {
418
+ readonly number: bigint;
419
+ readonly timestamp: bigint;
420
+ };
421
+ }) => Promise<VaultV2BlueReallocationData>;
422
+ /**
423
+ * Computes Vault V1 PublicAllocator reallocations for this market.
325
424
  *
326
425
  * Uses the shared-liquidity algorithm to determine which vaults should reallocate liquidity to
327
426
  * this market via the PublicAllocator, based on the post-operation utilization target.
@@ -329,7 +428,7 @@ export interface BlueActions {
329
428
  * Pass `{ borrowAmount }` for a borrow (legacy alias, equivalent to `{ operation: "borrow",
330
429
  * amount }`) or `{ operation: "withdraw", amount }` for a loan-asset withdraw.
331
430
  *
332
- * @param params.reallocationData - The current on-chain state (from {@link getReallocationData}).
431
+ * @param params.reallocationData - The current on-chain state (from {@link getVaultV1ReallocationData}).
333
432
  * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
334
433
  * Defaults to `"borrow"` when `borrowAmount` is provided.
335
434
  * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
@@ -342,28 +441,82 @@ export interface BlueActions {
342
441
  * or `withdraw()`. Empty array if no reallocation is needed.
343
442
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
344
443
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
444
+ * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds the target market supply.
345
445
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
346
446
  * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
447
+ * @example
448
+ * ```ts
449
+ * const reallocations = market.getVaultV1Reallocations({
450
+ * reallocationData,
451
+ * operation: "borrow",
452
+ * amount: 1_000_000n,
453
+ * });
454
+ * ```
347
455
  */
348
- getReallocations: (params: {
349
- reallocationData: ReallocationData;
350
- options?: ReallocationComputeOptions;
351
- } & ({
352
- operation: "borrow" | "withdraw";
353
- amount: bigint;
354
- borrowAmount?: never;
355
- } | {
356
- /** @deprecated Pass `{ operation: "borrow", amount }` instead. */
357
- borrowAmount: bigint;
358
- operation?: never;
359
- amount?: never;
360
- })) => readonly VaultReallocation[];
456
+ getVaultV1Reallocations: (params: VaultV1ReallocationsParams) => readonly VaultV1Reallocation[];
457
+ /**
458
+ * Computes Vault V1 PublicAllocator reallocations using the deprecated unversioned name.
459
+ *
460
+ * @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
461
+ * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
462
+ * @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
463
+ * @param params.borrowAmount - Deprecated borrow amount alias.
464
+ * @param params.options - Optional allocator and utilization options.
465
+ * @returns Vault V1 reallocations ready for a Blue action.
466
+ * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
467
+ * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
468
+ * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
469
+ * @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
470
+ * @throws {UnknownReallocationMarketError} when the target market is absent.
471
+ * @deprecated Use {@link getVaultV1Reallocations} instead.
472
+ * @example
473
+ * ```ts
474
+ * const reallocations = market.getReallocations({
475
+ * reallocationData,
476
+ * operation: "borrow",
477
+ * amount: 1_000_000n,
478
+ * });
479
+ * ```
480
+ */
481
+ getReallocations: (params: VaultV1ReallocationsParams) => readonly VaultV1Reallocation[];
482
+ /**
483
+ * Computes Vault V2 BluePublicAllocator reallocations for this market.
484
+ *
485
+ * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
486
+ * @param params.options - Optional allocator discovery controls and operation to support.
487
+ * @returns Action-ready reallocations and their post-simulation state.
488
+ * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
489
+ * @throws {NegativeInputError} when a utilization or penalty limit is negative.
490
+ * @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
491
+ * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
492
+ * @throws {UnknownReallocationMarketError} when a required market is absent.
493
+ * @throws {UnknownReallocationVaultError} when configured vault state is absent.
494
+ * @throws {UnknownReallocationPublicAllocatorConfigError} when allocator authorization state is absent.
495
+ * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent.
496
+ * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
497
+ * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
498
+ * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
499
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
500
+ * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
501
+ * @example
502
+ * ```ts
503
+ * const result = market.getVaultV2BlueReallocations({
504
+ * reallocationData,
505
+ * options: { operation: { type: "borrow", amount: 1_000_000n } },
506
+ * });
507
+ * ```
508
+ */
509
+ getVaultV2BlueReallocations: (params: VaultV2BlueReallocationsParams) => {
510
+ readonly reallocations: readonly VaultV2BlueReallocation[];
511
+ readonly data: VaultV2BlueReallocationData;
512
+ };
361
513
  }
362
514
  export declare class MorphoBlue implements BlueActions {
363
515
  private readonly client;
364
516
  readonly marketParams: MarketParams;
365
517
  private readonly chainId;
366
518
  constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
519
+ private getReallocationPenaltyRequirements;
367
520
  getMarketData(parameters?: FetchParameters): Promise<Market>;
368
521
  getPositionData(userAddress: Address, parameters?: FetchParameters): Promise<AccrualPosition>;
369
522
  supply({ amount, userAddress, nativeAmount, marketData, slippageTolerance, }: {
@@ -373,7 +526,7 @@ export declare class MorphoBlue implements BlueActions {
373
526
  } & DepositAmountArgs): {
374
527
  getRequirements: (params?: {
375
528
  useSimplePermit?: boolean;
376
- }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
529
+ }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
377
530
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyAction>>;
378
531
  };
379
532
  withdraw(params: {
@@ -381,9 +534,9 @@ export declare class MorphoBlue implements BlueActions {
381
534
  receiver?: Address;
382
535
  positionData: AccrualPosition;
383
536
  slippageTolerance?: bigint;
384
- reallocations?: readonly VaultReallocation[];
537
+ reallocations?: BlueReallocationPlan;
385
538
  } & AssetsOrSharesArgs): {
386
- getRequirements: () => Promise<(Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
539
+ getRequirements: () => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
387
540
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueWithdrawAction>>;
388
541
  };
389
542
  supplyCollateral({ amount, userAddress, nativeAmount, }: {
@@ -391,7 +544,7 @@ export declare class MorphoBlue implements BlueActions {
391
544
  } & DepositAmountArgs): {
392
545
  getRequirements: (params?: {
393
546
  useSimplePermit?: boolean;
394
- }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
547
+ }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
395
548
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralAction>>;
396
549
  };
397
550
  borrow({ amount, userAddress, positionData, slippageTolerance, reallocations, }: {
@@ -399,9 +552,9 @@ export declare class MorphoBlue implements BlueActions {
399
552
  userAddress: Address;
400
553
  positionData: AccrualPosition;
401
554
  slippageTolerance?: bigint;
402
- reallocations?: readonly VaultReallocation[];
555
+ reallocations?: BlueReallocationPlan;
403
556
  }): {
404
- getRequirements: () => Promise<(Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
557
+ getRequirements: () => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
405
558
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueBorrowAction>>;
406
559
  };
407
560
  repay(params: {
@@ -411,7 +564,7 @@ export declare class MorphoBlue implements BlueActions {
411
564
  } & RepayAmountArgs): {
412
565
  getRequirements: (reqParams?: {
413
566
  useSimplePermit?: boolean;
414
- }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
567
+ }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
415
568
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRepayAction>>;
416
569
  };
417
570
  withdrawCollateral({ userAddress, amount, positionData, }: {
@@ -429,7 +582,7 @@ export declare class MorphoBlue implements BlueActions {
429
582
  } & RepayAmountArgs): {
430
583
  getRequirements: (reqParams?: {
431
584
  useSimplePermit?: boolean;
432
- }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
585
+ }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
433
586
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
434
587
  };
435
588
  supplyCollateralBorrow({ amount, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance, reallocations, }: {
@@ -437,11 +590,11 @@ export declare class MorphoBlue implements BlueActions {
437
590
  positionData: AccrualPosition;
438
591
  borrowAmount: bigint;
439
592
  slippageTolerance?: bigint;
440
- reallocations?: readonly VaultReallocation[];
593
+ reallocations?: BlueReallocationPlan;
441
594
  } & DepositAmountArgs): {
442
595
  getRequirements: (params?: {
443
596
  useSimplePermit?: boolean;
444
- }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
597
+ }) => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
445
598
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
446
599
  };
447
600
  refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance, targetReallocations, }: {
@@ -455,35 +608,118 @@ export declare class MorphoBlue implements BlueActions {
455
608
  borrowAssets?: bigint;
456
609
  borrowShares?: bigint;
457
610
  slippageTolerance?: bigint;
458
- targetReallocations?: readonly VaultReallocation[];
611
+ targetReallocations?: BlueReallocationPlan;
459
612
  }): {
460
- getRequirements: () => Promise<(Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
613
+ getRequirements: () => Promise<(import("../../index.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../index.js").AuthorizationRequirementSignature, undefined>)[]>;
461
614
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
462
615
  };
463
616
  /**
464
617
  * Fetches all on-chain inputs needed to compute public allocator reallocations.
465
618
  *
466
- * @param params - Reallocation data fetch parameters.
467
619
  * @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
468
- * @param params.block - Block number and timestamp used for consistent RPC reads.
469
- * @returns Reallocation data ready for {@link getReallocations}.
620
+ * @param params.block.number - Block number used for every RPC read.
621
+ * @param params.block.timestamp - Timestamp corresponding to the fetched block.
622
+ * @returns Reallocation data ready for {@link getVaultV1Reallocations}.
623
+ * @throws {ChainIdMismatchError} when the client chain does not match this market.
624
+ * @example
625
+ * ```ts
626
+ * import { markets, vaults } from "@morpho-org/morpho-test";
627
+ * import { createPublicClient, http } from "viem";
628
+ * import { mainnet } from "viem/chains";
629
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
630
+ * import type { VaultV1ReallocationData } from "@morpho-org/morpho-sdk/entities";
631
+ *
632
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
633
+ * .extend(morphoViemExtension());
634
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
635
+ * const block = await client.getBlock();
636
+ * const data: VaultV1ReallocationData = await market.getVaultV1ReallocationData({
637
+ * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
638
+ * block,
639
+ * });
640
+ * ```
641
+ */
642
+ getVaultV1ReallocationData({ vaultAddresses, block, }: {
643
+ vaultAddresses: readonly Address[];
644
+ block: {
645
+ readonly number: bigint;
646
+ readonly timestamp: bigint;
647
+ };
648
+ }): Promise<VaultV1ReallocationData>;
649
+ /**
650
+ * Fetches Vault V1 PublicAllocator state using the deprecated unversioned name.
651
+ *
652
+ * @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
653
+ * @param params.block.number - Block number used for every RPC read.
654
+ * @param params.block.timestamp - Timestamp corresponding to the fetched block.
655
+ * @returns A `VaultV1ReallocationData` snapshot populated from one block.
470
656
  * @throws {ChainIdMismatchError} when the client chain does not match this market.
657
+ * @deprecated Use {@link getVaultV1ReallocationData} instead.
658
+ * @example
659
+ * ```ts
660
+ * const data = await market.getReallocationData({ vaultAddresses, block });
661
+ * // Equivalent to market.getVaultV1ReallocationData({ vaultAddresses, block }).
662
+ * ```
471
663
  */
472
- getReallocationData({ vaultAddresses, block, }: {
664
+ getReallocationData(params: {
473
665
  vaultAddresses: readonly Address[];
474
666
  block: {
475
667
  readonly number: bigint;
476
668
  readonly timestamp: bigint;
477
669
  };
478
- }): Promise<ReallocationData>;
670
+ }): Promise<VaultV1ReallocationData>;
479
671
  /**
480
- * Computes public allocator reallocations for a borrow or withdraw on this market.
672
+ * Fetches Vault V2 BluePublicAllocator state for this target market.
673
+ *
674
+ * Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
675
+ * vault's BluePublicAllocator permissions and allocation caps at one block.
676
+ *
677
+ * @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
678
+ * @param params.block.number - Block number used for every RPC read.
679
+ * @param params.block.timestamp - Timestamp corresponding to the fetched block.
680
+ * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
681
+ * @throws {ChainIdMismatchError} when the client chain does not match this market.
682
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
683
+ * @throws {UnknownAddressError} when the chain has no BluePublicAllocator deployment.
684
+ * @throws {UnknownFactory} when the chain has no Vault V2 factory.
685
+ * @throws {UnknownOfFactory} when a requested address is not a Vault V2 from that factory.
686
+ * @throws {UnsupportedVaultV2AdapterError} when a vault contains an unsupported adapter.
687
+ * @throws {viem.BaseError} when an RPC or contract read fails with no fallback left.
688
+ * @example
689
+ * ```ts
690
+ * import { markets } from "@morpho-org/morpho-test";
691
+ * import { createPublicClient, http } from "viem";
692
+ * import { mainnet } from "viem/chains";
693
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
694
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
695
+ *
696
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
697
+ * .extend(morphoViemExtension());
698
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
699
+ * const block = await client.getBlock();
700
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
701
+ * const data: VaultV2BlueReallocationData =
702
+ * await market.getVaultV2BlueReallocationData({
703
+ * vaultAddresses: [keyrockUsdcVaultV2],
704
+ * block,
705
+ * });
706
+ * ```
707
+ */
708
+ getVaultV2BlueReallocationData({ vaultAddresses, block, }: {
709
+ vaultAddresses: readonly Address[];
710
+ block: {
711
+ readonly number: bigint;
712
+ readonly timestamp: bigint;
713
+ };
714
+ }): Promise<VaultV2BlueReallocationData>;
715
+ /**
716
+ * Computes Vault V1 PublicAllocator reallocations for this market.
481
717
  *
482
718
  * Pass `{ borrowAmount }` for a borrow (legacy alias, equivalent to `{ operation: "borrow", amount }`)
483
719
  * or `{ operation, amount }` for a borrow or loan-asset withdraw.
484
720
  *
485
721
  * @param params - Reallocation computation parameters.
486
- * @param params.reallocationData - State returned by {@link getReallocationData}.
722
+ * @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
487
723
  * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
488
724
  * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
489
725
  * @param params.borrowAmount - {@deprecated Pass `{ operation: "borrow", amount }` instead.}
@@ -494,18 +730,71 @@ export declare class MorphoBlue implements BlueActions {
494
730
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
495
731
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
496
732
  * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
733
+ * @example
734
+ * ```ts
735
+ * const reallocations = market.getVaultV1Reallocations({
736
+ * reallocationData,
737
+ * operation: "borrow",
738
+ * amount: 1_000_000n,
739
+ * });
740
+ * ```
497
741
  */
498
- getReallocations(params: {
499
- reallocationData: ReallocationData;
500
- options?: ReallocationComputeOptions;
501
- } & ({
502
- operation: "borrow" | "withdraw";
503
- amount: bigint;
504
- borrowAmount?: never;
505
- } | {
506
- /** @deprecated Pass `{ operation: "borrow", amount }` instead. */
507
- borrowAmount: bigint;
508
- operation?: never;
509
- amount?: never;
510
- })): readonly VaultReallocation[];
742
+ getVaultV1Reallocations(params: VaultV1ReallocationsParams): readonly VaultV1Reallocation[];
743
+ /**
744
+ * Computes Vault V1 PublicAllocator reallocations using the deprecated unversioned name.
745
+ *
746
+ * @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
747
+ * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
748
+ * @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
749
+ * @param params.borrowAmount - Deprecated borrow amount alias.
750
+ * @param params.options - Optional allocator and utilization options.
751
+ * @returns Vault V1 reallocations ready for a Blue action.
752
+ * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
753
+ * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
754
+ * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
755
+ * @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
756
+ * @throws {UnknownReallocationMarketError} when the target market is absent.
757
+ * @deprecated Use {@link getVaultV1Reallocations} instead.
758
+ * @example
759
+ * ```ts
760
+ * const reallocations = market.getReallocations({
761
+ * reallocationData,
762
+ * operation: "borrow",
763
+ * amount: 1_000_000n,
764
+ * });
765
+ * ```
766
+ */
767
+ getReallocations(params: VaultV1ReallocationsParams): readonly VaultV1Reallocation[];
768
+ /**
769
+ * Computes Vault V2 BluePublicAllocator reallocations for this market.
770
+ *
771
+ * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
772
+ * @param params.options - Optional allocator discovery controls and operation to support.
773
+ * @returns Action-ready reallocations and their post-simulation state.
774
+ * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
775
+ * @throws {NegativeInputError} when a utilization or penalty limit is negative.
776
+ * @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
777
+ * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
778
+ * @throws {UnknownReallocationMarketError} when a required market is absent.
779
+ * @throws {UnknownReallocationVaultError} when configured vault state is absent.
780
+ * @throws {UnknownReallocationPublicAllocatorConfigError} when allocator authorization state is absent.
781
+ * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent.
782
+ * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
783
+ * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
784
+ * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
785
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
786
+ * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
787
+ * @example
788
+ * ```ts
789
+ * const result = market.getVaultV2BlueReallocations({
790
+ * reallocationData,
791
+ * options: { operation: { type: "borrow", amount: 1_000_000n } },
792
+ * });
793
+ * ```
794
+ */
795
+ getVaultV2BlueReallocations({ reallocationData, options, }: VaultV2BlueReallocationsParams): {
796
+ readonly reallocations: readonly VaultV2BlueReallocation[];
797
+ readonly data: VaultV2BlueReallocationData;
798
+ };
511
799
  }
800
+ export {};