@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
|
@@ -11,6 +11,7 @@ export interface VaultV2Actions {
|
|
|
11
11
|
* @param {FetchParameters} [parameters] - The parameters for the fetch operation.
|
|
12
12
|
*
|
|
13
13
|
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>} The latest vault data.
|
|
14
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
|
|
14
15
|
*/
|
|
15
16
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
|
|
16
17
|
/**
|
|
@@ -21,7 +22,7 @@ export interface VaultV2Actions {
|
|
|
21
22
|
* Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
|
|
22
23
|
* always minted to the transaction sender, which must be `userAddress`.
|
|
23
24
|
* Concurrent requirement reads share the first caller's options; later calls refresh on-chain
|
|
24
|
-
* state using their own options.
|
|
25
|
+
* state using their own options.
|
|
25
26
|
*
|
|
26
27
|
* @param params.userAddress - Account that funds, signs, submits, and receives the vault shares.
|
|
27
28
|
* @param params.vaultData - Pre-fetched Vault V2 snapshot used for asset and share conversion.
|
|
@@ -57,8 +58,9 @@ export interface VaultV2Actions {
|
|
|
57
58
|
* `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
58
59
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
59
60
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
60
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature
|
|
61
|
-
* this
|
|
61
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
62
|
+
* deadline differ from this operation's, or when the signature's carried action nonce is
|
|
63
|
+
* inconsistent with its signed nonce.
|
|
62
64
|
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
63
65
|
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the vault asset.
|
|
64
66
|
* @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when signature metadata is malformed.
|
|
@@ -98,13 +100,14 @@ export interface VaultV2Actions {
|
|
|
98
100
|
/**
|
|
99
101
|
* Prepares an exact-assets Vault V2 withdrawal through VaultBundlesV1.
|
|
100
102
|
*
|
|
101
|
-
*
|
|
102
|
-
* vault-share allowance and, when a signature is needed, the permit nonce on
|
|
103
|
-
* Captures the requested amount and owner at creation, so later
|
|
104
|
-
* change this handle's requirements or transaction.
|
|
103
|
+
* Derives the share-burn cap from the supplied `vaultData` snapshot at handle creation, then
|
|
104
|
+
* reads the live vault-share allowance and, when a signature is needed, the permit nonce on
|
|
105
|
+
* each `getRequirements()` call. Captures the requested amount and owner at creation, so later
|
|
106
|
+
* changes to `params` do not change this handle's requirements or transaction.
|
|
105
107
|
*
|
|
106
108
|
* @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
|
|
107
109
|
* @param params.userAddress - Share owner that must sign and submit; receives the net assets.
|
|
110
|
+
* @param params.vaultData - Pre-fetched Vault V2 snapshot used to derive the share cap.
|
|
108
111
|
* @param params.slippageTolerance - Optional WAD-scaled share-price loss tolerance applied to
|
|
109
112
|
* the share cap.
|
|
110
113
|
* Defaults to 0.03% and cannot exceed 10%.
|
|
@@ -115,9 +118,13 @@ export interface VaultV2Actions {
|
|
|
115
118
|
* defaults to two hours from handle creation.
|
|
116
119
|
* @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
|
|
117
120
|
* which returns a deep-frozen `Transaction<VaultV2WithdrawAction>`. Requirements are empty
|
|
118
|
-
* when the allowance equals the cap;
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
+
* when the allowance equals the cap; an oversized allowance is always reset with an exact
|
|
122
|
+
* onchain approval, and an insufficient one is raised by an approval or, with signature
|
|
123
|
+
* support, an ERC-2612 request. The cap is fixed at handle creation while each call re-reads
|
|
124
|
+
* the allowance. Confirm the approval or pass its signed permit to `buildTx`.
|
|
125
|
+
* @remarks VaultBundlesV1 skips a share permit whose nonce was already consumed and proceeds
|
|
126
|
+
* under the live allowance, so execute every requirement returned by the latest
|
|
127
|
+
* `getRequirements()` — including the oversized-allowance reset — before submitting.
|
|
121
128
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
122
129
|
* @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
|
|
123
130
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
@@ -127,14 +134,14 @@ export interface VaultV2Actions {
|
|
|
127
134
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
128
135
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
129
136
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
|
|
137
|
+
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
130
138
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
131
139
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
132
140
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
133
141
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
|
|
134
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* @throws {viem.BaseError} when a vault, allowance, or nonce read or transaction encoding fails.
|
|
142
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed or
|
|
143
|
+
* its spender, amount or deadline differ from this operation's.
|
|
144
|
+
* @throws {viem.BaseError} when an allowance or nonce read or transaction encoding fails.
|
|
138
145
|
* @example
|
|
139
146
|
* ```ts
|
|
140
147
|
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
@@ -146,7 +153,8 @@ export interface VaultV2Actions {
|
|
|
146
153
|
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
147
154
|
* .extend(morphoViemExtension({ supportSignature: false }));
|
|
148
155
|
* const vault = client.morpho.vaultV2(vaultAddress, mainnet.id);
|
|
149
|
-
* const
|
|
156
|
+
* const vaultData = await vault.getData();
|
|
157
|
+
* const action = vault.withdraw({ amount: 1_000_000n, userAddress, vaultData });
|
|
150
158
|
* const requirements = await action.getRequirements();
|
|
151
159
|
* // Send and confirm each approval before calling action.buildTx().
|
|
152
160
|
* // action.buildTx() returns Readonly<Transaction<VaultV2WithdrawAction>>.
|
|
@@ -157,6 +165,7 @@ export interface VaultV2Actions {
|
|
|
157
165
|
withdraw: (params: {
|
|
158
166
|
readonly amount: bigint;
|
|
159
167
|
readonly userAddress: Address;
|
|
168
|
+
readonly vaultData: AccrualVaultV2;
|
|
160
169
|
readonly slippageTolerance?: bigint;
|
|
161
170
|
readonly referralFeePct?: bigint;
|
|
162
171
|
readonly referralFeeRecipient?: Address;
|
|
@@ -168,19 +177,19 @@ export interface VaultV2Actions {
|
|
|
168
177
|
* Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
|
|
169
178
|
* The caller must satisfy the exact vault-share allowance returned by `getRequirements()` before
|
|
170
179
|
* `buildTx()`; every requirement resolution re-reads the live allowance and checks the deadline.
|
|
171
|
-
* `buildTx()` accepts permits from the latest completed requirement resolution.
|
|
172
180
|
*
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
175
|
-
* @param
|
|
176
|
-
* @param
|
|
177
|
-
* @param
|
|
178
|
-
* @param
|
|
181
|
+
* @param params - The redeem parameters.
|
|
182
|
+
* @param params.shares - Exact vault shares to burn.
|
|
183
|
+
* @param params.userAddress - Account that must sign and submit the transaction; VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`.
|
|
184
|
+
* @param [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be below WAD.
|
|
185
|
+
* @param [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
|
|
186
|
+
* @param [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
|
|
179
187
|
* @returns Lazy exact share-allowance requirements and a synchronous transaction builder.
|
|
180
188
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
181
189
|
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
182
190
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
183
191
|
* requirement resolution.
|
|
192
|
+
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
184
193
|
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
185
194
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
186
195
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
@@ -189,8 +198,8 @@ export interface VaultV2Actions {
|
|
|
189
198
|
* @throws {viem.BaseError} from `getRequirements()` when an allowance or nonce read fails.
|
|
190
199
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
191
200
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
192
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the
|
|
193
|
-
*
|
|
201
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
202
|
+
* deadline differ from this operation's.
|
|
194
203
|
* @example
|
|
195
204
|
* ```ts
|
|
196
205
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -320,9 +329,11 @@ export interface VaultV2Actions {
|
|
|
320
329
|
* and permit nonce are read on-chain.
|
|
321
330
|
*
|
|
322
331
|
* The SDK derives a conservative lower bound on the realized exit share price from the snapshot
|
|
323
|
-
* and `slippageTolerance
|
|
324
|
-
*
|
|
325
|
-
*
|
|
332
|
+
* and `slippageTolerance`: the floor is priced off whichever of the raw snapshot or its accrual
|
|
333
|
+
* to `now` burns more shares, so neither pending fee mints nor interest the chain has not yet
|
|
334
|
+
* accrued can lift it above the realized price. A supplied `minSharePriceE27` replaces the
|
|
335
|
+
* tolerance-derived bound (it may be tighter or looser) but must be at least the floor derived
|
|
336
|
+
* at `MAX_SLIPPAGE_TOLERANCE`, so an override can never disable meaningful protection.
|
|
326
337
|
* The bound rejects a share price drop, a penalty increase, and liquidity shifting from the
|
|
327
338
|
* penalty-free leg to the penalised leg. It does **not** cover the referral fee, which the
|
|
328
339
|
* contract deducts afterwards.
|
|
@@ -332,16 +343,21 @@ export interface VaultV2Actions {
|
|
|
332
343
|
* send-shares gate is arbitrary code re-evaluated after each penalty burn. The SDK also does not
|
|
333
344
|
* validate the user's share balance. Per-market penalties and each vault withdrawal round the
|
|
334
345
|
* 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
|
-
*
|
|
346
|
+
* implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)` so a
|
|
347
|
+
* full-balance exit does not revert for insufficient shares. The approved share allowance this
|
|
348
|
+
* handle returns covers a burn at least one `slippageTolerance` step below the price floor
|
|
349
|
+
* whenever the floor exceeds one RAY unit and, in any case, at least one share above the burn
|
|
350
|
+
* at the floor, so a price within that headroom below the floor reverts on the contract's
|
|
351
|
+
* `minSharePriceE27` check rather than on the allowance; a deeper drop can still surface as an
|
|
352
|
+
* ERC-20 allowance underflow.
|
|
338
353
|
*
|
|
339
354
|
* Idle balance, penalty, adapter positions, and market liquidity can drift after the snapshot, so
|
|
340
355
|
* 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
|
|
356
|
+
* A fee-recipient `userAddress` gets a floor from the larger of the raw snapshot burn and the
|
|
357
|
+
* `now` burn net of its own fee mints, and a guard against fee mints reaching the lower burn
|
|
358
|
+
* bound by the deadline. Its allowance includes the projected fee shares through that same
|
|
359
|
+
* deadline. Deadlines beyond one year after handle creation are rejected, so the guard and
|
|
360
|
+
* allowance cover the whole accepted window.
|
|
345
361
|
*
|
|
346
362
|
* @param params - Force withdrawal parameters.
|
|
347
363
|
* @param params.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
|
|
@@ -396,7 +412,7 @@ export interface VaultV2Actions {
|
|
|
396
412
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
397
413
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender, amount, or
|
|
398
414
|
* deadline differs from this operation. Any handle built from the same inputs accepts the
|
|
399
|
-
* permit;
|
|
415
|
+
* permit; a permit whose nonce was consumed is skipped onchain and the live allowance applies.
|
|
400
416
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
401
417
|
* @example
|
|
402
418
|
* ```ts
|
|
@@ -486,6 +502,7 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
486
502
|
withdraw(params: {
|
|
487
503
|
readonly amount: bigint;
|
|
488
504
|
readonly userAddress: Address;
|
|
505
|
+
readonly vaultData: AccrualVaultV2;
|
|
489
506
|
readonly slippageTolerance?: bigint;
|
|
490
507
|
readonly referralFeePct?: bigint;
|
|
491
508
|
readonly referralFeeRecipient?: Address;
|
|
@@ -27,10 +27,7 @@ class MorphoVaultV2 {
|
|
|
27
27
|
this.chainId = chainId;
|
|
28
28
|
}
|
|
29
29
|
async getData(parameters) {
|
|
30
|
-
|
|
31
|
-
this.client.viemClient.chain?.id !== this.chainId) {
|
|
32
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
33
|
-
}
|
|
30
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
34
31
|
return (0, blue_sdk_viem_1.fetchAccrualVaultV2)(this.vault, this.client.viemClient, {
|
|
35
32
|
...parameters,
|
|
36
33
|
deployless: this.client.options.supportDeployless,
|
|
@@ -69,7 +66,6 @@ class MorphoVaultV2 {
|
|
|
69
66
|
});
|
|
70
67
|
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
71
68
|
let pendingRequirements;
|
|
72
|
-
let expectedRequirement;
|
|
73
69
|
return Object.freeze({
|
|
74
70
|
getRequirements: async (requirementOptions) => {
|
|
75
71
|
const now = morpho_ts_1.Time.timestamp();
|
|
@@ -77,33 +73,22 @@ class MorphoVaultV2 {
|
|
|
77
73
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
78
74
|
if (pendingRequirements != null)
|
|
79
75
|
return await pendingRequirements;
|
|
80
|
-
// Memoize the in-flight promise
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
97
|
-
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
98
|
-
});
|
|
99
|
-
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
100
|
-
expectedRequirement =
|
|
101
|
-
signatureRequirement?.action.type === "permit" ||
|
|
102
|
-
signatureRequirement?.action.type === "permit2SignatureTransfer"
|
|
103
|
-
? signatureRequirement.action
|
|
104
|
-
: undefined;
|
|
105
|
-
return requirements;
|
|
106
|
-
})();
|
|
76
|
+
// Memoize the in-flight promise so concurrent callers share one round of
|
|
77
|
+
// allowance/nonce reads.
|
|
78
|
+
const pending = funding.value > 0n
|
|
79
|
+
? Promise.resolve([])
|
|
80
|
+
: (0, index_js_4.getBundlesTokenRequirements)(this.client.viemClient, {
|
|
81
|
+
token: vaultAsset,
|
|
82
|
+
spender,
|
|
83
|
+
amount: funding.assets,
|
|
84
|
+
owner: userAddress,
|
|
85
|
+
chainId: this.chainId,
|
|
86
|
+
deadline,
|
|
87
|
+
supportSignature: this.client.options.supportSignature,
|
|
88
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
89
|
+
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
90
|
+
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
91
|
+
});
|
|
107
92
|
pendingRequirements = pending;
|
|
108
93
|
try {
|
|
109
94
|
return await pending;
|
|
@@ -115,7 +100,8 @@ class MorphoVaultV2 {
|
|
|
115
100
|
}
|
|
116
101
|
},
|
|
117
102
|
buildTx: (signatures) => {
|
|
118
|
-
|
|
103
|
+
// The pure deposit action rejects a token signature supplied alongside native funding.
|
|
104
|
+
const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signatures, { spender, amount: funding.assets, deadline });
|
|
119
105
|
return (0, index_js_1.vaultV2Deposit)({
|
|
120
106
|
vault: {
|
|
121
107
|
chainId: this.chainId,
|
|
@@ -139,8 +125,11 @@ class MorphoVaultV2 {
|
|
|
139
125
|
});
|
|
140
126
|
}
|
|
141
127
|
withdraw(params) {
|
|
142
|
-
const { amount, userAddress } = params;
|
|
128
|
+
const { amount, userAddress, vaultData } = params;
|
|
143
129
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
130
|
+
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
131
|
+
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
132
|
+
}
|
|
144
133
|
if (amount <= 0n)
|
|
145
134
|
throw new index_js_3.NonPositiveInputError("amount", amount);
|
|
146
135
|
// Reject values outside the ABI range before resolving any requirements.
|
|
@@ -156,11 +145,14 @@ class MorphoVaultV2 {
|
|
|
156
145
|
});
|
|
157
146
|
const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
|
|
158
147
|
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
159
|
-
//
|
|
160
|
-
(0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
148
|
+
// Resolve the spender eagerly so an unregistered VaultBundlesV1 fails at handle creation.
|
|
149
|
+
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
150
|
+
const requiredShareAllowance = (0, index_js_2.computeVaultMaxShareAllowance)({
|
|
151
|
+
vaultData,
|
|
152
|
+
deadline,
|
|
153
|
+
assets: amount,
|
|
154
|
+
slippageTolerance,
|
|
155
|
+
});
|
|
164
156
|
return Object.freeze({
|
|
165
157
|
getRequirements: async () => {
|
|
166
158
|
const now = morpho_ts_1.Time.timestamp();
|
|
@@ -169,18 +161,9 @@ class MorphoVaultV2 {
|
|
|
169
161
|
// Re-read the live share allowance on every call instead of caching the resolved
|
|
170
162
|
// requirements: the allowance is the sole cap on the burn, so a caller that executed the
|
|
171
163
|
// returned approval must see it satisfied on the next call, and an allowance revoked or
|
|
172
|
-
// raised afterwards must resurface as an outstanding requirement.
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
// fields only.
|
|
176
|
-
const vaultData = (vaultSnapshot ??= await this.getData());
|
|
177
|
-
requiredShareAllowance ??= (0, index_js_2.computeVaultMaxShareAllowance)({
|
|
178
|
-
vaultData,
|
|
179
|
-
deadline,
|
|
180
|
-
assets: amount,
|
|
181
|
-
slippageTolerance,
|
|
182
|
-
});
|
|
183
|
-
const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
164
|
+
// raised afterwards must resurface as an outstanding requirement. The cap derived from
|
|
165
|
+
// `vaultData` is pinned at handle creation, so re-reading cannot move it.
|
|
166
|
+
return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
184
167
|
vaultData,
|
|
185
168
|
version: "vaultV2",
|
|
186
169
|
owner: userAddress,
|
|
@@ -189,16 +172,12 @@ class MorphoVaultV2 {
|
|
|
189
172
|
deadline,
|
|
190
173
|
supportSignature: this.client.options.supportSignature,
|
|
191
174
|
});
|
|
192
|
-
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
193
|
-
if (signatureRequirement?.action.type === "permit") {
|
|
194
|
-
expectedRequirement = signatureRequirement.action;
|
|
195
|
-
}
|
|
196
|
-
return requirements;
|
|
197
175
|
},
|
|
198
176
|
buildTx: (signatures) => {
|
|
199
|
-
const permit = (0, common_js_1.
|
|
200
|
-
|
|
201
|
-
|
|
177
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
|
|
178
|
+
spender,
|
|
179
|
+
amount: requiredShareAllowance,
|
|
180
|
+
deadline,
|
|
202
181
|
});
|
|
203
182
|
return (0, index_js_1.vaultV2Withdraw)({
|
|
204
183
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -230,14 +209,13 @@ class MorphoVaultV2 {
|
|
|
230
209
|
referralFeePct: params.referralFeePct,
|
|
231
210
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
232
211
|
});
|
|
233
|
-
(0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
234
|
-
let expectedRequirement;
|
|
212
|
+
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
235
213
|
return Object.freeze({
|
|
236
214
|
getRequirements: async () => {
|
|
237
215
|
const now = morpho_ts_1.Time.timestamp();
|
|
238
216
|
if (deadline <= now)
|
|
239
217
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
240
|
-
|
|
218
|
+
return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
241
219
|
vaultData: await this.getData(),
|
|
242
220
|
version: "vaultV2",
|
|
243
221
|
owner: userAddress,
|
|
@@ -246,17 +224,12 @@ class MorphoVaultV2 {
|
|
|
246
224
|
deadline,
|
|
247
225
|
supportSignature: this.client.options.supportSignature,
|
|
248
226
|
});
|
|
249
|
-
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
250
|
-
expectedRequirement =
|
|
251
|
-
signatureRequirement?.action.type === "permit"
|
|
252
|
-
? signatureRequirement.action
|
|
253
|
-
: undefined;
|
|
254
|
-
return requirements;
|
|
255
227
|
},
|
|
256
228
|
buildTx: (signatures) => {
|
|
257
|
-
const permit = (0, common_js_1.
|
|
258
|
-
|
|
259
|
-
|
|
229
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
|
|
230
|
+
spender,
|
|
231
|
+
amount: shares,
|
|
232
|
+
deadline,
|
|
260
233
|
});
|
|
261
234
|
return (0, index_js_1.vaultV2Redeem)({
|
|
262
235
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -550,10 +523,19 @@ class MorphoVaultV2 {
|
|
|
550
523
|
}
|
|
551
524
|
const projectionTimestamp = deadline;
|
|
552
525
|
// VaultExitBundlesV1 measures shares as `sharesBefore - balanceAfter`; its first withdrawal
|
|
553
|
-
// accrues the vault before burning.
|
|
554
|
-
//
|
|
526
|
+
// accrues the vault before burning. The realized price sits between the raw snapshot price
|
|
527
|
+
// (pending fee mints not yet diluting it) and the `now` projection (interest the chain may not
|
|
528
|
+
// have accrued yet, e.g. when the wall clock runs ahead of the chain). Price the floor off the
|
|
529
|
+
// larger *net* burn of the two endpoints — the raw snapshot mints no fee shares, the `now`
|
|
530
|
+
// accrual mints `feeSharesNow` — so it never exceeds either, and use the projected deadline
|
|
531
|
+
// accrual for the fee-mint guard.
|
|
555
532
|
const { vault: nowVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(now, vaultData.lastUpdate));
|
|
556
533
|
const { vault: projectedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(projectionTimestamp, vaultData.lastUpdate));
|
|
534
|
+
const sharesBurntRaw = (0, index_js_2.computeVaultV2ForceWithdrawSharesBurnt)({
|
|
535
|
+
vaultData,
|
|
536
|
+
deadlineVaultData: vaultData,
|
|
537
|
+
plan,
|
|
538
|
+
});
|
|
557
539
|
const sharesBurntNow = (0, index_js_2.computeVaultV2ForceWithdrawSharesBurnt)({
|
|
558
540
|
vaultData: nowVaultData,
|
|
559
541
|
deadlineVaultData: nowVaultData,
|
|
@@ -584,13 +566,13 @@ class MorphoVaultV2 {
|
|
|
584
566
|
});
|
|
585
567
|
}
|
|
586
568
|
// sharesBurntNow ≥ minSharesBurntNow ≥ minSharesBurntProjected > feeSharesProjected ≥ feeSharesNow
|
|
587
|
-
const
|
|
569
|
+
const sharesBurntForFloor = blue_sdk_1.MathLib.max(sharesBurntRaw, sharesBurntNow - feeSharesNow);
|
|
588
570
|
if (minSharePriceE27Override != null) {
|
|
589
571
|
// The maximum-slippage threshold only bounds the override; unlike the transaction floor it
|
|
590
572
|
// may round to zero, in which case every positive override is acceptable.
|
|
591
573
|
const minAllowedSharePriceE27 = (0, morpho_ts_1._try)(() => (0, index_js_2.computeMinForceWithdrawSharePrice)({
|
|
592
574
|
withdrawnAssets: plan.withdrawnAssets,
|
|
593
|
-
sharesBurnt:
|
|
575
|
+
sharesBurnt: sharesBurntForFloor,
|
|
594
576
|
slippageTolerance: index_js_2.MAX_SLIPPAGE_TOLERANCE,
|
|
595
577
|
}), index_js_3.VaultV2ForceWithdrawZeroSharePriceError) ?? 1n;
|
|
596
578
|
if (minSharePriceE27Override < minAllowedSharePriceE27) {
|
|
@@ -603,7 +585,7 @@ class MorphoVaultV2 {
|
|
|
603
585
|
const minSharePriceE27 = minSharePriceE27Override ??
|
|
604
586
|
(0, index_js_2.computeMinForceWithdrawSharePrice)({
|
|
605
587
|
withdrawnAssets: plan.withdrawnAssets,
|
|
606
|
-
sharesBurnt:
|
|
588
|
+
sharesBurnt: sharesBurntForFloor,
|
|
607
589
|
slippageTolerance,
|
|
608
590
|
});
|
|
609
591
|
// The floor is deliberately *not* capped at `MAX_ABSOLUTE_SHARE_PRICE` (100 assets/share):
|
|
@@ -611,11 +593,19 @@ class MorphoVaultV2 {
|
|
|
611
593
|
// with no real protection. Its two sibling `computeMin*SharePrice` helpers cap nothing either —
|
|
612
594
|
// only the `computeMax*` ones do, where capping relaxes an upper bound and is safe.
|
|
613
595
|
(0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27);
|
|
614
|
-
//
|
|
615
|
-
//
|
|
616
|
-
//
|
|
617
|
-
|
|
618
|
-
|
|
596
|
+
// The allowance is only a spend cap, never the price protection: the bundle checks
|
|
597
|
+
// `minSharePriceE27` after its last withdrawal, so an allowance sized exactly to the floor
|
|
598
|
+
// underflows `_spendAllowance` (panic 0x11) on a below-floor price before that check runs. Size
|
|
599
|
+
// it for a price at least one tolerance step below the floor so the miss surfaces as the
|
|
600
|
+
// bundle's own revert instead, and, in any case, for at least one share above the at-floor
|
|
601
|
+
// burn — a burn of `atFloor + 1` shares prices strictly below the floor since
|
|
602
|
+
// `atFloor >= exitAssets * RAY / floor`. The `minSharePriceE27 - 1` branch keeps the
|
|
603
|
+
// denominator strictly below the floor whenever the floor exceeds 1, so even
|
|
604
|
+
// `slippageTolerance: 0n` leaves price-space headroom; a deeper drop still exhausts the
|
|
605
|
+
// allowance first. Add the fee shares the first withdrawal mints since the burn measured
|
|
606
|
+
// on-chain includes them. Saturated at `maxUint256` as an ABI-slot guard.
|
|
607
|
+
const allowanceSharePriceE27 = blue_sdk_1.MathLib.max(blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivDown(minSharePriceE27, blue_sdk_1.MathLib.WAD - slippageTolerance, blue_sdk_1.MathLib.WAD), minSharePriceE27 - 1n), 1n);
|
|
608
|
+
const requiredShareAllowance = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.max(blue_sdk_1.MathLib.mulDivUp(exitAssets, blue_sdk_1.MathLib.RAY, allowanceSharePriceE27), blue_sdk_1.MathLib.mulDivUp(exitAssets, blue_sdk_1.MathLib.RAY, minSharePriceE27) + 1n) + feeSharesProjected, viem_1.maxUint256);
|
|
619
609
|
const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
|
|
620
610
|
return {
|
|
621
611
|
getRequirements: async () => {
|
package/lib/cjs/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/cjs/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
|
|
3
|
+
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
|
|
6
6
|
Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
|
|
@@ -16,11 +16,13 @@ Object.defineProperty(exports, "UnknownBlueTokenPriceError", { enumerable: true,
|
|
|
16
16
|
Object.defineProperty(exports, "UnknownBlueVaultConfigError", { enumerable: true, get: function () { return blue_sdk_1.UnknownVaultConfigError; } });
|
|
17
17
|
Object.defineProperty(exports, "UnsupportedChainIdError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedChainIdError; } });
|
|
18
18
|
Object.defineProperty(exports, "UnsupportedBlueMarketIrmError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedMarketIrmError; } });
|
|
19
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
19
20
|
Object.defineProperty(exports, "UnsupportedBluePreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
|
|
20
21
|
Object.defineProperty(exports, "UnsupportedBlueVaultV2AdapterError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedVaultV2AdapterError; } });
|
|
21
22
|
Object.defineProperty(exports, "VaultV2Errors", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Errors; } });
|
|
22
23
|
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
23
24
|
Object.defineProperty(exports, "getBlueUnsupportedVaultV2Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.getUnsupportedVaultV2Adapter; } });
|
|
25
|
+
Object.defineProperty(exports, "InvalidNumberError", { enumerable: true, get: function () { return blue_sdk_viem_1.InvalidNumberError; } });
|
|
24
26
|
Object.defineProperty(exports, "InvalidPermitDomainChainIdError", { enumerable: true, get: function () { return blue_sdk_viem_1.InvalidPermitDomainChainIdError; } });
|
|
25
27
|
Object.defineProperty(exports, "InvalidPermitDomainVerifyingContractError", { enumerable: true, get: function () { return blue_sdk_viem_1.InvalidPermitDomainVerifyingContractError; } });
|
|
26
28
|
Object.defineProperty(exports, "isBlueUnknownOfFactoryError", { enumerable: true, get: function () { return blue_sdk_viem_1.isUnknownOfFactoryError; } });
|
|
@@ -29,6 +31,7 @@ var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
|
29
31
|
Object.defineProperty(exports, "MidnightChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
|
|
30
32
|
Object.defineProperty(exports, "InvalidMidnightEcrecoverSignatureVError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureVError; } });
|
|
31
33
|
Object.defineProperty(exports, "InvalidMidnightMarketParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMarketParameterError; } });
|
|
34
|
+
Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiQuoteTargetError; } });
|
|
32
35
|
Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
|
|
33
36
|
Object.defineProperty(exports, "InvalidMidnightOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
|
|
34
37
|
Object.defineProperty(exports, "InvalidMidnightOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
|
package/lib/cjs/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/cjs/fetch.js
CHANGED
|
@@ -13,7 +13,9 @@ Object.defineProperty(exports, "fetchHolding", { enumerable: true, get: function
|
|
|
13
13
|
Object.defineProperty(exports, "fetchBlueMarket", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchMarket; } });
|
|
14
14
|
Object.defineProperty(exports, "fetchBlueMarketParams", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchMarketParams; } });
|
|
15
15
|
Object.defineProperty(exports, "fetchBluePosition", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchPosition; } });
|
|
16
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
16
17
|
Object.defineProperty(exports, "fetchBluePreLiquidationParams", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchPreLiquidationParams; } });
|
|
18
|
+
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
17
19
|
Object.defineProperty(exports, "fetchBluePreLiquidationPosition", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchPreLiquidationPosition; } });
|
|
18
20
|
Object.defineProperty(exports, "fetchToken", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchToken; } });
|
|
19
21
|
Object.defineProperty(exports, "fetchBlueUser", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchUser; } });
|
|
@@ -98,15 +98,21 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
98
98
|
// zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
|
|
99
99
|
// dwarfing `totalAssets`) offers no price protection at all. Screen at the entity's default
|
|
100
100
|
// `DEFAULT_SLIPPAGE_TOLERANCE`, not slippage-free, against the same burn upper bound the entity
|
|
101
|
-
// divides by (
|
|
102
|
-
// realized price is a single RAY-unit, yet
|
|
103
|
-
// to zero — so the entity would reject
|
|
101
|
+
// divides by (the larger of the raw snapshot burn and the net burn accrued to `timestamp` like
|
|
102
|
+
// the plan): a tolerance-free screen clears an exit whose realized price is a single RAY-unit, yet
|
|
103
|
+
// the default tolerance scales that below 1 and rounds it to zero — so the entity would reject
|
|
104
|
+
// with `VaultV2ForceWithdrawZeroSharePriceError` the very
|
|
104
105
|
// `exitAssets` this preview handed back. A caller passing a larger tolerance still relies on the
|
|
105
106
|
// entity's own guard. The entity validates this derived value with
|
|
106
107
|
// `validateUint256Field("minSharePriceE27")`, which throws `InputExceedsMaxError` when it
|
|
107
108
|
// cannot fit uint256.
|
|
108
109
|
const { vault: accruedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(timestamp, vaultData.lastUpdate));
|
|
109
|
-
const
|
|
110
|
+
const sharesBurntRaw = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawSharesBurnt)({
|
|
111
|
+
vaultData,
|
|
112
|
+
deadlineVaultData: vaultData,
|
|
113
|
+
plan,
|
|
114
|
+
});
|
|
115
|
+
const sharesBurntAccrued = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawSharesBurnt)({
|
|
110
116
|
vaultData: accruedVaultData,
|
|
111
117
|
deadlineVaultData: accruedVaultData,
|
|
112
118
|
plan,
|
|
@@ -135,7 +141,7 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
135
141
|
return undefined;
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
|
-
const sharesBurntForFloor =
|
|
144
|
+
const sharesBurntForFloor = blue_sdk_1.MathLib.max(sharesBurntRaw, sharesBurntAccrued - feeShares);
|
|
139
145
|
const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
|
|
140
146
|
? blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
|
|
141
147
|
: 0n;
|