@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,7 +1,9 @@
|
|
|
1
|
+
import { Token } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { getPermitTypedData } from "@morpho-org/blue-sdk-viem";
|
|
1
3
|
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
4
|
import { maxUint256 } from "viem";
|
|
3
5
|
import { IncompleteTransactionPlanError, TransactionPlanSignatureMismatchError, } from "./error.js";
|
|
4
|
-
import { getPlanObject, validatePlanField, validatePlanFields, } from "./validation.js";
|
|
6
|
+
import { getPlanObject, matchesAddress, validatePlanField, validatePlanFields, } from "./validation.js";
|
|
5
7
|
/** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
|
|
6
8
|
export function validatePermitPlanRequest(request, path) {
|
|
7
9
|
const args = getPlanObject(request.args, `${path}.args`);
|
|
@@ -73,114 +75,139 @@ export function validatePermitPlanRequest(request, path) {
|
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
/** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
|
|
76
|
-
export function
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
export function validateVaultPermitRequest(request, action) {
|
|
79
|
+
if (request.kind !== "permit") {
|
|
80
|
+
throw new TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
81
|
+
}
|
|
79
82
|
let spenderKey;
|
|
80
83
|
let asset;
|
|
81
|
-
let
|
|
84
|
+
let amount;
|
|
85
|
+
let exact = false;
|
|
82
86
|
switch (action.type) {
|
|
83
|
-
case "vaultV2ForceRedeem":
|
|
84
|
-
throw new TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
85
|
-
case "erc20Approval":
|
|
86
|
-
throw new TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
87
87
|
case "vaultV2Deposit":
|
|
88
88
|
spenderKey = "bundles.vaultBundlesV1";
|
|
89
89
|
asset = action.inputs.asset;
|
|
90
|
-
|
|
90
|
+
amount = action.inputs.assets;
|
|
91
|
+
exact = true;
|
|
91
92
|
break;
|
|
92
93
|
case "vaultV1Deposit":
|
|
93
94
|
spenderKey = "bundles.vaultBundlesV1";
|
|
94
95
|
asset = action.inputs.asset;
|
|
95
|
-
|
|
96
|
+
amount = action.inputs.assets;
|
|
97
|
+
exact = true;
|
|
96
98
|
break;
|
|
97
99
|
case "vaultV1Withdraw":
|
|
98
100
|
spenderKey = "bundles.vaultBundlesV1";
|
|
99
101
|
asset = action.inputs.vault;
|
|
100
|
-
|
|
101
|
-
request.args.amount >= action.inputs.requiredShareAllowance;
|
|
102
|
+
amount = action.inputs.requiredShareAllowance;
|
|
102
103
|
break;
|
|
103
104
|
case "vaultV2Withdraw":
|
|
104
105
|
spenderKey = "bundles.vaultBundlesV1";
|
|
105
106
|
asset = action.inputs.vault;
|
|
106
|
-
|
|
107
|
-
request.args.amount >= action.inputs.requiredShareAllowance;
|
|
107
|
+
amount = action.inputs.requiredShareAllowance;
|
|
108
108
|
break;
|
|
109
109
|
case "vaultV2Redeem":
|
|
110
110
|
spenderKey = "bundles.vaultBundlesV1";
|
|
111
111
|
asset = action.inputs.vault;
|
|
112
|
-
|
|
112
|
+
amount = action.inputs.shares;
|
|
113
113
|
break;
|
|
114
114
|
case "vaultV1Redeem":
|
|
115
115
|
spenderKey = "bundles.vaultBundlesV1";
|
|
116
116
|
asset = action.inputs.vault;
|
|
117
|
-
|
|
117
|
+
amount = action.inputs.shares;
|
|
118
118
|
break;
|
|
119
119
|
case "vaultV2ForceWithdraw":
|
|
120
120
|
spenderKey = "bundles.vaultExitBundlesV1";
|
|
121
121
|
asset = action.inputs.vault;
|
|
122
|
-
|
|
122
|
+
amount = maxUint256;
|
|
123
|
+
exact = true;
|
|
123
124
|
break;
|
|
124
125
|
case "vaultV1MigrateToV2":
|
|
125
126
|
spenderKey = "bundles.vaultBundlesV1";
|
|
126
127
|
asset = action.inputs.sourceVault;
|
|
127
|
-
|
|
128
|
-
request.args.amount >= action.inputs.requiredShareAllowance;
|
|
128
|
+
amount = action.inputs.requiredShareAllowance;
|
|
129
129
|
break;
|
|
130
130
|
case "vaultV2InKindRedeem":
|
|
131
131
|
spenderKey = "bundles.vaultExitBundlesV1";
|
|
132
132
|
asset = action.inputs.vault;
|
|
133
|
-
|
|
133
|
+
amount = maxUint256;
|
|
134
|
+
exact = true;
|
|
134
135
|
break;
|
|
135
136
|
case "vaultV1InKindRedeem":
|
|
136
137
|
spenderKey = "bundles.vaultExitBundlesV1";
|
|
137
138
|
asset = action.inputs.vault;
|
|
138
|
-
|
|
139
|
+
amount = maxUint256;
|
|
140
|
+
exact = true;
|
|
139
141
|
break;
|
|
140
|
-
default:
|
|
141
|
-
const _exhaustive = action;
|
|
142
|
+
default:
|
|
142
143
|
throw new TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
143
|
-
}
|
|
144
144
|
}
|
|
145
145
|
if (action.signatureRequestIds.tokenPermit !== request.id) {
|
|
146
146
|
throw new TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
validateTokenPermitRequest(request, {
|
|
149
|
+
chainId: action.inputs.chainId,
|
|
150
|
+
account: action.inputs.account,
|
|
151
|
+
deadline: action.inputs.deadline,
|
|
152
|
+
bundler: spenderKey,
|
|
153
|
+
asset,
|
|
154
|
+
amount,
|
|
155
|
+
exact,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/** @internal Binds the signing payload and encoding arguments to a registered bundle's token pull. */
|
|
159
|
+
export function validateTokenPermitRequest(request, pull) {
|
|
160
|
+
const { chainId, account, asset, amount, exact } = pull;
|
|
161
|
+
const { domain, message, types, primaryType } = request.typedData;
|
|
162
|
+
const spender = getChainAddress(chainId, pull.bundler);
|
|
149
163
|
const checks = [
|
|
150
164
|
["domain.chainId", domain?.chainId === chainId],
|
|
151
165
|
[
|
|
152
166
|
"domain.verifyingContract",
|
|
153
|
-
|
|
154
|
-
domain.verifyingContract.toLowerCase() === asset.toLowerCase(),
|
|
155
|
-
],
|
|
156
|
-
[
|
|
157
|
-
"message.owner",
|
|
158
|
-
typeof message?.owner === "string" &&
|
|
159
|
-
message.owner.toLowerCase() === account.toLowerCase(),
|
|
160
|
-
],
|
|
161
|
-
[
|
|
162
|
-
"message.spender",
|
|
163
|
-
typeof message?.spender === "string" &&
|
|
164
|
-
message.spender.toLowerCase() === spender.toLowerCase(),
|
|
167
|
+
matchesAddress(domain?.verifyingContract, asset),
|
|
165
168
|
],
|
|
169
|
+
["message.owner", matchesAddress(message?.owner, account)],
|
|
170
|
+
["message.spender", matchesAddress(message?.spender, spender)],
|
|
171
|
+
["args.spender", matchesAddress(request.args.spender, spender)],
|
|
172
|
+
["message.value", message?.value === request.args.amount],
|
|
166
173
|
[
|
|
167
|
-
"
|
|
168
|
-
|
|
169
|
-
request.args.
|
|
174
|
+
"value",
|
|
175
|
+
exact
|
|
176
|
+
? request.args.amount === amount
|
|
177
|
+
: amount !== undefined && request.args.amount >= amount,
|
|
170
178
|
],
|
|
171
|
-
["message.value", message?.value === request.args.amount],
|
|
172
|
-
["value", amountMatches],
|
|
173
179
|
["message.nonce", message?.nonce === request.args.nonce],
|
|
174
180
|
["message.deadline", message?.deadline === request.args.deadline],
|
|
175
181
|
["primaryType", primaryType === "Permit"],
|
|
182
|
+
[
|
|
183
|
+
"args.deadline",
|
|
184
|
+
pull.deadline === undefined || request.args.deadline === pull.deadline,
|
|
185
|
+
],
|
|
176
186
|
];
|
|
177
187
|
const mismatch = checks.find(([, matches]) => !matches);
|
|
178
188
|
if (mismatch) {
|
|
179
189
|
throw new TransactionPlanSignatureMismatchError(request.id, mismatch[0]);
|
|
180
190
|
}
|
|
191
|
+
const expected = getPermitTypedData({
|
|
192
|
+
erc20: new Token({ address: asset, name: domain?.name ?? "" }),
|
|
193
|
+
owner: account,
|
|
194
|
+
spender,
|
|
195
|
+
allowance: request.args.amount,
|
|
196
|
+
nonce: request.args.nonce,
|
|
197
|
+
deadline: request.args.deadline,
|
|
198
|
+
}, chainId).types.Permit;
|
|
199
|
+
const fields = types?.Permit;
|
|
200
|
+
if (!Array.isArray(fields) ||
|
|
201
|
+
Object.keys(types).length !== 1 ||
|
|
202
|
+
fields.length !== expected.length ||
|
|
203
|
+
!expected.every(({ name, type }, index) => fields[index]?.name === name &&
|
|
204
|
+
fields[index]?.type === type &&
|
|
205
|
+
Object.keys(fields[index]).length === 2)) {
|
|
206
|
+
throw new TransactionPlanSignatureMismatchError(request.id, "types");
|
|
207
|
+
}
|
|
181
208
|
}
|
|
182
209
|
/** @internal Rebuilds a token permit from the action's account/asset and its resolved signature requests. */
|
|
183
|
-
export function
|
|
210
|
+
export function getSignedTokenPermit(requests, { id, asset, owner, }) {
|
|
184
211
|
if (id === undefined) {
|
|
185
212
|
return undefined;
|
|
186
213
|
}
|
|
@@ -188,6 +215,9 @@ export function getVaultPermit(requests, { id, asset, owner, }) {
|
|
|
188
215
|
if (request?.signature === undefined) {
|
|
189
216
|
throw new IncompleteTransactionPlanError(id);
|
|
190
217
|
}
|
|
218
|
+
if (request.kind !== "permit") {
|
|
219
|
+
throw new TransactionPlanSignatureMismatchError(id, "reference");
|
|
220
|
+
}
|
|
191
221
|
return {
|
|
192
222
|
action: {
|
|
193
223
|
type: request.kind,
|
|
@@ -204,3 +234,5 @@ export function getVaultPermit(requests, { id, asset, owner, }) {
|
|
|
204
234
|
},
|
|
205
235
|
};
|
|
206
236
|
}
|
|
237
|
+
/** @internal Alias for existing Vault V2 plan builders. */
|
|
238
|
+
export { getSignedTokenPermit as getVaultPermit };
|
|
@@ -5,11 +5,13 @@ import type { SignatureRequest, Step, TransactionPlan } from "./types.js";
|
|
|
5
5
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
6
6
|
* Validates every request against its actions, verifies supplied ECDSA signatures synchronously,
|
|
7
7
|
* and attaches serialized signatures by request ID. No client or RPC is used; the EIP-712 domain
|
|
8
|
-
* binds the signature to its chain. Only low-s compact or serialized ECDSA
|
|
8
|
+
* binds the signature to its chain. Only low-s compact or serialized ECDSA signatures are supported.
|
|
9
9
|
* Contract wallets should use `supportSignature: false` for direct approvals: deployed bundles
|
|
10
10
|
* consume ECDSA `v/r/s`, not arbitrary ERC-1271 or ERC-6492 signatures.
|
|
11
11
|
* Stored inputs remain trusted; verification does not establish the integrator's intent or protect
|
|
12
|
-
*
|
|
12
|
+
* unsigned fields from tampering. Stored signatures are reverified offline at parse, inspection and build.
|
|
13
|
+
* Permits bind owner, token, spender, value, nonce, deadline and chain; Morpho authorizations bind
|
|
14
|
+
* owner, authorized address, nonce, deadline and chain, not operation amounts, markets or referral fees/recipients.
|
|
13
15
|
* @param plan - Plan to update without mutating its requests or steps.
|
|
14
16
|
* @param signatures - Compact or serialized ECDSA signatures, each naming a unique existing request ID.
|
|
15
17
|
* @returns A new plan sharing steps and unpatched requests; omitted IDs are preserved. Empty input validates all requests and returns the original plan.
|
|
@@ -17,7 +19,8 @@ import type { SignatureRequest, Step, TransactionPlan } from "./types.js";
|
|
|
17
19
|
* @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests or updates.
|
|
18
20
|
* @throws {TransactionPlanSignatureMismatchError} If a request disagrees with its actions, an ID is unknown, or an input ID is duplicated (`field: "duplicate"`).
|
|
19
21
|
* @throws {BundlesPermitMismatchError} If a supplied signature cannot be parsed by the bundle permit builders.
|
|
20
|
-
* @throws {
|
|
22
|
+
* @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
|
|
23
|
+
* @throws {InvalidSignatureError} If a signature has high s, cannot recover a public key, or does not match the request owner and typed data.
|
|
21
24
|
* @example
|
|
22
25
|
* ```ts
|
|
23
26
|
* import { applySignatures, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
@@ -30,16 +33,22 @@ export declare function applySignatures(plan: TransactionPlan, signatures: reado
|
|
|
30
33
|
readonly id: string;
|
|
31
34
|
readonly signature: Hex;
|
|
32
35
|
}[]): TransactionPlan;
|
|
36
|
+
/** @internal Verifies and normalizes a signature offline after the request has been validated against its action. */
|
|
37
|
+
export declare function verifyPlanSignature(request: SignatureRequest, signature: Hex): Hex;
|
|
33
38
|
/**
|
|
34
39
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
35
|
-
* Lists pending signature requests once per request ID
|
|
40
|
+
* Lists pending signature requests once per request ID and validates them against their referencing actions.
|
|
41
|
+
* Signed requests are also checked and their signers recovered offline.
|
|
36
42
|
* Sign each request's typed data with your wallet stack, then verify and attach the results with
|
|
37
43
|
* {@link applySignatures}.
|
|
38
44
|
* @param plan - Plan to inspect without changing it.
|
|
39
45
|
* @returns Pending requests in first-reference order, each carrying its `id`, `kind` and validated `typedData`. Dangling IDs are omitted. The SDK never signs.
|
|
46
|
+
* @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
|
|
47
|
+
* @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
|
|
48
|
+
* @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed as a compact or serialized ECDSA signature.
|
|
40
49
|
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
|
|
41
50
|
* @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
|
|
42
|
-
* @throws {TransactionPlanSignatureMismatchError} If a pending
|
|
51
|
+
* @throws {TransactionPlanSignatureMismatchError} If a pending request or Morpho authorization disagrees with its action or arguments, or any request has no referencing step.
|
|
43
52
|
* @example
|
|
44
53
|
* ```ts
|
|
45
54
|
* import { getPendingSignatureRequests, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
@@ -54,23 +63,47 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
|
|
|
54
63
|
* Plans are trusted as given, whether restored or supplied directly. Signature checks establish
|
|
55
64
|
* only request/action consistency; they do not validate stored fees, recipients, share-price bounds,
|
|
56
65
|
* vaults or amounts against the intended operation. Integrators must protect stored plans from tampering.
|
|
57
|
-
*
|
|
66
|
+
* Stored signatures are verified offline. Permits bind owner, token, spender, value, nonce, deadline
|
|
67
|
+
* and chain; Morpho authorizations bind owner, authorized address, nonce, deadline and chain,
|
|
68
|
+
* not operation amounts, market parameters or referral fees/recipients. Protect those unsigned fields.
|
|
58
69
|
* @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
|
|
59
70
|
* @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
|
|
60
71
|
* @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
|
|
72
|
+
* @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
|
|
73
|
+
* @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
|
|
61
74
|
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
|
|
62
75
|
* @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
|
|
63
76
|
* @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
|
|
64
77
|
* @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
|
|
65
78
|
* @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
|
|
66
|
-
* @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a deadline, force-redeem shares or deallocation amount is not positive.
|
|
79
|
+
* @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
|
|
80
|
+
* @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
|
|
81
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
|
|
82
|
+
* @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
|
|
67
83
|
* @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
|
|
68
84
|
* @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
|
|
69
85
|
* @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
|
|
70
86
|
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
|
|
71
87
|
* @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
|
|
72
|
-
* @throws {TransactionPlanSignatureMismatchError} If a referenced
|
|
73
|
-
* @throws {BundlesPermitMismatchError} If a signed permit's
|
|
88
|
+
* @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with the step's action or its encoding arguments.
|
|
89
|
+
* @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
|
|
90
|
+
* @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
|
|
91
|
+
* @throws {NegativeInputError} If a Blue amount, native value, LTV bound or referral fee is negative.
|
|
92
|
+
* @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, or withdrawal-only funding is nonzero.
|
|
93
|
+
* @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
|
|
94
|
+
* @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
|
|
95
|
+
* @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
|
|
96
|
+
* @throws {ChainWNativeMissingError} If native funding targets a chain without wNative.
|
|
97
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If native funding targets a loan token other than wNative.
|
|
98
|
+
* @throws {UnexpectedRequirementSignatureError} If a Blue signature targets an inactive leg or native-funded token pull.
|
|
99
|
+
* @throws {DepositOwnerMismatchError} If a Blue signature belongs to another account.
|
|
100
|
+
* @throws {DepositAssetMismatchError} If a token signature names another loan token.
|
|
101
|
+
* @throws {DepositAmountMismatchError} If a token signature does not cover the repayment cap.
|
|
102
|
+
* @throws {DepositSpenderMismatchError} If a token signature names another spender.
|
|
103
|
+
* @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
|
|
104
|
+
* @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
|
|
105
|
+
* @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
|
|
106
|
+
* @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
|
|
74
107
|
* @example
|
|
75
108
|
* ```ts
|
|
76
109
|
* import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
|
|
@@ -86,19 +119,41 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
|
|
|
86
119
|
* Builds every step of the plan in order.
|
|
87
120
|
* @param plan - Plan whose referenced signature requests all carry a signature.
|
|
88
121
|
* @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
|
|
122
|
+
* @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
|
|
123
|
+
* @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
|
|
89
124
|
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
|
|
90
125
|
* @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
|
|
91
126
|
* @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
|
|
92
127
|
* @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
|
|
93
128
|
* @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
|
|
94
|
-
* @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a deadline, force-redeem shares or deallocation amount is not positive.
|
|
129
|
+
* @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
|
|
130
|
+
* @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
|
|
131
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
|
|
132
|
+
* @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
|
|
95
133
|
* @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
|
|
96
134
|
* @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
|
|
97
135
|
* @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
|
|
98
136
|
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
|
|
99
137
|
* @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
|
|
100
|
-
* @throws {TransactionPlanSignatureMismatchError} If a referenced
|
|
101
|
-
* @throws {BundlesPermitMismatchError} If a signed permit's
|
|
138
|
+
* @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with its action or encoding arguments.
|
|
139
|
+
* @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
|
|
140
|
+
* @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
|
|
141
|
+
* @throws {NegativeInputError} If a Blue amount, native value, LTV bound or referral fee is negative.
|
|
142
|
+
* @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, or withdrawal-only funding is nonzero.
|
|
143
|
+
* @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
|
|
144
|
+
* @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
|
|
145
|
+
* @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
|
|
146
|
+
* @throws {ChainWNativeMissingError} If native funding targets a chain without wNative.
|
|
147
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If native funding targets a loan token other than wNative.
|
|
148
|
+
* @throws {UnexpectedRequirementSignatureError} If a Blue signature targets an inactive leg or native-funded token pull.
|
|
149
|
+
* @throws {DepositOwnerMismatchError} If a Blue signature belongs to another account.
|
|
150
|
+
* @throws {DepositAssetMismatchError} If a token signature names another loan token.
|
|
151
|
+
* @throws {DepositAmountMismatchError} If a token signature does not cover the repayment cap.
|
|
152
|
+
* @throws {DepositSpenderMismatchError} If a token signature names another spender.
|
|
153
|
+
* @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
|
|
154
|
+
* @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
|
|
155
|
+
* @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
|
|
156
|
+
* @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
|
|
102
157
|
* @example
|
|
103
158
|
* ```ts
|
|
104
159
|
* import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
|