@morpho-org/morpho-sdk 1.2.1 → 2.1.1
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 +12 -11
- package/lib/cjs/actions/marketV1/repay.js +1 -1
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/marketV1/supplyCollateral.js +1 -1
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +4 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2.js +4 -7
- package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +32 -8
- package/lib/cjs/actions/requirements/getRequirementsAction.js +34 -12
- package/lib/cjs/actions/requirements/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/index.js +1 -0
- package/lib/cjs/actions/vaultV1/deposit.js +1 -1
- package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/cjs/actions/vaultV2/deposit.js +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +5 -4
- package/lib/cjs/client/morphoClient.d.ts +48 -9
- package/lib/cjs/client/morphoClient.js +48 -9
- package/lib/cjs/client/morphoViemExtension.d.ts +2 -2
- package/lib/cjs/client/morphoViemExtension.js +2 -2
- package/lib/cjs/entities/marketV1/marketV1.js +18 -17
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +6 -6
- package/lib/cjs/entities/vaultV1/vaultV1.js +14 -11
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +5 -5
- package/lib/cjs/entities/vaultV2/vaultV2.js +13 -8
- package/lib/cjs/helpers/computeReallocations.d.ts +1 -0
- package/lib/cjs/helpers/computeReallocations.js +15 -0
- package/lib/cjs/helpers/metadata.d.ts +10 -0
- package/lib/cjs/helpers/metadata.js +20 -1
- package/lib/cjs/helpers/validate.d.ts +10 -6
- package/lib/cjs/helpers/validate.js +13 -9
- package/lib/cjs/types/action.d.ts +3 -3
- package/lib/cjs/types/error.d.ts +24 -0
- package/lib/cjs/types/error.js +23 -1
- package/lib/esm/actions/marketV1/repay.js +1 -1
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/marketV1/supplyCollateral.js +1 -1
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -8
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.js +5 -8
- package/lib/esm/actions/requirements/getRequirementsAction.d.ts +32 -8
- package/lib/esm/actions/requirements/getRequirementsAction.js +35 -13
- package/lib/esm/actions/requirements/index.d.ts +1 -0
- package/lib/esm/actions/requirements/index.js +1 -0
- package/lib/esm/actions/vaultV1/deposit.js +1 -1
- package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/esm/actions/vaultV2/deposit.js +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +5 -4
- package/lib/esm/client/morphoClient.d.ts +48 -9
- package/lib/esm/client/morphoClient.js +48 -9
- package/lib/esm/client/morphoViemExtension.d.ts +2 -2
- package/lib/esm/client/morphoViemExtension.js +2 -2
- package/lib/esm/entities/marketV1/marketV1.js +19 -18
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +6 -6
- package/lib/esm/entities/vaultV1/vaultV1.js +15 -12
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +5 -5
- package/lib/esm/entities/vaultV2/vaultV2.js +13 -8
- package/lib/esm/helpers/computeReallocations.d.ts +1 -0
- package/lib/esm/helpers/computeReallocations.js +16 -1
- package/lib/esm/helpers/metadata.d.ts +10 -0
- package/lib/esm/helpers/metadata.js +20 -1
- package/lib/esm/helpers/validate.d.ts +10 -6
- package/lib/esm/helpers/validate.js +11 -7
- package/lib/esm/types/action.d.ts +3 -3
- package/lib/esm/types/error.d.ts +24 -0
- package/lib/esm/types/error.js +20 -0
- package/package.json +12 -12
|
@@ -3,7 +3,7 @@ import { fetchAccrualPosition, fetchHolding, fetchMarket, fetchPosition, fetchVa
|
|
|
3
3
|
import { Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { SimulationState } from "@morpho-org/simulation-sdk";
|
|
5
5
|
import { getMorphoAuthorizationRequirement, getRequirements, marketV1Borrow, marketV1Repay, marketV1RepayWithdrawCollateral, marketV1SupplyCollateral, marketV1SupplyCollateralBorrow, marketV1WithdrawCollateral, } from "../../actions/index.js";
|
|
6
|
-
import { computeMaxRepaySharePrice, computeMinBorrowSharePrice, computeReallocations, validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance,
|
|
6
|
+
import { computeMaxRepaySharePrice, computeMinBorrowSharePrice, computeReallocations, validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
7
7
|
import { MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, NegativeNativeAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveRepayAmountError, NonPositiveWithdrawCollateralAmountError, WithdrawExceedsCollateralError, ZeroCollateralAmountError, } from "../../types/index.js";
|
|
8
8
|
export class MorphoMarketV1 {
|
|
9
9
|
client;
|
|
@@ -33,7 +33,6 @@ export class MorphoMarketV1 {
|
|
|
33
33
|
}
|
|
34
34
|
supplyCollateral({ amount = 0n, userAddress, nativeAmount, }) {
|
|
35
35
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
36
|
-
validateUserAddress(this.client.viemClient.account?.address, userAddress);
|
|
37
36
|
if (amount < 0n) {
|
|
38
37
|
throw new NonPositiveAssetAmountError(this.marketParams.collateralToken);
|
|
39
38
|
}
|
|
@@ -73,7 +72,6 @@ export class MorphoMarketV1 {
|
|
|
73
72
|
}
|
|
74
73
|
borrow({ amount, userAddress, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
75
74
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
76
|
-
validateUserAddress(this.client.viemClient.account?.address, userAddress);
|
|
77
75
|
if (amount <= 0n) {
|
|
78
76
|
throw new NonPositiveBorrowAmountError(this.marketParams.id);
|
|
79
77
|
}
|
|
@@ -124,7 +122,6 @@ export class MorphoMarketV1 {
|
|
|
124
122
|
}
|
|
125
123
|
repay(params) {
|
|
126
124
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
127
|
-
validateUserAddress(this.client.viemClient.account?.address, params.userAddress);
|
|
128
125
|
const { userAddress, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, } = params;
|
|
129
126
|
if ("assets" in params && "shares" in params) {
|
|
130
127
|
throw new MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
@@ -152,6 +149,7 @@ export class MorphoMarketV1 {
|
|
|
152
149
|
let assets;
|
|
153
150
|
let shares;
|
|
154
151
|
let transferAmount;
|
|
152
|
+
let marketForRepay;
|
|
155
153
|
if (isSharesMode) {
|
|
156
154
|
validateRepayShares({
|
|
157
155
|
positionData,
|
|
@@ -160,10 +158,12 @@ export class MorphoMarketV1 {
|
|
|
160
158
|
});
|
|
161
159
|
assets = 0n;
|
|
162
160
|
shares = params.shares;
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
const
|
|
166
|
-
|
|
161
|
+
// 2h forward accrual upper-bounds the on-chain repay price; bundle
|
|
162
|
+
// skims residual back to the receiver.
|
|
163
|
+
const accrualTimestamp = MathLib.max(Time.timestamp(), positionData.market.lastUpdate) +
|
|
164
|
+
Time.s.from.h(2n);
|
|
165
|
+
marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
166
|
+
transferAmount = marketForRepay.toBorrowAssets(shares, "Up");
|
|
167
167
|
}
|
|
168
168
|
else {
|
|
169
169
|
validateRepayAmount({
|
|
@@ -174,11 +174,12 @@ export class MorphoMarketV1 {
|
|
|
174
174
|
assets = params.assets;
|
|
175
175
|
shares = 0n;
|
|
176
176
|
transferAmount = params.assets;
|
|
177
|
+
marketForRepay = positionData.market;
|
|
177
178
|
}
|
|
178
179
|
const maxSharePrice = computeMaxRepaySharePrice({
|
|
179
180
|
repayAssets: assets,
|
|
180
181
|
repayShares: shares,
|
|
181
|
-
market:
|
|
182
|
+
market: marketForRepay,
|
|
182
183
|
slippageTolerance,
|
|
183
184
|
});
|
|
184
185
|
return {
|
|
@@ -210,7 +211,6 @@ export class MorphoMarketV1 {
|
|
|
210
211
|
}
|
|
211
212
|
withdrawCollateral({ userAddress, amount, positionData, }) {
|
|
212
213
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
213
|
-
validateUserAddress(this.client.viemClient.account?.address, userAddress);
|
|
214
214
|
if (amount <= 0n) {
|
|
215
215
|
throw new NonPositiveWithdrawCollateralAmountError(this.marketParams.id);
|
|
216
216
|
}
|
|
@@ -252,7 +252,6 @@ export class MorphoMarketV1 {
|
|
|
252
252
|
}
|
|
253
253
|
repayWithdrawCollateral(params) {
|
|
254
254
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
255
|
-
validateUserAddress(this.client.viemClient.account?.address, params.userAddress);
|
|
256
255
|
const { userAddress, withdrawAmount, positionData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, } = params;
|
|
257
256
|
if ("assets" in params && "shares" in params) {
|
|
258
257
|
throw new MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
@@ -283,6 +282,11 @@ export class MorphoMarketV1 {
|
|
|
283
282
|
let assets;
|
|
284
283
|
let shares;
|
|
285
284
|
let transferAmount;
|
|
285
|
+
let marketForRepay;
|
|
286
|
+
// 2h forward accrual upper-bounds the on-chain repay price (shares
|
|
287
|
+
// mode) and the post-repay health check; bundle skims residual back.
|
|
288
|
+
const accrualTimestamp = MathLib.max(Time.timestamp(), positionData.market.lastUpdate) +
|
|
289
|
+
Time.s.from.h(2n);
|
|
286
290
|
if (isSharesMode) {
|
|
287
291
|
validateRepayShares({
|
|
288
292
|
positionData,
|
|
@@ -291,8 +295,8 @@ export class MorphoMarketV1 {
|
|
|
291
295
|
});
|
|
292
296
|
assets = 0n;
|
|
293
297
|
shares = params.shares;
|
|
294
|
-
|
|
295
|
-
transferAmount =
|
|
298
|
+
marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
299
|
+
transferAmount = marketForRepay.toBorrowAssets(shares, "Up");
|
|
296
300
|
}
|
|
297
301
|
else {
|
|
298
302
|
validateRepayAmount({
|
|
@@ -303,6 +307,7 @@ export class MorphoMarketV1 {
|
|
|
303
307
|
assets = params.assets;
|
|
304
308
|
shares = 0n;
|
|
305
309
|
transferAmount = params.assets;
|
|
310
|
+
marketForRepay = positionData.market;
|
|
306
311
|
}
|
|
307
312
|
if (withdrawAmount > positionData.collateral) {
|
|
308
313
|
throw new WithdrawExceedsCollateralError({
|
|
@@ -311,9 +316,6 @@ export class MorphoMarketV1 {
|
|
|
311
316
|
market: positionData.marketId,
|
|
312
317
|
});
|
|
313
318
|
}
|
|
314
|
-
// +10 min accrual buffer: residual debt grows between build and execute.
|
|
315
|
-
const accrualTimestamp = MathLib.max(Time.timestamp(), positionData.market.lastUpdate) +
|
|
316
|
-
Time.s.from.min(10n);
|
|
317
319
|
const { position: positionAfterRepay } = positionData.repay(assets, shares, accrualTimestamp);
|
|
318
320
|
validatePositionHealthAfterWithdraw({
|
|
319
321
|
positionData: positionAfterRepay,
|
|
@@ -324,7 +326,7 @@ export class MorphoMarketV1 {
|
|
|
324
326
|
const maxSharePrice = computeMaxRepaySharePrice({
|
|
325
327
|
repayAssets: assets,
|
|
326
328
|
repayShares: shares,
|
|
327
|
-
market:
|
|
329
|
+
market: marketForRepay,
|
|
328
330
|
slippageTolerance,
|
|
329
331
|
});
|
|
330
332
|
return {
|
|
@@ -367,7 +369,6 @@ export class MorphoMarketV1 {
|
|
|
367
369
|
}
|
|
368
370
|
supplyCollateralBorrow({ amount = 0n, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, reallocations, }) {
|
|
369
371
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
370
|
-
validateUserAddress(this.client.viemClient.account?.address, userAddress);
|
|
371
372
|
if (amount < 0n) {
|
|
372
373
|
throw new NonPositiveAssetAmountError(this.marketParams.collateralToken);
|
|
373
374
|
}
|
|
@@ -8,26 +8,26 @@ export interface VaultV1Actions {
|
|
|
8
8
|
* Fetches the latest vault data with accrued interest.
|
|
9
9
|
*
|
|
10
10
|
* @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
|
|
11
|
-
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The latest
|
|
11
|
+
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The latest vault data.
|
|
12
12
|
*/
|
|
13
13
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
|
|
14
14
|
/**
|
|
15
15
|
* Prepares a deposit into a VaultV1 (MetaMorpho) contract.
|
|
16
16
|
*
|
|
17
|
-
* Uses pre-fetched
|
|
17
|
+
* Uses pre-fetched vault data to compute `maxSharePrice` with slippage tolerance,
|
|
18
18
|
* then returns `buildTx` and `getRequirements` for lazy evaluation.
|
|
19
19
|
*
|
|
20
20
|
* @param {Object} params - The deposit parameters.
|
|
21
21
|
* @param {bigint} params.amount - Amount of assets to deposit.
|
|
22
22
|
* @param {Address} params.userAddress - User address initiating the deposit.
|
|
23
|
-
* @param {AccrualVault} params.
|
|
23
|
+
* @param {AccrualVault} params.vaultData - Pre-fetched vault data with asset address and share conversion.
|
|
24
24
|
* @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Slippage tolerance (default 0.03%, max 10%).
|
|
25
25
|
* @param {bigint} [params.nativeAmount] - Amount of native ETH to wrap into WETH. Vault asset must be wNative.
|
|
26
26
|
* @returns {Object} Object with `buildTx` and `getRequirements`.
|
|
27
27
|
*/
|
|
28
28
|
deposit: (params: {
|
|
29
29
|
userAddress: Address;
|
|
30
|
-
|
|
30
|
+
vaultData: AccrualVault;
|
|
31
31
|
slippageTolerance?: bigint;
|
|
32
32
|
} & DepositAmountArgs) => {
|
|
33
33
|
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV1DepositAction>>;
|
|
@@ -94,9 +94,9 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
94
94
|
private readonly chainId;
|
|
95
95
|
constructor(client: MorphoClientType, vault: Address, chainId: number);
|
|
96
96
|
getData(parameters?: FetchParameters): Promise<AccrualVault>;
|
|
97
|
-
deposit({ amount, userAddress,
|
|
97
|
+
deposit({ amount, userAddress, vaultData, slippageTolerance, nativeAmount, }: {
|
|
98
98
|
userAddress: Address;
|
|
99
|
-
|
|
99
|
+
vaultData: AccrualVault;
|
|
100
100
|
slippageTolerance?: bigint;
|
|
101
101
|
} & DepositAmountArgs): {
|
|
102
102
|
getRequirements: (params?: {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
3
4
|
import { isAddressEqual } from "viem";
|
|
4
5
|
import { getRequirements, vaultV1Deposit, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
5
6
|
import { MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, } from "../../helpers/constant.js";
|
|
6
|
-
import { validateChainId
|
|
7
|
+
import { validateChainId } from "../../helpers/index.js";
|
|
7
8
|
import { ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NegativeSlippageToleranceError, NonPositiveAssetAmountError, NonPositiveSharesAmountError, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
8
9
|
export class MorphoVaultV1 {
|
|
9
10
|
client;
|
|
@@ -26,12 +27,12 @@ export class MorphoVaultV1 {
|
|
|
26
27
|
deployless: this.client.options.supportDeployless,
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
|
-
deposit({ amount = 0n, userAddress,
|
|
30
|
+
deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
|
|
30
31
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
31
32
|
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
32
33
|
}
|
|
33
|
-
if (!isAddressEqual(
|
|
34
|
-
throw new VaultAddressMismatchError(this.vault,
|
|
34
|
+
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
35
|
+
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
35
36
|
}
|
|
36
37
|
if (amount < 0n) {
|
|
37
38
|
throw new NonPositiveAssetAmountError(this.vault);
|
|
@@ -53,19 +54,19 @@ export class MorphoVaultV1 {
|
|
|
53
54
|
throw new ExcessiveSlippageToleranceError(slippageTolerance);
|
|
54
55
|
}
|
|
55
56
|
if (nativeAmount && wNative) {
|
|
56
|
-
if (!isAddressEqual(
|
|
57
|
-
throw new NativeAmountOnNonWNativeVaultError(
|
|
57
|
+
if (!isAddressEqual(vaultData.asset, wNative)) {
|
|
58
|
+
throw new NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
61
|
-
const shares =
|
|
62
|
+
const shares = vaultData.toShares(totalAssets);
|
|
62
63
|
if (shares <= 0n) {
|
|
63
64
|
throw new NonPositiveSharesAmountError(this.vault);
|
|
64
65
|
}
|
|
65
66
|
const maxSharePrice = MathLib.min(MathLib.mulDivUp(totalAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), shares), MAX_ABSOLUTE_SHARE_PRICE);
|
|
66
67
|
return {
|
|
67
68
|
getRequirements: async (params) => await getRequirements(this.client.viemClient, {
|
|
68
|
-
address:
|
|
69
|
+
address: vaultData.asset,
|
|
69
70
|
chainId: this.chainId,
|
|
70
71
|
supportSignature: this.client.options.supportSignature,
|
|
71
72
|
supportDeployless: this.client.options.supportDeployless,
|
|
@@ -79,7 +80,7 @@ export class MorphoVaultV1 {
|
|
|
79
80
|
vault: {
|
|
80
81
|
chainId: this.chainId,
|
|
81
82
|
address: this.vault,
|
|
82
|
-
asset:
|
|
83
|
+
asset: vaultData.asset,
|
|
83
84
|
},
|
|
84
85
|
args: {
|
|
85
86
|
amount,
|
|
@@ -126,7 +127,6 @@ export class MorphoVaultV1 {
|
|
|
126
127
|
}
|
|
127
128
|
migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, }) {
|
|
128
129
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
129
|
-
validateUserAddress(this.client.viemClient.account?.address, userAddress);
|
|
130
130
|
if (!isAddressEqual(sourceVault.address, this.vault)) {
|
|
131
131
|
throw new VaultAddressMismatchError(this.vault, sourceVault.address);
|
|
132
132
|
}
|
|
@@ -145,8 +145,11 @@ export class MorphoVaultV1 {
|
|
|
145
145
|
// Compute minSharePriceVaultV1 for V1 redeem (slippage downward)
|
|
146
146
|
const v1RefAssets = sourceVault.toAssets(shares);
|
|
147
147
|
const minSharePriceVaultV1 = MathLib.mulDivDown(v1RefAssets, MathLib.wToRay(MathLib.WAD - slippageTolerance), shares);
|
|
148
|
-
// Compute maxSharePriceVaultV2 for V2 deposit (slippage upward)
|
|
149
|
-
|
|
148
|
+
// Compute maxSharePriceVaultV2 for V2 deposit (slippage upward).
|
|
149
|
+
// Accrue VaultV2 interest forward to bound the on-chain share price at execution.
|
|
150
|
+
const targetAccrualTimestamp = MathLib.max(Time.timestamp(), targetVault.lastUpdate) + Time.s.from.h(2n);
|
|
151
|
+
const { vault: accruedTargetVault } = targetVault.accrueInterest(targetAccrualTimestamp);
|
|
152
|
+
const v2RefShares = accruedTargetVault.toShares(v1RefAssets);
|
|
150
153
|
if (v2RefShares <= 0n) {
|
|
151
154
|
throw new NonPositiveSharesAmountError(targetVault.address);
|
|
152
155
|
}
|
|
@@ -17,14 +17,14 @@ export interface VaultV2Actions {
|
|
|
17
17
|
* Prepares a deposit transaction for the VaultV2 contract.
|
|
18
18
|
*
|
|
19
19
|
* This function constructs the transaction data required to deposit a specified amount of assets into the vault.
|
|
20
|
-
* Uses pre-fetched
|
|
20
|
+
* Uses pre-fetched vault data for accurate calculations of slippage and asset address,
|
|
21
21
|
* then returns the prepared deposit transaction and a function for retrieving all required approval transactions.
|
|
22
22
|
* Bundler Integration: This flow uses the bundler to atomically execute the user's asset transfer and vault deposit in a single transaction for slippage protection.
|
|
23
23
|
*
|
|
24
24
|
* @param {Object} params - The deposit parameters.
|
|
25
25
|
* @param {bigint} [params.amount=0n] - Amount of ERC-20 assets to deposit. At least one of amount or nativeAmount must be provided.
|
|
26
26
|
* @param {Address} params.userAddress - User address initiating the deposit.
|
|
27
|
-
* @param {AccrualVaultV2} params.
|
|
27
|
+
* @param {AccrualVaultV2} params.vaultData - Pre-fetched vault data with asset address and share conversion.
|
|
28
28
|
* @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Optional slippage tolerance value. Default is 0.03%. Slippage tolerance must be less than 10%.
|
|
29
29
|
* @param {bigint} [params.nativeAmount] - Amount of native token to wrap into wNative. Vault asset must be wNative.
|
|
30
30
|
* @returns {Object} The result object.
|
|
@@ -33,7 +33,7 @@ export interface VaultV2Actions {
|
|
|
33
33
|
*/
|
|
34
34
|
deposit: (params: {
|
|
35
35
|
userAddress: Address;
|
|
36
|
-
|
|
36
|
+
vaultData: AccrualVaultV2;
|
|
37
37
|
slippageTolerance?: bigint;
|
|
38
38
|
} & DepositAmountArgs) => {
|
|
39
39
|
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
@@ -137,9 +137,9 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
137
137
|
private readonly chainId;
|
|
138
138
|
constructor(client: MorphoClientType, vault: Address, chainId: number);
|
|
139
139
|
getData(parameters?: FetchParameters): Promise<AccrualVaultV2>;
|
|
140
|
-
deposit({ amount, userAddress,
|
|
140
|
+
deposit({ amount, userAddress, vaultData, slippageTolerance, nativeAmount, }: {
|
|
141
141
|
userAddress: Address;
|
|
142
|
-
|
|
142
|
+
vaultData: AccrualVaultV2;
|
|
143
143
|
slippageTolerance?: bigint;
|
|
144
144
|
} & DepositAmountArgs): {
|
|
145
145
|
getRequirements: (params?: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
3
4
|
import { isAddressEqual } from "viem";
|
|
4
5
|
import { getRequirements, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
|
|
5
6
|
import { MAX_SLIPPAGE_TOLERANCE } from "../../helpers/constant.js";
|
|
@@ -25,12 +26,12 @@ export class MorphoVaultV2 {
|
|
|
25
26
|
deployless: this.client.options.supportDeployless,
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
|
-
deposit({ amount = 0n, userAddress,
|
|
29
|
+
deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
|
|
29
30
|
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
30
31
|
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
31
32
|
}
|
|
32
|
-
if (!isAddressEqual(
|
|
33
|
-
throw new VaultAddressMismatchError(this.vault,
|
|
33
|
+
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
34
|
+
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
34
35
|
}
|
|
35
36
|
if (amount < 0n) {
|
|
36
37
|
throw new NonPositiveAssetAmountError(this.vault);
|
|
@@ -52,19 +53,23 @@ export class MorphoVaultV2 {
|
|
|
52
53
|
throw new ExcessiveSlippageToleranceError(slippageTolerance);
|
|
53
54
|
}
|
|
54
55
|
if (nativeAmount && wNative) {
|
|
55
|
-
if (!isAddressEqual(
|
|
56
|
-
throw new NativeAmountOnNonWNativeVaultError(
|
|
56
|
+
if (!isAddressEqual(vaultData.asset, wNative)) {
|
|
57
|
+
throw new NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
60
|
-
|
|
61
|
+
// Accrue interest forward to bound the on-chain share price at execution.
|
|
62
|
+
// Mirrors marketV1 repay's 2h forward-accrual buffer.
|
|
63
|
+
const accrualTimestamp = MathLib.max(Time.timestamp(), vaultData.lastUpdate) + Time.s.from.h(2n);
|
|
64
|
+
const { vault: accruedVault } = vaultData.accrueInterest(accrualTimestamp);
|
|
65
|
+
const shares = accruedVault.toShares(totalAssets);
|
|
61
66
|
if (shares <= 0n) {
|
|
62
67
|
throw new NonPositiveSharesAmountError(this.vault);
|
|
63
68
|
}
|
|
64
69
|
const maxSharePrice = MathLib.min(MathLib.mulDivUp(totalAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), shares), MathLib.RAY * 100n);
|
|
65
70
|
return {
|
|
66
71
|
getRequirements: async (params) => await getRequirements(this.client.viemClient, {
|
|
67
|
-
address:
|
|
72
|
+
address: vaultData.asset,
|
|
68
73
|
chainId: this.chainId,
|
|
69
74
|
supportSignature: this.client.options.supportSignature,
|
|
70
75
|
supportDeployless: this.client.options.supportDeployless,
|
|
@@ -78,7 +83,7 @@ export class MorphoVaultV2 {
|
|
|
78
83
|
vault: {
|
|
79
84
|
chainId: this.chainId,
|
|
80
85
|
address: this.vault,
|
|
81
|
-
asset:
|
|
86
|
+
asset: vaultData.asset,
|
|
82
87
|
},
|
|
83
88
|
args: {
|
|
84
89
|
amount,
|
|
@@ -14,6 +14,7 @@ import { type ReallocationComputeOptions, type VaultReallocation } from "../type
|
|
|
14
14
|
* @param params.borrowAmount - The intended borrow amount (used to compute post-borrow utilization).
|
|
15
15
|
* @param params.options - Optional reallocation computation options.
|
|
16
16
|
* @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
|
|
17
|
+
* @throws {InsufficientSharedLiquidityError} If shared liquidity cannot cover the borrow shortfall on the target market — preventing fee-bearing reallocations from being attached to a borrow that would still revert onchain.
|
|
17
18
|
*/
|
|
18
19
|
export declare const computeReallocations: ({ reallocationData: data, marketId, borrowAmount, options, }: {
|
|
19
20
|
readonly reallocationData: SimulationState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MarketUtils, MathLib } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { DEFAULT_SUPPLY_TARGET_UTILIZATION } from "@morpho-org/bundler-sdk-viem";
|
|
3
|
-
import { MissingPublicAllocatorConfigError, } from "../types/index.js";
|
|
3
|
+
import { InsufficientSharedLiquidityError, MissingPublicAllocatorConfigError, } from "../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Computes vault reallocations for a borrow operation on a target market.
|
|
6
6
|
*
|
|
@@ -14,6 +14,7 @@ import { MissingPublicAllocatorConfigError, } from "../types/index.js";
|
|
|
14
14
|
* @param params.borrowAmount - The intended borrow amount (used to compute post-borrow utilization).
|
|
15
15
|
* @param params.options - Optional reallocation computation options.
|
|
16
16
|
* @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
|
|
17
|
+
* @throws {InsufficientSharedLiquidityError} If shared liquidity cannot cover the borrow shortfall on the target market — preventing fee-bearing reallocations from being attached to a borrow that would still revert onchain.
|
|
17
18
|
*/
|
|
18
19
|
export const computeReallocations = ({ reallocationData: data, marketId, borrowAmount, options, }) => {
|
|
19
20
|
if (options?.enabled === false)
|
|
@@ -50,8 +51,13 @@ export const computeReallocations = ({ reallocationData: data, marketId, borrowA
|
|
|
50
51
|
}
|
|
51
52
|
if (requiredAssets <= 0n)
|
|
52
53
|
return [];
|
|
54
|
+
// Liquidity strictly required for `morphoBorrow` to succeed onchain.
|
|
55
|
+
const absoluteShortfall = newTotalBorrowAssets > newTotalSupplyAssets
|
|
56
|
+
? newTotalBorrowAssets - newTotalSupplyAssets
|
|
57
|
+
: 0n;
|
|
53
58
|
// Group withdrawals by vault, capping total at requiredAssets.
|
|
54
59
|
const reallocationsMap = {};
|
|
60
|
+
let totalReallocated = 0n;
|
|
55
61
|
for (const { vault, ...withdrawal } of withdrawals) {
|
|
56
62
|
const vaultReallocations = (reallocationsMap[vault] ??= []);
|
|
57
63
|
const existing = vaultReallocations.find((item) => item.id === withdrawal.id);
|
|
@@ -68,9 +74,18 @@ export const computeReallocations = ({ reallocationData: data, marketId, borrowA
|
|
|
68
74
|
});
|
|
69
75
|
}
|
|
70
76
|
requiredAssets -= reallocatedAssets;
|
|
77
|
+
totalReallocated += reallocatedAssets;
|
|
71
78
|
if (requiredAssets === 0n)
|
|
72
79
|
break;
|
|
73
80
|
}
|
|
81
|
+
// Refuse fee-bearing partial plans for an unreachable borrow.
|
|
82
|
+
if (totalReallocated < absoluteShortfall) {
|
|
83
|
+
throw new InsufficientSharedLiquidityError({
|
|
84
|
+
marketId,
|
|
85
|
+
shortfall: absoluteShortfall,
|
|
86
|
+
available: totalReallocated,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
74
89
|
// Transform into VaultReallocation[] format.
|
|
75
90
|
return Object.entries(reallocationsMap)
|
|
76
91
|
.filter(([, vaultWithdrawals]) => vaultWithdrawals.length > 0)
|
|
@@ -9,6 +9,16 @@ import type { Metadata } from "../types/index.js";
|
|
|
9
9
|
* The function ensures that the transaction data is correctly formatted
|
|
10
10
|
* and includes optional metadata elements if provided.
|
|
11
11
|
*
|
|
12
|
+
* `metadata.origin` accepts either a raw hex string (`"cafe"`) or a
|
|
13
|
+
* 0x-prefixed hex string (`"0xcafe"` / `"0Xcafe"`); both produce the same
|
|
14
|
+
* appended 4-byte origin tag. The 0x/0X prefix is stripped case-insensitively
|
|
15
|
+
* before length-validation, so an origin of `"0xdeadbeef"` (10 chars
|
|
16
|
+
* including prefix, 8 raw hex chars) is accepted while `"0xdeadbeef00"`
|
|
17
|
+
* (10 raw hex chars) is rejected and a warning is logged. Odd-length raw
|
|
18
|
+
* fragments (e.g. `"abc"`, `"0xabc"`) are also rejected — concatenating
|
|
19
|
+
* a non-byte-aligned fragment would corrupt the trailing analytics byte
|
|
20
|
+
* once viem's `concatHex` pads it to a whole byte at broadcast time.
|
|
21
|
+
*
|
|
12
22
|
* @param {Object} tx - The original transaction object.
|
|
13
23
|
* @param {Hex} tx.data - The existing hex-encoded data for the transaction.
|
|
14
24
|
* @param {bigint} tx.value - The value to be sent with the transaction.
|
|
@@ -9,6 +9,16 @@ import { concatHex, isHex, numberToHex } from "viem";
|
|
|
9
9
|
* The function ensures that the transaction data is correctly formatted
|
|
10
10
|
* and includes optional metadata elements if provided.
|
|
11
11
|
*
|
|
12
|
+
* `metadata.origin` accepts either a raw hex string (`"cafe"`) or a
|
|
13
|
+
* 0x-prefixed hex string (`"0xcafe"` / `"0Xcafe"`); both produce the same
|
|
14
|
+
* appended 4-byte origin tag. The 0x/0X prefix is stripped case-insensitively
|
|
15
|
+
* before length-validation, so an origin of `"0xdeadbeef"` (10 chars
|
|
16
|
+
* including prefix, 8 raw hex chars) is accepted while `"0xdeadbeef00"`
|
|
17
|
+
* (10 raw hex chars) is rejected and a warning is logged. Odd-length raw
|
|
18
|
+
* fragments (e.g. `"abc"`, `"0xabc"`) are also rejected — concatenating
|
|
19
|
+
* a non-byte-aligned fragment would corrupt the trailing analytics byte
|
|
20
|
+
* once viem's `concatHex` pads it to a whole byte at broadcast time.
|
|
21
|
+
*
|
|
12
22
|
* @param {Object} tx - The original transaction object.
|
|
13
23
|
* @param {Hex} tx.data - The existing hex-encoded data for the transaction.
|
|
14
24
|
* @param {bigint} tx.value - The value to be sent with the transaction.
|
|
@@ -31,11 +41,20 @@ export function addTransactionMetadata(tx, metadata) {
|
|
|
31
41
|
concatItems.push(numberToHex(Time.timestamp(), { size: 4 }));
|
|
32
42
|
}
|
|
33
43
|
try {
|
|
34
|
-
|
|
44
|
+
// Strip a leading "0x" / "0X" case-insensitively so callers can pass
|
|
45
|
+
// "cafe", "0xcafe", or "0Xcafe" — all produce the same 4-byte appended
|
|
46
|
+
// origin. The case-insensitive form prevents "0Xcafe" from falling
|
|
47
|
+
// through to `isHex("0x0Xcafe")` and being silently dropped.
|
|
48
|
+
const origin = metadata.origin.replace(/^0x/i, "");
|
|
35
49
|
if (!isHex(`0x${origin}`))
|
|
36
50
|
throw Error("Calldata origin must consists of only hex characters");
|
|
37
51
|
if (origin.length > 8)
|
|
38
52
|
throw Error("Calldata origin must be at most 8 characters long");
|
|
53
|
+
// Reject odd-length raw fragments. viem's `concatHex` would pad the
|
|
54
|
+
// stray nibble to a whole byte at broadcast, corrupting the trailing
|
|
55
|
+
// analytics byte on-chain.
|
|
56
|
+
if (origin.length % 2 !== 0)
|
|
57
|
+
throw Error("Calldata origin must have an even number of hex characters");
|
|
39
58
|
concatItems.push(`0x${origin}`);
|
|
40
59
|
}
|
|
41
60
|
catch (error) {
|
|
@@ -2,13 +2,17 @@ import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { type Address } from "viem";
|
|
3
3
|
import { type VaultReallocation } from "../types/index.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Asserts that the client has a connected account AND that it matches
|
|
6
6
|
* the provided user address.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Used internally by the signature requirements (`encodeErc20Permit`,
|
|
9
|
+
* `encodeErc20Permit2`) to enforce builder = signer at `sign()` time:
|
|
10
|
+
* the signing flow is the only path where an account/address mismatch
|
|
11
|
+
* is a real security concern (rather than just an integrator footgun).
|
|
12
|
+
*
|
|
13
|
+
* Transaction builders no longer call this helper — callers are
|
|
14
|
+
* responsible for keeping `userAddress` aligned with the signing account
|
|
15
|
+
* at the builder layer.
|
|
12
16
|
*
|
|
13
17
|
* Throws {@link MissingClientPropertyError} if the client has no account.
|
|
14
18
|
* Throws {@link AddressMismatchError} if the client account differs from
|
|
@@ -18,7 +22,7 @@ import { type VaultReallocation } from "../types/index.js";
|
|
|
18
22
|
* `MissingClientPropertyError` is thrown.
|
|
19
23
|
* @param userAddress - The user address provided by the caller.
|
|
20
24
|
*/
|
|
21
|
-
export declare
|
|
25
|
+
export declare function validateUserAddress(clientAccountAddress: Address | undefined, userAddress: Address): asserts clientAccountAddress is Address;
|
|
22
26
|
/**
|
|
23
27
|
* Validates that the accrual position belongs to the expected market and user.
|
|
24
28
|
* Throws {@link MarketIdMismatchError} if the position's market ID
|
|
@@ -4,13 +4,17 @@ import { isAddressEqual } from "viem";
|
|
|
4
4
|
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, MutuallyExclusiveRepayAmountsError, NativeAmountOnNonWNativeCollateralError, NegativeReallocationFeeError, NegativeSlippageToleranceError, NonPositiveReallocationAmountError, NonPositiveRepayAmountError, NonPositiveRepayMaxSharePriceError, NonPositiveTransferAmountError, ReallocationWithdrawalOnTargetMarketError, RepayExceedsDebtError, RepaySharesExceedDebtError, TransferAmountNotEqualToAssetsError, UnsortedReallocationWithdrawalsError, WithdrawExceedsCollateralError, WithdrawMakesPositionUnhealthyError, } from "../types/index.js";
|
|
5
5
|
import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE } from "./constant.js";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Asserts that the client has a connected account AND that it matches
|
|
8
8
|
* the provided user address.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Used internally by the signature requirements (`encodeErc20Permit`,
|
|
11
|
+
* `encodeErc20Permit2`) to enforce builder = signer at `sign()` time:
|
|
12
|
+
* the signing flow is the only path where an account/address mismatch
|
|
13
|
+
* is a real security concern (rather than just an integrator footgun).
|
|
14
|
+
*
|
|
15
|
+
* Transaction builders no longer call this helper — callers are
|
|
16
|
+
* responsible for keeping `userAddress` aligned with the signing account
|
|
17
|
+
* at the builder layer.
|
|
14
18
|
*
|
|
15
19
|
* Throws {@link MissingClientPropertyError} if the client has no account.
|
|
16
20
|
* Throws {@link AddressMismatchError} if the client account differs from
|
|
@@ -20,14 +24,14 @@ import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE } from "./constant.js";
|
|
|
20
24
|
* `MissingClientPropertyError` is thrown.
|
|
21
25
|
* @param userAddress - The user address provided by the caller.
|
|
22
26
|
*/
|
|
23
|
-
export
|
|
27
|
+
export function validateUserAddress(clientAccountAddress, userAddress) {
|
|
24
28
|
if (clientAccountAddress === undefined) {
|
|
25
29
|
throw new MissingClientPropertyError("account");
|
|
26
30
|
}
|
|
27
31
|
if (!isAddressEqual(clientAccountAddress, userAddress)) {
|
|
28
32
|
throw new AddressMismatchError(clientAccountAddress, userAddress);
|
|
29
33
|
}
|
|
30
|
-
}
|
|
34
|
+
}
|
|
31
35
|
/**
|
|
32
36
|
* Validates that the accrual position belongs to the expected market and user.
|
|
33
37
|
* Throws {@link MarketIdMismatchError} if the position's market ID
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Address,
|
|
1
|
+
import type { Address, Hex, WalletClient } from "viem";
|
|
2
2
|
import type { Deallocation } from "./deallocation.js";
|
|
3
3
|
export interface BaseAction<TType extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>> {
|
|
4
4
|
readonly type: TType;
|
|
@@ -10,7 +10,7 @@ export interface ERC20ApprovalAction extends BaseAction<"erc20Approval", {
|
|
|
10
10
|
}> {
|
|
11
11
|
}
|
|
12
12
|
export interface ERC20PermitAction {
|
|
13
|
-
sign: (client:
|
|
13
|
+
sign: (client: WalletClient, userAddress: Address) => Promise<Hex>;
|
|
14
14
|
}
|
|
15
15
|
export interface VaultV2DepositAction extends BaseAction<"vaultV2Deposit", {
|
|
16
16
|
vault: Address;
|
|
@@ -191,7 +191,7 @@ export interface Permit2Args {
|
|
|
191
191
|
expiration: bigint;
|
|
192
192
|
}
|
|
193
193
|
export interface Requirement {
|
|
194
|
-
sign: (client:
|
|
194
|
+
sign: (client: WalletClient, userAddress: Address) => Promise<RequirementSignature>;
|
|
195
195
|
action: PermitAction | Permit2Action;
|
|
196
196
|
}
|
|
197
197
|
export interface PermitAction extends BaseAction<"permit", {
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MarketId } from "@morpho-org/blue-sdk";
|
|
1
2
|
import type { Address } from "viem";
|
|
2
3
|
/** Thrown when an asset amount is required to be positive but is zero or negative. */
|
|
3
4
|
export declare class NonPositiveAssetAmountError extends Error {
|
|
@@ -51,6 +52,10 @@ export declare class DepositAmountMismatchError extends Error {
|
|
|
51
52
|
export declare class DepositAssetMismatchError extends Error {
|
|
52
53
|
constructor(depositAsset: Address, signatureAsset: Address);
|
|
53
54
|
}
|
|
55
|
+
/** Thrown when a `permit2` requirement signature is missing the `expiration` field. */
|
|
56
|
+
export declare class Permit2ExpirationMissingError extends Error {
|
|
57
|
+
constructor();
|
|
58
|
+
}
|
|
54
59
|
/** Thrown when a vault deposit uses `nativeAmount` but the vault asset is not the chain's wNative. */
|
|
55
60
|
export declare class NativeAmountOnNonWNativeVaultError extends Error {
|
|
56
61
|
constructor(vaultAsset: Address, wNative: Address);
|
|
@@ -191,6 +196,25 @@ export declare class RepaySharesExceedDebtError extends Error {
|
|
|
191
196
|
export declare class MissingPublicAllocatorConfigError extends Error {
|
|
192
197
|
constructor(vault: string);
|
|
193
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Thrown when shared liquidity selected by `computeReallocations` cannot cover
|
|
201
|
+
* the absolute borrow shortfall on the target market — the resulting
|
|
202
|
+
* `morphoBorrow` would still revert onchain.
|
|
203
|
+
*
|
|
204
|
+
* Pattern-match on the class and inspect `params` to surface the gap to users.
|
|
205
|
+
*/
|
|
206
|
+
export declare class InsufficientSharedLiquidityError extends Error {
|
|
207
|
+
readonly params: {
|
|
208
|
+
readonly marketId: MarketId;
|
|
209
|
+
readonly shortfall: bigint;
|
|
210
|
+
readonly available: bigint;
|
|
211
|
+
};
|
|
212
|
+
constructor(params: {
|
|
213
|
+
readonly marketId: MarketId;
|
|
214
|
+
readonly shortfall: bigint;
|
|
215
|
+
readonly available: bigint;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
194
218
|
/** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
|
|
195
219
|
export declare class NonPositiveMinBorrowSharePriceError extends Error {
|
|
196
220
|
constructor(market: string);
|