@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.2
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/MIGRATION-v5-to-v6.md +127 -16
- package/README.md +17 -11
- package/lib/cjs/abis.d.ts +17 -2
- package/lib/cjs/abis.js +14 -1
- package/lib/cjs/actions/blue/common.js +5 -26
- package/lib/cjs/actions/blue/supply.js +2 -7
- package/lib/cjs/actions/bundles/common.d.ts +32 -2
- package/lib/cjs/actions/bundles/common.js +68 -30
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +20 -20
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -27
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -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 +15 -6
- package/lib/cjs/entities/blue/blue.js +3 -0
- package/lib/cjs/entities/index.d.ts +8 -2
- package/lib/cjs/entities/index.js +1 -0
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +1 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +10 -5
- package/lib/cjs/entities/vaultV1/vaultV1.js +13 -1
- 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 +140 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +229 -16
- 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/index.d.ts +3 -1
- package/lib/cjs/helpers/index.js +10 -1
- package/lib/cjs/helpers/metadata.d.ts +3 -5
- package/lib/cjs/helpers/metadata.js +4 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/cjs/helpers/slippage.d.ts +46 -0
- package/lib/cjs/helpers/slippage.js +65 -0
- package/lib/cjs/helpers/validate.d.ts +65 -8
- package/lib/cjs/helpers/validate.js +83 -9
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/types/action.d.ts +95 -13
- package/lib/cjs/types/error.d.ts +290 -12
- package/lib/cjs/types/error.js +312 -24
- package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
- package/lib/cjs/utils.d.ts +3 -1
- package/lib/cjs/utils.js +10 -1
- package/lib/esm/abis.d.ts +17 -2
- package/lib/esm/abis.js +17 -2
- package/lib/esm/actions/blue/common.js +7 -28
- package/lib/esm/actions/blue/supply.js +4 -9
- package/lib/esm/actions/bundles/common.d.ts +32 -2
- package/lib/esm/actions/bundles/common.js +68 -31
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -28
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -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 +15 -6
- package/lib/esm/entities/blue/blue.js +3 -0
- package/lib/esm/entities/index.d.ts +8 -2
- package/lib/esm/entities/index.js +3 -1
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +10 -5
- package/lib/esm/entities/vaultV1/vaultV1.js +14 -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 +140 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +234 -21
- 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/index.d.ts +3 -1
- package/lib/esm/helpers/index.js +3 -1
- package/lib/esm/helpers/metadata.d.ts +3 -5
- package/lib/esm/helpers/metadata.js +4 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/esm/helpers/slippage.d.ts +46 -0
- package/lib/esm/helpers/slippage.js +65 -1
- package/lib/esm/helpers/validate.d.ts +65 -8
- package/lib/esm/helpers/validate.js +82 -10
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/types/action.d.ts +95 -13
- package/lib/esm/types/error.d.ts +290 -12
- package/lib/esm/types/error.js +301 -19
- package/lib/esm/types/sharedLiquidity.d.ts +2 -2
- package/lib/esm/utils.d.ts +3 -1
- package/lib/esm/utils.js +3 -1
- package/package.json +7 -7
- /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
- /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
|
@@ -37,6 +37,7 @@ export interface VaultV2Actions {
|
|
|
37
37
|
* two hours from handle creation.
|
|
38
38
|
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
|
|
39
39
|
* transaction builder.
|
|
40
|
+
* @throws {UnsupportedBlueMarketIrmError} when required interest projection encounters an unsupported IRM.
|
|
40
41
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
41
42
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
42
43
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
@@ -48,8 +49,8 @@ export interface VaultV2Actions {
|
|
|
48
49
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
49
50
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
50
51
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
51
|
-
* @throws {
|
|
52
|
-
*
|
|
52
|
+
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the
|
|
53
|
+
* owner is consumed and none was passed explicitly.
|
|
53
54
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
54
55
|
* explicit Permit2 nonce is consumed.
|
|
55
56
|
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
@@ -242,16 +243,18 @@ export interface VaultV2Actions {
|
|
|
242
243
|
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
243
244
|
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
244
245
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
246
|
+
* @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
|
|
245
247
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
246
|
-
* @throws {NonPositiveInputError} when `amount` is not positive.
|
|
248
|
+
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
247
249
|
* @throws {InKindRedeemZeroDeallocationError} when the vault has no idle assets and the
|
|
248
250
|
* penalty-adjusted amount rounds to zero deallocated assets.
|
|
249
251
|
* @throws {EmptyMarketParamsListError} when assets must be deallocated and the market list is empty.
|
|
252
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
250
253
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
251
254
|
* requirement resolution.
|
|
252
|
-
* @throws {
|
|
255
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
|
|
253
256
|
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
254
|
-
* @throws {
|
|
257
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
255
258
|
* @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
|
|
256
259
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
257
260
|
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
@@ -294,29 +297,129 @@ export interface VaultV2Actions {
|
|
|
294
297
|
readonly deadline?: bigint;
|
|
295
298
|
}) => ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
296
299
|
/**
|
|
297
|
-
* Prepares a
|
|
300
|
+
* Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
|
|
298
301
|
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
+
* The contract withdraws everything the vault can pay without a penalty — its idle assets plus
|
|
303
|
+
* the liquidity available through its liquidity adapter — then force-deallocates the remainder by
|
|
304
|
+
* looping over the adapter's markets. It computes the deallocations itself: the caller supplies
|
|
305
|
+
* neither a market list nor an order.
|
|
302
306
|
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
307
|
+
* `exitAssets` is **penalty-inclusive**, matching `inKindRedeem`. The contract debits it from the
|
|
308
|
+
* user's position but pays out only
|
|
309
|
+
* `assetsToWithdraw + floor((exitAssets - assetsToWithdraw) * WAD / (WAD + penalty))`, minus the
|
|
310
|
+
* referral fee. Quote the split with `previewVaultV2ForceWithdraw`.
|
|
311
|
+
*
|
|
312
|
+
* The vault must have exactly one `MorphoMarketV1AdapterV2` and route liquidity through that same
|
|
313
|
+
* adapter or none at all. Call `getRequirements()` before `buildTx()` so the vault-share allowance
|
|
314
|
+
* and permit nonce are read on-chain.
|
|
315
|
+
*
|
|
316
|
+
* Unless `minSharePriceE27` is overridden, the SDK derives a conservative lower bound on the
|
|
317
|
+
* realized exit share price from the snapshot and `slippageTolerance`. The bound rejects a share
|
|
318
|
+
* price drop, a penalty increase, and liquidity shifting from the penalty-free leg to the
|
|
319
|
+
* penalised leg. It does **not** cover the referral fee, which the contract deducts afterwards.
|
|
320
|
+
*
|
|
321
|
+
* Vault gates are enforced by the final transaction and are not preflighted: the receive-assets
|
|
322
|
+
* gate must allow VaultExitBundlesV1 and may depend on its transient initiator, while a
|
|
323
|
+
* send-shares gate is arbitrary code re-evaluated after each penalty burn. The SDK also does not
|
|
324
|
+
* validate the user's share balance. Per-market penalties and each vault withdrawal round the
|
|
325
|
+
* share burn up independently, so the exit can burn marginally more shares than `exitAssets` alone
|
|
326
|
+
* implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)` — the approved
|
|
327
|
+
* share allowance this handle returns is the exact upper bound on the burn — so a full-balance
|
|
328
|
+
* exit does not revert for insufficient shares.
|
|
329
|
+
*
|
|
330
|
+
* Idle balance, penalty, adapter positions, and market liquidity can drift after the snapshot, so
|
|
331
|
+
* an on-chain revert remains possible if vault state changes between preparation and inclusion.
|
|
332
|
+
* A fee-recipient `userAddress` gets a floor from the net share burn after fee mints at `now`,
|
|
333
|
+
* and a guard against fee mints reaching the lower burn bound by the deadline. Its allowance
|
|
334
|
+
* includes the projected fee shares through that same deadline. Deadlines beyond one year after
|
|
335
|
+
* handle creation are rejected, so the guard and allowance cover the whole accepted window.
|
|
336
|
+
*
|
|
337
|
+
* @param params - Force withdrawal parameters.
|
|
338
|
+
* @param params.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
|
|
339
|
+
* @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
340
|
+
* @param params.userAddress - Account that signs and submits the exit, and receives the assets.
|
|
341
|
+
* @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
|
|
342
|
+
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
343
|
+
* Deadlines more than one year after handle creation are rejected.
|
|
344
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance applied to the derived share
|
|
345
|
+
* price bound. Defaults to `DEFAULT_SLIPPAGE_TOLERANCE`, capped at `MAX_SLIPPAGE_TOLERANCE`.
|
|
346
|
+
* @param params.minSharePriceE27 - Optional RAY-scaled override of the derived bound. Must be
|
|
347
|
+
* positive: the contract reads `0` as "no bound", so it cannot be used to opt out.
|
|
348
|
+
* @param params.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
|
|
349
|
+
* `referralFeeRecipient`. Defaults to `0n`.
|
|
350
|
+
* @param params.referralFeeRecipient - Optional referral fee recipient, required when
|
|
351
|
+
* `referralFeePct` is positive.
|
|
352
|
+
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
353
|
+
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
354
|
+
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
355
|
+
* @throws {NonPositiveInputError} when `exitAssets`, `deadline`, or a supplied
|
|
356
|
+
* `minSharePriceE27` is not positive.
|
|
357
|
+
* @throws {NegativeInputError} when `slippageTolerance` or `referralFeePct` is negative.
|
|
358
|
+
* @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or the effective
|
|
359
|
+
* `minSharePriceE27` (supplied or derived) exceeds `uint256`, or when `referralFeePct` is not
|
|
360
|
+
* below WAD, or when `deadline` is more than one year after handle creation.
|
|
361
|
+
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
362
|
+
* requirement resolution.
|
|
363
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
364
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
|
|
365
|
+
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
366
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
367
|
+
* @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
|
|
368
|
+
* another adapter.
|
|
369
|
+
* @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
|
|
370
|
+
* as `MarketParams`.
|
|
371
|
+
* @throws {VaultV2ForceWithdrawZeroWithdrawalError} when the exit would withdraw nothing.
|
|
372
|
+
* @throws {VaultV2ForceWithdrawCoverageError} when the adapter's markets cannot cover the exit,
|
|
373
|
+
* which would overrun the contract's unbounded loop.
|
|
374
|
+
* @throws {VaultV2ForceWithdrawZeroSharePriceError} when the derived share-price floor rounds down
|
|
375
|
+
* to zero, which the contract would read as no bound at all.
|
|
376
|
+
* @throws {VaultV2ForceWithdrawFeeSharesExceedBurnError} when fee shares are minted to a
|
|
377
|
+
* fee-recipient `userAddress` and reach the lower-bound share burn at the deadline.
|
|
378
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
|
|
379
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
380
|
+
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
381
|
+
* @throws {viem.BaseError} from `getRequirements()` when an RPC or multicall contract read fails.
|
|
382
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
383
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
384
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender, amount, or
|
|
385
|
+
* deadline differs from this operation. Any handle built from the same inputs accepts the
|
|
386
|
+
* permit; the nonce is verified onchain by the vault's `permit`.
|
|
387
|
+
* @throws {VaultExitBundlesV1PermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
391
|
+
*
|
|
392
|
+
* const vault = client.morpho.vaultV2(vaultAddress, 1);
|
|
393
|
+
* const vaultData = await vault.getData();
|
|
394
|
+
* const exit = vault.forceWithdraw({
|
|
395
|
+
* exitAssets: 1_000_000n,
|
|
396
|
+
* vaultData,
|
|
397
|
+
* userAddress,
|
|
398
|
+
* });
|
|
399
|
+
* const signatures = [];
|
|
400
|
+
* for (const requirement of await exit.getRequirements()) {
|
|
401
|
+
* if (isRequirementSignature(requirement)) {
|
|
402
|
+
* signatures.push(await requirement.sign(walletClient, userAddress));
|
|
403
|
+
* } else {
|
|
404
|
+
* const hash = await walletClient.sendTransaction(requirement);
|
|
405
|
+
* await client.waitForTransactionReceipt({ hash });
|
|
406
|
+
* }
|
|
407
|
+
* }
|
|
408
|
+
* const tx = exit.buildTx(signatures);
|
|
409
|
+
* // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
|
|
410
|
+
* ```
|
|
310
411
|
*/
|
|
311
|
-
forceWithdraw: (params: {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
412
|
+
readonly forceWithdraw: (params: {
|
|
413
|
+
readonly exitAssets: bigint;
|
|
414
|
+
readonly vaultData: AccrualVaultV2;
|
|
415
|
+
readonly userAddress: Address;
|
|
416
|
+
readonly adapter?: Address;
|
|
417
|
+
readonly deadline?: bigint;
|
|
418
|
+
readonly slippageTolerance?: bigint;
|
|
419
|
+
readonly minSharePriceE27?: bigint;
|
|
420
|
+
readonly referralFeePct?: bigint;
|
|
421
|
+
readonly referralFeeRecipient?: Address;
|
|
422
|
+
}) => ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
|
|
320
423
|
/**
|
|
321
424
|
* Prepares a force redeem transaction for the VaultV2 contract using the vault's native multicall.
|
|
322
425
|
*
|
|
@@ -398,15 +501,18 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
398
501
|
readonly adapter?: Address;
|
|
399
502
|
readonly deadline?: bigint;
|
|
400
503
|
}): ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
504
|
+
/** {@inheritDoc VaultV2Actions.forceWithdraw} */
|
|
505
|
+
forceWithdraw({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance, minSharePriceE27: minSharePriceE27Override, referralFeePct, referralFeeRecipient, }: {
|
|
506
|
+
readonly exitAssets: bigint;
|
|
507
|
+
readonly vaultData: AccrualVaultV2;
|
|
508
|
+
readonly userAddress: Address;
|
|
509
|
+
readonly adapter?: Address;
|
|
510
|
+
readonly deadline?: bigint;
|
|
511
|
+
readonly slippageTolerance?: bigint;
|
|
512
|
+
readonly minSharePriceE27?: bigint;
|
|
513
|
+
readonly referralFeePct?: bigint;
|
|
514
|
+
readonly referralFeeRecipient?: Address;
|
|
515
|
+
}): ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
|
|
410
516
|
forceRedeem({ deallocations, redeem, userAddress, }: {
|
|
411
517
|
deallocations: readonly Deallocation[];
|
|
412
518
|
redeem: {
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { AccrualVaultV2MorphoMarketV1AdapterV2, DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MarketUtils, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { erc2612Abi, fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
4
|
-
import { erc20Abi, isAddressEqual } from "viem";
|
|
4
|
+
import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
|
|
5
5
|
import { multicall } from "viem/actions";
|
|
6
|
-
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
6
|
+
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
7
|
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2InKindRedeem, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
|
|
8
|
-
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
|
-
import { validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
10
|
-
import { AdapterNotPartOfVaultError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError,
|
|
8
|
+
import { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
|
+
import { validateDeadline, validateNativeVaultAsset, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
|
|
10
|
+
import { AdapterNotPartOfVaultError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InKindRedeemZeroDeallocationError, InputExceedsMaxError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, selectRequirementSignatures, VaultAddressMismatchError, VaultV2ForceWithdrawCoverageError, VaultV2ForceWithdrawFeeSharesExceedBurnError, VaultV2ForceWithdrawZeroWithdrawalError, VaultV2SingleAdapterRequiredError, VaultV2UndecodableLiquidityDataError, VaultV2UnsupportedExitAdapterError, VaultV2UnsupportedLiquidityAdapterError, } from "../../types/index.js";
|
|
11
11
|
import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
|
|
12
12
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
13
|
+
// Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
|
|
14
|
+
// accrual model stays well-defined inside it.
|
|
15
|
+
const VAULT_V2_FEE_PROJECTION_HORIZON = Time.s.from.y(1n);
|
|
13
16
|
export class MorphoVaultV2 {
|
|
14
17
|
client;
|
|
15
18
|
vault;
|
|
@@ -286,21 +289,24 @@ export class MorphoVaultV2 {
|
|
|
286
289
|
const marketIdListSnapshot = marketParamsListSnapshot.map((marketParams) => MarketUtils.getMarketId(marketParams));
|
|
287
290
|
const now = Time.timestamp();
|
|
288
291
|
const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
|
|
292
|
+
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
293
|
+
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
294
|
+
validateDeadline(deadline);
|
|
289
295
|
if (deadline <= now)
|
|
290
296
|
throw new ExpiredDeadlineError(deadline, now);
|
|
291
297
|
if (vaultData.accrualAdapters.length !== 1) {
|
|
292
|
-
throw new
|
|
298
|
+
throw new VaultV2SingleAdapterRequiredError(this.vault, vaultData.accrualAdapters.length);
|
|
293
299
|
}
|
|
294
300
|
const soleAdapter = vaultData.accrualAdapters[0];
|
|
295
301
|
if (soleAdapter == null) {
|
|
296
|
-
throw new
|
|
302
|
+
throw new VaultV2SingleAdapterRequiredError(this.vault, 0);
|
|
297
303
|
}
|
|
298
304
|
const adapter = adapterOverride ?? soleAdapter.address;
|
|
299
305
|
if (!isAddressEqual(adapter, soleAdapter.address)) {
|
|
300
306
|
throw new AdapterNotPartOfVaultError(this.vault, adapter);
|
|
301
307
|
}
|
|
302
308
|
if (!(soleAdapter instanceof AccrualVaultV2MorphoMarketV1AdapterV2)) {
|
|
303
|
-
throw new
|
|
309
|
+
throw new VaultV2UnsupportedExitAdapterError(adapter);
|
|
304
310
|
}
|
|
305
311
|
const penalty = vaultData.forceDeallocatePenalties[soleAdapter.address] ?? 0n;
|
|
306
312
|
const idleAssets = MathLib.min(vaultData.assetBalance, amount);
|
|
@@ -315,7 +321,9 @@ export class MorphoVaultV2 {
|
|
|
315
321
|
if (assetsToDeallocate > 0n && marketParamsListSnapshot.length === 0) {
|
|
316
322
|
throw new EmptyMarketParamsListError();
|
|
317
323
|
}
|
|
318
|
-
const assetsByMarket = new Map(soleAdapter.markets
|
|
324
|
+
const assetsByMarket = new Map(soleAdapter.markets
|
|
325
|
+
.filter((market) => (soleAdapter.supplyShares[market.id] ?? 0n) !== 0n)
|
|
326
|
+
.map((market) => [
|
|
319
327
|
market.id,
|
|
320
328
|
market
|
|
321
329
|
.accrueInterest(now)
|
|
@@ -446,21 +454,226 @@ export class MorphoVaultV2 {
|
|
|
446
454
|
},
|
|
447
455
|
};
|
|
448
456
|
}
|
|
449
|
-
|
|
457
|
+
/** {@inheritDoc VaultV2Actions.forceWithdraw} */
|
|
458
|
+
forceWithdraw({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, minSharePriceE27: minSharePriceE27Override, referralFeePct = 0n, referralFeeRecipient, }) {
|
|
450
459
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
460
|
+
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
461
|
+
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
462
|
+
}
|
|
463
|
+
if (exitAssets <= 0n)
|
|
464
|
+
throw new NonPositiveInputError("exitAssets", exitAssets);
|
|
465
|
+
validateUint256Field("exitAssets", exitAssets);
|
|
466
|
+
validateSlippageTolerance(slippageTolerance);
|
|
467
|
+
// Called for its throws only: the raw pair is forwarded to the action, which normalizes it
|
|
468
|
+
// again on the encode path so a direct action caller gets the same guarantees.
|
|
469
|
+
validateReferralFee({ referralFeePct, referralFeeRecipient });
|
|
470
|
+
if (minSharePriceE27Override != null) {
|
|
471
|
+
// An unbounded override reopens the exact hole this path closes: the contract reads
|
|
472
|
+
// `minSharePriceE27 == 0` as "no bound".
|
|
473
|
+
if (minSharePriceE27Override <= 0n) {
|
|
474
|
+
throw new NonPositiveInputError("minSharePriceE27", minSharePriceE27Override);
|
|
475
|
+
}
|
|
476
|
+
// And an override the uint256 slot cannot hold must fail here rather than after
|
|
477
|
+
// `getRequirements()` has already asked for an approval or a permit signature.
|
|
478
|
+
validateUint256Field("minSharePriceE27", minSharePriceE27Override);
|
|
479
|
+
}
|
|
480
|
+
const now = Time.timestamp();
|
|
481
|
+
const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
|
|
482
|
+
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
483
|
+
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
484
|
+
validateDeadline(deadline);
|
|
485
|
+
if (deadline <= now)
|
|
486
|
+
throw new ExpiredDeadlineError(deadline, now);
|
|
487
|
+
const maxDeadline = now + VAULT_V2_FEE_PROJECTION_HORIZON;
|
|
488
|
+
if (deadline > maxDeadline) {
|
|
489
|
+
throw new InputExceedsMaxError({
|
|
490
|
+
field: "deadline",
|
|
491
|
+
value: deadline,
|
|
492
|
+
max: maxDeadline,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData, adapterOverride);
|
|
496
|
+
switch (eligibility.type) {
|
|
497
|
+
case "eligible":
|
|
498
|
+
break;
|
|
499
|
+
case "adapterCount":
|
|
500
|
+
throw new VaultV2SingleAdapterRequiredError(this.vault, eligibility.adapters);
|
|
501
|
+
case "adapterMismatch":
|
|
502
|
+
throw new AdapterNotPartOfVaultError(this.vault, eligibility.adapter);
|
|
503
|
+
case "unsupportedAdapter":
|
|
504
|
+
throw new VaultV2UnsupportedExitAdapterError(eligibility.adapter);
|
|
505
|
+
case "unsupportedLiquidityAdapter":
|
|
506
|
+
throw new VaultV2UnsupportedLiquidityAdapterError({
|
|
507
|
+
vault: this.vault,
|
|
508
|
+
liquidityAdapter: eligibility.liquidityAdapter,
|
|
509
|
+
adapter: eligibility.adapter,
|
|
510
|
+
});
|
|
511
|
+
case "undecodableLiquidityData":
|
|
512
|
+
throw new VaultV2UndecodableLiquidityDataError({
|
|
513
|
+
vault: this.vault,
|
|
514
|
+
liquidityAdapter: eligibility.liquidityAdapter,
|
|
515
|
+
liquidityData: eligibility.liquidityData,
|
|
516
|
+
cause: eligibility.cause,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
const { adapter: accrualAdapter, liquidityMarketId } = eligibility;
|
|
520
|
+
const adapter = accrualAdapter.address;
|
|
521
|
+
const plan = computeVaultV2ForceWithdrawPlan({
|
|
522
|
+
vaultData,
|
|
523
|
+
adapter: accrualAdapter,
|
|
524
|
+
liquidityMarketId,
|
|
525
|
+
exitAssets,
|
|
526
|
+
timestamp: now,
|
|
527
|
+
});
|
|
528
|
+
if (plan.withdrawnAssets <= 0n) {
|
|
529
|
+
throw new VaultV2ForceWithdrawZeroWithdrawalError({
|
|
530
|
+
vault: this.vault,
|
|
531
|
+
exitAssets,
|
|
532
|
+
penalty: plan.penalty,
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
// The contract's force-deallocation loop is unbounded: under-coverage panics on-chain.
|
|
536
|
+
if (plan.coveredAssets < plan.assetsToDeallocate) {
|
|
537
|
+
throw new VaultV2ForceWithdrawCoverageError({
|
|
538
|
+
required: plan.assetsToDeallocate,
|
|
539
|
+
covered: plan.coveredAssets,
|
|
540
|
+
maxExitAssets: plan.maxExitAssets,
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
const projectionTimestamp = deadline;
|
|
544
|
+
// VaultExitBundlesV1 measures shares as `sharesBefore - balanceAfter`; its first withdrawal
|
|
545
|
+
// accrues the vault before burning. Use the `now` accrual for the floor and the projected
|
|
546
|
+
// deadline accrual for the fee-mint guard.
|
|
547
|
+
const { vault: nowVaultData } = vaultData.accrueInterest(MathLib.max(now, vaultData.lastUpdate));
|
|
548
|
+
const { vault: projectedVaultData } = vaultData.accrueInterest(MathLib.max(projectionTimestamp, vaultData.lastUpdate));
|
|
549
|
+
const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
|
|
550
|
+
vaultData: nowVaultData,
|
|
551
|
+
deadlineVaultData: nowVaultData,
|
|
552
|
+
plan,
|
|
553
|
+
});
|
|
554
|
+
const feeSharesNow = computeVaultV2ForceWithdrawFeeSharesMinted({
|
|
555
|
+
vaultData,
|
|
556
|
+
owner: userAddress,
|
|
557
|
+
timestamp: now,
|
|
558
|
+
});
|
|
559
|
+
const feeSharesProjected = computeVaultV2ForceWithdrawFeeSharesMinted({
|
|
560
|
+
vaultData,
|
|
561
|
+
owner: userAddress,
|
|
562
|
+
timestamp: projectionTimestamp,
|
|
563
|
+
});
|
|
564
|
+
const minSharesBurntProjected = computeVaultV2ForceWithdrawMinSharesBurnt({
|
|
565
|
+
vaultData: projectedVaultData,
|
|
566
|
+
plan,
|
|
567
|
+
});
|
|
568
|
+
// When fee shares are minted, the projected pair bounds every execution time in the window.
|
|
569
|
+
if (feeSharesProjected > 0n &&
|
|
570
|
+
feeSharesProjected >= minSharesBurntProjected) {
|
|
571
|
+
throw new VaultV2ForceWithdrawFeeSharesExceedBurnError({
|
|
572
|
+
vault: this.vault,
|
|
573
|
+
userAddress,
|
|
574
|
+
sharesBurnt: minSharesBurntProjected,
|
|
575
|
+
feeShares: feeSharesProjected,
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
// sharesBurntNow ≥ minSharesBurntNow ≥ minSharesBurntProjected > feeSharesProjected ≥ feeSharesNow
|
|
579
|
+
const netSharesBurntNow = sharesBurntNow - feeSharesNow;
|
|
580
|
+
const minSharePriceE27 = minSharePriceE27Override ??
|
|
581
|
+
computeMinForceWithdrawSharePrice({
|
|
582
|
+
withdrawnAssets: plan.withdrawnAssets,
|
|
583
|
+
sharesBurnt: netSharesBurntNow,
|
|
584
|
+
slippageTolerance,
|
|
585
|
+
});
|
|
586
|
+
// The floor is deliberately *not* capped at `MAX_ABSOLUTE_SHARE_PRICE` (100 assets/share):
|
|
587
|
+
// lowering a lower bound weakens it, so any vault whose share price grew past that would be left
|
|
588
|
+
// with no real protection. Its two sibling `computeMin*SharePrice` helpers cap nothing either —
|
|
589
|
+
// only the `computeMax*` ones do, where capping relaxes an upper bound and is safe.
|
|
590
|
+
//
|
|
591
|
+
// It still has to fit the ABI slot though. Defense-in-depth rather than a reachable input error:
|
|
592
|
+
// with `exitAssets` bounded above, the derived floor only exceeds `uint256` on a vault whose
|
|
593
|
+
// share price passed ~1e50 assets/share, which no fixture here can construct.
|
|
594
|
+
validateUint256Field("minSharePriceE27", minSharePriceE27);
|
|
595
|
+
// VaultExitBundlesV1's burn bound includes fee shares minted by the first withdrawal. Add the
|
|
596
|
+
// projected fee shares to the price-floor ceiling so the approval covers that mint.
|
|
597
|
+
// Saturated at `maxUint256`: a tiny accepted floor scales this above the ABI slot, and the
|
|
598
|
+
// approval encoder clamps what it emits — so an uncapped requirement would sit permanently above
|
|
599
|
+
// any allowance the user can actually grant and `getRequirements()` would return the same
|
|
600
|
+
// approval forever. No account can hold or burn more shares than that anyway.
|
|
601
|
+
const requiredShareAllowance = MathLib.min(MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) +
|
|
602
|
+
feeSharesProjected, maxUint256);
|
|
603
|
+
const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
|
|
451
604
|
return {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
605
|
+
getRequirements: async () => {
|
|
606
|
+
const requirementsTimestamp = Time.timestamp();
|
|
607
|
+
if (deadline <= requirementsTimestamp) {
|
|
608
|
+
throw new ExpiredDeadlineError(deadline, requirementsTimestamp);
|
|
609
|
+
}
|
|
610
|
+
// Vault gates are intentionally left to the final transaction: the receive-assets gate may
|
|
611
|
+
// inspect VaultExitBundlesV1's transient `initiator`, and a send-shares gate is arbitrary
|
|
612
|
+
// external code re-evaluated after each intermediate penalty burn, so neither is
|
|
613
|
+
// execution-equivalent from a standalone read. Unlike in-kind redemption, this exit never
|
|
614
|
+
// supplies into Morpho Blue, so no Blue token-balance check is needed.
|
|
615
|
+
const [allowance, nonce] = await multicall(this.client.viemClient, {
|
|
616
|
+
allowFailure: false,
|
|
617
|
+
contracts: [
|
|
618
|
+
{
|
|
619
|
+
address: this.vault,
|
|
620
|
+
abi: erc20Abi,
|
|
621
|
+
functionName: "allowance",
|
|
622
|
+
args: [userAddress, vaultExitBundlesV1],
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
address: this.vault,
|
|
626
|
+
abi: erc2612Abi,
|
|
627
|
+
functionName: "nonces",
|
|
628
|
+
args: [userAddress],
|
|
629
|
+
},
|
|
630
|
+
],
|
|
631
|
+
});
|
|
632
|
+
if (allowance >= requiredShareAllowance)
|
|
633
|
+
return [];
|
|
634
|
+
if (this.client.options.supportSignature) {
|
|
635
|
+
const requirement = encodeVaultSharesPermit({
|
|
636
|
+
vault: vaultData,
|
|
637
|
+
version: "vaultV2",
|
|
638
|
+
spender: vaultExitBundlesV1,
|
|
639
|
+
owner: userAddress,
|
|
640
|
+
chainId: this.chainId,
|
|
641
|
+
nonce,
|
|
642
|
+
amount: requiredShareAllowance,
|
|
643
|
+
deadline,
|
|
644
|
+
});
|
|
645
|
+
return [requirement];
|
|
646
|
+
}
|
|
647
|
+
return [
|
|
648
|
+
encodeErc20Approval({
|
|
649
|
+
token: this.vault,
|
|
650
|
+
spender: vaultExitBundlesV1,
|
|
651
|
+
amount: requiredShareAllowance,
|
|
652
|
+
chainId: this.chainId,
|
|
653
|
+
}),
|
|
654
|
+
];
|
|
655
|
+
},
|
|
656
|
+
buildTx: (signatures) => {
|
|
657
|
+
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
658
|
+
spender: vaultExitBundlesV1,
|
|
659
|
+
amount: requiredShareAllowance,
|
|
660
|
+
deadline,
|
|
661
|
+
});
|
|
662
|
+
return vaultV2ForceWithdraw({
|
|
663
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
664
|
+
args: {
|
|
665
|
+
adapter,
|
|
666
|
+
exitAssets,
|
|
667
|
+
minSharePriceE27,
|
|
668
|
+
userAddress,
|
|
669
|
+
deadline,
|
|
670
|
+
referralFeePct,
|
|
671
|
+
referralFeeRecipient,
|
|
672
|
+
requirementSignature: permit,
|
|
459
673
|
},
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
}),
|
|
674
|
+
metadata: this.client.options.metadata,
|
|
675
|
+
});
|
|
676
|
+
},
|
|
464
677
|
};
|
|
465
678
|
}
|
|
466
679
|
forceRedeem({ deallocations, redeem, userAddress, }) {
|
|
@@ -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.
|