@morpho-org/morpho-sdk 2.1.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/abis.d.ts +2816 -0
- package/lib/cjs/abis.js +1951 -0
- package/lib/cjs/actions/index.d.ts +3 -0
- package/lib/cjs/actions/marketV1/borrow.js +7 -10
- package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +2 -3
- package/lib/cjs/actions/marketV1/buildReallocationActions.js +1 -2
- package/lib/cjs/actions/marketV1/index.d.ts +2 -0
- package/lib/cjs/actions/marketV1/index.js +2 -0
- package/lib/cjs/actions/marketV1/repay.d.ts +2 -0
- package/lib/cjs/actions/marketV1/repay.js +7 -8
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +9 -10
- package/lib/cjs/actions/marketV1/supply.d.ts +69 -0
- package/lib/cjs/actions/marketV1/supply.js +128 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +3 -1
- package/lib/cjs/actions/marketV1/supplyCollateral.js +12 -13
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +3 -1
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +14 -15
- package/lib/cjs/actions/marketV1/withdraw.d.ts +83 -0
- package/lib/cjs/actions/marketV1/withdraw.js +110 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -2
- package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -0
- package/lib/cjs/actions/vaultV1/deposit.js +13 -14
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +11 -9
- package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -0
- package/lib/cjs/actions/vaultV2/deposit.js +13 -14
- package/lib/cjs/addresses.d.ts +2 -0
- package/lib/cjs/addresses.js +18 -0
- package/lib/cjs/augment/AccrualPosition.d.ts +9 -0
- package/lib/cjs/augment/AccrualPosition.js +8 -0
- package/lib/cjs/augment/AccrualVault.d.ts +8 -0
- package/lib/cjs/augment/AccrualVault.js +7 -0
- package/lib/cjs/augment/Holding.d.ts +8 -0
- package/lib/cjs/augment/Holding.js +7 -0
- package/lib/cjs/augment/Market.d.ts +8 -0
- package/lib/cjs/augment/Market.js +7 -0
- package/lib/cjs/augment/MarketParams.d.ts +8 -0
- package/lib/cjs/augment/MarketParams.js +7 -0
- package/lib/cjs/augment/Position.d.ts +8 -0
- package/lib/cjs/augment/Position.js +7 -0
- package/lib/cjs/augment/Token.d.ts +8 -0
- package/lib/cjs/augment/Token.js +7 -0
- package/lib/cjs/augment/User.d.ts +8 -0
- package/lib/cjs/augment/User.js +7 -0
- package/lib/cjs/augment/Vault.d.ts +8 -0
- package/lib/cjs/augment/Vault.js +7 -0
- package/lib/cjs/augment/VaultConfig.d.ts +8 -0
- package/lib/cjs/augment/VaultConfig.js +7 -0
- package/lib/cjs/augment/VaultMarketAllocation.d.ts +8 -0
- package/lib/cjs/augment/VaultMarketAllocation.js +7 -0
- package/lib/cjs/augment/VaultMarketConfig.d.ts +8 -0
- package/lib/cjs/augment/VaultMarketConfig.js +7 -0
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +8 -0
- package/lib/cjs/augment/VaultUser.d.ts +8 -0
- package/lib/cjs/augment/VaultUser.js +7 -0
- package/lib/cjs/augment.d.ts +14 -0
- package/lib/cjs/augment.js +16 -0
- package/lib/cjs/bundler/actions.d.ts +637 -0
- package/lib/cjs/bundler/actions.js +1088 -0
- package/lib/cjs/bundler/index.d.ts +2 -0
- package/lib/cjs/bundler/index.js +18 -0
- package/lib/cjs/bundler/types.d.ts +200 -0
- package/lib/cjs/bundler/types.js +2 -0
- package/lib/cjs/constants.d.ts +3 -0
- package/lib/cjs/constants.js +32 -0
- package/lib/cjs/entities/index.d.ts +6 -3
- package/lib/cjs/entities/index.js +41 -17
- package/lib/cjs/entities/marketV1/marketV1.d.ts +161 -24
- package/lib/cjs/entities/marketV1/marketV1.js +166 -19
- package/lib/cjs/entities/reallocationData.d.ts +193 -0
- package/lib/cjs/entities/reallocationData.js +406 -0
- package/lib/cjs/errors.d.ts +2 -0
- package/lib/cjs/errors.js +18 -0
- package/lib/cjs/fetch.d.ts +1 -0
- package/lib/cjs/fetch.js +30 -0
- package/lib/cjs/format.d.ts +2 -0
- package/lib/cjs/format.js +22 -0
- package/lib/cjs/helpers/computeReallocations.d.ts +63 -12
- package/lib/cjs/helpers/computeReallocations.js +160 -41
- package/lib/cjs/helpers/constant.d.ts +17 -0
- package/lib/cjs/helpers/constant.js +30 -1
- package/lib/cjs/helpers/index.d.ts +3 -2
- package/lib/cjs/helpers/index.js +14 -2
- package/lib/cjs/helpers/slippage.d.ts +57 -0
- package/lib/cjs/helpers/slippage.js +82 -0
- package/lib/cjs/helpers/validate.d.ts +40 -7
- package/lib/cjs/helpers/validate.js +67 -12
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/types/action.d.ts +27 -6
- package/lib/cjs/types/client.d.ts +1 -1
- package/lib/cjs/types/error.d.ts +155 -7
- package/lib/cjs/types/error.js +202 -11
- package/lib/cjs/types/sharedLiquidity.d.ts +43 -3
- package/lib/cjs/types.d.ts +3 -0
- package/lib/cjs/types.js +17 -0
- package/lib/cjs/utils.d.ts +9 -0
- package/lib/cjs/utils.js +65 -0
- package/lib/esm/abis.d.ts +2816 -0
- package/lib/esm/abis.js +1922 -0
- package/lib/esm/actions/index.d.ts +3 -0
- package/lib/esm/actions/marketV1/borrow.js +2 -5
- package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +2 -3
- package/lib/esm/actions/marketV1/buildReallocationActions.js +1 -2
- package/lib/esm/actions/marketV1/index.d.ts +2 -0
- package/lib/esm/actions/marketV1/index.js +2 -0
- package/lib/esm/actions/marketV1/repay.d.ts +2 -0
- package/lib/esm/actions/marketV1/repay.js +4 -5
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +4 -5
- package/lib/esm/actions/marketV1/supply.d.ts +69 -0
- package/lib/esm/actions/marketV1/supply.js +124 -0
- package/lib/esm/actions/marketV1/supplyCollateral.d.ts +3 -1
- package/lib/esm/actions/marketV1/supplyCollateral.js +7 -8
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +3 -1
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +7 -8
- package/lib/esm/actions/marketV1/withdraw.d.ts +83 -0
- package/lib/esm/actions/marketV1/withdraw.js +106 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +1 -1
- package/lib/esm/actions/requirements/getRequirementsAction.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.js +1 -1
- package/lib/esm/actions/vaultV1/deposit.d.ts +2 -0
- package/lib/esm/actions/vaultV1/deposit.js +3 -4
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +3 -1
- package/lib/esm/actions/vaultV2/deposit.d.ts +2 -0
- package/lib/esm/actions/vaultV2/deposit.js +3 -4
- package/lib/esm/addresses.d.ts +2 -0
- package/lib/esm/addresses.js +1 -0
- package/lib/esm/augment/AccrualPosition.d.ts +9 -0
- package/lib/esm/augment/AccrualPosition.js +5 -0
- package/lib/esm/augment/AccrualVault.d.ts +8 -0
- package/lib/esm/augment/AccrualVault.js +4 -0
- package/lib/esm/augment/Holding.d.ts +8 -0
- package/lib/esm/augment/Holding.js +4 -0
- package/lib/esm/augment/Market.d.ts +8 -0
- package/lib/esm/augment/Market.js +4 -0
- package/lib/esm/augment/MarketParams.d.ts +8 -0
- package/lib/esm/augment/MarketParams.js +4 -0
- package/lib/esm/augment/Position.d.ts +8 -0
- package/lib/esm/augment/Position.js +4 -0
- package/lib/esm/augment/Token.d.ts +8 -0
- package/lib/esm/augment/Token.js +4 -0
- package/lib/esm/augment/User.d.ts +8 -0
- package/lib/esm/augment/User.js +4 -0
- package/lib/esm/augment/Vault.d.ts +8 -0
- package/lib/esm/augment/Vault.js +4 -0
- package/lib/esm/augment/VaultConfig.d.ts +8 -0
- package/lib/esm/augment/VaultConfig.js +4 -0
- package/lib/esm/augment/VaultMarketAllocation.d.ts +8 -0
- package/lib/esm/augment/VaultMarketAllocation.js +4 -0
- package/lib/esm/augment/VaultMarketConfig.d.ts +8 -0
- package/lib/esm/augment/VaultMarketConfig.js +4 -0
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +5 -0
- package/lib/esm/augment/VaultUser.d.ts +8 -0
- package/lib/esm/augment/VaultUser.js +4 -0
- package/lib/esm/augment.d.ts +14 -0
- package/lib/esm/augment.js +14 -0
- package/lib/esm/bundler/actions.d.ts +637 -0
- package/lib/esm/bundler/actions.js +1085 -0
- package/lib/esm/bundler/index.d.ts +2 -0
- package/lib/esm/bundler/index.js +2 -0
- package/lib/esm/bundler/types.d.ts +200 -0
- package/lib/esm/bundler/types.js +1 -0
- package/lib/esm/constants.d.ts +3 -0
- package/lib/esm/constants.js +3 -0
- package/lib/esm/entities/index.d.ts +6 -3
- package/lib/esm/entities/index.js +5 -3
- package/lib/esm/entities/marketV1/marketV1.d.ts +161 -24
- package/lib/esm/entities/marketV1/marketV1.js +170 -23
- package/lib/esm/entities/reallocationData.d.ts +193 -0
- package/lib/esm/entities/reallocationData.js +402 -0
- package/lib/esm/errors.d.ts +2 -0
- package/lib/esm/errors.js +1 -0
- package/lib/esm/fetch.d.ts +1 -0
- package/lib/esm/fetch.js +1 -0
- package/lib/esm/format.d.ts +2 -0
- package/lib/esm/format.js +1 -0
- package/lib/esm/helpers/computeReallocations.d.ts +63 -12
- package/lib/esm/helpers/computeReallocations.js +160 -41
- package/lib/esm/helpers/constant.d.ts +17 -0
- package/lib/esm/helpers/constant.js +30 -1
- package/lib/esm/helpers/index.d.ts +3 -2
- package/lib/esm/helpers/index.js +3 -2
- package/lib/esm/helpers/slippage.d.ts +57 -0
- package/lib/esm/helpers/slippage.js +80 -0
- package/lib/esm/helpers/validate.d.ts +40 -7
- package/lib/esm/helpers/validate.js +63 -11
- package/lib/esm/index.d.ts +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/types/action.d.ts +27 -6
- package/lib/esm/types/client.d.ts +1 -1
- package/lib/esm/types/error.d.ts +155 -7
- package/lib/esm/types/error.js +185 -9
- package/lib/esm/types/sharedLiquidity.d.ts +43 -3
- package/lib/esm/types.d.ts +3 -0
- package/lib/esm/types.js +1 -0
- package/lib/esm/utils.d.ts +9 -0
- package/lib/esm/utils.js +7 -0
- package/package.json +128 -17
- package/src/index.ts +0 -1
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { getChainAddresses, MathLib, ORACLE_PRICE_SCALE, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { isDefined } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { isAddressEqual } from "viem";
|
|
4
|
-
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, MutuallyExclusiveRepayAmountsError,
|
|
4
|
+
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, MutuallyExclusiveRepayAmountsError, NativeAmountOnNonWNativeAssetError, NegativeReallocationFeeError, NegativeSlippageToleranceError, NonPositiveReallocationAmountError, NonPositiveRepayAmountError, NonPositiveRepayMaxSharePriceError, NonPositiveTransferAmountError, ReallocationWithdrawalOnTargetMarketError, RepayExceedsDebtError, RepaySharesExceedDebtError, TransferAmountNotEqualToAssetsError, UnsortedReallocationWithdrawalsError, WithdrawExceedsCollateralError, WithdrawExceedsSupplyError, WithdrawMakesPositionUnhealthyError, WithdrawSharesExceedSupplyError, } from "../types/index.js";
|
|
5
5
|
import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE } from "./constant.js";
|
|
6
|
+
/** @internal */
|
|
7
|
+
export const compareMarketIds = (idA, idB) => {
|
|
8
|
+
const normalizedIdA = idA.toLowerCase();
|
|
9
|
+
const normalizedIdB = idB.toLowerCase();
|
|
10
|
+
if (normalizedIdA > normalizedIdB)
|
|
11
|
+
return 1;
|
|
12
|
+
if (normalizedIdA < normalizedIdB)
|
|
13
|
+
return -1;
|
|
14
|
+
return 0;
|
|
15
|
+
};
|
|
6
16
|
/**
|
|
7
17
|
* Asserts that the client has a connected account AND that it matches
|
|
8
18
|
* the provided user address.
|
|
@@ -93,20 +103,22 @@ export const validateChainId = (clientChainId, expectedChainId) => {
|
|
|
93
103
|
}
|
|
94
104
|
};
|
|
95
105
|
/**
|
|
96
|
-
* Validates that the given
|
|
97
|
-
*
|
|
98
|
-
*
|
|
106
|
+
* Validates that the given asset is the chain's wrapped native token.
|
|
107
|
+
* Used by any action that may receive `nativeAmount` — the SDK wraps native
|
|
108
|
+
* into wNative, so the target asset must be wNative for the action to succeed.
|
|
99
109
|
*
|
|
100
110
|
* @param chainId - The chain to look up wNative on.
|
|
101
|
-
* @param
|
|
111
|
+
* @param asset - The asset address to check (collateral, loan, vault asset…).
|
|
112
|
+
* @throws {ChainWNativeMissingError} if wNative is not configured for the chain.
|
|
113
|
+
* @throws {NativeAmountOnNonWNativeAssetError} if the asset is not wNative.
|
|
102
114
|
*/
|
|
103
|
-
export const
|
|
115
|
+
export const validateNativeAsset = (chainId, asset) => {
|
|
104
116
|
const { wNative } = getChainAddresses(chainId);
|
|
105
117
|
if (!isDefined(wNative)) {
|
|
106
118
|
throw new ChainWNativeMissingError(chainId);
|
|
107
119
|
}
|
|
108
|
-
if (!isAddressEqual(
|
|
109
|
-
throw new
|
|
120
|
+
if (!isAddressEqual(asset, wNative)) {
|
|
121
|
+
throw new NativeAmountOnNonWNativeAssetError(asset, wNative);
|
|
110
122
|
}
|
|
111
123
|
};
|
|
112
124
|
/**
|
|
@@ -230,11 +242,12 @@ export const validateRepayParams = (params) => {
|
|
|
230
242
|
* - `fee` must be non-negative.
|
|
231
243
|
* - `withdrawals` must be non-empty.
|
|
232
244
|
* - Every withdrawal `amount` must be strictly positive.
|
|
233
|
-
* - No withdrawal may target `targetMarketId` (the
|
|
245
|
+
* - No withdrawal may target `targetMarketId` (the operation's target market — the market being
|
|
246
|
+
* borrowed from for `borrow`, or being withdrawn from for `withdraw`).
|
|
234
247
|
* - Withdrawal market IDs must be strictly ascending (required by `PublicAllocator.reallocateTo`).
|
|
235
248
|
*
|
|
236
249
|
* @param reallocations - The reallocations to validate.
|
|
237
|
-
* @param targetMarketId - The ID of the
|
|
250
|
+
* @param targetMarketId - The ID of the operation's target market. No withdrawal may reference this market.
|
|
238
251
|
*/
|
|
239
252
|
export const validateReallocations = (reallocations, targetMarketId) => {
|
|
240
253
|
for (const r of reallocations) {
|
|
@@ -252,7 +265,8 @@ export const validateReallocations = (reallocations, targetMarketId) => {
|
|
|
252
265
|
if (w.marketParams.id === targetMarketId) {
|
|
253
266
|
throw new ReallocationWithdrawalOnTargetMarketError(r.vault, w.marketParams.id);
|
|
254
267
|
}
|
|
255
|
-
if (prevId !== undefined &&
|
|
268
|
+
if (prevId !== undefined &&
|
|
269
|
+
compareMarketIds(w.marketParams.id, prevId) <= 0) {
|
|
256
270
|
throw new UnsortedReallocationWithdrawalsError(r.vault, w.marketParams.id);
|
|
257
271
|
}
|
|
258
272
|
prevId = w.marketParams.id;
|
|
@@ -275,3 +289,41 @@ export const validateSlippageTolerance = (slippageTolerance) => {
|
|
|
275
289
|
throw new ExcessiveSlippageToleranceError(slippageTolerance);
|
|
276
290
|
}
|
|
277
291
|
};
|
|
292
|
+
/**
|
|
293
|
+
* Validates that the withdraw assets do not exceed the user's supplied assets in the market.
|
|
294
|
+
*
|
|
295
|
+
* @param params - Validation parameters.
|
|
296
|
+
* @param params.positionData - The current accrual position.
|
|
297
|
+
* @param params.withdrawAssets - The amount of assets to withdraw.
|
|
298
|
+
* @param params.marketId - The market identifier (for error messages).
|
|
299
|
+
* @throws {WithdrawExceedsSupplyError} when `withdrawAssets > positionData.supplyAssets`.
|
|
300
|
+
*/
|
|
301
|
+
export const validateWithdrawAmount = (params) => {
|
|
302
|
+
const { positionData, withdrawAssets, marketId } = params;
|
|
303
|
+
if (withdrawAssets > positionData.supplyAssets) {
|
|
304
|
+
throw new WithdrawExceedsSupplyError({
|
|
305
|
+
withdrawAmount: withdrawAssets,
|
|
306
|
+
available: positionData.supplyAssets,
|
|
307
|
+
market: marketId,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
/**
|
|
312
|
+
* Validates that the withdraw shares do not exceed the user's owned supply shares in the market.
|
|
313
|
+
*
|
|
314
|
+
* @param params - Validation parameters.
|
|
315
|
+
* @param params.positionData - The current accrual position.
|
|
316
|
+
* @param params.withdrawShares - The amount of shares to withdraw.
|
|
317
|
+
* @param params.marketId - The market identifier (for error messages).
|
|
318
|
+
* @throws {WithdrawSharesExceedSupplyError} when `withdrawShares > positionData.supplyShares`.
|
|
319
|
+
*/
|
|
320
|
+
export const validateWithdrawShares = (params) => {
|
|
321
|
+
const { positionData, withdrawShares, marketId } = params;
|
|
322
|
+
if (withdrawShares > positionData.supplyShares) {
|
|
323
|
+
throw new WithdrawSharesExceedSupplyError({
|
|
324
|
+
withdrawShares,
|
|
325
|
+
supplyShares: positionData.supplyShares,
|
|
326
|
+
market: marketId,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
};
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.js
CHANGED
|
@@ -81,6 +81,23 @@ export interface VaultV1MigrateToV2Action extends BaseAction<"vaultV1MigrateToV2
|
|
|
81
81
|
recipient: Address;
|
|
82
82
|
}> {
|
|
83
83
|
}
|
|
84
|
+
export interface MarketV1SupplyAction extends BaseAction<"marketV1Supply", {
|
|
85
|
+
market: Hex;
|
|
86
|
+
amount: bigint;
|
|
87
|
+
onBehalf: Address;
|
|
88
|
+
maxSharePrice: bigint;
|
|
89
|
+
nativeAmount?: bigint;
|
|
90
|
+
}> {
|
|
91
|
+
}
|
|
92
|
+
export interface MarketV1WithdrawAction extends BaseAction<"marketV1Withdraw", {
|
|
93
|
+
market: Hex;
|
|
94
|
+
assets: bigint;
|
|
95
|
+
shares: bigint;
|
|
96
|
+
receiver: Address;
|
|
97
|
+
minSharePrice: bigint;
|
|
98
|
+
reallocationFee: bigint;
|
|
99
|
+
}> {
|
|
100
|
+
}
|
|
84
101
|
export interface MarketV1SupplyCollateralAction extends BaseAction<"marketV1SupplyCollateral", {
|
|
85
102
|
market: Hex;
|
|
86
103
|
amount: bigint;
|
|
@@ -136,23 +153,27 @@ export interface MarketV1RepayWithdrawCollateralAction extends BaseAction<"marke
|
|
|
136
153
|
}> {
|
|
137
154
|
}
|
|
138
155
|
/**
|
|
139
|
-
* Enforces that exactly one
|
|
156
|
+
* Enforces that exactly one of `assets` / `shares` is provided.
|
|
157
|
+
*
|
|
158
|
+
* - `assets`: operate on an exact asset amount.
|
|
159
|
+
* - `shares`: operate on an exact share count (typical for full position closes,
|
|
160
|
+
* immune to interest accrual between tx construction and execution).
|
|
140
161
|
*
|
|
141
|
-
*
|
|
142
|
-
* - `shares`: full repay by exact share count (guarantees full debt repayment
|
|
143
|
-
* regardless of interest accrued between tx construction and execution).
|
|
162
|
+
* Used by repay (asserts on borrow side) and withdraw (asserts on supply side).
|
|
144
163
|
*/
|
|
145
|
-
export type
|
|
164
|
+
export type AssetsOrSharesArgs = {
|
|
146
165
|
assets: bigint;
|
|
147
166
|
} | {
|
|
148
167
|
shares: bigint;
|
|
149
168
|
};
|
|
169
|
+
/** @deprecated Use {@link AssetsOrSharesArgs}. Kept as an alias for back-compat. */
|
|
170
|
+
export type RepayAmountArgs = AssetsOrSharesArgs;
|
|
150
171
|
export interface MorphoAuthorizationAction extends BaseAction<"morphoAuthorization", {
|
|
151
172
|
authorized: Address;
|
|
152
173
|
isAuthorized: boolean;
|
|
153
174
|
}> {
|
|
154
175
|
}
|
|
155
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | MarketV1SupplyCollateralAction | MarketV1BorrowAction | MarketV1SupplyCollateralBorrowAction | MarketV1RepayAction | MarketV1WithdrawCollateralAction | MarketV1RepayWithdrawCollateralAction | MorphoAuthorizationAction;
|
|
176
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | MarketV1SupplyAction | MarketV1WithdrawAction | MarketV1SupplyCollateralAction | MarketV1BorrowAction | MarketV1SupplyCollateralBorrowAction | MarketV1RepayAction | MarketV1WithdrawCollateralAction | MarketV1RepayWithdrawCollateralAction | MorphoAuthorizationAction;
|
|
156
177
|
export interface Transaction<TAction extends BaseAction = TransactionAction> {
|
|
157
178
|
readonly to: Address;
|
|
158
179
|
readonly value: bigint;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address, Client } from "viem";
|
|
3
|
-
import type { MarketV1Actions, VaultV1Actions, VaultV2Actions } from "../
|
|
3
|
+
import type { MarketV1Actions, VaultV1Actions, VaultV2Actions } from "../actions/index.js";
|
|
4
4
|
import type { Metadata } from "./index.js";
|
|
5
5
|
/**
|
|
6
6
|
* Structural contract every concrete `MorphoClient` implementation satisfies. Carries the viem
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MarketId, UnknownDataError } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
+
/**
|
|
4
|
+
* Typed errors thrown while encoding supported Bundler3 actions.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Import these classes through `@morpho-org/morpho-sdk` when handling
|
|
8
|
+
* failures from `BundlerAction`.
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace BundlerErrors {
|
|
11
|
+
/**
|
|
12
|
+
* Thrown when an action that requires an offchain signature is encoded before
|
|
13
|
+
* the signature has been attached.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { BundlerErrors } from "@morpho-org/morpho-sdk";
|
|
18
|
+
*
|
|
19
|
+
* if (error instanceof BundlerErrors.MissingSignature) {
|
|
20
|
+
* // Attach the missing permit or Permit2 signature, then encode again.
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
class MissingSignature extends Error {
|
|
25
|
+
constructor();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Thrown when an action is unsupported on the requested chain.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { BundlerErrors } from "@morpho-org/morpho-sdk";
|
|
33
|
+
*
|
|
34
|
+
* if (error instanceof BundlerErrors.UnexpectedAction) {
|
|
35
|
+
* // Remove or replace the action for the selected chain.
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
class UnexpectedAction extends Error {
|
|
40
|
+
/**
|
|
41
|
+
* @param type - Unsupported Bundler3 action discriminator or name.
|
|
42
|
+
* @param chainId - Chain where the action was requested.
|
|
43
|
+
*/
|
|
44
|
+
constructor(type: string, chainId: number);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
3
47
|
/** Thrown when an asset amount is required to be positive but is zero or negative. */
|
|
4
48
|
export declare class NonPositiveAssetAmountError extends Error {
|
|
5
49
|
constructor(origin: Address);
|
|
@@ -84,10 +128,13 @@ export declare class NonPositiveBorrowAmountError extends Error {
|
|
|
84
128
|
export declare class ZeroCollateralAmountError extends Error {
|
|
85
129
|
constructor(market: string);
|
|
86
130
|
}
|
|
87
|
-
/** Thrown when
|
|
88
|
-
export declare class
|
|
89
|
-
constructor(
|
|
131
|
+
/** Thrown when an action uses `nativeAmount` but the target asset is not the chain's wNative. */
|
|
132
|
+
export declare class NativeAmountOnNonWNativeAssetError extends Error {
|
|
133
|
+
constructor(asset: Address, wNative: Address);
|
|
90
134
|
}
|
|
135
|
+
/** @deprecated Use {@link NativeAmountOnNonWNativeAssetError}. */
|
|
136
|
+
export declare const NativeAmountOnNonWNativeCollateralError: typeof NativeAmountOnNonWNativeAssetError;
|
|
137
|
+
export type NativeAmountOnNonWNativeCollateralError = NativeAmountOnNonWNativeAssetError;
|
|
91
138
|
/** Thrown when a borrow exceeds the LLTV-buffered safe maximum for the position. */
|
|
92
139
|
export declare class BorrowExceedsSafeLtvError extends Error {
|
|
93
140
|
constructor(borrowAmount: bigint, maxSafeBorrow: bigint);
|
|
@@ -116,7 +163,7 @@ export declare class EmptyReallocationWithdrawalsError extends Error {
|
|
|
116
163
|
export declare class NonPositiveReallocationAmountError extends Error {
|
|
117
164
|
constructor(vault: string, market: string);
|
|
118
165
|
}
|
|
119
|
-
/** Thrown when a reallocation withdrawal references the
|
|
166
|
+
/** Thrown when a reallocation withdrawal references the operation's target market (which would be a no-op or self-deal). */
|
|
120
167
|
export declare class ReallocationWithdrawalOnTargetMarketError extends Error {
|
|
121
168
|
constructor(vault: string, marketId: string);
|
|
122
169
|
}
|
|
@@ -196,10 +243,16 @@ export declare class RepaySharesExceedDebtError extends Error {
|
|
|
196
243
|
export declare class MissingPublicAllocatorConfigError extends Error {
|
|
197
244
|
constructor(vault: string);
|
|
198
245
|
}
|
|
246
|
+
/** Thrown when a reallocation attempts to use a disabled vault market. */
|
|
247
|
+
export declare class DisabledReallocationMarketError extends Error {
|
|
248
|
+
readonly vault: Address;
|
|
249
|
+
readonly marketId: MarketId;
|
|
250
|
+
constructor(vault: Address, marketId: MarketId);
|
|
251
|
+
}
|
|
199
252
|
/**
|
|
200
253
|
* Thrown when shared liquidity selected by `computeReallocations` cannot cover
|
|
201
|
-
* the absolute
|
|
202
|
-
* `morphoBorrow` would still revert onchain.
|
|
254
|
+
* the operation's absolute shortfall on the target market — the resulting
|
|
255
|
+
* `morphoBorrow` or `morphoWithdraw` would still revert onchain.
|
|
203
256
|
*
|
|
204
257
|
* Pattern-match on the class and inspect `params` to surface the gap to users.
|
|
205
258
|
*/
|
|
@@ -215,10 +268,105 @@ export declare class InsufficientSharedLiquidityError extends Error {
|
|
|
215
268
|
readonly available: bigint;
|
|
216
269
|
});
|
|
217
270
|
}
|
|
271
|
+
/** Thrown when reallocation state does not contain a requested market. */
|
|
272
|
+
export declare class UnknownReallocationMarketError extends UnknownDataError {
|
|
273
|
+
readonly marketId: MarketId;
|
|
274
|
+
/**
|
|
275
|
+
* @param marketId - Missing market id.
|
|
276
|
+
*/
|
|
277
|
+
constructor(marketId: MarketId);
|
|
278
|
+
}
|
|
279
|
+
/** Thrown when reallocation state does not contain a requested vault. */
|
|
280
|
+
export declare class UnknownReallocationVaultError extends UnknownDataError {
|
|
281
|
+
readonly vault: Address;
|
|
282
|
+
/**
|
|
283
|
+
* @param vault - Missing vault address.
|
|
284
|
+
*/
|
|
285
|
+
constructor(vault: Address);
|
|
286
|
+
}
|
|
287
|
+
/** Thrown when reallocation state does not contain a requested vault-market config. */
|
|
288
|
+
export declare class UnknownReallocationVaultMarketConfigError extends UnknownDataError {
|
|
289
|
+
readonly vault: Address;
|
|
290
|
+
readonly marketId: MarketId;
|
|
291
|
+
/**
|
|
292
|
+
* @param vault - Vault address for the missing config.
|
|
293
|
+
* @param marketId - Market id for the missing config.
|
|
294
|
+
*/
|
|
295
|
+
constructor(vault: Address, marketId: MarketId);
|
|
296
|
+
}
|
|
297
|
+
/** Thrown when reallocation state does not contain a requested market position. */
|
|
298
|
+
export declare class UnknownReallocationPositionError extends UnknownDataError {
|
|
299
|
+
readonly user: Address;
|
|
300
|
+
readonly marketId: MarketId;
|
|
301
|
+
/**
|
|
302
|
+
* @param user - Position owner address.
|
|
303
|
+
* @param marketId - Market id for the missing position.
|
|
304
|
+
*/
|
|
305
|
+
constructor(user: Address, marketId: MarketId);
|
|
306
|
+
}
|
|
218
307
|
/** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
|
|
219
308
|
export declare class NonPositiveMinBorrowSharePriceError extends Error {
|
|
220
309
|
constructor(market: string);
|
|
221
310
|
}
|
|
311
|
+
/** Thrown when a market loan-asset supply amount is negative. */
|
|
312
|
+
export declare class NegativeSupplyAmountError extends Error {
|
|
313
|
+
constructor(market: string);
|
|
314
|
+
}
|
|
315
|
+
/** Thrown when a market loan-asset supply's `maxSharePrice` slippage bound is negative. */
|
|
316
|
+
export declare class NegativeSupplyMaxSharePriceError extends Error {
|
|
317
|
+
constructor(market: string);
|
|
318
|
+
}
|
|
319
|
+
/** Thrown when both `amount` and `nativeAmount` resolve to zero on a market loan-asset supply. */
|
|
320
|
+
export declare class ZeroSupplyAmountError extends Error {
|
|
321
|
+
constructor(market: string);
|
|
322
|
+
}
|
|
323
|
+
/** Thrown when a market loan-asset withdraw has both `assets` and `shares` zero, or either negative. */
|
|
324
|
+
export declare class NonPositiveWithdrawAmountError extends Error {
|
|
325
|
+
constructor(market: string);
|
|
326
|
+
}
|
|
327
|
+
/** Thrown when a market loan-asset withdraw's `minSharePrice` slippage bound is negative. */
|
|
328
|
+
export declare class NegativeWithdrawMinSharePriceError extends Error {
|
|
329
|
+
constructor(market: string);
|
|
330
|
+
}
|
|
331
|
+
/** Thrown when a loan-asset withdraw specifies both `assets` and `shares` as non-zero (modes are mutually exclusive). */
|
|
332
|
+
export declare class MutuallyExclusiveWithdrawAmountsError extends Error {
|
|
333
|
+
constructor(market: string);
|
|
334
|
+
}
|
|
335
|
+
/** Thrown when a loan-asset withdraw in assets mode exceeds the user's supplied assets in the market. */
|
|
336
|
+
export declare class WithdrawExceedsSupplyError extends Error {
|
|
337
|
+
constructor(params: {
|
|
338
|
+
withdrawAmount: bigint;
|
|
339
|
+
available: bigint;
|
|
340
|
+
market: string;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
/** Thrown when a loan-asset withdraw in shares mode exceeds the user's owned supply shares in the market. */
|
|
344
|
+
export declare class WithdrawSharesExceedSupplyError extends Error {
|
|
345
|
+
constructor(params: {
|
|
346
|
+
withdrawShares: bigint;
|
|
347
|
+
supplyShares: bigint;
|
|
348
|
+
market: string;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Thrown when `computeReallocations` is called with a withdraw `amount` greater
|
|
353
|
+
* than the target market's current `totalSupplyAssets` — the post-withdraw
|
|
354
|
+
* supply would be negative, making the on-chain `morphoWithdraw` revert
|
|
355
|
+
* regardless of any reallocation. Caught here so callers do not pay
|
|
356
|
+
* PublicAllocator fees on an unreachable operation.
|
|
357
|
+
*/
|
|
358
|
+
export declare class ReallocationWithdrawExceedsMarketSupplyError extends Error {
|
|
359
|
+
readonly params: {
|
|
360
|
+
readonly marketId: MarketId;
|
|
361
|
+
readonly withdrawAmount: bigint;
|
|
362
|
+
readonly totalSupplyAssets: bigint;
|
|
363
|
+
};
|
|
364
|
+
constructor(params: {
|
|
365
|
+
readonly marketId: MarketId;
|
|
366
|
+
readonly withdrawAmount: bigint;
|
|
367
|
+
readonly totalSupplyAssets: bigint;
|
|
368
|
+
});
|
|
369
|
+
}
|
|
222
370
|
/** Thrown when a vault migration's source vault asset differs from the target vault asset. */
|
|
223
371
|
export declare class VaultAssetMismatchError extends Error {
|
|
224
372
|
constructor(sourceAsset: Address, targetAsset: Address);
|
package/lib/esm/types/error.js
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
+
import { UnknownDataError } from "@morpho-org/blue-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Typed errors thrown while encoding supported Bundler3 actions.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Import these classes through `@morpho-org/morpho-sdk` when handling
|
|
7
|
+
* failures from `BundlerAction`.
|
|
8
|
+
*/
|
|
9
|
+
export var BundlerErrors;
|
|
10
|
+
(function (BundlerErrors) {
|
|
11
|
+
/**
|
|
12
|
+
* Thrown when an action that requires an offchain signature is encoded before
|
|
13
|
+
* the signature has been attached.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { BundlerErrors } from "@morpho-org/morpho-sdk";
|
|
18
|
+
*
|
|
19
|
+
* if (error instanceof BundlerErrors.MissingSignature) {
|
|
20
|
+
* // Attach the missing permit or Permit2 signature, then encode again.
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
class MissingSignature extends Error {
|
|
25
|
+
constructor() {
|
|
26
|
+
super("missing signature");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
BundlerErrors.MissingSignature = MissingSignature;
|
|
30
|
+
/**
|
|
31
|
+
* Thrown when an action is unsupported on the requested chain.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { BundlerErrors } from "@morpho-org/morpho-sdk";
|
|
36
|
+
*
|
|
37
|
+
* if (error instanceof BundlerErrors.UnexpectedAction) {
|
|
38
|
+
* // Remove or replace the action for the selected chain.
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
class UnexpectedAction extends Error {
|
|
43
|
+
/**
|
|
44
|
+
* @param type - Unsupported Bundler3 action discriminator or name.
|
|
45
|
+
* @param chainId - Chain where the action was requested.
|
|
46
|
+
*/
|
|
47
|
+
constructor(type, chainId) {
|
|
48
|
+
super(`unexpected action "${type}" on chain "${chainId}"`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
BundlerErrors.UnexpectedAction = UnexpectedAction;
|
|
52
|
+
})(BundlerErrors || (BundlerErrors = {}));
|
|
1
53
|
/** Thrown when an asset amount is required to be positive but is zero or negative. */
|
|
2
54
|
export class NonPositiveAssetAmountError extends Error {
|
|
3
55
|
constructor(origin) {
|
|
@@ -124,12 +176,14 @@ export class ZeroCollateralAmountError extends Error {
|
|
|
124
176
|
super(`Total collateral amount must be positive for market: ${market}. Both amount and nativeAmount are zero.`);
|
|
125
177
|
}
|
|
126
178
|
}
|
|
127
|
-
/** Thrown when
|
|
128
|
-
export class
|
|
129
|
-
constructor(
|
|
130
|
-
super(`Cannot use nativeAmount:
|
|
179
|
+
/** Thrown when an action uses `nativeAmount` but the target asset is not the chain's wNative. */
|
|
180
|
+
export class NativeAmountOnNonWNativeAssetError extends Error {
|
|
181
|
+
constructor(asset, wNative) {
|
|
182
|
+
super(`Cannot use nativeAmount: asset ${asset} is not the wrapped native token ${wNative}`);
|
|
131
183
|
}
|
|
132
184
|
}
|
|
185
|
+
/** @deprecated Use {@link NativeAmountOnNonWNativeAssetError}. */
|
|
186
|
+
export const NativeAmountOnNonWNativeCollateralError = NativeAmountOnNonWNativeAssetError;
|
|
133
187
|
/** Thrown when a borrow exceeds the LLTV-buffered safe maximum for the position. */
|
|
134
188
|
export class BorrowExceedsSafeLtvError extends Error {
|
|
135
189
|
constructor(borrowAmount, maxSafeBorrow) {
|
|
@@ -172,10 +226,10 @@ export class NonPositiveReallocationAmountError extends Error {
|
|
|
172
226
|
super(`Reallocation withdrawal amount must be positive for vault ${vault} on market ${market}`);
|
|
173
227
|
}
|
|
174
228
|
}
|
|
175
|
-
/** Thrown when a reallocation withdrawal references the
|
|
229
|
+
/** Thrown when a reallocation withdrawal references the operation's target market (which would be a no-op or self-deal). */
|
|
176
230
|
export class ReallocationWithdrawalOnTargetMarketError extends Error {
|
|
177
231
|
constructor(vault, marketId) {
|
|
178
|
-
super(`Reallocation withdrawal cannot include the
|
|
232
|
+
super(`Reallocation withdrawal cannot include the target market ${marketId} for vault ${vault}.`);
|
|
179
233
|
}
|
|
180
234
|
}
|
|
181
235
|
/** Thrown when reallocation withdrawals within a vault are not strictly sorted by market id. */
|
|
@@ -262,26 +316,148 @@ export class MissingPublicAllocatorConfigError extends Error {
|
|
|
262
316
|
super(`Vault ${vault} has no public allocator configured but was selected for reallocation`);
|
|
263
317
|
}
|
|
264
318
|
}
|
|
319
|
+
/** Thrown when a reallocation attempts to use a disabled vault market. */
|
|
320
|
+
export class DisabledReallocationMarketError extends Error {
|
|
321
|
+
vault;
|
|
322
|
+
marketId;
|
|
323
|
+
constructor(vault, marketId) {
|
|
324
|
+
super(`Vault ${vault} has disabled market ${marketId}. Remove it from reallocations or re-enable the market before reallocating.`);
|
|
325
|
+
this.vault = vault;
|
|
326
|
+
this.marketId = marketId;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
265
329
|
/**
|
|
266
330
|
* Thrown when shared liquidity selected by `computeReallocations` cannot cover
|
|
267
|
-
* the absolute
|
|
268
|
-
* `morphoBorrow` would still revert onchain.
|
|
331
|
+
* the operation's absolute shortfall on the target market — the resulting
|
|
332
|
+
* `morphoBorrow` or `morphoWithdraw` would still revert onchain.
|
|
269
333
|
*
|
|
270
334
|
* Pattern-match on the class and inspect `params` to surface the gap to users.
|
|
271
335
|
*/
|
|
272
336
|
export class InsufficientSharedLiquidityError extends Error {
|
|
273
337
|
params;
|
|
274
338
|
constructor(params) {
|
|
275
|
-
super(`Shared liquidity is insufficient
|
|
339
|
+
super(`Shared liquidity is insufficient on market ${params.marketId}: shortfall "${params.shortfall}", available "${params.available}". Reduce the operation amount or wait for additional vault liquidity.`);
|
|
276
340
|
this.params = params;
|
|
277
341
|
}
|
|
278
342
|
}
|
|
343
|
+
/** Thrown when reallocation state does not contain a requested market. */
|
|
344
|
+
export class UnknownReallocationMarketError extends UnknownDataError {
|
|
345
|
+
marketId;
|
|
346
|
+
/**
|
|
347
|
+
* @param marketId - Missing market id.
|
|
348
|
+
*/
|
|
349
|
+
constructor(marketId) {
|
|
350
|
+
super(`unknown reallocation market "${marketId}"`);
|
|
351
|
+
this.marketId = marketId;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/** Thrown when reallocation state does not contain a requested vault. */
|
|
355
|
+
export class UnknownReallocationVaultError extends UnknownDataError {
|
|
356
|
+
vault;
|
|
357
|
+
/**
|
|
358
|
+
* @param vault - Missing vault address.
|
|
359
|
+
*/
|
|
360
|
+
constructor(vault) {
|
|
361
|
+
super(`unknown reallocation vault "${vault}"`);
|
|
362
|
+
this.vault = vault;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/** Thrown when reallocation state does not contain a requested vault-market config. */
|
|
366
|
+
export class UnknownReallocationVaultMarketConfigError extends UnknownDataError {
|
|
367
|
+
vault;
|
|
368
|
+
marketId;
|
|
369
|
+
/**
|
|
370
|
+
* @param vault - Vault address for the missing config.
|
|
371
|
+
* @param marketId - Market id for the missing config.
|
|
372
|
+
*/
|
|
373
|
+
constructor(vault, marketId) {
|
|
374
|
+
super(`unknown reallocation config for vault "${vault}" on market "${marketId}"`);
|
|
375
|
+
this.vault = vault;
|
|
376
|
+
this.marketId = marketId;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/** Thrown when reallocation state does not contain a requested market position. */
|
|
380
|
+
export class UnknownReallocationPositionError extends UnknownDataError {
|
|
381
|
+
user;
|
|
382
|
+
marketId;
|
|
383
|
+
/**
|
|
384
|
+
* @param user - Position owner address.
|
|
385
|
+
* @param marketId - Market id for the missing position.
|
|
386
|
+
*/
|
|
387
|
+
constructor(user, marketId) {
|
|
388
|
+
super(`unknown reallocation position of "${user}" on market "${marketId}"`);
|
|
389
|
+
this.user = user;
|
|
390
|
+
this.marketId = marketId;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
279
393
|
/** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
|
|
280
394
|
export class NonPositiveMinBorrowSharePriceError extends Error {
|
|
281
395
|
constructor(market) {
|
|
282
396
|
super(`Min share price must be non-negative for market: ${market}`);
|
|
283
397
|
}
|
|
284
398
|
}
|
|
399
|
+
/** Thrown when a market loan-asset supply amount is negative. */
|
|
400
|
+
export class NegativeSupplyAmountError extends Error {
|
|
401
|
+
constructor(market) {
|
|
402
|
+
super(`Supply amount must be non-negative for market: ${market}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/** Thrown when a market loan-asset supply's `maxSharePrice` slippage bound is negative. */
|
|
406
|
+
export class NegativeSupplyMaxSharePriceError extends Error {
|
|
407
|
+
constructor(market) {
|
|
408
|
+
super(`Max share price must be non-negative for market: ${market}`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/** Thrown when both `amount` and `nativeAmount` resolve to zero on a market loan-asset supply. */
|
|
412
|
+
export class ZeroSupplyAmountError extends Error {
|
|
413
|
+
constructor(market) {
|
|
414
|
+
super(`Total supply amount must be positive for market: ${market}. Both amount and nativeAmount are zero.`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/** Thrown when a market loan-asset withdraw has both `assets` and `shares` zero, or either negative. */
|
|
418
|
+
export class NonPositiveWithdrawAmountError extends Error {
|
|
419
|
+
constructor(market) {
|
|
420
|
+
super(`Withdraw amount must be positive for market: ${market}`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
/** Thrown when a market loan-asset withdraw's `minSharePrice` slippage bound is negative. */
|
|
424
|
+
export class NegativeWithdrawMinSharePriceError extends Error {
|
|
425
|
+
constructor(market) {
|
|
426
|
+
super(`Min share price must be non-negative for market: ${market}`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/** Thrown when a loan-asset withdraw specifies both `assets` and `shares` as non-zero (modes are mutually exclusive). */
|
|
430
|
+
export class MutuallyExclusiveWithdrawAmountsError extends Error {
|
|
431
|
+
constructor(market) {
|
|
432
|
+
super(`Exactly one of assets or shares must be non-zero for market: ${market}. Both were provided.`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
/** Thrown when a loan-asset withdraw in assets mode exceeds the user's supplied assets in the market. */
|
|
436
|
+
export class WithdrawExceedsSupplyError extends Error {
|
|
437
|
+
constructor(params) {
|
|
438
|
+
super(`Withdraw amount ${params.withdrawAmount} exceeds available supply ${params.available} for market: ${params.market}. Reduce withdraw amount.`);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/** Thrown when a loan-asset withdraw in shares mode exceeds the user's owned supply shares in the market. */
|
|
442
|
+
export class WithdrawSharesExceedSupplyError extends Error {
|
|
443
|
+
constructor(params) {
|
|
444
|
+
super(`Withdraw shares ${params.withdrawShares} exceed owned supply shares ${params.supplyShares} for market: ${params.market}. Reduce withdraw shares.`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Thrown when `computeReallocations` is called with a withdraw `amount` greater
|
|
449
|
+
* than the target market's current `totalSupplyAssets` — the post-withdraw
|
|
450
|
+
* supply would be negative, making the on-chain `morphoWithdraw` revert
|
|
451
|
+
* regardless of any reallocation. Caught here so callers do not pay
|
|
452
|
+
* PublicAllocator fees on an unreachable operation.
|
|
453
|
+
*/
|
|
454
|
+
export class ReallocationWithdrawExceedsMarketSupplyError extends Error {
|
|
455
|
+
params;
|
|
456
|
+
constructor(params) {
|
|
457
|
+
super(`Withdraw amount "${params.withdrawAmount}" exceeds market total supply "${params.totalSupplyAssets}" on market ${params.marketId}. Reduce the withdraw amount.`);
|
|
458
|
+
this.params = params;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
285
461
|
/** Thrown when a vault migration's source vault asset differs from the target vault asset. */
|
|
286
462
|
export class VaultAssetMismatchError extends Error {
|
|
287
463
|
constructor(sourceAsset, targetAsset) {
|