@morpho-org/morpho-sdk 10.0.1 → 10.1.0-next.0
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/README.md +31 -10
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +5 -1
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +3 -8
- package/lib/cjs/actions/blue/refinanceValidation.d.ts +19 -0
- package/lib/cjs/actions/blue/refinanceValidation.js +46 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +4 -20
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +7 -21
- package/lib/cjs/actions/requirements/validateClientChainId.d.ts +1 -26
- package/lib/cjs/actions/requirements/validateClientChainId.js +2 -31
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +2 -1
- package/lib/cjs/actions/vaultV2/forceRedeem.js +20 -2
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/entities/blue/blue.js +24 -55
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +2 -5
- package/lib/cjs/entities/requirements/getErc2612Permit.js +9 -58
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/cjs/entities/vaultV2/vaultV2.js +39 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +6 -2
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -1
- package/lib/cjs/helpers/deadShares.js +3 -0
- package/lib/cjs/helpers/quoteBlueRepay.d.ts +16 -0
- package/lib/cjs/helpers/quoteBlueRepay.js +46 -0
- package/lib/cjs/helpers/tokenApproval.d.ts +14 -0
- package/lib/cjs/helpers/tokenApproval.js +20 -0
- package/lib/cjs/helpers/validate.d.ts +1 -1
- package/lib/cjs/helpers/validate.js +2 -2
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +13 -1
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/reads/readErc2612Permit.d.ts +22 -0
- package/lib/cjs/reads/readErc2612Permit.js +77 -0
- package/lib/cjs/reads/validateClientChainId.d.ts +26 -0
- package/lib/cjs/reads/validateClientChainId.js +34 -0
- package/lib/cjs/transactionPlan/blue/authorization.d.ts +23 -0
- package/lib/cjs/transactionPlan/blue/authorization.js +128 -0
- package/lib/cjs/transactionPlan/blue/borrow.d.ts +80 -0
- package/lib/cjs/transactionPlan/blue/borrow.js +248 -0
- package/lib/cjs/transactionPlan/blue/prepare.d.ts +102 -0
- package/lib/cjs/transactionPlan/blue/prepare.js +191 -0
- package/lib/cjs/transactionPlan/blue/refinance.d.ts +93 -0
- package/lib/cjs/transactionPlan/blue/refinance.js +281 -0
- package/lib/cjs/transactionPlan/blue/refinanceValidation.d.ts +11 -0
- package/lib/cjs/transactionPlan/blue/refinanceValidation.js +20 -0
- package/lib/cjs/transactionPlan/blue/repay.d.ts +80 -0
- package/lib/cjs/transactionPlan/blue/repay.js +229 -0
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.d.ts +98 -0
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +379 -0
- package/lib/cjs/transactionPlan/blue/supply.d.ts +181 -0
- package/lib/cjs/transactionPlan/blue/supply.js +238 -0
- package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +97 -0
- package/lib/cjs/transactionPlan/blue/supplyCollateral.js +231 -0
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.d.ts +102 -0
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +395 -0
- package/lib/cjs/transactionPlan/blue/withdraw.d.ts +136 -0
- package/lib/cjs/transactionPlan/blue/withdraw.js +340 -0
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +123 -0
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +246 -0
- package/lib/cjs/transactionPlan/deposit.js +8 -19
- package/lib/cjs/transactionPlan/error.d.ts +50 -0
- package/lib/cjs/transactionPlan/error.js +60 -1
- package/lib/cjs/transactionPlan/getTokenPermit.d.ts +17 -8
- package/lib/cjs/transactionPlan/getTokenPermit.js +35 -7
- package/lib/cjs/transactionPlan/index.d.ts +21 -1
- package/lib/cjs/transactionPlan/index.js +27 -5
- package/lib/cjs/transactionPlan/intent.d.ts +2 -2
- package/lib/cjs/transactionPlan/intent.js +8 -4
- package/lib/cjs/transactionPlan/permit.d.ts +16 -2
- package/lib/cjs/transactionPlan/permit.js +77 -45
- package/lib/cjs/transactionPlan/plan.d.ts +67 -12
- package/lib/cjs/transactionPlan/plan.js +284 -50
- package/lib/cjs/transactionPlan/requirements.d.ts +14 -5
- package/lib/cjs/transactionPlan/requirements.js +30 -12
- package/lib/cjs/transactionPlan/serde.d.ts +7 -4
- package/lib/cjs/transactionPlan/serde.js +80 -61
- package/lib/cjs/transactionPlan/types.d.ts +141 -13
- package/lib/cjs/transactionPlan/validateActions.js +11 -1
- package/lib/cjs/transactionPlan/validation.d.ts +8 -0
- package/lib/cjs/transactionPlan/validation.js +90 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +1 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +1 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +1 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +1 -0
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +4 -9
- package/lib/esm/actions/blue/refinanceValidation.d.ts +19 -0
- package/lib/esm/actions/blue/refinanceValidation.js +41 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -8
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -21
- package/lib/esm/actions/requirements/getRequirementsApproval.js +7 -21
- package/lib/esm/actions/requirements/validateClientChainId.d.ts +1 -26
- package/lib/esm/actions/requirements/validateClientChainId.js +1 -30
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -1
- package/lib/esm/actions/vaultV2/forceRedeem.js +20 -2
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.js +26 -57
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/requirements/getErc2612Permit.d.ts +2 -5
- package/lib/esm/entities/requirements/getErc2612Permit.js +9 -58
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/esm/entities/vaultV2/vaultV2.js +40 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +6 -2
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +4 -1
- package/lib/esm/helpers/quoteBlueRepay.d.ts +16 -0
- package/lib/esm/helpers/quoteBlueRepay.js +42 -0
- package/lib/esm/helpers/tokenApproval.d.ts +14 -0
- package/lib/esm/helpers/tokenApproval.js +16 -0
- package/lib/esm/helpers/validate.d.ts +1 -1
- package/lib/esm/helpers/validate.js +3 -3
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/reads/readErc2612Permit.d.ts +22 -0
- package/lib/esm/reads/readErc2612Permit.js +73 -0
- package/lib/esm/reads/validateClientChainId.d.ts +26 -0
- package/lib/esm/reads/validateClientChainId.js +30 -0
- package/lib/esm/transactionPlan/blue/authorization.d.ts +23 -0
- package/lib/esm/transactionPlan/blue/authorization.js +122 -0
- package/lib/esm/transactionPlan/blue/borrow.d.ts +80 -0
- package/lib/esm/transactionPlan/blue/borrow.js +243 -0
- package/lib/esm/transactionPlan/blue/prepare.d.ts +102 -0
- package/lib/esm/transactionPlan/blue/prepare.js +187 -0
- package/lib/esm/transactionPlan/blue/refinance.d.ts +93 -0
- package/lib/esm/transactionPlan/blue/refinance.js +276 -0
- package/lib/esm/transactionPlan/blue/refinanceValidation.d.ts +11 -0
- package/lib/esm/transactionPlan/blue/refinanceValidation.js +17 -0
- package/lib/esm/transactionPlan/blue/repay.d.ts +80 -0
- package/lib/esm/transactionPlan/blue/repay.js +223 -0
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.d.ts +98 -0
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +373 -0
- package/lib/esm/transactionPlan/blue/supply.d.ts +181 -0
- package/lib/esm/transactionPlan/blue/supply.js +232 -0
- package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +97 -0
- package/lib/esm/transactionPlan/blue/supplyCollateral.js +225 -0
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.d.ts +102 -0
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +389 -0
- package/lib/esm/transactionPlan/blue/withdraw.d.ts +136 -0
- package/lib/esm/transactionPlan/blue/withdraw.js +334 -0
- package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +123 -0
- package/lib/esm/transactionPlan/blue/withdrawCollateral.js +240 -0
- package/lib/esm/transactionPlan/deposit.js +9 -20
- package/lib/esm/transactionPlan/error.d.ts +50 -0
- package/lib/esm/transactionPlan/error.js +57 -0
- package/lib/esm/transactionPlan/getTokenPermit.d.ts +17 -8
- package/lib/esm/transactionPlan/getTokenPermit.js +35 -7
- package/lib/esm/transactionPlan/index.d.ts +21 -1
- package/lib/esm/transactionPlan/index.js +11 -1
- package/lib/esm/transactionPlan/intent.d.ts +2 -2
- package/lib/esm/transactionPlan/intent.js +8 -4
- package/lib/esm/transactionPlan/permit.d.ts +16 -2
- package/lib/esm/transactionPlan/permit.js +76 -44
- package/lib/esm/transactionPlan/plan.d.ts +67 -12
- package/lib/esm/transactionPlan/plan.js +279 -46
- package/lib/esm/transactionPlan/requirements.d.ts +14 -5
- package/lib/esm/transactionPlan/requirements.js +30 -12
- package/lib/esm/transactionPlan/serde.d.ts +7 -4
- package/lib/esm/transactionPlan/serde.js +73 -54
- package/lib/esm/transactionPlan/types.d.ts +141 -13
- package/lib/esm/transactionPlan/validateActions.js +11 -1
- package/lib/esm/transactionPlan/validation.d.ts +8 -0
- package/lib/esm/transactionPlan/validation.js +88 -1
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.js +1 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +1 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.js +1 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +1 -0
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +7 -7
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BundlesPermitMismatchError, InvalidSignatureError, } from "../types/error.js";
|
|
2
2
|
import { validateApprovalPlanAction } from "./approval.js";
|
|
3
|
+
import { validateMorphoAuthorizationPlanAction, validateMorphoAuthorizationPlanRequest, } from "./blue/authorization.js";
|
|
4
|
+
import { validateBorrowPlanAction } from "./blue/borrow.js";
|
|
5
|
+
import { validateRefinancePlanAction } from "./blue/refinance.js";
|
|
6
|
+
import { validateBlueRepayPlanAction } from "./blue/repay.js";
|
|
7
|
+
import { validateRepayWithdrawCollateralPlanAction } from "./blue/repayWithdrawCollateral.js";
|
|
8
|
+
import { validateBlueSupplyPlanAction } from "./blue/supply.js";
|
|
9
|
+
import { validateSupplyCollateralPlanAction } from "./blue/supplyCollateral.js";
|
|
10
|
+
import { validateSupplyCollateralBorrowPlanAction } from "./blue/supplyCollateralBorrow.js";
|
|
11
|
+
import { validateBlueWithdrawPlanAction } from "./blue/withdraw.js";
|
|
12
|
+
import { validateBlueWithdrawCollateralPlanAction } from "./blue/withdrawCollateral.js";
|
|
3
13
|
import { validateDepositPlanAction } from "./deposit.js";
|
|
4
14
|
import { InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "./error.js";
|
|
5
15
|
import { validatePermitPlanRequest } from "./permit.js";
|
|
6
|
-
import { getPendingSignatureRequests } from "./plan.js";
|
|
16
|
+
import { getPendingSignatureRequests, verifyPlanSignature } from "./plan.js";
|
|
7
17
|
import { validateRedeemPlanAction } from "./redeem.js";
|
|
8
18
|
import { validateTransactionPlanActions } from "./validateActions.js";
|
|
9
|
-
import { getPlanObject, validatePlanField, validatePlanFields, } from "./validation.js";
|
|
19
|
+
import { getPlanObject, validatePlanField, validatePlanFields, validateTransactionPlanHeader, } from "./validation.js";
|
|
10
20
|
import { validateInKindRedeemPlanAction as validateVaultV1InKindRedeemPlanAction } from "./vaultv1/inKindRedeem.js";
|
|
11
21
|
import { validateMigrateToV2PlanAction } from "./vaultv1/migrateToV2.js";
|
|
12
22
|
import { validateForceRedeemPlanAction } from "./vaultv2/forceRedeem.js";
|
|
@@ -16,12 +26,22 @@ import { validateTransactionPlanVersion } from "./version.js";
|
|
|
16
26
|
import { validateWithdrawPlanAction } from "./withdraw.js";
|
|
17
27
|
const actionValidators = {
|
|
18
28
|
vaultV1InKindRedeem: validateVaultV1InKindRedeemPlanAction,
|
|
29
|
+
blueSupply: validateBlueSupplyPlanAction,
|
|
30
|
+
blueSupplyCollateral: validateSupplyCollateralPlanAction,
|
|
31
|
+
blueBorrow: validateBorrowPlanAction,
|
|
32
|
+
blueSupplyCollateralBorrow: validateSupplyCollateralBorrowPlanAction,
|
|
33
|
+
blueRepay: validateBlueRepayPlanAction,
|
|
34
|
+
blueWithdraw: validateBlueWithdrawPlanAction,
|
|
35
|
+
blueWithdrawCollateral: validateBlueWithdrawCollateralPlanAction,
|
|
36
|
+
blueRepayWithdrawCollateral: validateRepayWithdrawCollateralPlanAction,
|
|
37
|
+
blueRefinance: validateRefinancePlanAction,
|
|
19
38
|
erc20Approval: validateApprovalPlanAction,
|
|
20
39
|
vaultV2Redeem: validateRedeemPlanAction,
|
|
21
40
|
vaultV2ForceWithdraw: validateForceWithdrawPlanAction,
|
|
22
41
|
vaultV1Deposit: validateDepositPlanAction,
|
|
23
42
|
vaultV1Redeem: validateRedeemPlanAction,
|
|
24
43
|
vaultV1MigrateToV2: validateMigrateToV2PlanAction,
|
|
44
|
+
morphoAuthorization: validateMorphoAuthorizationPlanAction,
|
|
25
45
|
vaultV2Deposit: validateDepositPlanAction,
|
|
26
46
|
vaultV2Withdraw: validateWithdrawPlanAction,
|
|
27
47
|
vaultV2ForceRedeem: validateForceRedeemPlanAction,
|
|
@@ -49,11 +69,14 @@ export function serializeTransactionPlan(plan) {
|
|
|
49
69
|
/**
|
|
50
70
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
51
71
|
* Restores bigint fields and validates version, action/request shapes, uint256 ranges, unique IDs,
|
|
52
|
-
* references, per-action chain/account and
|
|
53
|
-
* Extra keys are allowed. No clock or RPC is used: expiry, live state
|
|
54
|
-
* action-layer business constraints are not checked.
|
|
72
|
+
* references, per-action chain/account and signature-request consistency, including signed requests.
|
|
73
|
+
* Extra keys are allowed. No clock or RPC is used: current expiry, live state and
|
|
74
|
+
* action-layer business constraints are not checked. Stored signatures are recovered offline.
|
|
75
|
+
* Permits bind owner, token, spender, value, nonce, deadline and chain; Morpho authorizations bind
|
|
76
|
+
* owner, authorized address, nonce, deadline and chain, not operation amounts, markets or referral fees/recipients.
|
|
77
|
+
* Parsing does not prove authenticity or intent for unsigned fields;
|
|
55
78
|
* tampered but well-formed, internally consistent plans pass. Integrators must protect stored plans.
|
|
56
|
-
*
|
|
79
|
+
* Integrators must protect unsigned stored fields even when all signatures verify.
|
|
57
80
|
* @param json - JSON previously returned by `serializeTransactionPlan`.
|
|
58
81
|
* @returns The restored plan.
|
|
59
82
|
* @throws {InvalidTransactionPlanError} At the first malformed JSON, field shape or consistency failure, exposing its JSON `path` and `reason`.
|
|
@@ -95,15 +118,8 @@ export function parseTransactionPlan(json) {
|
|
|
95
118
|
signatureRequests: "array",
|
|
96
119
|
},
|
|
97
120
|
});
|
|
98
|
-
if (plan.calldataOrigin !== undefined) {
|
|
99
|
-
validatePlanField(plan.calldataOrigin, {
|
|
100
|
-
path: "$.calldataOrigin",
|
|
101
|
-
type: "hex",
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
121
|
const steps = plan.steps;
|
|
105
122
|
const requests = plan.signatureRequests;
|
|
106
|
-
const stepIds = new Set();
|
|
107
123
|
for (const [index, value] of steps.entries()) {
|
|
108
124
|
const path = `$.steps[${index}]`;
|
|
109
125
|
const step = getPlanObject(value, path);
|
|
@@ -111,13 +127,6 @@ export function parseTransactionPlan(json) {
|
|
|
111
127
|
path,
|
|
112
128
|
fields: { id: "string", label: "string" },
|
|
113
129
|
});
|
|
114
|
-
if (stepIds.has(step.id)) {
|
|
115
|
-
throw new InvalidTransactionPlanError({
|
|
116
|
-
path: `${path}.id`,
|
|
117
|
-
reason: "expected a unique step ID",
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
stepIds.add(step.id);
|
|
121
130
|
const action = getPlanObject(step.action, `${path}.action`);
|
|
122
131
|
validatePlanField(action.type, {
|
|
123
132
|
path: `${path}.action.type`,
|
|
@@ -135,18 +144,6 @@ export function parseTransactionPlan(json) {
|
|
|
135
144
|
fields: { chainId: "positive safe integer", account: "address" },
|
|
136
145
|
});
|
|
137
146
|
actionValidators[step.action.type](action, path);
|
|
138
|
-
if (inputs.chainId !== plan.chainId) {
|
|
139
|
-
throw new InvalidTransactionPlanError({
|
|
140
|
-
path: `${path}.inputs.chainId`,
|
|
141
|
-
reason: "expected the plan chainId",
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
if (!isAddressEqual(inputs.account, plan.account)) {
|
|
145
|
-
throw new InvalidTransactionPlanError({
|
|
146
|
-
path: `${path}.inputs.account`,
|
|
147
|
-
reason: "expected the plan account",
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
147
|
}
|
|
151
148
|
const requestIds = new Set();
|
|
152
149
|
for (const [index, value] of requests.entries()) {
|
|
@@ -156,20 +153,8 @@ export function parseTransactionPlan(json) {
|
|
|
156
153
|
path,
|
|
157
154
|
fields: { id: "string", kind: "string" },
|
|
158
155
|
});
|
|
159
|
-
if (requestIds.has(request.id)) {
|
|
160
|
-
throw new InvalidTransactionPlanError({
|
|
161
|
-
path: `${path}.id`,
|
|
162
|
-
reason: "expected a unique signature request ID",
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
156
|
requestIds.add(request.id);
|
|
166
|
-
|
|
167
|
-
throw new InvalidTransactionPlanError({
|
|
168
|
-
path: `${path}.kind`,
|
|
169
|
-
reason: "expected a supported signature request kind (permit)",
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
validatePermitPlanRequest(request, path);
|
|
157
|
+
validatePlanRequest(request, path);
|
|
173
158
|
}
|
|
174
159
|
for (const [index, step] of steps.entries()) {
|
|
175
160
|
if (!("signatureRequestIds" in step.action)) {
|
|
@@ -188,17 +173,36 @@ export function parseTransactionPlan(json) {
|
|
|
188
173
|
}
|
|
189
174
|
}
|
|
190
175
|
const result = restored;
|
|
176
|
+
// Apply the same context and deadline rules as direct builders.
|
|
177
|
+
validateTransactionPlanHeader(result);
|
|
191
178
|
try {
|
|
192
|
-
//
|
|
193
|
-
getPendingSignatureRequests(
|
|
194
|
-
...result,
|
|
195
|
-
signatureRequests: result.signatureRequests.map((request) => ({
|
|
196
|
-
...request,
|
|
197
|
-
signature: undefined,
|
|
198
|
-
})),
|
|
199
|
-
});
|
|
179
|
+
// Check references and request/action consistency, including restored signatures.
|
|
180
|
+
getPendingSignatureRequests(result);
|
|
200
181
|
}
|
|
201
182
|
catch (cause) {
|
|
183
|
+
if (cause instanceof InvalidSignatureError ||
|
|
184
|
+
cause instanceof BundlesPermitMismatchError) {
|
|
185
|
+
const index = result.signatureRequests.findIndex((request) => {
|
|
186
|
+
if (request.signature === undefined) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
// Locate the failed stored signature without duplicating recovery logic.
|
|
191
|
+
verifyPlanSignature(request, request.signature);
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
throw new InvalidTransactionPlanError({
|
|
199
|
+
path: `$.signatureRequests[${index}].signature`,
|
|
200
|
+
reason: cause instanceof InvalidSignatureError
|
|
201
|
+
? "expected a valid low-s signature from the request owner"
|
|
202
|
+
: "expected a compact or serialized ECDSA signature",
|
|
203
|
+
cause,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
202
206
|
if (cause instanceof TransactionPlanSignatureMismatchError) {
|
|
203
207
|
const index = result.signatureRequests.findIndex((request) => request.id === cause.id);
|
|
204
208
|
let field = `typedData.${cause.field}`;
|
|
@@ -225,3 +229,18 @@ export function parseTransactionPlan(json) {
|
|
|
225
229
|
}
|
|
226
230
|
return result;
|
|
227
231
|
}
|
|
232
|
+
function validatePlanRequest(request, path) {
|
|
233
|
+
switch (request.kind) {
|
|
234
|
+
case "permit":
|
|
235
|
+
validatePermitPlanRequest(request, path);
|
|
236
|
+
break;
|
|
237
|
+
case "morphoAuthorization":
|
|
238
|
+
validateMorphoAuthorizationPlanRequest(request, path);
|
|
239
|
+
break;
|
|
240
|
+
default:
|
|
241
|
+
throw new InvalidTransactionPlanError({
|
|
242
|
+
path: `${path}.kind`,
|
|
243
|
+
reason: "expected a supported signature request kind (permit or morphoAuthorization)",
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { InputMarketParams } from "@morpho-org/blue-sdk";
|
|
1
|
+
import type { InputMarketParams, MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address, Hex } from "viem";
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlueRepayParams } from "../actions/blue/repay.js";
|
|
4
|
+
import type { BlueRepayWithdrawCollateralParams } from "../actions/blue/repayWithdrawCollateral.js";
|
|
5
|
+
import type { BlueSupplyCollateralBorrowParams } from "../actions/blue/supplyCollateralBorrow.js";
|
|
6
|
+
import type { AuthorizationSignatureArgs, PermitAction, RequirementTypedData, VaultV1MigrateToV2AmountArgs, VaultV2BlueReallocation } from "../types/index.js";
|
|
4
7
|
interface ActionInputs {
|
|
5
8
|
readonly chainId: number;
|
|
6
9
|
readonly account: Address;
|
|
@@ -23,12 +26,11 @@ type VaultSignatureRequestIds = {
|
|
|
23
26
|
readonly tokenPermit?: string;
|
|
24
27
|
};
|
|
25
28
|
/**
|
|
26
|
-
*
|
|
27
|
-
* Recipes supported by vault plans. Each `type` equals the `action.type` of the
|
|
28
|
-
* {@link TransactionAction} it builds.
|
|
29
|
+
* Recipes supported by TransactionPlan.
|
|
29
30
|
* Snapshot-derived values such as the asset and the quote are fixed on `inputs` at preparation;
|
|
30
31
|
* each action also carries its own chain and account on `inputs`.
|
|
31
|
-
*
|
|
32
|
+
* The role map `signatureRequestIds` is a step's only request reference.
|
|
33
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
32
34
|
*/
|
|
33
35
|
export type Action = {
|
|
34
36
|
readonly type: "vaultV2ForceRedeem";
|
|
@@ -68,6 +70,96 @@ export type Action = {
|
|
|
68
70
|
readonly marketParamsList: readonly InputMarketParams[];
|
|
69
71
|
};
|
|
70
72
|
readonly signatureRequestIds: VaultSignatureRequestIds;
|
|
73
|
+
} | {
|
|
74
|
+
readonly type: "blueSupply";
|
|
75
|
+
readonly inputs: ActionInputs & {
|
|
76
|
+
readonly marketParams: Readonly<InputMarketParams>;
|
|
77
|
+
readonly assets: bigint;
|
|
78
|
+
readonly nativeAssets?: bigint;
|
|
79
|
+
readonly deadline: bigint;
|
|
80
|
+
readonly referralFeePct: bigint;
|
|
81
|
+
readonly referralFeeRecipient: Address;
|
|
82
|
+
};
|
|
83
|
+
readonly signatureRequestIds: VaultSignatureRequestIds;
|
|
84
|
+
} | {
|
|
85
|
+
readonly type: "blueBorrow";
|
|
86
|
+
readonly inputs: ActionInputs & {
|
|
87
|
+
readonly marketParams: MarketParams;
|
|
88
|
+
readonly borrowAssets: bigint;
|
|
89
|
+
readonly maxLtv: bigint;
|
|
90
|
+
readonly reallocations: readonly VaultV2BlueReallocation[];
|
|
91
|
+
readonly deadline: bigint;
|
|
92
|
+
readonly referralFeePct: bigint;
|
|
93
|
+
readonly referralFeeRecipient: Address;
|
|
94
|
+
readonly authorizationNonce: bigint;
|
|
95
|
+
};
|
|
96
|
+
readonly signatureRequestIds: {
|
|
97
|
+
readonly morphoAuthorization?: string;
|
|
98
|
+
};
|
|
99
|
+
} | {
|
|
100
|
+
readonly type: "blueSupplyCollateralBorrow";
|
|
101
|
+
readonly inputs: ActionInputs & Omit<BlueSupplyCollateralBorrowParams["args"], "userAddress" | "requirementSignature" | "authorizationSignature" | "reallocations" | "nativeAmount"> & {
|
|
102
|
+
readonly marketParams: BlueSupplyCollateralBorrowParams["market"]["marketParams"];
|
|
103
|
+
readonly nativeAssets?: bigint;
|
|
104
|
+
readonly reallocations: readonly VaultV2BlueReallocation[];
|
|
105
|
+
readonly authorizationNonce?: bigint;
|
|
106
|
+
};
|
|
107
|
+
readonly signatureRequestIds: {
|
|
108
|
+
readonly tokenPermit?: string;
|
|
109
|
+
readonly morphoAuthorization?: string;
|
|
110
|
+
};
|
|
111
|
+
} | {
|
|
112
|
+
readonly type: "blueRepay";
|
|
113
|
+
readonly inputs: ActionInputs & {
|
|
114
|
+
readonly marketParams: InputMarketParams;
|
|
115
|
+
readonly referralFeePct: bigint;
|
|
116
|
+
readonly referralFeeRecipient: Address;
|
|
117
|
+
readonly nativeAssets?: bigint;
|
|
118
|
+
} & Omit<BlueRepayParams["args"], "userAddress" | "requirementSignature" | "nativeAmount">;
|
|
119
|
+
readonly signatureRequestIds: VaultSignatureRequestIds;
|
|
120
|
+
} | {
|
|
121
|
+
readonly type: "blueWithdraw";
|
|
122
|
+
readonly inputs: ActionInputs & {
|
|
123
|
+
readonly marketParams: Pick<MarketParams, "loanToken" | "collateralToken" | "oracle" | "irm" | "lltv">;
|
|
124
|
+
readonly withdrawAssets: bigint;
|
|
125
|
+
readonly withdrawShares: bigint;
|
|
126
|
+
readonly reallocations: readonly VaultV2BlueReallocation[];
|
|
127
|
+
readonly deadline: bigint;
|
|
128
|
+
readonly referralFeePct: bigint;
|
|
129
|
+
readonly referralFeeRecipient: Address;
|
|
130
|
+
/** Morpho nonce pinned when preparing an inline authorization signature. */
|
|
131
|
+
readonly authorizationNonce?: bigint;
|
|
132
|
+
};
|
|
133
|
+
readonly signatureRequestIds: {
|
|
134
|
+
readonly morphoAuthorization?: string;
|
|
135
|
+
};
|
|
136
|
+
} | {
|
|
137
|
+
readonly type: "blueWithdrawCollateral";
|
|
138
|
+
readonly signatureRequestIds: {
|
|
139
|
+
readonly morphoAuthorization?: string;
|
|
140
|
+
};
|
|
141
|
+
readonly inputs: ActionInputs & {
|
|
142
|
+
readonly marketParams: Readonly<InputMarketParams>;
|
|
143
|
+
readonly collateralAssets: bigint;
|
|
144
|
+
readonly maxLtv: bigint;
|
|
145
|
+
readonly authorizationNonce?: bigint;
|
|
146
|
+
readonly deadline: bigint;
|
|
147
|
+
readonly referralFeePct: bigint;
|
|
148
|
+
readonly referralFeeRecipient: Address;
|
|
149
|
+
};
|
|
150
|
+
} | {
|
|
151
|
+
readonly type: "blueRepayWithdrawCollateral";
|
|
152
|
+
readonly inputs: ActionInputs & Omit<BlueRepayWithdrawCollateralParams["args"], "userAddress" | "requirementSignature" | "authorizationSignature" | "nativeAmount"> & {
|
|
153
|
+
readonly authorizationNonce?: bigint;
|
|
154
|
+
readonly nativeAssets?: bigint;
|
|
155
|
+
readonly referralFeePct: bigint;
|
|
156
|
+
readonly referralFeeRecipient: Address;
|
|
157
|
+
readonly marketParams: Pick<BlueRepayWithdrawCollateralParams["market"]["marketParams"], "loanToken" | "collateralToken" | "oracle" | "irm" | "lltv">;
|
|
158
|
+
};
|
|
159
|
+
readonly signatureRequestIds: {
|
|
160
|
+
readonly tokenPermit?: string;
|
|
161
|
+
readonly morphoAuthorization?: string;
|
|
162
|
+
};
|
|
71
163
|
} | {
|
|
72
164
|
readonly type: "erc20Approval";
|
|
73
165
|
readonly inputs: ActionInputs & {
|
|
@@ -80,6 +172,19 @@ export type Action = {
|
|
|
80
172
|
readonly shares: bigint;
|
|
81
173
|
readonly assets?: never;
|
|
82
174
|
});
|
|
175
|
+
} | {
|
|
176
|
+
readonly type: "blueSupplyCollateral";
|
|
177
|
+
readonly inputs: ActionInputs & {
|
|
178
|
+
readonly marketParams: Omit<MarketParams, "liquidationIncentiveFactor">;
|
|
179
|
+
readonly collateralAssets: bigint;
|
|
180
|
+
readonly nativeAssets?: bigint;
|
|
181
|
+
readonly deadline: bigint;
|
|
182
|
+
readonly referralFeePct: bigint;
|
|
183
|
+
readonly referralFeeRecipient: Address;
|
|
184
|
+
};
|
|
185
|
+
readonly signatureRequestIds: {
|
|
186
|
+
readonly tokenPermit?: string;
|
|
187
|
+
};
|
|
83
188
|
} | {
|
|
84
189
|
readonly type: "vaultV2Deposit";
|
|
85
190
|
readonly inputs: VaultInputs & ({
|
|
@@ -153,6 +258,25 @@ export type Action = {
|
|
|
153
258
|
readonly minSharePriceE27: bigint;
|
|
154
259
|
};
|
|
155
260
|
readonly signatureRequestIds: VaultSignatureRequestIds;
|
|
261
|
+
} | {
|
|
262
|
+
readonly type: "blueRefinance";
|
|
263
|
+
readonly inputs: ActionInputs & {
|
|
264
|
+
readonly sourceMarketParams: Readonly<MarketParams>;
|
|
265
|
+
readonly destinationMarketParams: Readonly<MarketParams>;
|
|
266
|
+
readonly maxLtv: bigint;
|
|
267
|
+
readonly deadline: bigint;
|
|
268
|
+
readonly referralFeePct: bigint;
|
|
269
|
+
readonly referralFeeRecipient: Address;
|
|
270
|
+
readonly reallocations: readonly VaultV2BlueReallocation[];
|
|
271
|
+
/** Expected Morpho nonce when the migration consumes an inline authorization. */
|
|
272
|
+
readonly authorizationNonce?: bigint;
|
|
273
|
+
};
|
|
274
|
+
readonly signatureRequestIds: {
|
|
275
|
+
readonly morphoAuthorization?: string;
|
|
276
|
+
};
|
|
277
|
+
} | {
|
|
278
|
+
readonly type: "morphoAuthorization";
|
|
279
|
+
readonly inputs: ActionInputs;
|
|
156
280
|
};
|
|
157
281
|
/**
|
|
158
282
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
@@ -164,22 +288,26 @@ export interface Step<TAction extends Action = Action> {
|
|
|
164
288
|
readonly action: TAction;
|
|
165
289
|
}
|
|
166
290
|
/**
|
|
291
|
+
* ERC-2612 permit or Morpho Blue authorization exposed as `{ id, kind, typedData }`.
|
|
292
|
+
* `signature` is undefined until the account signs `typedData`.
|
|
167
293
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
168
|
-
* ERC-2612 permit request exposed as `{ id, kind, typedData }`. `signature` is undefined until the
|
|
169
|
-
* account signs `typedData`. Protocol milestones add further `kind`s such as Blue authorization.
|
|
170
294
|
*/
|
|
171
|
-
export
|
|
295
|
+
export type SignatureRequest = {
|
|
172
296
|
readonly id: string;
|
|
173
|
-
readonly kind: "permit";
|
|
174
297
|
readonly typedData: RequirementTypedData;
|
|
298
|
+
readonly signature?: Hex;
|
|
299
|
+
} & ({
|
|
300
|
+
readonly kind: "permit";
|
|
175
301
|
readonly args: PermitAction["args"] & {
|
|
176
302
|
readonly nonce: bigint;
|
|
177
303
|
};
|
|
178
|
-
|
|
179
|
-
|
|
304
|
+
} | {
|
|
305
|
+
readonly kind: "morphoAuthorization";
|
|
306
|
+
readonly args: Omit<AuthorizationSignatureArgs, "signature" | "isAuthorized">;
|
|
307
|
+
});
|
|
180
308
|
/**
|
|
181
309
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
182
|
-
* Data-only operation prepared for one chain and account from the caller's intent and a
|
|
310
|
+
* Data-only operation prepared for one chain and account from the caller's intent and a protocol
|
|
183
311
|
* snapshot. Every step and signature request carries its own `id`, unique within the plan. Once
|
|
184
312
|
* prepared, a plan is static: only signatures are added before building.
|
|
185
313
|
*/
|
|
@@ -8,10 +8,20 @@ import { UnsupportedTransactionPlanActionError } from "./error.js";
|
|
|
8
8
|
export function validateTransactionPlanActions(steps) {
|
|
9
9
|
for (const step of steps) {
|
|
10
10
|
const actionType = step.action.type;
|
|
11
|
-
if (actionType !== "
|
|
11
|
+
if (actionType !== "blueRefinance" &&
|
|
12
|
+
actionType !== "erc20Approval" &&
|
|
12
13
|
actionType !== "vaultV1Deposit" &&
|
|
13
14
|
actionType !== "vaultV1MigrateToV2" &&
|
|
14
15
|
actionType !== "vaultV1InKindRedeem" &&
|
|
16
|
+
actionType !== "blueSupply" &&
|
|
17
|
+
actionType !== "blueSupplyCollateral" &&
|
|
18
|
+
actionType !== "blueBorrow" &&
|
|
19
|
+
actionType !== "blueSupplyCollateralBorrow" &&
|
|
20
|
+
actionType !== "blueRepay" &&
|
|
21
|
+
actionType !== "blueWithdraw" &&
|
|
22
|
+
actionType !== "blueWithdrawCollateral" &&
|
|
23
|
+
actionType !== "blueRepayWithdrawCollateral" &&
|
|
24
|
+
actionType !== "morphoAuthorization" &&
|
|
15
25
|
actionType !== "vaultV2Deposit" &&
|
|
16
26
|
actionType !== "vaultV2Withdraw" &&
|
|
17
27
|
actionType !== "vaultV2Redeem" &&
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { TransactionPlan } from "./types.js";
|
|
3
|
+
/** @internal Rejects attribution bytes above the preparation and stored-plan limit. */
|
|
4
|
+
export declare function validateCalldataOriginLength(calldataOrigin: string): void;
|
|
5
|
+
/** @internal Validates shared plan context without reading a clock or live state. */
|
|
6
|
+
export declare function validateTransactionPlanHeader(plan: TransactionPlan): void;
|
|
7
|
+
/** @internal Compares an untrusted address without throwing on malformed input. */
|
|
8
|
+
export declare function matchesAddress(value: unknown, expected: Address): boolean;
|
|
1
9
|
/** @internal Scalar and collection shapes used by stored plan fields. */
|
|
2
10
|
type PlanFieldType = "string" | "address" | "hex" | "safe integer" | "positive safe integer" | "uint256 bigint" | "array";
|
|
3
11
|
/** @internal Validates one restored field without coercing it. */
|
|
@@ -1,5 +1,92 @@
|
|
|
1
|
-
import { isAddress, maxUint256 } from "viem";
|
|
1
|
+
import { isAddress, isAddressEqual, maxUint256 } from "viem";
|
|
2
2
|
import { InvalidTransactionPlanError } from "./error.js";
|
|
3
|
+
/** @internal Maximum calldata-origin length in bytes. */
|
|
4
|
+
const MAX_CALLDATA_ORIGIN_BYTES = 1024 * 1024;
|
|
5
|
+
/** @internal Rejects attribution bytes above the preparation and stored-plan limit. */
|
|
6
|
+
export function validateCalldataOriginLength(calldataOrigin) {
|
|
7
|
+
if (calldataOrigin.length > 2 + MAX_CALLDATA_ORIGIN_BYTES * 2) {
|
|
8
|
+
throw new InvalidTransactionPlanError({
|
|
9
|
+
path: "$.calldataOrigin",
|
|
10
|
+
reason: "expected at most 1 MiB",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** @internal Validates shared plan context without reading a clock or live state. */
|
|
15
|
+
export function validateTransactionPlanHeader(plan) {
|
|
16
|
+
validatePlanField(plan.chainId, {
|
|
17
|
+
path: "$.chainId",
|
|
18
|
+
type: "positive safe integer",
|
|
19
|
+
});
|
|
20
|
+
validatePlanField(plan.account, { path: "$.account", type: "address" });
|
|
21
|
+
validatePlanField(plan.expiresAt, {
|
|
22
|
+
path: "$.expiresAt",
|
|
23
|
+
type: "safe integer",
|
|
24
|
+
});
|
|
25
|
+
if (plan.calldataOrigin !== undefined) {
|
|
26
|
+
validatePlanField(plan.calldataOrigin, {
|
|
27
|
+
path: "$.calldataOrigin",
|
|
28
|
+
type: "hex",
|
|
29
|
+
});
|
|
30
|
+
validateCalldataOriginLength(plan.calldataOrigin);
|
|
31
|
+
}
|
|
32
|
+
const stepIds = new Set();
|
|
33
|
+
for (const [index, step] of plan.steps.entries()) {
|
|
34
|
+
const path = `$.steps[${index}]`;
|
|
35
|
+
if (stepIds.has(step.id)) {
|
|
36
|
+
throw new InvalidTransactionPlanError({
|
|
37
|
+
path: `${path}.id`,
|
|
38
|
+
reason: "expected a unique step ID",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
stepIds.add(step.id);
|
|
42
|
+
const { inputs } = step.action;
|
|
43
|
+
if (inputs.chainId !== plan.chainId) {
|
|
44
|
+
throw new InvalidTransactionPlanError({
|
|
45
|
+
path: `${path}.action.inputs.chainId`,
|
|
46
|
+
reason: "expected the plan chainId",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (!matchesAddress(inputs.account, plan.account)) {
|
|
50
|
+
throw new InvalidTransactionPlanError({
|
|
51
|
+
path: `${path}.action.inputs.account`,
|
|
52
|
+
reason: "expected the plan account",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if ("deadline" in inputs &&
|
|
56
|
+
typeof inputs.deadline === "bigint" &&
|
|
57
|
+
inputs.deadline > 0n &&
|
|
58
|
+
inputs.deadline < BigInt(plan.expiresAt)) {
|
|
59
|
+
throw new InvalidTransactionPlanError({
|
|
60
|
+
path: `${path}.action.inputs.deadline`,
|
|
61
|
+
reason: "expected a deadline no earlier than expiresAt",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const requestIds = new Set();
|
|
66
|
+
for (const [index, request] of plan.signatureRequests.entries()) {
|
|
67
|
+
const path = `$.signatureRequests[${index}]`;
|
|
68
|
+
if (requestIds.has(request.id)) {
|
|
69
|
+
throw new InvalidTransactionPlanError({
|
|
70
|
+
path: `${path}.id`,
|
|
71
|
+
reason: "expected a unique signature request ID",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
requestIds.add(request.id);
|
|
75
|
+
if (request.args.deadline < BigInt(plan.expiresAt)) {
|
|
76
|
+
throw new InvalidTransactionPlanError({
|
|
77
|
+
path: `${path}.args.deadline`,
|
|
78
|
+
reason: "expected a deadline no earlier than expiresAt",
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** @internal Compares an untrusted address without throwing on malformed input. */
|
|
84
|
+
export function matchesAddress(value, expected) {
|
|
85
|
+
return (typeof value === "string" &&
|
|
86
|
+
isAddress(value, { strict: false }) &&
|
|
87
|
+
isAddress(expected, { strict: false }) &&
|
|
88
|
+
isAddressEqual(value, expected));
|
|
89
|
+
}
|
|
3
90
|
/** @internal Validates one restored field without coercing it. */
|
|
4
91
|
export function validatePlanField(value, options) {
|
|
5
92
|
const { path, type } = options;
|
|
@@ -58,6 +58,7 @@ export interface VaultV1DepositPlanParams extends DepositPlanParams<AccrualVault
|
|
|
58
58
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
59
59
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
60
60
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
61
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
61
62
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
62
63
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
63
64
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
|
|
@@ -32,6 +32,7 @@ import { getVaultPermit } from "../permit.js";
|
|
|
32
32
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
33
33
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
34
34
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
35
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
35
36
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
36
37
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
37
38
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
|
|
@@ -51,6 +51,7 @@ export interface VaultV1InKindRedeemPlanParams extends Omit<IntentParams, "refer
|
|
|
51
51
|
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
52
52
|
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
53
53
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
54
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
54
55
|
* @throws {ChainIdMismatchError} when the client declares or its RPC serves another chain.
|
|
55
56
|
* @throws {EmptyMarketParamsListError} when no markets are supplied.
|
|
56
57
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
@@ -28,6 +28,7 @@ import { getPlanObject, validatePlanFields } from "../validation.js";
|
|
|
28
28
|
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
29
29
|
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
30
30
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
31
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
31
32
|
* @throws {ChainIdMismatchError} when the client declares or its RPC serves another chain.
|
|
32
33
|
* @throws {EmptyMarketParamsListError} when no markets are supplied.
|
|
33
34
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
@@ -59,6 +59,7 @@ export type VaultV1MigrateToV2PlanParams = Omit<IntentParams, "deployless"> & Re
|
|
|
59
59
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or the selected amount exceeds uint256.
|
|
60
60
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
61
61
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
62
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
62
63
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
63
64
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
64
65
|
* @throws {ExpiredDeadlineError} If the expiry is not in the future.
|
|
@@ -72,6 +72,7 @@ export function validateMigrateToV2PlanAction(action, path) {
|
|
|
72
72
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or the selected amount exceeds uint256.
|
|
73
73
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
74
74
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
75
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
75
76
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
76
77
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
77
78
|
* @throws {ExpiredDeadlineError} If the expiry is not in the future.
|
|
@@ -39,6 +39,7 @@ export interface VaultV1RedeemPlanParams extends RedeemPlanParams {
|
|
|
39
39
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
40
40
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
|
|
41
41
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
42
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
42
43
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
43
44
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
44
45
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
@@ -24,6 +24,7 @@ import { prepareVaultRedeem } from "../redeem.js";
|
|
|
24
24
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
25
25
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
|
|
26
26
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
27
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
27
28
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
28
29
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
29
30
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
@@ -45,6 +45,7 @@ export interface VaultV1WithdrawPlanParams extends WithdrawPlanParams<AccrualVau
|
|
|
45
45
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
46
46
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
47
47
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
48
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
48
49
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
49
50
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
50
51
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
@@ -31,6 +31,7 @@ import { prepareVaultWithdraw } from "../withdraw.js";
|
|
|
31
31
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
32
32
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
33
33
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
34
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
34
35
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
35
36
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
36
37
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
@@ -37,6 +37,7 @@ export interface VaultV2DepositPlanParams extends DepositPlanParams<AccrualVault
|
|
|
37
37
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
38
38
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
39
39
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
40
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
40
41
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
41
42
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
42
43
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
|
|
@@ -31,6 +31,7 @@ import { getVaultPermit } from "../permit.js";
|
|
|
31
31
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
32
32
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
33
33
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
34
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
34
35
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
35
36
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
36
37
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
|