@morpho-org/morpho-sdk 6.0.0-next.3 → 6.0.0-next.4
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 +5 -3
- package/lib/cjs/abis.d.ts +5 -1
- package/lib/cjs/abis.js +2 -0
- package/lib/cjs/actions/bundles/common.d.ts +2 -2
- package/lib/cjs/actions/bundles/common.js +10 -2
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +2 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +2 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +2 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +2 -1
- package/lib/cjs/augment/AccrualPosition.d.ts +1 -0
- package/lib/cjs/blue/abis.d.ts +5 -1
- package/lib/cjs/blue/abis.js +2 -0
- package/lib/cjs/blue/entities.d.ts +10 -2
- package/lib/cjs/blue/entities.js +2 -0
- package/lib/cjs/blue/errors.d.ts +4 -2
- package/lib/cjs/blue/errors.js +3 -1
- package/lib/cjs/blue/fetch.d.ts +5 -1
- package/lib/cjs/blue/fetch.js +2 -0
- package/lib/cjs/blue/utils.d.ts +5 -1
- package/lib/cjs/blue/utils.js +2 -0
- package/lib/cjs/entities/index.d.ts +10 -2
- package/lib/cjs/entities/index.js +2 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +4 -3
- package/lib/cjs/entities/vaultV1/vaultV1.js +4 -3
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +21 -13
- package/lib/cjs/entities/vaultV2/vaultV2.js +31 -13
- package/lib/cjs/errors.d.ts +5 -3
- package/lib/cjs/errors.js +4 -1
- package/lib/cjs/fetch.d.ts +5 -1
- package/lib/cjs/fetch.js +2 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +11 -5
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +48 -15
- package/lib/cjs/midnight/errors.d.ts +1 -1
- package/lib/cjs/midnight/errors.js +2 -1
- package/lib/cjs/utils.d.ts +5 -1
- package/lib/cjs/utils.js +2 -0
- package/lib/esm/abis.d.ts +5 -1
- package/lib/esm/abis.js +5 -1
- package/lib/esm/actions/bundles/common.d.ts +2 -2
- package/lib/esm/actions/bundles/common.js +10 -2
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +2 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +2 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +2 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.js +2 -1
- package/lib/esm/augment/AccrualPosition.d.ts +1 -0
- package/lib/esm/blue/abis.d.ts +5 -1
- package/lib/esm/blue/abis.js +5 -1
- package/lib/esm/blue/entities.d.ts +10 -2
- package/lib/esm/blue/entities.js +5 -1
- package/lib/esm/blue/errors.d.ts +4 -2
- package/lib/esm/blue/errors.js +4 -2
- package/lib/esm/blue/fetch.d.ts +5 -1
- package/lib/esm/blue/fetch.js +5 -1
- package/lib/esm/blue/utils.d.ts +5 -1
- package/lib/esm/blue/utils.js +5 -1
- package/lib/esm/entities/index.d.ts +10 -2
- package/lib/esm/entities/index.js +5 -1
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +4 -3
- package/lib/esm/entities/vaultV1/vaultV1.js +4 -3
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +21 -13
- package/lib/esm/entities/vaultV2/vaultV2.js +31 -13
- package/lib/esm/errors.d.ts +5 -3
- package/lib/esm/errors.js +5 -3
- package/lib/esm/fetch.d.ts +5 -1
- package/lib/esm/fetch.js +5 -1
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +11 -5
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +48 -15
- package/lib/esm/midnight/errors.d.ts +1 -1
- package/lib/esm/midnight/errors.js +1 -1
- package/lib/esm/utils.d.ts +5 -1
- package/lib/esm/utils.js +5 -1
- package/package.json +6 -9
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
|
|
2
|
-
|
|
1
|
+
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
|
|
2
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
|
+
IPreLiquidationParams as IBluePreLiquidationParams,
|
|
4
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
+
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
|
|
6
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
7
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
8
|
+
PreLiquidationParams as BluePreLiquidationParams,
|
|
9
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
10
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
3
11
|
export type { BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, RatifierTreeInput as MidnightRatifierTreeInput, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeDescriptor as MidnightTreeDescriptor, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, } from "@morpho-org/midnight-sdk";
|
|
4
12
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
5
13
|
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
1
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
2
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
|
+
PreLiquidationParams as BluePreLiquidationParams,
|
|
4
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
2
6
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
3
7
|
export { MorphoBlue } from "./blue/index.js";
|
|
4
8
|
export { MorphoMidnight, } from "./midnight/index.js";
|
|
@@ -6,14 +6,17 @@ import { type ActionRequirement } from "../../types/index.js";
|
|
|
6
6
|
*
|
|
7
7
|
* The exit burns however many shares the vault prices at execution time, so the share allowance is
|
|
8
8
|
* the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
|
|
9
|
-
* satisfy the requirement: it is replaced by an approval
|
|
9
|
+
* satisfy the requirement: it is replaced by an onchain approval for exactly the computed cap. Only
|
|
10
|
+
* an insufficient allowance may be raised through an ERC-2612 permit, because VaultBundlesV1 skips a
|
|
11
|
+
* permit whose nonce was already consumed and the leftover allowance would then stay in force.
|
|
10
12
|
*
|
|
11
13
|
* @internal
|
|
12
14
|
*
|
|
13
15
|
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
14
16
|
* @param params - Vault snapshot, owner, exact allowance, and deadline values.
|
|
15
17
|
* @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
|
|
16
|
-
*
|
|
18
|
+
* approval that sets it to exactly that cap, or one permit when the allowance is below the cap
|
|
19
|
+
* and signatures are supported.
|
|
17
20
|
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
18
21
|
* @throws {viem.BaseError} when an allowance or nonce read fails.
|
|
19
22
|
*/
|
|
@@ -10,14 +10,17 @@ import { ExpiredDeadlineError, } from "../../types/index.js";
|
|
|
10
10
|
*
|
|
11
11
|
* The exit burns however many shares the vault prices at execution time, so the share allowance is
|
|
12
12
|
* the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
|
|
13
|
-
* satisfy the requirement: it is replaced by an approval
|
|
13
|
+
* satisfy the requirement: it is replaced by an onchain approval for exactly the computed cap. Only
|
|
14
|
+
* an insufficient allowance may be raised through an ERC-2612 permit, because VaultBundlesV1 skips a
|
|
15
|
+
* permit whose nonce was already consumed and the leftover allowance would then stay in force.
|
|
14
16
|
*
|
|
15
17
|
* @internal
|
|
16
18
|
*
|
|
17
19
|
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
18
20
|
* @param params - Vault snapshot, owner, exact allowance, and deadline values.
|
|
19
21
|
* @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
|
|
20
|
-
*
|
|
22
|
+
* approval that sets it to exactly that cap, or one permit when the allowance is below the cap
|
|
23
|
+
* and signatures are supported.
|
|
21
24
|
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
22
25
|
* @throws {viem.BaseError} when an allowance or nonce read fails.
|
|
23
26
|
*/
|
|
@@ -39,7 +42,9 @@ export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
|
39
42
|
// so only an exact match skips the approval or permit that resets it to the computed cap.
|
|
40
43
|
if (allowance === params.requiredShareAllowance)
|
|
41
44
|
return [];
|
|
42
|
-
|
|
45
|
+
// An oversized allowance is only ever lowered onchain: `TokenLib.submitPermit` skips a permit
|
|
46
|
+
// whose nonce was already consumed, which would silently leave the stale cap in force.
|
|
47
|
+
if (allowance < params.requiredShareAllowance && params.supportSignature) {
|
|
43
48
|
const nonce = await readContract(viemClient, {
|
|
44
49
|
address: params.vaultData.address,
|
|
45
50
|
abi: erc2612Abi,
|
|
@@ -112,9 +112,10 @@ export interface VaultV1Actions {
|
|
|
112
112
|
* defaults to two hours from handle creation.
|
|
113
113
|
* @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
|
|
114
114
|
* which returns a deep-frozen `Transaction<VaultV1WithdrawAction>`. Requirements are empty
|
|
115
|
-
* when the allowance equals the cap;
|
|
116
|
-
*
|
|
117
|
-
*
|
|
115
|
+
* when the allowance equals the cap; an oversized allowance is always reset with an exact
|
|
116
|
+
* onchain approval, and an insufficient one is raised by an approval or, with signature
|
|
117
|
+
* support, an ERC-2612 request. The cap stays pinned to the first resolution while each call
|
|
118
|
+
* re-reads the allowance. Confirm the approval or pass its signed permit to `buildTx`.
|
|
118
119
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
119
120
|
* @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
|
|
120
121
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
@@ -184,9 +184,10 @@ export class MorphoVaultV1 {
|
|
|
184
184
|
supportSignature: this.client.options.supportSignature,
|
|
185
185
|
});
|
|
186
186
|
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
expectedRequirement =
|
|
188
|
+
signatureRequirement?.action.type === "permit"
|
|
189
|
+
? signatureRequirement.action
|
|
190
|
+
: undefined;
|
|
190
191
|
return requirements;
|
|
191
192
|
},
|
|
192
193
|
buildTx: (signatures) => {
|
|
@@ -115,9 +115,10 @@ export interface VaultV2Actions {
|
|
|
115
115
|
* defaults to two hours from handle creation.
|
|
116
116
|
* @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
|
|
117
117
|
* which returns a deep-frozen `Transaction<VaultV2WithdrawAction>`. Requirements are empty
|
|
118
|
-
* when the allowance equals the cap;
|
|
119
|
-
*
|
|
120
|
-
*
|
|
118
|
+
* when the allowance equals the cap; an oversized allowance is always reset with an exact
|
|
119
|
+
* onchain approval, and an insufficient one is raised by an approval or, with signature
|
|
120
|
+
* support, an ERC-2612 request. The cap stays pinned to the first resolution while each call
|
|
121
|
+
* re-reads the allowance. Confirm the approval or pass its signed permit to `buildTx`.
|
|
121
122
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
122
123
|
* @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
|
|
123
124
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
@@ -320,9 +321,11 @@ export interface VaultV2Actions {
|
|
|
320
321
|
* and permit nonce are read on-chain.
|
|
321
322
|
*
|
|
322
323
|
* The SDK derives a conservative lower bound on the realized exit share price from the snapshot
|
|
323
|
-
* and `slippageTolerance
|
|
324
|
-
*
|
|
325
|
-
*
|
|
324
|
+
* and `slippageTolerance`: the floor is priced off whichever of the raw snapshot or its accrual
|
|
325
|
+
* to `now` burns more shares, so neither pending fee mints nor interest the chain has not yet
|
|
326
|
+
* accrued can lift it above the realized price. A supplied `minSharePriceE27` replaces the
|
|
327
|
+
* tolerance-derived bound (it may be tighter or looser) but must be at least the floor derived
|
|
328
|
+
* at `MAX_SLIPPAGE_TOLERANCE`, so an override can never disable meaningful protection.
|
|
326
329
|
* The bound rejects a share price drop, a penalty increase, and liquidity shifting from the
|
|
327
330
|
* penalty-free leg to the penalised leg. It does **not** cover the referral fee, which the
|
|
328
331
|
* contract deducts afterwards.
|
|
@@ -332,16 +335,21 @@ export interface VaultV2Actions {
|
|
|
332
335
|
* send-shares gate is arbitrary code re-evaluated after each penalty burn. The SDK also does not
|
|
333
336
|
* validate the user's share balance. Per-market penalties and each vault withdrawal round the
|
|
334
337
|
* share burn up independently, so the exit can burn marginally more shares than `exitAssets` alone
|
|
335
|
-
* implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)`
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
+
* implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)` so a
|
|
339
|
+
* full-balance exit does not revert for insufficient shares. The approved share allowance this
|
|
340
|
+
* handle returns covers a burn at least one `slippageTolerance` step below the price floor
|
|
341
|
+
* whenever the floor exceeds one RAY unit and, in any case, at least one share above the burn
|
|
342
|
+
* at the floor, so a price within that headroom below the floor reverts on the contract's
|
|
343
|
+
* `minSharePriceE27` check rather than on the allowance; a deeper drop can still surface as an
|
|
344
|
+
* ERC-20 allowance underflow.
|
|
338
345
|
*
|
|
339
346
|
* Idle balance, penalty, adapter positions, and market liquidity can drift after the snapshot, so
|
|
340
347
|
* an on-chain revert remains possible if vault state changes between preparation and inclusion.
|
|
341
|
-
* A fee-recipient `userAddress` gets a floor from the
|
|
342
|
-
* and a guard against fee mints reaching the lower burn
|
|
343
|
-
* includes the projected fee shares through that same
|
|
344
|
-
* handle creation are rejected, so the guard and
|
|
348
|
+
* A fee-recipient `userAddress` gets a floor from the larger of the raw snapshot burn and the
|
|
349
|
+
* `now` burn net of its own fee mints, and a guard against fee mints reaching the lower burn
|
|
350
|
+
* bound by the deadline. Its allowance includes the projected fee shares through that same
|
|
351
|
+
* deadline. Deadlines beyond one year after handle creation are rejected, so the guard and
|
|
352
|
+
* allowance cover the whole accepted window.
|
|
345
353
|
*
|
|
346
354
|
* @param params - Force withdrawal parameters.
|
|
347
355
|
* @param params.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
|
|
@@ -187,9 +187,10 @@ export class MorphoVaultV2 {
|
|
|
187
187
|
supportSignature: this.client.options.supportSignature,
|
|
188
188
|
});
|
|
189
189
|
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
expectedRequirement =
|
|
191
|
+
signatureRequirement?.action.type === "permit"
|
|
192
|
+
? signatureRequirement.action
|
|
193
|
+
: undefined;
|
|
193
194
|
return requirements;
|
|
194
195
|
},
|
|
195
196
|
buildTx: (signatures) => {
|
|
@@ -547,10 +548,19 @@ export class MorphoVaultV2 {
|
|
|
547
548
|
}
|
|
548
549
|
const projectionTimestamp = deadline;
|
|
549
550
|
// VaultExitBundlesV1 measures shares as `sharesBefore - balanceAfter`; its first withdrawal
|
|
550
|
-
// accrues the vault before burning.
|
|
551
|
-
//
|
|
551
|
+
// accrues the vault before burning. The realized price sits between the raw snapshot price
|
|
552
|
+
// (pending fee mints not yet diluting it) and the `now` projection (interest the chain may not
|
|
553
|
+
// have accrued yet, e.g. when the wall clock runs ahead of the chain). Price the floor off the
|
|
554
|
+
// larger *net* burn of the two endpoints — the raw snapshot mints no fee shares, the `now`
|
|
555
|
+
// accrual mints `feeSharesNow` — so it never exceeds either, and use the projected deadline
|
|
556
|
+
// accrual for the fee-mint guard.
|
|
552
557
|
const { vault: nowVaultData } = vaultData.accrueInterest(MathLib.max(now, vaultData.lastUpdate));
|
|
553
558
|
const { vault: projectedVaultData } = vaultData.accrueInterest(MathLib.max(projectionTimestamp, vaultData.lastUpdate));
|
|
559
|
+
const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
|
|
560
|
+
vaultData,
|
|
561
|
+
deadlineVaultData: vaultData,
|
|
562
|
+
plan,
|
|
563
|
+
});
|
|
554
564
|
const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
|
|
555
565
|
vaultData: nowVaultData,
|
|
556
566
|
deadlineVaultData: nowVaultData,
|
|
@@ -581,13 +591,13 @@ export class MorphoVaultV2 {
|
|
|
581
591
|
});
|
|
582
592
|
}
|
|
583
593
|
// sharesBurntNow ≥ minSharesBurntNow ≥ minSharesBurntProjected > feeSharesProjected ≥ feeSharesNow
|
|
584
|
-
const
|
|
594
|
+
const sharesBurntForFloor = MathLib.max(sharesBurntRaw, sharesBurntNow - feeSharesNow);
|
|
585
595
|
if (minSharePriceE27Override != null) {
|
|
586
596
|
// The maximum-slippage threshold only bounds the override; unlike the transaction floor it
|
|
587
597
|
// may round to zero, in which case every positive override is acceptable.
|
|
588
598
|
const minAllowedSharePriceE27 = _try(() => computeMinForceWithdrawSharePrice({
|
|
589
599
|
withdrawnAssets: plan.withdrawnAssets,
|
|
590
|
-
sharesBurnt:
|
|
600
|
+
sharesBurnt: sharesBurntForFloor,
|
|
591
601
|
slippageTolerance: MAX_SLIPPAGE_TOLERANCE,
|
|
592
602
|
}), VaultV2ForceWithdrawZeroSharePriceError) ?? 1n;
|
|
593
603
|
if (minSharePriceE27Override < minAllowedSharePriceE27) {
|
|
@@ -600,7 +610,7 @@ export class MorphoVaultV2 {
|
|
|
600
610
|
const minSharePriceE27 = minSharePriceE27Override ??
|
|
601
611
|
computeMinForceWithdrawSharePrice({
|
|
602
612
|
withdrawnAssets: plan.withdrawnAssets,
|
|
603
|
-
sharesBurnt:
|
|
613
|
+
sharesBurnt: sharesBurntForFloor,
|
|
604
614
|
slippageTolerance,
|
|
605
615
|
});
|
|
606
616
|
// The floor is deliberately *not* capped at `MAX_ABSOLUTE_SHARE_PRICE` (100 assets/share):
|
|
@@ -608,11 +618,19 @@ export class MorphoVaultV2 {
|
|
|
608
618
|
// with no real protection. Its two sibling `computeMin*SharePrice` helpers cap nothing either —
|
|
609
619
|
// only the `computeMax*` ones do, where capping relaxes an upper bound and is safe.
|
|
610
620
|
validateUint256Field("minSharePriceE27", minSharePriceE27);
|
|
611
|
-
//
|
|
612
|
-
//
|
|
613
|
-
//
|
|
614
|
-
|
|
615
|
-
|
|
621
|
+
// The allowance is only a spend cap, never the price protection: the bundle checks
|
|
622
|
+
// `minSharePriceE27` after its last withdrawal, so an allowance sized exactly to the floor
|
|
623
|
+
// underflows `_spendAllowance` (panic 0x11) on a below-floor price before that check runs. Size
|
|
624
|
+
// it for a price at least one tolerance step below the floor so the miss surfaces as the
|
|
625
|
+
// bundle's own revert instead, and, in any case, for at least one share above the at-floor
|
|
626
|
+
// burn — a burn of `atFloor + 1` shares prices strictly below the floor since
|
|
627
|
+
// `atFloor >= exitAssets * RAY / floor`. The `minSharePriceE27 - 1` branch keeps the
|
|
628
|
+
// denominator strictly below the floor whenever the floor exceeds 1, so even
|
|
629
|
+
// `slippageTolerance: 0n` leaves price-space headroom; a deeper drop still exhausts the
|
|
630
|
+
// allowance first. Add the fee shares the first withdrawal mints since the burn measured
|
|
631
|
+
// on-chain includes them. Saturated at `maxUint256` as an ABI-slot guard.
|
|
632
|
+
const allowanceSharePriceE27 = MathLib.max(MathLib.min(MathLib.mulDivDown(minSharePriceE27, MathLib.WAD - slippageTolerance, MathLib.WAD), minSharePriceE27 - 1n), 1n);
|
|
633
|
+
const requiredShareAllowance = MathLib.min(MathLib.max(MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27), MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n) + feeSharesProjected, maxUint256);
|
|
616
634
|
const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
|
|
617
635
|
return {
|
|
618
636
|
getRequirements: async () => {
|
package/lib/esm/errors.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
|
|
2
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
|
+
UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
4
|
+
export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
|
5
|
+
export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
4
6
|
export type { ErrorClass } from "@morpho-org/morpho-ts";
|
|
5
7
|
export { _try, DivisionByZeroError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
|
package/lib/esm/errors.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
|
|
2
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
|
+
UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
4
|
+
export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
|
5
|
+
export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
4
6
|
export { _try, DivisionByZeroError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
|
package/lib/esm/fetch.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
|
|
1
|
+
export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
|
|
2
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
|
+
fetchPreLiquidationParams as fetchBluePreLiquidationParams,
|
|
4
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
+
fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
|
2
6
|
export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
|
package/lib/esm/fetch.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
|
|
1
|
+
export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
|
|
2
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
|
+
fetchPreLiquidationParams as fetchBluePreLiquidationParams,
|
|
4
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
+
fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
|
2
6
|
export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
|
|
@@ -95,15 +95,21 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
95
95
|
// zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
|
|
96
96
|
// dwarfing `totalAssets`) offers no price protection at all. Screen at the entity's default
|
|
97
97
|
// `DEFAULT_SLIPPAGE_TOLERANCE`, not slippage-free, against the same burn upper bound the entity
|
|
98
|
-
// divides by (
|
|
99
|
-
// realized price is a single RAY-unit, yet
|
|
100
|
-
// to zero — so the entity would reject
|
|
98
|
+
// divides by (the larger of the raw snapshot burn and the net burn accrued to `timestamp` like
|
|
99
|
+
// the plan): a tolerance-free screen clears an exit whose realized price is a single RAY-unit, yet
|
|
100
|
+
// the default tolerance scales that below 1 and rounds it to zero — so the entity would reject
|
|
101
|
+
// with `VaultV2ForceWithdrawZeroSharePriceError` the very
|
|
101
102
|
// `exitAssets` this preview handed back. A caller passing a larger tolerance still relies on the
|
|
102
103
|
// entity's own guard. The entity validates this derived value with
|
|
103
104
|
// `validateUint256Field("minSharePriceE27")`, which throws `InputExceedsMaxError` when it
|
|
104
105
|
// cannot fit uint256.
|
|
105
106
|
const { vault: accruedVaultData } = vaultData.accrueInterest(MathLib.max(timestamp, vaultData.lastUpdate));
|
|
106
|
-
const
|
|
107
|
+
const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
|
|
108
|
+
vaultData,
|
|
109
|
+
deadlineVaultData: vaultData,
|
|
110
|
+
plan,
|
|
111
|
+
});
|
|
112
|
+
const sharesBurntAccrued = computeVaultV2ForceWithdrawSharesBurnt({
|
|
107
113
|
vaultData: accruedVaultData,
|
|
108
114
|
deadlineVaultData: accruedVaultData,
|
|
109
115
|
plan,
|
|
@@ -132,7 +138,7 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
132
138
|
return undefined;
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
|
-
const sharesBurntForFloor =
|
|
141
|
+
const sharesBurntForFloor = MathLib.max(sharesBurntRaw, sharesBurntAccrued - feeShares);
|
|
136
142
|
const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
|
|
137
143
|
? MathLib.mulDivDown(plan.withdrawnAssets, MathLib.wToRay(MathLib.WAD - DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
|
|
138
144
|
: 0n;
|
|
@@ -192,23 +192,34 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
|
|
|
192
192
|
* The result is the **denominator of {@link computeMinForceWithdrawSharePrice}** — the largest share
|
|
193
193
|
* burn the realized exit price is measured against. It takes the max over the two supplied snapshots
|
|
194
194
|
* because interest lowers the burn while management fees raise it, so neither snapshot alone bounds
|
|
195
|
-
* execution. The entity passes
|
|
196
|
-
* underestimates the burn a stale fee-bearing vault realizes —
|
|
197
|
-
* management fees before burning shares —
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
195
|
+
* execution. The entity passes the raw `lastUpdate` snapshot and the same vault accrued to `now`
|
|
196
|
+
* (execution time): the raw snapshot underestimates the burn a stale fee-bearing vault realizes —
|
|
197
|
+
* the first withdrawal accrues pending management fees before burning shares — while the `now`
|
|
198
|
+
* accrual underestimates it when it projects interest the chain has not realized (a wall clock
|
|
199
|
+
* running ahead of the chain, or a capped `maxRate`); either alone would lift the floor above the
|
|
200
|
+
* faithful price and trip `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`,
|
|
201
|
+
* tracks execution without letting a long deadline silently weaken the guard; `slippageTolerance`
|
|
202
|
+
* absorbs the residual drift until inclusion.
|
|
201
203
|
*
|
|
202
|
-
* This is **not** the share allowance to authorize. The
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* `
|
|
206
|
-
*
|
|
204
|
+
* This is **not** the share allowance to authorize. The contract measures the *net* burn, which
|
|
205
|
+
* fee mints to `owner` shrink, and the raw snapshot mints none while the `now` accrual mints
|
|
206
|
+
* `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`; so the
|
|
207
|
+
* entity nets each endpoint before taking the max (`max(burnRaw, burnNow - feeSharesNow)`) rather
|
|
208
|
+
* than subtracting the `now` fee from a gross max. The allowance is
|
|
209
|
+
* `min(max(mulDivUp(exitAssets, RAY, max(min(mulDivDown(minSharePriceE27, WAD - slippageTolerance,
|
|
210
|
+
* WAD), minSharePriceE27 - 1), 1)), mulDivUp(exitAssets, RAY, minSharePriceE27) + 1)
|
|
211
|
+
* + computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: deadline }),
|
|
212
|
+
* maxUint256)`: the permit pays for the *gross* burn, covering a burn at least one tolerance step
|
|
213
|
+
* below the floor whenever the floor exceeds one RAY unit and, in any case, at least one share
|
|
214
|
+
* above the burn at the floor, so a price within that headroom below the floor reverts on the
|
|
215
|
+
* contract's `minSharePriceE27` check rather than on the allowance; a deeper drop can still
|
|
216
|
+
* surface as an ERC-20 allowance underflow.
|
|
207
217
|
*
|
|
208
218
|
* @param params - Share-bound inputs.
|
|
209
219
|
* @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
210
220
|
* @param params.deadlineVaultData - The same vault accrued to a second timestamp; the max of the two
|
|
211
|
-
* share burns is returned. The entity
|
|
221
|
+
* share burns is returned. The entity calls this twice — the raw snapshot for both parameters,
|
|
222
|
+
* then the `now` accrual for both — and nets each result before taking the max.
|
|
212
223
|
* @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
|
|
213
224
|
* @returns An upper bound, in vault shares, of what the exit burns.
|
|
214
225
|
* @example
|
|
@@ -220,7 +231,12 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
|
|
|
220
231
|
* } from "@morpho-org/morpho-sdk";
|
|
221
232
|
*
|
|
222
233
|
* const { vault: nowVaultData } = vaultData.accrueInterest(now);
|
|
223
|
-
* const
|
|
234
|
+
* const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
|
|
235
|
+
* vaultData,
|
|
236
|
+
* deadlineVaultData: vaultData,
|
|
237
|
+
* plan,
|
|
238
|
+
* });
|
|
239
|
+
* const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
|
|
224
240
|
* vaultData: nowVaultData,
|
|
225
241
|
* deadlineVaultData: nowVaultData,
|
|
226
242
|
* plan,
|
|
@@ -230,9 +246,26 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
|
|
|
230
246
|
* owner,
|
|
231
247
|
* timestamp: now,
|
|
232
248
|
* });
|
|
233
|
-
* const sharesBurntForFloor =
|
|
249
|
+
* const sharesBurntForFloor = MathLib.max(
|
|
250
|
+
* sharesBurntRaw,
|
|
251
|
+
* sharesBurntNow - feeSharesNow,
|
|
252
|
+
* );
|
|
253
|
+
* const allowanceSharePriceE27 = MathLib.max(
|
|
254
|
+
* MathLib.min(
|
|
255
|
+
* MathLib.mulDivDown(
|
|
256
|
+
* minSharePriceE27,
|
|
257
|
+
* MathLib.WAD - slippageTolerance,
|
|
258
|
+
* MathLib.WAD,
|
|
259
|
+
* ),
|
|
260
|
+
* minSharePriceE27 - 1n,
|
|
261
|
+
* ),
|
|
262
|
+
* 1n,
|
|
263
|
+
* );
|
|
234
264
|
* const requiredShareAllowance = MathLib.min(
|
|
235
|
-
* MathLib.
|
|
265
|
+
* MathLib.max(
|
|
266
|
+
* MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27),
|
|
267
|
+
* MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n,
|
|
268
|
+
* ) +
|
|
236
269
|
* computeVaultV2ForceWithdrawFeeSharesMinted({
|
|
237
270
|
* vaultData,
|
|
238
271
|
* owner,
|
|
@@ -262,23 +262,34 @@ export function computeVaultV2ForceWithdrawPlan(params) {
|
|
|
262
262
|
* The result is the **denominator of {@link computeMinForceWithdrawSharePrice}** — the largest share
|
|
263
263
|
* burn the realized exit price is measured against. It takes the max over the two supplied snapshots
|
|
264
264
|
* because interest lowers the burn while management fees raise it, so neither snapshot alone bounds
|
|
265
|
-
* execution. The entity passes
|
|
266
|
-
* underestimates the burn a stale fee-bearing vault realizes —
|
|
267
|
-
* management fees before burning shares —
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
265
|
+
* execution. The entity passes the raw `lastUpdate` snapshot and the same vault accrued to `now`
|
|
266
|
+
* (execution time): the raw snapshot underestimates the burn a stale fee-bearing vault realizes —
|
|
267
|
+
* the first withdrawal accrues pending management fees before burning shares — while the `now`
|
|
268
|
+
* accrual underestimates it when it projects interest the chain has not realized (a wall clock
|
|
269
|
+
* running ahead of the chain, or a capped `maxRate`); either alone would lift the floor above the
|
|
270
|
+
* faithful price and trip `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`,
|
|
271
|
+
* tracks execution without letting a long deadline silently weaken the guard; `slippageTolerance`
|
|
272
|
+
* absorbs the residual drift until inclusion.
|
|
271
273
|
*
|
|
272
|
-
* This is **not** the share allowance to authorize. The
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* `
|
|
276
|
-
*
|
|
274
|
+
* This is **not** the share allowance to authorize. The contract measures the *net* burn, which
|
|
275
|
+
* fee mints to `owner` shrink, and the raw snapshot mints none while the `now` accrual mints
|
|
276
|
+
* `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`; so the
|
|
277
|
+
* entity nets each endpoint before taking the max (`max(burnRaw, burnNow - feeSharesNow)`) rather
|
|
278
|
+
* than subtracting the `now` fee from a gross max. The allowance is
|
|
279
|
+
* `min(max(mulDivUp(exitAssets, RAY, max(min(mulDivDown(minSharePriceE27, WAD - slippageTolerance,
|
|
280
|
+
* WAD), minSharePriceE27 - 1), 1)), mulDivUp(exitAssets, RAY, minSharePriceE27) + 1)
|
|
281
|
+
* + computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: deadline }),
|
|
282
|
+
* maxUint256)`: the permit pays for the *gross* burn, covering a burn at least one tolerance step
|
|
283
|
+
* below the floor whenever the floor exceeds one RAY unit and, in any case, at least one share
|
|
284
|
+
* above the burn at the floor, so a price within that headroom below the floor reverts on the
|
|
285
|
+
* contract's `minSharePriceE27` check rather than on the allowance; a deeper drop can still
|
|
286
|
+
* surface as an ERC-20 allowance underflow.
|
|
277
287
|
*
|
|
278
288
|
* @param params - Share-bound inputs.
|
|
279
289
|
* @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
280
290
|
* @param params.deadlineVaultData - The same vault accrued to a second timestamp; the max of the two
|
|
281
|
-
* share burns is returned. The entity
|
|
291
|
+
* share burns is returned. The entity calls this twice — the raw snapshot for both parameters,
|
|
292
|
+
* then the `now` accrual for both — and nets each result before taking the max.
|
|
282
293
|
* @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
|
|
283
294
|
* @returns An upper bound, in vault shares, of what the exit burns.
|
|
284
295
|
* @example
|
|
@@ -290,7 +301,12 @@ export function computeVaultV2ForceWithdrawPlan(params) {
|
|
|
290
301
|
* } from "@morpho-org/morpho-sdk";
|
|
291
302
|
*
|
|
292
303
|
* const { vault: nowVaultData } = vaultData.accrueInterest(now);
|
|
293
|
-
* const
|
|
304
|
+
* const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
|
|
305
|
+
* vaultData,
|
|
306
|
+
* deadlineVaultData: vaultData,
|
|
307
|
+
* plan,
|
|
308
|
+
* });
|
|
309
|
+
* const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
|
|
294
310
|
* vaultData: nowVaultData,
|
|
295
311
|
* deadlineVaultData: nowVaultData,
|
|
296
312
|
* plan,
|
|
@@ -300,9 +316,26 @@ export function computeVaultV2ForceWithdrawPlan(params) {
|
|
|
300
316
|
* owner,
|
|
301
317
|
* timestamp: now,
|
|
302
318
|
* });
|
|
303
|
-
* const sharesBurntForFloor =
|
|
319
|
+
* const sharesBurntForFloor = MathLib.max(
|
|
320
|
+
* sharesBurntRaw,
|
|
321
|
+
* sharesBurntNow - feeSharesNow,
|
|
322
|
+
* );
|
|
323
|
+
* const allowanceSharePriceE27 = MathLib.max(
|
|
324
|
+
* MathLib.min(
|
|
325
|
+
* MathLib.mulDivDown(
|
|
326
|
+
* minSharePriceE27,
|
|
327
|
+
* MathLib.WAD - slippageTolerance,
|
|
328
|
+
* MathLib.WAD,
|
|
329
|
+
* ),
|
|
330
|
+
* minSharePriceE27 - 1n,
|
|
331
|
+
* ),
|
|
332
|
+
* 1n,
|
|
333
|
+
* );
|
|
304
334
|
* const requiredShareAllowance = MathLib.min(
|
|
305
|
-
* MathLib.
|
|
335
|
+
* MathLib.max(
|
|
336
|
+
* MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27),
|
|
337
|
+
* MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n,
|
|
338
|
+
* ) +
|
|
306
339
|
* computeVaultV2ForceWithdrawFeeSharesMinted({
|
|
307
340
|
* vaultData,
|
|
308
341
|
* owner,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
1
|
+
export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
1
|
+
export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export type { CapacityLimit, RoundingDirection } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
2
|
+
export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
3
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
|
+
defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
|
|
5
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
|
+
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
3
7
|
export { decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
4
8
|
export { EcrecoverRatifierUtils as MidnightEcrecoverRatifierUtils, eip712Digest, GroupUtils as MidnightGroupUtils, MarketUtils as MidnightMarketUtils, OfferChainUtils as MidnightOfferChainUtils, OfferUtils as MidnightOfferUtils, Payload as MidnightPayload, PositionUtils as MidnightPositionUtils, RatifierUtils as MidnightRatifierUtils, SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
|
|
5
9
|
export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, } from "@morpho-org/morpho-ts";
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
1
|
+
export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
2
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
|
+
defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
|
|
4
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
+
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
2
6
|
export { decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
3
7
|
export { EcrecoverRatifierUtils as MidnightEcrecoverRatifierUtils, eip712Digest, GroupUtils as MidnightGroupUtils, MarketUtils as MidnightMarketUtils, OfferChainUtils as MidnightOfferChainUtils, OfferUtils as MidnightOfferUtils, Payload as MidnightPayload, PositionUtils as MidnightPositionUtils, RatifierUtils as MidnightRatifierUtils, SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
|
|
4
8
|
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
|