@morpho-org/morpho-sdk 6.0.0-next.3 → 6.0.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/MIGRATION-v5-to-v6.md +24 -16
- package/README.md +6 -4
- package/lib/cjs/abis.d.ts +5 -1
- package/lib/cjs/abis.js +2 -0
- package/lib/cjs/actions/bundles/common.d.ts +20 -25
- package/lib/cjs/actions/bundles/common.js +46 -85
- package/lib/cjs/actions/bundles/index.d.ts +1 -1
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +19 -1
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +12 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +2 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +2 -1
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +62 -17
- package/lib/cjs/actions/vaultV1/migrateToV2.js +48 -17
- package/lib/cjs/actions/vaultV1/redeem.d.ts +28 -1
- package/lib/cjs/actions/vaultV1/redeem.js +17 -1
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.js +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +3 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -2
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +2 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +2 -1
- package/lib/cjs/actions/vaultV2/redeem.d.ts +28 -1
- package/lib/cjs/actions/vaultV2/redeem.js +17 -1
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.js +1 -1
- package/lib/cjs/augment/AccrualPosition.d.ts +1 -0
- package/lib/cjs/blue/abis.d.ts +5 -1
- package/lib/cjs/blue/abis.js +2 -0
- package/lib/cjs/blue/entities.d.ts +10 -2
- package/lib/cjs/blue/entities.js +2 -0
- package/lib/cjs/blue/errors.d.ts +4 -2
- package/lib/cjs/blue/errors.js +3 -1
- package/lib/cjs/blue/fetch.d.ts +5 -1
- package/lib/cjs/blue/fetch.js +2 -0
- package/lib/cjs/blue/utils.d.ts +5 -1
- package/lib/cjs/blue/utils.js +2 -0
- package/lib/cjs/entities/index.d.ts +10 -2
- package/lib/cjs/entities/index.js +2 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +31 -21
- package/lib/cjs/entities/vaultV1/vaultV1.js +50 -83
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +52 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +71 -81
- package/lib/cjs/errors.d.ts +5 -3
- package/lib/cjs/errors.js +4 -1
- package/lib/cjs/fetch.d.ts +5 -1
- package/lib/cjs/fetch.js +2 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +11 -5
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +48 -15
- package/lib/cjs/midnight/errors.d.ts +1 -1
- package/lib/cjs/midnight/errors.js +2 -1
- package/lib/cjs/types/action.d.ts +1 -0
- package/lib/cjs/utils.d.ts +5 -1
- package/lib/cjs/utils.js +2 -0
- package/lib/esm/abis.d.ts +5 -1
- package/lib/esm/abis.js +5 -1
- package/lib/esm/actions/bundles/common.d.ts +20 -25
- package/lib/esm/actions/bundles/common.js +44 -82
- package/lib/esm/actions/bundles/index.d.ts +1 -1
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -3
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +14 -2
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +2 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +2 -1
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +62 -17
- package/lib/esm/actions/vaultV1/migrateToV2.js +48 -17
- package/lib/esm/actions/vaultV1/redeem.d.ts +28 -1
- package/lib/esm/actions/vaultV1/redeem.js +17 -1
- package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV1/withdraw.js +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +3 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -2
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +2 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.js +2 -1
- package/lib/esm/actions/vaultV2/redeem.d.ts +28 -1
- package/lib/esm/actions/vaultV2/redeem.js +17 -1
- package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/withdraw.js +1 -1
- package/lib/esm/augment/AccrualPosition.d.ts +1 -0
- package/lib/esm/blue/abis.d.ts +5 -1
- package/lib/esm/blue/abis.js +5 -1
- package/lib/esm/blue/entities.d.ts +10 -2
- package/lib/esm/blue/entities.js +5 -1
- package/lib/esm/blue/errors.d.ts +4 -2
- package/lib/esm/blue/errors.js +4 -2
- package/lib/esm/blue/fetch.d.ts +5 -1
- package/lib/esm/blue/fetch.js +5 -1
- package/lib/esm/blue/utils.d.ts +5 -1
- package/lib/esm/blue/utils.js +5 -1
- package/lib/esm/entities/index.d.ts +10 -2
- package/lib/esm/entities/index.js +5 -1
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +31 -21
- package/lib/esm/entities/vaultV1/vaultV1.js +52 -85
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +52 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +73 -83
- package/lib/esm/errors.d.ts +5 -3
- package/lib/esm/errors.js +5 -3
- package/lib/esm/fetch.d.ts +5 -1
- package/lib/esm/fetch.js +5 -1
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +11 -5
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +48 -15
- package/lib/esm/midnight/errors.d.ts +1 -1
- package/lib/esm/midnight/errors.js +1 -1
- package/lib/esm/types/action.d.ts +1 -0
- package/lib/esm/utils.d.ts +5 -1
- package/lib/esm/utils.js +5 -1
- package/package.json +6 -9
|
@@ -3,11 +3,11 @@ import { blueAbi, erc2612Abi, fetchAccrualVault, metaMorphoAbi, } from "@morpho-
|
|
|
3
3
|
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual } from "viem";
|
|
5
5
|
import { multicall } from "viem/actions";
|
|
6
|
-
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature,
|
|
6
|
+
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
7
|
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
8
8
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
9
|
import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
10
|
-
import { AmountAndSharesExclusiveError,
|
|
10
|
+
import { AmountAndSharesExclusiveError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
|
|
11
11
|
import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
|
|
12
12
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
13
13
|
export class MorphoVaultV1 {
|
|
@@ -21,10 +21,7 @@ export class MorphoVaultV1 {
|
|
|
21
21
|
this.chainId = chainId;
|
|
22
22
|
}
|
|
23
23
|
async getData(parameters) {
|
|
24
|
-
|
|
25
|
-
this.client.viemClient.chain?.id !== this.chainId) {
|
|
26
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
27
|
-
}
|
|
24
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
28
25
|
return fetchAccrualVault(this.vault, this.client.viemClient, {
|
|
29
26
|
...parameters,
|
|
30
27
|
deployless: this.client.options.supportDeployless,
|
|
@@ -63,7 +60,6 @@ export class MorphoVaultV1 {
|
|
|
63
60
|
});
|
|
64
61
|
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
65
62
|
let pendingRequirements;
|
|
66
|
-
let expectedRequirement;
|
|
67
63
|
return Object.freeze({
|
|
68
64
|
getRequirements: async (requirementOptions) => {
|
|
69
65
|
const now = Time.timestamp();
|
|
@@ -71,33 +67,22 @@ export class MorphoVaultV1 {
|
|
|
71
67
|
throw new ExpiredDeadlineError(deadline, now);
|
|
72
68
|
if (pendingRequirements != null)
|
|
73
69
|
return await pendingRequirements;
|
|
74
|
-
// Memoize the in-flight promise
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
91
|
-
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
92
|
-
});
|
|
93
|
-
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
94
|
-
expectedRequirement =
|
|
95
|
-
signatureRequirement?.action.type === "permit" ||
|
|
96
|
-
signatureRequirement?.action.type === "permit2SignatureTransfer"
|
|
97
|
-
? signatureRequirement.action
|
|
98
|
-
: undefined;
|
|
99
|
-
return requirements;
|
|
100
|
-
})();
|
|
70
|
+
// Memoize the in-flight promise so concurrent callers share one round of
|
|
71
|
+
// allowance/nonce reads.
|
|
72
|
+
const pending = funding.value > 0n
|
|
73
|
+
? Promise.resolve([])
|
|
74
|
+
: getBundlesTokenRequirements(this.client.viemClient, {
|
|
75
|
+
token: vaultAsset,
|
|
76
|
+
spender,
|
|
77
|
+
amount: funding.assets,
|
|
78
|
+
owner: userAddress,
|
|
79
|
+
chainId: this.chainId,
|
|
80
|
+
deadline,
|
|
81
|
+
supportSignature: this.client.options.supportSignature,
|
|
82
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
83
|
+
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
84
|
+
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
85
|
+
});
|
|
101
86
|
pendingRequirements = pending;
|
|
102
87
|
try {
|
|
103
88
|
return await pending;
|
|
@@ -109,7 +94,8 @@ export class MorphoVaultV1 {
|
|
|
109
94
|
}
|
|
110
95
|
},
|
|
111
96
|
buildTx: (signatures) => {
|
|
112
|
-
|
|
97
|
+
// The pure deposit action rejects a token signature supplied alongside native funding.
|
|
98
|
+
const requirementSignature = selectBundlesTokenRequirementSignature(signatures, { spender, amount: funding.assets, deadline });
|
|
113
99
|
return vaultV1Deposit({
|
|
114
100
|
vault: {
|
|
115
101
|
chainId: this.chainId,
|
|
@@ -133,8 +119,11 @@ export class MorphoVaultV1 {
|
|
|
133
119
|
});
|
|
134
120
|
}
|
|
135
121
|
withdraw(params) {
|
|
136
|
-
const { amount, userAddress } = params;
|
|
122
|
+
const { amount, userAddress, vaultData } = params;
|
|
137
123
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
124
|
+
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
125
|
+
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
126
|
+
}
|
|
138
127
|
if (amount <= 0n)
|
|
139
128
|
throw new NonPositiveInputError("amount", amount);
|
|
140
129
|
// Reject values outside the ABI range before resolving any requirements.
|
|
@@ -150,11 +139,14 @@ export class MorphoVaultV1 {
|
|
|
150
139
|
});
|
|
151
140
|
const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
|
|
152
141
|
validateSlippageTolerance(slippageTolerance);
|
|
153
|
-
//
|
|
154
|
-
getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
142
|
+
// Resolve the spender eagerly so an unregistered VaultBundlesV1 fails at handle creation.
|
|
143
|
+
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
144
|
+
const requiredShareAllowance = computeVaultMaxShareAllowance({
|
|
145
|
+
vaultData,
|
|
146
|
+
deadline,
|
|
147
|
+
assets: amount,
|
|
148
|
+
slippageTolerance,
|
|
149
|
+
});
|
|
158
150
|
return Object.freeze({
|
|
159
151
|
getRequirements: async () => {
|
|
160
152
|
const now = Time.timestamp();
|
|
@@ -163,18 +155,9 @@ export class MorphoVaultV1 {
|
|
|
163
155
|
// Re-read the live share allowance on every call instead of caching the resolved
|
|
164
156
|
// requirements: the allowance is the sole cap on the burn, so a caller that executed the
|
|
165
157
|
// returned approval must see it satisfied on the next call, and an allowance revoked or
|
|
166
|
-
// raised afterwards must resurface as an outstanding requirement.
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
// fields only.
|
|
170
|
-
const vaultData = (vaultSnapshot ??= await this.getData());
|
|
171
|
-
requiredShareAllowance ??= computeVaultMaxShareAllowance({
|
|
172
|
-
vaultData,
|
|
173
|
-
deadline,
|
|
174
|
-
assets: amount,
|
|
175
|
-
slippageTolerance,
|
|
176
|
-
});
|
|
177
|
-
const requirements = await getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
158
|
+
// raised afterwards must resurface as an outstanding requirement. The cap derived from
|
|
159
|
+
// `vaultData` is pinned at handle creation, so re-reading cannot move it.
|
|
160
|
+
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
178
161
|
vaultData,
|
|
179
162
|
version: "vaultV1",
|
|
180
163
|
owner: userAddress,
|
|
@@ -183,16 +166,12 @@ export class MorphoVaultV1 {
|
|
|
183
166
|
deadline,
|
|
184
167
|
supportSignature: this.client.options.supportSignature,
|
|
185
168
|
});
|
|
186
|
-
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
187
|
-
if (signatureRequirement?.action.type === "permit") {
|
|
188
|
-
expectedRequirement = signatureRequirement.action;
|
|
189
|
-
}
|
|
190
|
-
return requirements;
|
|
191
169
|
},
|
|
192
170
|
buildTx: (signatures) => {
|
|
193
|
-
const permit =
|
|
194
|
-
|
|
195
|
-
|
|
171
|
+
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
172
|
+
spender,
|
|
173
|
+
amount: requiredShareAllowance,
|
|
174
|
+
deadline,
|
|
196
175
|
});
|
|
197
176
|
return vaultV1Withdraw({
|
|
198
177
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -224,14 +203,13 @@ export class MorphoVaultV1 {
|
|
|
224
203
|
referralFeePct: params.referralFeePct,
|
|
225
204
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
226
205
|
});
|
|
227
|
-
getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
228
|
-
let expectedRequirement;
|
|
206
|
+
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
229
207
|
return Object.freeze({
|
|
230
208
|
getRequirements: async () => {
|
|
231
209
|
const now = Time.timestamp();
|
|
232
210
|
if (deadline <= now)
|
|
233
211
|
throw new ExpiredDeadlineError(deadline, now);
|
|
234
|
-
|
|
212
|
+
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
235
213
|
vaultData: await this.getData(),
|
|
236
214
|
version: "vaultV1",
|
|
237
215
|
owner: userAddress,
|
|
@@ -240,17 +218,12 @@ export class MorphoVaultV1 {
|
|
|
240
218
|
deadline,
|
|
241
219
|
supportSignature: this.client.options.supportSignature,
|
|
242
220
|
});
|
|
243
|
-
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
244
|
-
expectedRequirement =
|
|
245
|
-
signatureRequirement?.action.type === "permit"
|
|
246
|
-
? signatureRequirement.action
|
|
247
|
-
: undefined;
|
|
248
|
-
return requirements;
|
|
249
221
|
},
|
|
250
222
|
buildTx: (signatures) => {
|
|
251
|
-
const permit =
|
|
252
|
-
|
|
253
|
-
|
|
223
|
+
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
224
|
+
spender,
|
|
225
|
+
amount: shares,
|
|
226
|
+
deadline,
|
|
254
227
|
});
|
|
255
228
|
return vaultV1Redeem({
|
|
256
229
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -493,7 +466,7 @@ export class MorphoVaultV1 {
|
|
|
493
466
|
assets: assets ?? 0n,
|
|
494
467
|
slippageTolerance,
|
|
495
468
|
});
|
|
496
|
-
getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
469
|
+
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
497
470
|
const { userAddress } = params;
|
|
498
471
|
const sourceAsset = params.sourceVault.asset;
|
|
499
472
|
const targetAddress = params.targetVault.address;
|
|
@@ -509,7 +482,6 @@ export class MorphoVaultV1 {
|
|
|
509
482
|
extensions: [...domain.extensions],
|
|
510
483
|
}),
|
|
511
484
|
});
|
|
512
|
-
let expectedRequirement;
|
|
513
485
|
return Object.freeze({
|
|
514
486
|
getRequirements: async () => {
|
|
515
487
|
const now = Time.timestamp();
|
|
@@ -521,7 +493,7 @@ export class MorphoVaultV1 {
|
|
|
521
493
|
// satisfied on the next call, and an allowance revoked or raised afterwards must resurface
|
|
522
494
|
// as an outstanding requirement. The pinned snapshot and the cap derived from it stay
|
|
523
495
|
// fixed, so re-reading cannot move the cap this handle already committed to.
|
|
524
|
-
|
|
496
|
+
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
525
497
|
vaultData: sourceToken,
|
|
526
498
|
version: "vaultV1",
|
|
527
499
|
owner: userAddress,
|
|
@@ -530,17 +502,12 @@ export class MorphoVaultV1 {
|
|
|
530
502
|
deadline,
|
|
531
503
|
supportSignature: this.client.options.supportSignature,
|
|
532
504
|
});
|
|
533
|
-
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
534
|
-
expectedRequirement =
|
|
535
|
-
signatureRequirement?.action.type === "permit"
|
|
536
|
-
? signatureRequirement.action
|
|
537
|
-
: undefined;
|
|
538
|
-
return requirements;
|
|
539
505
|
},
|
|
540
506
|
buildTx: (signatures) => {
|
|
541
|
-
const permit =
|
|
542
|
-
|
|
543
|
-
|
|
507
|
+
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
508
|
+
spender,
|
|
509
|
+
amount: requiredShareAllowance,
|
|
510
|
+
deadline,
|
|
544
511
|
});
|
|
545
512
|
return vaultV1MigrateToV2({
|
|
546
513
|
vault: {
|
|
@@ -11,6 +11,7 @@ export interface VaultV2Actions {
|
|
|
11
11
|
* @param {FetchParameters} [parameters] - The parameters for the fetch operation.
|
|
12
12
|
*
|
|
13
13
|
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>} The latest vault data.
|
|
14
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
|
|
14
15
|
*/
|
|
15
16
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
|
|
16
17
|
/**
|
|
@@ -21,7 +22,7 @@ export interface VaultV2Actions {
|
|
|
21
22
|
* Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
|
|
22
23
|
* always minted to the transaction sender, which must be `userAddress`.
|
|
23
24
|
* Concurrent requirement reads share the first caller's options; later calls refresh on-chain
|
|
24
|
-
* state using their own options.
|
|
25
|
+
* state using their own options.
|
|
25
26
|
*
|
|
26
27
|
* @param params.userAddress - Account that funds, signs, submits, and receives the vault shares.
|
|
27
28
|
* @param params.vaultData - Pre-fetched Vault V2 snapshot used for asset and share conversion.
|
|
@@ -57,8 +58,9 @@ export interface VaultV2Actions {
|
|
|
57
58
|
* `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
58
59
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
59
60
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
60
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature
|
|
61
|
-
* this
|
|
61
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
62
|
+
* deadline differ from this operation's, or when the signature's carried action nonce is
|
|
63
|
+
* inconsistent with its signed nonce.
|
|
62
64
|
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
63
65
|
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the vault asset.
|
|
64
66
|
* @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when signature metadata is malformed.
|
|
@@ -98,13 +100,14 @@ export interface VaultV2Actions {
|
|
|
98
100
|
/**
|
|
99
101
|
* Prepares an exact-assets Vault V2 withdrawal through VaultBundlesV1.
|
|
100
102
|
*
|
|
101
|
-
*
|
|
102
|
-
* vault-share allowance and, when a signature is needed, the permit nonce on
|
|
103
|
-
* Captures the requested amount and owner at creation, so later
|
|
104
|
-
* change this handle's requirements or transaction.
|
|
103
|
+
* Derives the share-burn cap from the supplied `vaultData` snapshot at handle creation, then
|
|
104
|
+
* reads the live vault-share allowance and, when a signature is needed, the permit nonce on
|
|
105
|
+
* each `getRequirements()` call. Captures the requested amount and owner at creation, so later
|
|
106
|
+
* changes to `params` do not change this handle's requirements or transaction.
|
|
105
107
|
*
|
|
106
108
|
* @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
|
|
107
109
|
* @param params.userAddress - Share owner that must sign and submit; receives the net assets.
|
|
110
|
+
* @param params.vaultData - Pre-fetched Vault V2 snapshot used to derive the share cap.
|
|
108
111
|
* @param params.slippageTolerance - Optional WAD-scaled share-price loss tolerance applied to
|
|
109
112
|
* the share cap.
|
|
110
113
|
* Defaults to 0.03% and cannot exceed 10%.
|
|
@@ -115,9 +118,13 @@ export interface VaultV2Actions {
|
|
|
115
118
|
* defaults to two hours from handle creation.
|
|
116
119
|
* @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
|
|
117
120
|
* which returns a deep-frozen `Transaction<VaultV2WithdrawAction>`. Requirements are empty
|
|
118
|
-
* when the allowance equals the cap;
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
+
* when the allowance equals the cap; an oversized allowance is always reset with an exact
|
|
122
|
+
* onchain approval, and an insufficient one is raised by an approval or, with signature
|
|
123
|
+
* support, an ERC-2612 request. The cap is fixed at handle creation while each call re-reads
|
|
124
|
+
* the allowance. Confirm the approval or pass its signed permit to `buildTx`.
|
|
125
|
+
* @remarks VaultBundlesV1 skips a share permit whose nonce was already consumed and proceeds
|
|
126
|
+
* under the live allowance, so execute every requirement returned by the latest
|
|
127
|
+
* `getRequirements()` — including the oversized-allowance reset — before submitting.
|
|
121
128
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
122
129
|
* @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
|
|
123
130
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
@@ -127,14 +134,14 @@ export interface VaultV2Actions {
|
|
|
127
134
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
128
135
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
129
136
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
|
|
137
|
+
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
130
138
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
131
139
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
132
140
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
133
141
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
|
|
134
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* @throws {viem.BaseError} when a vault, allowance, or nonce read or transaction encoding fails.
|
|
142
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed or
|
|
143
|
+
* its spender, amount or deadline differ from this operation's.
|
|
144
|
+
* @throws {viem.BaseError} when an allowance or nonce read or transaction encoding fails.
|
|
138
145
|
* @example
|
|
139
146
|
* ```ts
|
|
140
147
|
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
@@ -146,7 +153,8 @@ export interface VaultV2Actions {
|
|
|
146
153
|
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
147
154
|
* .extend(morphoViemExtension({ supportSignature: false }));
|
|
148
155
|
* const vault = client.morpho.vaultV2(vaultAddress, mainnet.id);
|
|
149
|
-
* const
|
|
156
|
+
* const vaultData = await vault.getData();
|
|
157
|
+
* const action = vault.withdraw({ amount: 1_000_000n, userAddress, vaultData });
|
|
150
158
|
* const requirements = await action.getRequirements();
|
|
151
159
|
* // Send and confirm each approval before calling action.buildTx().
|
|
152
160
|
* // action.buildTx() returns Readonly<Transaction<VaultV2WithdrawAction>>.
|
|
@@ -157,6 +165,7 @@ export interface VaultV2Actions {
|
|
|
157
165
|
withdraw: (params: {
|
|
158
166
|
readonly amount: bigint;
|
|
159
167
|
readonly userAddress: Address;
|
|
168
|
+
readonly vaultData: AccrualVaultV2;
|
|
160
169
|
readonly slippageTolerance?: bigint;
|
|
161
170
|
readonly referralFeePct?: bigint;
|
|
162
171
|
readonly referralFeeRecipient?: Address;
|
|
@@ -168,19 +177,19 @@ export interface VaultV2Actions {
|
|
|
168
177
|
* Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
|
|
169
178
|
* The caller must satisfy the exact vault-share allowance returned by `getRequirements()` before
|
|
170
179
|
* `buildTx()`; every requirement resolution re-reads the live allowance and checks the deadline.
|
|
171
|
-
* `buildTx()` accepts permits from the latest completed requirement resolution.
|
|
172
180
|
*
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
175
|
-
* @param
|
|
176
|
-
* @param
|
|
177
|
-
* @param
|
|
178
|
-
* @param
|
|
181
|
+
* @param params - The redeem parameters.
|
|
182
|
+
* @param params.shares - Exact vault shares to burn.
|
|
183
|
+
* @param params.userAddress - Account that must sign and submit the transaction; VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`.
|
|
184
|
+
* @param [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be below WAD.
|
|
185
|
+
* @param [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
|
|
186
|
+
* @param [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
|
|
179
187
|
* @returns Lazy exact share-allowance requirements and a synchronous transaction builder.
|
|
180
188
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
181
189
|
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
182
190
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
183
191
|
* requirement resolution.
|
|
192
|
+
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
184
193
|
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
185
194
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
186
195
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
@@ -189,8 +198,8 @@ export interface VaultV2Actions {
|
|
|
189
198
|
* @throws {viem.BaseError} from `getRequirements()` when an allowance or nonce read fails.
|
|
190
199
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
191
200
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
192
|
-
* @throws {BundlesPermitMismatchError} from `buildTx()` when the
|
|
193
|
-
*
|
|
201
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
202
|
+
* deadline differ from this operation's.
|
|
194
203
|
* @example
|
|
195
204
|
* ```ts
|
|
196
205
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -320,9 +329,11 @@ export interface VaultV2Actions {
|
|
|
320
329
|
* and permit nonce are read on-chain.
|
|
321
330
|
*
|
|
322
331
|
* The SDK derives a conservative lower bound on the realized exit share price from the snapshot
|
|
323
|
-
* and `slippageTolerance
|
|
324
|
-
*
|
|
325
|
-
*
|
|
332
|
+
* and `slippageTolerance`: the floor is priced off whichever of the raw snapshot or its accrual
|
|
333
|
+
* to `now` burns more shares, so neither pending fee mints nor interest the chain has not yet
|
|
334
|
+
* accrued can lift it above the realized price. A supplied `minSharePriceE27` replaces the
|
|
335
|
+
* tolerance-derived bound (it may be tighter or looser) but must be at least the floor derived
|
|
336
|
+
* at `MAX_SLIPPAGE_TOLERANCE`, so an override can never disable meaningful protection.
|
|
326
337
|
* The bound rejects a share price drop, a penalty increase, and liquidity shifting from the
|
|
327
338
|
* penalty-free leg to the penalised leg. It does **not** cover the referral fee, which the
|
|
328
339
|
* contract deducts afterwards.
|
|
@@ -332,16 +343,21 @@ export interface VaultV2Actions {
|
|
|
332
343
|
* send-shares gate is arbitrary code re-evaluated after each penalty burn. The SDK also does not
|
|
333
344
|
* validate the user's share balance. Per-market penalties and each vault withdrawal round the
|
|
334
345
|
* share burn up independently, so the exit can burn marginally more shares than `exitAssets` alone
|
|
335
|
-
* implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)`
|
|
336
|
-
*
|
|
337
|
-
*
|
|
346
|
+
* implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)` so a
|
|
347
|
+
* full-balance exit does not revert for insufficient shares. The approved share allowance this
|
|
348
|
+
* handle returns covers a burn at least one `slippageTolerance` step below the price floor
|
|
349
|
+
* whenever the floor exceeds one RAY unit and, in any case, at least one share above the burn
|
|
350
|
+
* at the floor, so a price within that headroom below the floor reverts on the contract's
|
|
351
|
+
* `minSharePriceE27` check rather than on the allowance; a deeper drop can still surface as an
|
|
352
|
+
* ERC-20 allowance underflow.
|
|
338
353
|
*
|
|
339
354
|
* Idle balance, penalty, adapter positions, and market liquidity can drift after the snapshot, so
|
|
340
355
|
* an on-chain revert remains possible if vault state changes between preparation and inclusion.
|
|
341
|
-
* A fee-recipient `userAddress` gets a floor from the
|
|
342
|
-
* and a guard against fee mints reaching the lower burn
|
|
343
|
-
* includes the projected fee shares through that same
|
|
344
|
-
* handle creation are rejected, so the guard and
|
|
356
|
+
* A fee-recipient `userAddress` gets a floor from the larger of the raw snapshot burn and the
|
|
357
|
+
* `now` burn net of its own fee mints, and a guard against fee mints reaching the lower burn
|
|
358
|
+
* bound by the deadline. Its allowance includes the projected fee shares through that same
|
|
359
|
+
* deadline. Deadlines beyond one year after handle creation are rejected, so the guard and
|
|
360
|
+
* allowance cover the whole accepted window.
|
|
345
361
|
*
|
|
346
362
|
* @param params - Force withdrawal parameters.
|
|
347
363
|
* @param params.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
|
|
@@ -396,7 +412,7 @@ export interface VaultV2Actions {
|
|
|
396
412
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
397
413
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender, amount, or
|
|
398
414
|
* deadline differs from this operation. Any handle built from the same inputs accepts the
|
|
399
|
-
* permit;
|
|
415
|
+
* permit; a permit whose nonce was consumed is skipped onchain and the live allowance applies.
|
|
400
416
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
401
417
|
* @example
|
|
402
418
|
* ```ts
|
|
@@ -486,6 +502,7 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
486
502
|
withdraw(params: {
|
|
487
503
|
readonly amount: bigint;
|
|
488
504
|
readonly userAddress: Address;
|
|
505
|
+
readonly vaultData: AccrualVaultV2;
|
|
489
506
|
readonly slippageTolerance?: bigint;
|
|
490
507
|
readonly referralFeePct?: bigint;
|
|
491
508
|
readonly referralFeeRecipient?: Address;
|