@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
|
@@ -3,8 +3,8 @@ 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");
|
|
7
6
|
const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
|
|
7
|
+
const validate_js_1 = require("../../../helpers/validate.js");
|
|
8
8
|
const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
|
|
9
9
|
const index_js_1 = require("../../../types/index.js");
|
|
10
10
|
/**
|
|
@@ -13,30 +13,34 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
13
13
|
*
|
|
14
14
|
* Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
|
|
15
15
|
* signature, verifies it against the connected account, and returns a `RequirementSignature`
|
|
16
|
-
* the selected transaction route can consume.
|
|
17
|
-
*
|
|
16
|
+
* the selected transaction route can consume. The requirement's `action.typedData` holds that
|
|
17
|
+
* EIP-712 payload so it can be inspected or displayed before signing. Deadline defaults to two
|
|
18
|
+
* hours from `Time.timestamp()`.
|
|
18
19
|
*
|
|
19
20
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
20
21
|
* @param params - Permit encoding parameters.
|
|
21
22
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
22
|
-
* @param params.
|
|
23
|
-
*
|
|
23
|
+
* @param params.owner - Account that owns the tokens and signs the permit.
|
|
24
|
+
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
25
|
+
* VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
24
26
|
* @param params.amount - Permit allowance amount.
|
|
25
27
|
* @param params.chainId - Target chain id.
|
|
26
|
-
* @param params.nonce - The
|
|
28
|
+
* @param params.nonce - The owner's current EIP-2612 nonce on `token`.
|
|
27
29
|
* @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
|
|
28
30
|
* @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
|
|
29
|
-
* @returns A `Requirement` whose `
|
|
31
|
+
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
32
|
+
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
30
33
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
31
34
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
32
35
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
|
|
33
|
-
* MidnightBundles, or BlueBundlesV1 for `chainId`.
|
|
36
|
+
* MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
|
|
34
37
|
* @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
|
|
35
38
|
* @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
|
|
36
39
|
* @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
|
|
37
40
|
* @throws {viem.BaseError} when the token metadata read fails with no fallback left.
|
|
38
41
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
39
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
42
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
43
|
+
* client account differs from `userAddress`.
|
|
40
44
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
41
45
|
* @example
|
|
42
46
|
* ```ts
|
|
@@ -47,39 +51,38 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
47
51
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
48
52
|
* const requirement = await encodeErc20Permit(client, {
|
|
49
53
|
* token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
|
|
54
|
+
* owner,
|
|
50
55
|
* spender: generalAdapter1,
|
|
51
56
|
* amount: 1_000_000n,
|
|
52
57
|
* chainId: 1,
|
|
53
58
|
* nonce: 0n,
|
|
54
59
|
* });
|
|
55
|
-
* //
|
|
60
|
+
* // Inspect the EIP-712 payload, then sign via the requirement:
|
|
61
|
+
* const typedData = requirement.action.typedData;
|
|
62
|
+
* const signed = await requirement.sign(client, owner);
|
|
56
63
|
* ```
|
|
57
64
|
*/
|
|
58
65
|
const encodeErc20Permit = async (viemClient, params) => {
|
|
59
|
-
const { token, spender, amount, chainId, nonce, supportDeployless } = params;
|
|
66
|
+
const { token, owner, spender, amount, chainId, nonce, supportDeployless } = params;
|
|
60
67
|
if (viemClient.chain?.id !== chainId) {
|
|
61
68
|
throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
62
69
|
}
|
|
63
70
|
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
64
71
|
chainId,
|
|
65
72
|
spender,
|
|
66
|
-
allowed: [
|
|
73
|
+
allowed: [
|
|
74
|
+
"generalAdapter1",
|
|
75
|
+
"midnightBundles",
|
|
76
|
+
"vaultBundlesV1",
|
|
77
|
+
"blueBundlesV1",
|
|
78
|
+
],
|
|
67
79
|
});
|
|
68
80
|
const now = morpho_ts_1.Time.timestamp();
|
|
69
81
|
// Validate an explicit deadline before the token-metadata read: this exported encoder can be
|
|
70
82
|
// called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
|
|
71
83
|
// deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
|
|
72
84
|
if (params.deadline != null) {
|
|
73
|
-
|
|
74
|
-
throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
|
|
75
|
-
}
|
|
76
|
-
if (params.deadline > viem_1.maxUint256) {
|
|
77
|
-
throw new index_js_1.InputExceedsMaxError({
|
|
78
|
-
field: "deadline",
|
|
79
|
-
value: params.deadline,
|
|
80
|
-
max: viem_1.maxUint256,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
85
|
+
(0, validate_js_1.validateDeadline)(params.deadline);
|
|
83
86
|
if (params.deadline <= now) {
|
|
84
87
|
throw new index_js_1.ExpiredDeadlineError(params.deadline, now);
|
|
85
88
|
}
|
|
@@ -88,25 +91,34 @@ const encodeErc20Permit = async (viemClient, params) => {
|
|
|
88
91
|
const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient, {
|
|
89
92
|
deployless: supportDeployless,
|
|
90
93
|
});
|
|
94
|
+
const permitTypedData = (0, blue_sdk_viem_1.getPermitTypedData)({
|
|
95
|
+
erc20: tokenData,
|
|
96
|
+
owner,
|
|
97
|
+
spender,
|
|
98
|
+
allowance: amount,
|
|
99
|
+
nonce,
|
|
100
|
+
deadline,
|
|
101
|
+
}, chainId);
|
|
102
|
+
const typedData = (0, morpho_ts_1.deepFreeze)({
|
|
103
|
+
...permitTypedData,
|
|
104
|
+
domain: { ...permitTypedData.domain },
|
|
105
|
+
});
|
|
91
106
|
const action = {
|
|
92
107
|
type: "permit",
|
|
93
108
|
args: {
|
|
94
109
|
spender,
|
|
95
110
|
amount,
|
|
96
111
|
deadline,
|
|
112
|
+
nonce,
|
|
97
113
|
},
|
|
114
|
+
typedData,
|
|
98
115
|
};
|
|
99
116
|
return {
|
|
100
117
|
action,
|
|
101
118
|
async sign(client, userAddress) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
spender,
|
|
106
|
-
allowance: amount,
|
|
107
|
-
nonce,
|
|
108
|
-
deadline,
|
|
109
|
-
}, chainId);
|
|
119
|
+
// The permit's owner is fixed at build time (the fetched nonce is owner-specific), so a
|
|
120
|
+
// different signer cannot produce a valid signature for it.
|
|
121
|
+
(0, validate_js_1.validateUserAddress)(userAddress, owner);
|
|
110
122
|
const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
|
|
111
123
|
client,
|
|
112
124
|
userAddress,
|
|
@@ -114,7 +126,7 @@ const encodeErc20Permit = async (viemClient, params) => {
|
|
|
114
126
|
});
|
|
115
127
|
return (0, morpho_ts_1.deepFreeze)({
|
|
116
128
|
args: {
|
|
117
|
-
owner
|
|
129
|
+
owner,
|
|
118
130
|
signature,
|
|
119
131
|
deadline,
|
|
120
132
|
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.
|
|
@@ -9,7 +9,8 @@ const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTyped
|
|
|
9
9
|
* Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
|
|
10
10
|
* via the Permit2 contract.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
|
|
13
|
+
* displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
|
|
13
14
|
*
|
|
14
15
|
* @param params - Permit2 encoding parameters.
|
|
15
16
|
* @param params.token - ERC-20 token address.
|
|
@@ -17,7 +18,8 @@ const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTyped
|
|
|
17
18
|
* @param params.chainId - Target chain id.
|
|
18
19
|
* @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
|
|
19
20
|
* @param params.expiration - Permit2-managed allowance expiration timestamp.
|
|
20
|
-
* @returns A `Requirement` whose `
|
|
21
|
+
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
22
|
+
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
21
23
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
22
24
|
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
23
25
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
@@ -40,6 +42,16 @@ const encodeErc20Permit2Approve = (params) => {
|
|
|
40
42
|
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
41
43
|
const now = morpho_ts_1.Time.timestamp();
|
|
42
44
|
const deadline = now + morpho_ts_1.Time.s.from.h(2n);
|
|
45
|
+
// Permit2 AllowanceTransfer signs over `PermitSingle` (token, spender, expiration, nonce), which
|
|
46
|
+
// does not include the owner, so the payload is fully determined at build time.
|
|
47
|
+
const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getPermit2PermitTypedData)({
|
|
48
|
+
spender: generalAdapter1,
|
|
49
|
+
allowance: amount,
|
|
50
|
+
erc20: token,
|
|
51
|
+
nonce: Number(nonce),
|
|
52
|
+
deadline,
|
|
53
|
+
expiration: Number(expiration),
|
|
54
|
+
}, chainId));
|
|
43
55
|
const action = {
|
|
44
56
|
type: "permit2",
|
|
45
57
|
args: {
|
|
@@ -48,18 +60,11 @@ const encodeErc20Permit2Approve = (params) => {
|
|
|
48
60
|
deadline,
|
|
49
61
|
expiration,
|
|
50
62
|
},
|
|
63
|
+
typedData,
|
|
51
64
|
};
|
|
52
65
|
return {
|
|
53
66
|
action,
|
|
54
67
|
async sign(client, userAddress) {
|
|
55
|
-
const typedData = (0, blue_sdk_viem_1.getPermit2PermitTypedData)({
|
|
56
|
-
spender: generalAdapter1,
|
|
57
|
-
allowance: amount,
|
|
58
|
-
erc20: token,
|
|
59
|
-
nonce: Number(nonce),
|
|
60
|
-
deadline,
|
|
61
|
-
expiration: Number(expiration),
|
|
62
|
-
}, chainId);
|
|
63
68
|
const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
|
|
64
69
|
client,
|
|
65
70
|
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>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.encodeErc20Permit2SignatureTransfer = 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
6
|
const viem_1 = require("viem");
|
|
@@ -9,26 +9,28 @@ const validate_js_1 = require("../../../helpers/validate.js");
|
|
|
9
9
|
const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
|
|
10
10
|
const index_js_1 = require("../../../types/index.js");
|
|
11
11
|
/**
|
|
12
|
-
* Builds a Permit2 SignatureTransfer requirement for a direct
|
|
12
|
+
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
13
13
|
*
|
|
14
14
|
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
15
|
-
* it has no managed allowance expiration.
|
|
15
|
+
* it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
|
|
16
|
+
* payload so it can be inspected or displayed before signing.
|
|
16
17
|
*
|
|
17
18
|
* @param params - SignatureTransfer parameters.
|
|
18
19
|
* @param params.token - ERC-20 token pulled through Permit2.
|
|
19
|
-
* @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
|
|
20
|
+
* @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
|
|
20
21
|
* @param params.amount - Exact `uint256` token amount authorized.
|
|
21
22
|
* @param params.chainId - Target chain id.
|
|
22
23
|
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
23
24
|
* @param params.deadline - Signature expiration timestamp in seconds.
|
|
24
|
-
* @returns A requirement whose `
|
|
25
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
|
|
26
|
+
* `sign(client, userAddress)` returns a deep-frozen signature result.
|
|
25
27
|
* @throws {NegativeInputError} when `amount` or `nonce` is negative.
|
|
26
28
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
27
29
|
* @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
|
|
28
30
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
29
31
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
30
32
|
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
31
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
33
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
|
|
32
34
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
|
|
33
35
|
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
|
|
34
36
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
|
|
@@ -36,22 +38,22 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
36
38
|
* @example
|
|
37
39
|
* ```ts
|
|
38
40
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
39
|
-
* import {
|
|
41
|
+
* import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
|
|
40
42
|
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
41
43
|
* import { mainnet } from "viem/chains";
|
|
42
44
|
*
|
|
43
|
-
* const requirement =
|
|
45
|
+
* const requirement = encodeErc20Permit2SignatureTransfer({
|
|
44
46
|
* token: addressesRegistry[mainnet.id].usdc,
|
|
45
|
-
* spender: getChainAddress(mainnet.id, "bundles.
|
|
47
|
+
* spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
|
|
46
48
|
* amount: 1_000_000n,
|
|
47
49
|
* chainId: mainnet.id,
|
|
48
50
|
* nonce: 0n,
|
|
49
51
|
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
50
52
|
* });
|
|
51
|
-
* // requirement satisfies Requirement<
|
|
53
|
+
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
52
54
|
* ```
|
|
53
55
|
*/
|
|
54
|
-
const
|
|
56
|
+
const encodeErc20Permit2SignatureTransfer = (params) => {
|
|
55
57
|
const { token, spender, amount, chainId, nonce, deadline } = params;
|
|
56
58
|
// Bound every uint256 field before signing: getPermit2TransferFromTypedData silently clamps an
|
|
57
59
|
// oversized allowance to maxUint256, which would desync the signed value from the requirement
|
|
@@ -79,7 +81,7 @@ const encodeErc20Permit2TransferFrom = (params) => {
|
|
|
79
81
|
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
80
82
|
chainId,
|
|
81
83
|
spender,
|
|
82
|
-
allowed: ["blueBundlesV1"],
|
|
84
|
+
allowed: ["vaultBundlesV1", "blueBundlesV1"],
|
|
83
85
|
});
|
|
84
86
|
// getPermit2TransferFromTypedData derives its EIP-712 domain's verifyingContract from
|
|
85
87
|
// getChainAddresses(chainId).permit2. A chain that registers BlueBundlesV1 but no canonical Permit2
|
|
@@ -87,20 +89,23 @@ const encodeErc20Permit2TransferFrom = (params) => {
|
|
|
87
89
|
// sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
|
|
88
90
|
// this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
|
|
89
91
|
(0, morpho_ts_1.getChainAddress)(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
|
|
92
|
+
// Permit2 SignatureTransfer signs over `PermitTransferFrom` (permitted, spender, nonce,
|
|
93
|
+
// deadline), which does not include the owner, so the payload is fully determined at build time.
|
|
94
|
+
const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getPermit2TransferFromTypedData)({
|
|
95
|
+
erc20: token,
|
|
96
|
+
allowance: amount,
|
|
97
|
+
spender,
|
|
98
|
+
nonce,
|
|
99
|
+
deadline,
|
|
100
|
+
}, chainId));
|
|
90
101
|
const action = {
|
|
91
|
-
type: "
|
|
92
|
-
args: { spender, amount, deadline },
|
|
102
|
+
type: "permit2SignatureTransfer",
|
|
103
|
+
args: { spender, amount, nonce, deadline },
|
|
104
|
+
typedData,
|
|
93
105
|
};
|
|
94
106
|
return {
|
|
95
107
|
action,
|
|
96
108
|
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
109
|
const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
|
|
105
110
|
client,
|
|
106
111
|
userAddress,
|
|
@@ -120,4 +125,4 @@ const encodeErc20Permit2TransferFrom = (params) => {
|
|
|
120
125
|
},
|
|
121
126
|
};
|
|
122
127
|
};
|
|
123
|
-
exports.
|
|
128
|
+
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;
|
|
@@ -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";
|
|
@@ -12,26 +12,29 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
|
|
|
12
12
|
* Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
|
|
13
13
|
*
|
|
14
14
|
* Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
|
|
15
|
-
* only `chainId` and `verifyingContract`.
|
|
15
|
+
* only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
|
|
16
|
+
* payload so it can be inspected or displayed before signing.
|
|
16
17
|
*
|
|
17
18
|
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
18
19
|
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
19
|
-
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
20
|
+
* @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
|
|
20
21
|
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
21
22
|
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
22
23
|
* @param params.nonce - Current vault permit nonce for the owner.
|
|
23
24
|
* @param params.amount - Vault-share allowance to authorize.
|
|
24
25
|
* @param params.deadline - Shared permit and bundle deadline.
|
|
25
|
-
* @returns A requirement whose `
|
|
26
|
+
* @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
|
|
27
|
+
* can be embedded in fixed vault-bundles calldata.
|
|
26
28
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
27
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
29
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
|
|
28
30
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
29
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
31
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
32
|
+
* wallet account differs from `userAddress`.
|
|
30
33
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
31
34
|
* @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
|
|
32
|
-
* @throws {InvalidPermitDomainChainIdError}
|
|
33
|
-
* @throws {InvalidPermitDomainVerifyingContractError}
|
|
34
|
-
* @throws {UnsupportedPermitDomainExtensionsError}
|
|
35
|
+
* @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
|
|
36
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
|
|
37
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
|
|
35
38
|
* @example
|
|
36
39
|
* ```ts
|
|
37
40
|
* import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
|
|
@@ -79,11 +82,23 @@ const encodeVaultSharesPermit = (params) => {
|
|
|
79
82
|
extensions: [...inputDomain.extensions],
|
|
80
83
|
}),
|
|
81
84
|
});
|
|
82
|
-
// Bind the permit to the
|
|
85
|
+
// Bind the permit to one of the registered fixed vault bundles deployments.
|
|
83
86
|
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
84
87
|
chainId,
|
|
85
88
|
spender,
|
|
86
|
-
allowed: ["vaultExitBundlesV1"],
|
|
89
|
+
allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
|
|
90
|
+
});
|
|
91
|
+
const permitTypedData = (0, blue_sdk_viem_1.getPermitTypedData)({
|
|
92
|
+
owner,
|
|
93
|
+
spender,
|
|
94
|
+
allowance: amount,
|
|
95
|
+
nonce,
|
|
96
|
+
deadline,
|
|
97
|
+
erc20: vault,
|
|
98
|
+
}, chainId);
|
|
99
|
+
const typedData = (0, morpho_ts_1.deepFreeze)({
|
|
100
|
+
...permitTypedData,
|
|
101
|
+
domain: { ...permitTypedData.domain },
|
|
87
102
|
});
|
|
88
103
|
const action = {
|
|
89
104
|
type: "permit",
|
|
@@ -91,24 +106,15 @@ const encodeVaultSharesPermit = (params) => {
|
|
|
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
116
|
// The bundle spends msg.sender's shares, so another signer cannot authorize this exit.
|
|
100
117
|
(0, validate_js_1.validateUserAddress)(userAddress, owner);
|
|
101
|
-
const permit = {
|
|
102
|
-
owner,
|
|
103
|
-
spender,
|
|
104
|
-
allowance: amount,
|
|
105
|
-
nonce,
|
|
106
|
-
deadline,
|
|
107
|
-
};
|
|
108
|
-
const typedData = (0, blue_sdk_viem_1.getPermitTypedData)({
|
|
109
|
-
...permit,
|
|
110
|
-
erc20: vault,
|
|
111
|
-
}, chainId);
|
|
112
118
|
const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
|
|
113
119
|
client,
|
|
114
120
|
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";
|
|
@@ -18,5 +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("./
|
|
21
|
+
__exportStar(require("./encodeErc20Permit2SignatureTransfer.js"), exports);
|
|
22
22
|
__exportStar(require("./encodeVaultSharesPermit.js"), exports);
|
|
@@ -95,6 +95,7 @@ const getGeneralAdapterRequirements = async (viemClient, params) => {
|
|
|
95
95
|
// the pulled amount leaves no residual direct allowance after inclusion.
|
|
96
96
|
return (0, getGeneralAdapterRequirementsPermit_js_1.getGeneralAdapterRequirementsPermit)(viemClient, {
|
|
97
97
|
token: address,
|
|
98
|
+
owner: from,
|
|
98
99
|
chainId,
|
|
99
100
|
args: { amount },
|
|
100
101
|
nonce: erc2612Nonce,
|
package/lib/cjs/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;
|