@morpho-org/morpho-sdk 8.3.0 → 9.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-v8-to-v9.md +54 -0
- package/README.md +13 -7
- package/lib/cjs/actions/bundles/common.d.ts +4 -7
- package/lib/cjs/actions/bundles/common.js +8 -14
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -8
- package/lib/cjs/actions/midnight/authorization.d.ts +3 -1
- package/lib/cjs/actions/midnight/authorization.js +11 -1
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -0
- package/lib/cjs/actions/midnight/cancelAndMake.js +10 -2
- package/lib/cjs/actions/midnight/redeem.d.ts +3 -1
- package/lib/cjs/actions/midnight/redeem.js +9 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +7 -3
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +4 -1
- package/lib/cjs/actions/midnight/supplyCollateral.js +10 -3
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +9 -3
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +3 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +9 -3
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeLend.js +7 -2
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +8 -2
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +3 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +10 -3
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +5 -7
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +7 -11
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +8 -15
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +11 -8
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +4 -4
- package/lib/cjs/actions/vaultV1/withdraw.js +4 -4
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +1 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +4 -4
- package/lib/cjs/actions/vaultV2/withdraw.js +4 -4
- package/lib/cjs/entities/blue/blue.d.ts +2 -12
- package/lib/cjs/entities/blue/blue.js +0 -4
- package/lib/cjs/entities/midnight/midnight.d.ts +56 -17
- package/lib/cjs/entities/midnight/midnight.js +131 -52
- package/lib/cjs/entities/midnight/types.d.ts +2 -9
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +0 -7
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -20
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +40 -37
- package/lib/cjs/entities/vaultV1/vaultV1.js +5 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +36 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +8 -34
- package/lib/cjs/helpers/encodeMidnightCalldata.d.ts +48 -0
- package/lib/cjs/helpers/encodeMidnightCalldata.js +74 -0
- package/lib/cjs/helpers/slippage.d.ts +9 -25
- package/lib/cjs/helpers/slippage.js +10 -27
- package/lib/cjs/helpers/validate.d.ts +1 -0
- package/lib/cjs/helpers/validate.js +5 -0
- package/lib/cjs/helpers/validateMidnightAccount.d.ts +34 -0
- package/lib/cjs/helpers/validateMidnightAccount.js +47 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +4 -0
- package/lib/cjs/helpers/validateMidnightMarket.d.ts +2 -0
- package/lib/cjs/helpers/validateMidnightMarket.js +5 -0
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +11 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +12 -1
- package/lib/cjs/helpers/validateMidnightReceiver.d.ts +1 -0
- package/lib/cjs/helpers/validateMidnightReceiver.js +8 -0
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +4 -3
- package/lib/cjs/types/action.d.ts +3 -1
- package/lib/cjs/types/error.d.ts +56 -5
- package/lib/cjs/types/error.js +139 -10
- package/lib/esm/actions/bundles/common.d.ts +4 -7
- package/lib/esm/actions/bundles/common.js +8 -14
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -9
- package/lib/esm/actions/midnight/authorization.d.ts +3 -1
- package/lib/esm/actions/midnight/authorization.js +12 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -0
- package/lib/esm/actions/midnight/cancelAndMake.js +11 -3
- package/lib/esm/actions/midnight/redeem.d.ts +3 -1
- package/lib/esm/actions/midnight/redeem.js +10 -4
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +8 -4
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +4 -1
- package/lib/esm/actions/midnight/supplyCollateral.js +11 -4
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +10 -4
- package/lib/esm/actions/midnight/takeBorrow.d.ts +3 -1
- package/lib/esm/actions/midnight/takeBorrow.js +10 -4
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
- package/lib/esm/actions/midnight/takeLend.js +8 -3
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +9 -3
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +3 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +11 -4
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -8
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +7 -11
- package/lib/esm/actions/requirements/getRequirementsApproval.js +9 -16
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +12 -9
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +1 -1
- package/lib/esm/actions/vaultV1/withdraw.d.ts +4 -4
- package/lib/esm/actions/vaultV1/withdraw.js +4 -4
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +1 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.js +1 -1
- package/lib/esm/actions/vaultV2/withdraw.d.ts +4 -4
- package/lib/esm/actions/vaultV2/withdraw.js +4 -4
- package/lib/esm/entities/blue/blue.d.ts +2 -12
- package/lib/esm/entities/blue/blue.js +0 -4
- package/lib/esm/entities/midnight/midnight.d.ts +56 -17
- package/lib/esm/entities/midnight/midnight.js +132 -53
- package/lib/esm/entities/midnight/types.d.ts +2 -9
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +1 -8
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +9 -21
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +40 -37
- package/lib/esm/entities/vaultV1/vaultV1.js +6 -35
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +36 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +8 -34
- package/lib/esm/helpers/encodeMidnightCalldata.d.ts +48 -0
- package/lib/esm/helpers/encodeMidnightCalldata.js +69 -0
- package/lib/esm/helpers/slippage.d.ts +9 -25
- package/lib/esm/helpers/slippage.js +9 -25
- package/lib/esm/helpers/validate.d.ts +1 -0
- package/lib/esm/helpers/validate.js +5 -0
- package/lib/esm/helpers/validateMidnightAccount.d.ts +34 -0
- package/lib/esm/helpers/validateMidnightAccount.js +43 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +4 -0
- package/lib/esm/helpers/validateMidnightMarket.d.ts +2 -0
- package/lib/esm/helpers/validateMidnightMarket.js +5 -0
- package/lib/esm/helpers/validateMidnightPublication.d.ts +11 -0
- package/lib/esm/helpers/validateMidnightPublication.js +10 -0
- package/lib/esm/helpers/validateMidnightReceiver.d.ts +1 -0
- package/lib/esm/helpers/validateMidnightReceiver.js +8 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +4 -3
- package/lib/esm/types/action.d.ts +3 -1
- package/lib/esm/types/error.d.ts +56 -5
- package/lib/esm/types/error.js +134 -6
- package/package.json +4 -3
|
@@ -85,15 +85,8 @@ export interface SupplyCollateralMakeBorrowParams extends MakeOffersParams {
|
|
|
85
85
|
* wNative. The wNative approval to `MidnightBundlesV2` is still required for the full pulled amount. */
|
|
86
86
|
readonly nativeAmount?: bigint;
|
|
87
87
|
}
|
|
88
|
-
/**
|
|
89
|
-
export
|
|
90
|
-
/**
|
|
91
|
-
* ERC-20 allowance to set when an approval is needed. Defaults to `maxUint256` (capped per token by
|
|
92
|
-
* `MAX_TOKEN_APPROVALS`). Applies to every token the flow approves and must cover the amount each
|
|
93
|
-
* of them pulls. Flows that need no token approval ignore it.
|
|
94
|
-
*/
|
|
95
|
-
readonly approvalAmount?: bigint;
|
|
96
|
-
}
|
|
88
|
+
/** No per-call options are available for Midnight requirements. */
|
|
89
|
+
export type MidnightRequirementsParams = Record<string, never>;
|
|
97
90
|
/**
|
|
98
91
|
* Lazy Midnight entity result with async requirements and sync transaction building.
|
|
99
92
|
*
|
|
@@ -8,8 +8,6 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
8
8
|
readonly spender: Address;
|
|
9
9
|
/** Exact amount the bundles contract will pull. */
|
|
10
10
|
readonly amount: bigint;
|
|
11
|
-
/** Classic approval amount; defaults to the exact pull amount. */
|
|
12
|
-
readonly approvalAmount?: bigint;
|
|
13
11
|
/** Account funding the operation. */
|
|
14
12
|
readonly owner: Address;
|
|
15
13
|
/** Target chain id. */
|
|
@@ -41,7 +39,6 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
41
39
|
* @param params.token - ERC-20 token funded by the operation.
|
|
42
40
|
* @param params.spender - Registered fixed bundles contract that pulls the token.
|
|
43
41
|
* @param params.amount - Exact amount the contract will pull; zero returns no requirements.
|
|
44
|
-
* @param params.approvalAmount - Classic approval amount; defaults to `amount` and is ignored by signature paths.
|
|
45
42
|
* @param params.owner - Account funding the operation.
|
|
46
43
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
47
44
|
* @param params.deadline - Final-call and signature deadline.
|
|
@@ -67,7 +64,6 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
67
64
|
* was passed explicitly.
|
|
68
65
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
69
66
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
70
|
-
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
71
67
|
* @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
|
|
72
68
|
* undecodable data, or is out of range.
|
|
73
69
|
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
@@ -26,7 +26,6 @@ const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
|
|
|
26
26
|
* @param params.token - ERC-20 token funded by the operation.
|
|
27
27
|
* @param params.spender - Registered fixed bundles contract that pulls the token.
|
|
28
28
|
* @param params.amount - Exact amount the contract will pull; zero returns no requirements.
|
|
29
|
-
* @param params.approvalAmount - Classic approval amount; defaults to `amount` and is ignored by signature paths.
|
|
30
29
|
* @param params.owner - Account funding the operation.
|
|
31
30
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
32
31
|
* @param params.deadline - Final-call and signature deadline.
|
|
@@ -52,7 +51,6 @@ const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
|
|
|
52
51
|
* was passed explicitly.
|
|
53
52
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
54
53
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
55
|
-
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
56
54
|
* @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
|
|
57
55
|
* undecodable data, or is out of range.
|
|
58
56
|
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
@@ -207,10 +205,6 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
207
205
|
});
|
|
208
206
|
}
|
|
209
207
|
}
|
|
210
|
-
const approvalAmount = params.approvalAmount ?? params.amount;
|
|
211
|
-
if (approvalAmount < params.amount) {
|
|
212
|
-
throw new index_js_3.ApprovalAmountLessThanSpendAmountError();
|
|
213
|
-
}
|
|
214
208
|
const allowance = await (0, actions_1.readContract)(viemClient, {
|
|
215
209
|
abi: viem_1.erc20Abi,
|
|
216
210
|
address: params.token,
|
|
@@ -228,7 +222,6 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
228
222
|
state: {
|
|
229
223
|
type: "approval",
|
|
230
224
|
allowance,
|
|
231
|
-
approvalAmount,
|
|
232
225
|
},
|
|
233
226
|
});
|
|
234
227
|
};
|
|
@@ -2,25 +2,17 @@ import type { Token } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import type { Address, Client } from "viem";
|
|
3
3
|
import { type ActionRequirement } from "../../types/index.js";
|
|
4
4
|
/**
|
|
5
|
-
* Resolves the
|
|
5
|
+
* Resolves the vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* the
|
|
9
|
-
* satisfies the requirement; one above `maxShareAllowance` is replaced by an onchain approval for
|
|
10
|
-
* exactly the computed cap. Only an insufficient allowance may be raised through an ERC-2612 permit,
|
|
11
|
-
* because VaultBundlesV1 skips a permit whose nonce was already consumed and the leftover allowance
|
|
12
|
-
* would then stay in force.
|
|
7
|
+
* An allowance at least as large as `requiredShareAllowance` satisfies the requirement. Otherwise
|
|
8
|
+
* the helper returns a maxUint256 approval or, when supported, a vault-share permit.
|
|
13
9
|
*
|
|
14
10
|
* @internal
|
|
15
11
|
*
|
|
16
12
|
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
17
|
-
* @param params - Vault snapshot, owner, allowance
|
|
18
|
-
* defaults to `requiredShareAllowance`, which accepts only an exact match.
|
|
13
|
+
* @param params - Vault snapshot, owner, minimum allowance, and deadline values.
|
|
19
14
|
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
20
|
-
* @returns No requirement when the allowance is
|
|
21
|
-
* maxShareAllowance]`, otherwise one
|
|
22
|
-
* approval that sets it to exactly that cap, or one permit when the allowance is below the cap
|
|
23
|
-
* and signatures are supported.
|
|
15
|
+
* @returns No requirement when the allowance is sufficient, otherwise one approval or permit.
|
|
24
16
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
25
17
|
* another chain than `params.chainId`.
|
|
26
18
|
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
@@ -32,7 +24,6 @@ export declare const getVaultBundlesSharesRequirements: (viemClient: Client, par
|
|
|
32
24
|
readonly owner: Address;
|
|
33
25
|
readonly chainId: number;
|
|
34
26
|
readonly requiredShareAllowance: bigint;
|
|
35
|
-
readonly maxShareAllowance?: bigint;
|
|
36
27
|
readonly deadline: bigint;
|
|
37
28
|
readonly supportSignature: boolean;
|
|
38
29
|
readonly now?: bigint;
|
|
@@ -10,25 +10,17 @@ const validateClientChainId_js_1 = require("../../actions/requirements/validateC
|
|
|
10
10
|
const index_js_2 = require("../../helpers/index.js");
|
|
11
11
|
const index_js_3 = require("../../types/index.js");
|
|
12
12
|
/**
|
|
13
|
-
* Resolves the
|
|
13
|
+
* Resolves the vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
* the
|
|
17
|
-
* satisfies the requirement; one above `maxShareAllowance` is replaced by an onchain approval for
|
|
18
|
-
* exactly the computed cap. Only an insufficient allowance may be raised through an ERC-2612 permit,
|
|
19
|
-
* because VaultBundlesV1 skips a permit whose nonce was already consumed and the leftover allowance
|
|
20
|
-
* would then stay in force.
|
|
15
|
+
* An allowance at least as large as `requiredShareAllowance` satisfies the requirement. Otherwise
|
|
16
|
+
* the helper returns a maxUint256 approval or, when supported, a vault-share permit.
|
|
21
17
|
*
|
|
22
18
|
* @internal
|
|
23
19
|
*
|
|
24
20
|
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
25
|
-
* @param params - Vault snapshot, owner, allowance
|
|
26
|
-
* defaults to `requiredShareAllowance`, which accepts only an exact match.
|
|
21
|
+
* @param params - Vault snapshot, owner, minimum allowance, and deadline values.
|
|
27
22
|
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
28
|
-
* @returns No requirement when the allowance is
|
|
29
|
-
* maxShareAllowance]`, otherwise one
|
|
30
|
-
* approval that sets it to exactly that cap, or one permit when the allowance is below the cap
|
|
31
|
-
* and signatures are supported.
|
|
23
|
+
* @returns No requirement when the allowance is sufficient, otherwise one approval or permit.
|
|
32
24
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
33
25
|
* another chain than `params.chainId`.
|
|
34
26
|
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
@@ -49,12 +41,9 @@ const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
|
49
41
|
functionName: "allowance",
|
|
50
42
|
args: [params.owner, spender],
|
|
51
43
|
});
|
|
52
|
-
|
|
53
|
-
// allowance up to `maxShareAllowance` skips the approval or permit that resets it to the cap.
|
|
54
|
-
if (allowance >= params.requiredShareAllowance &&
|
|
55
|
-
allowance <= (params.maxShareAllowance ?? params.requiredShareAllowance))
|
|
44
|
+
if (allowance >= params.requiredShareAllowance)
|
|
56
45
|
return [];
|
|
57
|
-
if (
|
|
46
|
+
if (params.supportSignature) {
|
|
58
47
|
const nonce = await (0, actions_1.readContract)(viemClient, {
|
|
59
48
|
address: params.vaultData.address,
|
|
60
49
|
abi: blue_sdk_viem_1.erc2612Abi,
|
|
@@ -69,7 +58,6 @@ const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
|
69
58
|
owner: params.owner,
|
|
70
59
|
chainId: params.chainId,
|
|
71
60
|
nonce,
|
|
72
|
-
amount: params.requiredShareAllowance,
|
|
73
61
|
deadline: params.deadline,
|
|
74
62
|
now,
|
|
75
63
|
}),
|
|
@@ -79,7 +67,7 @@ const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
|
79
67
|
(0, index_js_1.encodeErc20Approval)({
|
|
80
68
|
token: params.vaultData.address,
|
|
81
69
|
spender,
|
|
82
|
-
amount:
|
|
70
|
+
amount: viem_1.maxUint256,
|
|
83
71
|
chainId: params.chainId,
|
|
84
72
|
}),
|
|
85
73
|
];
|
|
@@ -116,16 +116,16 @@ export interface VaultV1Actions {
|
|
|
116
116
|
/**
|
|
117
117
|
* Prepares an exact-assets Vault V1 withdrawal through VaultBundlesV1.
|
|
118
118
|
*
|
|
119
|
-
* Derives the share
|
|
120
|
-
* reads the live vault-share allowance and, when a signature is needed, the permit
|
|
121
|
-
* each `getRequirements()` call. Captures the requested amount and owner at creation, so
|
|
122
|
-
* changes to `params` do not change this handle's requirements or transaction.
|
|
119
|
+
* Derives the minimum required share allowance from the supplied `vaultData` snapshot at handle
|
|
120
|
+
* creation, then reads the live vault-share allowance and, when a signature is needed, the permit
|
|
121
|
+
* nonce on each `getRequirements()` call. Captures the requested amount and owner at creation, so
|
|
122
|
+
* later changes to `params` do not change this handle's requirements or transaction.
|
|
123
123
|
*
|
|
124
124
|
* @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
|
|
125
125
|
* @param params.userAddress - Share owner that must sign and submit; receives the net assets.
|
|
126
|
-
* @param params.vaultData - Pre-fetched Vault V1 snapshot used to derive the share
|
|
127
|
-
* @param params.slippageTolerance - Optional WAD-scaled
|
|
128
|
-
*
|
|
126
|
+
* @param params.vaultData - Pre-fetched Vault V1 snapshot used to derive the minimum share allowance.
|
|
127
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance used only to size the minimum
|
|
128
|
+
* share allowance. It does not impose an on-chain share-burn bound.
|
|
129
129
|
* Defaults to 0.03% and cannot exceed 10%.
|
|
130
130
|
* @param params.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero;
|
|
131
131
|
* rounded down and deducted from the gross withdrawn assets.
|
|
@@ -134,17 +134,16 @@ export interface VaultV1Actions {
|
|
|
134
134
|
* defaults to two hours from handle creation.
|
|
135
135
|
* @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
|
|
136
136
|
* which returns a deep-frozen `Transaction<VaultV1WithdrawAction>`. Requirements are empty
|
|
137
|
-
* when the allowance
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* the allowance. Confirm the approval or pass its signed permit to `buildTx`.
|
|
137
|
+
* when the allowance meets or exceeds the required share amount. An insufficient allowance is
|
|
138
|
+
* raised by an unlimited approval or, with signature support, an ERC-2612 request. The minimum
|
|
139
|
+
* is fixed at handle creation while each call re-reads the allowance. Confirm the approval or
|
|
140
|
+
* pass its signed permit to `buildTx`.
|
|
142
141
|
* @remarks VaultBundlesV1 skips a share permit whose nonce was already consumed and proceeds
|
|
143
142
|
* under the live allowance, so execute every requirement returned by the latest
|
|
144
|
-
* `getRequirements()`
|
|
143
|
+
* `getRequirements()` before submitting.
|
|
145
144
|
* @throws {ChainIdMismatchError} when the connected client targets another chain, or from
|
|
146
145
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
147
|
-
* @throws {NonPositiveInputError} when `amount` or the computed share
|
|
146
|
+
* @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
|
|
148
147
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
149
148
|
* at any `getRequirements()` call.
|
|
150
149
|
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
|
|
@@ -158,8 +157,8 @@ export interface VaultV1Actions {
|
|
|
158
157
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
159
158
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
|
|
160
159
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed or
|
|
161
|
-
* its spender or deadline differ from this operation's, or its amount is
|
|
162
|
-
*
|
|
160
|
+
* its spender or deadline differ from this operation's, or its amount is below the required
|
|
161
|
+
* share allowance.
|
|
163
162
|
* @throws {MissingPermitDomainNameError} from `getRequirements()` when signatures are enabled,
|
|
164
163
|
* the share allowance is insufficient, and the supplied `vaultData` share token exposes
|
|
165
164
|
* neither `name()` nor an EIP-5267 domain.
|
|
@@ -200,8 +199,9 @@ export interface VaultV1Actions {
|
|
|
200
199
|
* Prepares an exact-shares Vault V1 redemption through VaultBundlesV1.
|
|
201
200
|
*
|
|
202
201
|
* Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
|
|
203
|
-
* The caller must satisfy the
|
|
204
|
-
* `buildTx()`;
|
|
202
|
+
* The caller must satisfy the minimum share allowance returned by `getRequirements()` before
|
|
203
|
+
* `buildTx()`; larger allowances also suffice, and each requirement resolution re-reads the live
|
|
204
|
+
* allowance and checks the deadline.
|
|
205
205
|
*
|
|
206
206
|
* @param params.shares - Exact vault shares to burn.
|
|
207
207
|
* @param params.userAddress - Account that signs and submits the transaction; VaultBundlesV1
|
|
@@ -211,7 +211,7 @@ export interface VaultV1Actions {
|
|
|
211
211
|
* @param params.referralFeeRecipient - Optional non-zero recipient required for a positive fee.
|
|
212
212
|
* @param params.deadline - Optional execution and share-permit deadline in Unix seconds; defaults
|
|
213
213
|
* to two hours from handle creation.
|
|
214
|
-
* @returns Lazy
|
|
214
|
+
* @returns Lazy share-allowance requirements and a synchronous transaction builder.
|
|
215
215
|
* @throws {ChainIdMismatchError} when the connected client targets another chain, or from
|
|
216
216
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
217
217
|
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
@@ -235,8 +235,8 @@ export interface VaultV1Actions {
|
|
|
235
235
|
* `eth_chainId` read fails.
|
|
236
236
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permit signatures are supplied.
|
|
237
237
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
238
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender
|
|
239
|
-
* deadline
|
|
238
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender or
|
|
239
|
+
* deadline differs from this operation's, or its amount is below the required share allowance.
|
|
240
240
|
* @example
|
|
241
241
|
* ```ts
|
|
242
242
|
* import { vaults } from "@morpho-org/morpho-test";
|
|
@@ -289,9 +289,10 @@ export interface VaultV1Actions {
|
|
|
289
289
|
* Snapshot state can drift before inclusion, so a later reallocation may still make the on-chain
|
|
290
290
|
* loop under-cover even after pre-flight succeeds.
|
|
291
291
|
*
|
|
292
|
-
* In-kind exits
|
|
293
|
-
*
|
|
294
|
-
*
|
|
292
|
+
* In-kind exits have no on-chain share-price or max-shares bound. A share-price drop before
|
|
293
|
+
* inclusion can burn more shares than quoted when the allowance is unlimited. The SDK requires
|
|
294
|
+
* the computed minimum allowance, and an insufficient allowance is raised by an unlimited
|
|
295
|
+
* approval or ERC-2612 permit.
|
|
295
296
|
*
|
|
296
297
|
* @param params - In-kind redemption parameters.
|
|
297
298
|
* @param params.amount - Asset-denominated amount to exit.
|
|
@@ -326,8 +327,8 @@ export interface VaultV1Actions {
|
|
|
326
327
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
327
328
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
328
329
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit is not ERC-2612, has
|
|
329
|
-
* the wrong asset, owner, or signature encoding,
|
|
330
|
-
*
|
|
330
|
+
* the wrong asset, owner, or signature encoding, names another spender or deadline, or
|
|
331
|
+
* signs an amount below the required share allowance.
|
|
331
332
|
* @example
|
|
332
333
|
* ```ts
|
|
333
334
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -364,30 +365,32 @@ export interface VaultV1Actions {
|
|
|
364
365
|
* Prepares a Vault V1-to-Vault V2 migration through VaultBundlesV1.
|
|
365
366
|
*
|
|
366
367
|
* Exits V1 by assets or shares and atomically deposits the resulting assets into V2 through
|
|
367
|
-
* VaultBundlesV1.
|
|
368
|
-
*
|
|
368
|
+
* VaultBundlesV1. The asset-mode source exit has no on-chain share-price or max-shares bound, so
|
|
369
|
+
* a share-price drop before inclusion can burn more shares than quoted when the allowance is
|
|
370
|
+
* unlimited. The shares-mode source amount is fixed, and the destination deposit enforces
|
|
371
|
+
* `maxSharePrice`.
|
|
369
372
|
* Captures vault identities, permit-domain metadata, and the owner at handle creation.
|
|
370
373
|
*
|
|
371
374
|
* @param params.userAddress - Account that signs and submits the transaction; VaultBundlesV1
|
|
372
375
|
* burns and mints shares for `msg.sender`.
|
|
373
376
|
* @param params.sourceVault - Pre-fetched Vault V1 snapshot used for source conversion and the
|
|
374
|
-
* share
|
|
377
|
+
* minimum share allowance.
|
|
375
378
|
* @param params.targetVault - Pre-fetched Vault V2 snapshot used for the destination share-price
|
|
376
379
|
* bound.
|
|
377
380
|
* @param params.shares - Optional exact Vault V1 shares to migrate; exclusive with `assets`.
|
|
378
381
|
* @param params.assets - Optional exact Vault V1 assets to withdraw and migrate; exclusive with
|
|
379
382
|
* `shares`.
|
|
380
|
-
* @param params.slippageTolerance - Optional WAD-scaled tolerance
|
|
381
|
-
*
|
|
383
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance used to size the minimum
|
|
384
|
+
* assets-mode source share allowance and the destination `maxSharePrice`; it does not impose
|
|
385
|
+
* an on-chain source share-burn bound. Defaults to 0.03% and cannot exceed 10%.
|
|
382
386
|
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%, deducted from the
|
|
383
387
|
* source-vault proceeds.
|
|
384
388
|
* @param params.referralFeeRecipient - Optional non-zero recipient required for a positive fee.
|
|
385
389
|
* @param params.deadline - Optional execution and share-permit deadline in Unix seconds; defaults
|
|
386
390
|
* to two hours from handle creation.
|
|
387
|
-
* @returns Lazy source-share requirements and a synchronous transaction builder.
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
* satisfied between calls stops being reported, while the derived source share cap stays
|
|
391
|
+
* @returns Lazy source-share requirements and a synchronous transaction builder. Requirements
|
|
392
|
+
* are empty when the allowance meets or exceeds the required share amount. `getRequirements()` re-reads the live share allowance on every call, so a requirement
|
|
393
|
+
* satisfied between calls stops being reported, while the derived source share amount stays
|
|
391
394
|
* pinned to the supplied snapshot.
|
|
392
395
|
* @throws {UnknownBlueMarketAllocationError} when a source withdraw-queue market has no allocation snapshot.
|
|
393
396
|
* @throws {ChainIdMismatchError} when the connected client targets another chain, or from
|
|
@@ -413,8 +416,8 @@ export interface VaultV1Actions {
|
|
|
413
416
|
* `eth_chainId` read fails.
|
|
414
417
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permit signatures are supplied.
|
|
415
418
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
416
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender
|
|
417
|
-
* deadline
|
|
419
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender or
|
|
420
|
+
* deadline differs from this operation's, or its amount is below the required share allowance.
|
|
418
421
|
* @example
|
|
419
422
|
* ```ts
|
|
420
423
|
* import { vaults } from "@morpho-org/morpho-test";
|
|
@@ -10,7 +10,6 @@ const common_js_1 = require("../../actions/bundles/common.js");
|
|
|
10
10
|
const index_js_1 = require("../../actions/index.js");
|
|
11
11
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
12
12
|
const index_js_2 = require("../../helpers/index.js");
|
|
13
|
-
const slippage_js_1 = require("../../helpers/slippage.js");
|
|
14
13
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
15
14
|
const index_js_3 = require("../../types/index.js");
|
|
16
15
|
const assertContractCode_js_1 = require("../requirements/assertContractCode.js");
|
|
@@ -181,28 +180,19 @@ class MorphoVaultV1 {
|
|
|
181
180
|
assets: amount,
|
|
182
181
|
slippageTolerance,
|
|
183
182
|
});
|
|
184
|
-
const maxShareAllowance = (0, slippage_js_1.computeVaultShareAllowanceCeiling)({
|
|
185
|
-
requiredShareAllowance,
|
|
186
|
-
slippageTolerance,
|
|
187
|
-
});
|
|
188
183
|
return Object.freeze({
|
|
189
184
|
getRequirements: async () => {
|
|
190
185
|
const now = morpho_ts_1.Time.timestamp();
|
|
191
186
|
if (deadline <= now)
|
|
192
187
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
193
188
|
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
194
|
-
// Re-read the live share allowance on every call instead of caching the resolved
|
|
195
|
-
// requirements: the allowance is the sole cap on the burn, so a caller that executed the
|
|
196
|
-
// returned approval must see it satisfied on the next call, and an allowance revoked or
|
|
197
|
-
// raised afterwards must resurface as an outstanding requirement. The cap derived from
|
|
198
|
-
// `vaultData` is pinned at handle creation, so re-reading cannot move it.
|
|
189
|
+
// Re-read the live share allowance on every call instead of caching the resolved requirements.
|
|
199
190
|
return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
200
191
|
vaultData,
|
|
201
192
|
version: "vaultV1",
|
|
202
193
|
owner: userAddress,
|
|
203
194
|
chainId: this.chainId,
|
|
204
195
|
requiredShareAllowance,
|
|
205
|
-
maxShareAllowance,
|
|
206
196
|
deadline,
|
|
207
197
|
supportSignature: this.client.options.supportSignature,
|
|
208
198
|
now,
|
|
@@ -212,7 +202,6 @@ class MorphoVaultV1 {
|
|
|
212
202
|
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
|
|
213
203
|
spender,
|
|
214
204
|
amount: requiredShareAllowance,
|
|
215
|
-
maxAmount: maxShareAllowance,
|
|
216
205
|
deadline,
|
|
217
206
|
});
|
|
218
207
|
return (0, index_js_1.vaultV1Withdraw)({
|
|
@@ -407,14 +396,9 @@ class MorphoVaultV1 {
|
|
|
407
396
|
required: amount,
|
|
408
397
|
});
|
|
409
398
|
}
|
|
410
|
-
|
|
411
|
-
// larger leftover allowance would let a share-price loss burn past `requiredShareAllowance`.
|
|
412
|
-
if (allowance === requiredShareAllowance)
|
|
399
|
+
if (allowance >= requiredShareAllowance)
|
|
413
400
|
return [];
|
|
414
|
-
|
|
415
|
-
// must be reset with an onchain approval.
|
|
416
|
-
if (allowance < requiredShareAllowance &&
|
|
417
|
-
this.client.options.supportSignature) {
|
|
401
|
+
if (this.client.options.supportSignature) {
|
|
418
402
|
return [
|
|
419
403
|
(0, index_js_1.encodeVaultSharesPermit)({
|
|
420
404
|
vault: vaultData,
|
|
@@ -423,7 +407,6 @@ class MorphoVaultV1 {
|
|
|
423
407
|
owner: userAddress,
|
|
424
408
|
chainId: this.chainId,
|
|
425
409
|
nonce,
|
|
426
|
-
amount: requiredShareAllowance,
|
|
427
410
|
deadline,
|
|
428
411
|
}),
|
|
429
412
|
];
|
|
@@ -432,7 +415,7 @@ class MorphoVaultV1 {
|
|
|
432
415
|
(0, index_js_1.encodeErc20Approval)({
|
|
433
416
|
token: this.vault,
|
|
434
417
|
spender: vaultExitBundlesV1,
|
|
435
|
-
amount:
|
|
418
|
+
amount: viem_1.maxUint256,
|
|
436
419
|
chainId: this.chainId,
|
|
437
420
|
}),
|
|
438
421
|
];
|
|
@@ -510,12 +493,6 @@ class MorphoVaultV1 {
|
|
|
510
493
|
assets: assets ?? 0n,
|
|
511
494
|
slippageTolerance,
|
|
512
495
|
});
|
|
513
|
-
// In shares mode the calldata pins the burn, so only an exact allowance is accepted there.
|
|
514
|
-
const maxShareAllowance = shares ??
|
|
515
|
-
(0, slippage_js_1.computeVaultShareAllowanceCeiling)({
|
|
516
|
-
requiredShareAllowance,
|
|
517
|
-
slippageTolerance,
|
|
518
|
-
});
|
|
519
496
|
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
520
497
|
const { userAddress } = params;
|
|
521
498
|
const sourceAsset = params.sourceVault.asset;
|
|
@@ -538,19 +515,13 @@ class MorphoVaultV1 {
|
|
|
538
515
|
if (deadline <= now)
|
|
539
516
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
540
517
|
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
541
|
-
// Re-read the live share allowance on every call instead of caching the resolved
|
|
542
|
-
// requirements: in assets mode the calldata carries no share limit, so the allowance is
|
|
543
|
-
// the sole cap on the burn. A caller that executed the returned approval must see it
|
|
544
|
-
// satisfied on the next call, and an allowance revoked or raised afterwards must resurface
|
|
545
|
-
// as an outstanding requirement. The pinned snapshot and the cap derived from it stay
|
|
546
|
-
// fixed, so re-reading cannot move the cap this handle already committed to.
|
|
518
|
+
// Re-read the live share allowance on every call instead of caching the resolved requirements.
|
|
547
519
|
return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
548
520
|
vaultData: sourceToken,
|
|
549
521
|
version: "vaultV1",
|
|
550
522
|
owner: userAddress,
|
|
551
523
|
chainId: this.chainId,
|
|
552
524
|
requiredShareAllowance,
|
|
553
|
-
maxShareAllowance,
|
|
554
525
|
deadline,
|
|
555
526
|
supportSignature: this.client.options.supportSignature,
|
|
556
527
|
now,
|
|
@@ -122,16 +122,16 @@ export interface VaultV2Actions {
|
|
|
122
122
|
/**
|
|
123
123
|
* Prepares an exact-assets Vault V2 withdrawal through VaultBundlesV1.
|
|
124
124
|
*
|
|
125
|
-
* Derives the share
|
|
126
|
-
* reads the live vault-share allowance and, when a signature is needed, the permit
|
|
127
|
-
* each `getRequirements()` call. Captures the requested amount and owner at creation, so
|
|
128
|
-
* changes to `params` do not change this handle's requirements or transaction.
|
|
125
|
+
* Derives the minimum required share allowance from the supplied `vaultData` snapshot at handle
|
|
126
|
+
* creation, then reads the live vault-share allowance and, when a signature is needed, the permit
|
|
127
|
+
* nonce on each `getRequirements()` call. Captures the requested amount and owner at creation, so
|
|
128
|
+
* later changes to `params` do not change this handle's requirements or transaction.
|
|
129
129
|
*
|
|
130
130
|
* @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
|
|
131
131
|
* @param params.userAddress - Share owner that must sign and submit; receives the net assets.
|
|
132
|
-
* @param params.vaultData - Pre-fetched Vault V2 snapshot used to derive the share
|
|
133
|
-
* @param params.slippageTolerance - Optional WAD-scaled
|
|
134
|
-
*
|
|
132
|
+
* @param params.vaultData - Pre-fetched Vault V2 snapshot used to derive the minimum share allowance.
|
|
133
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance used only to size the minimum
|
|
134
|
+
* share allowance. It does not impose an on-chain share-burn bound.
|
|
135
135
|
* Defaults to 0.03% and cannot exceed 10%.
|
|
136
136
|
* @param params.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero;
|
|
137
137
|
* rounded down and deducted from the gross withdrawn assets.
|
|
@@ -140,17 +140,16 @@ export interface VaultV2Actions {
|
|
|
140
140
|
* defaults to two hours from handle creation.
|
|
141
141
|
* @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
|
|
142
142
|
* which returns a deep-frozen `Transaction<VaultV2WithdrawAction>`. Requirements are empty
|
|
143
|
-
* when the allowance
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* the allowance. Confirm the approval or pass its signed permit to `buildTx`.
|
|
143
|
+
* when the allowance meets or exceeds the required share amount. An insufficient allowance is
|
|
144
|
+
* raised by an unlimited approval or, with signature support, an ERC-2612 request. The minimum
|
|
145
|
+
* is fixed at handle creation while each call re-reads the allowance. Confirm the approval or
|
|
146
|
+
* pass its signed permit to `buildTx`.
|
|
148
147
|
* @remarks VaultBundlesV1 skips a share permit whose nonce was already consumed and proceeds
|
|
149
148
|
* under the live allowance, so execute every requirement returned by the latest
|
|
150
|
-
* `getRequirements()`
|
|
149
|
+
* `getRequirements()` before submitting.
|
|
151
150
|
* @throws {ChainIdMismatchError} when the connected client targets another chain, or from
|
|
152
151
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
153
|
-
* @throws {NonPositiveInputError} when `amount` or the computed share
|
|
152
|
+
* @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
|
|
154
153
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
155
154
|
* at any `getRequirements()` call.
|
|
156
155
|
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
|
|
@@ -164,8 +163,8 @@ export interface VaultV2Actions {
|
|
|
164
163
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
165
164
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
|
|
166
165
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed or
|
|
167
|
-
* its spender or deadline differ from this operation's, or its amount is
|
|
168
|
-
*
|
|
166
|
+
* its spender or deadline differ from this operation's, or its amount is below the required
|
|
167
|
+
* share allowance.
|
|
169
168
|
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
|
|
170
169
|
* contract has no code at its registered address.
|
|
171
170
|
* @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or `eth_chainId`
|
|
@@ -203,8 +202,9 @@ export interface VaultV2Actions {
|
|
|
203
202
|
* Prepares an exact-shares Vault V2 redemption through VaultBundlesV1.
|
|
204
203
|
*
|
|
205
204
|
* Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
|
|
206
|
-
* The caller must satisfy the
|
|
207
|
-
* `buildTx()`;
|
|
205
|
+
* The caller must satisfy the minimum share allowance returned by `getRequirements()` before
|
|
206
|
+
* `buildTx()`; larger allowances also suffice, and each requirement resolution re-reads the live
|
|
207
|
+
* allowance and checks the deadline.
|
|
208
208
|
*
|
|
209
209
|
* @param params - The redeem parameters.
|
|
210
210
|
* @param params.shares - Exact vault shares to burn.
|
|
@@ -212,7 +212,7 @@ export interface VaultV2Actions {
|
|
|
212
212
|
* @param [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be below WAD.
|
|
213
213
|
* @param [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
|
|
214
214
|
* @param [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
|
|
215
|
-
* @returns Lazy
|
|
215
|
+
* @returns Lazy share-allowance requirements and a synchronous transaction builder.
|
|
216
216
|
* @throws {ChainIdMismatchError} when the client and entity target different chains, or from
|
|
217
217
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
218
218
|
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
@@ -235,8 +235,8 @@ export interface VaultV2Actions {
|
|
|
235
235
|
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
236
236
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
237
237
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
238
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender
|
|
239
|
-
* deadline
|
|
238
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender or
|
|
239
|
+
* deadline differs from this operation's, or its amount is below the required share allowance.
|
|
240
240
|
* @example
|
|
241
241
|
* ```ts
|
|
242
242
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -279,9 +279,10 @@ export interface VaultV2Actions {
|
|
|
279
279
|
* Idle balance, penalty, and adapter positions can drift after the snapshot, so an on-chain
|
|
280
280
|
* under-coverage panic remains possible if vault state changes between preparation and inclusion.
|
|
281
281
|
*
|
|
282
|
-
* In-kind exits
|
|
283
|
-
*
|
|
284
|
-
*
|
|
282
|
+
* In-kind exits have no on-chain share-price or max-shares bound. A share-price drop before
|
|
283
|
+
* inclusion can burn more shares than quoted when the allowance is unlimited. The SDK requires
|
|
284
|
+
* the computed minimum allowance, and an insufficient allowance is raised by an unlimited
|
|
285
|
+
* approval or ERC-2612 permit.
|
|
285
286
|
*
|
|
286
287
|
* @param params - In-kind redemption parameters.
|
|
287
288
|
* @param params.amount - Penalty-inclusive, asset-denominated amount to exit.
|
|
@@ -316,8 +317,8 @@ export interface VaultV2Actions {
|
|
|
316
317
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
317
318
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
318
319
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit is not ERC-2612, has
|
|
319
|
-
* the wrong asset, owner, or signature encoding,
|
|
320
|
-
*
|
|
320
|
+
* the wrong asset, owner, or signature encoding, names another spender or deadline, or
|
|
321
|
+
* signs an amount below the required share allowance.
|
|
321
322
|
* @example
|
|
322
323
|
* ```ts
|
|
323
324
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -384,12 +385,13 @@ export interface VaultV2Actions {
|
|
|
384
385
|
* validate the user's share balance. Per-market penalties and each vault withdrawal round the
|
|
385
386
|
* share burn up independently, so the exit can burn marginally more shares than `exitAssets` alone
|
|
386
387
|
* implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)` so a
|
|
387
|
-
* full-balance exit does not revert for insufficient shares.
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
* ERC-20 allowance underflow
|
|
388
|
+
* full-balance exit does not revert for insufficient shares. Any approval or permit this handle
|
|
389
|
+
* returns is unlimited. The computed share amount is only the smallest existing allowance the
|
|
390
|
+
* SDK accepts without a new requirement: it covers a burn at least one `slippageTolerance` step
|
|
391
|
+
* below the price floor whenever the floor exceeds one RAY unit and, in any case, at least one
|
|
392
|
+
* share above the burn at the floor. A reused allowance just above that minimum can still
|
|
393
|
+
* surface a deeper price drop as an ERC-20 allowance underflow rather than the contract's
|
|
394
|
+
* `minSharePriceE27` check.
|
|
393
395
|
*
|
|
394
396
|
* Idle balance, penalty, adapter positions, and market liquidity can drift after the snapshot, so
|
|
395
397
|
* an on-chain revert remains possible if vault state changes between preparation and inclusion.
|
|
@@ -453,8 +455,8 @@ export interface VaultV2Actions {
|
|
|
453
455
|
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol contract has no code at its registered address.
|
|
454
456
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
455
457
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
456
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender
|
|
457
|
-
*
|
|
458
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender or deadline
|
|
459
|
+
* differs from this operation, or its amount is below the required share allowance. Any handle built from the same inputs accepts the
|
|
458
460
|
* permit; a permit whose nonce was consumed is skipped onchain and the live allowance applies.
|
|
459
461
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
460
462
|
* @example
|