@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
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { maxUint256 } from "viem";
|
|
3
|
-
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
1
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
4
2
|
import { vaultV1InKindRedeem } from "../../actions/vaultV1/inKindRedeem.js";
|
|
5
3
|
import { getVaultV1InKindRedeemRequirements } from "../../entities/requirements/getVaultV1InKindRedeemRequirements.js";
|
|
6
4
|
import { computeVaultV1InKindRedeemQuote } from "../../entities/vaultV1/inKindRedeemQuote.js";
|
|
7
5
|
import { validateChainId } from "../../helpers/validate.js";
|
|
8
|
-
import {
|
|
6
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
9
7
|
import { resolveIntent } from "../intent.js";
|
|
10
|
-
import {
|
|
11
|
-
import { buildApprovalStep, buildPermitSignatureRequest, } from "../requirements.js";
|
|
8
|
+
import { selectVaultPermit } from "../permit.js";
|
|
12
9
|
import { getPlanObject, validatePlanFields } from "../validation.js";
|
|
10
|
+
import { vaultRequirementSteps } from "../vaultRequirements.js";
|
|
13
11
|
/**
|
|
14
12
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
15
13
|
* Prepares the stable Vault V1 in-kind exit through VaultExitBundlesV1.
|
|
@@ -98,31 +96,13 @@ export async function prepareVaultV1InKindRedeem(client, params) {
|
|
|
98
96
|
now,
|
|
99
97
|
amount: params.assets,
|
|
100
98
|
});
|
|
101
|
-
const approvals =
|
|
102
|
-
|
|
103
|
-
const id = "vaultV1InKindRedeem:tokenPermit";
|
|
104
|
-
for (const requirement of requirements) {
|
|
105
|
-
if (isRequirementApproval(requirement)) {
|
|
106
|
-
approvals.push(buildApprovalStep(requirement, {
|
|
107
|
-
id: "vaultV1InKindRedeem:approval",
|
|
108
|
-
chainId,
|
|
109
|
-
account,
|
|
110
|
-
denomination: "shares",
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
else if (requirement.action.type === "permit") {
|
|
114
|
-
signatureRequests.push(buildPermitSignatureRequest({ action: requirement.action }, id));
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
throw new UnsupportedRequirementSignatureError(requirement.action.type);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return deepFreeze(structuredClone({
|
|
121
|
-
version: 2,
|
|
99
|
+
const { approvals, signatureRequests, signatureRequestIds } = vaultRequirementSteps(requirements, {
|
|
100
|
+
id: "vaultV1InKindRedeem",
|
|
122
101
|
chainId,
|
|
123
102
|
account,
|
|
124
|
-
|
|
125
|
-
|
|
103
|
+
});
|
|
104
|
+
return freezePlan({
|
|
105
|
+
...planHeader({ chainId, account }, intent),
|
|
126
106
|
steps: [
|
|
127
107
|
...approvals,
|
|
128
108
|
{
|
|
@@ -138,28 +118,17 @@ export async function prepareVaultV1InKindRedeem(client, params) {
|
|
|
138
118
|
deadline: inputs.deadline,
|
|
139
119
|
marketParamsList: inputs.marketParamsList,
|
|
140
120
|
},
|
|
141
|
-
signatureRequestIds
|
|
142
|
-
? { tokenPermit: id }
|
|
143
|
-
: {},
|
|
121
|
+
signatureRequestIds,
|
|
144
122
|
},
|
|
145
123
|
},
|
|
146
124
|
],
|
|
147
125
|
signatureRequests,
|
|
148
|
-
})
|
|
126
|
+
}, { detach: true });
|
|
149
127
|
}
|
|
150
128
|
/** @internal Encodes the fixed in-kind exit with its referenced permit. */
|
|
151
129
|
export function buildVaultV1InKindRedeem(action, requests) {
|
|
152
130
|
const { chainId, account, vault, assets, ...args } = action.inputs;
|
|
153
|
-
const
|
|
154
|
-
id: action.signatureRequestIds.tokenPermit,
|
|
155
|
-
asset: vault,
|
|
156
|
-
owner: account,
|
|
157
|
-
});
|
|
158
|
-
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
159
|
-
spender: getChainAddress(chainId, "bundles.vaultExitBundlesV1"),
|
|
160
|
-
amount: maxUint256,
|
|
161
|
-
deadline: action.inputs.deadline,
|
|
162
|
-
});
|
|
131
|
+
const permit = selectVaultPermit(action, requests);
|
|
163
132
|
return vaultV1InKindRedeem({
|
|
164
133
|
vault: { chainId, address: vault },
|
|
165
134
|
args: {
|
|
@@ -47,7 +47,7 @@ export type VaultV1MigrateToV2PlanParams = Omit<IntentParams, "deployless"> & Re
|
|
|
47
47
|
* @param params.supportSignature - Optional unlimited ERC-2612 share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient. Vault V1 shares support ERC-2612; no Permit2 is used.
|
|
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
|
* @returns A static migration plan with any required source share approval or permit.
|
|
52
52
|
* @throws {InvalidBigIntInputError} when `now` is not a bigint.
|
|
53
53
|
* @throws {VaultAssetMismatchError} If the vault assets differ.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, Token, } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { isAddressEqual } from "viem";
|
|
4
|
-
import { normalizeBundlesCommonParams
|
|
4
|
+
import { normalizeBundlesCommonParams } from "../../actions/bundles/common.js";
|
|
5
5
|
import { vaultV1MigrateToV2 } from "../../actions/vaultV1/migrateToV2.js";
|
|
6
6
|
import { computeVaultV1MigrateToV2Quote } from "../../entities/vaultV1/migrateToV2Quote.js";
|
|
7
7
|
import { validateReferenceTime, validateSlippageTolerance, validateUint256Field, validateVaultDepositDeadline, } from "../../helpers/validate.js";
|
|
8
8
|
import { AmountAndSharesExclusiveError, NonPositiveInputError, SameVaultMigrationError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
9
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
9
10
|
import { InvalidTransactionPlanError } from "../error.js";
|
|
10
11
|
import { resolveIntent } from "../intent.js";
|
|
11
|
-
import {
|
|
12
|
+
import { selectVaultPermit } from "../permit.js";
|
|
12
13
|
import { getVaultShareSpendingRequirements } from "../shareSpending.js";
|
|
13
14
|
import { getPlanObject, validatePlanField, validatePlanFields, validateVaultPlanAction, } from "../validation.js";
|
|
14
15
|
/** @internal Validates the stored Vault V1 migration action's input shape. */
|
|
@@ -60,7 +61,7 @@ export function validateMigrateToV2PlanAction(action, path) {
|
|
|
60
61
|
* @param params.supportSignature - Optional unlimited ERC-2612 share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient. Vault V1 shares support ERC-2612; no Permit2 is used.
|
|
61
62
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
62
63
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
63
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
64
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
64
65
|
* @returns A static migration plan with any required source share approval or permit.
|
|
65
66
|
* @throws {InvalidBigIntInputError} when `now` is not a bigint.
|
|
66
67
|
* @throws {VaultAssetMismatchError} If the vault assets differ.
|
|
@@ -157,12 +158,8 @@ export async function prepareVaultV1MigrateToV2(client, params) {
|
|
|
157
158
|
supportSignature: intent.supportSignature,
|
|
158
159
|
now,
|
|
159
160
|
});
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
account,
|
|
163
|
-
chainId,
|
|
164
|
-
expiresAt: intent.expiresAt,
|
|
165
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
161
|
+
return freezePlan({
|
|
162
|
+
...planHeader({ chainId, account }, intent),
|
|
166
163
|
steps: [
|
|
167
164
|
...approvals,
|
|
168
165
|
{
|
|
@@ -189,21 +186,12 @@ export async function prepareVaultV1MigrateToV2(client, params) {
|
|
|
189
186
|
},
|
|
190
187
|
],
|
|
191
188
|
signatureRequests,
|
|
192
|
-
})
|
|
189
|
+
}, { detach: true });
|
|
193
190
|
}
|
|
194
191
|
/** @internal Maps stored maxSharePrice to the ABI maxSharePriceVaultV2 and encodes the source permit. */
|
|
195
192
|
export function buildVaultV1MigrateToV2(action, requests) {
|
|
196
193
|
const { vault: _vault, sourceVault, maxSharePrice, asset, requiredShareAllowance, chainId, account, ...args } = action.inputs;
|
|
197
|
-
const
|
|
198
|
-
id: action.signatureRequestIds.tokenPermit,
|
|
199
|
-
asset: sourceVault,
|
|
200
|
-
owner: account,
|
|
201
|
-
});
|
|
202
|
-
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
203
|
-
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
204
|
-
amount: requiredShareAllowance,
|
|
205
|
-
deadline: args.deadline,
|
|
206
|
-
});
|
|
194
|
+
const permit = selectVaultPermit(action, requests);
|
|
207
195
|
return vaultV1MigrateToV2({
|
|
208
196
|
vault: { chainId, address: sourceVault, asset },
|
|
209
197
|
args: {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
-
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
3
1
|
import { vaultV1Redeem } from "../../actions/vaultV1/redeem.js";
|
|
4
|
-
import {
|
|
2
|
+
import { selectVaultPermit } from "../permit.js";
|
|
5
3
|
import { prepareVaultRedeem } from "../redeem.js";
|
|
6
4
|
/**
|
|
7
5
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
@@ -53,16 +51,7 @@ export async function prepareVaultV1Redeem(client, params) {
|
|
|
53
51
|
/** @internal Encodes a redemption from fixed inputs and the referenced share permit. */
|
|
54
52
|
export function buildVaultV1Redeem(action, requests) {
|
|
55
53
|
const { chainId, account, ...args } = action.inputs;
|
|
56
|
-
const
|
|
57
|
-
id: action.signatureRequestIds.tokenPermit,
|
|
58
|
-
asset: action.inputs.vault,
|
|
59
|
-
owner: account,
|
|
60
|
-
});
|
|
61
|
-
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
62
|
-
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
63
|
-
amount: action.inputs.shares,
|
|
64
|
-
deadline: action.inputs.deadline,
|
|
65
|
-
});
|
|
54
|
+
const permit = selectVaultPermit(action, requests);
|
|
66
55
|
return vaultV1Redeem({
|
|
67
56
|
vault: { chainId, address: action.inputs.vault },
|
|
68
57
|
args: {
|
|
@@ -36,7 +36,7 @@ export interface VaultV1WithdrawPlanParams extends WithdrawPlanParams<AccrualVau
|
|
|
36
36
|
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
37
37
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
38
38
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
39
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
39
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
40
40
|
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
41
41
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
42
42
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
-
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
3
1
|
import { vaultV1Withdraw } from "../../actions/vaultV1/withdraw.js";
|
|
4
|
-
import {
|
|
2
|
+
import { selectVaultPermit } from "../permit.js";
|
|
5
3
|
import { prepareVaultWithdraw } from "../withdraw.js";
|
|
6
4
|
/**
|
|
7
5
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
@@ -22,7 +20,7 @@ import { prepareVaultWithdraw } from "../withdraw.js";
|
|
|
22
20
|
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
23
21
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
24
22
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
25
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
23
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
26
24
|
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
27
25
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
28
26
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
@@ -62,16 +60,7 @@ export async function prepareVaultV1Withdraw(client, params) {
|
|
|
62
60
|
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
63
61
|
export function buildVaultV1Withdraw(action, requests) {
|
|
64
62
|
const { requiredShareAllowance, chainId, account, assets, ...args } = action.inputs;
|
|
65
|
-
const
|
|
66
|
-
id: action.signatureRequestIds.tokenPermit,
|
|
67
|
-
asset: action.inputs.vault,
|
|
68
|
-
owner: account,
|
|
69
|
-
});
|
|
70
|
-
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
71
|
-
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
72
|
-
amount: requiredShareAllowance,
|
|
73
|
-
deadline: action.inputs.deadline,
|
|
74
|
-
});
|
|
63
|
+
const permit = selectVaultPermit(action, requests);
|
|
75
64
|
return vaultV1Withdraw({
|
|
76
65
|
vault: { chainId, address: action.inputs.vault },
|
|
77
66
|
args: {
|
|
@@ -26,7 +26,7 @@ export interface VaultV2DepositPlanParams extends DepositPlanParams<AccrualVault
|
|
|
26
26
|
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
|
|
27
27
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
28
28
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
|
|
29
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
29
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
30
30
|
* @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
|
|
31
31
|
* @returns A plan with approvals, concrete signature requests and the deposit step.
|
|
32
32
|
* @throws {InvalidBigIntInputError} when `now` is not a bigint.
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
-
import { selectBundlesTokenRequirementSignature } from "../../actions/bundles/common.js";
|
|
3
1
|
import { vaultV2Deposit } from "../../actions/vaultV2/deposit.js";
|
|
4
2
|
import { prepareVaultDeposit } from "../deposit.js";
|
|
5
|
-
import {
|
|
3
|
+
import { selectVaultPermit } from "../permit.js";
|
|
6
4
|
/**
|
|
7
5
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
6
|
* Prepares a deposit plan from caller intent and a vault snapshot, reading the token prerequisites
|
|
@@ -20,7 +18,7 @@ import { getVaultPermit } from "../permit.js";
|
|
|
20
18
|
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
|
|
21
19
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
22
20
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
|
|
23
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
21
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
24
22
|
* @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
|
|
25
23
|
* @returns A plan with approvals, concrete signature requests and the deposit step.
|
|
26
24
|
* @throws {InvalidBigIntInputError} when `now` is not a bigint.
|
|
@@ -60,16 +58,7 @@ export async function prepareVaultV2Deposit(client, params) {
|
|
|
60
58
|
/** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
|
|
61
59
|
export function buildVaultV2Deposit(action, requests) {
|
|
62
60
|
const { asset, chainId, account, assets, nativeAssets, ...args } = action.inputs;
|
|
63
|
-
const
|
|
64
|
-
id: action.signatureRequestIds.tokenPermit,
|
|
65
|
-
asset,
|
|
66
|
-
owner: account,
|
|
67
|
-
});
|
|
68
|
-
const requirementSignature = selectBundlesTokenRequirementSignature(signature ? [signature] : [], {
|
|
69
|
-
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
70
|
-
amount: assets ?? nativeAssets,
|
|
71
|
-
deadline: action.inputs.deadline,
|
|
72
|
-
});
|
|
61
|
+
const requirementSignature = selectVaultPermit(action, requests);
|
|
73
62
|
return vaultV2Deposit({
|
|
74
63
|
vault: { chainId, address: action.inputs.vault, asset },
|
|
75
64
|
args: {
|
|
@@ -37,7 +37,7 @@ export interface VaultV2ForceRedeemPlanParams extends Pick<IntentParams, "chainI
|
|
|
37
37
|
* @param params.deallocations - Non-empty, ordered deallocations with positive `assets` in asset base units, including any penalty buffer.
|
|
38
38
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
39
39
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` and is plan metadata only.
|
|
40
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
40
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
41
41
|
* @returns A deep-frozen `TransactionPlan` containing one `vaultV2ForceRedeem` step and no signature requests.
|
|
42
42
|
* @throws {ChainIdMismatchError} If the client targets another chain.
|
|
43
43
|
* @throws {EmptyDeallocationsError} If `deallocations` is empty.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
4
4
|
import { vaultV2ForceRedeem } from "../../actions/vaultV2/forceRedeem.js";
|
|
5
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
5
6
|
import { resolveIntent } from "../intent.js";
|
|
6
7
|
import { getPlanObject, validatePlanFields } from "../validation.js";
|
|
7
8
|
/** @internal Validates the stored force-redeem action's plain input shape. */
|
|
@@ -50,7 +51,7 @@ export function validateForceRedeemPlanAction(action, path) {
|
|
|
50
51
|
* @param params.deallocations - Non-empty, ordered deallocations with positive `assets` in asset base units, including any penalty buffer.
|
|
51
52
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
52
53
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` and is plan metadata only.
|
|
53
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
54
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
54
55
|
* @returns A deep-frozen `TransactionPlan` containing one `vaultV2ForceRedeem` step and no signature requests.
|
|
55
56
|
* @throws {ChainIdMismatchError} If the client targets another chain.
|
|
56
57
|
* @throws {EmptyDeallocationsError} If `deallocations` is empty.
|
|
@@ -85,11 +86,7 @@ export async function prepareVaultV2ForceRedeem(client, params) {
|
|
|
85
86
|
const now = params.now ?? Time.timestamp();
|
|
86
87
|
const intent = resolveIntent(params, now);
|
|
87
88
|
const plan = structuredClone({
|
|
88
|
-
|
|
89
|
-
account: params.account,
|
|
90
|
-
chainId: params.chainId,
|
|
91
|
-
expiresAt: intent.expiresAt,
|
|
92
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
89
|
+
...planHeader({ chainId: params.chainId, account: params.account }, intent),
|
|
93
90
|
steps: [
|
|
94
91
|
{
|
|
95
92
|
id: "vaultV2ForceRedeem",
|
|
@@ -123,7 +120,7 @@ export async function prepareVaultV2ForceRedeem(client, params) {
|
|
|
123
120
|
// Validate the cloned inputs with the action encoder before returning a plan.
|
|
124
121
|
buildVaultV2ForceRedeem(plan.steps[0].action);
|
|
125
122
|
await validateClientChainId(client, params.chainId);
|
|
126
|
-
return
|
|
123
|
+
return freezePlan(plan, { detach: false });
|
|
127
124
|
}
|
|
128
125
|
/** @internal Encodes the fixed multicall through the same action as the forceRedeem handle. */
|
|
129
126
|
export function buildVaultV2ForceRedeem(action) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import type { Address, Client } from "viem";
|
|
3
3
|
import { type ReferenceTimestampParams, type Transaction, type VaultV2ForceWithdrawAction } from "../../types/index.js";
|
|
4
4
|
import { type IntentParams } from "../intent.js";
|
|
5
5
|
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
@@ -44,7 +44,7 @@ export interface VaultV2ForceWithdrawPlanParams extends Omit<IntentParams, "depl
|
|
|
44
44
|
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; insufficient allowance produces an unlimited direct share approval, or an unlimited share permit when `true`.
|
|
45
45
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
46
46
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now` and within the fee-projection horizon; defaults to `now + 2h`.
|
|
47
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
47
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
48
48
|
* @returns A deep-frozen plan containing ordered share approvals, if needed, followed by the forced exit and its concrete permit request, if needed.
|
|
49
49
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
50
50
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { maxUint256 } from "viem";
|
|
3
|
-
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
1
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
4
2
|
import { vaultV2ForceWithdraw } from "../../actions/vaultV2/forceWithdraw.js";
|
|
5
3
|
import { getVaultV2ForceWithdrawRequirements } from "../../entities/requirements/getVaultV2ForceWithdrawRequirements.js";
|
|
6
4
|
import { computeVaultV2ForceWithdrawQuote } from "../../entities/vaultV2/forceWithdrawQuote.js";
|
|
7
5
|
import { validateChainId } from "../../helpers/validate.js";
|
|
8
|
-
import {
|
|
6
|
+
import { NonPositiveInputError, } from "../../types/index.js";
|
|
7
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
9
8
|
import { InvalidTransactionPlanError } from "../error.js";
|
|
10
9
|
import { resolveIntent } from "../intent.js";
|
|
11
|
-
import {
|
|
12
|
-
import { buildApprovalStep, buildPermitSignatureRequest, } from "../requirements.js";
|
|
10
|
+
import { selectVaultPermit } from "../permit.js";
|
|
13
11
|
import { validatePlanFields, validateVaultPlanAction } from "../validation.js";
|
|
12
|
+
import { vaultRequirementSteps } from "../vaultRequirements.js";
|
|
14
13
|
/**
|
|
15
14
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
16
15
|
* Prepares a static forced-exit plan using shared snapshot quoting and requirement helpers.
|
|
@@ -29,7 +28,7 @@ import { validatePlanFields, validateVaultPlanAction } from "../validation.js";
|
|
|
29
28
|
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; insufficient allowance produces an unlimited direct share approval, or an unlimited share permit when `true`.
|
|
30
29
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
31
30
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now` and within the fee-projection horizon; defaults to `now + 2h`.
|
|
32
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
31
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
33
32
|
* @returns A deep-frozen plan containing ordered share approvals, if needed, followed by the forced exit and its concrete permit request, if needed.
|
|
34
33
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
35
34
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
@@ -114,31 +113,13 @@ export async function prepareVaultV2ForceWithdraw(client, params) {
|
|
|
114
113
|
supportSignature: intent.supportSignature,
|
|
115
114
|
now,
|
|
116
115
|
});
|
|
117
|
-
const approvals =
|
|
118
|
-
|
|
119
|
-
const tokenPermitRequestId = "vaultV2ForceWithdraw:tokenPermit";
|
|
120
|
-
for (const requirement of requirements) {
|
|
121
|
-
if (isRequirementApproval(requirement)) {
|
|
122
|
-
approvals.push(buildApprovalStep(requirement, {
|
|
123
|
-
id: "vaultV2ForceWithdraw:approval",
|
|
124
|
-
chainId,
|
|
125
|
-
account,
|
|
126
|
-
denomination: "shares",
|
|
127
|
-
}));
|
|
128
|
-
}
|
|
129
|
-
else if (requirement.action.type === "permit") {
|
|
130
|
-
signatureRequests.push(buildPermitSignatureRequest({ action: requirement.action }, tokenPermitRequestId));
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
throw new UnsupportedRequirementSignatureError(requirement.action.type);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return deepFreeze(structuredClone({
|
|
137
|
-
version: 2,
|
|
138
|
-
account,
|
|
116
|
+
const { approvals, signatureRequests, signatureRequestIds } = vaultRequirementSteps(requirements, {
|
|
117
|
+
id: "vaultV2ForceWithdraw",
|
|
139
118
|
chainId,
|
|
140
|
-
|
|
141
|
-
|
|
119
|
+
account,
|
|
120
|
+
});
|
|
121
|
+
return freezePlan({
|
|
122
|
+
...planHeader({ chainId, account }, intent),
|
|
142
123
|
steps: [
|
|
143
124
|
...approvals,
|
|
144
125
|
{
|
|
@@ -147,14 +128,12 @@ export async function prepareVaultV2ForceWithdraw(client, params) {
|
|
|
147
128
|
action: {
|
|
148
129
|
type: "vaultV2ForceWithdraw",
|
|
149
130
|
inputs: { ...inputs, assets, chainId, account },
|
|
150
|
-
signatureRequestIds
|
|
151
|
-
? { tokenPermit: tokenPermitRequestId }
|
|
152
|
-
: {},
|
|
131
|
+
signatureRequestIds,
|
|
153
132
|
},
|
|
154
133
|
},
|
|
155
134
|
],
|
|
156
135
|
signatureRequests,
|
|
157
|
-
})
|
|
136
|
+
}, { detach: true });
|
|
158
137
|
}
|
|
159
138
|
/** @internal Encodes the forced exit from fixed inputs and its referenced vault-share permit. */
|
|
160
139
|
export function buildVaultV2ForceWithdraw(action, requests) {
|
|
@@ -162,16 +141,7 @@ export function buildVaultV2ForceWithdraw(action, requests) {
|
|
|
162
141
|
if (args.minSharePriceE27 <= 0n) {
|
|
163
142
|
throw new NonPositiveInputError("minSharePriceE27", args.minSharePriceE27);
|
|
164
143
|
}
|
|
165
|
-
const
|
|
166
|
-
id: action.signatureRequestIds.tokenPermit,
|
|
167
|
-
asset: action.inputs.vault,
|
|
168
|
-
owner: account,
|
|
169
|
-
});
|
|
170
|
-
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
171
|
-
spender: getChainAddress(chainId, "bundles.vaultExitBundlesV1"),
|
|
172
|
-
amount: maxUint256,
|
|
173
|
-
deadline: action.inputs.deadline,
|
|
174
|
-
});
|
|
144
|
+
const permit = selectVaultPermit(action, requests);
|
|
175
145
|
return vaultV2ForceWithdraw({
|
|
176
146
|
vault: { chainId, address: action.inputs.vault },
|
|
177
147
|
args: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AccrualVaultV2, MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { Address, Client } from "viem";
|
|
3
|
+
import type { ReferenceTimestampParams, Transaction, VaultV2InKindRedeemAction } from "../../types/index.js";
|
|
4
4
|
import { type IntentParams } from "../intent.js";
|
|
5
5
|
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
6
6
|
/**
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { maxUint256 } from "viem";
|
|
3
|
-
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
1
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
4
2
|
import { vaultV2InKindRedeem } from "../../actions/vaultV2/inKindRedeem.js";
|
|
5
3
|
import { getVaultV2InKindRedeemRequirements } from "../../entities/requirements/getVaultV2InKindRedeemRequirements.js";
|
|
6
4
|
import { computeVaultV2InKindRedeemQuote } from "../../entities/vaultV2/inKindRedeemQuote.js";
|
|
7
5
|
import { validateChainId } from "../../helpers/validate.js";
|
|
8
|
-
import {
|
|
6
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
9
7
|
import { resolveIntent } from "../intent.js";
|
|
10
|
-
import {
|
|
11
|
-
import { buildApprovalStep, buildPermitSignatureRequest, } from "../requirements.js";
|
|
8
|
+
import { selectVaultPermit } from "../permit.js";
|
|
12
9
|
import { getPlanObject, validatePlanFields } from "../validation.js";
|
|
10
|
+
import { vaultRequirementSteps } from "../vaultRequirements.js";
|
|
13
11
|
/**
|
|
14
12
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
15
13
|
* Prepares the existing Vault V2 in-kind exit through VaultExitBundlesV1. Preparation validates
|
|
@@ -107,31 +105,13 @@ export async function prepareVaultV2InKindRedeem(client, params) {
|
|
|
107
105
|
peak: quote.peak,
|
|
108
106
|
now,
|
|
109
107
|
});
|
|
110
|
-
const approvals =
|
|
111
|
-
|
|
112
|
-
const tokenPermit = "vaultV2InKindRedeem:tokenPermit";
|
|
113
|
-
for (const requirement of requirements) {
|
|
114
|
-
if (isRequirementApproval(requirement)) {
|
|
115
|
-
approvals.push(buildApprovalStep(requirement, {
|
|
116
|
-
id: "vaultV2InKindRedeem:approval",
|
|
117
|
-
chainId,
|
|
118
|
-
account,
|
|
119
|
-
denomination: "shares",
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
else if (requirement.action.type === "permit") {
|
|
123
|
-
signatureRequests.push(buildPermitSignatureRequest({ action: requirement.action }, tokenPermit));
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
throw new UnsupportedRequirementSignatureError(requirement.action.type);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return deepFreeze(structuredClone({
|
|
130
|
-
version: 2,
|
|
108
|
+
const { approvals, signatureRequests, signatureRequestIds } = vaultRequirementSteps(requirements, {
|
|
109
|
+
id: "vaultV2InKindRedeem",
|
|
131
110
|
chainId,
|
|
132
111
|
account,
|
|
133
|
-
|
|
134
|
-
|
|
112
|
+
});
|
|
113
|
+
return freezePlan({
|
|
114
|
+
...planHeader({ chainId, account }, intent),
|
|
135
115
|
steps: [
|
|
136
116
|
...approvals,
|
|
137
117
|
{
|
|
@@ -140,28 +120,17 @@ export async function prepareVaultV2InKindRedeem(client, params) {
|
|
|
140
120
|
action: {
|
|
141
121
|
type: "vaultV2InKindRedeem",
|
|
142
122
|
inputs: { ...inputs, assets, chainId, account },
|
|
143
|
-
signatureRequestIds
|
|
144
|
-
? { tokenPermit }
|
|
145
|
-
: {},
|
|
123
|
+
signatureRequestIds,
|
|
146
124
|
},
|
|
147
125
|
},
|
|
148
126
|
],
|
|
149
127
|
signatureRequests,
|
|
150
|
-
})
|
|
128
|
+
}, { detach: true });
|
|
151
129
|
}
|
|
152
130
|
/** @internal Encodes only the saved inputs and referenced unlimited share permit. */
|
|
153
131
|
export function buildVaultV2InKindRedeem(action, requests) {
|
|
154
132
|
const { chainId, account, assets, ...args } = action.inputs;
|
|
155
|
-
const
|
|
156
|
-
id: action.signatureRequestIds.tokenPermit,
|
|
157
|
-
asset: args.vault,
|
|
158
|
-
owner: account,
|
|
159
|
-
});
|
|
160
|
-
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
161
|
-
spender: getChainAddress(chainId, "bundles.vaultExitBundlesV1"),
|
|
162
|
-
amount: maxUint256,
|
|
163
|
-
deadline: args.deadline,
|
|
164
|
-
});
|
|
133
|
+
const permit = selectVaultPermit(action, requests);
|
|
165
134
|
return vaultV2InKindRedeem({
|
|
166
135
|
vault: { chainId, address: args.vault },
|
|
167
136
|
args: {
|
|
@@ -40,7 +40,7 @@ export interface VaultV2RedeemPlanParams extends RedeemPlanParams {
|
|
|
40
40
|
* @param params.supportSignature - Optional ERC-2612 share-permit preference; defaults to `false` for direct approval.
|
|
41
41
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
42
42
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
|
|
43
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
43
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
44
44
|
* @returns A deep-frozen, serializable `TransactionPlan` with version, chain, account, expiry,
|
|
45
45
|
* ordered approval/redeem steps and signature requests. Any required share approval or permit is unlimited.
|
|
46
46
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
-
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
3
1
|
import { vaultV2Redeem } from "../../actions/vaultV2/redeem.js";
|
|
4
|
-
import {
|
|
2
|
+
import { selectVaultPermit } from "../permit.js";
|
|
5
3
|
import { prepareVaultRedeem } from "../redeem.js";
|
|
6
4
|
/**
|
|
7
5
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
@@ -17,7 +15,7 @@ import { prepareVaultRedeem } from "../redeem.js";
|
|
|
17
15
|
* @param params.supportSignature - Optional ERC-2612 share-permit preference; defaults to `false` for direct approval.
|
|
18
16
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
19
17
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
|
|
20
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
18
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
21
19
|
* @returns A deep-frozen, serializable `TransactionPlan` with version, chain, account, expiry,
|
|
22
20
|
* ordered approval/redeem steps and signature requests. Any required share approval or permit is unlimited.
|
|
23
21
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
@@ -60,16 +58,7 @@ export async function prepareVaultV2Redeem(client, params) {
|
|
|
60
58
|
/** @internal Encodes a redemption from its fixed inputs and referenced share permit. */
|
|
61
59
|
export function buildVaultV2Redeem(action, requests) {
|
|
62
60
|
const { chainId, account, vault, shares, ...common } = action.inputs;
|
|
63
|
-
const
|
|
64
|
-
id: action.signatureRequestIds.tokenPermit,
|
|
65
|
-
asset: vault,
|
|
66
|
-
owner: account,
|
|
67
|
-
});
|
|
68
|
-
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
69
|
-
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
70
|
-
amount: shares,
|
|
71
|
-
deadline: action.inputs.deadline,
|
|
72
|
-
});
|
|
61
|
+
const permit = selectVaultPermit(action, requests);
|
|
73
62
|
return vaultV2Redeem({
|
|
74
63
|
vault: { chainId, address: vault },
|
|
75
64
|
args: {
|
|
@@ -28,7 +28,7 @@ export interface VaultV2WithdrawPlanParams extends WithdrawPlanParams<AccrualVau
|
|
|
28
28
|
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
29
29
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
30
30
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
|
|
31
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
31
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
32
32
|
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
33
33
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
34
34
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|