@morpho-org/morpho-sdk 5.4.0 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/lib/cjs/abis.d.ts +313 -0
- package/lib/cjs/abis.js +167 -1
- 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 +3 -2
- 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 +1 -2
- package/lib/cjs/bundler/actions.js +1 -2
- package/lib/cjs/entities/blue/blue.d.ts +8 -8
- package/lib/cjs/entities/reallocationData.d.ts +1 -2
- package/lib/cjs/entities/reallocationData.js +1 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +82 -4
- package/lib/cjs/entities/vaultV1/vaultV1.js +164 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +89 -3
- package/lib/cjs/entities/vaultV2/vaultV2.js +181 -0
- package/lib/cjs/helpers/index.d.ts +1 -0
- package/lib/cjs/helpers/index.js +3 -1
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +73 -0
- package/lib/cjs/helpers/validate.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +2 -1
- package/lib/cjs/types/action.d.ts +21 -1
- package/lib/cjs/types/error.d.ts +139 -0
- package/lib/cjs/types/error.js +189 -2
- package/lib/esm/abis.d.ts +313 -0
- package/lib/esm/abis.js +166 -0
- 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 +3 -2
- 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 +1 -2
- package/lib/esm/bundler/actions.js +1 -2
- package/lib/esm/entities/blue/blue.d.ts +5 -5
- package/lib/esm/entities/reallocationData.d.ts +1 -2
- package/lib/esm/entities/reallocationData.js +1 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +80 -2
- package/lib/esm/entities/vaultV1/vaultV1.js +170 -6
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +88 -2
- package/lib/esm/entities/vaultV2/vaultV2.js +187 -6
- package/lib/esm/helpers/index.d.ts +1 -0
- package/lib/esm/helpers/index.js +1 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +70 -0
- package/lib/esm/helpers/validate.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +2 -1
- package/lib/esm/types/action.d.ts +21 -1
- package/lib/esm/types/error.d.ts +139 -0
- package/lib/esm/types/error.js +175 -0
- package/package.json +9 -11
package/lib/esm/abis.js
CHANGED
|
@@ -1,6 +1,172 @@
|
|
|
1
1
|
export { marketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi, preLiquidationAbi, preLiquidationFactoryAbi, publicAllocatorAbi, vaultV1AdapterAbi, vaultV1AdapterFactoryAbi, vaultV2Abi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
export { ecrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
4
|
+
/** ABI for the VaultExitBundlesV1 periphery contract. */
|
|
5
|
+
export const vaultExitBundlesV1Abi = [
|
|
6
|
+
{
|
|
7
|
+
type: "constructor",
|
|
8
|
+
inputs: [{ name: "_blue", type: "address", internalType: "address" }],
|
|
9
|
+
stateMutability: "nonpayable",
|
|
10
|
+
},
|
|
11
|
+
{ type: "error", name: "AdapterNotPartOfVault", inputs: [] },
|
|
12
|
+
{ type: "error", name: "AlreadyInitiated", inputs: [] },
|
|
13
|
+
{ type: "error", name: "ApproveReturnedFalse", inputs: [] },
|
|
14
|
+
{ type: "error", name: "DeadlinePassed", inputs: [] },
|
|
15
|
+
{ type: "error", name: "InvalidAdaptersLength", inputs: [] },
|
|
16
|
+
{ type: "error", name: "MorphoMismatch", inputs: [] },
|
|
17
|
+
{ type: "error", name: "NoCode", inputs: [] },
|
|
18
|
+
{ type: "error", name: "PctExceeded", inputs: [] },
|
|
19
|
+
{ type: "error", name: "SlippageExceeded", inputs: [] },
|
|
20
|
+
{ type: "error", name: "TransferReturnedFalse", inputs: [] },
|
|
21
|
+
{ type: "error", name: "UnauthorizedCallback", inputs: [] },
|
|
22
|
+
{
|
|
23
|
+
type: "function",
|
|
24
|
+
name: "BLUE",
|
|
25
|
+
inputs: [],
|
|
26
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
27
|
+
stateMutability: "view",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: "function",
|
|
31
|
+
name: "initiator",
|
|
32
|
+
inputs: [],
|
|
33
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
34
|
+
stateMutability: "view",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: "function",
|
|
38
|
+
name: "onMorphoFlashLoan",
|
|
39
|
+
inputs: [
|
|
40
|
+
{ name: "exitAssets", type: "uint256", internalType: "uint256" },
|
|
41
|
+
{ name: "data", type: "bytes", internalType: "bytes" },
|
|
42
|
+
],
|
|
43
|
+
outputs: [],
|
|
44
|
+
stateMutability: "nonpayable",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "function",
|
|
48
|
+
name: "onMorphoSupply",
|
|
49
|
+
inputs: [
|
|
50
|
+
{ name: "assets", type: "uint256", internalType: "uint256" },
|
|
51
|
+
{ name: "data", type: "bytes", internalType: "bytes" },
|
|
52
|
+
],
|
|
53
|
+
outputs: [],
|
|
54
|
+
stateMutability: "nonpayable",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "function",
|
|
58
|
+
name: "vaultExitBundlesV1ForceWithdrawVaultV2",
|
|
59
|
+
inputs: [
|
|
60
|
+
{ name: "vault", type: "address", internalType: "address" },
|
|
61
|
+
{ name: "adapter", type: "address", internalType: "address" },
|
|
62
|
+
{ name: "exitAssets", type: "uint256", internalType: "uint256" },
|
|
63
|
+
{ name: "minSharePriceE27", type: "uint256", internalType: "uint256" },
|
|
64
|
+
{
|
|
65
|
+
name: "sharesPermit",
|
|
66
|
+
type: "tuple",
|
|
67
|
+
internalType: "struct Permit",
|
|
68
|
+
components: [
|
|
69
|
+
{ name: "value", type: "uint256", internalType: "uint256" },
|
|
70
|
+
{ name: "nonce", type: "uint256", internalType: "uint256" },
|
|
71
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" },
|
|
72
|
+
{ name: "v", type: "uint8", internalType: "uint8" },
|
|
73
|
+
{ name: "r", type: "bytes32", internalType: "bytes32" },
|
|
74
|
+
{ name: "s", type: "bytes32", internalType: "bytes32" },
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{ name: "referralFeePct", type: "uint256", internalType: "uint256" },
|
|
78
|
+
{
|
|
79
|
+
name: "referralFeeRecipient",
|
|
80
|
+
type: "address",
|
|
81
|
+
internalType: "address",
|
|
82
|
+
},
|
|
83
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" },
|
|
84
|
+
],
|
|
85
|
+
outputs: [],
|
|
86
|
+
stateMutability: "nonpayable",
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: "function",
|
|
90
|
+
name: "vaultExitBundlesV1InKindRedemptionVaultV1",
|
|
91
|
+
inputs: [
|
|
92
|
+
{ name: "vault", type: "address", internalType: "address" },
|
|
93
|
+
{
|
|
94
|
+
name: "marketParamsList",
|
|
95
|
+
type: "tuple[]",
|
|
96
|
+
internalType: "struct MarketParams[]",
|
|
97
|
+
components: [
|
|
98
|
+
{ name: "loanToken", type: "address", internalType: "address" },
|
|
99
|
+
{
|
|
100
|
+
name: "collateralToken",
|
|
101
|
+
type: "address",
|
|
102
|
+
internalType: "address",
|
|
103
|
+
},
|
|
104
|
+
{ name: "oracle", type: "address", internalType: "address" },
|
|
105
|
+
{ name: "irm", type: "address", internalType: "address" },
|
|
106
|
+
{ name: "lltv", type: "uint256", internalType: "uint256" },
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
{ name: "exitAssets", type: "uint256", internalType: "uint256" },
|
|
110
|
+
{
|
|
111
|
+
name: "sharesPermit",
|
|
112
|
+
type: "tuple",
|
|
113
|
+
internalType: "struct Permit",
|
|
114
|
+
components: [
|
|
115
|
+
{ name: "value", type: "uint256", internalType: "uint256" },
|
|
116
|
+
{ name: "nonce", type: "uint256", internalType: "uint256" },
|
|
117
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" },
|
|
118
|
+
{ name: "v", type: "uint8", internalType: "uint8" },
|
|
119
|
+
{ name: "r", type: "bytes32", internalType: "bytes32" },
|
|
120
|
+
{ name: "s", type: "bytes32", internalType: "bytes32" },
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" },
|
|
124
|
+
],
|
|
125
|
+
outputs: [],
|
|
126
|
+
stateMutability: "nonpayable",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: "function",
|
|
130
|
+
name: "vaultExitBundlesV1InKindRedemptionVaultV2",
|
|
131
|
+
inputs: [
|
|
132
|
+
{ name: "vault", type: "address", internalType: "address" },
|
|
133
|
+
{ name: "adapter", type: "address", internalType: "address" },
|
|
134
|
+
{
|
|
135
|
+
name: "marketParamsList",
|
|
136
|
+
type: "tuple[]",
|
|
137
|
+
internalType: "struct MarketParams[]",
|
|
138
|
+
components: [
|
|
139
|
+
{ name: "loanToken", type: "address", internalType: "address" },
|
|
140
|
+
{
|
|
141
|
+
name: "collateralToken",
|
|
142
|
+
type: "address",
|
|
143
|
+
internalType: "address",
|
|
144
|
+
},
|
|
145
|
+
{ name: "oracle", type: "address", internalType: "address" },
|
|
146
|
+
{ name: "irm", type: "address", internalType: "address" },
|
|
147
|
+
{ name: "lltv", type: "uint256", internalType: "uint256" },
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
{ name: "exitAssets", type: "uint256", internalType: "uint256" },
|
|
151
|
+
{
|
|
152
|
+
name: "sharesPermit",
|
|
153
|
+
type: "tuple",
|
|
154
|
+
internalType: "struct Permit",
|
|
155
|
+
components: [
|
|
156
|
+
{ name: "value", type: "uint256", internalType: "uint256" },
|
|
157
|
+
{ name: "nonce", type: "uint256", internalType: "uint256" },
|
|
158
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" },
|
|
159
|
+
{ name: "v", type: "uint8", internalType: "uint8" },
|
|
160
|
+
{ name: "r", type: "bytes32", internalType: "bytes32" },
|
|
161
|
+
{ name: "s", type: "bytes32", internalType: "bytes32" },
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" },
|
|
165
|
+
],
|
|
166
|
+
outputs: [],
|
|
167
|
+
stateMutability: "nonpayable",
|
|
168
|
+
},
|
|
169
|
+
];
|
|
4
170
|
/** ABI for the Bundler3 multicall contract. */
|
|
5
171
|
export const bundler3Abi = [
|
|
6
172
|
{
|
|
@@ -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.
|
|
@@ -12,7 +12,7 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
|
|
|
12
12
|
* @param params - Encoding parameters.
|
|
13
13
|
* @param params.token - ERC-20 token address to approve.
|
|
14
14
|
* @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
|
|
15
|
-
* Midnight, or
|
|
15
|
+
* Midnight, MidnightBundles, or VaultExitBundlesV1 for the chain.
|
|
16
16
|
* @param params.amount - Allowance amount before per-token cap.
|
|
17
17
|
* @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
|
|
18
18
|
* @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
|
|
@@ -32,10 +32,17 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
|
|
|
32
32
|
*/
|
|
33
33
|
export const encodeErc20Approval = (params) => {
|
|
34
34
|
const { token, spender, amount, chainId } = params;
|
|
35
|
+
// Reject approval targets outside the SDK's registered protocol spenders.
|
|
35
36
|
validateRequirementSpender({
|
|
36
37
|
chainId,
|
|
37
38
|
spender,
|
|
38
|
-
allowed: [
|
|
39
|
+
allowed: [
|
|
40
|
+
"generalAdapter1",
|
|
41
|
+
"permit2",
|
|
42
|
+
"midnight",
|
|
43
|
+
"midnightBundles",
|
|
44
|
+
"vaultExitBundlesV1",
|
|
45
|
+
],
|
|
39
46
|
});
|
|
40
47
|
const amountValue = MathLib.min(amount, MAX_TOKEN_APPROVALS[chainId]?.[token] ?? maxUint256);
|
|
41
48
|
return 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,127 @@
|
|
|
1
|
+
import { Eip5267Domain, Token } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { getPermitTypedData } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
4
|
+
import { zeroHash } from "viem";
|
|
5
|
+
import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
|
|
6
|
+
import { validateUserAddress } from "../../../helpers/validate.js";
|
|
7
|
+
import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
|
|
8
|
+
/**
|
|
9
|
+
* Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
|
|
10
|
+
*
|
|
11
|
+
* Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
|
|
12
|
+
* only `chainId` and `verifyingContract`.
|
|
13
|
+
*
|
|
14
|
+
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
15
|
+
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
16
|
+
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
17
|
+
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
18
|
+
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
19
|
+
* @param params.nonce - Current vault permit nonce for the owner.
|
|
20
|
+
* @param params.amount - Vault-share allowance to authorize.
|
|
21
|
+
* @param params.deadline - Shared permit and bundle deadline.
|
|
22
|
+
* @returns A requirement whose `sign()` result can be embedded in VaultExitBundlesV1 calldata.
|
|
23
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
24
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the registered VaultExitBundlesV1.
|
|
25
|
+
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
26
|
+
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
|
|
27
|
+
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|
|
28
|
+
* @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
|
|
29
|
+
* @throws {InvalidPermitDomainChainIdError} from `sign()` when a Vault V1 permit domain targets another chain or omits `chainId`.
|
|
30
|
+
* @throws {InvalidPermitDomainVerifyingContractError} from `sign()` when a Vault V1 permit domain targets another token or omits `verifyingContract`.
|
|
31
|
+
* @throws {UnsupportedPermitDomainExtensionsError} from `sign()` when a Vault V1 permit domain advertises unsupported extensions.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
|
|
35
|
+
*
|
|
36
|
+
* const requirement = encodeVaultSharesPermit({
|
|
37
|
+
* vault: vaultData,
|
|
38
|
+
* version: "vaultV2",
|
|
39
|
+
* spender: vaultExitBundlesV1,
|
|
40
|
+
* owner,
|
|
41
|
+
* chainId: 1,
|
|
42
|
+
* nonce: 0n,
|
|
43
|
+
* amount: 1_000_000n,
|
|
44
|
+
* deadline,
|
|
45
|
+
* });
|
|
46
|
+
* const signature = await requirement.sign(walletClient, owner);
|
|
47
|
+
* // signature satisfies PermitRequirementSignature
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export const encodeVaultSharesPermit = (params) => {
|
|
51
|
+
const { vault: inputVault, version, spender, owner, chainId, nonce, amount, deadline, } = params;
|
|
52
|
+
const inputDomain = inputVault.eip5267Domain;
|
|
53
|
+
const vault = new Token({
|
|
54
|
+
address: inputVault.address,
|
|
55
|
+
name: inputVault.name,
|
|
56
|
+
eip5267Domain: version === "vaultV2"
|
|
57
|
+
? new Eip5267Domain({
|
|
58
|
+
// Only the bitmap-selected fields enter Vault V2's domain separator.
|
|
59
|
+
fields: "0x0c",
|
|
60
|
+
name: "",
|
|
61
|
+
version: "",
|
|
62
|
+
chainId: BigInt(chainId),
|
|
63
|
+
verifyingContract: inputVault.address,
|
|
64
|
+
salt: zeroHash,
|
|
65
|
+
extensions: [],
|
|
66
|
+
})
|
|
67
|
+
: inputDomain == null
|
|
68
|
+
? undefined
|
|
69
|
+
: new Eip5267Domain({
|
|
70
|
+
fields: inputDomain.fields,
|
|
71
|
+
name: inputDomain.name,
|
|
72
|
+
version: inputDomain.version,
|
|
73
|
+
chainId: inputDomain.chainId,
|
|
74
|
+
verifyingContract: inputDomain.verifyingContract,
|
|
75
|
+
salt: inputDomain.salt,
|
|
76
|
+
extensions: [...inputDomain.extensions],
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
// Bind the permit to the standalone vault-exit deployment for this chain.
|
|
80
|
+
validateRequirementSpender({
|
|
81
|
+
chainId,
|
|
82
|
+
spender,
|
|
83
|
+
allowed: ["vaultExitBundlesV1"],
|
|
84
|
+
});
|
|
85
|
+
const action = {
|
|
86
|
+
type: "permit",
|
|
87
|
+
args: {
|
|
88
|
+
spender,
|
|
89
|
+
amount,
|
|
90
|
+
deadline,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
action,
|
|
95
|
+
async sign(client, userAddress) {
|
|
96
|
+
// The bundle spends msg.sender's shares, so another signer cannot authorize this exit.
|
|
97
|
+
validateUserAddress(userAddress, owner);
|
|
98
|
+
const permit = {
|
|
99
|
+
owner,
|
|
100
|
+
spender,
|
|
101
|
+
allowance: amount,
|
|
102
|
+
nonce,
|
|
103
|
+
deadline,
|
|
104
|
+
};
|
|
105
|
+
const typedData = getPermitTypedData({
|
|
106
|
+
...permit,
|
|
107
|
+
erc20: vault,
|
|
108
|
+
}, chainId);
|
|
109
|
+
const signature = await signAndVerifyTypedData({
|
|
110
|
+
client,
|
|
111
|
+
userAddress,
|
|
112
|
+
typedData,
|
|
113
|
+
});
|
|
114
|
+
return deepFreeze({
|
|
115
|
+
args: {
|
|
116
|
+
owner,
|
|
117
|
+
signature,
|
|
118
|
+
deadline,
|
|
119
|
+
amount,
|
|
120
|
+
asset: vault.address,
|
|
121
|
+
nonce,
|
|
122
|
+
},
|
|
123
|
+
action,
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
};
|
|
@@ -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.
|
|
@@ -6,7 +6,8 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
|
|
|
6
6
|
* allowance.
|
|
7
7
|
*
|
|
8
8
|
* The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
|
|
9
|
-
* GeneralAdapter1, Permit2, Midnight, and
|
|
9
|
+
* GeneralAdapter1, Permit2, Midnight, MidnightBundles, and VaultExitBundlesV1 addresses when
|
|
10
|
+
* configured.
|
|
10
11
|
*
|
|
11
12
|
* Returns an empty array when the allowance already covers `spendAmount`. When the token is in
|
|
12
13
|
* `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
|
|
@@ -20,7 +21,7 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
|
|
|
20
21
|
* @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
|
|
21
22
|
* may be `MAX_UINT_160` for Permit2 prerequisites).
|
|
22
23
|
* @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
|
|
23
|
-
* Permit2, Midnight, or
|
|
24
|
+
* Permit2, Midnight, MidnightBundles, or VaultExitBundlesV1 for `chainId`.
|
|
24
25
|
* @param params.allowances - The user's current allowance of `address` for `spender`.
|
|
25
26
|
* @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
|
|
26
27
|
* followed by the new approval. Empty when no approval is needed.
|
|
@@ -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;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { compactSignatureToSignature, isAddressEqual, parseCompactSignature, parseSignature, size, zeroHash, } from "viem";
|
|
2
|
+
import { VaultExitBundlesV1PermitMismatchError, } from "../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the permit struct consumed by VaultExitBundlesV1 from an optional vault-share
|
|
5
|
+
* requirement signature.
|
|
6
|
+
*
|
|
7
|
+
* Without a signature, returns the contract's empty-permit sentinel. With a signature, validates
|
|
8
|
+
* the ERC-2612 kind and vault asset before splitting the serialized signature.
|
|
9
|
+
* Owner, spender, deadline, nonce, and cryptographic validity are verified onchain by the vault.
|
|
10
|
+
*
|
|
11
|
+
* @param params.vault - Vault share token authorized by the permit.
|
|
12
|
+
* @param params.deadline - Bundle deadline used by the empty-permit sentinel.
|
|
13
|
+
* @param params.requirementSignature - Optional signed bounded ERC-2612 requirement.
|
|
14
|
+
* @returns The VaultExitBundlesV1 permit tuple.
|
|
15
|
+
* @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { getVaultExitBundlesV1PermitStruct } from "@morpho-org/morpho-sdk";
|
|
19
|
+
*
|
|
20
|
+
* const permit = getVaultExitBundlesV1PermitStruct({
|
|
21
|
+
* vault,
|
|
22
|
+
* deadline,
|
|
23
|
+
* requirementSignature,
|
|
24
|
+
* });
|
|
25
|
+
* // permit satisfies VaultExitBundlesV1PermitStruct
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const getVaultExitBundlesV1PermitStruct = (params) => {
|
|
29
|
+
const { requirementSignature } = params;
|
|
30
|
+
if (requirementSignature == null) {
|
|
31
|
+
return {
|
|
32
|
+
value: 0n,
|
|
33
|
+
nonce: 0n,
|
|
34
|
+
deadline: params.deadline,
|
|
35
|
+
v: 0,
|
|
36
|
+
r: zeroHash,
|
|
37
|
+
s: zeroHash,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (requirementSignature.action.type !== "permit") {
|
|
41
|
+
throw new VaultExitBundlesV1PermitMismatchError({
|
|
42
|
+
field: "type",
|
|
43
|
+
expected: "permit",
|
|
44
|
+
actual: requirementSignature.action.type,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (!isAddressEqual(requirementSignature.args.asset, params.vault)) {
|
|
48
|
+
throw new VaultExitBundlesV1PermitMismatchError({
|
|
49
|
+
field: "asset",
|
|
50
|
+
expected: params.vault,
|
|
51
|
+
actual: requirementSignature.args.asset,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const signature = (() => {
|
|
55
|
+
try {
|
|
56
|
+
const serializedSignature = requirementSignature.args.signature;
|
|
57
|
+
return size(serializedSignature) === 64
|
|
58
|
+
? compactSignatureToSignature(parseCompactSignature(serializedSignature))
|
|
59
|
+
: parseSignature(serializedSignature);
|
|
60
|
+
}
|
|
61
|
+
catch (cause) {
|
|
62
|
+
throw new VaultExitBundlesV1PermitMismatchError({
|
|
63
|
+
field: "signature",
|
|
64
|
+
expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
|
|
65
|
+
actual: requirementSignature.args.signature,
|
|
66
|
+
cause,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
})();
|
|
70
|
+
const { r, s, v, yParity } = signature;
|
|
71
|
+
const normalizedV = v ?? (yParity == null ? undefined : BigInt(yParity + 27));
|
|
72
|
+
if (normalizedV == null) {
|
|
73
|
+
throw new VaultExitBundlesV1PermitMismatchError({
|
|
74
|
+
field: "signature",
|
|
75
|
+
expected: "a signature containing v or yParity",
|
|
76
|
+
actual: requirementSignature.args.signature,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
value: requirementSignature.args.amount,
|
|
81
|
+
nonce: requirementSignature.args.nonce,
|
|
82
|
+
deadline: requirementSignature.args.deadline,
|
|
83
|
+
v: Number(normalizedV),
|
|
84
|
+
r,
|
|
85
|
+
s,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { InputMarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type Metadata, type PermitRequirementSignature, type Transaction, type VaultV1InKindRedeemAction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link vaultV1InKindRedeem}. */
|
|
5
|
+
export interface VaultV1InKindRedeemParams {
|
|
6
|
+
readonly vault: {
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
readonly address: Address;
|
|
9
|
+
};
|
|
10
|
+
readonly args: {
|
|
11
|
+
readonly amount: bigint;
|
|
12
|
+
readonly marketParamsList: readonly InputMarketParams[];
|
|
13
|
+
readonly userAddress: Address;
|
|
14
|
+
readonly deadline: bigint;
|
|
15
|
+
readonly requirementSignature?: PermitRequirementSignature;
|
|
16
|
+
};
|
|
17
|
+
readonly metadata?: Metadata;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Prepares a Vault V1 in-kind redemption into Morpho Blue supply positions.
|
|
21
|
+
*
|
|
22
|
+
* The transaction calls VaultExitBundlesV1 directly. Without a signature it embeds the contract's
|
|
23
|
+
* empty-permit sentinel; the user must first approve enough shares for the exit.
|
|
24
|
+
*
|
|
25
|
+
* @param params - In-kind redemption parameters.
|
|
26
|
+
* @param params.vault.chainId - Chain containing the target Vault V1 and VaultExitBundlesV1.
|
|
27
|
+
* @param params.vault.address - Target Vault V1 address.
|
|
28
|
+
* @param params.args.amount - Asset-denominated amount to exit.
|
|
29
|
+
* @param params.args.marketParamsList - Ordered markets consumed greedily by the contract.
|
|
30
|
+
* @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
|
|
31
|
+
* VaultExitBundlesV1 burns `msg.sender`'s vault shares, so the submitting account must equal this
|
|
32
|
+
* address.
|
|
33
|
+
* @param params.args.deadline - Permit and bundle deadline.
|
|
34
|
+
* @param params.args.requirementSignature - Optional bounded Vault V1 shares permit.
|
|
35
|
+
* @param params.metadata - Optional analytics metadata.
|
|
36
|
+
* @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
|
|
37
|
+
* `data`, and the typed action discriminator.
|
|
38
|
+
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
39
|
+
* @throws {EmptyMarketParamsListError} when no markets are supplied.
|
|
40
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
41
|
+
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
42
|
+
* @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { vaultV1InKindRedeem } from "@morpho-org/morpho-sdk";
|
|
46
|
+
*
|
|
47
|
+
* const tx = vaultV1InKindRedeem({
|
|
48
|
+
* vault: { chainId: 1, address: vault },
|
|
49
|
+
* args: { amount: 1_000_000n, marketParamsList, userAddress, deadline },
|
|
50
|
+
* });
|
|
51
|
+
* // tx satisfies Readonly<Transaction<VaultV1InKindRedeemAction>>
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const vaultV1InKindRedeem: ({ vault, args, metadata, }: VaultV1InKindRedeemParams) => Readonly<Transaction<VaultV1InKindRedeemAction>>;
|