@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
|
@@ -3,27 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.encodeBlueSignatureAuthorization = void 0;
|
|
4
4
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
6
7
|
const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
|
|
7
8
|
const index_js_1 = require("../../../types/index.js");
|
|
8
9
|
/**
|
|
9
10
|
* Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
|
|
10
|
-
* Morpho on the signer's behalf through `setAuthorizationWithSig
|
|
11
|
-
*
|
|
11
|
+
* Morpho on the signer's behalf. Bundler3 consumes the result through `setAuthorizationWithSig`;
|
|
12
|
+
* BlueBundlesV1 embeds the same signed authorization in its direct-call struct.
|
|
12
13
|
*
|
|
13
14
|
* The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
|
|
14
15
|
* typed data, verifies it against the connected account, and returns a deep-frozen
|
|
15
|
-
* `RequirementSignature` the
|
|
16
|
-
* `Time.timestamp()`.
|
|
16
|
+
* `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
|
|
17
|
+
* from `Time.timestamp()`.
|
|
17
18
|
*
|
|
18
19
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
19
20
|
* @param params - Authorization encoding parameters.
|
|
20
|
-
* @param params.authorized -
|
|
21
|
+
* @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
|
|
21
22
|
* @param params.chainId - Target chain id.
|
|
22
23
|
* @param params.nonce - The signer's current Morpho authorization nonce.
|
|
23
24
|
* @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
|
|
24
25
|
* @param params.deadline - Optional signature deadline in seconds.
|
|
25
26
|
* @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
|
|
26
27
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
28
|
+
* @throws {NonPositiveInputError} when a provided `deadline` is not positive.
|
|
29
|
+
* @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
|
|
30
|
+
* @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
|
|
27
31
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
28
32
|
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
29
33
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
@@ -47,6 +51,27 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
|
|
|
47
51
|
if (viemClient.chain?.id !== chainId) {
|
|
48
52
|
throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
49
53
|
}
|
|
54
|
+
// Reject an invalid or already-expired caller-supplied deadline before signing, so a direct caller
|
|
55
|
+
// is never walked through a wallet EIP-712 prompt for an authorization Morpho would reject with
|
|
56
|
+
// `SIGNATURE_EXPIRED`. Mirrors the sibling `encodeErc20Permit2SignatureTransfer` and the
|
|
57
|
+
// `getBlueAuthorizationRequirement` resolver guards. An omitted deadline defaults to two hours
|
|
58
|
+
// from now and is always valid.
|
|
59
|
+
if (params.deadline != null) {
|
|
60
|
+
if (params.deadline <= 0n) {
|
|
61
|
+
throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
|
|
62
|
+
}
|
|
63
|
+
if (params.deadline > viem_1.maxUint256) {
|
|
64
|
+
throw new index_js_1.InputExceedsMaxError({
|
|
65
|
+
field: "deadline",
|
|
66
|
+
value: params.deadline,
|
|
67
|
+
max: viem_1.maxUint256,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const timestamp = morpho_ts_1.Time.timestamp();
|
|
71
|
+
if (params.deadline <= timestamp) {
|
|
72
|
+
throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
50
75
|
const deadline = params.deadline ?? morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(2n);
|
|
51
76
|
const action = {
|
|
52
77
|
type: "authorization",
|
|
@@ -16,10 +16,11 @@ interface EncodeErc20ApprovalParams {
|
|
|
16
16
|
* @param params - Encoding parameters.
|
|
17
17
|
* @param params.token - ERC-20 token address to approve.
|
|
18
18
|
* @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
|
|
19
|
-
* Midnight, MidnightBundles, or
|
|
19
|
+
* Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
20
20
|
* @param params.amount - Allowance amount before per-token cap.
|
|
21
21
|
* @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
|
|
22
22
|
* @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
|
|
23
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
23
24
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
|
|
24
25
|
* @example
|
|
25
26
|
* ```ts
|
|
@@ -15,10 +15,11 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
|
|
|
15
15
|
* @param params - Encoding parameters.
|
|
16
16
|
* @param params.token - ERC-20 token address to approve.
|
|
17
17
|
* @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
|
|
18
|
-
* Midnight, MidnightBundles, or
|
|
18
|
+
* Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
19
19
|
* @param params.amount - Allowance amount before per-token cap.
|
|
20
20
|
* @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
|
|
21
21
|
* @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
|
|
22
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
22
23
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
|
|
23
24
|
* @example
|
|
24
25
|
* ```ts
|
|
@@ -45,9 +46,14 @@ const encodeErc20Approval = (params) => {
|
|
|
45
46
|
"midnight",
|
|
46
47
|
"midnightBundles",
|
|
47
48
|
"vaultExitBundlesV1",
|
|
49
|
+
"vaultBundlesV1",
|
|
50
|
+
"blueBundlesV1",
|
|
48
51
|
],
|
|
49
52
|
});
|
|
50
|
-
const amountValue = blue_sdk_1.MathLib.min(amount,
|
|
53
|
+
const amountValue = blue_sdk_1.MathLib.min(amount,
|
|
54
|
+
// Checksum the lookup key so a differently-cased token still resolves its per-token cap
|
|
55
|
+
// instead of falling back to `maxUint256`, which UNI/ONDO/COMP/FLUID reject above `uint96`.
|
|
56
|
+
constant_js_1.MAX_TOKEN_APPROVALS[chainId]?.[(0, viem_1.getAddress)(token)] ?? viem_1.maxUint256);
|
|
51
57
|
return (0, morpho_ts_1.deepFreeze)({
|
|
52
58
|
to: token,
|
|
53
59
|
data: (0, viem_1.encodeFunctionData)({
|
|
@@ -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 {};
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.encodeErc20Permit = void 0;
|
|
4
4
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
6
7
|
const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
|
|
7
8
|
const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
|
|
8
9
|
const index_js_1 = require("../../../types/index.js");
|
|
@@ -12,20 +13,28 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
12
13
|
*
|
|
13
14
|
* Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
|
|
14
15
|
* signature, verifies it against the connected account, and returns a `RequirementSignature`
|
|
15
|
-
* the
|
|
16
|
+
* the selected transaction route can consume. Deadline defaults to two hours from
|
|
17
|
+
* `Time.timestamp()`.
|
|
16
18
|
*
|
|
17
19
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
18
20
|
* @param params - Permit encoding parameters.
|
|
19
21
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
20
|
-
* @param params.spender - Permit spender. Must be GeneralAdapter1
|
|
22
|
+
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
23
|
+
* VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
21
24
|
* @param params.amount - Permit allowance amount.
|
|
22
25
|
* @param params.chainId - Target chain id.
|
|
23
26
|
* @param params.nonce - The user's current EIP-2612 nonce on `token`.
|
|
24
27
|
* @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
|
|
28
|
+
* @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
|
|
25
29
|
* @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
|
|
26
30
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
27
|
-
* @throws {
|
|
28
|
-
*
|
|
31
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
32
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
|
|
33
|
+
* MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
|
|
34
|
+
* @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
|
|
35
|
+
* @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
|
|
36
|
+
* @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
|
|
37
|
+
* @throws {viem.BaseError} when the token metadata read fails with no fallback left.
|
|
29
38
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
30
39
|
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
31
40
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
@@ -54,10 +63,33 @@ const encodeErc20Permit = async (viemClient, params) => {
|
|
|
54
63
|
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
55
64
|
chainId,
|
|
56
65
|
spender,
|
|
57
|
-
allowed: [
|
|
66
|
+
allowed: [
|
|
67
|
+
"generalAdapter1",
|
|
68
|
+
"midnightBundles",
|
|
69
|
+
"vaultBundlesV1",
|
|
70
|
+
"blueBundlesV1",
|
|
71
|
+
],
|
|
58
72
|
});
|
|
59
73
|
const now = morpho_ts_1.Time.timestamp();
|
|
60
|
-
|
|
74
|
+
// Validate an explicit deadline before the token-metadata read: this exported encoder can be
|
|
75
|
+
// called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
|
|
76
|
+
// deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
|
|
77
|
+
if (params.deadline != null) {
|
|
78
|
+
if (params.deadline <= 0n) {
|
|
79
|
+
throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
|
|
80
|
+
}
|
|
81
|
+
if (params.deadline > viem_1.maxUint256) {
|
|
82
|
+
throw new index_js_1.InputExceedsMaxError({
|
|
83
|
+
field: "deadline",
|
|
84
|
+
value: params.deadline,
|
|
85
|
+
max: viem_1.maxUint256,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (params.deadline <= now) {
|
|
89
|
+
throw new index_js_1.ExpiredDeadlineError(params.deadline, now);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const deadline = params.deadline ?? now + morpho_ts_1.Time.s.from.h(2n);
|
|
61
93
|
const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient, {
|
|
62
94
|
deployless: supportDeployless,
|
|
63
95
|
});
|
|
@@ -67,6 +99,7 @@ const encodeErc20Permit = async (viemClient, params) => {
|
|
|
67
99
|
spender,
|
|
68
100
|
amount,
|
|
69
101
|
deadline,
|
|
102
|
+
nonce,
|
|
70
103
|
},
|
|
71
104
|
};
|
|
72
105
|
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,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeErc20Permit2SignatureTransfer = void 0;
|
|
4
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
|
|
8
|
+
const validate_js_1 = require("../../../helpers/validate.js");
|
|
9
|
+
const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
|
|
10
|
+
const index_js_1 = require("../../../types/index.js");
|
|
11
|
+
/**
|
|
12
|
+
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
13
|
+
*
|
|
14
|
+
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
15
|
+
* it has no managed allowance expiration.
|
|
16
|
+
*
|
|
17
|
+
* @param params - SignatureTransfer parameters.
|
|
18
|
+
* @param params.token - ERC-20 token pulled through Permit2.
|
|
19
|
+
* @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
|
|
20
|
+
* @param params.amount - Exact `uint256` token amount authorized.
|
|
21
|
+
* @param params.chainId - Target chain id.
|
|
22
|
+
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
23
|
+
* @param params.deadline - Signature expiration timestamp in seconds.
|
|
24
|
+
* @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
|
|
25
|
+
* @throws {NegativeInputError} when `amount` or `nonce` is negative.
|
|
26
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
27
|
+
* @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
|
|
28
|
+
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
29
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
30
|
+
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
31
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
|
|
32
|
+
* @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
|
|
33
|
+
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
|
|
34
|
+
* @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
|
|
35
|
+
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
39
|
+
* import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
|
|
40
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
41
|
+
* import { mainnet } from "viem/chains";
|
|
42
|
+
*
|
|
43
|
+
* const requirement = encodeErc20Permit2SignatureTransfer({
|
|
44
|
+
* token: addressesRegistry[mainnet.id].usdc,
|
|
45
|
+
* spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
|
|
46
|
+
* amount: 1_000_000n,
|
|
47
|
+
* chainId: mainnet.id,
|
|
48
|
+
* nonce: 0n,
|
|
49
|
+
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
50
|
+
* });
|
|
51
|
+
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
const encodeErc20Permit2SignatureTransfer = (params) => {
|
|
55
|
+
const { token, spender, amount, chainId, nonce, deadline } = params;
|
|
56
|
+
// Bound every uint256 field before signing: getPermit2TransferFromTypedData silently clamps an
|
|
57
|
+
// oversized allowance to maxUint256, which would desync the signed value from the requirement
|
|
58
|
+
// metadata that blueSupply verifies. Direct callers bypass the token-requirement resolver, so
|
|
59
|
+
// this public encoder must reject the same out-of-range inputs itself.
|
|
60
|
+
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
61
|
+
(0, validate_js_1.validateUint256Field)("nonce", nonce);
|
|
62
|
+
if (deadline <= 0n) {
|
|
63
|
+
throw new index_js_1.NonPositiveInputError("deadline", deadline);
|
|
64
|
+
}
|
|
65
|
+
if (deadline > viem_1.maxUint256) {
|
|
66
|
+
throw new index_js_1.InputExceedsMaxError({
|
|
67
|
+
field: "deadline",
|
|
68
|
+
value: deadline,
|
|
69
|
+
max: viem_1.maxUint256,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Reject an already-expired deadline before signing so a direct caller is never walked through a
|
|
73
|
+
// wallet EIP-712 prompt for a SignatureTransfer that Permit2 would revert with `SignatureExpired`.
|
|
74
|
+
// The sibling encodeErc20Permit and the token-requirement resolver enforce the same guard.
|
|
75
|
+
const timestamp = morpho_ts_1.Time.timestamp();
|
|
76
|
+
if (deadline <= timestamp) {
|
|
77
|
+
throw new index_js_1.ExpiredDeadlineError(deadline, timestamp);
|
|
78
|
+
}
|
|
79
|
+
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
80
|
+
chainId,
|
|
81
|
+
spender,
|
|
82
|
+
allowed: ["vaultBundlesV1", "blueBundlesV1"],
|
|
83
|
+
});
|
|
84
|
+
// getPermit2TransferFromTypedData derives its EIP-712 domain's verifyingContract from
|
|
85
|
+
// getChainAddresses(chainId).permit2. A chain that registers BlueBundlesV1 but no canonical Permit2
|
|
86
|
+
// leaves that undefined, and viem drops the undefined field from the domain — the wallet would then
|
|
87
|
+
// sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
|
|
88
|
+
// this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
|
|
89
|
+
(0, morpho_ts_1.getChainAddress)(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
|
|
90
|
+
const action = {
|
|
91
|
+
type: "permit2SignatureTransfer",
|
|
92
|
+
args: { spender, amount, nonce, deadline },
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
action,
|
|
96
|
+
async sign(client, userAddress) {
|
|
97
|
+
const typedData = (0, blue_sdk_viem_1.getPermit2TransferFromTypedData)({
|
|
98
|
+
erc20: token,
|
|
99
|
+
allowance: amount,
|
|
100
|
+
spender,
|
|
101
|
+
nonce,
|
|
102
|
+
deadline,
|
|
103
|
+
}, chainId);
|
|
104
|
+
const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
|
|
105
|
+
client,
|
|
106
|
+
userAddress,
|
|
107
|
+
typedData,
|
|
108
|
+
});
|
|
109
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
110
|
+
args: {
|
|
111
|
+
owner: userAddress,
|
|
112
|
+
asset: token,
|
|
113
|
+
amount,
|
|
114
|
+
nonce,
|
|
115
|
+
deadline,
|
|
116
|
+
signature,
|
|
117
|
+
},
|
|
118
|
+
action,
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
exports.encodeErc20Permit2SignatureTransfer = encodeErc20Permit2SignatureTransfer;
|
|
@@ -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.
|
|
@@ -16,15 +16,15 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
|
|
|
16
16
|
*
|
|
17
17
|
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
18
18
|
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
19
|
-
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
19
|
+
* @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
|
|
20
20
|
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
21
21
|
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
22
22
|
* @param params.nonce - Current vault permit nonce for the owner.
|
|
23
23
|
* @param params.amount - Vault-share allowance to authorize.
|
|
24
24
|
* @param params.deadline - Shared permit and bundle deadline.
|
|
25
|
-
* @returns A requirement whose `sign()` result can be embedded in
|
|
25
|
+
* @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
|
|
26
26
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
27
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
27
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
|
|
28
28
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
29
29
|
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
|
|
30
30
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
@@ -79,11 +79,11 @@ const encodeVaultSharesPermit = (params) => {
|
|
|
79
79
|
extensions: [...inputDomain.extensions],
|
|
80
80
|
}),
|
|
81
81
|
});
|
|
82
|
-
// Bind the permit to the
|
|
82
|
+
// Bind the permit to one of the registered fixed vault bundles deployments.
|
|
83
83
|
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
84
84
|
chainId,
|
|
85
85
|
spender,
|
|
86
|
-
allowed: ["vaultExitBundlesV1"],
|
|
86
|
+
allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
|
|
87
87
|
});
|
|
88
88
|
const action = {
|
|
89
89
|
type: "permit",
|
|
@@ -91,6 +91,7 @@ const encodeVaultSharesPermit = (params) => {
|
|
|
91
91
|
spender,
|
|
92
92
|
amount,
|
|
93
93
|
deadline,
|
|
94
|
+
nonce,
|
|
94
95
|
},
|
|
95
96
|
};
|
|
96
97
|
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";
|
|
@@ -18,4 +18,5 @@ __exportStar(require("./encodeBlueSignatureAuthorization.js"), exports);
|
|
|
18
18
|
__exportStar(require("./encodeErc20Approval.js"), exports);
|
|
19
19
|
__exportStar(require("./encodeErc20Permit.js"), exports);
|
|
20
20
|
__exportStar(require("./encodeErc20Permit2Approve.js"), exports);
|
|
21
|
+
__exportStar(require("./encodeErc20Permit2SignatureTransfer.js"), exports);
|
|
21
22
|
__exportStar(require("./encodeVaultSharesPermit.js"), exports);
|
package/lib/cjs/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
|
|
@@ -10,8 +10,8 @@ const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
|
|
|
10
10
|
* allowance.
|
|
11
11
|
*
|
|
12
12
|
* The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
|
|
13
|
-
* GeneralAdapter1, Permit2, Midnight, MidnightBundles,
|
|
14
|
-
* configured.
|
|
13
|
+
* GeneralAdapter1, Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and
|
|
14
|
+
* BlueBundlesV1 addresses when configured.
|
|
15
15
|
*
|
|
16
16
|
* Returns an empty array when the allowance already covers `spendAmount`. When the token is in
|
|
17
17
|
* `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
|
|
@@ -23,13 +23,15 @@ const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
|
|
|
23
23
|
* and token approval caps.
|
|
24
24
|
* @param params.args.spendAmount - The amount the bundle will actually pull.
|
|
25
25
|
* @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
|
|
26
|
-
* may be `
|
|
26
|
+
* may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
|
|
27
27
|
* @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
|
|
28
|
-
* Permit2, Midnight, MidnightBundles, or
|
|
28
|
+
* Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for
|
|
29
|
+
* `chainId`.
|
|
29
30
|
* @param params.allowances - The user's current allowance of `address` for `spender`.
|
|
30
31
|
* @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
|
|
31
32
|
* followed by the new approval. Empty when no approval is needed.
|
|
32
33
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < spendAmount`.
|
|
34
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
33
35
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
|
|
34
36
|
* @example
|
|
35
37
|
* ```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
|
|
@@ -21,6 +21,7 @@ const index_js_1 = require("../../types/index.js");
|
|
|
21
21
|
* @returns Bundler `Action`s needed to pull the token.
|
|
22
22
|
* @throws {DepositAssetMismatchError} when the signed asset differs from `asset`.
|
|
23
23
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
|
|
24
|
+
* @throws {UnexpectedRequirementSignatureError} when passed a BlueBundlesV1-only SignatureTransfer result.
|
|
24
25
|
* @throws {Permit2ExpirationMissingError} when `action.type === "permit2"` but `args.expiration` is missing.
|
|
25
26
|
* @example
|
|
26
27
|
* ```ts
|
|
@@ -58,6 +59,9 @@ const getTokenRequirementActions = ({ asset, amount, recipient, requirementSigna
|
|
|
58
59
|
},
|
|
59
60
|
];
|
|
60
61
|
}
|
|
62
|
+
if ((0, index_js_1.isPermit2SignatureTransferSignature)(requirementSignature)) {
|
|
63
|
+
throw new index_js_1.UnexpectedRequirementSignatureError("permit2SignatureTransfer");
|
|
64
|
+
}
|
|
61
65
|
if (!(0, viem_1.isAddressEqual)(requirementSignature.args.asset, asset)) {
|
|
62
66
|
throw new index_js_1.DepositAssetMismatchError(asset, requirementSignature.args.asset);
|
|
63
67
|
}
|