@morpho-org/morpho-sdk 6.0.0-next.4 → 6.1.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 +21 -15
- package/README.md +7 -5
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +3 -1
- package/lib/cjs/actions/bundles/common.d.ts +18 -23
- package/lib/cjs/actions/bundles/common.js +36 -83
- 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/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 +19 -7
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +19 -7
- 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/constants.d.ts +1 -1
- package/lib/cjs/constants.js +4 -1
- package/lib/cjs/entities/blue/blue.d.ts +28 -0
- package/lib/cjs/entities/blue/blue.js +1 -0
- package/lib/cjs/entities/index.d.ts +1 -1
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +38 -22
- package/lib/cjs/entities/vaultV1/vaultV1.js +51 -84
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +68 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +45 -72
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +8 -1
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +10 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -6
- package/lib/cjs/helpers/slippage.d.ts +3 -2
- package/lib/cjs/helpers/slippage.js +3 -2
- package/lib/cjs/helpers/validate.d.ts +40 -0
- package/lib/cjs/helpers/validate.js +40 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +94 -59
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +94 -59
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +3 -1
- package/lib/cjs/midnight/constants.d.ts +1 -1
- package/lib/cjs/midnight/constants.js +4 -1
- package/lib/cjs/midnight/entities.d.ts +1 -1
- package/lib/cjs/midnight/errors.d.ts +1 -1
- package/lib/cjs/midnight/errors.js +7 -1
- package/lib/cjs/midnight/types.d.ts +1 -1
- package/lib/cjs/midnight/utils.d.ts +11 -1
- package/lib/cjs/midnight/utils.js +13 -1
- package/lib/cjs/types/action.d.ts +35 -0
- package/lib/cjs/types/action.js +10 -0
- package/lib/cjs/types.d.ts +1 -1
- package/lib/cjs/utils.d.ts +11 -1
- package/lib/cjs/utils.js +14 -2
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +18 -23
- package/lib/esm/actions/bundles/common.js +34 -80
- 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/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 +19 -7
- package/lib/esm/actions/vaultV2/forceWithdraw.js +19 -7
- 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/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +28 -0
- package/lib/esm/entities/blue/blue.js +1 -0
- package/lib/esm/entities/index.d.ts +1 -1
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +38 -22
- package/lib/esm/entities/vaultV1/vaultV1.js +53 -86
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +68 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +47 -74
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +10 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -6
- package/lib/esm/helpers/slippage.d.ts +3 -2
- package/lib/esm/helpers/slippage.js +3 -2
- package/lib/esm/helpers/validate.d.ts +40 -0
- package/lib/esm/helpers/validate.js +40 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +94 -59
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +94 -59
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/midnight/constants.d.ts +1 -1
- package/lib/esm/midnight/constants.js +1 -1
- package/lib/esm/midnight/entities.d.ts +1 -1
- package/lib/esm/midnight/errors.d.ts +1 -1
- package/lib/esm/midnight/errors.js +1 -1
- package/lib/esm/midnight/types.d.ts +1 -1
- package/lib/esm/midnight/utils.d.ts +11 -1
- package/lib/esm/midnight/utils.js +11 -1
- package/lib/esm/types/action.d.ts +35 -0
- package/lib/esm/types/action.js +10 -0
- package/lib/esm/types.d.ts +1 -1
- package/lib/esm/utils.d.ts +11 -1
- package/lib/esm/utils.js +11 -1
- package/package.json +5 -5
|
@@ -3,14 +3,24 @@ import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import type { FetchParameters } from "../../types/data.js";
|
|
5
5
|
import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type Deallocation, type MorphoClientType, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2InKindRedeemAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Action surface for Vault V2 reads and writes; writes route through VaultBundlesV1 and
|
|
8
|
+
* VaultExitBundlesV1, except `forceRedeem`, which uses the vault's native multicall.
|
|
9
|
+
*/
|
|
6
10
|
export interface VaultV2Actions {
|
|
7
11
|
/**
|
|
8
|
-
* Fetches the latest vault
|
|
12
|
+
* Fetches the latest accrual snapshot of the vault.
|
|
9
13
|
*
|
|
10
|
-
*
|
|
11
|
-
* @param {FetchParameters} [parameters] - The parameters for the fetch operation.
|
|
14
|
+
* Reads the Vault V2 state through `fetchAccrualVaultV2` on the entity's client.
|
|
12
15
|
*
|
|
13
|
-
* @
|
|
16
|
+
* @param parameters - Optional viem fetch parameters (block number, block tag, state override).
|
|
17
|
+
* @returns The hydrated `AccrualVaultV2` snapshot.
|
|
18
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
|
|
19
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
20
|
+
* @throws {UnknownBlueFactory} when the configured chain has no VaultV2 factory.
|
|
21
|
+
* @throws {UnknownBlueOfFactory} when the vault is not a VaultV2 from the configured factory.
|
|
22
|
+
* @throws {UnsupportedBlueVaultV2AdapterError} when the vault or one of its adapters uses an
|
|
23
|
+
* unsupported adapter class.
|
|
14
24
|
*/
|
|
15
25
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
|
|
16
26
|
/**
|
|
@@ -21,7 +31,7 @@ export interface VaultV2Actions {
|
|
|
21
31
|
* Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
|
|
22
32
|
* always minted to the transaction sender, which must be `userAddress`.
|
|
23
33
|
* Concurrent requirement reads share the first caller's options; later calls refresh on-chain
|
|
24
|
-
* state using their own options.
|
|
34
|
+
* state using their own options.
|
|
25
35
|
*
|
|
26
36
|
* @param params.userAddress - Account that funds, signs, submits, and receives the vault shares.
|
|
27
37
|
* @param params.vaultData - Pre-fetched Vault V2 snapshot used for asset and share conversion.
|
|
@@ -57,8 +67,9 @@ export interface VaultV2Actions {
|
|
|
57
67
|
* `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
58
68
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
59
69
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
60
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature
|
|
61
|
-
* this
|
|
70
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
71
|
+
* deadline differ from this operation's, or when the signature's carried action nonce is
|
|
72
|
+
* inconsistent with its signed nonce.
|
|
62
73
|
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
63
74
|
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the vault asset.
|
|
64
75
|
* @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when signature metadata is malformed.
|
|
@@ -98,13 +109,14 @@ export interface VaultV2Actions {
|
|
|
98
109
|
/**
|
|
99
110
|
* Prepares an exact-assets Vault V2 withdrawal through VaultBundlesV1.
|
|
100
111
|
*
|
|
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.
|
|
112
|
+
* Derives the share-burn cap from the supplied `vaultData` snapshot at handle creation, then
|
|
113
|
+
* reads the live vault-share allowance and, when a signature is needed, the permit nonce on
|
|
114
|
+
* each `getRequirements()` call. Captures the requested amount and owner at creation, so later
|
|
115
|
+
* changes to `params` do not change this handle's requirements or transaction.
|
|
105
116
|
*
|
|
106
117
|
* @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
|
|
107
118
|
* @param params.userAddress - Share owner that must sign and submit; receives the net assets.
|
|
119
|
+
* @param params.vaultData - Pre-fetched Vault V2 snapshot used to derive the share cap.
|
|
108
120
|
* @param params.slippageTolerance - Optional WAD-scaled share-price loss tolerance applied to
|
|
109
121
|
* the share cap.
|
|
110
122
|
* Defaults to 0.03% and cannot exceed 10%.
|
|
@@ -117,8 +129,11 @@ export interface VaultV2Actions {
|
|
|
117
129
|
* which returns a deep-frozen `Transaction<VaultV2WithdrawAction>`. Requirements are empty
|
|
118
130
|
* when the allowance equals the cap; an oversized allowance is always reset with an exact
|
|
119
131
|
* onchain approval, and an insufficient one is raised by an approval or, with signature
|
|
120
|
-
* support, an ERC-2612 request. The cap
|
|
121
|
-
*
|
|
132
|
+
* support, an ERC-2612 request. The cap is fixed at handle creation while each call re-reads
|
|
133
|
+
* the allowance. Confirm the approval or pass its signed permit to `buildTx`.
|
|
134
|
+
* @remarks VaultBundlesV1 skips a share permit whose nonce was already consumed and proceeds
|
|
135
|
+
* under the live allowance, so execute every requirement returned by the latest
|
|
136
|
+
* `getRequirements()` — including the oversized-allowance reset — before submitting.
|
|
122
137
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
123
138
|
* @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
|
|
124
139
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
@@ -128,14 +143,14 @@ export interface VaultV2Actions {
|
|
|
128
143
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
129
144
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
130
145
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
|
|
146
|
+
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
131
147
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
132
148
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
133
149
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
134
150
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
|
|
135
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @throws {viem.BaseError} when a vault, allowance, or nonce read or transaction encoding fails.
|
|
151
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed or
|
|
152
|
+
* its spender, amount or deadline differ from this operation's.
|
|
153
|
+
* @throws {viem.BaseError} when an allowance or nonce read or transaction encoding fails.
|
|
139
154
|
* @example
|
|
140
155
|
* ```ts
|
|
141
156
|
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
@@ -147,7 +162,8 @@ export interface VaultV2Actions {
|
|
|
147
162
|
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
148
163
|
* .extend(morphoViemExtension({ supportSignature: false }));
|
|
149
164
|
* const vault = client.morpho.vaultV2(vaultAddress, mainnet.id);
|
|
150
|
-
* const
|
|
165
|
+
* const vaultData = await vault.getData();
|
|
166
|
+
* const action = vault.withdraw({ amount: 1_000_000n, userAddress, vaultData });
|
|
151
167
|
* const requirements = await action.getRequirements();
|
|
152
168
|
* // Send and confirm each approval before calling action.buildTx().
|
|
153
169
|
* // action.buildTx() returns Readonly<Transaction<VaultV2WithdrawAction>>.
|
|
@@ -158,6 +174,7 @@ export interface VaultV2Actions {
|
|
|
158
174
|
withdraw: (params: {
|
|
159
175
|
readonly amount: bigint;
|
|
160
176
|
readonly userAddress: Address;
|
|
177
|
+
readonly vaultData: AccrualVaultV2;
|
|
161
178
|
readonly slippageTolerance?: bigint;
|
|
162
179
|
readonly referralFeePct?: bigint;
|
|
163
180
|
readonly referralFeeRecipient?: Address;
|
|
@@ -169,19 +186,19 @@ export interface VaultV2Actions {
|
|
|
169
186
|
* Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
|
|
170
187
|
* The caller must satisfy the exact vault-share allowance returned by `getRequirements()` before
|
|
171
188
|
* `buildTx()`; every requirement resolution re-reads the live allowance and checks the deadline.
|
|
172
|
-
* `buildTx()` accepts permits from the latest completed requirement resolution.
|
|
173
189
|
*
|
|
174
|
-
* @param
|
|
175
|
-
* @param
|
|
176
|
-
* @param
|
|
177
|
-
* @param
|
|
178
|
-
* @param
|
|
179
|
-
* @param
|
|
190
|
+
* @param params - The redeem parameters.
|
|
191
|
+
* @param params.shares - Exact vault shares to burn.
|
|
192
|
+
* @param params.userAddress - Account that must sign and submit the transaction; VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`.
|
|
193
|
+
* @param [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be below WAD.
|
|
194
|
+
* @param [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
|
|
195
|
+
* @param [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
|
|
180
196
|
* @returns Lazy exact share-allowance requirements and a synchronous transaction builder.
|
|
181
197
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
182
198
|
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
183
199
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
184
200
|
* requirement resolution.
|
|
201
|
+
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
185
202
|
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
186
203
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
187
204
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
@@ -190,8 +207,8 @@ export interface VaultV2Actions {
|
|
|
190
207
|
* @throws {viem.BaseError} from `getRequirements()` when an allowance or nonce read fails.
|
|
191
208
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
192
209
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
193
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the
|
|
194
|
-
*
|
|
210
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
211
|
+
* deadline differ from this operation's.
|
|
195
212
|
* @example
|
|
196
213
|
* ```ts
|
|
197
214
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -404,7 +421,7 @@ export interface VaultV2Actions {
|
|
|
404
421
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
405
422
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender, amount, or
|
|
406
423
|
* deadline differs from this operation. Any handle built from the same inputs accepts the
|
|
407
|
-
* permit;
|
|
424
|
+
* permit; a permit whose nonce was consumed is skipped onchain and the live allowance applies.
|
|
408
425
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
409
426
|
* @example
|
|
410
427
|
* ```ts
|
|
@@ -455,13 +472,27 @@ export interface VaultV2Actions {
|
|
|
455
472
|
* asset-equivalent of the redeemed shares. The caller should apply a buffer on the deallocated
|
|
456
473
|
* amounts to account for share-price drift between submission and execution.
|
|
457
474
|
*
|
|
458
|
-
* @param
|
|
459
|
-
* @param
|
|
460
|
-
* @param
|
|
461
|
-
* @
|
|
462
|
-
*
|
|
463
|
-
* @
|
|
464
|
-
* @
|
|
475
|
+
* @param params.deallocations - Typed list of `forceDeallocate` calls to perform before the redeem.
|
|
476
|
+
* @param params.redeem.shares - Amount of vault shares to redeem after the deallocations.
|
|
477
|
+
* @param params.userAddress - Account that pays the deallocation penalties and receives the redeemed assets.
|
|
478
|
+
* @returns An object whose `buildTx()` returns a deep-frozen `Transaction<VaultV2ForceRedeemAction>`
|
|
479
|
+
* encoding the vault `multicall`.
|
|
480
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
|
|
481
|
+
* @throws {EmptyDeallocationsError} from `buildTx()` when `deallocations` is empty.
|
|
482
|
+
* @throws {NonPositiveInputError} from `buildTx()` when `redeem.shares <= 0n` or any deallocation
|
|
483
|
+
* amount is non-positive.
|
|
484
|
+
* @example
|
|
485
|
+
* ```ts
|
|
486
|
+
* const vault = client.morpho.vaultV2(vaultAddress, 1);
|
|
487
|
+
* const tx = vault
|
|
488
|
+
* .forceRedeem({
|
|
489
|
+
* deallocations: [{ adapter, marketParams, amount: 1_000_000n }],
|
|
490
|
+
* redeem: { shares: 500_000n },
|
|
491
|
+
* userAddress,
|
|
492
|
+
* })
|
|
493
|
+
* .buildTx();
|
|
494
|
+
* // tx satisfies Readonly<Transaction<VaultV2ForceRedeemAction>>
|
|
495
|
+
* ```
|
|
465
496
|
*/
|
|
466
497
|
forceRedeem: (params: {
|
|
467
498
|
deallocations: readonly Deallocation[];
|
|
@@ -473,6 +504,7 @@ export interface VaultV2Actions {
|
|
|
473
504
|
buildTx: () => Readonly<Transaction<VaultV2ForceRedeemAction>>;
|
|
474
505
|
};
|
|
475
506
|
}
|
|
507
|
+
/** Binds a viem client to a Vault V2 vault's action builders. */
|
|
476
508
|
export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
477
509
|
private readonly client;
|
|
478
510
|
private readonly vault;
|
|
@@ -494,6 +526,7 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
494
526
|
withdraw(params: {
|
|
495
527
|
readonly amount: bigint;
|
|
496
528
|
readonly userAddress: Address;
|
|
529
|
+
readonly vaultData: AccrualVaultV2;
|
|
497
530
|
readonly slippageTolerance?: bigint;
|
|
498
531
|
readonly referralFeePct?: bigint;
|
|
499
532
|
readonly referralFeeRecipient?: Address;
|
|
@@ -16,6 +16,7 @@ const index_js_4 = require("../requirements/index.js");
|
|
|
16
16
|
// Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
|
|
17
17
|
// accrual model stays well-defined inside it.
|
|
18
18
|
const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
|
|
19
|
+
/** Binds a viem client to a Vault V2 vault's action builders. */
|
|
19
20
|
class MorphoVaultV2 {
|
|
20
21
|
client;
|
|
21
22
|
vault;
|
|
@@ -27,10 +28,7 @@ class MorphoVaultV2 {
|
|
|
27
28
|
this.chainId = chainId;
|
|
28
29
|
}
|
|
29
30
|
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
|
-
}
|
|
31
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
34
32
|
return (0, blue_sdk_viem_1.fetchAccrualVaultV2)(this.vault, this.client.viemClient, {
|
|
35
33
|
...parameters,
|
|
36
34
|
deployless: this.client.options.supportDeployless,
|
|
@@ -69,7 +67,6 @@ class MorphoVaultV2 {
|
|
|
69
67
|
});
|
|
70
68
|
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
71
69
|
let pendingRequirements;
|
|
72
|
-
let expectedRequirement;
|
|
73
70
|
return Object.freeze({
|
|
74
71
|
getRequirements: async (requirementOptions) => {
|
|
75
72
|
const now = morpho_ts_1.Time.timestamp();
|
|
@@ -77,33 +74,22 @@ class MorphoVaultV2 {
|
|
|
77
74
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
78
75
|
if (pendingRequirements != null)
|
|
79
76
|
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
|
-
})();
|
|
77
|
+
// Memoize the in-flight promise so concurrent callers share one round of
|
|
78
|
+
// allowance/nonce reads.
|
|
79
|
+
const pending = funding.value > 0n
|
|
80
|
+
? Promise.resolve([])
|
|
81
|
+
: (0, index_js_4.getBundlesTokenRequirements)(this.client.viemClient, {
|
|
82
|
+
token: vaultAsset,
|
|
83
|
+
spender,
|
|
84
|
+
amount: funding.assets,
|
|
85
|
+
owner: userAddress,
|
|
86
|
+
chainId: this.chainId,
|
|
87
|
+
deadline,
|
|
88
|
+
supportSignature: this.client.options.supportSignature,
|
|
89
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
90
|
+
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
91
|
+
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
92
|
+
});
|
|
107
93
|
pendingRequirements = pending;
|
|
108
94
|
try {
|
|
109
95
|
return await pending;
|
|
@@ -115,7 +101,8 @@ class MorphoVaultV2 {
|
|
|
115
101
|
}
|
|
116
102
|
},
|
|
117
103
|
buildTx: (signatures) => {
|
|
118
|
-
|
|
104
|
+
// The pure deposit action rejects a token signature supplied alongside native funding.
|
|
105
|
+
const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signatures, { spender, amount: funding.assets, deadline });
|
|
119
106
|
return (0, index_js_1.vaultV2Deposit)({
|
|
120
107
|
vault: {
|
|
121
108
|
chainId: this.chainId,
|
|
@@ -139,8 +126,11 @@ class MorphoVaultV2 {
|
|
|
139
126
|
});
|
|
140
127
|
}
|
|
141
128
|
withdraw(params) {
|
|
142
|
-
const { amount, userAddress } = params;
|
|
129
|
+
const { amount, userAddress, vaultData } = params;
|
|
143
130
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
131
|
+
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
132
|
+
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
133
|
+
}
|
|
144
134
|
if (amount <= 0n)
|
|
145
135
|
throw new index_js_3.NonPositiveInputError("amount", amount);
|
|
146
136
|
// Reject values outside the ABI range before resolving any requirements.
|
|
@@ -156,11 +146,14 @@ class MorphoVaultV2 {
|
|
|
156
146
|
});
|
|
157
147
|
const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
|
|
158
148
|
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
159
|
-
//
|
|
160
|
-
(0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
149
|
+
// Resolve the spender eagerly so an unregistered VaultBundlesV1 fails at handle creation.
|
|
150
|
+
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
151
|
+
const requiredShareAllowance = (0, index_js_2.computeVaultMaxShareAllowance)({
|
|
152
|
+
vaultData,
|
|
153
|
+
deadline,
|
|
154
|
+
assets: amount,
|
|
155
|
+
slippageTolerance,
|
|
156
|
+
});
|
|
164
157
|
return Object.freeze({
|
|
165
158
|
getRequirements: async () => {
|
|
166
159
|
const now = morpho_ts_1.Time.timestamp();
|
|
@@ -169,18 +162,9 @@ class MorphoVaultV2 {
|
|
|
169
162
|
// Re-read the live share allowance on every call instead of caching the resolved
|
|
170
163
|
// requirements: the allowance is the sole cap on the burn, so a caller that executed the
|
|
171
164
|
// 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, {
|
|
165
|
+
// raised afterwards must resurface as an outstanding requirement. The cap derived from
|
|
166
|
+
// `vaultData` is pinned at handle creation, so re-reading cannot move it.
|
|
167
|
+
return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
184
168
|
vaultData,
|
|
185
169
|
version: "vaultV2",
|
|
186
170
|
owner: userAddress,
|
|
@@ -189,17 +173,12 @@ class MorphoVaultV2 {
|
|
|
189
173
|
deadline,
|
|
190
174
|
supportSignature: this.client.options.supportSignature,
|
|
191
175
|
});
|
|
192
|
-
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
193
|
-
expectedRequirement =
|
|
194
|
-
signatureRequirement?.action.type === "permit"
|
|
195
|
-
? signatureRequirement.action
|
|
196
|
-
: undefined;
|
|
197
|
-
return requirements;
|
|
198
176
|
},
|
|
199
177
|
buildTx: (signatures) => {
|
|
200
|
-
const permit = (0, common_js_1.
|
|
201
|
-
|
|
202
|
-
|
|
178
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
|
|
179
|
+
spender,
|
|
180
|
+
amount: requiredShareAllowance,
|
|
181
|
+
deadline,
|
|
203
182
|
});
|
|
204
183
|
return (0, index_js_1.vaultV2Withdraw)({
|
|
205
184
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -231,14 +210,13 @@ class MorphoVaultV2 {
|
|
|
231
210
|
referralFeePct: params.referralFeePct,
|
|
232
211
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
233
212
|
});
|
|
234
|
-
(0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
235
|
-
let expectedRequirement;
|
|
213
|
+
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
236
214
|
return Object.freeze({
|
|
237
215
|
getRequirements: async () => {
|
|
238
216
|
const now = morpho_ts_1.Time.timestamp();
|
|
239
217
|
if (deadline <= now)
|
|
240
218
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
241
|
-
|
|
219
|
+
return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
242
220
|
vaultData: await this.getData(),
|
|
243
221
|
version: "vaultV2",
|
|
244
222
|
owner: userAddress,
|
|
@@ -247,17 +225,12 @@ class MorphoVaultV2 {
|
|
|
247
225
|
deadline,
|
|
248
226
|
supportSignature: this.client.options.supportSignature,
|
|
249
227
|
});
|
|
250
|
-
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
251
|
-
expectedRequirement =
|
|
252
|
-
signatureRequirement?.action.type === "permit"
|
|
253
|
-
? signatureRequirement.action
|
|
254
|
-
: undefined;
|
|
255
|
-
return requirements;
|
|
256
228
|
},
|
|
257
229
|
buildTx: (signatures) => {
|
|
258
|
-
const permit = (0, common_js_1.
|
|
259
|
-
|
|
260
|
-
|
|
230
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
|
|
231
|
+
spender,
|
|
232
|
+
amount: shares,
|
|
233
|
+
deadline,
|
|
261
234
|
});
|
|
262
235
|
return (0, index_js_1.vaultV2Redeem)({
|
|
263
236
|
vault: { chainId: this.chainId, address: this.vault },
|
package/lib/cjs/errors.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as I
|
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
4
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";
|
|
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, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
6
6
|
export type { ErrorClass } from "@morpho-org/morpho-ts";
|
|
7
7
|
export { _try, DivisionByZeroError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
|
package/lib/cjs/errors.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = 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
|
+
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.DivisionByZeroError = exports._try = void 0;
|
|
4
5
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
6
|
Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
|
|
6
7
|
Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
|
|
@@ -38,6 +39,10 @@ Object.defineProperty(exports, "InvalidMidnightOfferParameterError", { enumerabl
|
|
|
38
39
|
Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
|
|
39
40
|
Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
|
|
40
41
|
Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
|
|
42
|
+
Object.defineProperty(exports, "InvalidMidnightRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
|
|
43
|
+
Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
|
|
44
|
+
Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
|
|
45
|
+
Object.defineProperty(exports, "InvalidMidnightRatifierV1AddressError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRatifierV1AddressError; } });
|
|
41
46
|
Object.defineProperty(exports, "InvalidMidnightTickSpacingError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidTickSpacingError; } });
|
|
42
47
|
Object.defineProperty(exports, "InvalidMidnightTreeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidTreeError; } });
|
|
43
48
|
Object.defineProperty(exports, "InvalidMidnightTreeHeightError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidTreeHeightError; } });
|
|
@@ -46,6 +51,8 @@ Object.defineProperty(exports, "MidnightApiError", { enumerable: true, get: func
|
|
|
46
51
|
Object.defineProperty(exports, "MidnightMempoolValidationError", { enumerable: true, get: function () { return midnight_sdk_1.MidnightMempoolValidationError; } });
|
|
47
52
|
Object.defineProperty(exports, "MidnightPayloadDecodeError", { enumerable: true, get: function () { return midnight_sdk_1.PayloadDecodeError; } });
|
|
48
53
|
Object.defineProperty(exports, "MidnightPriceGreaterThanOneError", { enumerable: true, get: function () { return midnight_sdk_1.PriceGreaterThanOneError; } });
|
|
54
|
+
Object.defineProperty(exports, "MidnightRateRatifierV1BoundOverflowError", { enumerable: true, get: function () { return midnight_sdk_1.RateRatifierV1BoundOverflowError; } });
|
|
55
|
+
Object.defineProperty(exports, "MidnightRatifierV1TakerNotAllowedError", { enumerable: true, get: function () { return midnight_sdk_1.RatifierV1TakerNotAllowedError; } });
|
|
49
56
|
Object.defineProperty(exports, "MidnightSettlementFeeExceedsPriceError", { enumerable: true, get: function () { return midnight_sdk_1.SettlementFeeExceedsPriceError; } });
|
|
50
57
|
Object.defineProperty(exports, "MidnightTickOutOfRangeError", { enumerable: true, get: function () { return midnight_sdk_1.TickOutOfRangeError; } });
|
|
51
58
|
Object.defineProperty(exports, "UnknownMidnightCollateralIndexError", { enumerable: true, get: function () { return midnight_sdk_1.UnknownCollateralIndexError; } });
|
|
@@ -94,14 +94,18 @@ export interface VaultV2ForceWithdrawPreview {
|
|
|
94
94
|
* floor cannot fit `uint256`.
|
|
95
95
|
* @example
|
|
96
96
|
* ```ts
|
|
97
|
+
* import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
97
98
|
* import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
|
|
98
99
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
100
|
+
* export function preview(vaultData: AccrualVaultV2, timestamp: bigint) {
|
|
101
|
+
* const preview = previewVaultV2ForceWithdraw(vaultData, {
|
|
102
|
+
* requestedExitAssets: 1_000_000n,
|
|
103
|
+
* timestamp,
|
|
104
|
+
* });
|
|
105
|
+
* // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
|
|
106
|
+
* // preview?.netAssets is what the user receives
|
|
107
|
+
* return preview;
|
|
108
|
+
* }
|
|
105
109
|
* ```
|
|
106
110
|
*/
|
|
107
111
|
export declare function previewVaultV2ForceWithdraw(vaultData: AccrualVaultV2, params: PreviewVaultV2ForceWithdrawParams): VaultV2ForceWithdrawPreview | undefined;
|
|
@@ -43,14 +43,18 @@ const vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
|
43
43
|
* floor cannot fit `uint256`.
|
|
44
44
|
* @example
|
|
45
45
|
* ```ts
|
|
46
|
+
* import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
46
47
|
* import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
|
|
47
48
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
49
|
+
* export function preview(vaultData: AccrualVaultV2, timestamp: bigint) {
|
|
50
|
+
* const preview = previewVaultV2ForceWithdraw(vaultData, {
|
|
51
|
+
* requestedExitAssets: 1_000_000n,
|
|
52
|
+
* timestamp,
|
|
53
|
+
* });
|
|
54
|
+
* // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
|
|
55
|
+
* // preview?.netAssets is what the user receives
|
|
56
|
+
* return preview;
|
|
57
|
+
* }
|
|
54
58
|
* ```
|
|
55
59
|
*/
|
|
56
60
|
function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
@@ -32,10 +32,11 @@ import { type AccrualVault, AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
|
32
32
|
* @example
|
|
33
33
|
* ```ts
|
|
34
34
|
* import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
|
|
35
|
+
* import { DEFAULT_SLIPPAGE_TOLERANCE } from "@morpho-org/morpho-sdk/constants";
|
|
35
36
|
*
|
|
36
37
|
* const minSharePriceE27 = computeMinForceWithdrawSharePrice({
|
|
37
|
-
* withdrawnAssets:
|
|
38
|
-
* sharesBurnt,
|
|
38
|
+
* withdrawnAssets: 1_000_000n,
|
|
39
|
+
* sharesBurnt: 900_000n,
|
|
39
40
|
* slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
40
41
|
* });
|
|
41
42
|
* ```
|
|
@@ -39,10 +39,11 @@ const validate_js_1 = require("./validate.js");
|
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
41
|
* import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
|
|
42
|
+
* import { DEFAULT_SLIPPAGE_TOLERANCE } from "@morpho-org/morpho-sdk/constants";
|
|
42
43
|
*
|
|
43
44
|
* const minSharePriceE27 = computeMinForceWithdrawSharePrice({
|
|
44
|
-
* withdrawnAssets:
|
|
45
|
-
* sharesBurnt,
|
|
45
|
+
* withdrawnAssets: 1_000_000n,
|
|
46
|
+
* sharesBurnt: 900_000n,
|
|
46
47
|
* slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
47
48
|
* });
|
|
48
49
|
* ```
|
|
@@ -176,6 +176,31 @@ export declare const validateNativeVaultAsset: (chainId: number, vaultAsset: Add
|
|
|
176
176
|
* @param params.withdrawAmount - Amount of collateral being withdrawn.
|
|
177
177
|
* @param params.lltv - The market's liquidation LTV.
|
|
178
178
|
* @param params.marketId - The market identifier (for error messages).
|
|
179
|
+
* @returns `void` when the post-withdraw position stays within the safe LTV threshold.
|
|
180
|
+
* @throws {MarketIdMismatchError} when `positionData.marketId` differs from `marketId`.
|
|
181
|
+
* @throws {WithdrawExceedsCollateralError} when `withdrawAmount` exceeds the position's collateral.
|
|
182
|
+
* @throws {MissingMarketPriceError} when the position carries debt but the market has no oracle price.
|
|
183
|
+
* @throws {WithdrawMakesPositionUnhealthyError} when the remaining collateral cannot cover the debt
|
|
184
|
+
* at LLTV minus `DEFAULT_LLTV_BUFFER`.
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* import type { AccrualPosition, MarketId } from "@morpho-org/blue-sdk";
|
|
188
|
+
* import { validatePositionHealthAfterWithdraw } from "@morpho-org/morpho-sdk";
|
|
189
|
+
*
|
|
190
|
+
* export function assertSafeWithdraw(
|
|
191
|
+
* positionData: AccrualPosition,
|
|
192
|
+
* withdrawAmount: bigint,
|
|
193
|
+
* lltv: bigint,
|
|
194
|
+
* marketId: MarketId,
|
|
195
|
+
* ): void {
|
|
196
|
+
* validatePositionHealthAfterWithdraw({
|
|
197
|
+
* positionData,
|
|
198
|
+
* withdrawAmount,
|
|
199
|
+
* lltv,
|
|
200
|
+
* marketId,
|
|
201
|
+
* });
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
179
204
|
*/
|
|
180
205
|
export declare const validatePositionHealthAfterWithdraw: (params: {
|
|
181
206
|
positionData: AccrualPosition;
|
|
@@ -203,6 +228,21 @@ export declare const validateRepayAmount: (params: {
|
|
|
203
228
|
* @param params.positionData - The current accrual position.
|
|
204
229
|
* @param params.repayShares - The amount of shares to repay.
|
|
205
230
|
* @param params.marketId - The market identifier (for error messages).
|
|
231
|
+
* @returns `void` when `repayShares` does not exceed the position's borrow shares.
|
|
232
|
+
* @throws {RepaySharesExceedDebtError} when `repayShares` exceeds the position's borrow shares.
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* import type { AccrualPosition, MarketId } from "@morpho-org/blue-sdk";
|
|
236
|
+
* import { validateRepayShares } from "@morpho-org/morpho-sdk";
|
|
237
|
+
*
|
|
238
|
+
* export function assertRepayable(
|
|
239
|
+
* positionData: AccrualPosition,
|
|
240
|
+
* repayShares: bigint,
|
|
241
|
+
* marketId: MarketId,
|
|
242
|
+
* ): void {
|
|
243
|
+
* validateRepayShares({ positionData, repayShares, marketId });
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
206
246
|
*/
|
|
207
247
|
export declare const validateRepayShares: (params: {
|
|
208
248
|
positionData: AccrualPosition;
|