@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.
- package/README.md +11 -7
- package/lib/cjs/abis.d.ts +15 -3
- package/lib/cjs/abis.js +15 -1
- package/lib/cjs/actions/blue/borrow.d.ts +21 -15
- package/lib/cjs/actions/blue/borrow.js +25 -18
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +1 -1
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +1 -1
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +62 -19
- package/lib/cjs/actions/blue/buildReallocationActions.js +123 -27
- package/lib/cjs/actions/blue/refinance.d.ts +14 -7
- package/lib/cjs/actions/blue/refinance.js +18 -10
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +28 -19
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +39 -23
- package/lib/cjs/actions/blue/withdraw.d.ts +20 -13
- package/lib/cjs/actions/blue/withdraw.js +23 -18
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +2 -2
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +2 -2
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +1 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -1
- package/lib/cjs/blue/abis.d.ts +2 -0
- package/lib/cjs/blue/abis.js +33 -0
- package/lib/cjs/blue/addresses.d.ts +2 -0
- package/lib/cjs/blue/addresses.js +19 -0
- package/lib/cjs/blue/constants.d.ts +1 -0
- package/lib/cjs/blue/constants.js +13 -0
- package/lib/cjs/blue/entities.d.ts +2 -0
- package/lib/cjs/blue/entities.js +37 -0
- package/lib/cjs/blue/errors.d.ts +2 -0
- package/lib/cjs/blue/errors.js +29 -0
- package/lib/cjs/blue/fetch.d.ts +1 -0
- package/lib/cjs/blue/fetch.js +33 -0
- package/lib/cjs/blue/types.d.ts +2 -0
- package/lib/cjs/blue/types.js +2 -0
- package/lib/cjs/blue/utils.d.ts +3 -0
- package/lib/cjs/blue/utils.js +29 -0
- package/lib/cjs/bundler/actions.d.ts +122 -3
- package/lib/cjs/bundler/actions.js +216 -7
- package/lib/cjs/bundler/types.d.ts +20 -0
- package/lib/cjs/constants.d.ts +37 -3
- package/lib/cjs/constants.js +41 -1
- package/lib/cjs/entities/blue/blue.d.ts +362 -71
- package/lib/cjs/entities/blue/blue.js +286 -52
- package/lib/cjs/entities/index.d.ts +64 -4
- package/lib/cjs/entities/index.js +37 -22
- package/lib/cjs/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
- package/lib/cjs/entities/{reallocationData.js → vaultV1ReallocationData.js} +29 -16
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +1 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +511 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +1300 -0
- package/lib/cjs/errors.d.ts +48 -3
- package/lib/cjs/errors.js +62 -1
- package/lib/cjs/fetch.d.ts +16 -1
- package/lib/cjs/fetch.js +24 -1
- package/lib/{esm/helpers/computeReallocations.d.ts → cjs/helpers/computeVaultV1Reallocations.d.ts} +14 -8
- package/lib/cjs/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +27 -13
- package/lib/cjs/helpers/constant.d.ts +5 -3
- package/lib/cjs/helpers/constant.js +6 -4
- package/lib/cjs/helpers/index.d.ts +2 -2
- package/lib/cjs/helpers/index.js +6 -3
- package/lib/cjs/helpers/validate.d.ts +32 -16
- package/lib/cjs/helpers/validate.js +142 -29
- package/lib/cjs/midnight/abis.d.ts +1 -0
- package/lib/cjs/midnight/abis.js +8 -0
- package/lib/cjs/midnight/constants.d.ts +1 -0
- package/lib/cjs/midnight/constants.js +19 -0
- package/lib/cjs/midnight/entities.d.ts +2 -0
- package/lib/cjs/midnight/entities.js +11 -0
- package/lib/cjs/midnight/errors.d.ts +1 -0
- package/lib/cjs/midnight/errors.js +24 -0
- package/lib/cjs/midnight/fetch.d.ts +1 -0
- package/lib/cjs/midnight/fetch.js +9 -0
- package/lib/cjs/midnight/types.d.ts +1 -0
- package/lib/cjs/midnight/types.js +2 -0
- package/lib/cjs/midnight/utils.d.ts +1 -0
- package/lib/cjs/midnight/utils.js +17 -0
- package/lib/cjs/types/action.d.ts +12 -0
- package/lib/cjs/types/error.d.ts +224 -5
- package/lib/cjs/types/error.js +269 -7
- package/lib/cjs/types/sharedLiquidity.d.ts +72 -8
- package/lib/cjs/types.d.ts +17 -2
- package/lib/cjs/utils.d.ts +31 -4
- package/lib/cjs/utils.js +44 -4
- package/lib/esm/abis.d.ts +15 -3
- package/lib/esm/abis.js +15 -3
- package/lib/esm/actions/blue/borrow.d.ts +21 -15
- package/lib/esm/actions/blue/borrow.js +26 -19
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +1 -1
- package/lib/esm/actions/blue/buildAssetFundingActions.js +1 -1
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +62 -19
- package/lib/esm/actions/blue/buildReallocationActions.js +119 -25
- package/lib/esm/actions/blue/refinance.d.ts +14 -7
- package/lib/esm/actions/blue/refinance.js +19 -11
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +28 -19
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +40 -24
- package/lib/esm/actions/blue/withdraw.d.ts +20 -13
- package/lib/esm/actions/blue/withdraw.js +24 -19
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +2 -2
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +2 -2
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +1 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -1
- package/lib/esm/blue/abis.d.ts +2 -0
- package/lib/esm/blue/abis.js +2 -0
- package/lib/esm/blue/addresses.d.ts +2 -0
- package/lib/esm/blue/addresses.js +1 -0
- package/lib/esm/blue/constants.d.ts +1 -0
- package/lib/esm/blue/constants.js +1 -0
- package/lib/esm/blue/entities.d.ts +2 -0
- package/lib/esm/blue/entities.js +1 -0
- package/lib/esm/blue/errors.d.ts +2 -0
- package/lib/esm/blue/errors.js +2 -0
- package/lib/esm/blue/fetch.d.ts +1 -0
- package/lib/esm/blue/fetch.js +1 -0
- package/lib/esm/blue/types.d.ts +2 -0
- package/lib/esm/blue/types.js +1 -0
- package/lib/esm/blue/utils.d.ts +3 -0
- package/lib/esm/blue/utils.js +2 -0
- package/lib/esm/bundler/actions.d.ts +122 -3
- package/lib/esm/bundler/actions.js +219 -10
- package/lib/esm/bundler/types.d.ts +20 -0
- package/lib/esm/constants.d.ts +37 -3
- package/lib/esm/constants.js +37 -3
- package/lib/esm/entities/blue/blue.d.ts +362 -71
- package/lib/esm/entities/blue/blue.js +289 -55
- package/lib/esm/entities/index.d.ts +64 -4
- package/lib/esm/entities/index.js +19 -3
- package/lib/esm/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
- package/lib/esm/entities/{reallocationData.js → vaultV1ReallocationData.js} +32 -14
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +1 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +511 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +1296 -0
- package/lib/esm/errors.d.ts +48 -3
- package/lib/esm/errors.js +48 -3
- package/lib/esm/fetch.d.ts +16 -1
- package/lib/esm/fetch.js +16 -1
- package/lib/{cjs/helpers/computeReallocations.d.ts → esm/helpers/computeVaultV1Reallocations.d.ts} +14 -8
- package/lib/esm/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +25 -11
- package/lib/esm/helpers/constant.d.ts +5 -3
- package/lib/esm/helpers/constant.js +5 -3
- package/lib/esm/helpers/index.d.ts +2 -2
- package/lib/esm/helpers/index.js +2 -2
- package/lib/esm/helpers/validate.d.ts +32 -16
- package/lib/esm/helpers/validate.js +143 -32
- package/lib/esm/midnight/abis.d.ts +1 -0
- package/lib/esm/midnight/abis.js +1 -0
- package/lib/esm/midnight/constants.d.ts +1 -0
- package/lib/esm/midnight/constants.js +1 -0
- package/lib/esm/midnight/entities.d.ts +2 -0
- package/lib/esm/midnight/entities.js +1 -0
- package/lib/esm/midnight/errors.d.ts +1 -0
- package/lib/esm/midnight/errors.js +1 -0
- package/lib/esm/midnight/fetch.d.ts +1 -0
- package/lib/esm/midnight/fetch.js +1 -0
- package/lib/esm/midnight/types.d.ts +1 -0
- package/lib/esm/midnight/types.js +1 -0
- package/lib/esm/midnight/utils.d.ts +1 -0
- package/lib/esm/midnight/utils.js +1 -0
- package/lib/esm/types/action.d.ts +12 -0
- package/lib/esm/types/error.d.ts +224 -5
- package/lib/esm/types/error.js +253 -4
- package/lib/esm/types/sharedLiquidity.d.ts +72 -8
- package/lib/esm/types.d.ts +17 -2
- package/lib/esm/utils.d.ts +31 -4
- package/lib/esm/utils.js +31 -4
- 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
|
|
5
|
+
* Input state required to construct {@link VaultV1ReallocationData}.
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
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 `
|
|
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
|
|
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:
|
|
56
|
+
constructor(input: InputVaultV1ReallocationData);
|
|
51
57
|
/**
|
|
52
58
|
* Creates a deep clone of this reallocation state.
|
|
53
59
|
*
|
|
54
|
-
* @returns A new `
|
|
60
|
+
* @returns A new `VaultV1ReallocationData` instance with cloned entity objects.
|
|
55
61
|
*/
|
|
56
|
-
clone():
|
|
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 {
|
|
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.
|
|
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:
|
|
152
|
-
* } = reallocationData.
|
|
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:
|
|
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.
|
|
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.
|
|
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
|
-
}):
|
|
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 `
|
|
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
|
|
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 `
|
|
109
|
+
* @returns A new `VaultV1ReallocationData` instance with cloned entity objects.
|
|
110
110
|
*/
|
|
111
111
|
clone() {
|
|
112
|
-
return new
|
|
112
|
+
return new VaultV1ReallocationData(this);
|
|
113
113
|
}
|
|
114
114
|
forkAliasedState() {
|
|
115
|
-
const data = new
|
|
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 {
|
|
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.
|
|
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:
|
|
242
|
-
* } = reallocationData.
|
|
241
|
+
* data: VaultV1ReallocationData;
|
|
242
|
+
* } = reallocationData.computeVaultV1Reallocations(marketParams.id, {
|
|
243
243
|
* timestamp: block.timestamp,
|
|
244
244
|
* });
|
|
245
245
|
* ```
|
|
246
246
|
*/
|
|
247
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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) {
|