@morpho-org/morpho-sdk 5.5.0 → 5.7.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 (168) hide show
  1. package/README.md +11 -7
  2. package/lib/cjs/abis.d.ts +15 -3
  3. package/lib/cjs/abis.js +15 -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/midnight/mempoolSubmitOffers.d.ts +2 -2
  17. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +2 -2
  18. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +1 -1
  19. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +1 -1
  20. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -1
  21. package/lib/cjs/blue/abis.d.ts +2 -0
  22. package/lib/cjs/blue/abis.js +33 -0
  23. package/lib/cjs/blue/addresses.d.ts +2 -0
  24. package/lib/cjs/blue/addresses.js +19 -0
  25. package/lib/cjs/blue/constants.d.ts +1 -0
  26. package/lib/cjs/blue/constants.js +13 -0
  27. package/lib/cjs/blue/entities.d.ts +2 -0
  28. package/lib/cjs/blue/entities.js +37 -0
  29. package/lib/cjs/blue/errors.d.ts +2 -0
  30. package/lib/cjs/blue/errors.js +29 -0
  31. package/lib/cjs/blue/fetch.d.ts +1 -0
  32. package/lib/cjs/blue/fetch.js +33 -0
  33. package/lib/cjs/blue/types.d.ts +2 -0
  34. package/lib/cjs/blue/types.js +2 -0
  35. package/lib/cjs/blue/utils.d.ts +3 -0
  36. package/lib/cjs/blue/utils.js +29 -0
  37. package/lib/cjs/bundler/actions.d.ts +122 -3
  38. package/lib/cjs/bundler/actions.js +216 -7
  39. package/lib/cjs/bundler/types.d.ts +20 -0
  40. package/lib/cjs/constants.d.ts +37 -3
  41. package/lib/cjs/constants.js +41 -1
  42. package/lib/cjs/entities/blue/blue.d.ts +362 -71
  43. package/lib/cjs/entities/blue/blue.js +286 -52
  44. package/lib/cjs/entities/index.d.ts +64 -4
  45. package/lib/cjs/entities/index.js +37 -22
  46. package/lib/cjs/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
  47. package/lib/cjs/entities/{reallocationData.js → vaultV1ReallocationData.js} +29 -16
  48. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +1 -1
  49. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -1
  50. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +511 -0
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1300 -0
  52. package/lib/cjs/errors.d.ts +48 -3
  53. package/lib/cjs/errors.js +62 -1
  54. package/lib/cjs/fetch.d.ts +16 -1
  55. package/lib/cjs/fetch.js +24 -1
  56. package/lib/{esm/helpers/computeReallocations.d.ts → cjs/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  57. package/lib/cjs/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +27 -13
  58. package/lib/cjs/helpers/constant.d.ts +5 -3
  59. package/lib/cjs/helpers/constant.js +6 -4
  60. package/lib/cjs/helpers/index.d.ts +2 -2
  61. package/lib/cjs/helpers/index.js +6 -3
  62. package/lib/cjs/helpers/validate.d.ts +32 -16
  63. package/lib/cjs/helpers/validate.js +142 -29
  64. package/lib/cjs/midnight/abis.d.ts +1 -0
  65. package/lib/cjs/midnight/abis.js +8 -0
  66. package/lib/cjs/midnight/constants.d.ts +1 -0
  67. package/lib/cjs/midnight/constants.js +19 -0
  68. package/lib/cjs/midnight/entities.d.ts +2 -0
  69. package/lib/cjs/midnight/entities.js +11 -0
  70. package/lib/cjs/midnight/errors.d.ts +1 -0
  71. package/lib/cjs/midnight/errors.js +24 -0
  72. package/lib/cjs/midnight/fetch.d.ts +1 -0
  73. package/lib/cjs/midnight/fetch.js +9 -0
  74. package/lib/cjs/midnight/types.d.ts +1 -0
  75. package/lib/cjs/midnight/types.js +2 -0
  76. package/lib/cjs/midnight/utils.d.ts +1 -0
  77. package/lib/cjs/midnight/utils.js +17 -0
  78. package/lib/cjs/types/action.d.ts +12 -0
  79. package/lib/cjs/types/error.d.ts +224 -5
  80. package/lib/cjs/types/error.js +269 -7
  81. package/lib/cjs/types/sharedLiquidity.d.ts +72 -8
  82. package/lib/cjs/types.d.ts +17 -2
  83. package/lib/cjs/utils.d.ts +31 -4
  84. package/lib/cjs/utils.js +44 -4
  85. package/lib/esm/abis.d.ts +15 -3
  86. package/lib/esm/abis.js +15 -3
  87. package/lib/esm/actions/blue/borrow.d.ts +21 -15
  88. package/lib/esm/actions/blue/borrow.js +26 -19
  89. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +1 -1
  90. package/lib/esm/actions/blue/buildAssetFundingActions.js +1 -1
  91. package/lib/esm/actions/blue/buildReallocationActions.d.ts +62 -19
  92. package/lib/esm/actions/blue/buildReallocationActions.js +119 -25
  93. package/lib/esm/actions/blue/refinance.d.ts +14 -7
  94. package/lib/esm/actions/blue/refinance.js +19 -11
  95. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +28 -19
  96. package/lib/esm/actions/blue/supplyCollateralBorrow.js +40 -24
  97. package/lib/esm/actions/blue/withdraw.d.ts +20 -13
  98. package/lib/esm/actions/blue/withdraw.js +24 -19
  99. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +2 -2
  100. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +2 -2
  101. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +1 -1
  102. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +1 -1
  103. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -1
  104. package/lib/esm/blue/abis.d.ts +2 -0
  105. package/lib/esm/blue/abis.js +2 -0
  106. package/lib/esm/blue/addresses.d.ts +2 -0
  107. package/lib/esm/blue/addresses.js +1 -0
  108. package/lib/esm/blue/constants.d.ts +1 -0
  109. package/lib/esm/blue/constants.js +1 -0
  110. package/lib/esm/blue/entities.d.ts +2 -0
  111. package/lib/esm/blue/entities.js +1 -0
  112. package/lib/esm/blue/errors.d.ts +2 -0
  113. package/lib/esm/blue/errors.js +2 -0
  114. package/lib/esm/blue/fetch.d.ts +1 -0
  115. package/lib/esm/blue/fetch.js +1 -0
  116. package/lib/esm/blue/types.d.ts +2 -0
  117. package/lib/esm/blue/types.js +1 -0
  118. package/lib/esm/blue/utils.d.ts +3 -0
  119. package/lib/esm/blue/utils.js +2 -0
  120. package/lib/esm/bundler/actions.d.ts +122 -3
  121. package/lib/esm/bundler/actions.js +219 -10
  122. package/lib/esm/bundler/types.d.ts +20 -0
  123. package/lib/esm/constants.d.ts +37 -3
  124. package/lib/esm/constants.js +37 -3
  125. package/lib/esm/entities/blue/blue.d.ts +362 -71
  126. package/lib/esm/entities/blue/blue.js +289 -55
  127. package/lib/esm/entities/index.d.ts +64 -4
  128. package/lib/esm/entities/index.js +19 -3
  129. package/lib/esm/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
  130. package/lib/esm/entities/{reallocationData.js → vaultV1ReallocationData.js} +32 -14
  131. package/lib/esm/entities/vaultV2/vaultV2.d.ts +1 -1
  132. package/lib/esm/entities/vaultV2/vaultV2.js +1 -1
  133. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +511 -0
  134. package/lib/esm/entities/vaultV2BlueReallocationData.js +1296 -0
  135. package/lib/esm/errors.d.ts +48 -3
  136. package/lib/esm/errors.js +48 -3
  137. package/lib/esm/fetch.d.ts +16 -1
  138. package/lib/esm/fetch.js +16 -1
  139. package/lib/{cjs/helpers/computeReallocations.d.ts → esm/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  140. package/lib/esm/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +25 -11
  141. package/lib/esm/helpers/constant.d.ts +5 -3
  142. package/lib/esm/helpers/constant.js +5 -3
  143. package/lib/esm/helpers/index.d.ts +2 -2
  144. package/lib/esm/helpers/index.js +2 -2
  145. package/lib/esm/helpers/validate.d.ts +32 -16
  146. package/lib/esm/helpers/validate.js +143 -32
  147. package/lib/esm/midnight/abis.d.ts +1 -0
  148. package/lib/esm/midnight/abis.js +1 -0
  149. package/lib/esm/midnight/constants.d.ts +1 -0
  150. package/lib/esm/midnight/constants.js +1 -0
  151. package/lib/esm/midnight/entities.d.ts +2 -0
  152. package/lib/esm/midnight/entities.js +1 -0
  153. package/lib/esm/midnight/errors.d.ts +1 -0
  154. package/lib/esm/midnight/errors.js +1 -0
  155. package/lib/esm/midnight/fetch.d.ts +1 -0
  156. package/lib/esm/midnight/fetch.js +1 -0
  157. package/lib/esm/midnight/types.d.ts +1 -0
  158. package/lib/esm/midnight/types.js +1 -0
  159. package/lib/esm/midnight/utils.d.ts +1 -0
  160. package/lib/esm/midnight/utils.js +1 -0
  161. package/lib/esm/types/action.d.ts +12 -0
  162. package/lib/esm/types/error.d.ts +224 -5
  163. package/lib/esm/types/error.js +253 -4
  164. package/lib/esm/types/sharedLiquidity.d.ts +72 -8
  165. package/lib/esm/types.d.ts +17 -2
  166. package/lib/esm/utils.d.ts +31 -4
  167. package/lib/esm/utils.js +31 -4
  168. package/package.json +23 -7
@@ -2,9 +2,9 @@ import { AccrualPosition, Market, type MarketId, Position, Vault, VaultMarketCon
2
2
  import type { Address } from "viem";
3
3
  import type { PublicAllocatorOptions, PublicReallocation, ReallocationComputeOptions } from "../types/index.js";
4
4
  /**
5
- * Input state required to construct {@link ReallocationData}.
5
+ * Input state required to construct {@link VaultV1ReallocationData}.
6
6
  */
7
- export interface InputReallocationData {
7
+ export interface InputVaultV1ReallocationData {
8
8
  /** Chain id associated with the fetched state. */
9
9
  readonly chainId: number;
10
10
  /** Markets indexed by market id. */
@@ -16,13 +16,19 @@ export interface InputReallocationData {
16
16
  /** Vault market configs indexed by vault address, then by market id. */
17
17
  readonly vaultMarketConfigs?: Readonly<Record<Address, Readonly<Record<MarketId, VaultMarketConfig | undefined>>>>;
18
18
  }
19
+ /**
20
+ * Deprecated input name for Vault V1 reallocation data.
21
+ *
22
+ * @deprecated Use {@link InputVaultV1ReallocationData} instead.
23
+ */
24
+ export type InputReallocationData = InputVaultV1ReallocationData;
19
25
  /**
20
26
  * Narrow state container for computing public allocator reallocations.
21
27
  *
22
28
  * @remarks
23
29
  * The class owns only the market, vault, position, vault-market-config,
24
30
  * and chain data needed by the shared-liquidity algorithm. Constructor inputs
25
- * are cloned, and simulation steps return cloned `ReallocationData` instances
31
+ * are cloned, and simulation steps return cloned `VaultV1ReallocationData` instances
26
32
  * so fetched caller inputs are not mutated.
27
33
  *
28
34
  * Public records are exposed for inspection and snapshotting only. Treat
@@ -30,7 +36,7 @@ export interface InputReallocationData {
30
36
  * contract keyed by market id or address; use the getters for typed absence
31
37
  * errors and use simulation methods to produce updated state.
32
38
  */
33
- export declare class ReallocationData implements InputReallocationData {
39
+ export declare class VaultV1ReallocationData implements InputVaultV1ReallocationData {
34
40
  /** Chain id associated with the fetched reallocation data. */
35
41
  readonly chainId: number;
36
42
  /** Markets indexed by market id. */
@@ -47,13 +53,13 @@ export declare class ReallocationData implements InputReallocationData {
47
53
  *
48
54
  * @param input - Reallocation input data fetched at a consistent chain state.
49
55
  */
50
- constructor(input: InputReallocationData);
56
+ constructor(input: InputVaultV1ReallocationData);
51
57
  /**
52
58
  * Creates a deep clone of this reallocation state.
53
59
  *
54
- * @returns A new `ReallocationData` instance with cloned entity objects.
60
+ * @returns A new `VaultV1ReallocationData` instance with cloned entity objects.
55
61
  */
56
- clone(): ReallocationData;
62
+ clone(): VaultV1ReallocationData;
57
63
  private forkAliasedState;
58
64
  /**
59
65
  * Gets a market by id.
@@ -131,7 +137,7 @@ export declare class ReallocationData implements InputReallocationData {
131
137
  * morphoViemExtension,
132
138
  * type PublicReallocation,
133
139
  * } from "@morpho-org/morpho-sdk";
134
- * import type { ReallocationData } from "@morpho-org/morpho-sdk/entities";
140
+ * import type { VaultV1ReallocationData } from "@morpho-org/morpho-sdk/entities";
135
141
  *
136
142
  * const client = createPublicClient({
137
143
  * chain: mainnet,
@@ -141,22 +147,35 @@ export declare class ReallocationData implements InputReallocationData {
141
147
  * const marketParams = markets[mainnet.id].usdc_wbtc;
142
148
  * const market = client.morpho.blue(marketParams, mainnet.id);
143
149
  * const block = await client.getBlock();
144
- * const reallocationData = await market.getReallocationData({
150
+ * const reallocationData = await market.getVaultV1ReallocationData({
145
151
  * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
146
152
  * block: { number: block.number, timestamp: block.timestamp },
147
153
  * });
148
154
  *
149
155
  * const result: {
150
156
  * withdrawals: readonly PublicReallocation[];
151
- * data: ReallocationData;
152
- * } = reallocationData.getMarketPublicReallocations(marketParams.id, {
157
+ * data: VaultV1ReallocationData;
158
+ * } = reallocationData.computeVaultV1Reallocations(marketParams.id, {
153
159
  * timestamp: block.timestamp,
154
160
  * });
155
161
  * ```
156
162
  */
163
+ computeVaultV1Reallocations(marketId: MarketId, options?: PublicAllocatorOptions): {
164
+ readonly withdrawals: readonly PublicReallocation[];
165
+ data: VaultV1ReallocationData;
166
+ };
167
+ /**
168
+ * Calculates Vault V1 public reallocations that can supply liquidity to `marketId`.
169
+ *
170
+ * @param marketId - Target market to supply with shared liquidity.
171
+ * @param options - Optional allocator discovery options.
172
+ * @returns Computed source-market withdrawals and the post-reallocation state.
173
+ * @throws {@link UnknownReallocationMarketError} when the target market is absent.
174
+ * @deprecated Use {@link computeVaultV1Reallocations} instead.
175
+ */
157
176
  getMarketPublicReallocations(marketId: MarketId, options?: PublicAllocatorOptions): {
158
177
  readonly withdrawals: readonly PublicReallocation[];
159
- data: ReallocationData;
178
+ data: VaultV1ReallocationData;
160
179
  };
161
180
  /**
162
181
  * Sums the public-allocator liquidity reallocatable into `marketId` from
@@ -186,7 +205,7 @@ export declare class ReallocationData implements InputReallocationData {
186
205
  * const marketParams = markets[mainnet.id].usdc_wbtc;
187
206
  * const market = client.morpho.blue(marketParams, mainnet.id);
188
207
  * const block = await client.getBlock();
189
- * const reallocationData = await market.getReallocationData({
208
+ * const reallocationData = await market.getVaultV1ReallocationData({
190
209
  * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
191
210
  * block: { number: block.number, timestamp: block.timestamp },
192
211
  * });
@@ -237,7 +256,7 @@ export declare class ReallocationData implements InputReallocationData {
237
256
  * const marketParams = markets[mainnet.id].usdc_wbtc;
238
257
  * const market = client.morpho.blue(marketParams, mainnet.id);
239
258
  * const block = await client.getBlock();
240
- * const reallocationData = await market.getReallocationData({
259
+ * const reallocationData = await market.getVaultV1ReallocationData({
241
260
  * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
242
261
  * block: { number: block.number, timestamp: block.timestamp },
243
262
  * });
@@ -282,5 +301,11 @@ export declare class ReallocationData implements InputReallocationData {
282
301
  readonly assets: bigint;
283
302
  };
284
303
  readonly timestamp: bigint;
285
- }): ReallocationData;
304
+ }): VaultV1ReallocationData;
286
305
  }
306
+ /**
307
+ * Deprecated class name for Vault V1 reallocation data.
308
+ *
309
+ * @deprecated Use {@link VaultV1ReallocationData} instead.
310
+ */
311
+ export { VaultV1ReallocationData as ReallocationData };
@@ -50,7 +50,7 @@ const cloneVaultMarketConfig = (config) => new VaultMarketConfig({
50
50
  * @remarks
51
51
  * The class owns only the market, vault, position, vault-market-config,
52
52
  * and chain data needed by the shared-liquidity algorithm. Constructor inputs
53
- * are cloned, and simulation steps return cloned `ReallocationData` instances
53
+ * are cloned, and simulation steps return cloned `VaultV1ReallocationData` instances
54
54
  * so fetched caller inputs are not mutated.
55
55
  *
56
56
  * Public records are exposed for inspection and snapshotting only. Treat
@@ -58,7 +58,7 @@ const cloneVaultMarketConfig = (config) => new VaultMarketConfig({
58
58
  * contract keyed by market id or address; use the getters for typed absence
59
59
  * errors and use simulation methods to produce updated state.
60
60
  */
61
- export class ReallocationData {
61
+ export class VaultV1ReallocationData {
62
62
  /** Chain id associated with the fetched reallocation data. */
63
63
  chainId;
64
64
  /** Markets indexed by market id. */
@@ -106,13 +106,13 @@ export class ReallocationData {
106
106
  /**
107
107
  * Creates a deep clone of this reallocation state.
108
108
  *
109
- * @returns A new `ReallocationData` instance with cloned entity objects.
109
+ * @returns A new `VaultV1ReallocationData` instance with cloned entity objects.
110
110
  */
111
111
  clone() {
112
- return new ReallocationData(this);
112
+ return new VaultV1ReallocationData(this);
113
113
  }
114
114
  forkAliasedState() {
115
- const data = new ReallocationData({ chainId: this.chainId });
115
+ const data = new VaultV1ReallocationData({ chainId: this.chainId });
116
116
  Object.assign(data.markets, this.markets);
117
117
  Object.assign(data.vaults, this.vaults);
118
118
  for (const [user, positions] of Object.entries(this.positions)) {
@@ -221,7 +221,7 @@ export class ReallocationData {
221
221
  * morphoViemExtension,
222
222
  * type PublicReallocation,
223
223
  * } from "@morpho-org/morpho-sdk";
224
- * import type { ReallocationData } from "@morpho-org/morpho-sdk/entities";
224
+ * import type { VaultV1ReallocationData } from "@morpho-org/morpho-sdk/entities";
225
225
  *
226
226
  * const client = createPublicClient({
227
227
  * chain: mainnet,
@@ -231,27 +231,27 @@ export class ReallocationData {
231
231
  * const marketParams = markets[mainnet.id].usdc_wbtc;
232
232
  * const market = client.morpho.blue(marketParams, mainnet.id);
233
233
  * const block = await client.getBlock();
234
- * const reallocationData = await market.getReallocationData({
234
+ * const reallocationData = await market.getVaultV1ReallocationData({
235
235
  * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
236
236
  * block: { number: block.number, timestamp: block.timestamp },
237
237
  * });
238
238
  *
239
239
  * const result: {
240
240
  * withdrawals: readonly PublicReallocation[];
241
- * data: ReallocationData;
242
- * } = reallocationData.getMarketPublicReallocations(marketParams.id, {
241
+ * data: VaultV1ReallocationData;
242
+ * } = reallocationData.computeVaultV1Reallocations(marketParams.id, {
243
243
  * timestamp: block.timestamp,
244
244
  * });
245
245
  * ```
246
246
  */
247
- getMarketPublicReallocations(marketId, options = {}) {
247
+ computeVaultV1Reallocations(marketId, options = {}) {
248
248
  const { enabled = true, timestamp, reallocatableVaults, defaultMaxWithdrawalUtilization = DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, maxWithdrawalUtilization = {}, } = options;
249
249
  if (!enabled)
250
250
  return { withdrawals: [], data: this };
251
251
  const accrualTimestamp = BigInt(timestamp ?? this.getMarket(marketId).lastUpdate);
252
252
  const configuredVaults = Object.keys(this.vaultMarketConfigs);
253
253
  const vaultKeyByLower = new Map(configuredVaults.map((vault) => [vault.toLowerCase(), vault]));
254
- const vaults = Array.from(new Set((reallocatableVaults ?? configuredVaults)
254
+ const vaults = Array.from(new Set([...(reallocatableVaults ?? configuredVaults)]
255
255
  .map((vault) => vaultKeyByLower.get(vault.toLowerCase()))
256
256
  .filter((vault) => vault != null))).filter((vault) => {
257
257
  const vaultMarketConfig = this.vaultMarketConfigs[vault]?.[marketId];
@@ -300,6 +300,18 @@ export class ReallocationData {
300
300
  });
301
301
  }
302
302
  }
303
+ /**
304
+ * Calculates Vault V1 public reallocations that can supply liquidity to `marketId`.
305
+ *
306
+ * @param marketId - Target market to supply with shared liquidity.
307
+ * @param options - Optional allocator discovery options.
308
+ * @returns Computed source-market withdrawals and the post-reallocation state.
309
+ * @throws {@link UnknownReallocationMarketError} when the target market is absent.
310
+ * @deprecated Use {@link computeVaultV1Reallocations} instead.
311
+ */
312
+ getMarketPublicReallocations(marketId, options = {}) {
313
+ return this.computeVaultV1Reallocations(marketId, options);
314
+ }
303
315
  /**
304
316
  * Sums the public-allocator liquidity reallocatable into `marketId` from
305
317
  * sibling markets.
@@ -328,7 +340,7 @@ export class ReallocationData {
328
340
  * const marketParams = markets[mainnet.id].usdc_wbtc;
329
341
  * const market = client.morpho.blue(marketParams, mainnet.id);
330
342
  * const block = await client.getBlock();
331
- * const reallocationData = await market.getReallocationData({
343
+ * const reallocationData = await market.getVaultV1ReallocationData({
332
344
  * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
333
345
  * block: { number: block.number, timestamp: block.timestamp },
334
346
  * });
@@ -340,7 +352,7 @@ export class ReallocationData {
340
352
  * ```
341
353
  */
342
354
  getPublicReallocationLiquidity(marketId, options) {
343
- const { withdrawals } = this.getMarketPublicReallocations(marketId, options);
355
+ const { withdrawals } = this.computeVaultV1Reallocations(marketId, options);
344
356
  return withdrawals.reduce((total, { assets }) => total + assets, 0n);
345
357
  }
346
358
  /**
@@ -382,7 +394,7 @@ export class ReallocationData {
382
394
  * const marketParams = markets[mainnet.id].usdc_wbtc;
383
395
  * const market = client.morpho.blue(marketParams, mainnet.id);
384
396
  * const block = await client.getBlock();
385
- * const reallocationData = await market.getReallocationData({
397
+ * const reallocationData = await market.getVaultV1ReallocationData({
386
398
  * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
387
399
  * block: { number: block.number, timestamp: block.timestamp },
388
400
  * });
@@ -513,3 +525,9 @@ export class ReallocationData {
513
525
  return data;
514
526
  }
515
527
  }
528
+ /**
529
+ * Deprecated class name for Vault V1 reallocation data.
530
+ *
531
+ * @deprecated Use {@link VaultV1ReallocationData} instead.
532
+ */
533
+ export { VaultV1ReallocationData as ReallocationData };
@@ -86,7 +86,7 @@ export interface VaultV2Actions {
86
86
  * multiple share burns. The SDK intentionally does not validate the user's share balance; size
87
87
  * it so `amount + BigInt(marketParamsList.length) <= vault.previewRedeem(sharesHeld)`. The
88
88
  * per-market term covers V2 withdrawal rounding and is not needed for V1. The share allowance
89
- * includes the penalty burns and accrual through the bundle deadline.
89
+ * includes that buffer, the penalty burns, and accrual through the bundle deadline.
90
90
  *
91
91
  * Idle balance, penalty, and adapter positions can drift after the snapshot, so an on-chain
92
92
  * under-coverage panic remains possible if vault state changes between preparation and inclusion.
@@ -205,11 +205,11 @@ export class MorphoVaultV2 {
205
205
  }
206
206
  let remaining = assetsToDeallocate;
207
207
  let peak = 0n;
208
- let requiredShareAllowance = 0n;
209
208
  const consumedMarketIds = new Set();
210
209
  const { vault: allowanceVault } = vaultData.accrueInterest(deadline);
211
210
  // Interest can lower the burn, while management fees can raise it; bound both endpoints.
212
211
  const previewAllowance = (assets) => MathLib.max(vaultData.toShares(assets, "Up"), allowanceVault.toShares(assets, "Up"));
212
+ let requiredShareAllowance = previewAllowance(BigInt(marketParamsListSnapshot.length));
213
213
  // Pre-burn previews upper-bound each separately rounded idle, penalty, and main burn.
214
214
  requiredShareAllowance += previewAllowance(idleAssets);
215
215
  for (const id of marketIdListSnapshot) {