@morpho-org/morpho-sdk 6.0.0-next.3 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v5-to-v6.md +24 -16
- package/README.md +6 -4
- package/lib/cjs/abis.d.ts +5 -1
- package/lib/cjs/abis.js +2 -0
- package/lib/cjs/actions/bundles/common.d.ts +20 -25
- package/lib/cjs/actions/bundles/common.js +46 -85
- package/lib/cjs/actions/bundles/index.d.ts +1 -1
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +19 -1
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +12 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +2 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +2 -1
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +62 -17
- package/lib/cjs/actions/vaultV1/migrateToV2.js +48 -17
- package/lib/cjs/actions/vaultV1/redeem.d.ts +28 -1
- package/lib/cjs/actions/vaultV1/redeem.js +17 -1
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.js +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +3 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -2
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +2 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +2 -1
- package/lib/cjs/actions/vaultV2/redeem.d.ts +28 -1
- package/lib/cjs/actions/vaultV2/redeem.js +17 -1
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.js +1 -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 +31 -21
- package/lib/cjs/entities/vaultV1/vaultV1.js +50 -83
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +52 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +71 -81
- 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/types/action.d.ts +1 -0
- 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 +20 -25
- package/lib/esm/actions/bundles/common.js +44 -82
- package/lib/esm/actions/bundles/index.d.ts +1 -1
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -3
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +14 -2
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +2 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +2 -1
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +62 -17
- package/lib/esm/actions/vaultV1/migrateToV2.js +48 -17
- package/lib/esm/actions/vaultV1/redeem.d.ts +28 -1
- package/lib/esm/actions/vaultV1/redeem.js +17 -1
- package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV1/withdraw.js +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +3 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -2
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +2 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.js +2 -1
- package/lib/esm/actions/vaultV2/redeem.d.ts +28 -1
- package/lib/esm/actions/vaultV2/redeem.js +17 -1
- package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/withdraw.js +1 -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 +31 -21
- package/lib/esm/entities/vaultV1/vaultV1.js +52 -85
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +52 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +73 -83
- 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/types/action.d.ts +1 -0
- package/lib/esm/utils.d.ts +5 -1
- package/lib/esm/utils.js +5 -1
- package/package.json +6 -9
|
@@ -3,11 +3,11 @@ import { erc2612Abi, fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
|
3
3
|
import { _try, getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
|
|
5
5
|
import { multicall } from "viem/actions";
|
|
6
|
-
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature,
|
|
6
|
+
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
7
|
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2InKindRedeem, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
|
|
8
8
|
import { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, MAX_SLIPPAGE_TOLERANCE, resolveVaultV2ForceWithdrawEligibility, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
9
|
import { validateDeadline, validateNativeVaultAsset, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
|
|
10
|
-
import { AdapterNotPartOfVaultError,
|
|
10
|
+
import { AdapterNotPartOfVaultError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InKindRedeemZeroDeallocationError, InputExceedsMaxError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, VaultAddressMismatchError, VaultV2ForceWithdrawCoverageError, VaultV2ForceWithdrawFeeSharesExceedBurnError, VaultV2ForceWithdrawSharePriceBelowFloorError, VaultV2ForceWithdrawZeroSharePriceError, 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
13
|
// Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
|
|
@@ -24,10 +24,7 @@ export class MorphoVaultV2 {
|
|
|
24
24
|
this.chainId = chainId;
|
|
25
25
|
}
|
|
26
26
|
async getData(parameters) {
|
|
27
|
-
|
|
28
|
-
this.client.viemClient.chain?.id !== this.chainId) {
|
|
29
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
30
|
-
}
|
|
27
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
31
28
|
return fetchAccrualVaultV2(this.vault, this.client.viemClient, {
|
|
32
29
|
...parameters,
|
|
33
30
|
deployless: this.client.options.supportDeployless,
|
|
@@ -66,7 +63,6 @@ export class MorphoVaultV2 {
|
|
|
66
63
|
});
|
|
67
64
|
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
68
65
|
let pendingRequirements;
|
|
69
|
-
let expectedRequirement;
|
|
70
66
|
return Object.freeze({
|
|
71
67
|
getRequirements: async (requirementOptions) => {
|
|
72
68
|
const now = Time.timestamp();
|
|
@@ -74,33 +70,22 @@ export class MorphoVaultV2 {
|
|
|
74
70
|
throw new ExpiredDeadlineError(deadline, now);
|
|
75
71
|
if (pendingRequirements != null)
|
|
76
72
|
return await pendingRequirements;
|
|
77
|
-
// Memoize the in-flight promise
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
94
|
-
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
95
|
-
});
|
|
96
|
-
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
97
|
-
expectedRequirement =
|
|
98
|
-
signatureRequirement?.action.type === "permit" ||
|
|
99
|
-
signatureRequirement?.action.type === "permit2SignatureTransfer"
|
|
100
|
-
? signatureRequirement.action
|
|
101
|
-
: undefined;
|
|
102
|
-
return requirements;
|
|
103
|
-
})();
|
|
73
|
+
// Memoize the in-flight promise so concurrent callers share one round of
|
|
74
|
+
// allowance/nonce reads.
|
|
75
|
+
const pending = funding.value > 0n
|
|
76
|
+
? Promise.resolve([])
|
|
77
|
+
: getBundlesTokenRequirements(this.client.viemClient, {
|
|
78
|
+
token: vaultAsset,
|
|
79
|
+
spender,
|
|
80
|
+
amount: funding.assets,
|
|
81
|
+
owner: userAddress,
|
|
82
|
+
chainId: this.chainId,
|
|
83
|
+
deadline,
|
|
84
|
+
supportSignature: this.client.options.supportSignature,
|
|
85
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
86
|
+
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
87
|
+
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
88
|
+
});
|
|
104
89
|
pendingRequirements = pending;
|
|
105
90
|
try {
|
|
106
91
|
return await pending;
|
|
@@ -112,7 +97,8 @@ export class MorphoVaultV2 {
|
|
|
112
97
|
}
|
|
113
98
|
},
|
|
114
99
|
buildTx: (signatures) => {
|
|
115
|
-
|
|
100
|
+
// The pure deposit action rejects a token signature supplied alongside native funding.
|
|
101
|
+
const requirementSignature = selectBundlesTokenRequirementSignature(signatures, { spender, amount: funding.assets, deadline });
|
|
116
102
|
return vaultV2Deposit({
|
|
117
103
|
vault: {
|
|
118
104
|
chainId: this.chainId,
|
|
@@ -136,8 +122,11 @@ export class MorphoVaultV2 {
|
|
|
136
122
|
});
|
|
137
123
|
}
|
|
138
124
|
withdraw(params) {
|
|
139
|
-
const { amount, userAddress } = params;
|
|
125
|
+
const { amount, userAddress, vaultData } = params;
|
|
140
126
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
127
|
+
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
128
|
+
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
129
|
+
}
|
|
141
130
|
if (amount <= 0n)
|
|
142
131
|
throw new NonPositiveInputError("amount", amount);
|
|
143
132
|
// Reject values outside the ABI range before resolving any requirements.
|
|
@@ -153,11 +142,14 @@ export class MorphoVaultV2 {
|
|
|
153
142
|
});
|
|
154
143
|
const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
|
|
155
144
|
validateSlippageTolerance(slippageTolerance);
|
|
156
|
-
//
|
|
157
|
-
getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
145
|
+
// Resolve the spender eagerly so an unregistered VaultBundlesV1 fails at handle creation.
|
|
146
|
+
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
147
|
+
const requiredShareAllowance = computeVaultMaxShareAllowance({
|
|
148
|
+
vaultData,
|
|
149
|
+
deadline,
|
|
150
|
+
assets: amount,
|
|
151
|
+
slippageTolerance,
|
|
152
|
+
});
|
|
161
153
|
return Object.freeze({
|
|
162
154
|
getRequirements: async () => {
|
|
163
155
|
const now = Time.timestamp();
|
|
@@ -166,18 +158,9 @@ export class MorphoVaultV2 {
|
|
|
166
158
|
// Re-read the live share allowance on every call instead of caching the resolved
|
|
167
159
|
// requirements: the allowance is the sole cap on the burn, so a caller that executed the
|
|
168
160
|
// returned approval must see it satisfied on the next call, and an allowance revoked or
|
|
169
|
-
// raised afterwards must resurface as an outstanding requirement.
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
// fields only.
|
|
173
|
-
const vaultData = (vaultSnapshot ??= await this.getData());
|
|
174
|
-
requiredShareAllowance ??= computeVaultMaxShareAllowance({
|
|
175
|
-
vaultData,
|
|
176
|
-
deadline,
|
|
177
|
-
assets: amount,
|
|
178
|
-
slippageTolerance,
|
|
179
|
-
});
|
|
180
|
-
const requirements = await getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
161
|
+
// raised afterwards must resurface as an outstanding requirement. The cap derived from
|
|
162
|
+
// `vaultData` is pinned at handle creation, so re-reading cannot move it.
|
|
163
|
+
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
181
164
|
vaultData,
|
|
182
165
|
version: "vaultV2",
|
|
183
166
|
owner: userAddress,
|
|
@@ -186,16 +169,12 @@ export class MorphoVaultV2 {
|
|
|
186
169
|
deadline,
|
|
187
170
|
supportSignature: this.client.options.supportSignature,
|
|
188
171
|
});
|
|
189
|
-
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
190
|
-
if (signatureRequirement?.action.type === "permit") {
|
|
191
|
-
expectedRequirement = signatureRequirement.action;
|
|
192
|
-
}
|
|
193
|
-
return requirements;
|
|
194
172
|
},
|
|
195
173
|
buildTx: (signatures) => {
|
|
196
|
-
const permit =
|
|
197
|
-
|
|
198
|
-
|
|
174
|
+
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
175
|
+
spender,
|
|
176
|
+
amount: requiredShareAllowance,
|
|
177
|
+
deadline,
|
|
199
178
|
});
|
|
200
179
|
return vaultV2Withdraw({
|
|
201
180
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -227,14 +206,13 @@ export class MorphoVaultV2 {
|
|
|
227
206
|
referralFeePct: params.referralFeePct,
|
|
228
207
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
229
208
|
});
|
|
230
|
-
getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
231
|
-
let expectedRequirement;
|
|
209
|
+
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
232
210
|
return Object.freeze({
|
|
233
211
|
getRequirements: async () => {
|
|
234
212
|
const now = Time.timestamp();
|
|
235
213
|
if (deadline <= now)
|
|
236
214
|
throw new ExpiredDeadlineError(deadline, now);
|
|
237
|
-
|
|
215
|
+
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
238
216
|
vaultData: await this.getData(),
|
|
239
217
|
version: "vaultV2",
|
|
240
218
|
owner: userAddress,
|
|
@@ -243,17 +221,12 @@ export class MorphoVaultV2 {
|
|
|
243
221
|
deadline,
|
|
244
222
|
supportSignature: this.client.options.supportSignature,
|
|
245
223
|
});
|
|
246
|
-
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
247
|
-
expectedRequirement =
|
|
248
|
-
signatureRequirement?.action.type === "permit"
|
|
249
|
-
? signatureRequirement.action
|
|
250
|
-
: undefined;
|
|
251
|
-
return requirements;
|
|
252
224
|
},
|
|
253
225
|
buildTx: (signatures) => {
|
|
254
|
-
const permit =
|
|
255
|
-
|
|
256
|
-
|
|
226
|
+
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
227
|
+
spender,
|
|
228
|
+
amount: shares,
|
|
229
|
+
deadline,
|
|
257
230
|
});
|
|
258
231
|
return vaultV2Redeem({
|
|
259
232
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -547,10 +520,19 @@ export class MorphoVaultV2 {
|
|
|
547
520
|
}
|
|
548
521
|
const projectionTimestamp = deadline;
|
|
549
522
|
// VaultExitBundlesV1 measures shares as `sharesBefore - balanceAfter`; its first withdrawal
|
|
550
|
-
// accrues the vault before burning.
|
|
551
|
-
//
|
|
523
|
+
// accrues the vault before burning. The realized price sits between the raw snapshot price
|
|
524
|
+
// (pending fee mints not yet diluting it) and the `now` projection (interest the chain may not
|
|
525
|
+
// have accrued yet, e.g. when the wall clock runs ahead of the chain). Price the floor off the
|
|
526
|
+
// larger *net* burn of the two endpoints — the raw snapshot mints no fee shares, the `now`
|
|
527
|
+
// accrual mints `feeSharesNow` — so it never exceeds either, and use the projected deadline
|
|
528
|
+
// accrual for the fee-mint guard.
|
|
552
529
|
const { vault: nowVaultData } = vaultData.accrueInterest(MathLib.max(now, vaultData.lastUpdate));
|
|
553
530
|
const { vault: projectedVaultData } = vaultData.accrueInterest(MathLib.max(projectionTimestamp, vaultData.lastUpdate));
|
|
531
|
+
const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
|
|
532
|
+
vaultData,
|
|
533
|
+
deadlineVaultData: vaultData,
|
|
534
|
+
plan,
|
|
535
|
+
});
|
|
554
536
|
const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
|
|
555
537
|
vaultData: nowVaultData,
|
|
556
538
|
deadlineVaultData: nowVaultData,
|
|
@@ -581,13 +563,13 @@ export class MorphoVaultV2 {
|
|
|
581
563
|
});
|
|
582
564
|
}
|
|
583
565
|
// sharesBurntNow ≥ minSharesBurntNow ≥ minSharesBurntProjected > feeSharesProjected ≥ feeSharesNow
|
|
584
|
-
const
|
|
566
|
+
const sharesBurntForFloor = MathLib.max(sharesBurntRaw, sharesBurntNow - feeSharesNow);
|
|
585
567
|
if (minSharePriceE27Override != null) {
|
|
586
568
|
// The maximum-slippage threshold only bounds the override; unlike the transaction floor it
|
|
587
569
|
// may round to zero, in which case every positive override is acceptable.
|
|
588
570
|
const minAllowedSharePriceE27 = _try(() => computeMinForceWithdrawSharePrice({
|
|
589
571
|
withdrawnAssets: plan.withdrawnAssets,
|
|
590
|
-
sharesBurnt:
|
|
572
|
+
sharesBurnt: sharesBurntForFloor,
|
|
591
573
|
slippageTolerance: MAX_SLIPPAGE_TOLERANCE,
|
|
592
574
|
}), VaultV2ForceWithdrawZeroSharePriceError) ?? 1n;
|
|
593
575
|
if (minSharePriceE27Override < minAllowedSharePriceE27) {
|
|
@@ -600,7 +582,7 @@ export class MorphoVaultV2 {
|
|
|
600
582
|
const minSharePriceE27 = minSharePriceE27Override ??
|
|
601
583
|
computeMinForceWithdrawSharePrice({
|
|
602
584
|
withdrawnAssets: plan.withdrawnAssets,
|
|
603
|
-
sharesBurnt:
|
|
585
|
+
sharesBurnt: sharesBurntForFloor,
|
|
604
586
|
slippageTolerance,
|
|
605
587
|
});
|
|
606
588
|
// The floor is deliberately *not* capped at `MAX_ABSOLUTE_SHARE_PRICE` (100 assets/share):
|
|
@@ -608,11 +590,19 @@ export class MorphoVaultV2 {
|
|
|
608
590
|
// with no real protection. Its two sibling `computeMin*SharePrice` helpers cap nothing either —
|
|
609
591
|
// only the `computeMax*` ones do, where capping relaxes an upper bound and is safe.
|
|
610
592
|
validateUint256Field("minSharePriceE27", minSharePriceE27);
|
|
611
|
-
//
|
|
612
|
-
//
|
|
613
|
-
//
|
|
614
|
-
|
|
615
|
-
|
|
593
|
+
// The allowance is only a spend cap, never the price protection: the bundle checks
|
|
594
|
+
// `minSharePriceE27` after its last withdrawal, so an allowance sized exactly to the floor
|
|
595
|
+
// underflows `_spendAllowance` (panic 0x11) on a below-floor price before that check runs. Size
|
|
596
|
+
// it for a price at least one tolerance step below the floor so the miss surfaces as the
|
|
597
|
+
// bundle's own revert instead, and, in any case, for at least one share above the at-floor
|
|
598
|
+
// burn — a burn of `atFloor + 1` shares prices strictly below the floor since
|
|
599
|
+
// `atFloor >= exitAssets * RAY / floor`. The `minSharePriceE27 - 1` branch keeps the
|
|
600
|
+
// denominator strictly below the floor whenever the floor exceeds 1, so even
|
|
601
|
+
// `slippageTolerance: 0n` leaves price-space headroom; a deeper drop still exhausts the
|
|
602
|
+
// allowance first. Add the fee shares the first withdrawal mints since the burn measured
|
|
603
|
+
// on-chain includes them. Saturated at `maxUint256` as an ABI-slot guard.
|
|
604
|
+
const allowanceSharePriceE27 = MathLib.max(MathLib.min(MathLib.mulDivDown(minSharePriceE27, MathLib.WAD - slippageTolerance, MathLib.WAD), minSharePriceE27 - 1n), 1n);
|
|
605
|
+
const requiredShareAllowance = MathLib.min(MathLib.max(MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27), MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n) + feeSharesProjected, maxUint256);
|
|
616
606
|
const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
|
|
617
607
|
return {
|
|
618
608
|
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";
|
|
@@ -482,6 +482,7 @@ export interface MidnightOfferRootSignatureArgs {
|
|
|
482
482
|
}
|
|
483
483
|
/** EIP-712 payload carried by a signable requirement action. */
|
|
484
484
|
export type RequirementTypedData = TypedDataDefinition<Record<string, unknown>, string>;
|
|
485
|
+
/** Signable ERC-2612 permit requirement for a fixed-bundles token pull. */
|
|
485
486
|
export interface PermitAction extends BaseAction<"permit", {
|
|
486
487
|
readonly spender: Address;
|
|
487
488
|
readonly amount: bigint;
|
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";
|