@morpho-org/morpho-sdk 5.4.1 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -7
- package/lib/cjs/abis.d.ts +314 -1
- package/lib/cjs/abis.js +169 -1
- package/lib/cjs/actions/blue/borrow.d.ts +21 -15
- package/lib/cjs/actions/blue/borrow.js +25 -18
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +1 -1
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +1 -1
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +62 -19
- package/lib/cjs/actions/blue/buildReallocationActions.js +123 -27
- package/lib/cjs/actions/blue/refinance.d.ts +14 -7
- package/lib/cjs/actions/blue/refinance.js +18 -10
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +28 -19
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +39 -23
- package/lib/cjs/actions/blue/withdraw.d.ts +20 -13
- package/lib/cjs/actions/blue/withdraw.js +23 -18
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +9 -2
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +131 -0
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/index.js +1 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -3
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +91 -0
- package/lib/cjs/actions/signatures/index.d.ts +1 -0
- package/lib/cjs/actions/signatures/index.js +1 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +54 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +96 -0
- package/lib/cjs/actions/vaultV1/index.d.ts +1 -0
- package/lib/cjs/actions/vaultV1/index.js +1 -0
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +56 -0
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +97 -0
- package/lib/cjs/actions/vaultV2/index.d.ts +1 -0
- package/lib/cjs/actions/vaultV2/index.js +1 -0
- package/lib/cjs/bundler/actions.d.ts +118 -2
- package/lib/cjs/bundler/actions.js +212 -6
- package/lib/cjs/bundler/types.d.ts +20 -0
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +3 -1
- package/lib/cjs/entities/blue/blue.d.ts +365 -76
- package/lib/cjs/entities/blue/blue.js +285 -52
- package/lib/cjs/entities/index.d.ts +2 -1
- package/lib/cjs/entities/index.js +6 -3
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +82 -4
- package/lib/cjs/entities/vaultV1/vaultV1.js +164 -0
- package/lib/cjs/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +41 -17
- package/lib/cjs/entities/{reallocationData.js → vaultV1ReallocationData.js} +30 -18
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +89 -3
- package/lib/cjs/entities/vaultV2/vaultV2.js +181 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +511 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +1311 -0
- package/lib/{esm/helpers/computeReallocations.d.ts → cjs/helpers/computeVaultV1Reallocations.d.ts} +14 -8
- package/lib/cjs/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +27 -13
- package/lib/cjs/helpers/constant.d.ts +5 -3
- package/lib/cjs/helpers/constant.js +6 -4
- package/lib/cjs/helpers/index.d.ts +3 -2
- package/lib/cjs/helpers/index.js +8 -3
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +73 -0
- package/lib/cjs/helpers/validate.d.ts +31 -15
- package/lib/cjs/helpers/validate.js +140 -27
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +2 -1
- package/lib/cjs/types/action.d.ts +33 -1
- package/lib/cjs/types/error.d.ts +363 -5
- package/lib/cjs/types/error.js +455 -6
- package/lib/cjs/types/sharedLiquidity.d.ts +72 -8
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +6 -4
- package/lib/esm/abis.d.ts +314 -1
- package/lib/esm/abis.js +167 -1
- package/lib/esm/actions/blue/borrow.d.ts +21 -15
- package/lib/esm/actions/blue/borrow.js +26 -19
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +1 -1
- package/lib/esm/actions/blue/buildAssetFundingActions.js +1 -1
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +62 -19
- package/lib/esm/actions/blue/buildReallocationActions.js +119 -25
- package/lib/esm/actions/blue/refinance.d.ts +14 -7
- package/lib/esm/actions/blue/refinance.js +19 -11
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +28 -19
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +40 -24
- package/lib/esm/actions/blue/withdraw.d.ts +20 -13
- package/lib/esm/actions/blue/withdraw.js +24 -19
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -2
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +127 -0
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/index.js +1 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -3
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +87 -0
- package/lib/esm/actions/signatures/index.d.ts +1 -0
- package/lib/esm/actions/signatures/index.js +1 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +54 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.js +92 -0
- package/lib/esm/actions/vaultV1/index.d.ts +1 -0
- package/lib/esm/actions/vaultV1/index.js +1 -0
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +56 -0
- package/lib/esm/actions/vaultV2/inKindRedeem.js +93 -0
- package/lib/esm/actions/vaultV2/index.d.ts +1 -0
- package/lib/esm/actions/vaultV2/index.js +1 -0
- package/lib/esm/bundler/actions.d.ts +118 -2
- package/lib/esm/bundler/actions.js +215 -9
- package/lib/esm/bundler/types.d.ts +20 -0
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +362 -73
- package/lib/esm/entities/blue/blue.js +288 -55
- package/lib/esm/entities/index.d.ts +2 -1
- package/lib/esm/entities/index.js +2 -1
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +80 -2
- package/lib/esm/entities/vaultV1/vaultV1.js +170 -6
- package/lib/esm/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +41 -17
- package/lib/esm/entities/{reallocationData.js → vaultV1ReallocationData.js} +33 -16
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +88 -2
- package/lib/esm/entities/vaultV2/vaultV2.js +187 -6
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +511 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +1307 -0
- package/lib/{cjs/helpers/computeReallocations.d.ts → esm/helpers/computeVaultV1Reallocations.d.ts} +14 -8
- package/lib/esm/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +25 -11
- package/lib/esm/helpers/constant.d.ts +5 -3
- package/lib/esm/helpers/constant.js +5 -3
- package/lib/esm/helpers/index.d.ts +3 -2
- package/lib/esm/helpers/index.js +3 -2
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +70 -0
- package/lib/esm/helpers/validate.d.ts +31 -15
- package/lib/esm/helpers/validate.js +141 -30
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +2 -1
- package/lib/esm/types/action.d.ts +33 -1
- package/lib/esm/types/error.d.ts +363 -5
- package/lib/esm/types/error.js +428 -4
- package/lib/esm/types/sharedLiquidity.d.ts +72 -8
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +9 -11
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.blueSupplyCollateralBorrow = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
+
const viem_1 = require("viem");
|
|
5
6
|
const index_js_1 = require("../../bundler/index.js");
|
|
6
7
|
const index_js_2 = require("../../helpers/index.js");
|
|
7
8
|
const index_js_3 = require("../../types/index.js");
|
|
@@ -11,9 +12,13 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
11
12
|
/**
|
|
12
13
|
* Prepares an atomic supply-collateral-and-borrow transaction for a Morpho Blue market.
|
|
13
14
|
*
|
|
14
|
-
* Routed through bundler3: collateral
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Routed through bundler3: collateral funding → `morphoSupplyCollateral` → optional Public
|
|
16
|
+
* Allocator calls → `morphoBorrow`. Each plan contains either V1 or V2 entries,
|
|
17
|
+
* never both. When `nativeAmount > 0`, native ETH is wrapped via
|
|
18
|
+
* `GeneralAdapter1.wrapNative()` before the supply leg. V1 fees add to
|
|
19
|
+
* `tx.value`; V2 penalties are paid in the target loan token and donated to the vaults. When the
|
|
20
|
+
* collateral and loan tokens match, one combined pull funds both collateral and penalties through
|
|
21
|
+
* `GeneralAdapter1`.
|
|
17
22
|
*
|
|
18
23
|
* Prerequisite: `GeneralAdapter1` must be authorized on Morpho to borrow on behalf of the user.
|
|
19
24
|
* Use `getRequirements()` on the entity to check and obtain the authorization transaction.
|
|
@@ -30,35 +35,40 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
30
35
|
* @param params.args.receiver - Address that receives the borrowed assets.
|
|
31
36
|
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
32
37
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
33
|
-
* collateral
|
|
38
|
+
* collateral funding. When collateral and loan tokens match, its amount includes V2 penalties.
|
|
34
39
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
35
40
|
* collateral supply. Requires the collateral token to be the chain's wNative.
|
|
36
|
-
* @param params.args.reallocations - Optional
|
|
37
|
-
*
|
|
41
|
+
* @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
|
|
42
|
+
* execute between the supply and borrow legs.
|
|
38
43
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
39
44
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
40
45
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
46
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
|
|
42
47
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
43
|
-
* @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, or
|
|
44
|
-
*
|
|
48
|
+
* @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, a V1 fee, or a V2
|
|
49
|
+
* penalty is negative.
|
|
45
50
|
* @throws {NonPositiveInputError} when `borrowAmount <= 0n`, both collateral amounts resolve to
|
|
46
51
|
* zero, or any reallocation withdrawal amount is non-positive.
|
|
52
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
53
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
54
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
55
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
56
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
57
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
47
58
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
48
59
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
49
60
|
* token is not the chain's wNative.
|
|
50
61
|
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
51
62
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
52
63
|
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
53
|
-
* is provided and the signed amount differs from
|
|
64
|
+
* is provided and the signed amount differs from the total ERC-20 funding amount.
|
|
54
65
|
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
55
66
|
* signature is missing its expiration.
|
|
56
|
-
* @throws {EmptyReallocationWithdrawalsError}
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* reallocation withdrawals are not strictly sorted by market id.
|
|
67
|
+
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
68
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
69
|
+
* the target market.
|
|
70
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
71
|
+
* sorted by market id.
|
|
62
72
|
* @example
|
|
63
73
|
* ```ts
|
|
64
74
|
* import { blueSupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
|
|
@@ -93,6 +103,16 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
93
103
|
if (totalCollateral === 0n) {
|
|
94
104
|
throw new index_js_3.NonPositiveInputError("totalCollateral", totalCollateral);
|
|
95
105
|
}
|
|
106
|
+
const usesSharedFundingToken = (0, viem_1.isAddressEqual)(marketParams.collateralToken, marketParams.loanToken);
|
|
107
|
+
const reallocationResult = (0, buildReallocationActions_js_1.buildBlueReallocationActions)({
|
|
108
|
+
chainId,
|
|
109
|
+
reallocations,
|
|
110
|
+
targetMarketParams: marketParams,
|
|
111
|
+
penaltyFundingSource: usesSharedFundingToken
|
|
112
|
+
? "generalAdapter1"
|
|
113
|
+
: "initiator",
|
|
114
|
+
});
|
|
115
|
+
const erc20FundingAmount = amount + (usesSharedFundingToken ? reallocationResult.penaltyAssets : 0n);
|
|
96
116
|
const actions = [];
|
|
97
117
|
if (authorizationSignature) {
|
|
98
118
|
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
@@ -100,7 +120,7 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
100
120
|
actions.push(...(0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
|
|
101
121
|
chainId,
|
|
102
122
|
asset: marketParams.collateralToken,
|
|
103
|
-
erc20Amount:
|
|
123
|
+
erc20Amount: erc20FundingAmount,
|
|
104
124
|
nativeAmount: nativeAmount ?? 0n,
|
|
105
125
|
requirementSignature,
|
|
106
126
|
}));
|
|
@@ -108,12 +128,7 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
108
128
|
type: "morphoSupplyCollateral",
|
|
109
129
|
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
110
130
|
});
|
|
111
|
-
|
|
112
|
-
if (reallocations && reallocations.length > 0) {
|
|
113
|
-
const result = (0, buildReallocationActions_js_1.buildReallocationActions)(reallocations, marketParams);
|
|
114
|
-
actions.push(...result.actions);
|
|
115
|
-
reallocationFee = result.fee;
|
|
116
|
-
}
|
|
131
|
+
actions.push(...reallocationResult.actions);
|
|
117
132
|
actions.push({
|
|
118
133
|
type: "morphoBorrow",
|
|
119
134
|
args: [marketParams, borrowAmount, 0n, minSharePrice, receiver, false],
|
|
@@ -134,7 +149,8 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
134
149
|
onBehalf,
|
|
135
150
|
receiver,
|
|
136
151
|
nativeAmount,
|
|
137
|
-
reallocationFee,
|
|
152
|
+
reallocationFee: reallocationResult.fee,
|
|
153
|
+
reallocationPenaltyAssets: reallocationResult.penaltyAssets,
|
|
138
154
|
},
|
|
139
155
|
},
|
|
140
156
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type AuthorizationRequirementSignature, type
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueReallocationPlan, type BlueWithdrawAction, type Metadata, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueWithdraw}. */
|
|
5
5
|
export interface BlueWithdrawParams {
|
|
6
6
|
market: {
|
|
@@ -17,11 +17,11 @@ export interface BlueWithdrawParams {
|
|
|
17
17
|
/** Minimum withdraw share price (in ray). Slippage protection. */
|
|
18
18
|
minSharePrice: bigint;
|
|
19
19
|
/**
|
|
20
|
-
* Vault reallocations to execute before withdrawing.
|
|
21
|
-
* `MorphoBlue.
|
|
22
|
-
* `
|
|
20
|
+
* Homogeneous Vault V1 or Vault V2 reallocations to execute before withdrawing. V1 entries can be
|
|
21
|
+
* computed via `MorphoBlue.getVaultV1Reallocations({ operation: "withdraw", amount })` or directly
|
|
22
|
+
* via `computeVaultV1Reallocations({ operation: "withdraw", amount, ... })`.
|
|
23
23
|
*/
|
|
24
|
-
reallocations?:
|
|
24
|
+
reallocations?: BlueReallocationPlan;
|
|
25
25
|
/**
|
|
26
26
|
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
27
27
|
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
@@ -40,10 +40,11 @@ export interface BlueWithdrawParams {
|
|
|
40
40
|
* - **By shares** (`assets = 0, shares > 0`): burns an exact share count (typical for a full
|
|
41
41
|
* supplier position close; immune to interest accrual between tx construction and execution).
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
43
|
+
* A `reallocations` plan contains either V1 entries or V2 market/idle entries,
|
|
44
|
+
* never both. The calls run before the withdraw. V1
|
|
45
|
+
* fees accumulate in `tx.value`; V2 penalties are paid in the target loan
|
|
46
|
+
* token and donated to the vaults. The on-chain `morphoWithdraw` sends the
|
|
47
|
+
* assets computed on-chain directly to `receiver`; no skim is required.
|
|
47
48
|
*
|
|
48
49
|
* The withdraw is performed on behalf of the transaction initiator (signer) — there is no
|
|
49
50
|
* separate `onBehalf` field; mirror `blueBorrow`. The entity layer keeps `receiver` aligned
|
|
@@ -57,17 +58,23 @@ export interface BlueWithdrawParams {
|
|
|
57
58
|
* @param params.args.receiver - Address that receives the withdrawn assets.
|
|
58
59
|
* @param params.args.minSharePrice - Minimum acceptable withdraw share price (in ray). Slippage
|
|
59
60
|
* protection.
|
|
60
|
-
* @param params.args.reallocations - Optional
|
|
61
|
-
*
|
|
61
|
+
* @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
|
|
62
|
+
* execute before withdrawing.
|
|
62
63
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
63
64
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
64
65
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
65
66
|
* @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
|
|
66
67
|
* the typed `action` discriminator the simulation layer consumes.
|
|
67
|
-
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, or
|
|
68
|
-
* is negative.
|
|
68
|
+
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, a V1 fee, or a V2
|
|
69
|
+
* penalty is negative.
|
|
69
70
|
* @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
|
|
70
71
|
* withdrawal amount is non-positive.
|
|
72
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
73
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
74
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
75
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
76
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
77
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
71
78
|
* @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
|
|
72
79
|
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
73
80
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
|
|
@@ -16,10 +16,11 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
16
16
|
* - **By shares** (`assets = 0, shares > 0`): burns an exact share count (typical for a full
|
|
17
17
|
* supplier position close; immune to interest accrual between tx construction and execution).
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* A `reallocations` plan contains either V1 entries or V2 market/idle entries,
|
|
20
|
+
* never both. The calls run before the withdraw. V1
|
|
21
|
+
* fees accumulate in `tx.value`; V2 penalties are paid in the target loan
|
|
22
|
+
* token and donated to the vaults. The on-chain `morphoWithdraw` sends the
|
|
23
|
+
* assets computed on-chain directly to `receiver`; no skim is required.
|
|
23
24
|
*
|
|
24
25
|
* The withdraw is performed on behalf of the transaction initiator (signer) — there is no
|
|
25
26
|
* separate `onBehalf` field; mirror `blueBorrow`. The entity layer keeps `receiver` aligned
|
|
@@ -33,17 +34,23 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
33
34
|
* @param params.args.receiver - Address that receives the withdrawn assets.
|
|
34
35
|
* @param params.args.minSharePrice - Minimum acceptable withdraw share price (in ray). Slippage
|
|
35
36
|
* protection.
|
|
36
|
-
* @param params.args.reallocations - Optional
|
|
37
|
-
*
|
|
37
|
+
* @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
|
|
38
|
+
* execute before withdrawing.
|
|
38
39
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
39
40
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
40
41
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
42
|
* @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
|
|
42
43
|
* the typed `action` discriminator the simulation layer consumes.
|
|
43
|
-
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, or
|
|
44
|
-
* is negative.
|
|
44
|
+
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, a V1 fee, or a V2
|
|
45
|
+
* penalty is negative.
|
|
45
46
|
* @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
|
|
46
47
|
* withdrawal amount is non-positive.
|
|
48
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
49
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
50
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
51
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
52
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
53
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
47
54
|
* @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
|
|
48
55
|
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
49
56
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
|
|
@@ -86,23 +93,20 @@ const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, share
|
|
|
86
93
|
throw new index_js_3.NegativeInputError("minSharePrice", minSharePrice);
|
|
87
94
|
}
|
|
88
95
|
const actions = [];
|
|
89
|
-
let reallocationFee = 0n;
|
|
90
96
|
if (authorizationSignature) {
|
|
91
97
|
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
92
98
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
99
|
+
const { actions: reallocationActions, fee: reallocationFee, penaltyAssets: reallocationPenaltyAssets, } = (0, buildReallocationActions_js_1.buildBlueReallocationActions)({
|
|
100
|
+
chainId,
|
|
101
|
+
reallocations,
|
|
102
|
+
targetMarketParams: marketParams,
|
|
103
|
+
});
|
|
104
|
+
actions.push(...reallocationActions);
|
|
98
105
|
actions.push({
|
|
99
106
|
type: "morphoWithdraw",
|
|
100
107
|
args: [marketParams, assets, shares, minSharePrice, receiver, false],
|
|
101
108
|
});
|
|
102
|
-
let tx =
|
|
103
|
-
...index_js_1.BundlerAction.encodeBundle(chainId, actions),
|
|
104
|
-
value: reallocationFee,
|
|
105
|
-
};
|
|
109
|
+
let tx = index_js_1.BundlerAction.encodeBundle(chainId, actions);
|
|
106
110
|
if (metadata) {
|
|
107
111
|
tx = (0, index_js_2.addTransactionMetadata)(tx, metadata);
|
|
108
112
|
}
|
|
@@ -117,6 +121,7 @@ const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, share
|
|
|
117
121
|
receiver,
|
|
118
122
|
minSharePrice,
|
|
119
123
|
reallocationFee,
|
|
124
|
+
reallocationPenaltyAssets,
|
|
120
125
|
},
|
|
121
126
|
},
|
|
122
127
|
});
|
|
@@ -16,7 +16,7 @@ interface EncodeErc20ApprovalParams {
|
|
|
16
16
|
* @param params - Encoding parameters.
|
|
17
17
|
* @param params.token - ERC-20 token address to approve.
|
|
18
18
|
* @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
|
|
19
|
-
* Midnight, or
|
|
19
|
+
* Midnight, MidnightBundles, or VaultExitBundlesV1 for the chain.
|
|
20
20
|
* @param params.amount - Allowance amount before per-token cap.
|
|
21
21
|
* @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
|
|
22
22
|
* @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
|
|
@@ -15,7 +15,7 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
|
|
|
15
15
|
* @param params - Encoding parameters.
|
|
16
16
|
* @param params.token - ERC-20 token address to approve.
|
|
17
17
|
* @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
|
|
18
|
-
* Midnight, or
|
|
18
|
+
* Midnight, MidnightBundles, or VaultExitBundlesV1 for the chain.
|
|
19
19
|
* @param params.amount - Allowance amount before per-token cap.
|
|
20
20
|
* @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
|
|
21
21
|
* @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
|
|
@@ -35,10 +35,17 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
|
|
|
35
35
|
*/
|
|
36
36
|
const encodeErc20Approval = (params) => {
|
|
37
37
|
const { token, spender, amount, chainId } = params;
|
|
38
|
+
// Reject approval targets outside the SDK's registered protocol spenders.
|
|
38
39
|
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
39
40
|
chainId,
|
|
40
41
|
spender,
|
|
41
|
-
allowed: [
|
|
42
|
+
allowed: [
|
|
43
|
+
"generalAdapter1",
|
|
44
|
+
"permit2",
|
|
45
|
+
"midnight",
|
|
46
|
+
"midnightBundles",
|
|
47
|
+
"vaultExitBundlesV1",
|
|
48
|
+
],
|
|
42
49
|
});
|
|
43
50
|
const amountValue = blue_sdk_1.MathLib.min(amount, constant_js_1.MAX_TOKEN_APPROVALS[chainId]?.[token] ?? viem_1.maxUint256);
|
|
44
51
|
return (0, morpho_ts_1.deepFreeze)({
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type Address, Token } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { PermitRequirementSignature, Requirement } from "../../../types/index.js";
|
|
3
|
+
/** Parameters for {@link encodeVaultSharesPermit}. */
|
|
4
|
+
export interface EncodeVaultSharesPermitParams {
|
|
5
|
+
/** Vault share token, including V1 permit-domain metadata when available. */
|
|
6
|
+
readonly vault: Token;
|
|
7
|
+
/** Vault generation, which selects the standard V1 or two-field V2 domain. */
|
|
8
|
+
readonly version: "vaultV1" | "vaultV2";
|
|
9
|
+
/** VaultExitBundlesV1 spender. */
|
|
10
|
+
readonly spender: Address;
|
|
11
|
+
/** Account that owns the vault shares. */
|
|
12
|
+
readonly owner: Address;
|
|
13
|
+
/** Target chain. */
|
|
14
|
+
readonly chainId: number;
|
|
15
|
+
/** Current vault permit nonce for the owner. */
|
|
16
|
+
readonly nonce: bigint;
|
|
17
|
+
/** Vault-share allowance to authorize. */
|
|
18
|
+
readonly amount: bigint;
|
|
19
|
+
/** Shared permit and bundle deadline. */
|
|
20
|
+
readonly deadline: bigint;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
|
|
24
|
+
*
|
|
25
|
+
* Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
|
|
26
|
+
* only `chainId` and `verifyingContract`.
|
|
27
|
+
*
|
|
28
|
+
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
29
|
+
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
30
|
+
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
31
|
+
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
32
|
+
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
33
|
+
* @param params.nonce - Current vault permit nonce for the owner.
|
|
34
|
+
* @param params.amount - Vault-share allowance to authorize.
|
|
35
|
+
* @param params.deadline - Shared permit and bundle deadline.
|
|
36
|
+
* @returns A requirement whose `sign()` result can be embedded in VaultExitBundlesV1 calldata.
|
|
37
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
38
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the registered VaultExitBundlesV1.
|
|
39
|
+
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
40
|
+
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
|
|
41
|
+
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
42
|
+
* @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
|
|
43
|
+
* @throws {InvalidPermitDomainChainIdError} from `sign()` when a Vault V1 permit domain targets another chain or omits `chainId`.
|
|
44
|
+
* @throws {InvalidPermitDomainVerifyingContractError} from `sign()` when a Vault V1 permit domain targets another token or omits `verifyingContract`.
|
|
45
|
+
* @throws {UnsupportedPermitDomainExtensionsError} from `sign()` when a Vault V1 permit domain advertises unsupported extensions.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
|
|
49
|
+
*
|
|
50
|
+
* const requirement = encodeVaultSharesPermit({
|
|
51
|
+
* vault: vaultData,
|
|
52
|
+
* version: "vaultV2",
|
|
53
|
+
* spender: vaultExitBundlesV1,
|
|
54
|
+
* owner,
|
|
55
|
+
* chainId: 1,
|
|
56
|
+
* nonce: 0n,
|
|
57
|
+
* amount: 1_000_000n,
|
|
58
|
+
* deadline,
|
|
59
|
+
* });
|
|
60
|
+
* const signature = await requirement.sign(walletClient, owner);
|
|
61
|
+
* // signature satisfies PermitRequirementSignature
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const encodeVaultSharesPermit: (params: EncodeVaultSharesPermitParams) => Requirement<PermitRequirementSignature>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeVaultSharesPermit = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
|
|
9
|
+
const validate_js_1 = require("../../../helpers/validate.js");
|
|
10
|
+
const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
|
|
11
|
+
/**
|
|
12
|
+
* Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
|
|
13
|
+
*
|
|
14
|
+
* Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
|
|
15
|
+
* only `chainId` and `verifyingContract`.
|
|
16
|
+
*
|
|
17
|
+
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
18
|
+
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
19
|
+
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
20
|
+
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
21
|
+
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
22
|
+
* @param params.nonce - Current vault permit nonce for the owner.
|
|
23
|
+
* @param params.amount - Vault-share allowance to authorize.
|
|
24
|
+
* @param params.deadline - Shared permit and bundle deadline.
|
|
25
|
+
* @returns A requirement whose `sign()` result can be embedded in VaultExitBundlesV1 calldata.
|
|
26
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
27
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the registered VaultExitBundlesV1.
|
|
28
|
+
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
29
|
+
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
|
|
30
|
+
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
31
|
+
* @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
|
|
32
|
+
* @throws {InvalidPermitDomainChainIdError} from `sign()` when a Vault V1 permit domain targets another chain or omits `chainId`.
|
|
33
|
+
* @throws {InvalidPermitDomainVerifyingContractError} from `sign()` when a Vault V1 permit domain targets another token or omits `verifyingContract`.
|
|
34
|
+
* @throws {UnsupportedPermitDomainExtensionsError} from `sign()` when a Vault V1 permit domain advertises unsupported extensions.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
|
|
38
|
+
*
|
|
39
|
+
* const requirement = encodeVaultSharesPermit({
|
|
40
|
+
* vault: vaultData,
|
|
41
|
+
* version: "vaultV2",
|
|
42
|
+
* spender: vaultExitBundlesV1,
|
|
43
|
+
* owner,
|
|
44
|
+
* chainId: 1,
|
|
45
|
+
* nonce: 0n,
|
|
46
|
+
* amount: 1_000_000n,
|
|
47
|
+
* deadline,
|
|
48
|
+
* });
|
|
49
|
+
* const signature = await requirement.sign(walletClient, owner);
|
|
50
|
+
* // signature satisfies PermitRequirementSignature
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
const encodeVaultSharesPermit = (params) => {
|
|
54
|
+
const { vault: inputVault, version, spender, owner, chainId, nonce, amount, deadline, } = params;
|
|
55
|
+
const inputDomain = inputVault.eip5267Domain;
|
|
56
|
+
const vault = new blue_sdk_1.Token({
|
|
57
|
+
address: inputVault.address,
|
|
58
|
+
name: inputVault.name,
|
|
59
|
+
eip5267Domain: version === "vaultV2"
|
|
60
|
+
? new blue_sdk_1.Eip5267Domain({
|
|
61
|
+
// Only the bitmap-selected fields enter Vault V2's domain separator.
|
|
62
|
+
fields: "0x0c",
|
|
63
|
+
name: "",
|
|
64
|
+
version: "",
|
|
65
|
+
chainId: BigInt(chainId),
|
|
66
|
+
verifyingContract: inputVault.address,
|
|
67
|
+
salt: viem_1.zeroHash,
|
|
68
|
+
extensions: [],
|
|
69
|
+
})
|
|
70
|
+
: inputDomain == null
|
|
71
|
+
? undefined
|
|
72
|
+
: new blue_sdk_1.Eip5267Domain({
|
|
73
|
+
fields: inputDomain.fields,
|
|
74
|
+
name: inputDomain.name,
|
|
75
|
+
version: inputDomain.version,
|
|
76
|
+
chainId: inputDomain.chainId,
|
|
77
|
+
verifyingContract: inputDomain.verifyingContract,
|
|
78
|
+
salt: inputDomain.salt,
|
|
79
|
+
extensions: [...inputDomain.extensions],
|
|
80
|
+
}),
|
|
81
|
+
});
|
|
82
|
+
// Bind the permit to the standalone vault-exit deployment for this chain.
|
|
83
|
+
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
84
|
+
chainId,
|
|
85
|
+
spender,
|
|
86
|
+
allowed: ["vaultExitBundlesV1"],
|
|
87
|
+
});
|
|
88
|
+
const action = {
|
|
89
|
+
type: "permit",
|
|
90
|
+
args: {
|
|
91
|
+
spender,
|
|
92
|
+
amount,
|
|
93
|
+
deadline,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
action,
|
|
98
|
+
async sign(client, userAddress) {
|
|
99
|
+
// The bundle spends msg.sender's shares, so another signer cannot authorize this exit.
|
|
100
|
+
(0, validate_js_1.validateUserAddress)(userAddress, owner);
|
|
101
|
+
const permit = {
|
|
102
|
+
owner,
|
|
103
|
+
spender,
|
|
104
|
+
allowance: amount,
|
|
105
|
+
nonce,
|
|
106
|
+
deadline,
|
|
107
|
+
};
|
|
108
|
+
const typedData = (0, blue_sdk_viem_1.getPermitTypedData)({
|
|
109
|
+
...permit,
|
|
110
|
+
erc20: vault,
|
|
111
|
+
}, chainId);
|
|
112
|
+
const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
|
|
113
|
+
client,
|
|
114
|
+
userAddress,
|
|
115
|
+
typedData,
|
|
116
|
+
});
|
|
117
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
118
|
+
args: {
|
|
119
|
+
owner,
|
|
120
|
+
signature,
|
|
121
|
+
deadline,
|
|
122
|
+
amount,
|
|
123
|
+
asset: vault.address,
|
|
124
|
+
nonce,
|
|
125
|
+
},
|
|
126
|
+
action,
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
exports.encodeVaultSharesPermit = encodeVaultSharesPermit;
|
|
@@ -18,3 +18,4 @@ __exportStar(require("./encodeBlueSignatureAuthorization.js"), exports);
|
|
|
18
18
|
__exportStar(require("./encodeErc20Approval.js"), exports);
|
|
19
19
|
__exportStar(require("./encodeErc20Permit.js"), exports);
|
|
20
20
|
__exportStar(require("./encodeErc20Permit2Approve.js"), exports);
|
|
21
|
+
__exportStar(require("./encodeVaultSharesPermit.js"), exports);
|
|
@@ -5,7 +5,8 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
|
|
|
5
5
|
* allowance.
|
|
6
6
|
*
|
|
7
7
|
* The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
|
|
8
|
-
* GeneralAdapter1, Permit2, Midnight, and
|
|
8
|
+
* GeneralAdapter1, Permit2, Midnight, MidnightBundles, and VaultExitBundlesV1 addresses when
|
|
9
|
+
* configured.
|
|
9
10
|
*
|
|
10
11
|
* Returns an empty array when the allowance already covers `spendAmount`. When the token is in
|
|
11
12
|
* `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
|
|
@@ -19,7 +20,7 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
|
|
|
19
20
|
* @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
|
|
20
21
|
* may be `MAX_UINT_160` for Permit2 prerequisites).
|
|
21
22
|
* @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
|
|
22
|
-
* Permit2, Midnight, or
|
|
23
|
+
* Permit2, Midnight, MidnightBundles, or VaultExitBundlesV1 for `chainId`.
|
|
23
24
|
* @param params.allowances - The user's current allowance of `address` for `spender`.
|
|
24
25
|
* @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
|
|
25
26
|
* followed by the new approval. Empty when no approval is needed.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRequirementsApproval = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
4
5
|
const constant_js_1 = require("../../helpers/constant.js");
|
|
5
6
|
const index_js_1 = require("../../types/index.js");
|
|
6
7
|
const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
|
|
@@ -9,7 +10,8 @@ const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
|
|
|
9
10
|
* allowance.
|
|
10
11
|
*
|
|
11
12
|
* The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
|
|
12
|
-
* GeneralAdapter1, Permit2, Midnight, and
|
|
13
|
+
* GeneralAdapter1, Permit2, Midnight, MidnightBundles, and VaultExitBundlesV1 addresses when
|
|
14
|
+
* configured.
|
|
13
15
|
*
|
|
14
16
|
* Returns an empty array when the allowance already covers `spendAmount`. When the token is in
|
|
15
17
|
* `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
|
|
@@ -23,7 +25,7 @@ const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
|
|
|
23
25
|
* @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
|
|
24
26
|
* may be `MAX_UINT_160` for Permit2 prerequisites).
|
|
25
27
|
* @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
|
|
26
|
-
* Permit2, Midnight, or
|
|
28
|
+
* Permit2, Midnight, MidnightBundles, or VaultExitBundlesV1 for `chainId`.
|
|
27
29
|
* @param params.allowances - The user's current allowance of `address` for `spender`.
|
|
28
30
|
* @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
|
|
29
31
|
* followed by the new approval. Empty when no approval is needed.
|
|
@@ -49,7 +51,7 @@ const getRequirementsApproval = (params) => {
|
|
|
49
51
|
}
|
|
50
52
|
const approvals = [];
|
|
51
53
|
if (allowances < spendAmount) {
|
|
52
|
-
if (constant_js_1.APPROVE_ONLY_ONCE_TOKENS[chainId]?.
|
|
54
|
+
if (constant_js_1.APPROVE_ONLY_ONCE_TOKENS[chainId]?.some((token) => (0, viem_1.isAddressEqual)(token, address)) &&
|
|
53
55
|
allowances > 0n) {
|
|
54
56
|
approvals.push((0, encodeErc20Approval_js_1.encodeErc20Approval)({
|
|
55
57
|
token: address,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import { type PermitRequirementSignature } from "../../types/index.js";
|
|
3
|
+
/** Permit tuple consumed by VaultExitBundlesV1. */
|
|
4
|
+
export interface VaultExitBundlesV1PermitStruct {
|
|
5
|
+
/** Vault-share allowance authorized by the permit. */
|
|
6
|
+
readonly value: bigint;
|
|
7
|
+
/** Vault permit nonce signed by the owner. */
|
|
8
|
+
readonly nonce: bigint;
|
|
9
|
+
/** Timestamp after which the permit is invalid. */
|
|
10
|
+
readonly deadline: bigint;
|
|
11
|
+
/** ECDSA recovery identifier, or zero for the empty-permit sentinel. */
|
|
12
|
+
readonly v: number;
|
|
13
|
+
/** ECDSA signature `r`, or zero for the empty-permit sentinel. */
|
|
14
|
+
readonly r: Hex;
|
|
15
|
+
/** ECDSA signature `s`, or zero for the empty-permit sentinel. */
|
|
16
|
+
readonly s: Hex;
|
|
17
|
+
}
|
|
18
|
+
/** Parameters for {@link getVaultExitBundlesV1PermitStruct}. */
|
|
19
|
+
export interface GetVaultExitBundlesV1PermitStructParams {
|
|
20
|
+
/** Vault share token authorized by the permit. */
|
|
21
|
+
readonly vault: Address;
|
|
22
|
+
/** Bundle deadline used by the empty-permit sentinel. */
|
|
23
|
+
readonly deadline: bigint;
|
|
24
|
+
/** Optional signed bounded ERC-2612 requirement. */
|
|
25
|
+
readonly requirementSignature?: PermitRequirementSignature;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns the permit struct consumed by VaultExitBundlesV1 from an optional vault-share
|
|
29
|
+
* requirement signature.
|
|
30
|
+
*
|
|
31
|
+
* Without a signature, returns the contract's empty-permit sentinel. With a signature, validates
|
|
32
|
+
* the ERC-2612 kind and vault asset before splitting the serialized signature.
|
|
33
|
+
* Owner, spender, deadline, nonce, and cryptographic validity are verified onchain by the vault.
|
|
34
|
+
*
|
|
35
|
+
* @param params.vault - Vault share token authorized by the permit.
|
|
36
|
+
* @param params.deadline - Bundle deadline used by the empty-permit sentinel.
|
|
37
|
+
* @param params.requirementSignature - Optional signed bounded ERC-2612 requirement.
|
|
38
|
+
* @returns The VaultExitBundlesV1 permit tuple.
|
|
39
|
+
* @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { getVaultExitBundlesV1PermitStruct } from "@morpho-org/morpho-sdk";
|
|
43
|
+
*
|
|
44
|
+
* const permit = getVaultExitBundlesV1PermitStruct({
|
|
45
|
+
* vault,
|
|
46
|
+
* deadline,
|
|
47
|
+
* requirementSignature,
|
|
48
|
+
* });
|
|
49
|
+
* // permit satisfies VaultExitBundlesV1PermitStruct
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const getVaultExitBundlesV1PermitStruct: (params: GetVaultExitBundlesV1PermitStructParams) => VaultExitBundlesV1PermitStruct;
|