@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
|
@@ -2,10 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serializeTransactionPlan = serializeTransactionPlan;
|
|
4
4
|
exports.parseTransactionPlan = parseTransactionPlan;
|
|
5
|
-
const
|
|
5
|
+
const error_js_1 = require("../types/error.js");
|
|
6
6
|
const approval_js_1 = require("./approval.js");
|
|
7
|
+
const authorization_js_1 = require("./blue/authorization.js");
|
|
8
|
+
const borrow_js_1 = require("./blue/borrow.js");
|
|
9
|
+
const refinance_js_1 = require("./blue/refinance.js");
|
|
10
|
+
const repay_js_1 = require("./blue/repay.js");
|
|
11
|
+
const repayWithdrawCollateral_js_1 = require("./blue/repayWithdrawCollateral.js");
|
|
12
|
+
const supply_js_1 = require("./blue/supply.js");
|
|
13
|
+
const supplyCollateral_js_1 = require("./blue/supplyCollateral.js");
|
|
14
|
+
const supplyCollateralBorrow_js_1 = require("./blue/supplyCollateralBorrow.js");
|
|
15
|
+
const withdraw_js_1 = require("./blue/withdraw.js");
|
|
16
|
+
const withdrawCollateral_js_1 = require("./blue/withdrawCollateral.js");
|
|
7
17
|
const deposit_js_1 = require("./deposit.js");
|
|
8
|
-
const
|
|
18
|
+
const error_js_2 = require("./error.js");
|
|
9
19
|
const permit_js_1 = require("./permit.js");
|
|
10
20
|
const plan_js_1 = require("./plan.js");
|
|
11
21
|
const redeem_js_1 = require("./redeem.js");
|
|
@@ -17,19 +27,29 @@ const forceRedeem_js_1 = require("./vaultv2/forceRedeem.js");
|
|
|
17
27
|
const forceWithdraw_js_1 = require("./vaultv2/forceWithdraw.js");
|
|
18
28
|
const inKindRedeem_js_2 = require("./vaultv2/inKindRedeem.js");
|
|
19
29
|
const version_js_1 = require("./version.js");
|
|
20
|
-
const
|
|
30
|
+
const withdraw_js_2 = require("./withdraw.js");
|
|
21
31
|
const actionValidators = {
|
|
22
32
|
vaultV1InKindRedeem: inKindRedeem_js_1.validateInKindRedeemPlanAction,
|
|
33
|
+
blueSupply: supply_js_1.validateBlueSupplyPlanAction,
|
|
34
|
+
blueSupplyCollateral: supplyCollateral_js_1.validateSupplyCollateralPlanAction,
|
|
35
|
+
blueBorrow: borrow_js_1.validateBorrowPlanAction,
|
|
36
|
+
blueSupplyCollateralBorrow: supplyCollateralBorrow_js_1.validateSupplyCollateralBorrowPlanAction,
|
|
37
|
+
blueRepay: repay_js_1.validateBlueRepayPlanAction,
|
|
38
|
+
blueWithdraw: withdraw_js_1.validateBlueWithdrawPlanAction,
|
|
39
|
+
blueWithdrawCollateral: withdrawCollateral_js_1.validateBlueWithdrawCollateralPlanAction,
|
|
40
|
+
blueRepayWithdrawCollateral: repayWithdrawCollateral_js_1.validateRepayWithdrawCollateralPlanAction,
|
|
41
|
+
blueRefinance: refinance_js_1.validateRefinancePlanAction,
|
|
23
42
|
erc20Approval: approval_js_1.validateApprovalPlanAction,
|
|
24
43
|
vaultV2Redeem: redeem_js_1.validateRedeemPlanAction,
|
|
25
44
|
vaultV2ForceWithdraw: forceWithdraw_js_1.validateForceWithdrawPlanAction,
|
|
26
45
|
vaultV1Deposit: deposit_js_1.validateDepositPlanAction,
|
|
27
46
|
vaultV1Redeem: redeem_js_1.validateRedeemPlanAction,
|
|
28
47
|
vaultV1MigrateToV2: migrateToV2_js_1.validateMigrateToV2PlanAction,
|
|
48
|
+
morphoAuthorization: authorization_js_1.validateMorphoAuthorizationPlanAction,
|
|
29
49
|
vaultV2Deposit: deposit_js_1.validateDepositPlanAction,
|
|
30
|
-
vaultV2Withdraw:
|
|
50
|
+
vaultV2Withdraw: withdraw_js_2.validateWithdrawPlanAction,
|
|
31
51
|
vaultV2ForceRedeem: forceRedeem_js_1.validateForceRedeemPlanAction,
|
|
32
|
-
vaultV1Withdraw:
|
|
52
|
+
vaultV1Withdraw: withdraw_js_2.validateWithdrawPlanAction,
|
|
33
53
|
vaultV2InKindRedeem: inKindRedeem_js_2.validateInKindRedeemPlanAction,
|
|
34
54
|
};
|
|
35
55
|
/**
|
|
@@ -53,11 +73,14 @@ function serializeTransactionPlan(plan) {
|
|
|
53
73
|
/**
|
|
54
74
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
55
75
|
* Restores bigint fields and validates version, action/request shapes, uint256 ranges, unique IDs,
|
|
56
|
-
* references, per-action chain/account and
|
|
57
|
-
* Extra keys are allowed. No clock or RPC is used: expiry, live state
|
|
58
|
-
* action-layer business constraints are not checked.
|
|
76
|
+
* references, per-action chain/account and signature-request consistency, including signed requests.
|
|
77
|
+
* Extra keys are allowed. No clock or RPC is used: current expiry, live state and
|
|
78
|
+
* action-layer business constraints are not checked. Stored signatures are recovered offline.
|
|
79
|
+
* Permits bind owner, token, spender, value, nonce, deadline and chain; Morpho authorizations bind
|
|
80
|
+
* owner, authorized address, nonce, deadline and chain, not operation amounts, markets or referral fees/recipients.
|
|
81
|
+
* Parsing does not prove authenticity or intent for unsigned fields;
|
|
59
82
|
* tampered but well-formed, internally consistent plans pass. Integrators must protect stored plans.
|
|
60
|
-
*
|
|
83
|
+
* Integrators must protect unsigned stored fields even when all signatures verify.
|
|
61
84
|
* @param json - JSON previously returned by `serializeTransactionPlan`.
|
|
62
85
|
* @returns The restored plan.
|
|
63
86
|
* @throws {InvalidTransactionPlanError} At the first malformed JSON, field shape or consistency failure, exposing its JSON `path` and `reason`.
|
|
@@ -80,7 +103,7 @@ function parseTransactionPlan(json) {
|
|
|
80
103
|
: field);
|
|
81
104
|
}
|
|
82
105
|
catch (cause) {
|
|
83
|
-
throw new
|
|
106
|
+
throw new error_js_2.InvalidTransactionPlanError({
|
|
84
107
|
path: "$",
|
|
85
108
|
reason: "expected JSON with valid bigint tags",
|
|
86
109
|
cause,
|
|
@@ -99,15 +122,8 @@ function parseTransactionPlan(json) {
|
|
|
99
122
|
signatureRequests: "array",
|
|
100
123
|
},
|
|
101
124
|
});
|
|
102
|
-
if (plan.calldataOrigin !== undefined) {
|
|
103
|
-
(0, validation_js_1.validatePlanField)(plan.calldataOrigin, {
|
|
104
|
-
path: "$.calldataOrigin",
|
|
105
|
-
type: "hex",
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
125
|
const steps = plan.steps;
|
|
109
126
|
const requests = plan.signatureRequests;
|
|
110
|
-
const stepIds = new Set();
|
|
111
127
|
for (const [index, value] of steps.entries()) {
|
|
112
128
|
const path = `$.steps[${index}]`;
|
|
113
129
|
const step = (0, validation_js_1.getPlanObject)(value, path);
|
|
@@ -115,13 +131,6 @@ function parseTransactionPlan(json) {
|
|
|
115
131
|
path,
|
|
116
132
|
fields: { id: "string", label: "string" },
|
|
117
133
|
});
|
|
118
|
-
if (stepIds.has(step.id)) {
|
|
119
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
120
|
-
path: `${path}.id`,
|
|
121
|
-
reason: "expected a unique step ID",
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
stepIds.add(step.id);
|
|
125
134
|
const action = (0, validation_js_1.getPlanObject)(step.action, `${path}.action`);
|
|
126
135
|
(0, validation_js_1.validatePlanField)(action.type, {
|
|
127
136
|
path: `${path}.action.type`,
|
|
@@ -139,18 +148,6 @@ function parseTransactionPlan(json) {
|
|
|
139
148
|
fields: { chainId: "positive safe integer", account: "address" },
|
|
140
149
|
});
|
|
141
150
|
actionValidators[step.action.type](action, path);
|
|
142
|
-
if (inputs.chainId !== plan.chainId) {
|
|
143
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
144
|
-
path: `${path}.inputs.chainId`,
|
|
145
|
-
reason: "expected the plan chainId",
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
if (!(0, viem_1.isAddressEqual)(inputs.account, plan.account)) {
|
|
149
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
150
|
-
path: `${path}.inputs.account`,
|
|
151
|
-
reason: "expected the plan account",
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
151
|
}
|
|
155
152
|
const requestIds = new Set();
|
|
156
153
|
for (const [index, value] of requests.entries()) {
|
|
@@ -160,20 +157,8 @@ function parseTransactionPlan(json) {
|
|
|
160
157
|
path,
|
|
161
158
|
fields: { id: "string", kind: "string" },
|
|
162
159
|
});
|
|
163
|
-
if (requestIds.has(request.id)) {
|
|
164
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
165
|
-
path: `${path}.id`,
|
|
166
|
-
reason: "expected a unique signature request ID",
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
160
|
requestIds.add(request.id);
|
|
170
|
-
|
|
171
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
172
|
-
path: `${path}.kind`,
|
|
173
|
-
reason: "expected a supported signature request kind (permit)",
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
(0, permit_js_1.validatePermitPlanRequest)(request, path);
|
|
161
|
+
validatePlanRequest(request, path);
|
|
177
162
|
}
|
|
178
163
|
for (const [index, step] of steps.entries()) {
|
|
179
164
|
if (!("signatureRequestIds" in step.action)) {
|
|
@@ -184,7 +169,7 @@ function parseTransactionPlan(json) {
|
|
|
184
169
|
for (const [role, id] of Object.entries(ids)) {
|
|
185
170
|
(0, validation_js_1.validatePlanField)(id, { path: `${path}.${role}`, type: "string" });
|
|
186
171
|
if (!requestIds.has(id)) {
|
|
187
|
-
throw new
|
|
172
|
+
throw new error_js_2.InvalidTransactionPlanError({
|
|
188
173
|
path: `${path}.${role}`,
|
|
189
174
|
reason: "expected an existing signature request ID",
|
|
190
175
|
});
|
|
@@ -192,18 +177,37 @@ function parseTransactionPlan(json) {
|
|
|
192
177
|
}
|
|
193
178
|
}
|
|
194
179
|
const result = restored;
|
|
180
|
+
// Apply the same context and deadline rules as direct builders.
|
|
181
|
+
(0, validation_js_1.validateTransactionPlanHeader)(result);
|
|
195
182
|
try {
|
|
196
|
-
//
|
|
197
|
-
(0, plan_js_1.getPendingSignatureRequests)(
|
|
198
|
-
...result,
|
|
199
|
-
signatureRequests: result.signatureRequests.map((request) => ({
|
|
200
|
-
...request,
|
|
201
|
-
signature: undefined,
|
|
202
|
-
})),
|
|
203
|
-
});
|
|
183
|
+
// Check references and request/action consistency, including restored signatures.
|
|
184
|
+
(0, plan_js_1.getPendingSignatureRequests)(result);
|
|
204
185
|
}
|
|
205
186
|
catch (cause) {
|
|
206
|
-
if (cause instanceof error_js_1.
|
|
187
|
+
if (cause instanceof error_js_1.InvalidSignatureError ||
|
|
188
|
+
cause instanceof error_js_1.BundlesPermitMismatchError) {
|
|
189
|
+
const index = result.signatureRequests.findIndex((request) => {
|
|
190
|
+
if (request.signature === undefined) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
// Locate the failed stored signature without duplicating recovery logic.
|
|
195
|
+
(0, plan_js_1.verifyPlanSignature)(request, request.signature);
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
throw new error_js_2.InvalidTransactionPlanError({
|
|
203
|
+
path: `$.signatureRequests[${index}].signature`,
|
|
204
|
+
reason: cause instanceof error_js_1.InvalidSignatureError
|
|
205
|
+
? "expected a valid low-s signature from the request owner"
|
|
206
|
+
: "expected a compact or serialized ECDSA signature",
|
|
207
|
+
cause,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (cause instanceof error_js_2.TransactionPlanSignatureMismatchError) {
|
|
207
211
|
const index = result.signatureRequests.findIndex((request) => request.id === cause.id);
|
|
208
212
|
let field = `typedData.${cause.field}`;
|
|
209
213
|
if (cause.field === "reference") {
|
|
@@ -215,13 +219,13 @@ function parseTransactionPlan(json) {
|
|
|
215
219
|
else if (cause.field.startsWith("args.")) {
|
|
216
220
|
field = cause.field;
|
|
217
221
|
}
|
|
218
|
-
throw new
|
|
222
|
+
throw new error_js_2.InvalidTransactionPlanError({
|
|
219
223
|
path: `$.signatureRequests[${index}].${field}`,
|
|
220
224
|
reason: "expected agreement with every referencing action",
|
|
221
225
|
cause,
|
|
222
226
|
});
|
|
223
227
|
}
|
|
224
|
-
throw new
|
|
228
|
+
throw new error_js_2.InvalidTransactionPlanError({
|
|
225
229
|
path: "$.signatureRequests",
|
|
226
230
|
reason: "expected requests consistent with supported action chains",
|
|
227
231
|
cause,
|
|
@@ -229,3 +233,18 @@ function parseTransactionPlan(json) {
|
|
|
229
233
|
}
|
|
230
234
|
return result;
|
|
231
235
|
}
|
|
236
|
+
function validatePlanRequest(request, path) {
|
|
237
|
+
switch (request.kind) {
|
|
238
|
+
case "permit":
|
|
239
|
+
(0, permit_js_1.validatePermitPlanRequest)(request, path);
|
|
240
|
+
break;
|
|
241
|
+
case "morphoAuthorization":
|
|
242
|
+
(0, authorization_js_1.validateMorphoAuthorizationPlanRequest)(request, path);
|
|
243
|
+
break;
|
|
244
|
+
default:
|
|
245
|
+
throw new error_js_2.InvalidTransactionPlanError({
|
|
246
|
+
path: `${path}.kind`,
|
|
247
|
+
reason: "expected a supported signature request kind (permit or morphoAuthorization)",
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -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
|
*/
|
|
@@ -11,10 +11,20 @@ const error_js_1 = require("./error.js");
|
|
|
11
11
|
function validateTransactionPlanActions(steps) {
|
|
12
12
|
for (const step of steps) {
|
|
13
13
|
const actionType = step.action.type;
|
|
14
|
-
if (actionType !== "
|
|
14
|
+
if (actionType !== "blueRefinance" &&
|
|
15
|
+
actionType !== "erc20Approval" &&
|
|
15
16
|
actionType !== "vaultV1Deposit" &&
|
|
16
17
|
actionType !== "vaultV1MigrateToV2" &&
|
|
17
18
|
actionType !== "vaultV1InKindRedeem" &&
|
|
19
|
+
actionType !== "blueSupply" &&
|
|
20
|
+
actionType !== "blueSupplyCollateral" &&
|
|
21
|
+
actionType !== "blueBorrow" &&
|
|
22
|
+
actionType !== "blueSupplyCollateralBorrow" &&
|
|
23
|
+
actionType !== "blueRepay" &&
|
|
24
|
+
actionType !== "blueWithdraw" &&
|
|
25
|
+
actionType !== "blueWithdrawCollateral" &&
|
|
26
|
+
actionType !== "blueRepayWithdrawCollateral" &&
|
|
27
|
+
actionType !== "morphoAuthorization" &&
|
|
18
28
|
actionType !== "vaultV2Deposit" &&
|
|
19
29
|
actionType !== "vaultV2Withdraw" &&
|
|
20
30
|
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,11 +1,101 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCalldataOriginLength = validateCalldataOriginLength;
|
|
4
|
+
exports.validateTransactionPlanHeader = validateTransactionPlanHeader;
|
|
5
|
+
exports.matchesAddress = matchesAddress;
|
|
3
6
|
exports.validatePlanField = validatePlanField;
|
|
4
7
|
exports.getPlanObject = getPlanObject;
|
|
5
8
|
exports.validatePlanFields = validatePlanFields;
|
|
6
9
|
exports.validateVaultPlanAction = validateVaultPlanAction;
|
|
7
10
|
const viem_1 = require("viem");
|
|
8
11
|
const error_js_1 = require("./error.js");
|
|
12
|
+
/** @internal Maximum calldata-origin length in bytes. */
|
|
13
|
+
const MAX_CALLDATA_ORIGIN_BYTES = 1024 * 1024;
|
|
14
|
+
/** @internal Rejects attribution bytes above the preparation and stored-plan limit. */
|
|
15
|
+
function validateCalldataOriginLength(calldataOrigin) {
|
|
16
|
+
if (calldataOrigin.length > 2 + MAX_CALLDATA_ORIGIN_BYTES * 2) {
|
|
17
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
18
|
+
path: "$.calldataOrigin",
|
|
19
|
+
reason: "expected at most 1 MiB",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** @internal Validates shared plan context without reading a clock or live state. */
|
|
24
|
+
function validateTransactionPlanHeader(plan) {
|
|
25
|
+
validatePlanField(plan.chainId, {
|
|
26
|
+
path: "$.chainId",
|
|
27
|
+
type: "positive safe integer",
|
|
28
|
+
});
|
|
29
|
+
validatePlanField(plan.account, { path: "$.account", type: "address" });
|
|
30
|
+
validatePlanField(plan.expiresAt, {
|
|
31
|
+
path: "$.expiresAt",
|
|
32
|
+
type: "safe integer",
|
|
33
|
+
});
|
|
34
|
+
if (plan.calldataOrigin !== undefined) {
|
|
35
|
+
validatePlanField(plan.calldataOrigin, {
|
|
36
|
+
path: "$.calldataOrigin",
|
|
37
|
+
type: "hex",
|
|
38
|
+
});
|
|
39
|
+
validateCalldataOriginLength(plan.calldataOrigin);
|
|
40
|
+
}
|
|
41
|
+
const stepIds = new Set();
|
|
42
|
+
for (const [index, step] of plan.steps.entries()) {
|
|
43
|
+
const path = `$.steps[${index}]`;
|
|
44
|
+
if (stepIds.has(step.id)) {
|
|
45
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
46
|
+
path: `${path}.id`,
|
|
47
|
+
reason: "expected a unique step ID",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
stepIds.add(step.id);
|
|
51
|
+
const { inputs } = step.action;
|
|
52
|
+
if (inputs.chainId !== plan.chainId) {
|
|
53
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
54
|
+
path: `${path}.action.inputs.chainId`,
|
|
55
|
+
reason: "expected the plan chainId",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (!matchesAddress(inputs.account, plan.account)) {
|
|
59
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
60
|
+
path: `${path}.action.inputs.account`,
|
|
61
|
+
reason: "expected the plan account",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if ("deadline" in inputs &&
|
|
65
|
+
typeof inputs.deadline === "bigint" &&
|
|
66
|
+
inputs.deadline > 0n &&
|
|
67
|
+
inputs.deadline < BigInt(plan.expiresAt)) {
|
|
68
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
69
|
+
path: `${path}.action.inputs.deadline`,
|
|
70
|
+
reason: "expected a deadline no earlier than expiresAt",
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const requestIds = new Set();
|
|
75
|
+
for (const [index, request] of plan.signatureRequests.entries()) {
|
|
76
|
+
const path = `$.signatureRequests[${index}]`;
|
|
77
|
+
if (requestIds.has(request.id)) {
|
|
78
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
79
|
+
path: `${path}.id`,
|
|
80
|
+
reason: "expected a unique signature request ID",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
requestIds.add(request.id);
|
|
84
|
+
if (request.args.deadline < BigInt(plan.expiresAt)) {
|
|
85
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
86
|
+
path: `${path}.args.deadline`,
|
|
87
|
+
reason: "expected a deadline no earlier than expiresAt",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** @internal Compares an untrusted address without throwing on malformed input. */
|
|
93
|
+
function matchesAddress(value, expected) {
|
|
94
|
+
return (typeof value === "string" &&
|
|
95
|
+
(0, viem_1.isAddress)(value, { strict: false }) &&
|
|
96
|
+
(0, viem_1.isAddress)(expected, { strict: false }) &&
|
|
97
|
+
(0, viem_1.isAddressEqual)(value, expected));
|
|
98
|
+
}
|
|
9
99
|
/** @internal Validates one restored field without coercing it. */
|
|
10
100
|
function validatePlanField(value, options) {
|
|
11
101
|
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.
|
|
@@ -36,6 +36,7 @@ const permit_js_1 = require("../permit.js");
|
|
|
36
36
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
37
37
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
38
38
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
39
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
39
40
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
40
41
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
41
42
|
* @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`.
|
|
@@ -33,6 +33,7 @@ const validation_js_1 = require("../validation.js");
|
|
|
33
33
|
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
34
34
|
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
35
35
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
36
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
36
37
|
* @throws {ChainIdMismatchError} when the client declares or its RPC serves another chain.
|
|
37
38
|
* @throws {EmptyMarketParamsListError} when no markets are supplied.
|
|
38
39
|
* @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.
|
|
@@ -77,6 +77,7 @@ function validateMigrateToV2PlanAction(action, path) {
|
|
|
77
77
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or the selected amount exceeds uint256.
|
|
78
78
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
79
79
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
80
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
80
81
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
81
82
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
82
83
|
* @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.
|
|
@@ -28,6 +28,7 @@ const redeem_js_2 = require("../redeem.js");
|
|
|
28
28
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
29
29
|
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
|
|
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 {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
32
33
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
33
34
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|