@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.3
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 +199 -34
- package/README.md +23 -15
- package/lib/cjs/abis.d.ts +3 -2829
- package/lib/cjs/abis.js +1 -1938
- package/lib/cjs/actions/blue/borrow.d.ts +3 -2
- package/lib/cjs/actions/blue/borrow.js +3 -2
- package/lib/cjs/actions/blue/common.js +6 -35
- package/lib/cjs/actions/blue/refinance.d.ts +2 -2
- package/lib/cjs/actions/blue/refinance.js +2 -2
- package/lib/cjs/actions/blue/repay.d.ts +1 -1
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/cjs/actions/blue/supply.d.ts +2 -2
- package/lib/cjs/actions/blue/supply.js +4 -9
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
- package/lib/cjs/actions/blue/withdraw.js +3 -3
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/bundles/common.d.ts +38 -4
- package/lib/cjs/actions/bundles/common.js +91 -35
- package/lib/cjs/actions/index.d.ts +0 -1
- package/lib/cjs/actions/index.js +0 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +17 -26
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +24 -25
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -38
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/encode/index.js +0 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/cjs/actions/requirements/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/index.js +0 -1
- package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV1/deposit.js +1 -2
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -4
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +12 -8
- package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV2/deposit.js +1 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -4
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +12 -8
- package/lib/cjs/augment.d.ts +0 -1
- package/lib/cjs/augment.js +0 -1
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +2 -2
- package/lib/cjs/blue/entities.js +1 -2
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +1 -1
- package/lib/cjs/blue/fetch.js +1 -2
- package/lib/cjs/blue/types.d.ts +2 -4
- package/lib/cjs/blue/utils.d.ts +1 -3
- package/lib/cjs/blue/utils.js +1 -3
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -1
- package/lib/cjs/constants.d.ts +3 -37
- package/lib/cjs/constants.js +1 -39
- package/lib/cjs/entities/blue/blue.d.ts +38 -264
- package/lib/cjs/entities/blue/blue.js +2 -203
- package/lib/cjs/entities/index.d.ts +3 -60
- package/lib/cjs/entities/index.js +1 -20
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +1 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +18 -6
- package/lib/cjs/entities/vaultV1/vaultV1.js +25 -8
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +154 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +249 -23
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +50 -34
- package/lib/cjs/errors.d.ts +2 -46
- package/lib/cjs/errors.js +2 -46
- package/lib/cjs/fetch.d.ts +1 -15
- package/lib/cjs/fetch.js +1 -16
- package/lib/cjs/helpers/constant.d.ts +0 -2
- package/lib/cjs/helpers/constant.js +0 -2
- package/lib/cjs/helpers/index.d.ts +4 -3
- package/lib/cjs/helpers/index.js +10 -9
- package/lib/cjs/helpers/metadata.d.ts +3 -5
- package/lib/cjs/helpers/metadata.js +4 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/cjs/helpers/slippage.d.ts +34 -90
- package/lib/cjs/helpers/slippage.js +52 -137
- package/lib/cjs/helpers/utilization.d.ts +12 -10
- package/lib/cjs/helpers/utilization.js +27 -12
- package/lib/cjs/helpers/validate.d.ts +66 -32
- package/lib/cjs/helpers/validate.js +84 -57
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/types/action.d.ts +102 -68
- package/lib/cjs/types/action.js +11 -4
- package/lib/cjs/types/error.d.ts +332 -385
- package/lib/cjs/types/error.js +369 -412
- package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
- package/lib/cjs/types.d.ts +2 -18
- package/lib/cjs/utils.d.ts +8 -35
- package/lib/cjs/utils.js +11 -36
- package/lib/esm/abis.d.ts +3 -2829
- package/lib/esm/abis.js +3 -1935
- package/lib/esm/actions/blue/borrow.d.ts +3 -2
- package/lib/esm/actions/blue/borrow.js +3 -2
- package/lib/esm/actions/blue/common.js +8 -37
- package/lib/esm/actions/blue/refinance.d.ts +2 -2
- package/lib/esm/actions/blue/refinance.js +2 -2
- package/lib/esm/actions/blue/repay.d.ts +1 -1
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/esm/actions/blue/supply.d.ts +2 -2
- package/lib/esm/actions/blue/supply.js +6 -11
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/supplyCollateral.js +2 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/esm/actions/blue/withdraw.d.ts +3 -3
- package/lib/esm/actions/blue/withdraw.js +3 -3
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
- package/lib/esm/actions/bundles/common.d.ts +38 -4
- package/lib/esm/actions/bundles/common.js +91 -36
- package/lib/esm/actions/index.d.ts +0 -1
- package/lib/esm/actions/index.js +0 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +20 -29
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +25 -26
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -39
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
- package/lib/esm/actions/requirements/encode/index.js +0 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/esm/actions/requirements/index.d.ts +0 -1
- package/lib/esm/actions/requirements/index.js +0 -1
- package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV1/deposit.js +1 -2
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -4
- package/lib/esm/actions/vaultV1/inKindRedeem.js +12 -8
- package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV2/deposit.js +1 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -4
- package/lib/esm/actions/vaultV2/inKindRedeem.js +12 -8
- package/lib/esm/augment.d.ts +0 -1
- package/lib/esm/augment.js +0 -1
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +2 -2
- package/lib/esm/blue/entities.js +1 -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 +1 -1
- package/lib/esm/blue/fetch.js +1 -1
- package/lib/esm/blue/types.d.ts +2 -4
- package/lib/esm/blue/utils.d.ts +1 -3
- package/lib/esm/blue/utils.js +1 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -1
- package/lib/esm/constants.d.ts +3 -37
- package/lib/esm/constants.js +3 -37
- package/lib/esm/entities/blue/blue.d.ts +38 -264
- package/lib/esm/entities/blue/blue.js +5 -206
- package/lib/esm/entities/index.d.ts +3 -60
- package/lib/esm/entities/index.js +1 -16
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +18 -6
- package/lib/esm/entities/vaultV1/vaultV1.js +29 -12
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +154 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +256 -30
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +48 -32
- package/lib/esm/errors.d.ts +2 -46
- package/lib/esm/errors.js +2 -46
- package/lib/esm/fetch.d.ts +1 -15
- package/lib/esm/fetch.js +1 -15
- package/lib/esm/helpers/constant.d.ts +0 -2
- package/lib/esm/helpers/constant.js +0 -2
- package/lib/esm/helpers/index.d.ts +4 -3
- package/lib/esm/helpers/index.js +4 -3
- package/lib/esm/helpers/metadata.d.ts +3 -5
- package/lib/esm/helpers/metadata.js +4 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/esm/helpers/slippage.d.ts +34 -90
- package/lib/esm/helpers/slippage.js +52 -134
- package/lib/esm/helpers/utilization.d.ts +12 -10
- package/lib/esm/helpers/utilization.js +26 -11
- package/lib/esm/helpers/validate.d.ts +66 -32
- package/lib/esm/helpers/validate.js +83 -57
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -3
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/types/action.d.ts +102 -68
- package/lib/esm/types/action.js +12 -5
- package/lib/esm/types/error.d.ts +332 -385
- package/lib/esm/types/error.js +355 -392
- package/lib/esm/types/sharedLiquidity.d.ts +1 -117
- package/lib/esm/types.d.ts +2 -18
- package/lib/esm/utils.d.ts +8 -35
- package/lib/esm/utils.js +7 -34
- package/package.json +7 -15
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -83
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -151
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -50
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -43
- package/lib/cjs/actions/signatures/index.d.ts +0 -3
- package/lib/cjs/actions/signatures/index.js +0 -19
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
- package/lib/cjs/bundler/actions.d.ts +0 -797
- package/lib/cjs/bundler/actions.js +0 -1371
- package/lib/cjs/bundler/index.d.ts +0 -2
- package/lib/cjs/bundler/index.js +0 -18
- package/lib/cjs/bundler/types.d.ts +0 -235
- package/lib/cjs/bundler/types.js +0 -2
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -326
- package/lib/cjs/entities/vaultV1ReallocationData.js +0 -542
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -78
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -243
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -79
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -147
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -46
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -39
- package/lib/esm/actions/signatures/index.d.ts +0 -3
- package/lib/esm/actions/signatures/index.js +0 -3
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -5
- package/lib/esm/bundler/actions.d.ts +0 -797
- package/lib/esm/bundler/actions.js +0 -1368
- package/lib/esm/bundler/index.d.ts +0 -2
- package/lib/esm/bundler/index.js +0 -2
- package/lib/esm/bundler/types.d.ts +0 -235
- package/lib/esm/bundler/types.js +0 -1
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -326
- package/lib/esm/entities/vaultV1ReallocationData.js +0 -544
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -78
- package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -239
- /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
- /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { MathLib } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
-
import { compactSignatureToSignature, encodeAbiParameters, isAddressEqual,
|
|
3
|
+
import { compactSignatureToSignature, encodeAbiParameters, isAddressEqual, parseCompactSignature, parseSignature, size, zeroHash, } from "viem";
|
|
4
4
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { validateDeadline, validateReferralFee, } from "../../helpers/validate.js";
|
|
6
|
+
import { AmbiguousRequirementSignaturesError, BundlesPermitMismatchError, BundlesRequirementSignatureMismatchError, DepositAmountMismatchError, DepositAssetMismatchError, DepositOwnerMismatchError, DepositSpenderMismatchError, MixedBundlesFundingError, NegativeInputError, NonPositiveInputError, selectRequirementSignatures, UnexpectedRequirementSignatureError, UnsupportedRequirementSignatureError, } from "../../types/index.js";
|
|
6
7
|
/** Numeric permit kinds consumed by `TokenLib.pullToken`. */
|
|
7
8
|
export const BundlesPermitKind = {
|
|
8
9
|
None: 0,
|
|
@@ -27,32 +28,12 @@ const EMPTY_TOKEN_PERMIT = {
|
|
|
27
28
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
|
|
28
29
|
*/
|
|
29
30
|
export const normalizeBundlesCommonParams = (params) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
if (params.deadline > maxUint256) {
|
|
34
|
-
throw new InputExceedsMaxError({
|
|
35
|
-
field: "deadline",
|
|
36
|
-
value: params.deadline,
|
|
37
|
-
max: maxUint256,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const referralFeePct = params.referralFeePct ?? 0n;
|
|
41
|
-
if (referralFeePct < 0n) {
|
|
42
|
-
throw new NegativeInputError("referralFeePct", referralFeePct);
|
|
43
|
-
}
|
|
44
|
-
if (referralFeePct >= MathLib.WAD) {
|
|
45
|
-
throw new ReferralFeePctExceededError(referralFeePct);
|
|
46
|
-
}
|
|
47
|
-
if (referralFeePct > 0n &&
|
|
48
|
-
(params.referralFeeRecipient == null ||
|
|
49
|
-
isAddressEqual(params.referralFeeRecipient, zeroAddress))) {
|
|
50
|
-
throw new ReferralFeeRecipientMissingError();
|
|
51
|
-
}
|
|
31
|
+
validateDeadline(params.deadline);
|
|
32
|
+
const { referralFeePct, referralFeeRecipient } = validateReferralFee(params);
|
|
52
33
|
return {
|
|
53
34
|
deadline: params.deadline,
|
|
54
35
|
referralFeePct,
|
|
55
|
-
referralFeeRecipient
|
|
36
|
+
referralFeeRecipient,
|
|
56
37
|
};
|
|
57
38
|
};
|
|
58
39
|
/**
|
|
@@ -98,11 +79,12 @@ export const resolveBundlesFunding = (params) => {
|
|
|
98
79
|
* @param params.amount - Exact pull amount in the token's smallest unit; must match both signed amount fields.
|
|
99
80
|
* @param params.requirementSignature - Optional signed ERC-2612 or Permit2 SignatureTransfer requirement; omit for allowance funding.
|
|
100
81
|
* @returns An empty, ERC-2612, or Permit2 SignatureTransfer token permit.
|
|
101
|
-
* @throws {UnexpectedRequirementSignatureError} when Permit2 AllowanceTransfer is supplied.
|
|
102
82
|
* @throws {DepositOwnerMismatchError} when the signature owner differs from `userAddress`.
|
|
103
83
|
* @throws {DepositAssetMismatchError} when the signed token differs from `token`.
|
|
104
84
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
|
|
105
85
|
* @throws {DepositSpenderMismatchError} when the signed spender differs from `spender`.
|
|
86
|
+
* @throws {UnsupportedRequirementSignatureError} when the signature's action type is neither
|
|
87
|
+
* "permit" nor "permit2SignatureTransfer".
|
|
106
88
|
* @throws {BundlesRequirementSignatureMismatchError} when signature metadata is malformed.
|
|
107
89
|
* @example
|
|
108
90
|
* ```ts
|
|
@@ -122,9 +104,9 @@ export const getBundlesTokenPermit = (params) => {
|
|
|
122
104
|
const { requirementSignature } = params;
|
|
123
105
|
if (requirementSignature == null)
|
|
124
106
|
return { ...EMPTY_TOKEN_PERMIT };
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
107
|
+
const { type } = requirementSignature.action;
|
|
108
|
+
if (type !== "permit" && type !== "permit2SignatureTransfer")
|
|
109
|
+
throw new UnsupportedRequirementSignatureError(type);
|
|
128
110
|
if (!isAddressEqual(requirementSignature.args.owner, params.userAddress)) {
|
|
129
111
|
throw new DepositOwnerMismatchError(params.userAddress, requirementSignature.args.owner);
|
|
130
112
|
}
|
|
@@ -198,8 +180,17 @@ export const getBundlesTokenPermit = (params) => {
|
|
|
198
180
|
]),
|
|
199
181
|
};
|
|
200
182
|
};
|
|
201
|
-
/**
|
|
202
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Normalizes a compact or serialized ECDSA signature for bundles permit tuples.
|
|
185
|
+
*
|
|
186
|
+
* @internal
|
|
187
|
+
*
|
|
188
|
+
* @param serializedSignature - Compact or serialized ECDSA signature.
|
|
189
|
+
* @param onInvalid - Error factory used when parsing or extracting the recovery identifier fails.
|
|
190
|
+
* @returns The normalized signature tuple.
|
|
191
|
+
* @throws {BundlesPermitMismatchError} when the signature is malformed.
|
|
192
|
+
*/
|
|
193
|
+
export const normalizeBundlesSignature = (serializedSignature, onInvalid = (details) => new BundlesPermitMismatchError({ field: "signature", ...details })) => {
|
|
203
194
|
let parsed;
|
|
204
195
|
try {
|
|
205
196
|
parsed =
|
|
@@ -208,8 +199,7 @@ export const normalizeBundlesSignature = (serializedSignature) => {
|
|
|
208
199
|
: parseSignature(serializedSignature);
|
|
209
200
|
}
|
|
210
201
|
catch (cause) {
|
|
211
|
-
throw
|
|
212
|
-
field: "signature",
|
|
202
|
+
throw onInvalid({
|
|
213
203
|
expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
|
|
214
204
|
actual: serializedSignature,
|
|
215
205
|
cause,
|
|
@@ -218,8 +208,7 @@ export const normalizeBundlesSignature = (serializedSignature) => {
|
|
|
218
208
|
const normalizedV = parsed.v ??
|
|
219
209
|
(parsed.yParity == null ? undefined : BigInt(parsed.yParity + 27));
|
|
220
210
|
if (normalizedV == null) {
|
|
221
|
-
throw
|
|
222
|
-
field: "signature",
|
|
211
|
+
throw onInvalid({
|
|
223
212
|
expected: "a signature containing v or yParity",
|
|
224
213
|
actual: serializedSignature,
|
|
225
214
|
});
|
|
@@ -237,7 +226,10 @@ export const normalizeBundlesSignature = (serializedSignature) => {
|
|
|
237
226
|
* @param params.amount - Optional exact share allowance in the vault share token's smallest unit.
|
|
238
227
|
* @param params.requirementSignature - Optional signed ERC-2612 share requirement; omit for the empty-permit sentinel.
|
|
239
228
|
* @returns The signed share permit or the contract's empty-permit sentinel.
|
|
240
|
-
* @throws {
|
|
229
|
+
* @throws {NonPositiveInputError} when a bundle or permit deadline is not positive.
|
|
230
|
+
* @throws {InputExceedsMaxError} when a bundle or permit deadline exceeds uint256.
|
|
231
|
+
* @throws {BundlesPermitMismatchError} when the requirement kind, token, owner, spender, amount or
|
|
232
|
+
* deadline, or signature is invalid.
|
|
241
233
|
* @example
|
|
242
234
|
* ```ts
|
|
243
235
|
* import { getBundlesSharesPermit } from "@morpho-org/morpho-sdk";
|
|
@@ -252,6 +244,12 @@ export const normalizeBundlesSignature = (serializedSignature) => {
|
|
|
252
244
|
*/
|
|
253
245
|
export const getBundlesSharesPermit = (params) => {
|
|
254
246
|
const { requirementSignature } = params;
|
|
247
|
+
// Require a positive uint256 for the fallback permit deadline.
|
|
248
|
+
validateDeadline(params.deadline);
|
|
249
|
+
if (requirementSignature != null) {
|
|
250
|
+
// Require a positive uint256 for the signed permit deadline too.
|
|
251
|
+
validateDeadline(requirementSignature.args.deadline);
|
|
252
|
+
}
|
|
255
253
|
if (requirementSignature == null) {
|
|
256
254
|
return {
|
|
257
255
|
value: 0n,
|
|
@@ -301,6 +299,14 @@ export const getBundlesSharesPermit = (params) => {
|
|
|
301
299
|
actual: String(requirementSignature.args.amount),
|
|
302
300
|
});
|
|
303
301
|
}
|
|
302
|
+
if ((params.owner != null || params.spender != null || params.amount != null) &&
|
|
303
|
+
requirementSignature.action.args.amount !== requirementSignature.args.amount) {
|
|
304
|
+
throw new BundlesPermitMismatchError({
|
|
305
|
+
field: "amount",
|
|
306
|
+
expected: String(requirementSignature.args.amount),
|
|
307
|
+
actual: String(requirementSignature.action.args.amount),
|
|
308
|
+
});
|
|
309
|
+
}
|
|
304
310
|
if ((params.owner != null || params.spender != null || params.amount != null) &&
|
|
305
311
|
requirementSignature.action.args.deadline !==
|
|
306
312
|
requirementSignature.args.deadline) {
|
|
@@ -441,6 +447,55 @@ export const selectBundlesSharesRequirementSignature = (signatures, prepared) =>
|
|
|
441
447
|
validatePreparedBundlesRequirementSignature(selectedPermit, prepared.expectedRequirement);
|
|
442
448
|
return selectedPermit;
|
|
443
449
|
};
|
|
450
|
+
/**
|
|
451
|
+
* Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
|
|
452
|
+
*
|
|
453
|
+
* @internal
|
|
454
|
+
*
|
|
455
|
+
* @param signatures - Signatures passed to the operation's `buildTx` function.
|
|
456
|
+
* @param expected - Immutable spender, amount, and deadline required by the operation.
|
|
457
|
+
* @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
|
|
458
|
+
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
|
|
459
|
+
* deadline differ from the operation's. The nonce is not checked here: it is onchain state the
|
|
460
|
+
* vault's `permit` verifies at execution.
|
|
461
|
+
*/
|
|
462
|
+
export const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
463
|
+
const { permit } = selectRequirementSignatures(signatures, { permit: true });
|
|
464
|
+
if (permit == null)
|
|
465
|
+
return undefined;
|
|
466
|
+
const { action } = permit;
|
|
467
|
+
if (action.type !== "permit") {
|
|
468
|
+
throw new BundlesPermitMismatchError({
|
|
469
|
+
field: "type",
|
|
470
|
+
expected: "permit",
|
|
471
|
+
actual: action.type,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
if (!isAddressEqual(action.args.spender, expected.spender)) {
|
|
475
|
+
throw new BundlesPermitMismatchError({
|
|
476
|
+
field: "spender",
|
|
477
|
+
expected: expected.spender,
|
|
478
|
+
actual: action.args.spender,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
if (permit.args.amount !== expected.amount ||
|
|
482
|
+
action.args.amount !== expected.amount) {
|
|
483
|
+
throw new BundlesPermitMismatchError({
|
|
484
|
+
field: "amount",
|
|
485
|
+
expected: String(expected.amount),
|
|
486
|
+
actual: String(permit.args.amount),
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (permit.args.deadline !== expected.deadline ||
|
|
490
|
+
action.args.deadline !== expected.deadline) {
|
|
491
|
+
throw new BundlesPermitMismatchError({
|
|
492
|
+
field: "deadline",
|
|
493
|
+
expected: String(expected.deadline),
|
|
494
|
+
actual: String(permit.args.deadline),
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
return { args: permit.args, action };
|
|
498
|
+
};
|
|
444
499
|
/** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
|
|
445
500
|
export const getBundlesReferralFeeAssets = (assets, referralFeePct) => MathLib.mulDivDown(assets, referralFeePct, MathLib.WAD);
|
|
446
501
|
/** @internal Finalizes a direct VaultBundlesV1 transaction with metadata and immutable action data. */
|
|
@@ -6,6 +6,5 @@ export * from "./blue/index.js";
|
|
|
6
6
|
export * from "./bundles/index.js";
|
|
7
7
|
export * from "./midnight/index.js";
|
|
8
8
|
export * from "./requirements/index.js";
|
|
9
|
-
export * from "./signatures/index.js";
|
|
10
9
|
export * from "./vaultV1/index.js";
|
|
11
10
|
export * from "./vaultV2/index.js";
|
package/lib/esm/actions/index.js
CHANGED
|
@@ -10,15 +10,13 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
|
|
|
10
10
|
* - When `supportSignature` is falsy (default), returns the
|
|
11
11
|
* `setAuthorization(authorized, true)` transaction the user submits before the operation.
|
|
12
12
|
* - When `supportSignature` is `true`, reads the user's Morpho `nonce` and returns a signable
|
|
13
|
-
* `Requirement
|
|
14
|
-
* `setAuthorizationWithSig`, while BlueBundlesV1 embeds its signed-authorization struct.
|
|
13
|
+
* `Requirement` consumed by BlueBundlesV1.
|
|
15
14
|
*
|
|
16
15
|
* @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
17
|
-
* @param params.chainId - Target chain id used to resolve Morpho and
|
|
16
|
+
* @param params.chainId - Target chain id used to resolve Morpho and BlueBundlesV1.
|
|
18
17
|
* @param params.userAddress - The user granting authorization.
|
|
19
|
-
* @param params.authorized - Operator to authorize. Defaults to
|
|
20
|
-
*
|
|
21
|
-
* GeneralAdapter1 or BlueBundlesV1 operator.
|
|
18
|
+
* @param params.authorized - Operator to authorize. Defaults to the chain's registered
|
|
19
|
+
* BlueBundlesV1 deployment and must match it.
|
|
22
20
|
* @param params.deadline - Optional signature deadline forwarded to the authorization encoder.
|
|
23
21
|
* @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
|
|
24
22
|
* transaction so the destination route can consume the signed authorization.
|
|
@@ -26,8 +24,11 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
|
|
|
26
24
|
* `Requirement` (when `supportSignature` is `true`), or `null` when authorization is already in
|
|
27
25
|
* place.
|
|
28
26
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
29
|
-
* @throws {UnsupportedAuthorizationOperatorError} when `authorized` is
|
|
30
|
-
*
|
|
27
|
+
* @throws {UnsupportedAuthorizationOperatorError} when `authorized` is not the chain's
|
|
28
|
+
* BlueBundlesV1 operator.
|
|
29
|
+
* @throws {NonPositiveInputError} when a provided `deadline` is not positive.
|
|
30
|
+
* @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
|
|
31
|
+
* @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
|
|
31
32
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
32
33
|
* @throws {viem.BaseError} when an authorization or nonce RPC read fails.
|
|
33
34
|
* @example
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { blueAbi } from "@morpho-org/blue-sdk-viem";
|
|
3
|
-
import { deepFreeze, Time } from "@morpho-org/morpho-ts";
|
|
4
|
-
import { encodeFunctionData, isAddressEqual,
|
|
5
|
-
import {
|
|
3
|
+
import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
4
|
+
import { encodeFunctionData, isAddressEqual, publicActions, } from "viem";
|
|
5
|
+
import { validateDeadline } from "../../../helpers/validate.js";
|
|
6
|
+
import { ChainIdMismatchError, ExpiredDeadlineError, UnsupportedAuthorizationOperatorError, } from "../../../types/index.js";
|
|
6
7
|
import { encodeBlueSignatureAuthorization } from "../encode/encodeBlueSignatureAuthorization.js";
|
|
7
8
|
/**
|
|
8
9
|
* Resolves whether a supported operator needs Blue authorization for the given user, and returns
|
|
@@ -13,15 +14,13 @@ import { encodeBlueSignatureAuthorization } from "../encode/encodeBlueSignatureA
|
|
|
13
14
|
* - When `supportSignature` is falsy (default), returns the
|
|
14
15
|
* `setAuthorization(authorized, true)` transaction the user submits before the operation.
|
|
15
16
|
* - When `supportSignature` is `true`, reads the user's Morpho `nonce` and returns a signable
|
|
16
|
-
* `Requirement
|
|
17
|
-
* `setAuthorizationWithSig`, while BlueBundlesV1 embeds its signed-authorization struct.
|
|
17
|
+
* `Requirement` consumed by BlueBundlesV1.
|
|
18
18
|
*
|
|
19
19
|
* @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
20
|
-
* @param params.chainId - Target chain id used to resolve Morpho and
|
|
20
|
+
* @param params.chainId - Target chain id used to resolve Morpho and BlueBundlesV1.
|
|
21
21
|
* @param params.userAddress - The user granting authorization.
|
|
22
|
-
* @param params.authorized - Operator to authorize. Defaults to
|
|
23
|
-
*
|
|
24
|
-
* GeneralAdapter1 or BlueBundlesV1 operator.
|
|
22
|
+
* @param params.authorized - Operator to authorize. Defaults to the chain's registered
|
|
23
|
+
* BlueBundlesV1 deployment and must match it.
|
|
25
24
|
* @param params.deadline - Optional signature deadline forwarded to the authorization encoder.
|
|
26
25
|
* @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
|
|
27
26
|
* transaction so the destination route can consume the signed authorization.
|
|
@@ -29,8 +28,11 @@ import { encodeBlueSignatureAuthorization } from "../encode/encodeBlueSignatureA
|
|
|
29
28
|
* `Requirement` (when `supportSignature` is `true`), or `null` when authorization is already in
|
|
30
29
|
* place.
|
|
31
30
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
32
|
-
* @throws {UnsupportedAuthorizationOperatorError} when `authorized` is
|
|
33
|
-
*
|
|
31
|
+
* @throws {UnsupportedAuthorizationOperatorError} when `authorized` is not the chain's
|
|
32
|
+
* BlueBundlesV1 operator.
|
|
33
|
+
* @throws {NonPositiveInputError} when a provided `deadline` is not positive.
|
|
34
|
+
* @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
|
|
35
|
+
* @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
|
|
34
36
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
35
37
|
* @throws {viem.BaseError} when an authorization or nonce RPC read fails.
|
|
36
38
|
* @example
|
|
@@ -59,16 +61,13 @@ export const getBlueAuthorizationRequirement = async (params) => {
|
|
|
59
61
|
if (viemClient.chain?.id !== chainId) {
|
|
60
62
|
throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
61
63
|
}
|
|
62
|
-
const {
|
|
63
|
-
const
|
|
64
|
-
|
|
64
|
+
const { blue: morpho } = getChainAddresses(chainId);
|
|
65
|
+
const blueBundlesV1 = getChainAddress(chainId, "bundles.blueBundlesV1");
|
|
66
|
+
const authorized = params.authorized ?? blueBundlesV1;
|
|
67
|
+
// The SDK only ever authorizes the chain's registered BlueBundlesV1 operator;
|
|
65
68
|
// reject any other override so a misconfigured `authorized` cannot grant an arbitrary address
|
|
66
69
|
// control over the user's Morpho positions.
|
|
67
|
-
|
|
68
|
-
if (bundles?.blueBundlesV1 != null) {
|
|
69
|
-
supportedOperators.push(bundles.blueBundlesV1);
|
|
70
|
-
}
|
|
71
|
-
if (!supportedOperators.some((operator) => isAddressEqual(operator, authorized))) {
|
|
70
|
+
if (!isAddressEqual(blueBundlesV1, authorized)) {
|
|
72
71
|
throw new UnsupportedAuthorizationOperatorError(authorized, chainId);
|
|
73
72
|
}
|
|
74
73
|
const pc = viemClient.extend(publicActions);
|
|
@@ -77,16 +76,7 @@ export const getBlueAuthorizationRequirement = async (params) => {
|
|
|
77
76
|
// one before the RPC reads so the caller never signs an authorization that cannot be encoded
|
|
78
77
|
// or would revert on-chain. An omitted deadline defaults downstream to two hours from now.
|
|
79
78
|
if (params.deadline != null) {
|
|
80
|
-
|
|
81
|
-
throw new NonPositiveInputError("deadline", params.deadline);
|
|
82
|
-
}
|
|
83
|
-
if (params.deadline > maxUint256) {
|
|
84
|
-
throw new InputExceedsMaxError({
|
|
85
|
-
field: "deadline",
|
|
86
|
-
value: params.deadline,
|
|
87
|
-
max: maxUint256,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
79
|
+
validateDeadline(params.deadline);
|
|
90
80
|
const timestamp = Time.timestamp();
|
|
91
81
|
if (params.deadline <= timestamp) {
|
|
92
82
|
throw new ExpiredDeadlineError(params.deadline, timestamp);
|
|
@@ -114,6 +104,7 @@ export const getBlueAuthorizationRequirement = async (params) => {
|
|
|
114
104
|
return null;
|
|
115
105
|
}
|
|
116
106
|
return encodeBlueSignatureAuthorization(viemClient, {
|
|
107
|
+
owner: userAddress,
|
|
117
108
|
authorized,
|
|
118
109
|
chainId,
|
|
119
110
|
nonce,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Address } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import type { Client } from "viem";
|
|
3
3
|
import { type AuthorizationRequirementSignature, type Requirement } from "../../../types/index.js";
|
|
4
4
|
/** Parameters for {@link encodeBlueSignatureAuthorization}. */
|
|
5
5
|
interface EncodeBlueSignatureAuthorizationParams {
|
|
6
|
-
/**
|
|
6
|
+
/** Account granting the authorization and signing it (the Morpho `authorizer`). */
|
|
7
|
+
owner: Address;
|
|
8
|
+
/** BlueBundlesV1 operator to authorize on Morpho. */
|
|
7
9
|
authorized: Address;
|
|
8
10
|
/** Target chain id; must match `viemClient.chain.id`. */
|
|
9
11
|
chainId: number;
|
|
10
|
-
/** The
|
|
12
|
+
/** The owner's current Morpho authorization nonce. */
|
|
11
13
|
nonce: bigint;
|
|
12
14
|
/** Whether to grant (`true`, default) or revoke (`false`) the authorization. */
|
|
13
15
|
isAuthorized?: boolean;
|
|
@@ -15,29 +17,32 @@ interface EncodeBlueSignatureAuthorizationParams {
|
|
|
15
17
|
deadline?: bigint;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
|
-
* Builds a Morpho authorization `Requirement` that, once signed, lets
|
|
19
|
-
* Morpho on the signer's behalf.
|
|
20
|
-
* BlueBundlesV1 embeds the same signed authorization in its direct-call struct.
|
|
20
|
+
* Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
|
|
21
|
+
* Morpho on the signer's behalf.
|
|
21
22
|
*
|
|
22
23
|
* The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
|
|
23
24
|
* typed data, verifies it against the connected account, and returns a deep-frozen
|
|
24
|
-
* `RequirementSignature` the selected transaction route consumes.
|
|
25
|
-
*
|
|
25
|
+
* `RequirementSignature` the selected transaction route consumes. The requirement's
|
|
26
|
+
* `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
|
|
27
|
+
* Deadline defaults to two hours from `Time.timestamp()`.
|
|
26
28
|
*
|
|
27
29
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
28
30
|
* @param params - Authorization encoding parameters.
|
|
29
|
-
* @param params.
|
|
31
|
+
* @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
|
|
32
|
+
* @param params.authorized - BlueBundlesV1 operator to authorize.
|
|
30
33
|
* @param params.chainId - Target chain id.
|
|
31
|
-
* @param params.nonce - The
|
|
34
|
+
* @param params.nonce - The owner's current Morpho authorization nonce.
|
|
32
35
|
* @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
|
|
33
36
|
* @param params.deadline - Optional signature deadline in seconds.
|
|
34
|
-
* @returns A `Requirement` whose `
|
|
37
|
+
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
38
|
+
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
35
39
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
36
40
|
* @throws {NonPositiveInputError} when a provided `deadline` is not positive.
|
|
37
41
|
* @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
|
|
38
42
|
* @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
|
|
39
43
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
40
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
44
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
45
|
+
* client account differs from `userAddress`.
|
|
41
46
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
42
47
|
* @example
|
|
43
48
|
* ```ts
|
|
@@ -47,11 +52,12 @@ interface EncodeBlueSignatureAuthorizationParams {
|
|
|
47
52
|
*
|
|
48
53
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
49
54
|
* const requirement = await encodeBlueSignatureAuthorization(client, {
|
|
50
|
-
*
|
|
55
|
+
* owner,
|
|
56
|
+
* authorized: blueBundlesV1,
|
|
51
57
|
* chainId: 1,
|
|
52
58
|
* nonce: 0n,
|
|
53
59
|
* });
|
|
54
|
-
* // requirement
|
|
60
|
+
* // Inspect the EIP-712 payload (requirement.action.typedData) or sign via requirement.sign(...).
|
|
55
61
|
* ```
|
|
56
62
|
*/
|
|
57
63
|
export declare const encodeBlueSignatureAuthorization: (viemClient: Client, params: EncodeBlueSignatureAuthorizationParams) => Promise<Requirement<AuthorizationRequirementSignature>>;
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
import { getAuthorizationTypedData } 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";
|
|
5
|
-
import {
|
|
4
|
+
import { validateDeadline, validateUserAddress, } from "../../../helpers/validate.js";
|
|
5
|
+
import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/index.js";
|
|
6
6
|
/**
|
|
7
|
-
* Builds a Morpho authorization `Requirement` that, once signed, lets
|
|
8
|
-
* Morpho on the signer's behalf.
|
|
9
|
-
* BlueBundlesV1 embeds the same signed authorization in its direct-call struct.
|
|
7
|
+
* Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
|
|
8
|
+
* Morpho on the signer's behalf.
|
|
10
9
|
*
|
|
11
10
|
* The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
|
|
12
11
|
* typed data, verifies it against the connected account, and returns a deep-frozen
|
|
13
|
-
* `RequirementSignature` the selected transaction route consumes.
|
|
14
|
-
*
|
|
12
|
+
* `RequirementSignature` the selected transaction route consumes. The requirement's
|
|
13
|
+
* `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
|
|
14
|
+
* Deadline defaults to two hours from `Time.timestamp()`.
|
|
15
15
|
*
|
|
16
16
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
17
17
|
* @param params - Authorization encoding parameters.
|
|
18
|
-
* @param params.
|
|
18
|
+
* @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
|
|
19
|
+
* @param params.authorized - BlueBundlesV1 operator to authorize.
|
|
19
20
|
* @param params.chainId - Target chain id.
|
|
20
|
-
* @param params.nonce - The
|
|
21
|
+
* @param params.nonce - The owner's current Morpho authorization nonce.
|
|
21
22
|
* @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
|
|
22
23
|
* @param params.deadline - Optional signature deadline in seconds.
|
|
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 {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
25
27
|
* @throws {NonPositiveInputError} when a provided `deadline` is not positive.
|
|
26
28
|
* @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
|
|
27
29
|
* @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
|
|
28
30
|
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
29
|
-
* @throws {AddressMismatchError} from `sign()` when
|
|
31
|
+
* @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
|
|
32
|
+
* client account differs from `userAddress`.
|
|
30
33
|
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
31
34
|
* @example
|
|
32
35
|
* ```ts
|
|
@@ -36,15 +39,16 @@ import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPo
|
|
|
36
39
|
*
|
|
37
40
|
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
38
41
|
* const requirement = await encodeBlueSignatureAuthorization(client, {
|
|
39
|
-
*
|
|
42
|
+
* owner,
|
|
43
|
+
* authorized: blueBundlesV1,
|
|
40
44
|
* chainId: 1,
|
|
41
45
|
* nonce: 0n,
|
|
42
46
|
* });
|
|
43
|
-
* // requirement
|
|
47
|
+
* // Inspect the EIP-712 payload (requirement.action.typedData) or sign via requirement.sign(...).
|
|
44
48
|
* ```
|
|
45
49
|
*/
|
|
46
50
|
export const encodeBlueSignatureAuthorization = async (viemClient, params) => {
|
|
47
|
-
const { authorized, chainId, nonce, isAuthorized = true } = params;
|
|
51
|
+
const { owner, authorized, chainId, nonce, isAuthorized = true } = params;
|
|
48
52
|
if (viemClient.chain?.id !== chainId) {
|
|
49
53
|
throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
50
54
|
}
|
|
@@ -54,30 +58,25 @@ export const encodeBlueSignatureAuthorization = async (viemClient, params) => {
|
|
|
54
58
|
// `getBlueAuthorizationRequirement` resolver guards. An omitted deadline defaults to two hours
|
|
55
59
|
// from now and is always valid.
|
|
56
60
|
if (params.deadline != null) {
|
|
57
|
-
|
|
58
|
-
throw new NonPositiveInputError("deadline", params.deadline);
|
|
59
|
-
}
|
|
60
|
-
if (params.deadline > maxUint256) {
|
|
61
|
-
throw new InputExceedsMaxError({
|
|
62
|
-
field: "deadline",
|
|
63
|
-
value: params.deadline,
|
|
64
|
-
max: maxUint256,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
61
|
+
validateDeadline(params.deadline);
|
|
67
62
|
const timestamp = Time.timestamp();
|
|
68
63
|
if (params.deadline <= timestamp) {
|
|
69
64
|
throw new ExpiredDeadlineError(params.deadline, timestamp);
|
|
70
65
|
}
|
|
71
66
|
}
|
|
72
67
|
const deadline = params.deadline ?? Time.timestamp() + Time.s.from.h(2n);
|
|
68
|
+
const typedData = deepFreeze(getAuthorizationTypedData({ authorizer: owner, authorized, isAuthorized, nonce, deadline }, chainId));
|
|
73
69
|
const action = {
|
|
74
70
|
type: "authorization",
|
|
75
71
|
args: { authorized, isAuthorized, deadline },
|
|
72
|
+
typedData,
|
|
76
73
|
};
|
|
77
74
|
return {
|
|
78
75
|
action,
|
|
79
76
|
async sign(client, userAddress) {
|
|
80
|
-
|
|
77
|
+
// The authorizer is fixed at build time (the fetched nonce is owner-specific), so a different
|
|
78
|
+
// signer cannot produce a valid authorization for it.
|
|
79
|
+
validateUserAddress(userAddress, owner);
|
|
81
80
|
const signature = await signAndVerifyTypedData({
|
|
82
81
|
client,
|
|
83
82
|
userAddress,
|
|
@@ -85,7 +84,7 @@ export const encodeBlueSignatureAuthorization = async (viemClient, params) => {
|
|
|
85
84
|
});
|
|
86
85
|
return deepFreeze({
|
|
87
86
|
args: {
|
|
88
|
-
owner
|
|
87
|
+
owner,
|
|
89
88
|
authorized,
|
|
90
89
|
isAuthorized,
|
|
91
90
|
nonce,
|
|
@@ -11,12 +11,12 @@ interface EncodeErc20ApprovalParams {
|
|
|
11
11
|
* Encodes a deep-frozen ERC-20 approval transaction for a supported SDK spender.
|
|
12
12
|
*
|
|
13
13
|
* Caps `amount` at the per-chain, per-token maximum from `MAX_TOKEN_APPROVALS` (defaults to
|
|
14
|
-
* `maxUint256`). Used by {@link getRequirementsApproval}
|
|
14
|
+
* `maxUint256`). Used by {@link getRequirementsApproval}.
|
|
15
15
|
*
|
|
16
16
|
* @param params - Encoding parameters.
|
|
17
17
|
* @param params.token - ERC-20 token address to approve.
|
|
18
|
-
* @param params.spender - Address granted the allowance. Must be
|
|
19
|
-
*
|
|
18
|
+
* @param params.spender - Address granted the allowance. Must be Permit2, Midnight,
|
|
19
|
+
* MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
20
20
|
* @param params.amount - Allowance amount before per-token cap.
|
|
21
21
|
* @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
|
|
22
22
|
* @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
|
|
@@ -28,7 +28,7 @@ interface EncodeErc20ApprovalParams {
|
|
|
28
28
|
*
|
|
29
29
|
* const tx = encodeErc20Approval({
|
|
30
30
|
* token: USDC,
|
|
31
|
-
* spender:
|
|
31
|
+
* spender: blueBundlesV1,
|
|
32
32
|
* amount: 1_000_000n,
|
|
33
33
|
* chainId: 1,
|
|
34
34
|
* });
|
|
@@ -7,12 +7,12 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
|
|
|
7
7
|
* Encodes a deep-frozen ERC-20 approval transaction for a supported SDK spender.
|
|
8
8
|
*
|
|
9
9
|
* Caps `amount` at the per-chain, per-token maximum from `MAX_TOKEN_APPROVALS` (defaults to
|
|
10
|
-
* `maxUint256`). Used by {@link getRequirementsApproval}
|
|
10
|
+
* `maxUint256`). Used by {@link getRequirementsApproval}.
|
|
11
11
|
*
|
|
12
12
|
* @param params - Encoding parameters.
|
|
13
13
|
* @param params.token - ERC-20 token address to approve.
|
|
14
|
-
* @param params.spender - Address granted the allowance. Must be
|
|
15
|
-
*
|
|
14
|
+
* @param params.spender - Address granted the allowance. Must be Permit2, Midnight,
|
|
15
|
+
* MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
16
16
|
* @param params.amount - Allowance amount before per-token cap.
|
|
17
17
|
* @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
|
|
18
18
|
* @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
|
|
@@ -24,7 +24,7 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
|
|
|
24
24
|
*
|
|
25
25
|
* const tx = encodeErc20Approval({
|
|
26
26
|
* token: USDC,
|
|
27
|
-
* spender:
|
|
27
|
+
* spender: blueBundlesV1,
|
|
28
28
|
* amount: 1_000_000n,
|
|
29
29
|
* chainId: 1,
|
|
30
30
|
* });
|
|
@@ -38,7 +38,6 @@ export const encodeErc20Approval = (params) => {
|
|
|
38
38
|
chainId,
|
|
39
39
|
spender,
|
|
40
40
|
allowed: [
|
|
41
|
-
"generalAdapter1",
|
|
42
41
|
"permit2",
|
|
43
42
|
"midnight",
|
|
44
43
|
"midnightBundles",
|