@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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
2
|
import { blueSupply } from "../../actions/blue/supply.js";
|
|
4
3
|
import { normalizeBundlesCommonParams } from "../../actions/bundles/common.js";
|
|
5
4
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
5
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
6
6
|
import { InvalidTransactionPlanError } from "../error.js";
|
|
7
7
|
import { getVaultPermit, validateTokenPermitRequest } from "../permit.js";
|
|
8
8
|
import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
|
|
9
9
|
import { prepareBlue } from "./prepare.js";
|
|
10
|
+
import { BUNDLES_COMMON_FIELDS, validateStoredBlueMarketParams, } from "./stored.js";
|
|
10
11
|
/** @internal Validates the stored supply recipe without requiring class instances. */
|
|
11
12
|
export function validateBlueSupplyPlanAction(action, path) {
|
|
12
13
|
const inputs = getPlanObject(action.inputs, `${path}.inputs`);
|
|
@@ -14,9 +15,7 @@ export function validateBlueSupplyPlanAction(action, path) {
|
|
|
14
15
|
path: `${path}.inputs`,
|
|
15
16
|
fields: {
|
|
16
17
|
assets: "uint256 bigint",
|
|
17
|
-
|
|
18
|
-
referralFeePct: "uint256 bigint",
|
|
19
|
-
referralFeeRecipient: "address",
|
|
18
|
+
...BUNDLES_COMMON_FIELDS,
|
|
20
19
|
},
|
|
21
20
|
});
|
|
22
21
|
if (inputs.nativeAssets !== undefined) {
|
|
@@ -26,17 +25,7 @@ export function validateBlueSupplyPlanAction(action, path) {
|
|
|
26
25
|
});
|
|
27
26
|
validateNativeAssets(inputs, `${path}.inputs.nativeAssets`);
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
validatePlanFields(market, {
|
|
31
|
-
path: `${path}.inputs.marketParams`,
|
|
32
|
-
fields: {
|
|
33
|
-
loanToken: "address",
|
|
34
|
-
collateralToken: "address",
|
|
35
|
-
oracle: "address",
|
|
36
|
-
irm: "address",
|
|
37
|
-
lltv: "uint256 bigint",
|
|
38
|
-
},
|
|
39
|
-
});
|
|
28
|
+
validateStoredBlueMarketParams(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
40
29
|
getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
41
30
|
}
|
|
42
31
|
/**
|
|
@@ -151,12 +140,8 @@ export async function prepareBlueSupply(client, params) {
|
|
|
151
140
|
});
|
|
152
141
|
await validateClientChainId(client, chainId);
|
|
153
142
|
const { intent, steps, signatureRequests } = prepared;
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
chainId,
|
|
157
|
-
account,
|
|
158
|
-
expiresAt: intent.expiresAt,
|
|
159
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
143
|
+
return freezePlan({
|
|
144
|
+
...planHeader({ chainId, account }, intent),
|
|
160
145
|
steps: [
|
|
161
146
|
...steps,
|
|
162
147
|
{
|
|
@@ -179,7 +164,7 @@ export async function prepareBlueSupply(client, params) {
|
|
|
179
164
|
},
|
|
180
165
|
],
|
|
181
166
|
signatureRequests,
|
|
182
|
-
})
|
|
167
|
+
}, { detach: true });
|
|
183
168
|
}
|
|
184
169
|
/** @internal Binds an exact token permit to this supply's pull. */
|
|
185
170
|
export 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.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
2
|
import { zeroAddress } from "viem";
|
|
4
3
|
import { blueSupplyCollateral } from "../../actions/blue/supplyCollateral.js";
|
|
5
4
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
6
5
|
import { validateNativeAsset, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
|
|
7
6
|
import { NonPositiveInputError, } from "../../types/index.js";
|
|
7
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
8
8
|
import { InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
|
|
9
9
|
import { getSignedTokenPermit, validateTokenPermitRequest } from "../permit.js";
|
|
10
10
|
import { getPlanObject, validatePlanFields } from "../validation.js";
|
|
11
11
|
import { prepareBlue } from "./prepare.js";
|
|
12
|
+
import { BUNDLES_COMMON_FIELDS, signatureRoles } from "./stored.js";
|
|
12
13
|
const actionId = "blueSupplyCollateral";
|
|
13
14
|
/**
|
|
14
15
|
* Prepares a collateral-only supply through BlueBundlesV1 from a caller-fetched market snapshot.
|
|
@@ -28,7 +29,7 @@ const actionId = "blueSupplyCollateral";
|
|
|
28
29
|
* @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
|
|
29
30
|
* @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
|
|
30
31
|
* @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
|
|
31
|
-
* @param params.calldataOrigin - Optional non-empty hex bytes appended to
|
|
32
|
+
* @param params.calldataOrigin - Optional non-empty hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
32
33
|
* @param params.deployless - Whether permit metadata reads may use deployless aggregation.
|
|
33
34
|
* @returns A frozen plan containing the collateral supply step and any token prerequisites.
|
|
34
35
|
* @throws {BlueSnapshotChainMismatchError} when the snapshot comes from another chain.
|
|
@@ -93,12 +94,8 @@ export async function prepareBlueSupplyCollateral(client, params) {
|
|
|
93
94
|
await validateClientChainId(client, chainId);
|
|
94
95
|
}
|
|
95
96
|
const tokenPermit = signatureRequests.find(({ kind }) => kind === "permit");
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
chainId,
|
|
99
|
-
account,
|
|
100
|
-
expiresAt: intent.expiresAt,
|
|
101
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
97
|
+
return freezePlan({
|
|
98
|
+
...planHeader({ chainId, account }, intent),
|
|
102
99
|
steps: [
|
|
103
100
|
...steps,
|
|
104
101
|
{
|
|
@@ -116,14 +113,14 @@ export async function prepareBlueSupplyCollateral(client, params) {
|
|
|
116
113
|
referralFeePct: intent.referralFeePct,
|
|
117
114
|
referralFeeRecipient: intent.referralFeeRecipient ?? zeroAddress,
|
|
118
115
|
},
|
|
119
|
-
signatureRequestIds:
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
signatureRequestIds: signatureRoles({
|
|
117
|
+
tokenPermit: tokenPermit?.id,
|
|
118
|
+
}),
|
|
122
119
|
},
|
|
123
120
|
},
|
|
124
121
|
],
|
|
125
122
|
signatureRequests,
|
|
126
|
-
})
|
|
123
|
+
}, { detach: true });
|
|
127
124
|
}
|
|
128
125
|
/** @internal Validates the stored collateral supply action and its token permit role. */
|
|
129
126
|
export function validateSupplyCollateralPlanAction(action, path) {
|
|
@@ -133,9 +130,7 @@ export function validateSupplyCollateralPlanAction(action, path) {
|
|
|
133
130
|
path: inputsPath,
|
|
134
131
|
fields: {
|
|
135
132
|
collateralAssets: "uint256 bigint",
|
|
136
|
-
|
|
137
|
-
referralFeePct: "uint256 bigint",
|
|
138
|
-
referralFeeRecipient: "address",
|
|
133
|
+
...BUNDLES_COMMON_FIELDS,
|
|
139
134
|
},
|
|
140
135
|
});
|
|
141
136
|
const marketPath = `${inputsPath}.marketParams`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MathLib } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { blueSupplyCollateralBorrow } from "../../actions/blue/supplyCollateralBorrow.js";
|
|
5
5
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
@@ -7,11 +7,13 @@ import { getBlueBundlesV1QuoteTimestamp } from "../../helpers/getBlueBundlesV1Qu
|
|
|
7
7
|
import { DEFAULT_LLTV_BUFFER, validatePositionHealth, } from "../../helpers/index.js";
|
|
8
8
|
import { parseNativeFunding } from "../../helpers/parse.js";
|
|
9
9
|
import { MissingAccrualPositionError, } from "../../types/index.js";
|
|
10
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
10
11
|
import { IncompleteTransactionPlanError, InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
|
|
11
12
|
import { getVaultPermit, validateTokenPermitRequest } from "../permit.js";
|
|
12
13
|
import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
|
|
13
14
|
import { validateMorphoAuthorizationRequest } from "./authorization.js";
|
|
14
15
|
import { prepareBlue, } from "./prepare.js";
|
|
16
|
+
import { signatureRoles, validateStoredBlueMarket, validateStoredReallocations, } from "./stored.js";
|
|
15
17
|
/**
|
|
16
18
|
* Prepares collateral funding and Morpho authorization for one BlueBundlesV1 call. Snapshots
|
|
17
19
|
* are validated before reads; health uses the expiry floored at max(now, lastUpdate).
|
|
@@ -156,14 +158,8 @@ export async function prepareBlueSupplyCollateralBorrow(client, params) {
|
|
|
156
158
|
await validateClientChainId(client, chainId);
|
|
157
159
|
const authorization = prepared.signatureRequests.find((request) => request.id === prepared.morphoAuthorizationRequestId);
|
|
158
160
|
const permit = prepared.signatureRequests.find((request) => request.kind === "permit");
|
|
159
|
-
return
|
|
160
|
-
|
|
161
|
-
chainId,
|
|
162
|
-
account,
|
|
163
|
-
expiresAt: prepared.intent.expiresAt,
|
|
164
|
-
...(prepared.intent.calldataOrigin && {
|
|
165
|
-
calldataOrigin: prepared.intent.calldataOrigin,
|
|
166
|
-
}),
|
|
161
|
+
return freezePlan({
|
|
162
|
+
...planHeader({ chainId, account }, prepared.intent),
|
|
167
163
|
steps: [
|
|
168
164
|
...prepared.steps,
|
|
169
165
|
{
|
|
@@ -199,15 +195,15 @@ export async function prepareBlueSupplyCollateralBorrow(client, params) {
|
|
|
199
195
|
authorizationNonce: authorization.args.nonce,
|
|
200
196
|
}),
|
|
201
197
|
},
|
|
202
|
-
signatureRequestIds: {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
},
|
|
198
|
+
signatureRequestIds: signatureRoles({
|
|
199
|
+
tokenPermit: permit?.id,
|
|
200
|
+
morphoAuthorization: authorization?.id,
|
|
201
|
+
}),
|
|
206
202
|
},
|
|
207
203
|
},
|
|
208
204
|
],
|
|
209
205
|
signatureRequests: prepared.signatureRequests,
|
|
210
|
-
})
|
|
206
|
+
}, { detach: true });
|
|
211
207
|
}
|
|
212
208
|
function captureSupplyBorrowIntent(params) {
|
|
213
209
|
const { chainId, account, marketId, marketData, positionData, expiresAt, referralFee, supportSignature, calldataOrigin, deployless, now = Time.timestamp(), } = params;
|
|
@@ -294,26 +290,6 @@ export function buildBlueSupplyCollateralBorrow(action, requests) {
|
|
|
294
290
|
},
|
|
295
291
|
});
|
|
296
292
|
}
|
|
297
|
-
function validateMarket(value, path) {
|
|
298
|
-
const market = getPlanObject(value, path);
|
|
299
|
-
validatePlanFields(market, {
|
|
300
|
-
path,
|
|
301
|
-
fields: {
|
|
302
|
-
id: "hex",
|
|
303
|
-
loanToken: "address",
|
|
304
|
-
collateralToken: "address",
|
|
305
|
-
oracle: "address",
|
|
306
|
-
irm: "address",
|
|
307
|
-
lltv: "uint256 bigint",
|
|
308
|
-
},
|
|
309
|
-
});
|
|
310
|
-
if (typeof market.id !== "string" || market.id.length !== 66) {
|
|
311
|
-
throw new InvalidTransactionPlanError({
|
|
312
|
-
path: `${path}.id`,
|
|
313
|
-
reason: "expected a 32-byte market ID",
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
293
|
/** @internal Validates the complete stored input and reallocation shape. */
|
|
318
294
|
export function validateSupplyCollateralBorrowPlanAction(action, path) {
|
|
319
295
|
const inputs = getPlanObject(action.inputs, `${path}.inputs`);
|
|
@@ -346,7 +322,7 @@ export function validateSupplyCollateralBorrowPlanAction(action, path) {
|
|
|
346
322
|
type: "address",
|
|
347
323
|
});
|
|
348
324
|
}
|
|
349
|
-
|
|
325
|
+
validateStoredBlueMarket(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
350
326
|
const ids = getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
351
327
|
for (const key of Object.keys(ids)) {
|
|
352
328
|
if (key !== "tokenPermit" && key !== "morphoAuthorization") {
|
|
@@ -373,34 +349,8 @@ export function validateSupplyCollateralBorrowPlanAction(action, path) {
|
|
|
373
349
|
type: "uint256 bigint",
|
|
374
350
|
});
|
|
375
351
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
path: entryPath,
|
|
381
|
-
fields: {
|
|
382
|
-
vault: "address",
|
|
383
|
-
assets: "uint256 bigint",
|
|
384
|
-
penalty: "uint256 bigint",
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
validatePlanFields(getPlanObject(entry.to, `${entryPath}.to`), {
|
|
388
|
-
path: `${entryPath}.to`,
|
|
389
|
-
fields: { adapter: "address" },
|
|
390
|
-
});
|
|
391
|
-
const from = getPlanObject(entry.from, `${entryPath}.from`);
|
|
392
|
-
if (from.type === "market") {
|
|
393
|
-
validatePlanFields(from, {
|
|
394
|
-
path: `${entryPath}.from`,
|
|
395
|
-
fields: { adapter: "address" },
|
|
396
|
-
});
|
|
397
|
-
validateMarket(from.marketParams, `${entryPath}.from.marketParams`);
|
|
398
|
-
}
|
|
399
|
-
else if (from.type !== "idle") {
|
|
400
|
-
throw new InvalidTransactionPlanError({
|
|
401
|
-
path: `${entryPath}.from.type`,
|
|
402
|
-
reason: "expected market or idle",
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
}
|
|
352
|
+
validateStoredReallocations(inputs.reallocations, {
|
|
353
|
+
path: `${path}.inputs.reallocations`,
|
|
354
|
+
marketParams: validateStoredBlueMarket,
|
|
355
|
+
});
|
|
406
356
|
}
|
|
@@ -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.
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { AccrualPosition,
|
|
2
|
-
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
1
|
+
import { AccrualPosition, MarketUtils, } from "@morpho-org/blue-sdk";
|
|
3
2
|
import { zeroAddress } from "viem";
|
|
4
3
|
import { getBlueBundlesV1PenaltyAssets } from "../../actions/blue/common.js";
|
|
5
4
|
import { blueWithdraw } from "../../actions/blue/withdraw.js";
|
|
6
5
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
7
6
|
import { validateVaultV2BlueReallocations, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/validate.js";
|
|
8
|
-
import { InputExceedsMaxError, MissingAccrualPositionError, } from "../../types/index.js";
|
|
9
|
-
import {
|
|
7
|
+
import { InputExceedsMaxError, InvalidVaultV2BlueReallocationShapeError, MissingAccrualPositionError, } from "../../types/index.js";
|
|
8
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
9
|
+
import { IncompleteTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
|
|
10
10
|
import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
|
|
11
11
|
import { validateMorphoAuthorizationRequest } from "./authorization.js";
|
|
12
12
|
import { prepareBlue, } from "./prepare.js";
|
|
13
|
+
import { BUNDLES_COMMON_FIELDS, validateStoredBlueMarketParams, validateStoredReallocations, } from "./stored.js";
|
|
13
14
|
/**
|
|
14
15
|
* Prepares a BlueBundlesV1 withdrawal with only Morpho authorization prerequisites, never token approvals.
|
|
15
16
|
* The caller supplies market and position snapshots; the SDK reads authorization but never signs.
|
|
@@ -42,7 +43,7 @@ import { prepareBlue, } from "./prepare.js";
|
|
|
42
43
|
* @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.
|
|
43
44
|
* @param params.now - Optional reference timestamp in seconds, normally the latest block timestamp; defaults to the device clock.
|
|
44
45
|
* @param params.expiresAt - Optional Unix expiry in safe-integer seconds, later than `now`; defaults to `now + 2h`.
|
|
45
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
46
|
+
* @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.
|
|
46
47
|
* @param params.deployless - Optional shared intent field; unused because withdrawal reads no token metadata.
|
|
47
48
|
* @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.
|
|
48
49
|
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
@@ -73,7 +74,6 @@ import { prepareBlue, } from "./prepare.js";
|
|
|
73
74
|
* @throws {WithdrawSharesExceedSupplyError} when `shares` exceeds the position's supply shares.
|
|
74
75
|
* @throws {MissingContractCodeError} when registered BlueBundlesV1 or Blue has no deployed code.
|
|
75
76
|
* @throws {viem.BaseError} when a chain, bytecode, authorization or nonce RPC read fails, or ABI encoding rejects malformed input.
|
|
76
|
-
* @throws {UnexpectedRequirementSignatureError} when an authorization requirement returns a nonce that is not a bigint.
|
|
77
77
|
* @throws {TransactionPlanSignatureMismatchError} when the authorization requirement does not match the prepared account, chain, nonce or deadline.
|
|
78
78
|
* @example
|
|
79
79
|
* ```ts
|
|
@@ -93,33 +93,65 @@ import { prepareBlue, } from "./prepare.js";
|
|
|
93
93
|
* positionData: { chainId: mainnet.id, position },
|
|
94
94
|
* now: (await client.getBlock()).timestamp,
|
|
95
95
|
* });
|
|
96
|
-
* // plan: { version:
|
|
96
|
+
* // plan: { version: 2, chainId, account, expiresAt, steps, signatureRequests }
|
|
97
97
|
* // Sign any pending Morpho authorization request, then build and submit each step in order.
|
|
98
98
|
* ```
|
|
99
99
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
100
100
|
*/
|
|
101
101
|
export async function prepareBlueWithdraw(client, params) {
|
|
102
|
-
const { maxPenalty } = params;
|
|
103
|
-
|
|
102
|
+
const { maxPenalty, chainId, account } = params;
|
|
103
|
+
const supplied = params.reallocations ?? [];
|
|
104
|
+
let reallocations;
|
|
105
|
+
try {
|
|
106
|
+
reallocations = structuredClone(Array.isArray(supplied)
|
|
107
|
+
? supplied.map((entry) => {
|
|
108
|
+
if (entry === null ||
|
|
109
|
+
typeof entry !== "object" ||
|
|
110
|
+
"withdrawals" in entry ||
|
|
111
|
+
"fee" in entry) {
|
|
112
|
+
return entry;
|
|
113
|
+
}
|
|
114
|
+
const { vault, from, to, assets, penalty } = entry;
|
|
115
|
+
return { vault, from, to, assets, penalty };
|
|
116
|
+
})
|
|
117
|
+
: supplied);
|
|
118
|
+
}
|
|
119
|
+
catch (cause) {
|
|
120
|
+
throw new InvalidVaultV2BlueReallocationShapeError({ cause });
|
|
121
|
+
}
|
|
122
|
+
await validateClientChainId(client, chainId);
|
|
104
123
|
const { positionData: snapshot } = params;
|
|
105
124
|
if (snapshot == null) {
|
|
106
125
|
throw new MissingAccrualPositionError(params.marketId);
|
|
107
126
|
}
|
|
108
127
|
const withdrawals = [];
|
|
109
|
-
const
|
|
128
|
+
const captured = {
|
|
129
|
+
chainId,
|
|
130
|
+
account,
|
|
131
|
+
marketId: params.marketId,
|
|
132
|
+
marketData: params.marketData,
|
|
133
|
+
positionData: snapshot,
|
|
134
|
+
now: params.now,
|
|
135
|
+
expiresAt: params.expiresAt,
|
|
136
|
+
supportSignature: params.supportSignature,
|
|
137
|
+
referralFee: params.referralFee,
|
|
138
|
+
calldataOrigin: params.calldataOrigin,
|
|
139
|
+
deployless: params.deployless,
|
|
140
|
+
};
|
|
141
|
+
const { intent: resolvedIntent, steps, signatureRequests, } = await prepareBlue({ client, params: captured }, (intent) => {
|
|
110
142
|
const inputs = {
|
|
111
|
-
chainId
|
|
112
|
-
account
|
|
143
|
+
chainId,
|
|
144
|
+
account,
|
|
113
145
|
marketParams: {
|
|
114
|
-
loanToken:
|
|
115
|
-
collateralToken:
|
|
116
|
-
oracle:
|
|
117
|
-
irm:
|
|
118
|
-
lltv:
|
|
146
|
+
loanToken: captured.marketData.market.params.loanToken,
|
|
147
|
+
collateralToken: captured.marketData.market.params.collateralToken,
|
|
148
|
+
oracle: captured.marketData.market.params.oracle,
|
|
149
|
+
irm: captured.marketData.market.params.irm,
|
|
150
|
+
lltv: captured.marketData.market.params.lltv,
|
|
119
151
|
},
|
|
120
152
|
withdrawAssets: "assets" in params ? (params.assets ?? 0n) : 0n,
|
|
121
153
|
withdrawShares: "shares" in params ? (params.shares ?? 0n) : 0n,
|
|
122
|
-
reallocations
|
|
154
|
+
reallocations,
|
|
123
155
|
...(maxPenalty !== undefined && { maxPenalty }),
|
|
124
156
|
deadline: intent.deadline,
|
|
125
157
|
referralFeePct: intent.referralFeePct,
|
|
@@ -151,7 +183,7 @@ export async function prepareBlueWithdraw(client, params) {
|
|
|
151
183
|
positionData,
|
|
152
184
|
withdrawShares: inputs.withdrawShares,
|
|
153
185
|
withdrawAssets: inputs.withdrawAssets,
|
|
154
|
-
marketId:
|
|
186
|
+
marketId: captured.marketId,
|
|
155
187
|
});
|
|
156
188
|
withdrawals.push({
|
|
157
189
|
id: "blueWithdraw",
|
|
@@ -160,14 +192,8 @@ export async function prepareBlueWithdraw(client, params) {
|
|
|
160
192
|
});
|
|
161
193
|
return { id: "blueWithdraw", needsAuthorization: true };
|
|
162
194
|
});
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
chainId: params.chainId,
|
|
166
|
-
account: params.account,
|
|
167
|
-
expiresAt: resolvedIntent.expiresAt,
|
|
168
|
-
...(resolvedIntent.calldataOrigin && {
|
|
169
|
-
calldataOrigin: resolvedIntent.calldataOrigin,
|
|
170
|
-
}),
|
|
195
|
+
return freezePlan({
|
|
196
|
+
...planHeader({ chainId, account }, resolvedIntent),
|
|
171
197
|
steps: [
|
|
172
198
|
...steps,
|
|
173
199
|
...withdrawals.map((step) => {
|
|
@@ -190,7 +216,7 @@ export async function prepareBlueWithdraw(client, params) {
|
|
|
190
216
|
}),
|
|
191
217
|
],
|
|
192
218
|
signatureRequests,
|
|
193
|
-
})
|
|
219
|
+
}, { detach: true });
|
|
194
220
|
}
|
|
195
221
|
/** @internal Binds an inline authorization to the withdrawal that consumes it. */
|
|
196
222
|
export function validateBlueWithdrawAuthorizationRequest(request, action) {
|
|
@@ -244,7 +270,7 @@ export function buildBlueWithdraw(action, requests = []) {
|
|
|
244
270
|
},
|
|
245
271
|
};
|
|
246
272
|
}
|
|
247
|
-
const targetMarketParams =
|
|
273
|
+
const targetMarketParams = toEncoderMarketParams(marketParams);
|
|
248
274
|
// Reject malformed entries with typed errors before reading their source fields.
|
|
249
275
|
validateVaultV2BlueReallocations(args.reallocations, {
|
|
250
276
|
targetMarketId: targetMarketParams.id,
|
|
@@ -255,7 +281,7 @@ export function buildBlueWithdraw(action, requests = []) {
|
|
|
255
281
|
from: entry.from.type === "market"
|
|
256
282
|
? {
|
|
257
283
|
...entry.from,
|
|
258
|
-
marketParams:
|
|
284
|
+
marketParams: toEncoderMarketParams(entry.from.marketParams),
|
|
259
285
|
}
|
|
260
286
|
: entry.from,
|
|
261
287
|
}));
|
|
@@ -269,6 +295,15 @@ export function buildBlueWithdraw(action, requests = []) {
|
|
|
269
295
|
},
|
|
270
296
|
});
|
|
271
297
|
}
|
|
298
|
+
function toEncoderMarketParams(marketParams) {
|
|
299
|
+
const { loanToken, collateralToken, oracle, irm, lltv } = marketParams;
|
|
300
|
+
const tuple = { loanToken, collateralToken, oracle, irm, lltv };
|
|
301
|
+
return {
|
|
302
|
+
...tuple,
|
|
303
|
+
id: MarketUtils.getMarketId(tuple),
|
|
304
|
+
liquidationIncentiveFactor: MarketUtils.getLiquidationIncentiveFactor(tuple),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
272
307
|
/** @internal Validates stored withdrawal scalars and allocator input shapes. */
|
|
273
308
|
export function validateBlueWithdrawPlanAction(action, path) {
|
|
274
309
|
const inputs = getPlanObject(action.inputs, `${path}.inputs`);
|
|
@@ -294,60 +329,13 @@ export function validateBlueWithdrawPlanAction(action, path) {
|
|
|
294
329
|
fields: {
|
|
295
330
|
withdrawAssets: "uint256 bigint",
|
|
296
331
|
withdrawShares: "uint256 bigint",
|
|
297
|
-
|
|
298
|
-
referralFeePct: "uint256 bigint",
|
|
299
|
-
referralFeeRecipient: "address",
|
|
332
|
+
...BUNDLES_COMMON_FIELDS,
|
|
300
333
|
reallocations: "array",
|
|
301
334
|
},
|
|
302
335
|
});
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
collateralToken: "address",
|
|
308
|
-
oracle: "address",
|
|
309
|
-
irm: "address",
|
|
310
|
-
lltv: "uint256 bigint",
|
|
311
|
-
},
|
|
336
|
+
validateStoredBlueMarketParams(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
337
|
+
validateStoredReallocations(inputs.reallocations, {
|
|
338
|
+
path: `${path}.inputs.reallocations`,
|
|
339
|
+
marketParams: validateStoredBlueMarketParams,
|
|
312
340
|
});
|
|
313
|
-
for (const [index, value] of inputs.reallocations.entries()) {
|
|
314
|
-
const entryPath = `${path}.inputs.reallocations[${index}]`;
|
|
315
|
-
const entry = getPlanObject(value, entryPath);
|
|
316
|
-
validatePlanFields(entry, {
|
|
317
|
-
path: entryPath,
|
|
318
|
-
fields: {
|
|
319
|
-
vault: "address",
|
|
320
|
-
assets: "uint256 bigint",
|
|
321
|
-
penalty: "uint256 bigint",
|
|
322
|
-
},
|
|
323
|
-
});
|
|
324
|
-
validatePlanFields(getPlanObject(entry.to, `${entryPath}.to`), {
|
|
325
|
-
path: `${entryPath}.to`,
|
|
326
|
-
fields: { adapter: "address" },
|
|
327
|
-
});
|
|
328
|
-
const from = getPlanObject(entry.from, `${entryPath}.from`);
|
|
329
|
-
if (from.type === "idle") {
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
if (from.type !== "market") {
|
|
333
|
-
throw new InvalidTransactionPlanError({
|
|
334
|
-
path: `${entryPath}.from.type`,
|
|
335
|
-
reason: "expected market or idle",
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
validatePlanFields(from, {
|
|
339
|
-
path: `${entryPath}.from`,
|
|
340
|
-
fields: { adapter: "address" },
|
|
341
|
-
});
|
|
342
|
-
validatePlanFields(getPlanObject(from.marketParams, `${entryPath}.from.marketParams`), {
|
|
343
|
-
path: `${entryPath}.from.marketParams`,
|
|
344
|
-
fields: {
|
|
345
|
-
loanToken: "address",
|
|
346
|
-
collateralToken: "address",
|
|
347
|
-
oracle: "address",
|
|
348
|
-
irm: "address",
|
|
349
|
-
lltv: "uint256 bigint",
|
|
350
|
-
},
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
341
|
}
|
|
@@ -48,7 +48,7 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
|
|
|
48
48
|
* @param params.supportSignature - Optional Morpho authorization signature preference, defaulting to `false`; otherwise prepares a direct authorization transaction when needed.
|
|
49
49
|
* @param params.now - Optional reference timestamp in Unix seconds, normally the latest block timestamp; defaults to the device clock.
|
|
50
50
|
* @param params.expiresAt - Optional safe-integer Unix expiry later than `now`; defaults to `now + 2h` and governs every deadline.
|
|
51
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to
|
|
51
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to the action transaction's calldata; approval and authorization steps carry none.
|
|
52
52
|
* @param params.deployless - Optional shared intent field; unused because this operation reads no token metadata or allowances.
|
|
53
53
|
* @returns A deep-frozen, data-only `TransactionPlan` with chain, account, expiry, withdrawal step,
|
|
54
54
|
* and any preceding Morpho authorization step and signature request. The caller signs; the SDK never does.
|
|
@@ -74,7 +74,6 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
|
|
|
74
74
|
* @throws {viem.BaseError} when a contract-code, chain ID, authorization or nonce RPC read fails.
|
|
75
75
|
* @example
|
|
76
76
|
* ```ts
|
|
77
|
-
* import assert from "node:assert/strict";
|
|
78
77
|
* import { markets } from "@morpho-org/morpho-test";
|
|
79
78
|
* import { fetchAccrualPosition } from "@morpho-org/morpho-sdk/blue/fetch";
|
|
80
79
|
* import {
|
|
@@ -89,7 +88,7 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
|
|
|
89
88
|
* if (!ethereum) throw new Error("Install an Ethereum wallet to continue.");
|
|
90
89
|
* const wallet = createWalletClient({ chain: mainnet, transport: custom(ethereum) });
|
|
91
90
|
* const [account] = await wallet.requestAddresses();
|
|
92
|
-
*
|
|
91
|
+
* if (!account) throw new Error("Connect a wallet holding collateral in this market.");
|
|
93
92
|
* const market = markets[mainnet.id].usdc_wbtc;
|
|
94
93
|
* const position = await fetchAccrualPosition(account, market.id, client);
|
|
95
94
|
* const plan = await prepareBlueWithdrawCollateral(client, {
|