@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v5-to-v6.md +329 -15
- package/README.md +93 -47
- package/lib/cjs/abis.d.ts +227 -2
- package/lib/cjs/abis.js +156 -3
- package/lib/cjs/actions/blue/borrow.d.ts +1 -1
- package/lib/cjs/actions/blue/borrow.js +1 -1
- package/lib/cjs/actions/blue/common.d.ts +6 -19
- package/lib/cjs/actions/blue/common.js +28 -162
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +1 -1
- package/lib/cjs/actions/blue/repay.d.ts +3 -3
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/blue/supply.d.ts +3 -3
- package/lib/cjs/actions/blue/supply.js +3 -8
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
- package/lib/cjs/actions/blue/withdraw.js +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
- package/lib/cjs/actions/bundles/common.d.ts +230 -0
- package/lib/cjs/actions/bundles/common.js +507 -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 +1 -0
- 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 +3 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -2
- package/lib/cjs/actions/requirements/blue/index.js +0 -2
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +43 -31
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +27 -22
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/index.js +1 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +20 -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/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
- 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/forceWithdraw.d.ts +58 -39
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/cjs/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/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/cjs/blue/abis.d.ts +5 -1
- package/lib/cjs/blue/abis.js +2 -0
- package/lib/cjs/blue/entities.d.ts +8 -2
- package/lib/cjs/blue/entities.js +1 -0
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +3 -1
- package/lib/cjs/blue/fetch.js +1 -0
- package/lib/cjs/entities/blue/blue.d.ts +29 -20
- package/lib/cjs/entities/blue/blue.js +6 -1
- package/lib/cjs/entities/index.d.ts +9 -2
- package/lib/cjs/entities/index.js +16 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +76 -75
- package/lib/{esm/actions/requirements/blue → cjs/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
- 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 +2 -0
- package/lib/cjs/entities/requirements/index.js +18 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +356 -101
- package/lib/cjs/entities/vaultV1/vaultV1.js +334 -120
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +359 -100
- package/lib/cjs/entities/vaultV2/vaultV2.js +448 -93
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +3 -2
- package/lib/cjs/fetch.d.ts +3 -1
- package/lib/cjs/fetch.js +1 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +14 -1
- package/lib/cjs/helpers/metadata.d.ts +3 -5
- package/lib/cjs/helpers/metadata.js +4 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/cjs/helpers/referralFee.d.ts +21 -0
- package/lib/cjs/helpers/referralFee.js +35 -0
- package/lib/cjs/helpers/slippage.d.ts +136 -1
- package/lib/cjs/helpers/slippage.js +188 -0
- package/lib/cjs/helpers/validate.d.ts +67 -8
- package/lib/cjs/helpers/validate.js +94 -9
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/types/action.d.ts +273 -82
- package/lib/cjs/types/action.js +12 -12
- package/lib/cjs/types/error.d.ts +349 -23
- package/lib/cjs/types/error.js +393 -39
- package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
- package/lib/cjs/utils.d.ts +3 -1
- package/lib/cjs/utils.js +10 -1
- package/lib/esm/abis.d.ts +227 -2
- package/lib/esm/abis.js +157 -2
- package/lib/esm/actions/blue/borrow.d.ts +1 -1
- package/lib/esm/actions/blue/borrow.js +1 -1
- package/lib/esm/actions/blue/common.d.ts +6 -19
- package/lib/esm/actions/blue/common.js +30 -164
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +1 -1
- package/lib/esm/actions/blue/repay.d.ts +3 -3
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/blue/supply.d.ts +3 -3
- package/lib/esm/actions/blue/supply.js +5 -10
- package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateral.js +1 -1
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -1
- package/lib/esm/actions/blue/withdraw.js +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +230 -0
- package/lib/esm/actions/bundles/common.js +494 -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 +1 -0
- 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 +3 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -2
- package/lib/esm/actions/requirements/blue/index.js +0 -2
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +22 -22
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +44 -32
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +25 -20
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/index.js +1 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +21 -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/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
- 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/forceWithdraw.d.ts +58 -39
- package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/esm/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/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
- package/lib/esm/blue/abis.d.ts +5 -1
- package/lib/esm/blue/abis.js +5 -1
- package/lib/esm/blue/entities.d.ts +8 -2
- package/lib/esm/blue/entities.js +3 -1
- package/lib/esm/blue/errors.d.ts +1 -1
- package/lib/esm/blue/errors.js +1 -1
- package/lib/esm/blue/fetch.d.ts +3 -1
- package/lib/esm/blue/fetch.js +3 -1
- package/lib/esm/entities/blue/blue.d.ts +29 -20
- package/lib/esm/entities/blue/blue.js +7 -2
- package/lib/esm/entities/index.d.ts +9 -2
- package/lib/esm/entities/index.js +4 -1
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +67 -66
- package/lib/{cjs/actions/requirements/blue → esm/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
- 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 +2 -0
- package/lib/esm/entities/requirements/index.js +2 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +356 -101
- package/lib/esm/entities/vaultV1/vaultV1.js +338 -124
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +359 -100
- package/lib/esm/entities/vaultV2/vaultV2.js +452 -97
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/fetch.d.ts +3 -1
- package/lib/esm/fetch.js +3 -1
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- package/lib/esm/helpers/metadata.d.ts +3 -5
- package/lib/esm/helpers/metadata.js +4 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/esm/helpers/referralFee.d.ts +21 -0
- package/lib/esm/helpers/referralFee.js +31 -0
- package/lib/esm/helpers/slippage.d.ts +136 -1
- package/lib/esm/helpers/slippage.js +186 -2
- package/lib/esm/helpers/validate.d.ts +67 -8
- package/lib/esm/helpers/validate.js +92 -10
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +273 -82
- package/lib/esm/types/action.js +11 -11
- package/lib/esm/types/error.d.ts +349 -23
- package/lib/esm/types/error.js +377 -31
- package/lib/esm/types/sharedLiquidity.d.ts +2 -2
- package/lib/esm/utils.d.ts +3 -1
- package/lib/esm/utils.js +3 -1
- package/package.json +7 -7
|
@@ -1,39 +1,43 @@
|
|
|
1
1
|
import { fetchToken, getPermitTypedData } from "@morpho-org/blue-sdk-viem";
|
|
2
2
|
import { deepFreeze, Time } from "@morpho-org/morpho-ts";
|
|
3
|
-
import { maxUint256 } from "viem";
|
|
4
3
|
import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
|
|
4
|
+
import { validateDeadline, validateUserAddress, } from "../../../helpers/validate.js";
|
|
5
5
|
import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
|
|
6
|
-
import { ChainIdMismatchError, ExpiredDeadlineError,
|
|
6
|
+
import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
|
|
9
9
|
* `amount` of `token`.
|
|
10
10
|
*
|
|
11
11
|
* Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
|
|
12
12
|
* signature, verifies it against the connected account, and returns a `RequirementSignature`
|
|
13
|
-
* the selected transaction route can consume.
|
|
14
|
-
*
|
|
13
|
+
* the selected transaction route can consume. The requirement's `action.typedData` holds that
|
|
14
|
+
* EIP-712 payload so it can be inspected or displayed before signing. Deadline defaults to two
|
|
15
|
+
* hours from `Time.timestamp()`.
|
|
15
16
|
*
|
|
16
17
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
17
18
|
* @param params - Permit encoding parameters.
|
|
18
19
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
19
|
-
* @param params.
|
|
20
|
-
*
|
|
20
|
+
* @param params.owner - Account that owns the tokens and signs the permit.
|
|
21
|
+
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
22
|
+
* VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
21
23
|
* @param params.amount - Permit allowance amount.
|
|
22
24
|
* @param params.chainId - Target chain id.
|
|
23
|
-
* @param params.nonce - The
|
|
25
|
+
* @param params.nonce - The owner's current EIP-2612 nonce on `token`.
|
|
24
26
|
* @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
|
|
25
27
|
* @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
|
|
26
|
-
* @returns A `Requirement` whose `
|
|
28
|
+
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
29
|
+
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
27
30
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
28
31
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
29
32
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
|
|
30
|
-
* MidnightBundles, or BlueBundlesV1 for `chainId`.
|
|
33
|
+
* MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
|
|
31
34
|
* @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
|
|
32
35
|
* @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
|
|
33
36
|
* @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
|
|
34
37
|
* @throws {viem.BaseError} when the token metadata read fails with no fallback left.
|
|
35
38
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
36
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
39
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
40
|
+
* client account differs from `userAddress`.
|
|
37
41
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
38
42
|
* @example
|
|
39
43
|
* ```ts
|
|
@@ -44,39 +48,38 @@ import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPo
|
|
|
44
48
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
45
49
|
* const requirement = await encodeErc20Permit(client, {
|
|
46
50
|
* token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
|
|
51
|
+
* owner,
|
|
47
52
|
* spender: generalAdapter1,
|
|
48
53
|
* amount: 1_000_000n,
|
|
49
54
|
* chainId: 1,
|
|
50
55
|
* nonce: 0n,
|
|
51
56
|
* });
|
|
52
|
-
* //
|
|
57
|
+
* // Inspect the EIP-712 payload, then sign via the requirement:
|
|
58
|
+
* const typedData = requirement.action.typedData;
|
|
59
|
+
* const signed = await requirement.sign(client, owner);
|
|
53
60
|
* ```
|
|
54
61
|
*/
|
|
55
62
|
export const encodeErc20Permit = async (viemClient, params) => {
|
|
56
|
-
const { token, spender, amount, chainId, nonce, supportDeployless } = params;
|
|
63
|
+
const { token, owner, spender, amount, chainId, nonce, supportDeployless } = params;
|
|
57
64
|
if (viemClient.chain?.id !== chainId) {
|
|
58
65
|
throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
59
66
|
}
|
|
60
67
|
validateRequirementSpender({
|
|
61
68
|
chainId,
|
|
62
69
|
spender,
|
|
63
|
-
allowed: [
|
|
70
|
+
allowed: [
|
|
71
|
+
"generalAdapter1",
|
|
72
|
+
"midnightBundles",
|
|
73
|
+
"vaultBundlesV1",
|
|
74
|
+
"blueBundlesV1",
|
|
75
|
+
],
|
|
64
76
|
});
|
|
65
77
|
const now = Time.timestamp();
|
|
66
78
|
// Validate an explicit deadline before the token-metadata read: this exported encoder can be
|
|
67
79
|
// called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
|
|
68
80
|
// deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
|
|
69
81
|
if (params.deadline != null) {
|
|
70
|
-
|
|
71
|
-
throw new NonPositiveInputError("deadline", params.deadline);
|
|
72
|
-
}
|
|
73
|
-
if (params.deadline > maxUint256) {
|
|
74
|
-
throw new InputExceedsMaxError({
|
|
75
|
-
field: "deadline",
|
|
76
|
-
value: params.deadline,
|
|
77
|
-
max: maxUint256,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
82
|
+
validateDeadline(params.deadline);
|
|
80
83
|
if (params.deadline <= now) {
|
|
81
84
|
throw new ExpiredDeadlineError(params.deadline, now);
|
|
82
85
|
}
|
|
@@ -85,25 +88,34 @@ export const encodeErc20Permit = async (viemClient, params) => {
|
|
|
85
88
|
const tokenData = await fetchToken(token, viemClient, {
|
|
86
89
|
deployless: supportDeployless,
|
|
87
90
|
});
|
|
91
|
+
const permitTypedData = getPermitTypedData({
|
|
92
|
+
erc20: tokenData,
|
|
93
|
+
owner,
|
|
94
|
+
spender,
|
|
95
|
+
allowance: amount,
|
|
96
|
+
nonce,
|
|
97
|
+
deadline,
|
|
98
|
+
}, chainId);
|
|
99
|
+
const typedData = deepFreeze({
|
|
100
|
+
...permitTypedData,
|
|
101
|
+
domain: { ...permitTypedData.domain },
|
|
102
|
+
});
|
|
88
103
|
const action = {
|
|
89
104
|
type: "permit",
|
|
90
105
|
args: {
|
|
91
106
|
spender,
|
|
92
107
|
amount,
|
|
93
108
|
deadline,
|
|
109
|
+
nonce,
|
|
94
110
|
},
|
|
111
|
+
typedData,
|
|
95
112
|
};
|
|
96
113
|
return {
|
|
97
114
|
action,
|
|
98
115
|
async sign(client, userAddress) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
spender,
|
|
103
|
-
allowance: amount,
|
|
104
|
-
nonce,
|
|
105
|
-
deadline,
|
|
106
|
-
}, chainId);
|
|
116
|
+
// The permit's owner is fixed at build time (the fetched nonce is owner-specific), so a
|
|
117
|
+
// different signer cannot produce a valid signature for it.
|
|
118
|
+
validateUserAddress(userAddress, owner);
|
|
107
119
|
const signature = await signAndVerifyTypedData({
|
|
108
120
|
client,
|
|
109
121
|
userAddress,
|
|
@@ -111,7 +123,7 @@ export const encodeErc20Permit = async (viemClient, params) => {
|
|
|
111
123
|
});
|
|
112
124
|
return deepFreeze({
|
|
113
125
|
args: {
|
|
114
|
-
owner
|
|
126
|
+
owner,
|
|
115
127
|
signature,
|
|
116
128
|
deadline,
|
|
117
129
|
amount,
|
|
@@ -12,7 +12,8 @@ interface EncodeErc20Permit2ApproveParams {
|
|
|
12
12
|
* Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
|
|
13
13
|
* via the Permit2 contract.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
15
|
+
* The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
|
|
16
|
+
* displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
|
|
16
17
|
*
|
|
17
18
|
* @param params - Permit2 encoding parameters.
|
|
18
19
|
* @param params.token - ERC-20 token address.
|
|
@@ -20,7 +21,8 @@ interface EncodeErc20Permit2ApproveParams {
|
|
|
20
21
|
* @param params.chainId - Target chain id.
|
|
21
22
|
* @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
|
|
22
23
|
* @param params.expiration - Permit2-managed allowance expiration timestamp.
|
|
23
|
-
* @returns A `Requirement` whose `
|
|
24
|
+
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
25
|
+
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
24
26
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
25
27
|
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
26
28
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
@@ -6,7 +6,8 @@ import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.
|
|
|
6
6
|
* Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
|
|
7
7
|
* via the Permit2 contract.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
|
|
10
|
+
* displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
|
|
10
11
|
*
|
|
11
12
|
* @param params - Permit2 encoding parameters.
|
|
12
13
|
* @param params.token - ERC-20 token address.
|
|
@@ -14,7 +15,8 @@ import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.
|
|
|
14
15
|
* @param params.chainId - Target chain id.
|
|
15
16
|
* @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
|
|
16
17
|
* @param params.expiration - Permit2-managed allowance expiration timestamp.
|
|
17
|
-
* @returns A `Requirement` whose `
|
|
18
|
+
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
19
|
+
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
18
20
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
19
21
|
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
20
22
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
@@ -37,6 +39,16 @@ export const encodeErc20Permit2Approve = (params) => {
|
|
|
37
39
|
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
38
40
|
const now = Time.timestamp();
|
|
39
41
|
const deadline = now + Time.s.from.h(2n);
|
|
42
|
+
// Permit2 AllowanceTransfer signs over `PermitSingle` (token, spender, expiration, nonce), which
|
|
43
|
+
// does not include the owner, so the payload is fully determined at build time.
|
|
44
|
+
const typedData = deepFreeze(getPermit2PermitTypedData({
|
|
45
|
+
spender: generalAdapter1,
|
|
46
|
+
allowance: amount,
|
|
47
|
+
erc20: token,
|
|
48
|
+
nonce: Number(nonce),
|
|
49
|
+
deadline,
|
|
50
|
+
expiration: Number(expiration),
|
|
51
|
+
}, chainId));
|
|
40
52
|
const action = {
|
|
41
53
|
type: "permit2",
|
|
42
54
|
args: {
|
|
@@ -45,18 +57,11 @@ export const encodeErc20Permit2Approve = (params) => {
|
|
|
45
57
|
deadline,
|
|
46
58
|
expiration,
|
|
47
59
|
},
|
|
60
|
+
typedData,
|
|
48
61
|
};
|
|
49
62
|
return {
|
|
50
63
|
action,
|
|
51
64
|
async sign(client, userAddress) {
|
|
52
|
-
const typedData = getPermit2PermitTypedData({
|
|
53
|
-
spender: generalAdapter1,
|
|
54
|
-
allowance: amount,
|
|
55
|
-
erc20: token,
|
|
56
|
-
nonce: Number(nonce),
|
|
57
|
-
deadline,
|
|
58
|
-
expiration: Number(expiration),
|
|
59
|
-
}, chainId);
|
|
60
65
|
const signature = await signAndVerifyTypedData({
|
|
61
66
|
client,
|
|
62
67
|
userAddress,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Address } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { type
|
|
3
|
-
/** Parameters for {@link
|
|
4
|
-
export interface
|
|
2
|
+
import { type Permit2SignatureTransferRequirementSignature, type Requirement } from "../../../types/index.js";
|
|
3
|
+
/** Parameters for {@link encodeErc20Permit2SignatureTransfer}. */
|
|
4
|
+
export interface EncodeErc20Permit2SignatureTransferParams {
|
|
5
5
|
/** ERC-20 token pulled through Permit2. */
|
|
6
6
|
readonly token: Address;
|
|
7
|
-
/**
|
|
7
|
+
/** Registered fixed bundles deployment receiving permission to pull the token. */
|
|
8
8
|
readonly spender: Address;
|
|
9
9
|
/** Exact token amount authorized by the one-time transfer. */
|
|
10
10
|
readonly amount: bigint;
|
|
@@ -16,26 +16,28 @@ export interface EncodeErc20Permit2TransferFromParams {
|
|
|
16
16
|
readonly deadline: bigint;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Builds a Permit2 SignatureTransfer requirement for a direct
|
|
19
|
+
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
20
20
|
*
|
|
21
21
|
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
22
|
-
* it has no managed allowance expiration.
|
|
22
|
+
* it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
|
|
23
|
+
* payload so it can be inspected or displayed before signing.
|
|
23
24
|
*
|
|
24
25
|
* @param params - SignatureTransfer parameters.
|
|
25
26
|
* @param params.token - ERC-20 token pulled through Permit2.
|
|
26
|
-
* @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
|
|
27
|
+
* @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
|
|
27
28
|
* @param params.amount - Exact `uint256` token amount authorized.
|
|
28
29
|
* @param params.chainId - Target chain id.
|
|
29
30
|
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
30
31
|
* @param params.deadline - Signature expiration timestamp in seconds.
|
|
31
|
-
* @returns A requirement whose `
|
|
32
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
|
|
33
|
+
* `sign(client, userAddress)` returns a deep-frozen signature result.
|
|
32
34
|
* @throws {NegativeInputError} when `amount` or `nonce` is negative.
|
|
33
35
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
34
36
|
* @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
|
|
35
37
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
36
38
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
37
39
|
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
38
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
40
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
|
|
39
41
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
|
|
40
42
|
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
|
|
41
43
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
|
|
@@ -43,19 +45,19 @@ export interface EncodeErc20Permit2TransferFromParams {
|
|
|
43
45
|
* @example
|
|
44
46
|
* ```ts
|
|
45
47
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
46
|
-
* import {
|
|
48
|
+
* import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
|
|
47
49
|
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
48
50
|
* import { mainnet } from "viem/chains";
|
|
49
51
|
*
|
|
50
|
-
* const requirement =
|
|
52
|
+
* const requirement = encodeErc20Permit2SignatureTransfer({
|
|
51
53
|
* token: addressesRegistry[mainnet.id].usdc,
|
|
52
|
-
* spender: getChainAddress(mainnet.id, "bundles.
|
|
54
|
+
* spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
|
|
53
55
|
* amount: 1_000_000n,
|
|
54
56
|
* chainId: mainnet.id,
|
|
55
57
|
* nonce: 0n,
|
|
56
58
|
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
57
59
|
* });
|
|
58
|
-
* // requirement satisfies Requirement<
|
|
60
|
+
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
59
61
|
* ```
|
|
60
62
|
*/
|
|
61
|
-
export declare const
|
|
63
|
+
export declare const encodeErc20Permit2SignatureTransfer: (params: EncodeErc20Permit2SignatureTransferParams) => Requirement<Permit2SignatureTransferRequirementSignature>;
|
|
@@ -6,26 +6,28 @@ import { validateUint256Field } from "../../../helpers/validate.js";
|
|
|
6
6
|
import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
|
|
7
7
|
import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } from "../../../types/index.js";
|
|
8
8
|
/**
|
|
9
|
-
* Builds a Permit2 SignatureTransfer requirement for a direct
|
|
9
|
+
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
10
10
|
*
|
|
11
11
|
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
12
|
-
* it has no managed allowance expiration.
|
|
12
|
+
* it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
|
|
13
|
+
* payload so it can be inspected or displayed before signing.
|
|
13
14
|
*
|
|
14
15
|
* @param params - SignatureTransfer parameters.
|
|
15
16
|
* @param params.token - ERC-20 token pulled through Permit2.
|
|
16
|
-
* @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
|
|
17
|
+
* @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
|
|
17
18
|
* @param params.amount - Exact `uint256` token amount authorized.
|
|
18
19
|
* @param params.chainId - Target chain id.
|
|
19
20
|
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
20
21
|
* @param params.deadline - Signature expiration timestamp in seconds.
|
|
21
|
-
* @returns A requirement whose `
|
|
22
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
|
|
23
|
+
* `sign(client, userAddress)` returns a deep-frozen signature result.
|
|
22
24
|
* @throws {NegativeInputError} when `amount` or `nonce` is negative.
|
|
23
25
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
24
26
|
* @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
|
|
25
27
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
26
28
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
27
29
|
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
28
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
30
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
|
|
29
31
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
|
|
30
32
|
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
|
|
31
33
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
|
|
@@ -33,22 +35,22 @@ import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } fr
|
|
|
33
35
|
* @example
|
|
34
36
|
* ```ts
|
|
35
37
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
36
|
-
* import {
|
|
38
|
+
* import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
|
|
37
39
|
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
38
40
|
* import { mainnet } from "viem/chains";
|
|
39
41
|
*
|
|
40
|
-
* const requirement =
|
|
42
|
+
* const requirement = encodeErc20Permit2SignatureTransfer({
|
|
41
43
|
* token: addressesRegistry[mainnet.id].usdc,
|
|
42
|
-
* spender: getChainAddress(mainnet.id, "bundles.
|
|
44
|
+
* spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
|
|
43
45
|
* amount: 1_000_000n,
|
|
44
46
|
* chainId: mainnet.id,
|
|
45
47
|
* nonce: 0n,
|
|
46
48
|
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
47
49
|
* });
|
|
48
|
-
* // requirement satisfies Requirement<
|
|
50
|
+
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
49
51
|
* ```
|
|
50
52
|
*/
|
|
51
|
-
export const
|
|
53
|
+
export const encodeErc20Permit2SignatureTransfer = (params) => {
|
|
52
54
|
const { token, spender, amount, chainId, nonce, deadline } = params;
|
|
53
55
|
// Bound every uint256 field before signing: getPermit2TransferFromTypedData silently clamps an
|
|
54
56
|
// oversized allowance to maxUint256, which would desync the signed value from the requirement
|
|
@@ -76,7 +78,7 @@ export const encodeErc20Permit2TransferFrom = (params) => {
|
|
|
76
78
|
validateRequirementSpender({
|
|
77
79
|
chainId,
|
|
78
80
|
spender,
|
|
79
|
-
allowed: ["blueBundlesV1"],
|
|
81
|
+
allowed: ["vaultBundlesV1", "blueBundlesV1"],
|
|
80
82
|
});
|
|
81
83
|
// getPermit2TransferFromTypedData derives its EIP-712 domain's verifyingContract from
|
|
82
84
|
// getChainAddresses(chainId).permit2. A chain that registers BlueBundlesV1 but no canonical Permit2
|
|
@@ -84,20 +86,23 @@ export const encodeErc20Permit2TransferFrom = (params) => {
|
|
|
84
86
|
// sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
|
|
85
87
|
// this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
|
|
86
88
|
getChainAddress(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
|
|
89
|
+
// Permit2 SignatureTransfer signs over `PermitTransferFrom` (permitted, spender, nonce,
|
|
90
|
+
// deadline), which does not include the owner, so the payload is fully determined at build time.
|
|
91
|
+
const typedData = deepFreeze(getPermit2TransferFromTypedData({
|
|
92
|
+
erc20: token,
|
|
93
|
+
allowance: amount,
|
|
94
|
+
spender,
|
|
95
|
+
nonce,
|
|
96
|
+
deadline,
|
|
97
|
+
}, chainId));
|
|
87
98
|
const action = {
|
|
88
|
-
type: "
|
|
89
|
-
args: { spender, amount, deadline },
|
|
99
|
+
type: "permit2SignatureTransfer",
|
|
100
|
+
args: { spender, amount, nonce, deadline },
|
|
101
|
+
typedData,
|
|
90
102
|
};
|
|
91
103
|
return {
|
|
92
104
|
action,
|
|
93
105
|
async sign(client, userAddress) {
|
|
94
|
-
const typedData = getPermit2TransferFromTypedData({
|
|
95
|
-
erc20: token,
|
|
96
|
-
allowance: amount,
|
|
97
|
-
spender,
|
|
98
|
-
nonce,
|
|
99
|
-
deadline,
|
|
100
|
-
}, chainId);
|
|
101
106
|
const signature = await signAndVerifyTypedData({
|
|
102
107
|
client,
|
|
103
108
|
userAddress,
|
|
@@ -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;
|
|
@@ -23,26 +23,29 @@ export interface EncodeVaultSharesPermitParams {
|
|
|
23
23
|
* Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
|
|
24
24
|
*
|
|
25
25
|
* Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
|
|
26
|
-
* only `chainId` and `verifyingContract`.
|
|
26
|
+
* only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
|
|
27
|
+
* payload so it can be inspected or displayed before signing.
|
|
27
28
|
*
|
|
28
29
|
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
29
30
|
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
30
|
-
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
31
|
+
* @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
|
|
31
32
|
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
32
33
|
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
33
34
|
* @param params.nonce - Current vault permit nonce for the owner.
|
|
34
35
|
* @param params.amount - Vault-share allowance to authorize.
|
|
35
36
|
* @param params.deadline - Shared permit and bundle deadline.
|
|
36
|
-
* @returns A requirement whose `
|
|
37
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
|
|
38
|
+
* can be embedded in fixed vault-bundles calldata.
|
|
37
39
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
38
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
40
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
|
|
39
41
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
40
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
42
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
43
|
+
* wallet account differs from `userAddress`.
|
|
41
44
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
42
45
|
* @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
|
|
43
|
-
* @throws {InvalidPermitDomainChainIdError}
|
|
44
|
-
* @throws {InvalidPermitDomainVerifyingContractError}
|
|
45
|
-
* @throws {UnsupportedPermitDomainExtensionsError}
|
|
46
|
+
* @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
|
|
47
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
|
|
48
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
|
|
46
49
|
* @example
|
|
47
50
|
* ```ts
|
|
48
51
|
* import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
|
|
@@ -9,26 +9,29 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
|
|
|
9
9
|
* Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
|
|
10
10
|
*
|
|
11
11
|
* Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
|
|
12
|
-
* only `chainId` and `verifyingContract`.
|
|
12
|
+
* only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
|
|
13
|
+
* payload so it can be inspected or displayed before signing.
|
|
13
14
|
*
|
|
14
15
|
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
15
16
|
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
16
|
-
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
17
|
+
* @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
|
|
17
18
|
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
18
19
|
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
19
20
|
* @param params.nonce - Current vault permit nonce for the owner.
|
|
20
21
|
* @param params.amount - Vault-share allowance to authorize.
|
|
21
22
|
* @param params.deadline - Shared permit and bundle deadline.
|
|
22
|
-
* @returns A requirement whose `
|
|
23
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
|
|
24
|
+
* can be embedded in fixed vault-bundles calldata.
|
|
23
25
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
24
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
26
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
|
|
25
27
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
26
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
28
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
29
|
+
* wallet account differs from `userAddress`.
|
|
27
30
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
28
31
|
* @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
|
|
29
|
-
* @throws {InvalidPermitDomainChainIdError}
|
|
30
|
-
* @throws {InvalidPermitDomainVerifyingContractError}
|
|
31
|
-
* @throws {UnsupportedPermitDomainExtensionsError}
|
|
32
|
+
* @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
|
|
33
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
|
|
34
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
|
|
32
35
|
* @example
|
|
33
36
|
* ```ts
|
|
34
37
|
* import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
|
|
@@ -76,11 +79,23 @@ export const encodeVaultSharesPermit = (params) => {
|
|
|
76
79
|
extensions: [...inputDomain.extensions],
|
|
77
80
|
}),
|
|
78
81
|
});
|
|
79
|
-
// Bind the permit to the
|
|
82
|
+
// Bind the permit to one of the registered fixed vault bundles deployments.
|
|
80
83
|
validateRequirementSpender({
|
|
81
84
|
chainId,
|
|
82
85
|
spender,
|
|
83
|
-
allowed: ["vaultExitBundlesV1"],
|
|
86
|
+
allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
|
|
87
|
+
});
|
|
88
|
+
const permitTypedData = getPermitTypedData({
|
|
89
|
+
owner,
|
|
90
|
+
spender,
|
|
91
|
+
allowance: amount,
|
|
92
|
+
nonce,
|
|
93
|
+
deadline,
|
|
94
|
+
erc20: vault,
|
|
95
|
+
}, chainId);
|
|
96
|
+
const typedData = deepFreeze({
|
|
97
|
+
...permitTypedData,
|
|
98
|
+
domain: { ...permitTypedData.domain },
|
|
84
99
|
});
|
|
85
100
|
const action = {
|
|
86
101
|
type: "permit",
|
|
@@ -88,24 +103,15 @@ export const encodeVaultSharesPermit = (params) => {
|
|
|
88
103
|
spender,
|
|
89
104
|
amount,
|
|
90
105
|
deadline,
|
|
106
|
+
nonce,
|
|
91
107
|
},
|
|
108
|
+
typedData,
|
|
92
109
|
};
|
|
93
110
|
return {
|
|
94
111
|
action,
|
|
95
112
|
async sign(client, userAddress) {
|
|
96
113
|
// The bundle spends msg.sender's shares, so another signer cannot authorize this exit.
|
|
97
114
|
validateUserAddress(userAddress, owner);
|
|
98
|
-
const permit = {
|
|
99
|
-
owner,
|
|
100
|
-
spender,
|
|
101
|
-
allowance: amount,
|
|
102
|
-
nonce,
|
|
103
|
-
deadline,
|
|
104
|
-
};
|
|
105
|
-
const typedData = getPermitTypedData({
|
|
106
|
-
...permit,
|
|
107
|
-
erc20: vault,
|
|
108
|
-
}, chainId);
|
|
109
115
|
const signature = await signAndVerifyTypedData({
|
|
110
116
|
client,
|
|
111
117
|
userAddress,
|
|
@@ -2,5 +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 "./
|
|
5
|
+
export * from "./encodeErc20Permit2SignatureTransfer.js";
|
|
6
6
|
export * from "./encodeVaultSharesPermit.js";
|
|
@@ -2,5 +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 "./
|
|
5
|
+
export * from "./encodeErc20Permit2SignatureTransfer.js";
|
|
6
6
|
export * from "./encodeVaultSharesPermit.js";
|
|
@@ -92,6 +92,7 @@ export const getGeneralAdapterRequirements = async (viemClient, params) => {
|
|
|
92
92
|
// the pulled amount leaves no residual direct allowance after inclusion.
|
|
93
93
|
return getGeneralAdapterRequirementsPermit(viemClient, {
|
|
94
94
|
token: address,
|
|
95
|
+
owner: from,
|
|
95
96
|
chainId,
|
|
96
97
|
args: { amount },
|
|
97
98
|
nonce: erc2612Nonce,
|
package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ import type { Address, Client } from "viem";
|
|
|
5
5
|
*
|
|
6
6
|
* @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
|
|
7
7
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
8
|
+
* @param params.owner - Account that owns the tokens and signs the permit.
|
|
8
9
|
* @param params.chainId - The chain the bundle targets.
|
|
9
10
|
* @param params.args.amount - Required token amount.
|
|
10
|
-
* @param params.nonce - The
|
|
11
|
+
* @param params.nonce - The owner's current EIP-2612 nonce on `token`.
|
|
11
12
|
* @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
|
|
12
13
|
* @returns A single-element array containing the exact-amount `Requirement` to sign.
|
|
13
14
|
* @example
|
|
@@ -19,6 +20,7 @@ import type { Address, Client } from "viem";
|
|
|
19
20
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
20
21
|
* const reqs = await getGeneralAdapterRequirementsPermit(client, {
|
|
21
22
|
* token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
|
|
23
|
+
* owner,
|
|
22
24
|
* chainId: 1,
|
|
23
25
|
* args: { amount: 1_000_000n },
|
|
24
26
|
* nonce: 0n,
|
|
@@ -28,6 +30,7 @@ import type { Address, Client } from "viem";
|
|
|
28
30
|
*/
|
|
29
31
|
export declare const getGeneralAdapterRequirementsPermit: (viemClient: Client, params: {
|
|
30
32
|
token: Address;
|
|
33
|
+
owner: Address;
|
|
31
34
|
chainId: number;
|
|
32
35
|
args: {
|
|
33
36
|
amount: bigint;
|
|
@@ -6,9 +6,10 @@ import { encodeErc20Permit } from "../encode/index.js";
|
|
|
6
6
|
*
|
|
7
7
|
* @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
|
|
8
8
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
9
|
+
* @param params.owner - Account that owns the tokens and signs the permit.
|
|
9
10
|
* @param params.chainId - The chain the bundle targets.
|
|
10
11
|
* @param params.args.amount - Required token amount.
|
|
11
|
-
* @param params.nonce - The
|
|
12
|
+
* @param params.nonce - The owner's current EIP-2612 nonce on `token`.
|
|
12
13
|
* @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
|
|
13
14
|
* @returns A single-element array containing the exact-amount `Requirement` to sign.
|
|
14
15
|
* @example
|
|
@@ -20,6 +21,7 @@ import { encodeErc20Permit } from "../encode/index.js";
|
|
|
20
21
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
21
22
|
* const reqs = await getGeneralAdapterRequirementsPermit(client, {
|
|
22
23
|
* token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
|
|
24
|
+
* owner,
|
|
23
25
|
* chainId: 1,
|
|
24
26
|
* args: { amount: 1_000_000n },
|
|
25
27
|
* nonce: 0n,
|
|
@@ -28,7 +30,7 @@ import { encodeErc20Permit } from "../encode/index.js";
|
|
|
28
30
|
* ```
|
|
29
31
|
*/
|
|
30
32
|
export const getGeneralAdapterRequirementsPermit = async (viemClient, params) => {
|
|
31
|
-
const { token, chainId, args: { amount }, nonce, supportDeployless, } = params;
|
|
33
|
+
const { token, owner, chainId, args: { amount }, nonce, supportDeployless, } = params;
|
|
32
34
|
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
33
35
|
// Existing direct ERC-20 allowance is intentionally not an input here. ERC-2612 overwrites the
|
|
34
36
|
// allowance with the signed amount, and the bundle spends exactly `amount`, leaving no residual
|
|
@@ -36,6 +38,7 @@ export const getGeneralAdapterRequirementsPermit = async (viemClient, params) =>
|
|
|
36
38
|
return [
|
|
37
39
|
await encodeErc20Permit(viemClient, {
|
|
38
40
|
token,
|
|
41
|
+
owner,
|
|
39
42
|
spender: generalAdapter1,
|
|
40
43
|
amount,
|
|
41
44
|
chainId,
|