@morpho-org/morpho-sdk 10.4.0 → 10.5.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/lib/cjs/actions/blue/common.js +12 -3
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
- package/lib/cjs/actions/midnight/takeBorrow.js +14 -8
- package/lib/cjs/actions/midnight/takeLend.js +15 -9
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
- package/lib/cjs/actions/midnight/takeWithdraw.js +14 -8
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +3 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +106 -103
- package/lib/cjs/entities/midnight/midnight.js +120 -101
- package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +0 -1
- package/lib/cjs/helpers/constant.d.ts +7 -0
- package/lib/cjs/helpers/constant.js +8 -1
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +2 -1
- package/lib/cjs/helpers/validate.d.ts +25 -1
- package/lib/cjs/helpers/validate.js +25 -1
- package/lib/cjs/transactionPlan/assemble.d.ts +24 -0
- package/lib/cjs/transactionPlan/assemble.js +25 -0
- package/lib/cjs/transactionPlan/blue/borrow.js +14 -64
- package/lib/cjs/transactionPlan/blue/refinance.js +9 -11
- package/lib/cjs/transactionPlan/blue/repay.js +10 -24
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +49 -45
- package/lib/cjs/transactionPlan/blue/stored.d.ts +26 -0
- package/lib/cjs/transactionPlan/blue/stored.js +87 -0
- package/lib/cjs/transactionPlan/blue/supply.js +7 -22
- package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/blue/supplyCollateral.js +10 -15
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +14 -64
- package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -3
- package/lib/cjs/transactionPlan/blue/withdraw.js +67 -79
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +31 -30
- package/lib/cjs/transactionPlan/deposit.js +4 -7
- package/lib/cjs/transactionPlan/intent.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeBorrow.js +1 -1
- package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeLend.js +1 -1
- package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeRepay.js +1 -1
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
- package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +6 -2
- package/lib/cjs/transactionPlan/midnight/takeBorrow.js +10 -4
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +1 -1
- package/lib/cjs/transactionPlan/permit.d.ts +15 -2
- package/lib/cjs/transactionPlan/permit.js +26 -68
- package/lib/cjs/transactionPlan/plan.d.ts +51 -1
- package/lib/cjs/transactionPlan/plan.js +56 -13
- package/lib/cjs/transactionPlan/redeem.js +4 -7
- package/lib/cjs/transactionPlan/types.d.ts +4 -3
- package/lib/cjs/transactionPlan/vaultBinding.d.ts +29 -0
- package/lib/cjs/transactionPlan/vaultBinding.js +69 -0
- package/lib/cjs/transactionPlan/vaultRequirements.d.ts +20 -0
- package/lib/cjs/transactionPlan/vaultRequirements.js +37 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -13
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +10 -41
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +6 -18
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -12
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -13
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +2 -13
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +4 -7
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +12 -42
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +10 -41
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -13
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -13
- package/lib/cjs/transactionPlan/withdraw.js +4 -7
- package/lib/cjs/types/error.d.ts +27 -1
- package/lib/cjs/types/error.js +32 -3
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/blue/common.js +13 -4
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
- package/lib/esm/actions/midnight/takeBorrow.js +14 -8
- package/lib/esm/actions/midnight/takeLend.js +15 -9
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
- package/lib/esm/actions/midnight/takeWithdraw.js +14 -8
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/midnight/midnight.d.ts +106 -103
- package/lib/esm/entities/midnight/midnight.js +120 -101
- package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +0 -1
- package/lib/esm/helpers/constant.d.ts +7 -0
- package/lib/esm/helpers/constant.js +7 -0
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +25 -1
- package/lib/esm/helpers/validate.js +25 -2
- package/lib/esm/transactionPlan/assemble.d.ts +24 -0
- package/lib/esm/transactionPlan/assemble.js +21 -0
- package/lib/esm/transactionPlan/blue/borrow.js +15 -65
- package/lib/esm/transactionPlan/blue/refinance.js +10 -12
- package/lib/esm/transactionPlan/blue/repay.js +11 -25
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +50 -46
- package/lib/esm/transactionPlan/blue/stored.d.ts +26 -0
- package/lib/esm/transactionPlan/blue/stored.js +80 -0
- package/lib/esm/transactionPlan/blue/supply.js +7 -22
- package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/blue/supplyCollateral.js +10 -15
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +15 -65
- package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -3
- package/lib/esm/transactionPlan/blue/withdraw.js +70 -82
- package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
- package/lib/esm/transactionPlan/blue/withdrawCollateral.js +32 -31
- package/lib/esm/transactionPlan/deposit.js +5 -8
- package/lib/esm/transactionPlan/intent.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeBorrow.js +1 -1
- package/lib/esm/transactionPlan/midnight/makeLend.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeLend.js +1 -1
- package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeRepay.js +1 -1
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateral.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
- package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +6 -2
- package/lib/esm/transactionPlan/midnight/takeBorrow.js +11 -5
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/takeWithdraw.js +1 -1
- package/lib/esm/transactionPlan/permit.d.ts +15 -2
- package/lib/esm/transactionPlan/permit.js +25 -68
- package/lib/esm/transactionPlan/plan.d.ts +51 -1
- package/lib/esm/transactionPlan/plan.js +55 -13
- package/lib/esm/transactionPlan/redeem.js +5 -8
- package/lib/esm/transactionPlan/types.d.ts +4 -3
- package/lib/esm/transactionPlan/vaultBinding.d.ts +29 -0
- package/lib/esm/transactionPlan/vaultBinding.js +65 -0
- package/lib/esm/transactionPlan/vaultRequirements.d.ts +20 -0
- package/lib/esm/transactionPlan/vaultRequirements.js +34 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -14
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +12 -43
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +9 -21
- package/lib/esm/transactionPlan/vaultv1/redeem.js +2 -13
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +3 -14
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -14
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +5 -8
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +15 -45
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +12 -43
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/redeem.js +3 -14
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +3 -14
- package/lib/esm/transactionPlan/withdraw.js +5 -8
- package/lib/esm/types/error.d.ts +27 -1
- package/lib/esm/types/error.js +30 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +3 -3
|
@@ -5,12 +5,14 @@ exports.validateVaultPermitRequest = validateVaultPermitRequest;
|
|
|
5
5
|
exports.validateTokenPermitRequest = validateTokenPermitRequest;
|
|
6
6
|
exports.getSignedTokenPermit = getSignedTokenPermit;
|
|
7
7
|
exports.getVaultPermit = getSignedTokenPermit;
|
|
8
|
+
exports.selectVaultPermit = selectVaultPermit;
|
|
8
9
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
9
10
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
10
11
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
11
|
-
const
|
|
12
|
+
const common_js_1 = require("../actions/bundles/common.js");
|
|
12
13
|
const error_js_1 = require("./error.js");
|
|
13
14
|
const validation_js_1 = require("./validation.js");
|
|
15
|
+
const vaultBinding_js_1 = require("./vaultBinding.js");
|
|
14
16
|
/** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
|
|
15
17
|
function validatePermitPlanRequest(request, path) {
|
|
16
18
|
const args = (0, validation_js_1.getPlanObject)(request.args, `${path}.args`);
|
|
@@ -83,72 +85,10 @@ function validatePermitPlanRequest(request, path) {
|
|
|
83
85
|
}
|
|
84
86
|
/** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
|
|
85
87
|
function validateVaultPermitRequest(request, action) {
|
|
86
|
-
if (request.kind !== "permit") {
|
|
88
|
+
if (request.kind !== "permit" || !(0, vaultBinding_js_1.isVaultPermitAction)(action)) {
|
|
87
89
|
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
88
90
|
}
|
|
89
|
-
|
|
90
|
-
let asset;
|
|
91
|
-
let amount;
|
|
92
|
-
let exact = false;
|
|
93
|
-
switch (action.type) {
|
|
94
|
-
case "vaultV2Deposit":
|
|
95
|
-
spenderKey = "bundles.vaultBundlesV1";
|
|
96
|
-
asset = action.inputs.asset;
|
|
97
|
-
amount = action.inputs.assets;
|
|
98
|
-
exact = true;
|
|
99
|
-
break;
|
|
100
|
-
case "vaultV1Deposit":
|
|
101
|
-
spenderKey = "bundles.vaultBundlesV1";
|
|
102
|
-
asset = action.inputs.asset;
|
|
103
|
-
amount = action.inputs.assets;
|
|
104
|
-
exact = true;
|
|
105
|
-
break;
|
|
106
|
-
case "vaultV1Withdraw":
|
|
107
|
-
spenderKey = "bundles.vaultBundlesV1";
|
|
108
|
-
asset = action.inputs.vault;
|
|
109
|
-
amount = action.inputs.requiredShareAllowance;
|
|
110
|
-
break;
|
|
111
|
-
case "vaultV2Withdraw":
|
|
112
|
-
spenderKey = "bundles.vaultBundlesV1";
|
|
113
|
-
asset = action.inputs.vault;
|
|
114
|
-
amount = action.inputs.requiredShareAllowance;
|
|
115
|
-
break;
|
|
116
|
-
case "vaultV2Redeem":
|
|
117
|
-
spenderKey = "bundles.vaultBundlesV1";
|
|
118
|
-
asset = action.inputs.vault;
|
|
119
|
-
amount = action.inputs.shares;
|
|
120
|
-
break;
|
|
121
|
-
case "vaultV1Redeem":
|
|
122
|
-
spenderKey = "bundles.vaultBundlesV1";
|
|
123
|
-
asset = action.inputs.vault;
|
|
124
|
-
amount = action.inputs.shares;
|
|
125
|
-
break;
|
|
126
|
-
case "vaultV2ForceWithdraw":
|
|
127
|
-
spenderKey = "bundles.vaultExitBundlesV1";
|
|
128
|
-
asset = action.inputs.vault;
|
|
129
|
-
amount = viem_1.maxUint256;
|
|
130
|
-
exact = true;
|
|
131
|
-
break;
|
|
132
|
-
case "vaultV1MigrateToV2":
|
|
133
|
-
spenderKey = "bundles.vaultBundlesV1";
|
|
134
|
-
asset = action.inputs.sourceVault;
|
|
135
|
-
amount = action.inputs.requiredShareAllowance;
|
|
136
|
-
break;
|
|
137
|
-
case "vaultV2InKindRedeem":
|
|
138
|
-
spenderKey = "bundles.vaultExitBundlesV1";
|
|
139
|
-
asset = action.inputs.vault;
|
|
140
|
-
amount = viem_1.maxUint256;
|
|
141
|
-
exact = true;
|
|
142
|
-
break;
|
|
143
|
-
case "vaultV1InKindRedeem":
|
|
144
|
-
spenderKey = "bundles.vaultExitBundlesV1";
|
|
145
|
-
asset = action.inputs.vault;
|
|
146
|
-
amount = viem_1.maxUint256;
|
|
147
|
-
exact = true;
|
|
148
|
-
break;
|
|
149
|
-
default:
|
|
150
|
-
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
151
|
-
}
|
|
91
|
+
const { bundler, asset, restore } = (0, vaultBinding_js_1.getVaultPermitBinding)(action);
|
|
152
92
|
if (action.signatureRequestIds.tokenPermit !== request.id) {
|
|
153
93
|
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
154
94
|
}
|
|
@@ -156,10 +96,10 @@ function validateVaultPermitRequest(request, action) {
|
|
|
156
96
|
chainId: action.inputs.chainId,
|
|
157
97
|
account: action.inputs.account,
|
|
158
98
|
deadline: action.inputs.deadline,
|
|
159
|
-
bundler
|
|
99
|
+
bundler,
|
|
160
100
|
asset,
|
|
161
|
-
amount,
|
|
162
|
-
exact,
|
|
101
|
+
amount: restore.amount,
|
|
102
|
+
exact: restore.exact,
|
|
163
103
|
});
|
|
164
104
|
}
|
|
165
105
|
/** @internal Binds the signing payload and encoding arguments to a registered bundle's token pull. */
|
|
@@ -241,3 +181,21 @@ function getSignedTokenPermit(requests, { id, asset, owner, }) {
|
|
|
241
181
|
},
|
|
242
182
|
};
|
|
243
183
|
}
|
|
184
|
+
function selectVaultPermit(action, requests) {
|
|
185
|
+
const { chainId, account, deadline } = action.inputs;
|
|
186
|
+
const { bundler, asset, build } = (0, vaultBinding_js_1.getVaultPermitBinding)(action);
|
|
187
|
+
const signature = getSignedTokenPermit(requests, {
|
|
188
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
189
|
+
asset,
|
|
190
|
+
owner: account,
|
|
191
|
+
});
|
|
192
|
+
const signatures = signature ? [signature] : [];
|
|
193
|
+
const expected = {
|
|
194
|
+
spender: (0, morpho_ts_1.getChainAddress)(chainId, bundler),
|
|
195
|
+
amount: build.amount,
|
|
196
|
+
deadline,
|
|
197
|
+
};
|
|
198
|
+
return build.pull === "token"
|
|
199
|
+
? (0, common_js_1.selectBundlesTokenRequirementSignature)(signatures, expected)
|
|
200
|
+
: (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, expected);
|
|
201
|
+
}
|
|
@@ -57,6 +57,56 @@ export declare function verifyPlanSignature(request: SignatureRequest, signature
|
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
59
|
export declare function getPendingSignatureRequests(plan: TransactionPlan): readonly SignatureRequest[];
|
|
60
|
+
/**
|
|
61
|
+
* @internal Whether a step's transaction carries the plan's `calldataOrigin`. Operation steps do;
|
|
62
|
+
* approval and authorization prerequisites never do, matching the entity path. Every action type
|
|
63
|
+
* must be listed, so a new type does not compile until its role is chosen.
|
|
64
|
+
*/
|
|
65
|
+
export declare const CALLDATA_ORIGIN_ROLE: {
|
|
66
|
+
readonly blueBorrow: "operation";
|
|
67
|
+
readonly blueRefinance: "operation";
|
|
68
|
+
readonly blueRepay: "operation";
|
|
69
|
+
readonly blueRepayWithdrawCollateral: "operation";
|
|
70
|
+
readonly blueSupply: "operation";
|
|
71
|
+
readonly blueSupplyCollateral: "operation";
|
|
72
|
+
readonly blueSupplyCollateralBorrow: "operation";
|
|
73
|
+
readonly blueWithdraw: "operation";
|
|
74
|
+
readonly blueWithdrawBuyCallback: "operation";
|
|
75
|
+
readonly blueWithdrawCollateral: "operation";
|
|
76
|
+
readonly erc20Approval: "prerequisite";
|
|
77
|
+
readonly midnightAuthorization: "prerequisite";
|
|
78
|
+
readonly midnightCancelOffers: "operation";
|
|
79
|
+
readonly midnightMakeBorrow: "operation";
|
|
80
|
+
readonly midnightMakeLend: "operation";
|
|
81
|
+
readonly midnightMakeRepay: "operation";
|
|
82
|
+
readonly midnightMakeWithdraw: "operation";
|
|
83
|
+
readonly midnightRedeem: "operation";
|
|
84
|
+
readonly midnightRepayWithdrawCollateral: "operation";
|
|
85
|
+
readonly midnightSupplyBlueMakeLend: "operation";
|
|
86
|
+
readonly midnightSupplyCollateral: "operation";
|
|
87
|
+
readonly midnightSupplyCollateralBatch: "operation";
|
|
88
|
+
readonly midnightSupplyCollateralMakeBorrow: "operation";
|
|
89
|
+
readonly midnightSupplyCollateralTakeBorrow: "operation";
|
|
90
|
+
readonly midnightSupplyCollateralWithNative: "operation";
|
|
91
|
+
readonly midnightTakeBorrow: "operation";
|
|
92
|
+
readonly midnightTakeLend: "operation";
|
|
93
|
+
readonly midnightTakeRepayWithdrawCollateral: "operation";
|
|
94
|
+
readonly midnightTakeWithdraw: "operation";
|
|
95
|
+
readonly midnightWithdrawCollateral: "operation";
|
|
96
|
+
readonly midnightWithdrawCollateralBatch: "operation";
|
|
97
|
+
readonly morphoAuthorization: "prerequisite";
|
|
98
|
+
readonly vaultV1Deposit: "operation";
|
|
99
|
+
readonly vaultV1InKindRedeem: "operation";
|
|
100
|
+
readonly vaultV1MigrateToV2: "operation";
|
|
101
|
+
readonly vaultV1Redeem: "operation";
|
|
102
|
+
readonly vaultV1Withdraw: "operation";
|
|
103
|
+
readonly vaultV2Deposit: "operation";
|
|
104
|
+
readonly vaultV2ForceRedeem: "operation";
|
|
105
|
+
readonly vaultV2ForceWithdraw: "operation";
|
|
106
|
+
readonly vaultV2InKindRedeem: "operation";
|
|
107
|
+
readonly vaultV2Redeem: "operation";
|
|
108
|
+
readonly vaultV2Withdraw: "operation";
|
|
109
|
+
};
|
|
60
110
|
/**
|
|
61
111
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
62
112
|
* Builds one transaction from a step, its fixed inputs and the signatures its action names.
|
|
@@ -68,7 +118,7 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
|
|
|
68
118
|
* not operation amounts, market parameters or referral fees/recipients. Protect those unsigned fields.
|
|
69
119
|
* @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
|
|
70
120
|
* @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
|
|
71
|
-
* @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
|
|
121
|
+
* @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set, except for ERC-20 approval, Morpho authorization and Midnight authorization prerequisite steps.
|
|
72
122
|
* @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
|
|
73
123
|
* @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
|
|
74
124
|
* @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CALLDATA_ORIGIN_ROLE = void 0;
|
|
3
4
|
exports.applySignatures = applySignatures;
|
|
4
5
|
exports.verifyPlanSignature = verifyPlanSignature;
|
|
5
6
|
exports.getPendingSignatureRequests = getPendingSignatureRequests;
|
|
@@ -41,6 +42,7 @@ const withdrawCollateralBatch_js_1 = require("./midnight/withdrawCollateralBatch
|
|
|
41
42
|
const permit_js_1 = require("./permit.js");
|
|
42
43
|
const validateActions_js_1 = require("./validateActions.js");
|
|
43
44
|
const validation_js_1 = require("./validation.js");
|
|
45
|
+
const vaultBinding_js_1 = require("./vaultBinding.js");
|
|
44
46
|
const deposit_js_1 = require("./vaultv1/deposit.js");
|
|
45
47
|
const inKindRedeem_js_1 = require("./vaultv1/inKindRedeem.js");
|
|
46
48
|
const migrateToV2_js_1 = require("./vaultv1/migrateToV2.js");
|
|
@@ -251,17 +253,7 @@ function validateSignatureRequest(request, action) {
|
|
|
251
253
|
nonce: action.inputs.authorizationNonce,
|
|
252
254
|
});
|
|
253
255
|
}
|
|
254
|
-
if (request.kind === "permit" &&
|
|
255
|
-
(action.type === "vaultV2Deposit" ||
|
|
256
|
-
action.type === "vaultV1Deposit" ||
|
|
257
|
-
action.type === "vaultV1Withdraw" ||
|
|
258
|
-
action.type === "vaultV2Withdraw" ||
|
|
259
|
-
action.type === "vaultV2Redeem" ||
|
|
260
|
-
action.type === "vaultV1Redeem" ||
|
|
261
|
-
action.type === "vaultV2ForceWithdraw" ||
|
|
262
|
-
action.type === "vaultV1MigrateToV2" ||
|
|
263
|
-
action.type === "vaultV2InKindRedeem" ||
|
|
264
|
-
action.type === "vaultV1InKindRedeem")) {
|
|
256
|
+
if (request.kind === "permit" && (0, vaultBinding_js_1.isVaultPermitAction)(action)) {
|
|
265
257
|
(0, permit_js_1.validateVaultPermitRequest)(request, action);
|
|
266
258
|
return;
|
|
267
259
|
}
|
|
@@ -409,6 +401,56 @@ function encodeStep(action, requests) {
|
|
|
409
401
|
return (0, inKindRedeem_js_2.buildVaultV2InKindRedeem)(action, requests);
|
|
410
402
|
}
|
|
411
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* @internal Whether a step's transaction carries the plan's `calldataOrigin`. Operation steps do;
|
|
406
|
+
* approval and authorization prerequisites never do, matching the entity path. Every action type
|
|
407
|
+
* must be listed, so a new type does not compile until its role is chosen.
|
|
408
|
+
*/
|
|
409
|
+
exports.CALLDATA_ORIGIN_ROLE = {
|
|
410
|
+
blueBorrow: "operation",
|
|
411
|
+
blueRefinance: "operation",
|
|
412
|
+
blueRepay: "operation",
|
|
413
|
+
blueRepayWithdrawCollateral: "operation",
|
|
414
|
+
blueSupply: "operation",
|
|
415
|
+
blueSupplyCollateral: "operation",
|
|
416
|
+
blueSupplyCollateralBorrow: "operation",
|
|
417
|
+
blueWithdraw: "operation",
|
|
418
|
+
blueWithdrawBuyCallback: "operation",
|
|
419
|
+
blueWithdrawCollateral: "operation",
|
|
420
|
+
erc20Approval: "prerequisite",
|
|
421
|
+
midnightAuthorization: "prerequisite",
|
|
422
|
+
midnightCancelOffers: "operation",
|
|
423
|
+
midnightMakeBorrow: "operation",
|
|
424
|
+
midnightMakeLend: "operation",
|
|
425
|
+
midnightMakeRepay: "operation",
|
|
426
|
+
midnightMakeWithdraw: "operation",
|
|
427
|
+
midnightRedeem: "operation",
|
|
428
|
+
midnightRepayWithdrawCollateral: "operation",
|
|
429
|
+
midnightSupplyBlueMakeLend: "operation",
|
|
430
|
+
midnightSupplyCollateral: "operation",
|
|
431
|
+
midnightSupplyCollateralBatch: "operation",
|
|
432
|
+
midnightSupplyCollateralMakeBorrow: "operation",
|
|
433
|
+
midnightSupplyCollateralTakeBorrow: "operation",
|
|
434
|
+
midnightSupplyCollateralWithNative: "operation",
|
|
435
|
+
midnightTakeBorrow: "operation",
|
|
436
|
+
midnightTakeLend: "operation",
|
|
437
|
+
midnightTakeRepayWithdrawCollateral: "operation",
|
|
438
|
+
midnightTakeWithdraw: "operation",
|
|
439
|
+
midnightWithdrawCollateral: "operation",
|
|
440
|
+
midnightWithdrawCollateralBatch: "operation",
|
|
441
|
+
morphoAuthorization: "prerequisite",
|
|
442
|
+
vaultV1Deposit: "operation",
|
|
443
|
+
vaultV1InKindRedeem: "operation",
|
|
444
|
+
vaultV1MigrateToV2: "operation",
|
|
445
|
+
vaultV1Redeem: "operation",
|
|
446
|
+
vaultV1Withdraw: "operation",
|
|
447
|
+
vaultV2Deposit: "operation",
|
|
448
|
+
vaultV2ForceRedeem: "operation",
|
|
449
|
+
vaultV2ForceWithdraw: "operation",
|
|
450
|
+
vaultV2InKindRedeem: "operation",
|
|
451
|
+
vaultV2Redeem: "operation",
|
|
452
|
+
vaultV2Withdraw: "operation",
|
|
453
|
+
};
|
|
412
454
|
/**
|
|
413
455
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
414
456
|
* Builds one transaction from a step, its fixed inputs and the signatures its action names.
|
|
@@ -420,7 +462,7 @@ function encodeStep(action, requests) {
|
|
|
420
462
|
* not operation amounts, market parameters or referral fees/recipients. Protect those unsigned fields.
|
|
421
463
|
* @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
|
|
422
464
|
* @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
|
|
423
|
-
* @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
|
|
465
|
+
* @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set, except for ERC-20 approval, Morpho authorization and Midnight authorization prerequisite steps.
|
|
424
466
|
* @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
|
|
425
467
|
* @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
|
|
426
468
|
* @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
|
|
@@ -525,7 +567,8 @@ function buildTransaction(plan, step) {
|
|
|
525
567
|
return (0, morpho_ts_1.deepFreeze)({
|
|
526
568
|
to,
|
|
527
569
|
value,
|
|
528
|
-
data: plan.calldataOrigin === undefined
|
|
570
|
+
data: plan.calldataOrigin === undefined ||
|
|
571
|
+
exports.CALLDATA_ORIGIN_ROLE[step.action.type] === "prerequisite"
|
|
529
572
|
? data
|
|
530
573
|
: (0, viem_1.concatHex)([data, plan.calldataOrigin]),
|
|
531
574
|
action,
|
|
@@ -6,6 +6,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
6
6
|
const common_js_1 = require("../actions/bundles/common.js");
|
|
7
7
|
const validate_js_1 = require("../helpers/validate.js");
|
|
8
8
|
const index_js_1 = require("../types/index.js");
|
|
9
|
+
const assemble_js_1 = require("./assemble.js");
|
|
9
10
|
const intent_js_1 = require("./intent.js");
|
|
10
11
|
const shareSpending_js_1 = require("./shareSpending.js");
|
|
11
12
|
const validation_js_1 = require("./validation.js");
|
|
@@ -30,12 +31,8 @@ async function prepareVaultRedeem(client, params) {
|
|
|
30
31
|
supportSignature: intent.supportSignature,
|
|
31
32
|
now,
|
|
32
33
|
});
|
|
33
|
-
return (0,
|
|
34
|
-
|
|
35
|
-
account,
|
|
36
|
-
chainId,
|
|
37
|
-
expiresAt: intent.expiresAt,
|
|
38
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
34
|
+
return (0, assemble_js_1.freezePlan)({
|
|
35
|
+
...(0, assemble_js_1.planHeader)({ chainId, account }, intent),
|
|
39
36
|
steps: [
|
|
40
37
|
...approvals,
|
|
41
38
|
{
|
|
@@ -51,7 +48,7 @@ async function prepareVaultRedeem(client, params) {
|
|
|
51
48
|
},
|
|
52
49
|
],
|
|
53
50
|
signatureRequests,
|
|
54
|
-
})
|
|
51
|
+
}, { detach: true });
|
|
55
52
|
}
|
|
56
53
|
/** @internal Validates stored V1 and V2 exact-share redemption inputs. */
|
|
57
54
|
function validateRedeemPlanAction(action, path) {
|
|
@@ -9,6 +9,7 @@ import type { MidnightTakeBorrowParams } from "../actions/midnight/takeBorrow.js
|
|
|
9
9
|
import type { MidnightTakeLendParams } from "../actions/midnight/takeLend.js";
|
|
10
10
|
import type { MidnightTakeRepayWithdrawCollateralParams } from "../actions/midnight/takeRepayWithdrawCollateral.js";
|
|
11
11
|
import type { MidnightTakeableOffer } from "../actions/midnight/types.js";
|
|
12
|
+
import type { BlueReallocationInput } from "../helpers/validate.js";
|
|
12
13
|
import type { MidnightBlueSupply, MidnightCollateralTransfer } from "../types/action.js";
|
|
13
14
|
import type { AuthorizationSignatureArgs, PermitAction, RequirementTypedData, VaultV1MigrateToV2AmountArgs, VaultV2BlueReallocation } from "../types/index.js";
|
|
14
15
|
import type { MidnightCancelAndMakeParams } from "../types/midnightCancelAndMake.js";
|
|
@@ -255,12 +256,12 @@ export type Action = {
|
|
|
255
256
|
} | {
|
|
256
257
|
readonly type: "blueWithdraw";
|
|
257
258
|
readonly inputs: ActionInputs & {
|
|
258
|
-
readonly marketParams:
|
|
259
|
+
readonly marketParams: Readonly<InputMarketParams>;
|
|
259
260
|
readonly withdrawAssets: bigint;
|
|
260
261
|
readonly withdrawShares: bigint;
|
|
261
262
|
/** Maximum WAD-scaled penalty rate per reallocation, defaulting to zero; it does not bound total proceeds lost. */
|
|
262
263
|
readonly maxPenalty?: bigint;
|
|
263
|
-
readonly reallocations: readonly
|
|
264
|
+
readonly reallocations: readonly BlueReallocationInput[];
|
|
264
265
|
readonly deadline: bigint;
|
|
265
266
|
readonly referralFeePct: bigint;
|
|
266
267
|
readonly referralFeeRecipient: Address;
|
|
@@ -470,7 +471,7 @@ export interface TransactionPlan {
|
|
|
470
471
|
readonly account: Address;
|
|
471
472
|
/** Unix seconds. One expiry governs every step deadline and signature deadline. */
|
|
472
473
|
readonly expiresAt: number;
|
|
473
|
-
/** Appended verbatim to
|
|
474
|
+
/** Appended verbatim to the action transaction's calldata; ERC-20 approval, Morpho authorization and Midnight authorization steps carry none. */
|
|
474
475
|
readonly calldataOrigin?: Hex;
|
|
475
476
|
readonly steps: readonly Step[];
|
|
476
477
|
readonly signatureRequests: readonly SignatureRequest[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { Action } from "./types.js";
|
|
3
|
+
declare const VAULT_PERMIT_ACTION_TYPES: readonly ["vaultV2Deposit", "vaultV1Deposit", "vaultV1Withdraw", "vaultV2Withdraw", "vaultV2Redeem", "vaultV1Redeem", "vaultV2ForceWithdraw", "vaultV1MigrateToV2", "vaultV2InKindRedeem", "vaultV1InKindRedeem"];
|
|
4
|
+
/** @internal Vault actions whose step pulls a token through a bundle and may consume a permit. */
|
|
5
|
+
export type VaultPermitAction = Extract<Action, {
|
|
6
|
+
readonly type: (typeof VAULT_PERMIT_ACTION_TYPES)[number];
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* @internal The bundle, signed token and amounts a vault action's token permit must match.
|
|
10
|
+
* `restore` binds the stored signing payload; `build` is what the bundle pull selects, which differs
|
|
11
|
+
* from `restore` for deposits (`assets` versus `assets ?? nativeAssets`).
|
|
12
|
+
*/
|
|
13
|
+
export interface VaultPermitBinding {
|
|
14
|
+
readonly bundler: "bundles.vaultBundlesV1" | "bundles.vaultExitBundlesV1";
|
|
15
|
+
readonly asset: Address;
|
|
16
|
+
readonly restore: {
|
|
17
|
+
readonly amount: bigint | undefined;
|
|
18
|
+
readonly exact: boolean;
|
|
19
|
+
};
|
|
20
|
+
readonly build: {
|
|
21
|
+
readonly amount: bigint;
|
|
22
|
+
readonly pull: "token" | "shares";
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** @internal Whether the action is one of the vault actions a token permit can fund. */
|
|
26
|
+
export declare function isVaultPermitAction(action: Action): action is VaultPermitAction;
|
|
27
|
+
/** @internal Reads the permit binding from the vault action's stored inputs. */
|
|
28
|
+
export declare function getVaultPermitBinding(action: VaultPermitAction): VaultPermitBinding;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isVaultPermitAction = isVaultPermitAction;
|
|
4
|
+
exports.getVaultPermitBinding = getVaultPermitBinding;
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const VAULT_PERMIT_ACTION_TYPES = [
|
|
7
|
+
"vaultV2Deposit",
|
|
8
|
+
"vaultV1Deposit",
|
|
9
|
+
"vaultV1Withdraw",
|
|
10
|
+
"vaultV2Withdraw",
|
|
11
|
+
"vaultV2Redeem",
|
|
12
|
+
"vaultV1Redeem",
|
|
13
|
+
"vaultV2ForceWithdraw",
|
|
14
|
+
"vaultV1MigrateToV2",
|
|
15
|
+
"vaultV2InKindRedeem",
|
|
16
|
+
"vaultV1InKindRedeem",
|
|
17
|
+
];
|
|
18
|
+
/** @internal Whether the action is one of the vault actions a token permit can fund. */
|
|
19
|
+
function isVaultPermitAction(action) {
|
|
20
|
+
return VAULT_PERMIT_ACTION_TYPES.includes(action.type);
|
|
21
|
+
}
|
|
22
|
+
/** @internal Reads the permit binding from the vault action's stored inputs. */
|
|
23
|
+
function getVaultPermitBinding(action) {
|
|
24
|
+
switch (action.type) {
|
|
25
|
+
case "vaultV2Deposit":
|
|
26
|
+
case "vaultV1Deposit":
|
|
27
|
+
return {
|
|
28
|
+
bundler: "bundles.vaultBundlesV1",
|
|
29
|
+
asset: action.inputs.asset,
|
|
30
|
+
restore: { amount: action.inputs.assets, exact: true },
|
|
31
|
+
build: {
|
|
32
|
+
amount: action.inputs.assets ?? action.inputs.nativeAssets,
|
|
33
|
+
pull: "token",
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
case "vaultV1Withdraw":
|
|
37
|
+
case "vaultV2Withdraw":
|
|
38
|
+
return {
|
|
39
|
+
bundler: "bundles.vaultBundlesV1",
|
|
40
|
+
asset: action.inputs.vault,
|
|
41
|
+
restore: { amount: action.inputs.requiredShareAllowance, exact: false },
|
|
42
|
+
build: { amount: action.inputs.requiredShareAllowance, pull: "shares" },
|
|
43
|
+
};
|
|
44
|
+
case "vaultV2Redeem":
|
|
45
|
+
case "vaultV1Redeem":
|
|
46
|
+
return {
|
|
47
|
+
bundler: "bundles.vaultBundlesV1",
|
|
48
|
+
asset: action.inputs.vault,
|
|
49
|
+
restore: { amount: action.inputs.shares, exact: false },
|
|
50
|
+
build: { amount: action.inputs.shares, pull: "shares" },
|
|
51
|
+
};
|
|
52
|
+
case "vaultV1MigrateToV2":
|
|
53
|
+
return {
|
|
54
|
+
bundler: "bundles.vaultBundlesV1",
|
|
55
|
+
asset: action.inputs.sourceVault,
|
|
56
|
+
restore: { amount: action.inputs.requiredShareAllowance, exact: false },
|
|
57
|
+
build: { amount: action.inputs.requiredShareAllowance, pull: "shares" },
|
|
58
|
+
};
|
|
59
|
+
case "vaultV2ForceWithdraw":
|
|
60
|
+
case "vaultV2InKindRedeem":
|
|
61
|
+
case "vaultV1InKindRedeem":
|
|
62
|
+
return {
|
|
63
|
+
bundler: "bundles.vaultExitBundlesV1",
|
|
64
|
+
asset: action.inputs.vault,
|
|
65
|
+
restore: { amount: viem_1.maxUint256, exact: true },
|
|
66
|
+
build: { amount: viem_1.maxUint256, pull: "shares" },
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import { type ActionRequirement } from "../types/index.js";
|
|
3
|
+
import type { SignatureRequest, Step } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal Turns a vault exit's share requirements into approval steps and permit requests.
|
|
6
|
+
* Steps take the ID `${id}:approval` and requests `${id}:tokenPermit`; `signatureRequestIds`
|
|
7
|
+
* names the permit only when one is requested.
|
|
8
|
+
* @throws {UnsupportedRequirementSignatureError} If a requirement is a signature other than a permit.
|
|
9
|
+
*/
|
|
10
|
+
export declare function vaultRequirementSteps(requirements: readonly ActionRequirement[], { id, chainId, account, }: {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly chainId: number;
|
|
13
|
+
readonly account: Address;
|
|
14
|
+
}): {
|
|
15
|
+
readonly approvals: Step[];
|
|
16
|
+
readonly signatureRequests: SignatureRequest[];
|
|
17
|
+
readonly signatureRequestIds: {
|
|
18
|
+
readonly tokenPermit?: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vaultRequirementSteps = vaultRequirementSteps;
|
|
4
|
+
const index_js_1 = require("../types/index.js");
|
|
5
|
+
const requirements_js_1 = require("./requirements.js");
|
|
6
|
+
/**
|
|
7
|
+
* @internal Turns a vault exit's share requirements into approval steps and permit requests.
|
|
8
|
+
* Steps take the ID `${id}:approval` and requests `${id}:tokenPermit`; `signatureRequestIds`
|
|
9
|
+
* names the permit only when one is requested.
|
|
10
|
+
* @throws {UnsupportedRequirementSignatureError} If a requirement is a signature other than a permit.
|
|
11
|
+
*/
|
|
12
|
+
function vaultRequirementSteps(requirements, { id, chainId, account, }) {
|
|
13
|
+
const approvals = [];
|
|
14
|
+
const signatureRequests = [];
|
|
15
|
+
const tokenPermit = `${id}:tokenPermit`;
|
|
16
|
+
for (const requirement of requirements) {
|
|
17
|
+
if ((0, index_js_1.isRequirementApproval)(requirement)) {
|
|
18
|
+
approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
|
|
19
|
+
id: `${id}:approval`,
|
|
20
|
+
chainId,
|
|
21
|
+
account,
|
|
22
|
+
denomination: "shares",
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
else if (requirement.action.type === "permit") {
|
|
26
|
+
signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)({ action: requirement.action }, tokenPermit));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new index_js_1.UnsupportedRequirementSignatureError(requirement.action.type);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
approvals,
|
|
34
|
+
signatureRequests,
|
|
35
|
+
signatureRequestIds: signatureRequests.length > 0 ? { tokenPermit } : {},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -47,7 +47,7 @@ export interface VaultV1DepositPlanParams extends DepositPlanParams<AccrualVault
|
|
|
47
47
|
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
|
|
48
48
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
49
49
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
50
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
50
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
51
51
|
* @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
|
|
52
52
|
* @returns A plan with approvals, concrete signature requests and the deposit step.
|
|
53
53
|
* @throws {InvalidBigIntInputError} when `now` is not a bigint.
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.prepareVaultV1Deposit = prepareVaultV1Deposit;
|
|
4
4
|
exports.buildVaultV1Deposit = buildVaultV1Deposit;
|
|
5
|
-
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
-
const common_js_1 = require("../../actions/bundles/common.js");
|
|
7
5
|
const deposit_js_1 = require("../../actions/vaultV1/deposit.js");
|
|
8
6
|
const deposit_js_2 = require("../deposit.js");
|
|
9
7
|
const permit_js_1 = require("../permit.js");
|
|
@@ -25,7 +23,7 @@ const permit_js_1 = require("../permit.js");
|
|
|
25
23
|
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
|
|
26
24
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
27
25
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
28
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
26
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
29
27
|
* @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
|
|
30
28
|
* @returns A plan with approvals, concrete signature requests and the deposit step.
|
|
31
29
|
* @throws {InvalidBigIntInputError} when `now` is not a bigint.
|
|
@@ -71,16 +69,7 @@ async function prepareVaultV1Deposit(client, params) {
|
|
|
71
69
|
/** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
|
|
72
70
|
function buildVaultV1Deposit(action, requests) {
|
|
73
71
|
const { asset, chainId, account, assets, nativeAssets, ...args } = action.inputs;
|
|
74
|
-
const
|
|
75
|
-
id: action.signatureRequestIds.tokenPermit,
|
|
76
|
-
asset,
|
|
77
|
-
owner: account,
|
|
78
|
-
});
|
|
79
|
-
const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signature ? [signature] : [], {
|
|
80
|
-
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
|
|
81
|
-
amount: assets ?? nativeAssets,
|
|
82
|
-
deadline: action.inputs.deadline,
|
|
83
|
-
});
|
|
72
|
+
const requirementSignature = (0, permit_js_1.selectVaultPermit)(action, requests);
|
|
84
73
|
return (0, deposit_js_1.vaultV1Deposit)({
|
|
85
74
|
vault: { chainId, address: action.inputs.vault, asset },
|
|
86
75
|
args: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AccrualVault, MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import type { ReferenceTimestampParams, Transaction, VaultV1InKindRedeemAction } from "../../types/index.js";
|
|
4
4
|
import { type IntentParams } from "../intent.js";
|
|
5
5
|
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
6
6
|
/**
|