@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.2
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 +127 -16
- package/README.md +17 -11
- package/lib/cjs/abis.d.ts +17 -2
- package/lib/cjs/abis.js +14 -1
- package/lib/cjs/actions/blue/common.js +5 -26
- package/lib/cjs/actions/blue/supply.js +2 -7
- package/lib/cjs/actions/bundles/common.d.ts +32 -2
- package/lib/cjs/actions/bundles/common.js +68 -30
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +20 -20
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -27
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/cjs/blue/abis.d.ts +5 -1
- package/lib/cjs/blue/abis.js +2 -0
- package/lib/cjs/blue/entities.d.ts +8 -2
- package/lib/cjs/blue/entities.js +1 -0
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +3 -1
- package/lib/cjs/blue/fetch.js +1 -0
- package/lib/cjs/entities/blue/blue.d.ts +15 -6
- package/lib/cjs/entities/blue/blue.js +3 -0
- package/lib/cjs/entities/index.d.ts +8 -2
- package/lib/cjs/entities/index.js +1 -0
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +1 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +10 -5
- package/lib/cjs/entities/vaultV1/vaultV1.js +13 -1
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +140 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +229 -16
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +3 -2
- package/lib/cjs/fetch.d.ts +3 -1
- package/lib/cjs/fetch.js +1 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/cjs/helpers/index.d.ts +3 -1
- package/lib/cjs/helpers/index.js +10 -1
- package/lib/cjs/helpers/metadata.d.ts +3 -5
- package/lib/cjs/helpers/metadata.js +4 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/cjs/helpers/slippage.d.ts +46 -0
- package/lib/cjs/helpers/slippage.js +65 -0
- package/lib/cjs/helpers/validate.d.ts +65 -8
- package/lib/cjs/helpers/validate.js +83 -9
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/types/action.d.ts +95 -13
- package/lib/cjs/types/error.d.ts +290 -12
- package/lib/cjs/types/error.js +312 -24
- package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
- package/lib/cjs/utils.d.ts +3 -1
- package/lib/cjs/utils.js +10 -1
- package/lib/esm/abis.d.ts +17 -2
- package/lib/esm/abis.js +17 -2
- package/lib/esm/actions/blue/common.js +7 -28
- package/lib/esm/actions/blue/supply.js +4 -9
- package/lib/esm/actions/bundles/common.d.ts +32 -2
- package/lib/esm/actions/bundles/common.js +68 -31
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -28
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
- package/lib/esm/blue/abis.d.ts +5 -1
- package/lib/esm/blue/abis.js +5 -1
- package/lib/esm/blue/entities.d.ts +8 -2
- package/lib/esm/blue/entities.js +3 -1
- package/lib/esm/blue/errors.d.ts +1 -1
- package/lib/esm/blue/errors.js +1 -1
- package/lib/esm/blue/fetch.d.ts +3 -1
- package/lib/esm/blue/fetch.js +3 -1
- package/lib/esm/entities/blue/blue.d.ts +15 -6
- package/lib/esm/entities/blue/blue.js +3 -0
- package/lib/esm/entities/index.d.ts +8 -2
- package/lib/esm/entities/index.js +3 -1
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +10 -5
- package/lib/esm/entities/vaultV1/vaultV1.js +14 -2
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +140 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +234 -21
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/fetch.d.ts +3 -1
- package/lib/esm/fetch.js +3 -1
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/esm/helpers/index.d.ts +3 -1
- package/lib/esm/helpers/index.js +3 -1
- package/lib/esm/helpers/metadata.d.ts +3 -5
- package/lib/esm/helpers/metadata.js +4 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/esm/helpers/slippage.d.ts +46 -0
- package/lib/esm/helpers/slippage.js +65 -1
- package/lib/esm/helpers/validate.d.ts +65 -8
- package/lib/esm/helpers/validate.js +82 -10
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/types/action.d.ts +95 -13
- package/lib/esm/types/error.d.ts +290 -12
- package/lib/esm/types/error.js +301 -19
- package/lib/esm/types/sharedLiquidity.d.ts +2 -2
- package/lib/esm/utils.d.ts +3 -1
- package/lib/esm/utils.js +3 -1
- package/package.json +7 -7
- /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
- /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import { fetchToken, getPermitTypedData } from "@morpho-org/blue-sdk-viem";
|
|
2
2
|
import { deepFreeze, Time } from "@morpho-org/morpho-ts";
|
|
3
|
-
import { maxUint256 } from "viem";
|
|
4
3
|
import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
|
|
4
|
+
import { validateDeadline, validateUserAddress, } from "../../../helpers/validate.js";
|
|
5
5
|
import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
|
|
6
|
-
import { ChainIdMismatchError, ExpiredDeadlineError,
|
|
6
|
+
import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
|
|
9
9
|
* `amount` of `token`.
|
|
10
10
|
*
|
|
11
11
|
* Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
|
|
12
12
|
* signature, verifies it against the connected account, and returns a `RequirementSignature`
|
|
13
|
-
* the selected transaction route can consume.
|
|
14
|
-
*
|
|
13
|
+
* the selected transaction route can consume. The requirement's `action.typedData` holds that
|
|
14
|
+
* EIP-712 payload so it can be inspected or displayed before signing. Deadline defaults to two
|
|
15
|
+
* hours from `Time.timestamp()`.
|
|
15
16
|
*
|
|
16
17
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
17
18
|
* @param params - Permit encoding parameters.
|
|
18
19
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
20
|
+
* @param params.owner - Account that owns the tokens and signs the permit.
|
|
19
21
|
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
20
22
|
* VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
21
23
|
* @param params.amount - Permit allowance amount.
|
|
22
24
|
* @param params.chainId - Target chain id.
|
|
23
|
-
* @param params.nonce - The
|
|
25
|
+
* @param params.nonce - The owner's current EIP-2612 nonce on `token`.
|
|
24
26
|
* @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
|
|
25
27
|
* @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
|
|
26
|
-
* @returns A `Requirement` whose `
|
|
28
|
+
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
29
|
+
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
27
30
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
28
31
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
29
32
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
|
|
@@ -33,7 +36,8 @@ import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPo
|
|
|
33
36
|
* @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
|
|
34
37
|
* @throws {viem.BaseError} when the token metadata read fails with no fallback left.
|
|
35
38
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
36
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
39
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
40
|
+
* client account differs from `userAddress`.
|
|
37
41
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
38
42
|
* @example
|
|
39
43
|
* ```ts
|
|
@@ -44,16 +48,19 @@ import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPo
|
|
|
44
48
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
45
49
|
* const requirement = await encodeErc20Permit(client, {
|
|
46
50
|
* token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
|
|
51
|
+
* owner,
|
|
47
52
|
* spender: generalAdapter1,
|
|
48
53
|
* amount: 1_000_000n,
|
|
49
54
|
* chainId: 1,
|
|
50
55
|
* nonce: 0n,
|
|
51
56
|
* });
|
|
52
|
-
* //
|
|
57
|
+
* // Inspect the EIP-712 payload, then sign via the requirement:
|
|
58
|
+
* const typedData = requirement.action.typedData;
|
|
59
|
+
* const signed = await requirement.sign(client, owner);
|
|
53
60
|
* ```
|
|
54
61
|
*/
|
|
55
62
|
export const encodeErc20Permit = async (viemClient, params) => {
|
|
56
|
-
const { token, spender, amount, chainId, nonce, supportDeployless } = params;
|
|
63
|
+
const { token, owner, spender, amount, chainId, nonce, supportDeployless } = params;
|
|
57
64
|
if (viemClient.chain?.id !== chainId) {
|
|
58
65
|
throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
59
66
|
}
|
|
@@ -72,16 +79,7 @@ export const encodeErc20Permit = async (viemClient, params) => {
|
|
|
72
79
|
// called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
|
|
73
80
|
// deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
|
|
74
81
|
if (params.deadline != null) {
|
|
75
|
-
|
|
76
|
-
throw new NonPositiveInputError("deadline", params.deadline);
|
|
77
|
-
}
|
|
78
|
-
if (params.deadline > maxUint256) {
|
|
79
|
-
throw new InputExceedsMaxError({
|
|
80
|
-
field: "deadline",
|
|
81
|
-
value: params.deadline,
|
|
82
|
-
max: maxUint256,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
82
|
+
validateDeadline(params.deadline);
|
|
85
83
|
if (params.deadline <= now) {
|
|
86
84
|
throw new ExpiredDeadlineError(params.deadline, now);
|
|
87
85
|
}
|
|
@@ -90,6 +88,18 @@ export const encodeErc20Permit = async (viemClient, params) => {
|
|
|
90
88
|
const tokenData = await fetchToken(token, viemClient, {
|
|
91
89
|
deployless: supportDeployless,
|
|
92
90
|
});
|
|
91
|
+
const permitTypedData = getPermitTypedData({
|
|
92
|
+
erc20: tokenData,
|
|
93
|
+
owner,
|
|
94
|
+
spender,
|
|
95
|
+
allowance: amount,
|
|
96
|
+
nonce,
|
|
97
|
+
deadline,
|
|
98
|
+
}, chainId);
|
|
99
|
+
const typedData = deepFreeze({
|
|
100
|
+
...permitTypedData,
|
|
101
|
+
domain: { ...permitTypedData.domain },
|
|
102
|
+
});
|
|
93
103
|
const action = {
|
|
94
104
|
type: "permit",
|
|
95
105
|
args: {
|
|
@@ -98,18 +108,14 @@ export const encodeErc20Permit = async (viemClient, params) => {
|
|
|
98
108
|
deadline,
|
|
99
109
|
nonce,
|
|
100
110
|
},
|
|
111
|
+
typedData,
|
|
101
112
|
};
|
|
102
113
|
return {
|
|
103
114
|
action,
|
|
104
115
|
async sign(client, userAddress) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
spender,
|
|
109
|
-
allowance: amount,
|
|
110
|
-
nonce,
|
|
111
|
-
deadline,
|
|
112
|
-
}, chainId);
|
|
116
|
+
// The permit's owner is fixed at build time (the fetched nonce is owner-specific), so a
|
|
117
|
+
// different signer cannot produce a valid signature for it.
|
|
118
|
+
validateUserAddress(userAddress, owner);
|
|
113
119
|
const signature = await signAndVerifyTypedData({
|
|
114
120
|
client,
|
|
115
121
|
userAddress,
|
|
@@ -117,7 +123,7 @@ export const encodeErc20Permit = async (viemClient, params) => {
|
|
|
117
123
|
});
|
|
118
124
|
return deepFreeze({
|
|
119
125
|
args: {
|
|
120
|
-
owner
|
|
126
|
+
owner,
|
|
121
127
|
signature,
|
|
122
128
|
deadline,
|
|
123
129
|
amount,
|
|
@@ -12,7 +12,8 @@ interface EncodeErc20Permit2ApproveParams {
|
|
|
12
12
|
* Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
|
|
13
13
|
* via the Permit2 contract.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
15
|
+
* The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
|
|
16
|
+
* displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
|
|
16
17
|
*
|
|
17
18
|
* @param params - Permit2 encoding parameters.
|
|
18
19
|
* @param params.token - ERC-20 token address.
|
|
@@ -20,7 +21,8 @@ interface EncodeErc20Permit2ApproveParams {
|
|
|
20
21
|
* @param params.chainId - Target chain id.
|
|
21
22
|
* @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
|
|
22
23
|
* @param params.expiration - Permit2-managed allowance expiration timestamp.
|
|
23
|
-
* @returns A `Requirement` whose `
|
|
24
|
+
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
25
|
+
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
24
26
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
25
27
|
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
26
28
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
@@ -6,7 +6,8 @@ import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.
|
|
|
6
6
|
* Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
|
|
7
7
|
* via the Permit2 contract.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
|
|
10
|
+
* displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
|
|
10
11
|
*
|
|
11
12
|
* @param params - Permit2 encoding parameters.
|
|
12
13
|
* @param params.token - ERC-20 token address.
|
|
@@ -14,7 +15,8 @@ import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.
|
|
|
14
15
|
* @param params.chainId - Target chain id.
|
|
15
16
|
* @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
|
|
16
17
|
* @param params.expiration - Permit2-managed allowance expiration timestamp.
|
|
17
|
-
* @returns A `Requirement` whose `
|
|
18
|
+
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
19
|
+
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
18
20
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
19
21
|
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
20
22
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
@@ -37,6 +39,16 @@ export const encodeErc20Permit2Approve = (params) => {
|
|
|
37
39
|
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
38
40
|
const now = Time.timestamp();
|
|
39
41
|
const deadline = now + Time.s.from.h(2n);
|
|
42
|
+
// Permit2 AllowanceTransfer signs over `PermitSingle` (token, spender, expiration, nonce), which
|
|
43
|
+
// does not include the owner, so the payload is fully determined at build time.
|
|
44
|
+
const typedData = deepFreeze(getPermit2PermitTypedData({
|
|
45
|
+
spender: generalAdapter1,
|
|
46
|
+
allowance: amount,
|
|
47
|
+
erc20: token,
|
|
48
|
+
nonce: Number(nonce),
|
|
49
|
+
deadline,
|
|
50
|
+
expiration: Number(expiration),
|
|
51
|
+
}, chainId));
|
|
40
52
|
const action = {
|
|
41
53
|
type: "permit2",
|
|
42
54
|
args: {
|
|
@@ -45,18 +57,11 @@ export const encodeErc20Permit2Approve = (params) => {
|
|
|
45
57
|
deadline,
|
|
46
58
|
expiration,
|
|
47
59
|
},
|
|
60
|
+
typedData,
|
|
48
61
|
};
|
|
49
62
|
return {
|
|
50
63
|
action,
|
|
51
64
|
async sign(client, userAddress) {
|
|
52
|
-
const typedData = getPermit2PermitTypedData({
|
|
53
|
-
spender: generalAdapter1,
|
|
54
|
-
allowance: amount,
|
|
55
|
-
erc20: token,
|
|
56
|
-
nonce: Number(nonce),
|
|
57
|
-
deadline,
|
|
58
|
-
expiration: Number(expiration),
|
|
59
|
-
}, chainId);
|
|
60
65
|
const signature = await signAndVerifyTypedData({
|
|
61
66
|
client,
|
|
62
67
|
userAddress,
|
|
@@ -19,7 +19,8 @@ export interface EncodeErc20Permit2SignatureTransferParams {
|
|
|
19
19
|
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
20
20
|
*
|
|
21
21
|
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
22
|
-
* it has no managed allowance expiration.
|
|
22
|
+
* it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
|
|
23
|
+
* payload so it can be inspected or displayed before signing.
|
|
23
24
|
*
|
|
24
25
|
* @param params - SignatureTransfer parameters.
|
|
25
26
|
* @param params.token - ERC-20 token pulled through Permit2.
|
|
@@ -28,7 +29,8 @@ export interface EncodeErc20Permit2SignatureTransferParams {
|
|
|
28
29
|
* @param params.chainId - Target chain id.
|
|
29
30
|
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
30
31
|
* @param params.deadline - Signature expiration timestamp in seconds.
|
|
31
|
-
* @returns A requirement whose `
|
|
32
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
|
|
33
|
+
* `sign(client, userAddress)` returns a deep-frozen signature result.
|
|
32
34
|
* @throws {NegativeInputError} when `amount` or `nonce` is negative.
|
|
33
35
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
34
36
|
* @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
|
|
@@ -9,7 +9,8 @@ import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } fr
|
|
|
9
9
|
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
10
10
|
*
|
|
11
11
|
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
12
|
-
* it has no managed allowance expiration.
|
|
12
|
+
* it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
|
|
13
|
+
* payload so it can be inspected or displayed before signing.
|
|
13
14
|
*
|
|
14
15
|
* @param params - SignatureTransfer parameters.
|
|
15
16
|
* @param params.token - ERC-20 token pulled through Permit2.
|
|
@@ -18,7 +19,8 @@ import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } fr
|
|
|
18
19
|
* @param params.chainId - Target chain id.
|
|
19
20
|
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
20
21
|
* @param params.deadline - Signature expiration timestamp in seconds.
|
|
21
|
-
* @returns A requirement whose `
|
|
22
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
|
|
23
|
+
* `sign(client, userAddress)` returns a deep-frozen signature result.
|
|
22
24
|
* @throws {NegativeInputError} when `amount` or `nonce` is negative.
|
|
23
25
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
24
26
|
* @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
|
|
@@ -84,20 +86,23 @@ export const encodeErc20Permit2SignatureTransfer = (params) => {
|
|
|
84
86
|
// sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
|
|
85
87
|
// this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
|
|
86
88
|
getChainAddress(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
|
|
89
|
+
// Permit2 SignatureTransfer signs over `PermitTransferFrom` (permitted, spender, nonce,
|
|
90
|
+
// deadline), which does not include the owner, so the payload is fully determined at build time.
|
|
91
|
+
const typedData = deepFreeze(getPermit2TransferFromTypedData({
|
|
92
|
+
erc20: token,
|
|
93
|
+
allowance: amount,
|
|
94
|
+
spender,
|
|
95
|
+
nonce,
|
|
96
|
+
deadline,
|
|
97
|
+
}, chainId));
|
|
87
98
|
const action = {
|
|
88
99
|
type: "permit2SignatureTransfer",
|
|
89
100
|
args: { spender, amount, nonce, deadline },
|
|
101
|
+
typedData,
|
|
90
102
|
};
|
|
91
103
|
return {
|
|
92
104
|
action,
|
|
93
105
|
async sign(client, userAddress) {
|
|
94
|
-
const typedData = getPermit2TransferFromTypedData({
|
|
95
|
-
erc20: token,
|
|
96
|
-
allowance: amount,
|
|
97
|
-
spender,
|
|
98
|
-
nonce,
|
|
99
|
-
deadline,
|
|
100
|
-
}, chainId);
|
|
101
106
|
const signature = await signAndVerifyTypedData({
|
|
102
107
|
client,
|
|
103
108
|
userAddress,
|
|
@@ -23,7 +23,8 @@ export interface EncodeVaultSharesPermitParams {
|
|
|
23
23
|
* Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
|
|
24
24
|
*
|
|
25
25
|
* Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
|
|
26
|
-
* only `chainId` and `verifyingContract`.
|
|
26
|
+
* only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
|
|
27
|
+
* payload so it can be inspected or displayed before signing.
|
|
27
28
|
*
|
|
28
29
|
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
29
30
|
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
@@ -33,16 +34,18 @@ export interface EncodeVaultSharesPermitParams {
|
|
|
33
34
|
* @param params.nonce - Current vault permit nonce for the owner.
|
|
34
35
|
* @param params.amount - Vault-share allowance to authorize.
|
|
35
36
|
* @param params.deadline - Shared permit and bundle deadline.
|
|
36
|
-
* @returns A requirement whose `
|
|
37
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
|
|
38
|
+
* can be embedded in fixed vault-bundles calldata.
|
|
37
39
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
38
40
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
|
|
39
41
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
40
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
42
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
43
|
+
* wallet account differs from `userAddress`.
|
|
41
44
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
42
45
|
* @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
|
|
43
|
-
* @throws {InvalidPermitDomainChainIdError}
|
|
44
|
-
* @throws {InvalidPermitDomainVerifyingContractError}
|
|
45
|
-
* @throws {UnsupportedPermitDomainExtensionsError}
|
|
46
|
+
* @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
|
|
47
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
|
|
48
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
|
|
46
49
|
* @example
|
|
47
50
|
* ```ts
|
|
48
51
|
* import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
|
|
@@ -9,7 +9,8 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
|
|
|
9
9
|
* Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
|
|
10
10
|
*
|
|
11
11
|
* Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
|
|
12
|
-
* only `chainId` and `verifyingContract`.
|
|
12
|
+
* only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
|
|
13
|
+
* payload so it can be inspected or displayed before signing.
|
|
13
14
|
*
|
|
14
15
|
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
15
16
|
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
@@ -19,16 +20,18 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
|
|
|
19
20
|
* @param params.nonce - Current vault permit nonce for the owner.
|
|
20
21
|
* @param params.amount - Vault-share allowance to authorize.
|
|
21
22
|
* @param params.deadline - Shared permit and bundle deadline.
|
|
22
|
-
* @returns A requirement whose `
|
|
23
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
|
|
24
|
+
* can be embedded in fixed vault-bundles calldata.
|
|
23
25
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
24
26
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
|
|
25
27
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
26
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
28
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
29
|
+
* wallet account differs from `userAddress`.
|
|
27
30
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
28
31
|
* @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
|
|
29
|
-
* @throws {InvalidPermitDomainChainIdError}
|
|
30
|
-
* @throws {InvalidPermitDomainVerifyingContractError}
|
|
31
|
-
* @throws {UnsupportedPermitDomainExtensionsError}
|
|
32
|
+
* @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
|
|
33
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
|
|
34
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
|
|
32
35
|
* @example
|
|
33
36
|
* ```ts
|
|
34
37
|
* import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
|
|
@@ -82,6 +85,18 @@ export const encodeVaultSharesPermit = (params) => {
|
|
|
82
85
|
spender,
|
|
83
86
|
allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
|
|
84
87
|
});
|
|
88
|
+
const permitTypedData = getPermitTypedData({
|
|
89
|
+
owner,
|
|
90
|
+
spender,
|
|
91
|
+
allowance: amount,
|
|
92
|
+
nonce,
|
|
93
|
+
deadline,
|
|
94
|
+
erc20: vault,
|
|
95
|
+
}, chainId);
|
|
96
|
+
const typedData = deepFreeze({
|
|
97
|
+
...permitTypedData,
|
|
98
|
+
domain: { ...permitTypedData.domain },
|
|
99
|
+
});
|
|
85
100
|
const action = {
|
|
86
101
|
type: "permit",
|
|
87
102
|
args: {
|
|
@@ -90,23 +105,13 @@ export const encodeVaultSharesPermit = (params) => {
|
|
|
90
105
|
deadline,
|
|
91
106
|
nonce,
|
|
92
107
|
},
|
|
108
|
+
typedData,
|
|
93
109
|
};
|
|
94
110
|
return {
|
|
95
111
|
action,
|
|
96
112
|
async sign(client, userAddress) {
|
|
97
113
|
// The bundle spends msg.sender's shares, so another signer cannot authorize this exit.
|
|
98
114
|
validateUserAddress(userAddress, owner);
|
|
99
|
-
const permit = {
|
|
100
|
-
owner,
|
|
101
|
-
spender,
|
|
102
|
-
allowance: amount,
|
|
103
|
-
nonce,
|
|
104
|
-
deadline,
|
|
105
|
-
};
|
|
106
|
-
const typedData = getPermitTypedData({
|
|
107
|
-
...permit,
|
|
108
|
-
erc20: vault,
|
|
109
|
-
}, chainId);
|
|
110
115
|
const signature = await signAndVerifyTypedData({
|
|
111
116
|
client,
|
|
112
117
|
userAddress,
|
|
@@ -92,6 +92,7 @@ export const getGeneralAdapterRequirements = async (viemClient, params) => {
|
|
|
92
92
|
// the pulled amount leaves no residual direct allowance after inclusion.
|
|
93
93
|
return getGeneralAdapterRequirementsPermit(viemClient, {
|
|
94
94
|
token: address,
|
|
95
|
+
owner: from,
|
|
95
96
|
chainId,
|
|
96
97
|
args: { amount },
|
|
97
98
|
nonce: erc2612Nonce,
|
package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ import type { Address, Client } from "viem";
|
|
|
5
5
|
*
|
|
6
6
|
* @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
|
|
7
7
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
8
|
+
* @param params.owner - Account that owns the tokens and signs the permit.
|
|
8
9
|
* @param params.chainId - The chain the bundle targets.
|
|
9
10
|
* @param params.args.amount - Required token amount.
|
|
10
|
-
* @param params.nonce - The
|
|
11
|
+
* @param params.nonce - The owner's current EIP-2612 nonce on `token`.
|
|
11
12
|
* @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
|
|
12
13
|
* @returns A single-element array containing the exact-amount `Requirement` to sign.
|
|
13
14
|
* @example
|
|
@@ -19,6 +20,7 @@ import type { Address, Client } from "viem";
|
|
|
19
20
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
20
21
|
* const reqs = await getGeneralAdapterRequirementsPermit(client, {
|
|
21
22
|
* token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
|
|
23
|
+
* owner,
|
|
22
24
|
* chainId: 1,
|
|
23
25
|
* args: { amount: 1_000_000n },
|
|
24
26
|
* nonce: 0n,
|
|
@@ -28,6 +30,7 @@ import type { Address, Client } from "viem";
|
|
|
28
30
|
*/
|
|
29
31
|
export declare const getGeneralAdapterRequirementsPermit: (viemClient: Client, params: {
|
|
30
32
|
token: Address;
|
|
33
|
+
owner: Address;
|
|
31
34
|
chainId: number;
|
|
32
35
|
args: {
|
|
33
36
|
amount: bigint;
|
|
@@ -6,9 +6,10 @@ import { encodeErc20Permit } from "../encode/index.js";
|
|
|
6
6
|
*
|
|
7
7
|
* @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
|
|
8
8
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
9
|
+
* @param params.owner - Account that owns the tokens and signs the permit.
|
|
9
10
|
* @param params.chainId - The chain the bundle targets.
|
|
10
11
|
* @param params.args.amount - Required token amount.
|
|
11
|
-
* @param params.nonce - The
|
|
12
|
+
* @param params.nonce - The owner's current EIP-2612 nonce on `token`.
|
|
12
13
|
* @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
|
|
13
14
|
* @returns A single-element array containing the exact-amount `Requirement` to sign.
|
|
14
15
|
* @example
|
|
@@ -20,6 +21,7 @@ import { encodeErc20Permit } from "../encode/index.js";
|
|
|
20
21
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
21
22
|
* const reqs = await getGeneralAdapterRequirementsPermit(client, {
|
|
22
23
|
* token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
|
|
24
|
+
* owner,
|
|
23
25
|
* chainId: 1,
|
|
24
26
|
* args: { amount: 1_000_000n },
|
|
25
27
|
* nonce: 0n,
|
|
@@ -28,7 +30,7 @@ import { encodeErc20Permit } from "../encode/index.js";
|
|
|
28
30
|
* ```
|
|
29
31
|
*/
|
|
30
32
|
export const getGeneralAdapterRequirementsPermit = async (viemClient, params) => {
|
|
31
|
-
const { token, chainId, args: { amount }, nonce, supportDeployless, } = params;
|
|
33
|
+
const { token, owner, chainId, args: { amount }, nonce, supportDeployless, } = params;
|
|
32
34
|
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
33
35
|
// Existing direct ERC-20 allowance is intentionally not an input here. ERC-2612 overwrites the
|
|
34
36
|
// allowance with the signed amount, and the bundle spends exactly `amount`, leaving no residual
|
|
@@ -36,6 +38,7 @@ export const getGeneralAdapterRequirementsPermit = async (viemClient, params) =>
|
|
|
36
38
|
return [
|
|
37
39
|
await encodeErc20Permit(viemClient, {
|
|
38
40
|
token,
|
|
41
|
+
owner,
|
|
39
42
|
spender: generalAdapter1,
|
|
40
43
|
amount,
|
|
41
44
|
chainId,
|
|
@@ -17,6 +17,10 @@ export interface GetVaultExitBundlesV1PermitStructParams {
|
|
|
17
17
|
readonly vault: Address;
|
|
18
18
|
/** Bundle deadline used by the empty-permit sentinel. */
|
|
19
19
|
readonly deadline: bigint;
|
|
20
|
+
/** Optional expected owner of the signed permit. */
|
|
21
|
+
readonly owner?: Address;
|
|
22
|
+
/** Optional expected spender of the signed permit. */
|
|
23
|
+
readonly spender?: Address;
|
|
20
24
|
/** Optional signed bounded ERC-2612 requirement. */
|
|
21
25
|
readonly requirementSignature?: PermitRequirementSignature;
|
|
22
26
|
}
|
|
@@ -25,6 +29,8 @@ export interface GetVaultExitBundlesV1PermitStructParams {
|
|
|
25
29
|
*
|
|
26
30
|
* @param params.vault - Vault share token authorized by the permit.
|
|
27
31
|
* @param params.deadline - Bundle deadline used by the empty-permit sentinel.
|
|
32
|
+
* @param params.owner - Optional expected owner of the signed permit.
|
|
33
|
+
* @param params.spender - Optional expected spender of the signed permit.
|
|
28
34
|
* @param params.requirementSignature - Optional signed ERC-2612 vault-share requirement.
|
|
29
35
|
* @returns The shared bundles share-permit tuple.
|
|
30
36
|
* @throws {VaultExitBundlesV1PermitMismatchError} when the requirement is incompatible.
|
|
@@ -5,6 +5,8 @@ import { getBundlesSharesPermit, } from "../bundles/common.js";
|
|
|
5
5
|
*
|
|
6
6
|
* @param params.vault - Vault share token authorized by the permit.
|
|
7
7
|
* @param params.deadline - Bundle deadline used by the empty-permit sentinel.
|
|
8
|
+
* @param params.owner - Optional expected owner of the signed permit.
|
|
9
|
+
* @param params.spender - Optional expected spender of the signed permit.
|
|
8
10
|
* @param params.requirementSignature - Optional signed ERC-2612 vault-share requirement.
|
|
9
11
|
* @returns The shared bundles share-permit tuple.
|
|
10
12
|
* @throws {VaultExitBundlesV1PermitMismatchError} when the requirement is incompatible.
|
|
@@ -36,6 +36,7 @@ export interface VaultV1InKindRedeemParams {
|
|
|
36
36
|
* @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
|
|
37
37
|
* `data`, and the typed action discriminator.
|
|
38
38
|
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
39
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
39
40
|
* @throws {EmptyMarketParamsListError} when no markets are supplied.
|
|
40
41
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
41
42
|
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
@@ -2,6 +2,7 @@ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
|
2
2
|
import { encodeFunctionData } from "viem";
|
|
3
3
|
import { vaultExitBundlesV1Abi } from "../../abis.js";
|
|
4
4
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
|
+
import { validateDeadline } from "../../helpers/validate.js";
|
|
5
6
|
import { EmptyMarketParamsListError, NonPositiveInputError, } from "../../types/index.js";
|
|
6
7
|
import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBundlesV1PermitStruct.js";
|
|
7
8
|
/**
|
|
@@ -24,6 +25,7 @@ import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBun
|
|
|
24
25
|
* @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
|
|
25
26
|
* `data`, and the typed action discriminator.
|
|
26
27
|
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
28
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
27
29
|
* @throws {EmptyMarketParamsListError} when no markets are supplied.
|
|
28
30
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
29
31
|
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
@@ -42,8 +44,7 @@ import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBun
|
|
|
42
44
|
export const vaultV1InKindRedeem = ({ vault, args, metadata, }) => {
|
|
43
45
|
if (args.amount <= 0n)
|
|
44
46
|
throw new NonPositiveInputError("amount", args.amount);
|
|
45
|
-
|
|
46
|
-
throw new NonPositiveInputError("deadline", args.deadline);
|
|
47
|
+
validateDeadline(args.deadline);
|
|
47
48
|
if (args.marketParamsList.length === 0)
|
|
48
49
|
throw new EmptyMarketParamsListError();
|
|
49
50
|
const to = getChainAddress(vault.chainId, "bundles.vaultExitBundlesV1");
|