@morpho-org/morpho-sdk 5.9.0 → 6.0.0-next.1
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 +404 -0
- package/README.md +127 -69
- package/lib/cjs/abis.d.ts +210 -0
- package/lib/cjs/abis.js +142 -2
- package/lib/cjs/actions/blue/borrow.d.ts +62 -61
- package/lib/cjs/actions/blue/borrow.js +48 -80
- package/lib/cjs/actions/blue/common.d.ts +86 -0
- package/lib/cjs/actions/blue/common.js +205 -0
- package/lib/cjs/actions/blue/refinance.d.ts +72 -112
- package/lib/cjs/actions/blue/refinance.js +97 -199
- package/lib/cjs/actions/blue/repay.d.ts +72 -68
- package/lib/cjs/actions/blue/repay.js +56 -118
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
- package/lib/cjs/actions/blue/supply.d.ts +62 -45
- package/lib/cjs/actions/blue/supply.js +94 -70
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -90
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -120
- package/lib/cjs/actions/blue/withdraw.d.ts +68 -79
- package/lib/cjs/actions/blue/withdraw.js +101 -97
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
- package/lib/cjs/actions/bundles/common.d.ts +200 -0
- package/lib/cjs/actions/bundles/common.js +469 -0
- package/lib/cjs/actions/bundles/index.d.ts +3 -0
- package/lib/cjs/actions/bundles/index.js +23 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
- package/lib/cjs/actions/index.d.ts +2 -1
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/blue/index.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +8 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +123 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/index.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +6 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +6 -4
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
- package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/cjs/actions/vaultV1/deposit.js +110 -109
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
- package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/cjs/actions/vaultV1/redeem.js +56 -33
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
- package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/cjs/actions/vaultV2/deposit.js +111 -109
- package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/cjs/actions/vaultV2/redeem.js +56 -34
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
- package/lib/cjs/bundler/actions.d.ts +4 -4
- package/lib/cjs/bundler/actions.js +4 -4
- package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
- package/lib/cjs/client/morphoViemExtension.js +2 -1
- package/lib/cjs/entities/blue/blue.d.ts +806 -374
- package/lib/cjs/entities/blue/blue.js +449 -696
- package/lib/cjs/entities/index.d.ts +2 -0
- package/lib/cjs/entities/index.js +15 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +203 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +17 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
- package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +3 -9
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +3 -9
- package/lib/cjs/helpers/index.d.ts +2 -1
- package/lib/cjs/helpers/index.js +5 -1
- package/lib/cjs/helpers/referralFee.d.ts +21 -0
- package/lib/cjs/helpers/referralFee.js +35 -0
- package/lib/cjs/helpers/slippage.d.ts +90 -1
- package/lib/cjs/helpers/slippage.js +123 -0
- package/lib/cjs/helpers/validate.d.ts +16 -23
- package/lib/cjs/helpers/validate.js +41 -48
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +3 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/types/action.d.ts +303 -210
- package/lib/cjs/types/action.js +29 -2
- package/lib/cjs/types/client.d.ts +9 -0
- package/lib/cjs/types/error.d.ts +193 -18
- package/lib/cjs/types/error.js +267 -24
- package/lib/cjs/types/sharedLiquidity.d.ts +0 -7
- package/lib/esm/abis.d.ts +210 -0
- package/lib/esm/abis.js +140 -0
- package/lib/esm/actions/blue/borrow.d.ts +62 -61
- package/lib/esm/actions/blue/borrow.js +48 -80
- package/lib/esm/actions/blue/common.d.ts +86 -0
- package/lib/esm/actions/blue/common.js +193 -0
- package/lib/esm/actions/blue/refinance.d.ts +72 -112
- package/lib/esm/actions/blue/refinance.js +98 -200
- package/lib/esm/actions/blue/repay.d.ts +72 -68
- package/lib/esm/actions/blue/repay.js +56 -118
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
- package/lib/esm/actions/blue/supply.d.ts +62 -45
- package/lib/esm/actions/blue/supply.js +94 -70
- package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/esm/actions/blue/supplyCollateral.js +52 -69
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -90
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -121
- package/lib/esm/actions/blue/withdraw.d.ts +68 -79
- package/lib/esm/actions/blue/withdraw.js +100 -96
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
- package/lib/esm/actions/bundles/common.d.ts +200 -0
- package/lib/esm/actions/bundles/common.js +457 -0
- package/lib/esm/actions/bundles/index.d.ts +3 -0
- package/lib/esm/actions/bundles/index.js +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
- package/lib/esm/actions/index.d.ts +2 -1
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
- package/lib/esm/actions/requirements/blue/index.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +119 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/index.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +6 -4
- package/lib/esm/actions/requirements/getRequirementsApproval.js +6 -4
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
- package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/esm/actions/vaultV1/deposit.js +112 -111
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
- package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/esm/actions/vaultV1/redeem.js +56 -33
- package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/esm/actions/vaultV1/withdraw.js +86 -34
- package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/esm/actions/vaultV2/deposit.js +113 -111
- package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/esm/actions/vaultV2/redeem.js +56 -34
- package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/esm/actions/vaultV2/withdraw.js +86 -35
- package/lib/esm/bundler/actions.d.ts +4 -4
- package/lib/esm/bundler/actions.js +4 -4
- package/lib/esm/client/morphoViemExtension.d.ts +2 -1
- package/lib/esm/client/morphoViemExtension.js +2 -1
- package/lib/esm/entities/blue/blue.d.ts +806 -374
- package/lib/esm/entities/blue/blue.js +455 -702
- package/lib/esm/entities/index.d.ts +2 -0
- package/lib/esm/entities/index.js +1 -0
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +199 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
- 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 +348 -98
- package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +3 -9
- package/lib/esm/helpers/computeVaultV1Reallocations.js +3 -9
- package/lib/esm/helpers/index.d.ts +2 -1
- package/lib/esm/helpers/index.js +2 -1
- package/lib/esm/helpers/referralFee.d.ts +21 -0
- package/lib/esm/helpers/referralFee.js +31 -0
- package/lib/esm/helpers/slippage.d.ts +90 -1
- package/lib/esm/helpers/slippage.js +122 -2
- package/lib/esm/helpers/validate.d.ts +16 -23
- package/lib/esm/helpers/validate.js +40 -48
- package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/esm/helpers/validateRequirementSpender.js +3 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +303 -210
- package/lib/esm/types/action.js +28 -2
- package/lib/esm/types/client.d.ts +9 -0
- package/lib/esm/types/error.d.ts +193 -18
- package/lib/esm/types/error.js +252 -21
- package/lib/esm/types/sharedLiquidity.d.ts +0 -7
- package/package.json +6 -5
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Address } from "@morpho-org/blue-sdk";
|
|
2
|
-
import type
|
|
3
|
-
import { type
|
|
2
|
+
import { type Client } from "viem";
|
|
3
|
+
import { type Erc2612RequirementSignature, type Requirement } from "../../../types/index.js";
|
|
4
4
|
/** Parameters for {@link encodeErc20Permit}. */
|
|
5
5
|
interface EncodeErc20PermitParams {
|
|
6
6
|
token: Address;
|
|
@@ -9,6 +9,7 @@ interface EncodeErc20PermitParams {
|
|
|
9
9
|
chainId: number;
|
|
10
10
|
nonce: bigint;
|
|
11
11
|
supportDeployless?: boolean;
|
|
12
|
+
deadline?: bigint;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
|
|
@@ -16,20 +17,28 @@ interface EncodeErc20PermitParams {
|
|
|
16
17
|
*
|
|
17
18
|
* Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
|
|
18
19
|
* signature, verifies it against the connected account, and returns a `RequirementSignature`
|
|
19
|
-
* the
|
|
20
|
+
* the selected transaction route can consume. Deadline defaults to two hours from
|
|
21
|
+
* `Time.timestamp()`.
|
|
20
22
|
*
|
|
21
23
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
22
24
|
* @param params - Permit encoding parameters.
|
|
23
25
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
24
|
-
* @param params.spender - Permit spender. Must be GeneralAdapter1
|
|
26
|
+
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
27
|
+
* VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
25
28
|
* @param params.amount - Permit allowance amount.
|
|
26
29
|
* @param params.chainId - Target chain id.
|
|
27
30
|
* @param params.nonce - The user's current EIP-2612 nonce on `token`.
|
|
28
31
|
* @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
|
|
32
|
+
* @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
|
|
29
33
|
* @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
|
|
30
34
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
31
|
-
* @throws {
|
|
32
|
-
*
|
|
35
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
36
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
|
|
37
|
+
* MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
|
|
38
|
+
* @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
|
|
39
|
+
* @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
|
|
40
|
+
* @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
|
|
41
|
+
* @throws {viem.BaseError} when the token metadata read fails with no fallback left.
|
|
33
42
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
34
43
|
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
35
44
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
@@ -50,5 +59,5 @@ interface EncodeErc20PermitParams {
|
|
|
50
59
|
* // requirement satisfies Requirement
|
|
51
60
|
* ```
|
|
52
61
|
*/
|
|
53
|
-
export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<
|
|
62
|
+
export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<Erc2612RequirementSignature>>;
|
|
54
63
|
export {};
|
|
@@ -1,28 +1,37 @@
|
|
|
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";
|
|
3
4
|
import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
|
|
4
5
|
import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
|
|
5
|
-
import { ChainIdMismatchError, } from "../../../types/index.js";
|
|
6
|
+
import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } from "../../../types/index.js";
|
|
6
7
|
/**
|
|
7
8
|
* Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
|
|
8
9
|
* `amount` of `token`.
|
|
9
10
|
*
|
|
10
11
|
* Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
|
|
11
12
|
* signature, verifies it against the connected account, and returns a `RequirementSignature`
|
|
12
|
-
* the
|
|
13
|
+
* the selected transaction route can consume. Deadline defaults to two hours from
|
|
14
|
+
* `Time.timestamp()`.
|
|
13
15
|
*
|
|
14
16
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
15
17
|
* @param params - Permit encoding parameters.
|
|
16
18
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
17
|
-
* @param params.spender - Permit spender. Must be GeneralAdapter1
|
|
19
|
+
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
20
|
+
* VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
18
21
|
* @param params.amount - Permit allowance amount.
|
|
19
22
|
* @param params.chainId - Target chain id.
|
|
20
23
|
* @param params.nonce - The user's current EIP-2612 nonce on `token`.
|
|
21
24
|
* @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
|
|
25
|
+
* @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
|
|
22
26
|
* @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
|
|
23
27
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
24
|
-
* @throws {
|
|
25
|
-
*
|
|
28
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
29
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
|
|
30
|
+
* MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
|
|
31
|
+
* @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
|
|
32
|
+
* @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
|
|
33
|
+
* @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
|
|
34
|
+
* @throws {viem.BaseError} when the token metadata read fails with no fallback left.
|
|
26
35
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
27
36
|
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
28
37
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
@@ -51,10 +60,33 @@ export const encodeErc20Permit = async (viemClient, params) => {
|
|
|
51
60
|
validateRequirementSpender({
|
|
52
61
|
chainId,
|
|
53
62
|
spender,
|
|
54
|
-
allowed: [
|
|
63
|
+
allowed: [
|
|
64
|
+
"generalAdapter1",
|
|
65
|
+
"midnightBundles",
|
|
66
|
+
"vaultBundlesV1",
|
|
67
|
+
"blueBundlesV1",
|
|
68
|
+
],
|
|
55
69
|
});
|
|
56
70
|
const now = Time.timestamp();
|
|
57
|
-
|
|
71
|
+
// Validate an explicit deadline before the token-metadata read: this exported encoder can be
|
|
72
|
+
// called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
|
|
73
|
+
// deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
|
|
74
|
+
if (params.deadline != null) {
|
|
75
|
+
if (params.deadline <= 0n) {
|
|
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
|
+
}
|
|
85
|
+
if (params.deadline <= now) {
|
|
86
|
+
throw new ExpiredDeadlineError(params.deadline, now);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const deadline = params.deadline ?? now + Time.s.from.h(2n);
|
|
58
90
|
const tokenData = await fetchToken(token, viemClient, {
|
|
59
91
|
deployless: supportDeployless,
|
|
60
92
|
});
|
|
@@ -64,6 +96,7 @@ export const encodeErc20Permit = async (viemClient, params) => {
|
|
|
64
96
|
spender,
|
|
65
97
|
amount,
|
|
66
98
|
deadline,
|
|
99
|
+
nonce,
|
|
67
100
|
},
|
|
68
101
|
};
|
|
69
102
|
return {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Address } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Permit2SignatureTransferRequirementSignature, type Requirement } from "../../../types/index.js";
|
|
3
|
+
/** Parameters for {@link encodeErc20Permit2SignatureTransfer}. */
|
|
4
|
+
export interface EncodeErc20Permit2SignatureTransferParams {
|
|
5
|
+
/** ERC-20 token pulled through Permit2. */
|
|
6
|
+
readonly token: Address;
|
|
7
|
+
/** Registered fixed bundles deployment receiving permission to pull the token. */
|
|
8
|
+
readonly spender: Address;
|
|
9
|
+
/** Exact token amount authorized by the one-time transfer. */
|
|
10
|
+
readonly amount: bigint;
|
|
11
|
+
/** Target chain id. */
|
|
12
|
+
readonly chainId: number;
|
|
13
|
+
/** Unused Permit2 unordered nonce. */
|
|
14
|
+
readonly nonce: bigint;
|
|
15
|
+
/** Signature expiration timestamp in seconds. */
|
|
16
|
+
readonly deadline: bigint;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
20
|
+
*
|
|
21
|
+
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
22
|
+
* it has no managed allowance expiration.
|
|
23
|
+
*
|
|
24
|
+
* @param params - SignatureTransfer parameters.
|
|
25
|
+
* @param params.token - ERC-20 token pulled through Permit2.
|
|
26
|
+
* @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
|
|
27
|
+
* @param params.amount - Exact `uint256` token amount authorized.
|
|
28
|
+
* @param params.chainId - Target chain id.
|
|
29
|
+
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
30
|
+
* @param params.deadline - Signature expiration timestamp in seconds.
|
|
31
|
+
* @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
|
|
32
|
+
* @throws {NegativeInputError} when `amount` or `nonce` is negative.
|
|
33
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
34
|
+
* @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
|
|
35
|
+
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
36
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
37
|
+
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
38
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
|
|
39
|
+
* @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
|
|
40
|
+
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
|
|
41
|
+
* @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
|
|
42
|
+
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
46
|
+
* import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
|
|
47
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
48
|
+
* import { mainnet } from "viem/chains";
|
|
49
|
+
*
|
|
50
|
+
* const requirement = encodeErc20Permit2SignatureTransfer({
|
|
51
|
+
* token: addressesRegistry[mainnet.id].usdc,
|
|
52
|
+
* spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
|
|
53
|
+
* amount: 1_000_000n,
|
|
54
|
+
* chainId: mainnet.id,
|
|
55
|
+
* nonce: 0n,
|
|
56
|
+
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
57
|
+
* });
|
|
58
|
+
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const encodeErc20Permit2SignatureTransfer: (params: EncodeErc20Permit2SignatureTransferParams) => Requirement<Permit2SignatureTransferRequirementSignature>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { getPermit2TransferFromTypedData } from "@morpho-org/blue-sdk-viem";
|
|
2
|
+
import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { maxUint256 } from "viem";
|
|
4
|
+
import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
|
|
5
|
+
import { validateUint256Field } from "../../../helpers/validate.js";
|
|
6
|
+
import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
|
|
7
|
+
import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } from "../../../types/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
10
|
+
*
|
|
11
|
+
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
12
|
+
* it has no managed allowance expiration.
|
|
13
|
+
*
|
|
14
|
+
* @param params - SignatureTransfer parameters.
|
|
15
|
+
* @param params.token - ERC-20 token pulled through Permit2.
|
|
16
|
+
* @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
|
|
17
|
+
* @param params.amount - Exact `uint256` token amount authorized.
|
|
18
|
+
* @param params.chainId - Target chain id.
|
|
19
|
+
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
20
|
+
* @param params.deadline - Signature expiration timestamp in seconds.
|
|
21
|
+
* @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
|
|
22
|
+
* @throws {NegativeInputError} when `amount` or `nonce` is negative.
|
|
23
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
24
|
+
* @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
|
|
25
|
+
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
26
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
27
|
+
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
28
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
|
|
29
|
+
* @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
|
|
30
|
+
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
|
|
31
|
+
* @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
|
|
32
|
+
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
36
|
+
* import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
|
|
37
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
38
|
+
* import { mainnet } from "viem/chains";
|
|
39
|
+
*
|
|
40
|
+
* const requirement = encodeErc20Permit2SignatureTransfer({
|
|
41
|
+
* token: addressesRegistry[mainnet.id].usdc,
|
|
42
|
+
* spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
|
|
43
|
+
* amount: 1_000_000n,
|
|
44
|
+
* chainId: mainnet.id,
|
|
45
|
+
* nonce: 0n,
|
|
46
|
+
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
47
|
+
* });
|
|
48
|
+
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export const encodeErc20Permit2SignatureTransfer = (params) => {
|
|
52
|
+
const { token, spender, amount, chainId, nonce, deadline } = params;
|
|
53
|
+
// Bound every uint256 field before signing: getPermit2TransferFromTypedData silently clamps an
|
|
54
|
+
// oversized allowance to maxUint256, which would desync the signed value from the requirement
|
|
55
|
+
// metadata that blueSupply verifies. Direct callers bypass the token-requirement resolver, so
|
|
56
|
+
// this public encoder must reject the same out-of-range inputs itself.
|
|
57
|
+
validateUint256Field("amount", amount);
|
|
58
|
+
validateUint256Field("nonce", nonce);
|
|
59
|
+
if (deadline <= 0n) {
|
|
60
|
+
throw new NonPositiveInputError("deadline", deadline);
|
|
61
|
+
}
|
|
62
|
+
if (deadline > maxUint256) {
|
|
63
|
+
throw new InputExceedsMaxError({
|
|
64
|
+
field: "deadline",
|
|
65
|
+
value: deadline,
|
|
66
|
+
max: maxUint256,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// Reject an already-expired deadline before signing so a direct caller is never walked through a
|
|
70
|
+
// wallet EIP-712 prompt for a SignatureTransfer that Permit2 would revert with `SignatureExpired`.
|
|
71
|
+
// The sibling encodeErc20Permit and the token-requirement resolver enforce the same guard.
|
|
72
|
+
const timestamp = Time.timestamp();
|
|
73
|
+
if (deadline <= timestamp) {
|
|
74
|
+
throw new ExpiredDeadlineError(deadline, timestamp);
|
|
75
|
+
}
|
|
76
|
+
validateRequirementSpender({
|
|
77
|
+
chainId,
|
|
78
|
+
spender,
|
|
79
|
+
allowed: ["vaultBundlesV1", "blueBundlesV1"],
|
|
80
|
+
});
|
|
81
|
+
// getPermit2TransferFromTypedData derives its EIP-712 domain's verifyingContract from
|
|
82
|
+
// getChainAddresses(chainId).permit2. A chain that registers BlueBundlesV1 but no canonical Permit2
|
|
83
|
+
// leaves that undefined, and viem drops the undefined field from the domain — the wallet would then
|
|
84
|
+
// sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
|
|
85
|
+
// this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
|
|
86
|
+
getChainAddress(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
|
|
87
|
+
const action = {
|
|
88
|
+
type: "permit2SignatureTransfer",
|
|
89
|
+
args: { spender, amount, nonce, deadline },
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
action,
|
|
93
|
+
async sign(client, userAddress) {
|
|
94
|
+
const typedData = getPermit2TransferFromTypedData({
|
|
95
|
+
erc20: token,
|
|
96
|
+
allowance: amount,
|
|
97
|
+
spender,
|
|
98
|
+
nonce,
|
|
99
|
+
deadline,
|
|
100
|
+
}, chainId);
|
|
101
|
+
const signature = await signAndVerifyTypedData({
|
|
102
|
+
client,
|
|
103
|
+
userAddress,
|
|
104
|
+
typedData,
|
|
105
|
+
});
|
|
106
|
+
return deepFreeze({
|
|
107
|
+
args: {
|
|
108
|
+
owner: userAddress,
|
|
109
|
+
asset: token,
|
|
110
|
+
amount,
|
|
111
|
+
nonce,
|
|
112
|
+
deadline,
|
|
113
|
+
signature,
|
|
114
|
+
},
|
|
115
|
+
action,
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
};
|
|
@@ -6,7 +6,7 @@ export interface EncodeVaultSharesPermitParams {
|
|
|
6
6
|
readonly vault: Token;
|
|
7
7
|
/** Vault generation, which selects the standard V1 or two-field V2 domain. */
|
|
8
8
|
readonly version: "vaultV1" | "vaultV2";
|
|
9
|
-
/**
|
|
9
|
+
/** Registered fixed vault bundles spender. */
|
|
10
10
|
readonly spender: Address;
|
|
11
11
|
/** Account that owns the vault shares. */
|
|
12
12
|
readonly owner: Address;
|
|
@@ -27,15 +27,15 @@ export interface EncodeVaultSharesPermitParams {
|
|
|
27
27
|
*
|
|
28
28
|
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
29
29
|
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
30
|
-
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
30
|
+
* @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
|
|
31
31
|
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
32
32
|
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
33
33
|
* @param params.nonce - Current vault permit nonce for the owner.
|
|
34
34
|
* @param params.amount - Vault-share allowance to authorize.
|
|
35
35
|
* @param params.deadline - Shared permit and bundle deadline.
|
|
36
|
-
* @returns A requirement whose `sign()` result can be embedded in
|
|
36
|
+
* @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
|
|
37
37
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
38
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
38
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
|
|
39
39
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
40
40
|
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
|
|
41
41
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
@@ -13,15 +13,15 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
|
|
|
13
13
|
*
|
|
14
14
|
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
15
15
|
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
16
|
-
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
16
|
+
* @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
|
|
17
17
|
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
18
18
|
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
19
19
|
* @param params.nonce - Current vault permit nonce for the owner.
|
|
20
20
|
* @param params.amount - Vault-share allowance to authorize.
|
|
21
21
|
* @param params.deadline - Shared permit and bundle deadline.
|
|
22
|
-
* @returns A requirement whose `sign()` result can be embedded in
|
|
22
|
+
* @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
|
|
23
23
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
24
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
24
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
|
|
25
25
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
26
26
|
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
|
|
27
27
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
@@ -76,11 +76,11 @@ export const encodeVaultSharesPermit = (params) => {
|
|
|
76
76
|
extensions: [...inputDomain.extensions],
|
|
77
77
|
}),
|
|
78
78
|
});
|
|
79
|
-
// Bind the permit to the
|
|
79
|
+
// Bind the permit to one of the registered fixed vault bundles deployments.
|
|
80
80
|
validateRequirementSpender({
|
|
81
81
|
chainId,
|
|
82
82
|
spender,
|
|
83
|
-
allowed: ["vaultExitBundlesV1"],
|
|
83
|
+
allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
|
|
84
84
|
});
|
|
85
85
|
const action = {
|
|
86
86
|
type: "permit",
|
|
@@ -88,6 +88,7 @@ export const encodeVaultSharesPermit = (params) => {
|
|
|
88
88
|
spender,
|
|
89
89
|
amount,
|
|
90
90
|
deadline,
|
|
91
|
+
nonce,
|
|
91
92
|
},
|
|
92
93
|
};
|
|
93
94
|
return {
|
|
@@ -2,4 +2,5 @@ export * from "./encodeBlueSignatureAuthorization.js";
|
|
|
2
2
|
export * from "./encodeErc20Approval.js";
|
|
3
3
|
export * from "./encodeErc20Permit.js";
|
|
4
4
|
export * from "./encodeErc20Permit2Approve.js";
|
|
5
|
+
export * from "./encodeErc20Permit2SignatureTransfer.js";
|
|
5
6
|
export * from "./encodeVaultSharesPermit.js";
|
|
@@ -2,4 +2,5 @@ export * from "./encodeBlueSignatureAuthorization.js";
|
|
|
2
2
|
export * from "./encodeErc20Approval.js";
|
|
3
3
|
export * from "./encodeErc20Permit.js";
|
|
4
4
|
export * from "./encodeErc20Permit2Approve.js";
|
|
5
|
+
export * from "./encodeErc20Permit2SignatureTransfer.js";
|
|
5
6
|
export * from "./encodeVaultSharesPermit.js";
|
package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts
CHANGED
|
@@ -34,4 +34,4 @@ export declare const getGeneralAdapterRequirementsPermit: (viemClient: Client, p
|
|
|
34
34
|
};
|
|
35
35
|
nonce: bigint;
|
|
36
36
|
supportDeployless?: boolean;
|
|
37
|
-
}) => Promise<import("../../../index.js").Requirement<import("../../../index.js").
|
|
37
|
+
}) => Promise<import("../../../index.js").Requirement<import("../../../index.js").Erc2612RequirementSignature, undefined>[]>;
|
|
@@ -5,8 +5,8 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
|
|
|
5
5
|
* allowance.
|
|
6
6
|
*
|
|
7
7
|
* The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
|
|
8
|
-
* GeneralAdapter1, Permit2, Midnight, MidnightBundles,
|
|
9
|
-
* configured.
|
|
8
|
+
* GeneralAdapter1, Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and
|
|
9
|
+
* BlueBundlesV1 addresses when configured.
|
|
10
10
|
*
|
|
11
11
|
* Returns an empty array when the allowance already covers `spendAmount`. When the token is in
|
|
12
12
|
* `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
|
|
@@ -18,13 +18,15 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
|
|
|
18
18
|
* and token approval caps.
|
|
19
19
|
* @param params.args.spendAmount - The amount the bundle will actually pull.
|
|
20
20
|
* @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
|
|
21
|
-
* may be `
|
|
21
|
+
* may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
|
|
22
22
|
* @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
|
|
23
|
-
* Permit2, Midnight, MidnightBundles, or
|
|
23
|
+
* Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for
|
|
24
|
+
* `chainId`.
|
|
24
25
|
* @param params.allowances - The user's current allowance of `address` for `spender`.
|
|
25
26
|
* @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
|
|
26
27
|
* followed by the new approval. Empty when no approval is needed.
|
|
27
28
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < spendAmount`.
|
|
29
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
28
30
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
|
|
29
31
|
* @example
|
|
30
32
|
* ```ts
|
|
@@ -7,8 +7,8 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
|
|
|
7
7
|
* allowance.
|
|
8
8
|
*
|
|
9
9
|
* The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
|
|
10
|
-
* GeneralAdapter1, Permit2, Midnight, MidnightBundles,
|
|
11
|
-
* configured.
|
|
10
|
+
* GeneralAdapter1, Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and
|
|
11
|
+
* BlueBundlesV1 addresses when configured.
|
|
12
12
|
*
|
|
13
13
|
* Returns an empty array when the allowance already covers `spendAmount`. When the token is in
|
|
14
14
|
* `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
|
|
@@ -20,13 +20,15 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
|
|
|
20
20
|
* and token approval caps.
|
|
21
21
|
* @param params.args.spendAmount - The amount the bundle will actually pull.
|
|
22
22
|
* @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
|
|
23
|
-
* may be `
|
|
23
|
+
* may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
|
|
24
24
|
* @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
|
|
25
|
-
* Permit2, Midnight, MidnightBundles, or
|
|
25
|
+
* Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for
|
|
26
|
+
* `chainId`.
|
|
26
27
|
* @param params.allowances - The user's current allowance of `address` for `spender`.
|
|
27
28
|
* @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
|
|
28
29
|
* followed by the new approval. Empty when no approval is needed.
|
|
29
30
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < spendAmount`.
|
|
31
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
30
32
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
|
|
31
33
|
* @example
|
|
32
34
|
* ```ts
|
|
@@ -25,6 +25,7 @@ interface GetTokenRequirementActionsParams {
|
|
|
25
25
|
* @returns Bundler `Action`s needed to pull the token.
|
|
26
26
|
* @throws {DepositAssetMismatchError} when the signed asset differs from `asset`.
|
|
27
27
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
|
|
28
|
+
* @throws {UnexpectedRequirementSignatureError} when passed a BlueBundlesV1-only SignatureTransfer result.
|
|
28
29
|
* @throws {Permit2ExpirationMissingError} when `action.type === "permit2"` but `args.expiration` is missing.
|
|
29
30
|
* @example
|
|
30
31
|
* ```ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isAddressEqual } from "viem";
|
|
2
|
-
import { DepositAmountMismatchError, DepositAssetMismatchError, Permit2ExpirationMissingError, } from "../../types/index.js";
|
|
2
|
+
import { DepositAmountMismatchError, DepositAssetMismatchError, isPermit2SignatureTransferSignature, Permit2ExpirationMissingError, UnexpectedRequirementSignatureError, } from "../../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Encodes the bundler actions that pull the asset to `recipient`, optionally consuming a
|
|
5
5
|
* pre-signed permit / permit2 requirement first.
|
|
@@ -18,6 +18,7 @@ import { DepositAmountMismatchError, DepositAssetMismatchError, Permit2Expiratio
|
|
|
18
18
|
* @returns Bundler `Action`s needed to pull the token.
|
|
19
19
|
* @throws {DepositAssetMismatchError} when the signed asset differs from `asset`.
|
|
20
20
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
|
|
21
|
+
* @throws {UnexpectedRequirementSignatureError} when passed a BlueBundlesV1-only SignatureTransfer result.
|
|
21
22
|
* @throws {Permit2ExpirationMissingError} when `action.type === "permit2"` but `args.expiration` is missing.
|
|
22
23
|
* @example
|
|
23
24
|
* ```ts
|
|
@@ -55,6 +56,9 @@ export const getTokenRequirementActions = ({ asset, amount, recipient, requireme
|
|
|
55
56
|
},
|
|
56
57
|
];
|
|
57
58
|
}
|
|
59
|
+
if (isPermit2SignatureTransferSignature(requirementSignature)) {
|
|
60
|
+
throw new UnexpectedRequirementSignatureError("permit2SignatureTransfer");
|
|
61
|
+
}
|
|
58
62
|
if (!isAddressEqual(requirementSignature.args.asset, asset)) {
|
|
59
63
|
throw new DepositAssetMismatchError(asset, requirementSignature.args.asset);
|
|
60
64
|
}
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Address } from "viem";
|
|
2
2
|
import { type PermitRequirementSignature } from "../../types/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/** ECDSA signature `s`, or zero for the empty-permit sentinel. */
|
|
16
|
-
readonly s: Hex;
|
|
17
|
-
}
|
|
18
|
-
/** Parameters for {@link getVaultExitBundlesV1PermitStruct}. */
|
|
3
|
+
import { type BundleSharesPermit } from "../bundles/common.js";
|
|
4
|
+
/**
|
|
5
|
+
* Compatibility alias for the canonical {@link BundleSharesPermit} tuple consumed by VaultExitBundlesV1.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Use {@link BundleSharesPermit}.
|
|
8
|
+
*/
|
|
9
|
+
export type VaultExitBundlesV1PermitStruct = BundleSharesPermit;
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for {@link getVaultExitBundlesV1PermitStruct}.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated Use the parameters of `getBundlesSharesPermit`.
|
|
14
|
+
*/
|
|
19
15
|
export interface GetVaultExitBundlesV1PermitStructParams {
|
|
20
16
|
/** Vault share token authorized by the permit. */
|
|
21
17
|
readonly vault: Address;
|
|
@@ -25,28 +21,24 @@ export interface GetVaultExitBundlesV1PermitStructParams {
|
|
|
25
21
|
readonly requirementSignature?: PermitRequirementSignature;
|
|
26
22
|
}
|
|
27
23
|
/**
|
|
28
|
-
*
|
|
29
|
-
* requirement signature.
|
|
30
|
-
*
|
|
31
|
-
* Without a signature, returns the contract's empty-permit sentinel. With a signature, validates
|
|
32
|
-
* the ERC-2612 kind and vault asset before splitting the serialized signature.
|
|
33
|
-
* Owner, spender, deadline, nonce, and cryptographic validity are verified onchain by the vault.
|
|
24
|
+
* Compatibility wrapper for the former VaultExitBundlesV1-specific permit reshaper.
|
|
34
25
|
*
|
|
35
26
|
* @param params.vault - Vault share token authorized by the permit.
|
|
36
27
|
* @param params.deadline - Bundle deadline used by the empty-permit sentinel.
|
|
37
|
-
* @param params.requirementSignature - Optional signed
|
|
38
|
-
* @returns The
|
|
39
|
-
* @throws {VaultExitBundlesV1PermitMismatchError} when the requirement
|
|
28
|
+
* @param params.requirementSignature - Optional signed ERC-2612 vault-share requirement.
|
|
29
|
+
* @returns The shared bundles share-permit tuple.
|
|
30
|
+
* @throws {VaultExitBundlesV1PermitMismatchError} when the requirement is incompatible.
|
|
31
|
+
* @deprecated Use `getBundlesSharesPermit`; this wrapper preserves the legacy error identity.
|
|
40
32
|
* @example
|
|
41
33
|
* ```ts
|
|
42
34
|
* import { getVaultExitBundlesV1PermitStruct } from "@morpho-org/morpho-sdk";
|
|
35
|
+
* import { zeroAddress } from "viem";
|
|
43
36
|
*
|
|
44
37
|
* const permit = getVaultExitBundlesV1PermitStruct({
|
|
45
|
-
* vault,
|
|
46
|
-
* deadline,
|
|
47
|
-
* requirementSignature,
|
|
38
|
+
* vault: zeroAddress,
|
|
39
|
+
* deadline: 1_900_000_000n,
|
|
48
40
|
* });
|
|
49
|
-
* // permit
|
|
41
|
+
* // permit.value === 0n
|
|
50
42
|
* ```
|
|
51
43
|
*/
|
|
52
44
|
export declare const getVaultExitBundlesV1PermitStruct: (params: GetVaultExitBundlesV1PermitStructParams) => VaultExitBundlesV1PermitStruct;
|