@morpho-org/morpho-sdk 10.4.0 → 10.5.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/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +5 -1
- package/lib/cjs/actions/blue/common.js +12 -3
- 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/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/midnight/midnight.d.ts +100 -103
- package/lib/cjs/entities/midnight/midnight.js +99 -99
- package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/cjs/entities/vaultV2/vaultV2.js +39 -2
- 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/validate.d.ts +11 -1
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- 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 +2 -2
- package/lib/cjs/transactionPlan/midnight/takeBorrow.js +2 -2
- 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 +2 -1
- package/lib/cjs/types/error.js +3 -2
- 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/common.js +13 -4
- 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/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +100 -103
- package/lib/esm/entities/midnight/midnight.js +99 -99
- package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/esm/entities/vaultV2/vaultV2.js +40 -3
- 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/validate.d.ts +11 -1
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- 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 +2 -2
- package/lib/esm/transactionPlan/midnight/takeBorrow.js +2 -2
- 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 +2 -1
- package/lib/esm/types/error.js +3 -2
- 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
|
@@ -15,11 +15,13 @@ const index_js_1 = require("../../helpers/index.js");
|
|
|
15
15
|
const parse_js_1 = require("../../helpers/parse.js");
|
|
16
16
|
const quoteBlueRepay_js_1 = require("../../helpers/quoteBlueRepay.js");
|
|
17
17
|
const index_js_2 = require("../../types/index.js");
|
|
18
|
+
const assemble_js_1 = require("../assemble.js");
|
|
18
19
|
const error_js_1 = require("../error.js");
|
|
19
20
|
const permit_js_1 = require("../permit.js");
|
|
20
21
|
const validation_js_1 = require("../validation.js");
|
|
21
22
|
const authorization_js_1 = require("./authorization.js");
|
|
22
23
|
const prepare_js_1 = require("./prepare.js");
|
|
24
|
+
const stored_js_1 = require("./stored.js");
|
|
23
25
|
/**
|
|
24
26
|
* Prepares one BlueBundlesV1 repayment and collateral withdrawal from caller-fetched snapshots.
|
|
25
27
|
* Withdrawal health uses the expiry floored at max(now, lastUpdate); expiries more than
|
|
@@ -79,23 +81,24 @@ const prepare_js_1 = require("./prepare.js");
|
|
|
79
81
|
*/
|
|
80
82
|
async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
81
83
|
const id = "blueRepayWithdrawCollateral";
|
|
82
|
-
const
|
|
84
|
+
const captured = captureRepayWithdrawInputs(params);
|
|
85
|
+
const { chainId, account, marketId, marketData, now } = captured;
|
|
83
86
|
let inputs;
|
|
84
|
-
const prepared = await (0, prepare_js_1.prepareBlue)({ client, params:
|
|
85
|
-
const marketParams =
|
|
87
|
+
const prepared = await (0, prepare_js_1.prepareBlue)({ client, params: captured }, (intent) => {
|
|
88
|
+
const marketParams = marketData.market.params;
|
|
86
89
|
// Reject chain and referral mismatches before deriving a repayment quote.
|
|
87
|
-
(0, index_js_1.validateChainId)(client.chain?.id,
|
|
90
|
+
(0, index_js_1.validateChainId)(client.chain?.id, chainId);
|
|
88
91
|
const common = (0, common_js_1.parseBlueBundlesV1Common)({
|
|
89
|
-
chainId
|
|
90
|
-
userAddress:
|
|
92
|
+
chainId,
|
|
93
|
+
userAddress: account,
|
|
91
94
|
deadline: intent.deadline,
|
|
92
95
|
referralFeePct: intent.referralFeePct,
|
|
93
96
|
referralFeeRecipient: intent.referralFeeRecipient,
|
|
94
97
|
});
|
|
95
|
-
const { repayAssets, repayShares, collateralAssets, hasRepay } = getRepayWithdrawAmounts(params);
|
|
98
|
+
const { repayAssets, repayShares, collateralAssets, hasRepay } = getRepayWithdrawAmounts(params, marketId);
|
|
96
99
|
const quoteParams = {
|
|
97
|
-
positionData: getMatchingPosition(
|
|
98
|
-
marketId
|
|
100
|
+
positionData: getMatchingPosition(captured),
|
|
101
|
+
marketId,
|
|
99
102
|
repayAssets,
|
|
100
103
|
repayShares,
|
|
101
104
|
deadline: intent.deadline,
|
|
@@ -106,7 +109,7 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
106
109
|
const maxRepayAssets = expectedRepayAssets +
|
|
107
110
|
(0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(expectedRepayAssets, common.referralFeePct);
|
|
108
111
|
const nativeValue = (0, parse_js_1.parseNativeFunding)({
|
|
109
|
-
chainId
|
|
112
|
+
chainId,
|
|
110
113
|
token: marketParams.loanToken,
|
|
111
114
|
fundedAmount: maxRepayAssets,
|
|
112
115
|
nativeAmount: params.funding?.type === "native" ? maxRepayAssets : undefined,
|
|
@@ -121,13 +124,13 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
121
124
|
positionData: postRepayPosition,
|
|
122
125
|
withdrawAmount: collateralAssets,
|
|
123
126
|
lltv: marketParams.lltv,
|
|
124
|
-
marketId
|
|
127
|
+
marketId,
|
|
125
128
|
});
|
|
126
129
|
}
|
|
127
130
|
const tx = (0, repayWithdrawCollateral_js_1.blueRepayWithdrawCollateral)({
|
|
128
|
-
market: { chainId
|
|
131
|
+
market: { chainId, marketParams },
|
|
129
132
|
args: {
|
|
130
|
-
userAddress:
|
|
133
|
+
userAddress: account,
|
|
131
134
|
repayAssets,
|
|
132
135
|
repayShares,
|
|
133
136
|
maxRepayAssets,
|
|
@@ -143,8 +146,8 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
143
146
|
inputs = {
|
|
144
147
|
...args,
|
|
145
148
|
...(nativeAmount !== undefined && { nativeAssets: nativeAmount }),
|
|
146
|
-
chainId
|
|
147
|
-
account
|
|
149
|
+
chainId,
|
|
150
|
+
account,
|
|
148
151
|
marketParams: {
|
|
149
152
|
loanToken: marketParams.loanToken,
|
|
150
153
|
collateralToken: marketParams.collateralToken,
|
|
@@ -161,27 +164,20 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
161
164
|
needsAuthorization: args.collateralAssets > 0n,
|
|
162
165
|
};
|
|
163
166
|
});
|
|
164
|
-
await (0, validateClientChainId_js_1.validateClientChainId)(client,
|
|
167
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
|
|
165
168
|
if (inputs === undefined) {
|
|
166
169
|
throw new error_js_1.IncompleteTransactionPlanError(id);
|
|
167
170
|
}
|
|
168
|
-
const signatureRequestIds =
|
|
169
|
-
.
|
|
170
|
-
.
|
|
171
|
-
|
|
172
|
-
signatureRequestIds.morphoAuthorization =
|
|
173
|
-
prepared.morphoAuthorizationRequestId;
|
|
174
|
-
}
|
|
171
|
+
const signatureRequestIds = (0, stored_js_1.signatureRoles)({
|
|
172
|
+
tokenPermit: prepared.signatureRequests.find((request) => request.kind === "permit")?.id,
|
|
173
|
+
morphoAuthorization: prepared.morphoAuthorizationRequestId,
|
|
174
|
+
});
|
|
175
175
|
const authorization = prepared.signatureRequests.find((request) => request.kind === "morphoAuthorization");
|
|
176
176
|
if (authorization !== undefined) {
|
|
177
177
|
inputs = { ...inputs, authorizationNonce: authorization.args.nonce };
|
|
178
178
|
}
|
|
179
|
-
return (0,
|
|
180
|
-
|
|
181
|
-
chainId: params.chainId,
|
|
182
|
-
account: params.account,
|
|
183
|
-
expiresAt: prepared.intent.expiresAt,
|
|
184
|
-
calldataOrigin: prepared.intent.calldataOrigin,
|
|
179
|
+
return (0, assemble_js_1.freezePlan)({
|
|
180
|
+
...(0, assemble_js_1.planHeader)({ chainId, account }, prepared.intent),
|
|
185
181
|
steps: [
|
|
186
182
|
...prepared.steps,
|
|
187
183
|
{
|
|
@@ -191,7 +187,7 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
191
187
|
},
|
|
192
188
|
],
|
|
193
189
|
signatureRequests: prepared.signatureRequests,
|
|
194
|
-
})
|
|
190
|
+
}, { detach: true });
|
|
195
191
|
}
|
|
196
192
|
function getRepayWithdrawLabel(inputs) {
|
|
197
193
|
if (inputs.collateralAssets === 0n) {
|
|
@@ -212,6 +208,25 @@ const MARKET_STATE_FIELDS = [
|
|
|
212
208
|
"price",
|
|
213
209
|
"rateAtTarget",
|
|
214
210
|
];
|
|
211
|
+
function captureRepayWithdrawInputs(params) {
|
|
212
|
+
const { chainId, account, marketId, marketData, positionData } = params;
|
|
213
|
+
return {
|
|
214
|
+
chainId,
|
|
215
|
+
account,
|
|
216
|
+
marketId,
|
|
217
|
+
marketData: { chainId: marketData.chainId, market: marketData.market },
|
|
218
|
+
positionData: {
|
|
219
|
+
chainId: positionData.chainId,
|
|
220
|
+
position: positionData.position,
|
|
221
|
+
},
|
|
222
|
+
now: params.now ?? morpho_ts_1.Time.timestamp(),
|
|
223
|
+
expiresAt: params.expiresAt,
|
|
224
|
+
supportSignature: params.supportSignature,
|
|
225
|
+
referralFee: params.referralFee,
|
|
226
|
+
calldataOrigin: params.calldataOrigin,
|
|
227
|
+
deployless: params.deployless,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
215
230
|
function getMatchingPosition(params) {
|
|
216
231
|
const { position } = params.positionData;
|
|
217
232
|
const positionMarket = position.market;
|
|
@@ -253,8 +268,8 @@ function quoteWithdrawal(quoteParams, collateralAssets) {
|
|
|
253
268
|
}),
|
|
254
269
|
});
|
|
255
270
|
}
|
|
256
|
-
function getRepayWithdrawAmounts(params) {
|
|
257
|
-
const { collateralAssets
|
|
271
|
+
function getRepayWithdrawAmounts(params, marketId) {
|
|
272
|
+
const { collateralAssets } = params;
|
|
258
273
|
const repayAssets = params.repayAssets ?? 0n;
|
|
259
274
|
const repayShares = params.repayShares ?? 0n;
|
|
260
275
|
if (repayAssets < 0n) {
|
|
@@ -368,9 +383,7 @@ function validateRepayWithdrawCollateralPlanAction(action, path) {
|
|
|
368
383
|
maxRepayAssets: "uint256 bigint",
|
|
369
384
|
collateralAssets: "uint256 bigint",
|
|
370
385
|
maxLtv: "uint256 bigint",
|
|
371
|
-
|
|
372
|
-
referralFeePct: "uint256 bigint",
|
|
373
|
-
referralFeeRecipient: "address",
|
|
386
|
+
...stored_js_1.BUNDLES_COMMON_FIELDS,
|
|
374
387
|
},
|
|
375
388
|
});
|
|
376
389
|
if (inputs.repayAssets > 0n &&
|
|
@@ -386,16 +399,7 @@ function validateRepayWithdrawCollateralPlanAction(action, path) {
|
|
|
386
399
|
fields: { nativeAssets: "uint256 bigint" },
|
|
387
400
|
});
|
|
388
401
|
}
|
|
389
|
-
(0,
|
|
390
|
-
path: `${path}.inputs.marketParams`,
|
|
391
|
-
fields: {
|
|
392
|
-
loanToken: "address",
|
|
393
|
-
collateralToken: "address",
|
|
394
|
-
oracle: "address",
|
|
395
|
-
irm: "address",
|
|
396
|
-
lltv: "uint256 bigint",
|
|
397
|
-
},
|
|
398
|
-
});
|
|
402
|
+
(0, stored_js_1.validateStoredBlueMarketParams)(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
399
403
|
const ids = (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
400
404
|
if (inputs.authorizationNonce !== undefined ||
|
|
401
405
|
ids.morphoAuthorization !== undefined) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @internal The stored BlueBundlesV1 deadline and referral fields, in their validation order. */
|
|
2
|
+
export declare const BUNDLES_COMMON_FIELDS: {
|
|
3
|
+
readonly deadline: "uint256 bigint";
|
|
4
|
+
readonly referralFeePct: "uint256 bigint";
|
|
5
|
+
readonly referralFeeRecipient: "address";
|
|
6
|
+
};
|
|
7
|
+
/** @internal Validates a stored five-field Blue market tuple at `path`. */
|
|
8
|
+
export declare function validateStoredBlueMarketParams(value: unknown, path: string): void;
|
|
9
|
+
/** @internal Validates a stored Blue market tuple that also carries its 32-byte market ID. */
|
|
10
|
+
export declare function validateStoredBlueMarket(value: unknown, path: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* @internal Validates stored Vault V2 reallocations at `path`, checking each source market tuple
|
|
13
|
+
* with `marketParams`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateStoredReallocations(reallocations: readonly unknown[], { path, marketParams, }: {
|
|
16
|
+
readonly path: string;
|
|
17
|
+
readonly marketParams: (value: unknown, path: string) => void;
|
|
18
|
+
}): void;
|
|
19
|
+
/** @internal Builds an action's role map with only the roles that reference a request, in argument order. */
|
|
20
|
+
export declare function signatureRoles({ tokenPermit, morphoAuthorization, }: {
|
|
21
|
+
readonly tokenPermit?: string;
|
|
22
|
+
readonly morphoAuthorization?: string;
|
|
23
|
+
}): {
|
|
24
|
+
tokenPermit?: string | undefined;
|
|
25
|
+
morphoAuthorization?: string | undefined;
|
|
26
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BUNDLES_COMMON_FIELDS = void 0;
|
|
4
|
+
exports.validateStoredBlueMarketParams = validateStoredBlueMarketParams;
|
|
5
|
+
exports.validateStoredBlueMarket = validateStoredBlueMarket;
|
|
6
|
+
exports.validateStoredReallocations = validateStoredReallocations;
|
|
7
|
+
exports.signatureRoles = signatureRoles;
|
|
8
|
+
const error_js_1 = require("../error.js");
|
|
9
|
+
const validation_js_1 = require("../validation.js");
|
|
10
|
+
/** @internal The stored BlueBundlesV1 deadline and referral fields, in their validation order. */
|
|
11
|
+
exports.BUNDLES_COMMON_FIELDS = {
|
|
12
|
+
deadline: "uint256 bigint",
|
|
13
|
+
referralFeePct: "uint256 bigint",
|
|
14
|
+
referralFeeRecipient: "address",
|
|
15
|
+
};
|
|
16
|
+
const MARKET_PARAMS_FIELDS = {
|
|
17
|
+
loanToken: "address",
|
|
18
|
+
collateralToken: "address",
|
|
19
|
+
oracle: "address",
|
|
20
|
+
irm: "address",
|
|
21
|
+
lltv: "uint256 bigint",
|
|
22
|
+
};
|
|
23
|
+
/** @internal Validates a stored five-field Blue market tuple at `path`. */
|
|
24
|
+
function validateStoredBlueMarketParams(value, path) {
|
|
25
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(value, path), {
|
|
26
|
+
path,
|
|
27
|
+
fields: MARKET_PARAMS_FIELDS,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** @internal Validates a stored Blue market tuple that also carries its 32-byte market ID. */
|
|
31
|
+
function validateStoredBlueMarket(value, path) {
|
|
32
|
+
const market = (0, validation_js_1.getPlanObject)(value, path);
|
|
33
|
+
(0, validation_js_1.validatePlanFields)(market, {
|
|
34
|
+
path,
|
|
35
|
+
fields: { id: "hex", ...MARKET_PARAMS_FIELDS },
|
|
36
|
+
});
|
|
37
|
+
if (typeof market.id !== "string" || market.id.length !== 66) {
|
|
38
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
39
|
+
path: `${path}.id`,
|
|
40
|
+
reason: "expected a 32-byte market ID",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @internal Validates stored Vault V2 reallocations at `path`, checking each source market tuple
|
|
46
|
+
* with `marketParams`.
|
|
47
|
+
*/
|
|
48
|
+
function validateStoredReallocations(reallocations, { path, marketParams, }) {
|
|
49
|
+
for (const [index, value] of reallocations.entries()) {
|
|
50
|
+
const entryPath = `${path}[${index}]`;
|
|
51
|
+
const entry = (0, validation_js_1.getPlanObject)(value, entryPath);
|
|
52
|
+
(0, validation_js_1.validatePlanFields)(entry, {
|
|
53
|
+
path: entryPath,
|
|
54
|
+
fields: {
|
|
55
|
+
vault: "address",
|
|
56
|
+
assets: "uint256 bigint",
|
|
57
|
+
penalty: "uint256 bigint",
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(entry.to, `${entryPath}.to`), {
|
|
61
|
+
path: `${entryPath}.to`,
|
|
62
|
+
fields: { adapter: "address" },
|
|
63
|
+
});
|
|
64
|
+
const from = (0, validation_js_1.getPlanObject)(entry.from, `${entryPath}.from`);
|
|
65
|
+
if (from.type === "idle") {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (from.type !== "market") {
|
|
69
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
70
|
+
path: `${entryPath}.from.type`,
|
|
71
|
+
reason: "expected market or idle",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
(0, validation_js_1.validatePlanFields)(from, {
|
|
75
|
+
path: `${entryPath}.from`,
|
|
76
|
+
fields: { adapter: "address" },
|
|
77
|
+
});
|
|
78
|
+
marketParams(from.marketParams, `${entryPath}.from.marketParams`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** @internal Builds an action's role map with only the roles that reference a request, in argument order. */
|
|
82
|
+
function signatureRoles({ tokenPermit, morphoAuthorization, }) {
|
|
83
|
+
return {
|
|
84
|
+
...(tokenPermit !== undefined && { tokenPermit }),
|
|
85
|
+
...(morphoAuthorization !== undefined && { morphoAuthorization }),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -5,14 +5,15 @@ exports.prepareBlueSupply = prepareBlueSupply;
|
|
|
5
5
|
exports.validateBlueSupplyPermitRequest = validateBlueSupplyPermitRequest;
|
|
6
6
|
exports.buildBlueSupply = buildBlueSupply;
|
|
7
7
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
8
|
-
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
9
8
|
const supply_js_1 = require("../../actions/blue/supply.js");
|
|
10
9
|
const common_js_1 = require("../../actions/bundles/common.js");
|
|
11
10
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
11
|
+
const assemble_js_1 = require("../assemble.js");
|
|
12
12
|
const error_js_1 = require("../error.js");
|
|
13
13
|
const permit_js_1 = require("../permit.js");
|
|
14
14
|
const validation_js_1 = require("../validation.js");
|
|
15
15
|
const prepare_js_1 = require("./prepare.js");
|
|
16
|
+
const stored_js_1 = require("./stored.js");
|
|
16
17
|
/** @internal Validates the stored supply recipe without requiring class instances. */
|
|
17
18
|
function validateBlueSupplyPlanAction(action, path) {
|
|
18
19
|
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
|
|
@@ -20,9 +21,7 @@ function validateBlueSupplyPlanAction(action, path) {
|
|
|
20
21
|
path: `${path}.inputs`,
|
|
21
22
|
fields: {
|
|
22
23
|
assets: "uint256 bigint",
|
|
23
|
-
|
|
24
|
-
referralFeePct: "uint256 bigint",
|
|
25
|
-
referralFeeRecipient: "address",
|
|
24
|
+
...stored_js_1.BUNDLES_COMMON_FIELDS,
|
|
26
25
|
},
|
|
27
26
|
});
|
|
28
27
|
if (inputs.nativeAssets !== undefined) {
|
|
@@ -32,17 +31,7 @@ function validateBlueSupplyPlanAction(action, path) {
|
|
|
32
31
|
});
|
|
33
32
|
validateNativeAssets(inputs, `${path}.inputs.nativeAssets`);
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
(0, validation_js_1.validatePlanFields)(market, {
|
|
37
|
-
path: `${path}.inputs.marketParams`,
|
|
38
|
-
fields: {
|
|
39
|
-
loanToken: "address",
|
|
40
|
-
collateralToken: "address",
|
|
41
|
-
oracle: "address",
|
|
42
|
-
irm: "address",
|
|
43
|
-
lltv: "uint256 bigint",
|
|
44
|
-
},
|
|
45
|
-
});
|
|
34
|
+
(0, stored_js_1.validateStoredBlueMarketParams)(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
46
35
|
(0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
47
36
|
}
|
|
48
37
|
/**
|
|
@@ -157,12 +146,8 @@ async function prepareBlueSupply(client, params) {
|
|
|
157
146
|
});
|
|
158
147
|
await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
|
|
159
148
|
const { intent, steps, signatureRequests } = prepared;
|
|
160
|
-
return (0,
|
|
161
|
-
|
|
162
|
-
chainId,
|
|
163
|
-
account,
|
|
164
|
-
expiresAt: intent.expiresAt,
|
|
165
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
149
|
+
return (0, assemble_js_1.freezePlan)({
|
|
150
|
+
...(0, assemble_js_1.planHeader)({ chainId, account }, intent),
|
|
166
151
|
steps: [
|
|
167
152
|
...steps,
|
|
168
153
|
{
|
|
@@ -185,7 +170,7 @@ async function prepareBlueSupply(client, params) {
|
|
|
185
170
|
},
|
|
186
171
|
],
|
|
187
172
|
signatureRequests,
|
|
188
|
-
})
|
|
173
|
+
}, { detach: true });
|
|
189
174
|
}
|
|
190
175
|
/** @internal Binds an exact token permit to this supply's pull. */
|
|
191
176
|
function validateBlueSupplyPermitRequest(request, action) {
|
|
@@ -45,7 +45,7 @@ export interface BlueSupplyCollateralPlanParams extends IntentParams, ReferenceT
|
|
|
45
45
|
* @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
|
|
46
46
|
* @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
|
|
47
47
|
* @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
|
|
48
|
-
* @param params.calldataOrigin - Optional non-empty hex bytes appended to
|
|
48
|
+
* @param params.calldataOrigin - Optional non-empty hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
49
49
|
* @param params.deployless - Whether permit metadata reads may use deployless aggregation.
|
|
50
50
|
* @returns A frozen plan containing the collateral supply step and any token prerequisites.
|
|
51
51
|
* @throws {BlueSnapshotChainMismatchError} when the snapshot comes from another chain.
|
|
@@ -5,16 +5,17 @@ exports.validateSupplyCollateralPlanAction = validateSupplyCollateralPlanAction;
|
|
|
5
5
|
exports.validateSupplyCollateralPermitRequest = validateSupplyCollateralPermitRequest;
|
|
6
6
|
exports.buildBlueSupplyCollateral = buildBlueSupplyCollateral;
|
|
7
7
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
8
|
-
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
9
8
|
const viem_1 = require("viem");
|
|
10
9
|
const supplyCollateral_js_1 = require("../../actions/blue/supplyCollateral.js");
|
|
11
10
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
12
11
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
13
12
|
const index_js_1 = require("../../types/index.js");
|
|
13
|
+
const assemble_js_1 = require("../assemble.js");
|
|
14
14
|
const error_js_1 = require("../error.js");
|
|
15
15
|
const permit_js_1 = require("../permit.js");
|
|
16
16
|
const validation_js_1 = require("../validation.js");
|
|
17
17
|
const prepare_js_1 = require("./prepare.js");
|
|
18
|
+
const stored_js_1 = require("./stored.js");
|
|
18
19
|
const actionId = "blueSupplyCollateral";
|
|
19
20
|
/**
|
|
20
21
|
* Prepares a collateral-only supply through BlueBundlesV1 from a caller-fetched market snapshot.
|
|
@@ -34,7 +35,7 @@ const actionId = "blueSupplyCollateral";
|
|
|
34
35
|
* @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
|
|
35
36
|
* @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
|
|
36
37
|
* @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
|
|
37
|
-
* @param params.calldataOrigin - Optional non-empty hex bytes appended to
|
|
38
|
+
* @param params.calldataOrigin - Optional non-empty hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
38
39
|
* @param params.deployless - Whether permit metadata reads may use deployless aggregation.
|
|
39
40
|
* @returns A frozen plan containing the collateral supply step and any token prerequisites.
|
|
40
41
|
* @throws {BlueSnapshotChainMismatchError} when the snapshot comes from another chain.
|
|
@@ -99,12 +100,8 @@ async function prepareBlueSupplyCollateral(client, params) {
|
|
|
99
100
|
await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
|
|
100
101
|
}
|
|
101
102
|
const tokenPermit = signatureRequests.find(({ kind }) => kind === "permit");
|
|
102
|
-
return (0,
|
|
103
|
-
|
|
104
|
-
chainId,
|
|
105
|
-
account,
|
|
106
|
-
expiresAt: intent.expiresAt,
|
|
107
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
103
|
+
return (0, assemble_js_1.freezePlan)({
|
|
104
|
+
...(0, assemble_js_1.planHeader)({ chainId, account }, intent),
|
|
108
105
|
steps: [
|
|
109
106
|
...steps,
|
|
110
107
|
{
|
|
@@ -122,14 +119,14 @@ async function prepareBlueSupplyCollateral(client, params) {
|
|
|
122
119
|
referralFeePct: intent.referralFeePct,
|
|
123
120
|
referralFeeRecipient: intent.referralFeeRecipient ?? viem_1.zeroAddress,
|
|
124
121
|
},
|
|
125
|
-
signatureRequestIds:
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
signatureRequestIds: (0, stored_js_1.signatureRoles)({
|
|
123
|
+
tokenPermit: tokenPermit?.id,
|
|
124
|
+
}),
|
|
128
125
|
},
|
|
129
126
|
},
|
|
130
127
|
],
|
|
131
128
|
signatureRequests,
|
|
132
|
-
})
|
|
129
|
+
}, { detach: true });
|
|
133
130
|
}
|
|
134
131
|
/** @internal Validates the stored collateral supply action and its token permit role. */
|
|
135
132
|
function validateSupplyCollateralPlanAction(action, path) {
|
|
@@ -139,9 +136,7 @@ function validateSupplyCollateralPlanAction(action, path) {
|
|
|
139
136
|
path: inputsPath,
|
|
140
137
|
fields: {
|
|
141
138
|
collateralAssets: "uint256 bigint",
|
|
142
|
-
|
|
143
|
-
referralFeePct: "uint256 bigint",
|
|
144
|
-
referralFeeRecipient: "address",
|
|
139
|
+
...stored_js_1.BUNDLES_COMMON_FIELDS,
|
|
145
140
|
},
|
|
146
141
|
});
|
|
147
142
|
const marketPath = `${inputsPath}.marketParams`;
|
|
@@ -13,11 +13,13 @@ const getBlueBundlesV1QuoteTimestamp_js_1 = require("../../helpers/getBlueBundle
|
|
|
13
13
|
const index_js_1 = require("../../helpers/index.js");
|
|
14
14
|
const parse_js_1 = require("../../helpers/parse.js");
|
|
15
15
|
const index_js_2 = require("../../types/index.js");
|
|
16
|
+
const assemble_js_1 = require("../assemble.js");
|
|
16
17
|
const error_js_1 = require("../error.js");
|
|
17
18
|
const permit_js_1 = require("../permit.js");
|
|
18
19
|
const validation_js_1 = require("../validation.js");
|
|
19
20
|
const authorization_js_1 = require("./authorization.js");
|
|
20
21
|
const prepare_js_1 = require("./prepare.js");
|
|
22
|
+
const stored_js_1 = require("./stored.js");
|
|
21
23
|
/**
|
|
22
24
|
* Prepares collateral funding and Morpho authorization for one BlueBundlesV1 call. Snapshots
|
|
23
25
|
* are validated before reads; health uses the expiry floored at max(now, lastUpdate).
|
|
@@ -162,14 +164,8 @@ async function prepareBlueSupplyCollateralBorrow(client, params) {
|
|
|
162
164
|
await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
|
|
163
165
|
const authorization = prepared.signatureRequests.find((request) => request.id === prepared.morphoAuthorizationRequestId);
|
|
164
166
|
const permit = prepared.signatureRequests.find((request) => request.kind === "permit");
|
|
165
|
-
return (0,
|
|
166
|
-
|
|
167
|
-
chainId,
|
|
168
|
-
account,
|
|
169
|
-
expiresAt: prepared.intent.expiresAt,
|
|
170
|
-
...(prepared.intent.calldataOrigin && {
|
|
171
|
-
calldataOrigin: prepared.intent.calldataOrigin,
|
|
172
|
-
}),
|
|
167
|
+
return (0, assemble_js_1.freezePlan)({
|
|
168
|
+
...(0, assemble_js_1.planHeader)({ chainId, account }, prepared.intent),
|
|
173
169
|
steps: [
|
|
174
170
|
...prepared.steps,
|
|
175
171
|
{
|
|
@@ -205,15 +201,15 @@ async function prepareBlueSupplyCollateralBorrow(client, params) {
|
|
|
205
201
|
authorizationNonce: authorization.args.nonce,
|
|
206
202
|
}),
|
|
207
203
|
},
|
|
208
|
-
signatureRequestIds: {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
},
|
|
204
|
+
signatureRequestIds: (0, stored_js_1.signatureRoles)({
|
|
205
|
+
tokenPermit: permit?.id,
|
|
206
|
+
morphoAuthorization: authorization?.id,
|
|
207
|
+
}),
|
|
212
208
|
},
|
|
213
209
|
},
|
|
214
210
|
],
|
|
215
211
|
signatureRequests: prepared.signatureRequests,
|
|
216
|
-
})
|
|
212
|
+
}, { detach: true });
|
|
217
213
|
}
|
|
218
214
|
function captureSupplyBorrowIntent(params) {
|
|
219
215
|
const { chainId, account, marketId, marketData, positionData, expiresAt, referralFee, supportSignature, calldataOrigin, deployless, now = morpho_ts_1.Time.timestamp(), } = params;
|
|
@@ -300,26 +296,6 @@ function buildBlueSupplyCollateralBorrow(action, requests) {
|
|
|
300
296
|
},
|
|
301
297
|
});
|
|
302
298
|
}
|
|
303
|
-
function validateMarket(value, path) {
|
|
304
|
-
const market = (0, validation_js_1.getPlanObject)(value, path);
|
|
305
|
-
(0, validation_js_1.validatePlanFields)(market, {
|
|
306
|
-
path,
|
|
307
|
-
fields: {
|
|
308
|
-
id: "hex",
|
|
309
|
-
loanToken: "address",
|
|
310
|
-
collateralToken: "address",
|
|
311
|
-
oracle: "address",
|
|
312
|
-
irm: "address",
|
|
313
|
-
lltv: "uint256 bigint",
|
|
314
|
-
},
|
|
315
|
-
});
|
|
316
|
-
if (typeof market.id !== "string" || market.id.length !== 66) {
|
|
317
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
318
|
-
path: `${path}.id`,
|
|
319
|
-
reason: "expected a 32-byte market ID",
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
299
|
/** @internal Validates the complete stored input and reallocation shape. */
|
|
324
300
|
function validateSupplyCollateralBorrowPlanAction(action, path) {
|
|
325
301
|
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
|
|
@@ -352,7 +328,7 @@ function validateSupplyCollateralBorrowPlanAction(action, path) {
|
|
|
352
328
|
type: "address",
|
|
353
329
|
});
|
|
354
330
|
}
|
|
355
|
-
|
|
331
|
+
(0, stored_js_1.validateStoredBlueMarket)(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
356
332
|
const ids = (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
357
333
|
for (const key of Object.keys(ids)) {
|
|
358
334
|
if (key !== "tokenPermit" && key !== "morphoAuthorization") {
|
|
@@ -379,34 +355,8 @@ function validateSupplyCollateralBorrowPlanAction(action, path) {
|
|
|
379
355
|
type: "uint256 bigint",
|
|
380
356
|
});
|
|
381
357
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
path: entryPath,
|
|
387
|
-
fields: {
|
|
388
|
-
vault: "address",
|
|
389
|
-
assets: "uint256 bigint",
|
|
390
|
-
penalty: "uint256 bigint",
|
|
391
|
-
},
|
|
392
|
-
});
|
|
393
|
-
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(entry.to, `${entryPath}.to`), {
|
|
394
|
-
path: `${entryPath}.to`,
|
|
395
|
-
fields: { adapter: "address" },
|
|
396
|
-
});
|
|
397
|
-
const from = (0, validation_js_1.getPlanObject)(entry.from, `${entryPath}.from`);
|
|
398
|
-
if (from.type === "market") {
|
|
399
|
-
(0, validation_js_1.validatePlanFields)(from, {
|
|
400
|
-
path: `${entryPath}.from`,
|
|
401
|
-
fields: { adapter: "address" },
|
|
402
|
-
});
|
|
403
|
-
validateMarket(from.marketParams, `${entryPath}.from.marketParams`);
|
|
404
|
-
}
|
|
405
|
-
else if (from.type !== "idle") {
|
|
406
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
407
|
-
path: `${entryPath}.from.type`,
|
|
408
|
-
reason: "expected market or idle",
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
}
|
|
358
|
+
(0, stored_js_1.validateStoredReallocations)(inputs.reallocations, {
|
|
359
|
+
path: `${path}.inputs.reallocations`,
|
|
360
|
+
marketParams: stored_js_1.validateStoredBlueMarket,
|
|
361
|
+
});
|
|
412
362
|
}
|
|
@@ -69,7 +69,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
|
|
|
69
69
|
* @param params.supportSignature - Optional Morpho authorization signature preference; defaults to `false`, selecting a direct authorization transaction when needed. Neither mode requests a token allowance or Permit2 signature.
|
|
70
70
|
* @param params.now - Optional reference timestamp in seconds, normally the latest block timestamp; defaults to the device clock.
|
|
71
71
|
* @param params.expiresAt - Optional Unix expiry in safe-integer seconds, later than `now`; defaults to `now + 2h`.
|
|
72
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
72
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata, not to approval or authorization steps; omitted by default.
|
|
73
73
|
* @param params.deployless - Optional shared intent field; unused because withdrawal reads no token metadata.
|
|
74
74
|
* @returns A deep-frozen, data-only `{ version, chainId, account, expiresAt, steps, signatureRequests, calldataOrigin? }` plan with a withdrawal step. Direct Morpho authorization is a preceding step; signed authorization is consumed inline by the withdrawal. Attach signatures before building.
|
|
75
75
|
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
@@ -100,7 +100,6 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
|
|
|
100
100
|
* @throws {WithdrawSharesExceedSupplyError} when `shares` exceeds the position's supply shares.
|
|
101
101
|
* @throws {MissingContractCodeError} when registered BlueBundlesV1 or Blue has no deployed code.
|
|
102
102
|
* @throws {viem.BaseError} when a chain, bytecode, authorization or nonce RPC read fails, or ABI encoding rejects malformed input.
|
|
103
|
-
* @throws {UnexpectedRequirementSignatureError} when an authorization requirement returns a nonce that is not a bigint.
|
|
104
103
|
* @throws {TransactionPlanSignatureMismatchError} when the authorization requirement does not match the prepared account, chain, nonce or deadline.
|
|
105
104
|
* @example
|
|
106
105
|
* ```ts
|
|
@@ -120,7 +119,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
|
|
|
120
119
|
* positionData: { chainId: mainnet.id, position },
|
|
121
120
|
* now: (await client.getBlock()).timestamp,
|
|
122
121
|
* });
|
|
123
|
-
* // plan: { version:
|
|
122
|
+
* // plan: { version: 2, chainId, account, expiresAt, steps, signatureRequests }
|
|
124
123
|
* // Sign any pending Morpho authorization request, then build and submit each step in order.
|
|
125
124
|
* ```
|
|
126
125
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|