@morpho-org/morpho-sdk 5.9.0 → 5.11.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 +6 -0
- package/lib/cjs/abis.d.ts +17 -2
- package/lib/cjs/abis.js +14 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/cjs/blue/abis.d.ts +5 -1
- package/lib/cjs/blue/abis.js +2 -0
- package/lib/cjs/blue/entities.d.ts +8 -2
- package/lib/cjs/blue/entities.js +1 -0
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +3 -1
- package/lib/cjs/blue/fetch.js +1 -0
- package/lib/cjs/entities/blue/blue.d.ts +10 -0
- package/lib/cjs/entities/blue/blue.js +9 -2
- package/lib/cjs/entities/index.d.ts +8 -2
- package/lib/cjs/entities/index.js +1 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/entities/midnight/midnight.js +5 -13
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +71 -12
- package/lib/cjs/entities/vaultV1/vaultV1.js +9 -2
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -0
- package/lib/cjs/entities/vaultV2/vaultV2.js +3 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +3 -2
- package/lib/cjs/fetch.d.ts +3 -1
- package/lib/cjs/fetch.js +1 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/cjs/helpers/metadata.d.ts +3 -5
- package/lib/cjs/helpers/metadata.js +4 -6
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/cjs/helpers/validate.d.ts +30 -8
- package/lib/cjs/helpers/validate.js +30 -8
- package/lib/cjs/types/action.d.ts +57 -4
- package/lib/cjs/types/error.d.ts +1 -1
- package/lib/cjs/types/error.js +2 -2
- package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
- package/lib/esm/abis.d.ts +17 -2
- package/lib/esm/abis.js +17 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
- package/lib/esm/blue/abis.d.ts +5 -1
- package/lib/esm/blue/abis.js +5 -1
- package/lib/esm/blue/entities.d.ts +8 -2
- package/lib/esm/blue/entities.js +3 -1
- package/lib/esm/blue/errors.d.ts +1 -1
- package/lib/esm/blue/errors.js +1 -1
- package/lib/esm/blue/fetch.d.ts +3 -1
- package/lib/esm/blue/fetch.js +3 -1
- package/lib/esm/entities/blue/blue.d.ts +10 -0
- package/lib/esm/entities/blue/blue.js +9 -2
- package/lib/esm/entities/index.d.ts +8 -2
- package/lib/esm/entities/index.js +3 -1
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/entities/midnight/midnight.js +5 -13
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +71 -12
- package/lib/esm/entities/vaultV1/vaultV1.js +9 -2
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -0
- package/lib/esm/entities/vaultV2/vaultV2.js +3 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/fetch.d.ts +3 -1
- package/lib/esm/fetch.js +3 -1
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/esm/helpers/metadata.d.ts +3 -5
- package/lib/esm/helpers/metadata.js +4 -6
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/esm/helpers/validate.d.ts +30 -8
- package/lib/esm/helpers/validate.js +30 -8
- package/lib/esm/types/action.d.ts +57 -4
- package/lib/esm/types/error.d.ts +1 -1
- package/lib/esm/types/error.js +2 -2
- package/lib/esm/types/sharedLiquidity.d.ts +2 -2
- package/package.json +8 -8
|
@@ -5,10 +5,10 @@ import type { FetchParameters } from "../../types/data.js";
|
|
|
5
5
|
import { type ActionOutput, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV1Actions {
|
|
7
7
|
/**
|
|
8
|
-
* Fetches
|
|
8
|
+
* Fetches direct onchain vault and allocation state without applying virtual interest.
|
|
9
9
|
*
|
|
10
10
|
* @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
|
|
11
|
-
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The
|
|
11
|
+
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The requested vault state.
|
|
12
12
|
*/
|
|
13
13
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
|
|
14
14
|
/**
|
|
@@ -85,6 +85,7 @@ export interface VaultV1Actions {
|
|
|
85
85
|
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
86
86
|
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
87
87
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
88
|
+
* @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
|
|
88
89
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
89
90
|
* @throws {NonPositiveInputError} when `amount` is not positive.
|
|
90
91
|
* @throws {EmptyMarketParamsListError} when the market list is empty.
|
|
@@ -134,18 +135,75 @@ export interface VaultV1Actions {
|
|
|
134
135
|
readonly deadline?: bigint;
|
|
135
136
|
}) => ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
136
137
|
/**
|
|
137
|
-
* Prepares
|
|
138
|
+
* Prepares an atomic migration of Vault V1 shares to Vault V2 through bundler3.
|
|
138
139
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
140
|
+
* Accrues the source snapshot before converting V1 shares to assets so pending Vault V1
|
|
141
|
+
* performance-fee shares are reflected in both migration bounds. Projects the target Vault V2
|
|
142
|
+
* two hours forward when computing the deposit-leg maximum share price.
|
|
141
143
|
*
|
|
142
|
-
* @param
|
|
143
|
-
* @param
|
|
144
|
-
*
|
|
145
|
-
* @param
|
|
146
|
-
* @param
|
|
147
|
-
*
|
|
148
|
-
* @
|
|
144
|
+
* @param params - Migration parameters.
|
|
145
|
+
* @param params.userAddress - Account whose Vault V1 shares are migrated and that receives Vault
|
|
146
|
+
* V2 shares.
|
|
147
|
+
* @param params.sourceVault - Pre-fetched Vault V1 state with market allocations for local accrual.
|
|
148
|
+
* @param params.targetVault - Pre-fetched Vault V2 accrual snapshot with the same underlying
|
|
149
|
+
* asset.
|
|
150
|
+
* @param params.shares - Positive number of Vault V1 shares to migrate.
|
|
151
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to
|
|
152
|
+
* `DEFAULT_SLIPPAGE_TOLERANCE` and cannot exceed 10%.
|
|
153
|
+
* @returns Lazy approval or permit resolution through `getRequirements()` and a synchronous
|
|
154
|
+
* `buildTx()` returning a deep-frozen `Transaction<VaultV1MigrateToV2Action>`.
|
|
155
|
+
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
156
|
+
* @throws {UnsupportedBlueMarketIrmError} when an allocated source or target market with positive debt uses an unsupported IRM.
|
|
157
|
+
* @throws {VaultAddressMismatchError} when `sourceVault` belongs to another vault.
|
|
158
|
+
* @throws {VaultAssetMismatchError} when the source and target assets differ.
|
|
159
|
+
* @throws {NonPositiveInputError} when `shares` is not positive or the target projection yields
|
|
160
|
+
* no shares.
|
|
161
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
162
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
163
|
+
* @throws {UnknownBlueMarketAllocationError} when `sourceVault.withdrawQueue` references a market
|
|
164
|
+
* absent from `sourceVault.allocations`.
|
|
165
|
+
* @throws {UnsupportedChainIdError} from `getRequirements()` or `buildTx()` when the chain has no
|
|
166
|
+
* address registry.
|
|
167
|
+
* @throws {viem.BaseError} from `getRequirements()` when an RPC contract read fails.
|
|
168
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is
|
|
169
|
+
* supplied.
|
|
170
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when several permit signatures
|
|
171
|
+
* are supplied.
|
|
172
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when a supplied permit targets another
|
|
173
|
+
* token.
|
|
174
|
+
* @throws {DepositAmountMismatchError} from `buildTx()` when a supplied permit covers another
|
|
175
|
+
* amount.
|
|
176
|
+
* @throws {Permit2ExpirationMissingError} from `buildTx()` when a Permit2 signature lacks an
|
|
177
|
+
* expiration.
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* import {
|
|
181
|
+
* morphoViemExtension,
|
|
182
|
+
* type Transaction,
|
|
183
|
+
* type VaultV1MigrateToV2Action,
|
|
184
|
+
* } from "@morpho-org/morpho-sdk";
|
|
185
|
+
* import { createPublicClient, http } from "viem";
|
|
186
|
+
* import { mainnet } from "viem/chains";
|
|
187
|
+
*
|
|
188
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
|
|
189
|
+
* morphoViemExtension(),
|
|
190
|
+
* );
|
|
191
|
+
* const sourceVaultAddress = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
192
|
+
* const targetVaultAddress = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
193
|
+
* const userAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
|
|
194
|
+
* const source = client.morpho.vaultV1(sourceVaultAddress, mainnet.id);
|
|
195
|
+
* const [sourceVault, targetVault] = await Promise.all([
|
|
196
|
+
* source.getData(),
|
|
197
|
+
* client.morpho.vaultV2(targetVaultAddress, mainnet.id).getData(),
|
|
198
|
+
* ]);
|
|
199
|
+
* const { buildTx } = source.migrateToV2({
|
|
200
|
+
* userAddress,
|
|
201
|
+
* sourceVault,
|
|
202
|
+
* targetVault,
|
|
203
|
+
* shares: 1_000_000n,
|
|
204
|
+
* });
|
|
205
|
+
* const tx: Readonly<Transaction<VaultV1MigrateToV2Action>> = buildTx();
|
|
206
|
+
* ```
|
|
149
207
|
*/
|
|
150
208
|
migrateToV2: (params: {
|
|
151
209
|
userAddress: Address;
|
|
@@ -194,6 +252,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
194
252
|
readonly userAddress: Address;
|
|
195
253
|
readonly deadline?: bigint;
|
|
196
254
|
}): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
255
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
197
256
|
migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance, }: {
|
|
198
257
|
userAddress: Address;
|
|
199
258
|
sourceVault: AccrualVault;
|
|
@@ -159,6 +159,8 @@ class MorphoVaultV1 {
|
|
|
159
159
|
const allocation = vaultData.allocations.get(marketId);
|
|
160
160
|
if (allocation?.config.enabled !== true)
|
|
161
161
|
continue;
|
|
162
|
+
if (allocation.position.supplyShares === 0n)
|
|
163
|
+
continue;
|
|
162
164
|
const market = allocation.position.market.accrueInterest(now);
|
|
163
165
|
const available = market.toSupplyAssets(allocation.position.supplyShares);
|
|
164
166
|
const assigned = assignedByMarket.get(marketId) ?? 0n;
|
|
@@ -287,6 +289,7 @@ class MorphoVaultV1 {
|
|
|
287
289
|
},
|
|
288
290
|
};
|
|
289
291
|
}
|
|
292
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
290
293
|
migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, }) {
|
|
291
294
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
292
295
|
if (!(0, viem_1.isAddressEqual)(sourceVault.address, this.vault)) {
|
|
@@ -299,8 +302,12 @@ class MorphoVaultV1 {
|
|
|
299
302
|
throw new index_js_3.NonPositiveInputError("shares", shares);
|
|
300
303
|
}
|
|
301
304
|
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
302
|
-
//
|
|
303
|
-
const
|
|
305
|
+
// V1 redeem accrues pending market interest and performance fees before converting shares.
|
|
306
|
+
const sourceAccrualTimestamp = sourceVault.allocations
|
|
307
|
+
.values()
|
|
308
|
+
.reduce((timestamp, { position }) => blue_sdk_1.MathLib.max(timestamp, position.market.lastUpdate), morpho_ts_1.Time.timestamp());
|
|
309
|
+
const accruedSourceVault = sourceVault.accrueInterest(sourceAccrualTimestamp);
|
|
310
|
+
const v1RefAssets = accruedSourceVault.toAssets(shares);
|
|
304
311
|
const minSharePriceVaultV1 = blue_sdk_1.MathLib.mulDivDown(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), shares);
|
|
305
312
|
// Compute maxSharePriceVaultV2 for V2 deposit (slippage upward).
|
|
306
313
|
// Accrue VaultV2 interest forward to bound the on-chain share price at execution.
|
|
@@ -130,10 +130,13 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
130
130
|
* Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
|
|
131
131
|
* on-chain `reallocateTo` fee semantics: one fee charge per vault with at
|
|
132
132
|
* least one computed withdrawal.
|
|
133
|
+
* Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
|
|
134
|
+
* are skipped before projecting source interest.
|
|
133
135
|
*
|
|
134
136
|
* @param marketId - Target market to supply with shared liquidity.
|
|
135
137
|
* @param options - Optional allocator discovery options.
|
|
136
138
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
139
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
137
140
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
138
141
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
139
142
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -179,6 +182,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
179
182
|
* @param marketId - Target market to supply with shared liquidity.
|
|
180
183
|
* @param options - Optional allocator discovery options.
|
|
181
184
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
185
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
182
186
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
183
187
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
184
188
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -199,6 +203,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
199
203
|
* @param marketId - Target market that would receive the liquidity.
|
|
200
204
|
* @param options - Optional allocator discovery options.
|
|
201
205
|
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
206
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
202
207
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
203
208
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
204
209
|
* `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
|
|
@@ -252,6 +257,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
252
257
|
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
253
258
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
254
259
|
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
260
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
255
261
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
256
262
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
257
263
|
* `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
|
|
@@ -213,10 +213,13 @@ class VaultV1ReallocationData {
|
|
|
213
213
|
* Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
|
|
214
214
|
* on-chain `reallocateTo` fee semantics: one fee charge per vault with at
|
|
215
215
|
* least one computed withdrawal.
|
|
216
|
+
* Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
|
|
217
|
+
* are skipped before projecting source interest.
|
|
216
218
|
*
|
|
217
219
|
* @param marketId - Target market to supply with shared liquidity.
|
|
218
220
|
* @param options - Optional allocator discovery options.
|
|
219
221
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
222
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
220
223
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
221
224
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
222
225
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -314,6 +317,7 @@ class VaultV1ReallocationData {
|
|
|
314
317
|
* @param marketId - Target market to supply with shared liquidity.
|
|
315
318
|
* @param options - Optional allocator discovery options.
|
|
316
319
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
320
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
317
321
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
318
322
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
319
323
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -333,6 +337,7 @@ class VaultV1ReallocationData {
|
|
|
333
337
|
* @param marketId - Target market that would receive the liquidity.
|
|
334
338
|
* @param options - Optional allocator discovery options.
|
|
335
339
|
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
340
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
336
341
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
337
342
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
338
343
|
* `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
|
|
@@ -389,6 +394,7 @@ class VaultV1ReallocationData {
|
|
|
389
394
|
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
390
395
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
391
396
|
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
397
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
392
398
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
393
399
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
394
400
|
* `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
|
|
@@ -446,25 +452,34 @@ class VaultV1ReallocationData {
|
|
|
446
452
|
getLargestVaultWithdrawal({ vault, marketId, withdrawals, defaultMaxWithdrawalUtilization, maxWithdrawalUtilization, timestamp, }) {
|
|
447
453
|
return (0, morpho_ts_1._try)(() => {
|
|
448
454
|
const { cap, pendingCap, publicAllocatorConfig } = this.getVaultMarketConfig(vault, marketId);
|
|
455
|
+
const maxIn = publicAllocatorConfig?.maxIn ?? 0n;
|
|
449
456
|
const validCap = pendingCap.validAt >= timestamp
|
|
450
457
|
? blue_sdk_1.MathLib.min(pendingCap.value, cap)
|
|
451
458
|
: cap;
|
|
459
|
+
if (maxIn === 0n || validCap === 0n)
|
|
460
|
+
return { vault };
|
|
452
461
|
const suppliable = blue_sdk_1.MathLib.zeroFloorSub(validCap, this.getAccrualPosition(vault, marketId).accrueInterest(timestamp)
|
|
453
462
|
.supplyAssets);
|
|
463
|
+
if (suppliable === 0n)
|
|
464
|
+
return { vault };
|
|
454
465
|
const marketWithdrawals = this.getVault(vault)
|
|
455
466
|
.withdrawQueue.filter((srcMarketId) => srcMarketId !== marketId &&
|
|
456
467
|
!withdrawals.some((withdrawal) => withdrawal.id === srcMarketId && withdrawal.vault === vault))
|
|
457
468
|
.map((srcMarketId) => {
|
|
458
469
|
const withdrawal = (0, morpho_ts_1._try)(() => {
|
|
459
|
-
const srcPosition = this.getAccrualPosition(vault, srcMarketId).accrueInterest(timestamp);
|
|
460
|
-
const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
|
|
461
|
-
defaultMaxWithdrawalUtilization);
|
|
462
470
|
const srcConfig = this.getVaultMarketConfig(vault, srcMarketId);
|
|
463
|
-
|
|
471
|
+
const maxOut = srcConfig.publicAllocatorConfig?.maxOut ?? 0n;
|
|
472
|
+
if (!srcConfig.enabled || maxOut === 0n)
|
|
473
|
+
return { id: srcMarketId, assets: 0n };
|
|
474
|
+
const rawSrcPosition = this.getAccrualPosition(vault, srcMarketId);
|
|
475
|
+
if (rawSrcPosition.supplyShares === 0n)
|
|
464
476
|
return { id: srcMarketId, assets: 0n };
|
|
477
|
+
const srcPosition = rawSrcPosition.accrueInterest(timestamp);
|
|
478
|
+
const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
|
|
479
|
+
defaultMaxWithdrawalUtilization);
|
|
465
480
|
return {
|
|
466
481
|
id: srcMarketId,
|
|
467
|
-
assets: blue_sdk_1.MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable,
|
|
482
|
+
assets: blue_sdk_1.MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable, maxIn, maxOut),
|
|
468
483
|
};
|
|
469
484
|
}, blue_sdk_1.UnknownDataError);
|
|
470
485
|
return withdrawal ?? { id: srcMarketId, assets: 0n };
|
|
@@ -30,6 +30,7 @@ export interface VaultV2Actions {
|
|
|
30
30
|
* @returns {Object} The result object.
|
|
31
31
|
* @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
|
|
32
32
|
* @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>} returns.getRequirements The function for retrieving all required approval transactions.
|
|
33
|
+
* @throws {UnsupportedBlueMarketIrmError} when an underlying market with positive debt uses an unsupported IRM.
|
|
33
34
|
*/
|
|
34
35
|
deposit: (params: {
|
|
35
36
|
userAddress: Address;
|
|
@@ -101,6 +102,7 @@ export interface VaultV2Actions {
|
|
|
101
102
|
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
102
103
|
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
103
104
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
105
|
+
* @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
|
|
104
106
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
105
107
|
* @throws {NonPositiveInputError} when `amount` is not positive.
|
|
106
108
|
* @throws {InKindRedeemZeroDeallocationError} when the vault has no idle assets and the
|
|
@@ -176,7 +176,9 @@ class MorphoVaultV2 {
|
|
|
176
176
|
if (assetsToDeallocate > 0n && marketParamsListSnapshot.length === 0) {
|
|
177
177
|
throw new index_js_3.EmptyMarketParamsListError();
|
|
178
178
|
}
|
|
179
|
-
const assetsByMarket = new Map(soleAdapter.markets
|
|
179
|
+
const assetsByMarket = new Map(soleAdapter.markets
|
|
180
|
+
.filter((market) => (soleAdapter.supplyShares[market.id] ?? 0n) !== 0n)
|
|
181
|
+
.map((market) => [
|
|
180
182
|
market.id,
|
|
181
183
|
market
|
|
182
184
|
.accrueInterest(now)
|
|
@@ -363,7 +363,11 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
363
363
|
* utilization defaults to 90% and is configurable through
|
|
364
364
|
* `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
|
|
365
365
|
* `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
|
|
366
|
-
* considered.
|
|
366
|
+
* considered. Targets with no remaining supply or allocator capacity are skipped before
|
|
367
|
+
* projecting source interest. The adapter's minimum share minting requirement, supply-share
|
|
368
|
+
* limits, and target absolute or zero relative caps are checked against a one-asset deposit.
|
|
369
|
+
* Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
|
|
370
|
+
* allocation does not increase after rounding.
|
|
367
371
|
*
|
|
368
372
|
* Shared-cap discovery is conservative. Operation planning searches at most
|
|
369
373
|
* 1,024 base units above its targeted amount for the nearest executable fit.
|
|
@@ -374,6 +378,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
374
378
|
* @param marketId - Target Blue market id.
|
|
375
379
|
* @param options - Optional discovery controls and operation to support.
|
|
376
380
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
381
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
377
382
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
378
383
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
379
384
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
@@ -430,6 +435,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
430
435
|
* @param marketId - Target Blue market id.
|
|
431
436
|
* @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
|
|
432
437
|
* @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
|
|
438
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
433
439
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
434
440
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
435
441
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -470,6 +476,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
470
476
|
* @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
|
|
471
477
|
* @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
|
|
472
478
|
* @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
|
|
479
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
473
480
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
474
481
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
475
482
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -107,7 +107,11 @@ const cloneAdapter = (adapter, markets) => {
|
|
|
107
107
|
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter)
|
|
108
108
|
return new blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter({ ...base, marketParamsList: [...adapter.marketParamsList] }, adapter.positions.map((position) => clonePosition(position, markets)));
|
|
109
109
|
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter)
|
|
110
|
-
return new blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter({
|
|
110
|
+
return new blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter({
|
|
111
|
+
...base,
|
|
112
|
+
morphoVaultV1: adapter.morphoVaultV1,
|
|
113
|
+
parentAllocation: adapter.parentAllocation,
|
|
114
|
+
}, cloneAccrualVault(adapter.accrualVaultV1, markets), adapter.shares);
|
|
111
115
|
throw new blue_sdk_1.UnsupportedVaultV2AdapterError(adapter.address);
|
|
112
116
|
};
|
|
113
117
|
const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
|
|
@@ -571,7 +575,11 @@ class VaultV2BlueReallocationData {
|
|
|
571
575
|
* utilization defaults to 90% and is configurable through
|
|
572
576
|
* `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
|
|
573
577
|
* `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
|
|
574
|
-
* considered.
|
|
578
|
+
* considered. Targets with no remaining supply or allocator capacity are skipped before
|
|
579
|
+
* projecting source interest. The adapter's minimum share minting requirement, supply-share
|
|
580
|
+
* limits, and target absolute or zero relative caps are checked against a one-asset deposit.
|
|
581
|
+
* Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
|
|
582
|
+
* allocation does not increase after rounding.
|
|
575
583
|
*
|
|
576
584
|
* Shared-cap discovery is conservative. Operation planning searches at most
|
|
577
585
|
* 1,024 base units above its targeted amount for the nearest executable fit.
|
|
@@ -582,6 +590,7 @@ class VaultV2BlueReallocationData {
|
|
|
582
590
|
* @param marketId - Target Blue market id.
|
|
583
591
|
* @param options - Optional discovery controls and operation to support.
|
|
584
592
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
593
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
585
594
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
586
595
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
587
596
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
@@ -722,9 +731,7 @@ class VaultV2BlueReallocationData {
|
|
|
722
731
|
: BigInt(options.timestamp);
|
|
723
732
|
let data = this;
|
|
724
733
|
let simulationContext = context;
|
|
725
|
-
data.setMarkets(
|
|
726
|
-
.filter((market) => market != null)
|
|
727
|
-
.map((market) => market.accrueInterest(timestamp)));
|
|
734
|
+
data.setMarkets([data.getMarket(marketId).accrueInterest(timestamp)]);
|
|
728
735
|
const reallocations = [];
|
|
729
736
|
const configuredVaults = Object.keys(data.vaults);
|
|
730
737
|
const vaultKeyByLower = new Map(configuredVaults.map((vault) => [vault.toLowerCase(), vault]));
|
|
@@ -759,6 +766,7 @@ class VaultV2BlueReallocationData {
|
|
|
759
766
|
activeAdaptersCache.set(vaultAddress, activeAdapters);
|
|
760
767
|
}
|
|
761
768
|
const targetSupplyHeadroom = blue_sdk_1.MathLib.zeroFloorSub(blue_sdk_1.MathLib.MAX_UINT_128, targetMarket.totalSupplyAssets);
|
|
769
|
+
const minimumSupply = targetMarket.supply(1n, 0n);
|
|
762
770
|
const rawCandidates = [];
|
|
763
771
|
// Missing nested allocator state means the snapshot is incomplete, so
|
|
764
772
|
// typed getter errors below must propagate. Only explicit zero caps or
|
|
@@ -780,17 +788,35 @@ class VaultV2BlueReallocationData {
|
|
|
780
788
|
const adapterCapAllocation = data.getAllocation(vaultAddress, adapterCapId);
|
|
781
789
|
const collateralCapAllocation = data.getAllocation(vaultAddress, collateralCapId);
|
|
782
790
|
const adapterMarketCapAllocation = data.getAllocation(vaultAddress, adapterMarketCapId);
|
|
783
|
-
|
|
791
|
+
const targetAllocations = [
|
|
784
792
|
adapterCapAllocation,
|
|
785
793
|
collateralCapAllocation,
|
|
786
794
|
adapterMarketCapAllocation,
|
|
787
|
-
]
|
|
795
|
+
];
|
|
796
|
+
if (targetAllocations.some(({ absoluteCap }) => absoluteCap === 0n))
|
|
788
797
|
continue;
|
|
789
798
|
const expectedSupplyAssets = targetMarket.toSupplyAssets(adapter.supplyShares[marketId] ?? 0n);
|
|
790
799
|
const untracked = blue_sdk_1.MathLib.zeroFloorSub(expectedSupplyAssets, adapterMarketCapAllocation.allocation);
|
|
791
800
|
const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation + untracked);
|
|
801
|
+
const minimumAllocation = minimumSupply.market.toSupplyAssets((adapter.supplyShares[marketId] ?? 0n) + minimumSupply.shares);
|
|
802
|
+
const minimumAllocationChange = minimumAllocation - adapterMarketCapAllocation.allocation;
|
|
803
|
+
const blockedTargetIds = targetAllocations
|
|
804
|
+
.filter(({ allocation, absoluteCap, relativeCap }) => {
|
|
805
|
+
const nextAllocation = allocation + minimumAllocationChange;
|
|
806
|
+
return (nextAllocation > absoluteCap ||
|
|
807
|
+
(relativeCap === 0n && nextAllocation > 0n));
|
|
808
|
+
})
|
|
809
|
+
.map(({ id }) => id);
|
|
810
|
+
// MorphoMarketV1AdapterV2 rejects supplies that mint fewer shares than assets.
|
|
811
|
+
if (targetSupplyHeadroom === 0n ||
|
|
812
|
+
allocatorHeadroom === 0n ||
|
|
813
|
+
minimumSupply.shares < minimumSupply.assets ||
|
|
814
|
+
minimumSupply.market.totalSupplyShares > blue_sdk_1.MathLib.MAX_UINT_128 ||
|
|
815
|
+
blockedTargetIds.includes(adapterMarketCapId))
|
|
816
|
+
continue;
|
|
792
817
|
if (publicAllocatorConfig.canPullFromIdle &&
|
|
793
|
-
availableIdleAssets > 0n
|
|
818
|
+
availableIdleAssets > 0n &&
|
|
819
|
+
blockedTargetIds.length === 0) {
|
|
794
820
|
const assets = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, availableIdleAssets);
|
|
795
821
|
if (assets > 0n) {
|
|
796
822
|
rawCandidates.push({
|
|
@@ -826,8 +852,16 @@ class VaultV2BlueReallocationData {
|
|
|
826
852
|
const sourceAllocations = sourceIds.map((id) => data.getAllocation(vaultAddress, id));
|
|
827
853
|
if (sourceAllocations.some(({ allocation }) => allocation === 0n))
|
|
828
854
|
continue;
|
|
829
|
-
const
|
|
830
|
-
|
|
855
|
+
const sourceSupplyShares = sourceAdapter.supplyShares[sourceMarket.id] ?? 0n;
|
|
856
|
+
if (sourceSupplyShares === 0n)
|
|
857
|
+
continue;
|
|
858
|
+
// A withdrawal can create target headroom only for shared cap IDs.
|
|
859
|
+
if (blockedTargetIds.some((id) => !sourceIds.includes(id)))
|
|
860
|
+
continue;
|
|
861
|
+
const accruedSourceMarket = sourceMarket.accrueInterest(timestamp);
|
|
862
|
+
data.setMarkets([accruedSourceMarket]);
|
|
863
|
+
const expectedSourceSupplyAssets = accruedSourceMarket.toSupplyAssets(sourceSupplyShares);
|
|
864
|
+
const assets = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, expectedSourceSupplyAssets, accruedSourceMarket.getWithdrawToUtilization(maxWithdrawalUtilization));
|
|
831
865
|
if (assets <= 0n)
|
|
832
866
|
continue;
|
|
833
867
|
rawCandidates.push({
|
|
@@ -848,9 +882,6 @@ class VaultV2BlueReallocationData {
|
|
|
848
882
|
for (const reallocation of rawCandidates) {
|
|
849
883
|
let lower = 0n;
|
|
850
884
|
let upper = reallocation.assets;
|
|
851
|
-
// MorphoMarketV1AdapterV2 rejects supplies that mint fewer shares than assets.
|
|
852
|
-
if (targetMarket.toSupplyShares(upper, "Down") < upper)
|
|
853
|
-
continue;
|
|
854
885
|
const reallocationAdapter = data.getAdapter(reallocation.vault, reallocation.to.adapter);
|
|
855
886
|
const targetIds = getAdapterIds(adapterIdsCache, reallocationAdapter, targetMarket);
|
|
856
887
|
const sourceIds = new Set();
|
|
@@ -954,6 +985,7 @@ class VaultV2BlueReallocationData {
|
|
|
954
985
|
* @param marketId - Target Blue market id.
|
|
955
986
|
* @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
|
|
956
987
|
* @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
|
|
988
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
957
989
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
958
990
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
959
991
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -1006,6 +1038,7 @@ class VaultV2BlueReallocationData {
|
|
|
1006
1038
|
* @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
|
|
1007
1039
|
* @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
|
|
1008
1040
|
* @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
|
|
1041
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
1009
1042
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
1010
1043
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
1011
1044
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
package/lib/cjs/errors.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ UnknownTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError,
|
|
|
14
14
|
/** @deprecated Use UnknownBlueTokenPriceError or the raw protocol subpath. */
|
|
15
15
|
UnknownTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError,
|
|
16
16
|
/** @deprecated Use UnknownBlueVaultConfigError or the raw protocol subpath. */
|
|
17
|
-
UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
|
|
17
|
+
UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
|
|
18
18
|
/** @deprecated Use UnsupportedBluePreLiquidationParamsError or the raw protocol subpath. */
|
|
19
19
|
UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError,
|
|
20
20
|
/** @deprecated Use UnsupportedBlueVaultV2AdapterError or the raw protocol subpath. */
|
package/lib/cjs/errors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.DivisionByZeroError = exports._try = exports.UnknownCollateralIndexError = exports.UnknownMidnightCollateralIndexError = exports.TickOutOfRangeError = exports.MidnightTickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.MidnightSettlementFeeExceedsPriceError = exports.PriceGreaterThanOneError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidTreeHeightError = void 0;
|
|
3
|
+
exports.InvalidTreeError = exports.InvalidMidnightTreeError = exports.InvalidTickSpacingError = exports.InvalidMidnightTickSpacingError = exports.InvalidPositionLossFactorError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidMidnightOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownBlueVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownBlueTokenPriceError = exports.UnknownTokenError = exports.UnknownBlueTokenError = exports.UnknownOfFactory = exports.UnknownBlueOfFactory = exports.UnknownMarketParamsError = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownFactory = exports.UnknownBlueFactory = exports.UnknownDataError = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidMarketParamsError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
|
|
4
|
+
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.DivisionByZeroError = exports._try = exports.UnknownCollateralIndexError = exports.UnknownMidnightCollateralIndexError = exports.TickOutOfRangeError = exports.MidnightTickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.MidnightSettlementFeeExceedsPriceError = exports.PriceGreaterThanOneError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidMidnightTreeHeightError = void 0;
|
|
5
5
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
|
|
7
7
|
Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
|
|
@@ -32,6 +32,7 @@ Object.defineProperty(exports, "UnknownBlueVaultConfigError", { enumerable: true
|
|
|
32
32
|
/** @deprecated Use UnknownBlueVaultConfigError or the raw protocol subpath. */
|
|
33
33
|
Object.defineProperty(exports, "UnknownVaultConfigError", { enumerable: true, get: function () { return blue_sdk_1.UnknownVaultConfigError; } });
|
|
34
34
|
Object.defineProperty(exports, "UnsupportedChainIdError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedChainIdError; } });
|
|
35
|
+
Object.defineProperty(exports, "UnsupportedBlueMarketIrmError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedMarketIrmError; } });
|
|
35
36
|
Object.defineProperty(exports, "UnsupportedBluePreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
|
|
36
37
|
/** @deprecated Use UnsupportedBluePreLiquidationParamsError or the raw protocol subpath. */
|
|
37
38
|
Object.defineProperty(exports, "UnsupportedPreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
|
package/lib/cjs/fetch.d.ts
CHANGED
|
@@ -12,5 +12,7 @@ fetchPreLiquidationParams, fetchPreLiquidationPosition as fetchBluePreLiquidatio
|
|
|
12
12
|
/** @deprecated Use `fetchBluePreLiquidationPosition` or the raw `/blue/fetch` subpath. */
|
|
13
13
|
fetchPreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser,
|
|
14
14
|
/** @deprecated Use `fetchBlueUser` or the raw `/blue/fetch` subpath. */
|
|
15
|
-
fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig,
|
|
15
|
+
fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig,
|
|
16
|
+
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `fetchVaultV2BlueMarketPublicAllocatorConfig`. */
|
|
17
|
+
fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
|
16
18
|
export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
|
package/lib/cjs/fetch.js
CHANGED
|
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "fetchVault", { enumerable: true, get: function (
|
|
|
35
35
|
Object.defineProperty(exports, "fetchVaultConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultConfig; } });
|
|
36
36
|
Object.defineProperty(exports, "fetchVaultMarketAllocation", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultMarketAllocation; } });
|
|
37
37
|
Object.defineProperty(exports, "fetchVaultMarketConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultMarketConfig; } });
|
|
38
|
+
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `fetchVaultV2BlueMarketPublicAllocatorConfig`. */
|
|
38
39
|
Object.defineProperty(exports, "fetchVaultMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultMarketPublicAllocatorConfig; } });
|
|
39
40
|
Object.defineProperty(exports, "fetchVaultUser", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultUser; } });
|
|
40
41
|
Object.defineProperty(exports, "fetchVaultV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2; } });
|
|
@@ -22,6 +22,7 @@ import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../ty
|
|
|
22
22
|
* @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
|
|
23
23
|
* @param params.options - Optional reallocation computation options.
|
|
24
24
|
* @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
|
|
25
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
25
26
|
* @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.
|
|
26
27
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
|
|
27
28
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
@@ -78,6 +79,7 @@ export declare const computeVaultV1Reallocations: ({ reallocationData: data, mar
|
|
|
78
79
|
/**
|
|
79
80
|
* Deprecated name for the Vault V1 amount-aware reallocation planner.
|
|
80
81
|
*
|
|
82
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
81
83
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
82
84
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
83
85
|
*/
|
|
@@ -78,6 +78,7 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
78
78
|
* @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
|
|
79
79
|
* @param params.options - Optional reallocation computation options.
|
|
80
80
|
* @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
|
|
81
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
81
82
|
* @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.
|
|
82
83
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
|
|
83
84
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
@@ -243,6 +244,7 @@ exports.computeVaultV1Reallocations = computeVaultV1Reallocations;
|
|
|
243
244
|
/**
|
|
244
245
|
* Deprecated name for the Vault V1 amount-aware reallocation planner.
|
|
245
246
|
*
|
|
247
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
246
248
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
247
249
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
248
250
|
*/
|
|
@@ -26,11 +26,9 @@ import type { Metadata } from "../types/index.js";
|
|
|
26
26
|
* @param {Metadata} metadata - An object containing optional metadata fields
|
|
27
27
|
* such as `timestamp` and `origin`.
|
|
28
28
|
*
|
|
29
|
-
* @returns
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* If no `data` is present in the original transaction, the function returns
|
|
33
|
-
* the transaction unmodified.
|
|
29
|
+
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
30
|
+
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
31
|
+
* with `data` containing any appended metadata. The input is never mutated.
|
|
34
32
|
*/
|
|
35
33
|
export declare function addTransactionMetadata(tx: {
|
|
36
34
|
data: Hex;
|
|
@@ -29,15 +29,13 @@ const viem_1 = require("viem");
|
|
|
29
29
|
* @param {Metadata} metadata - An object containing optional metadata fields
|
|
30
30
|
* such as `timestamp` and `origin`.
|
|
31
31
|
*
|
|
32
|
-
* @returns
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* If no `data` is present in the original transaction, the function returns
|
|
36
|
-
* the transaction unmodified.
|
|
32
|
+
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
33
|
+
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
34
|
+
* with `data` containing any appended metadata. The input is never mutated.
|
|
37
35
|
*/
|
|
38
36
|
function addTransactionMetadata(tx, metadata) {
|
|
39
37
|
const { data, ..._tx } = tx;
|
|
40
|
-
if (!data)
|
|
38
|
+
if (!data || data === "0x")
|
|
41
39
|
return tx;
|
|
42
40
|
const concatItems = [data];
|
|
43
41
|
if (metadata.timestamp) {
|
|
@@ -35,6 +35,7 @@ export interface VaultV2InKindRedeemMarketPreview {
|
|
|
35
35
|
* @param params.requestedExitAssets - Positive penalty-inclusive amount the user wants to exit.
|
|
36
36
|
* @param params.timestamp - Timestamp used to accrue Morpho Blue markets before calculating capacity.
|
|
37
37
|
* @returns Frontend-ready market choices, or an empty list when no choices are available.
|
|
38
|
+
* @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
|
|
38
39
|
* @example
|
|
39
40
|
* ```ts
|
|
40
41
|
* import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
|