@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,12 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateSlippageTolerance = exports.validateReallocations = exports.validateRepayParams = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.
|
|
3
|
+
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateReallocations = exports.validateRepayParams = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.compareMarketIds = void 0;
|
|
4
4
|
exports.validateUserAddress = validateUserAddress;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
7
|
const viem_1 = require("viem");
|
|
8
8
|
const index_js_1 = require("../types/index.js");
|
|
9
9
|
const constant_js_1 = require("./constant.js");
|
|
10
|
+
/** @internal */
|
|
11
|
+
const compareMarketIds = (idA, idB) => {
|
|
12
|
+
const normalizedIdA = idA.toLowerCase();
|
|
13
|
+
const normalizedIdB = idB.toLowerCase();
|
|
14
|
+
if (normalizedIdA > normalizedIdB)
|
|
15
|
+
return 1;
|
|
16
|
+
if (normalizedIdA < normalizedIdB)
|
|
17
|
+
return -1;
|
|
18
|
+
return 0;
|
|
19
|
+
};
|
|
20
|
+
exports.compareMarketIds = compareMarketIds;
|
|
10
21
|
/**
|
|
11
22
|
* Asserts that the client has a connected account AND that it matches
|
|
12
23
|
* the provided user address.
|
|
@@ -100,23 +111,25 @@ const validateChainId = (clientChainId, expectedChainId) => {
|
|
|
100
111
|
};
|
|
101
112
|
exports.validateChainId = validateChainId;
|
|
102
113
|
/**
|
|
103
|
-
* Validates that the given
|
|
104
|
-
*
|
|
105
|
-
*
|
|
114
|
+
* Validates that the given asset is the chain's wrapped native token.
|
|
115
|
+
* Used by any action that may receive `nativeAmount` — the SDK wraps native
|
|
116
|
+
* into wNative, so the target asset must be wNative for the action to succeed.
|
|
106
117
|
*
|
|
107
118
|
* @param chainId - The chain to look up wNative on.
|
|
108
|
-
* @param
|
|
119
|
+
* @param asset - The asset address to check (collateral, loan, vault asset…).
|
|
120
|
+
* @throws {ChainWNativeMissingError} if wNative is not configured for the chain.
|
|
121
|
+
* @throws {NativeAmountOnNonWNativeAssetError} if the asset is not wNative.
|
|
109
122
|
*/
|
|
110
|
-
const
|
|
123
|
+
const validateNativeAsset = (chainId, asset) => {
|
|
111
124
|
const { wNative } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
112
125
|
if (!(0, morpho_ts_1.isDefined)(wNative)) {
|
|
113
126
|
throw new index_js_1.ChainWNativeMissingError(chainId);
|
|
114
127
|
}
|
|
115
|
-
if (!(0, viem_1.isAddressEqual)(
|
|
116
|
-
throw new index_js_1.
|
|
128
|
+
if (!(0, viem_1.isAddressEqual)(asset, wNative)) {
|
|
129
|
+
throw new index_js_1.NativeAmountOnNonWNativeAssetError(asset, wNative);
|
|
117
130
|
}
|
|
118
131
|
};
|
|
119
|
-
exports.
|
|
132
|
+
exports.validateNativeAsset = validateNativeAsset;
|
|
120
133
|
/**
|
|
121
134
|
* Validates that the resulting position stays within the safe LTV threshold
|
|
122
135
|
* (LLTV minus buffer) after withdrawing collateral.
|
|
@@ -242,11 +255,12 @@ exports.validateRepayParams = validateRepayParams;
|
|
|
242
255
|
* - `fee` must be non-negative.
|
|
243
256
|
* - `withdrawals` must be non-empty.
|
|
244
257
|
* - Every withdrawal `amount` must be strictly positive.
|
|
245
|
-
* - No withdrawal may target `targetMarketId` (the
|
|
258
|
+
* - No withdrawal may target `targetMarketId` (the operation's target market — the market being
|
|
259
|
+
* borrowed from for `borrow`, or being withdrawn from for `withdraw`).
|
|
246
260
|
* - Withdrawal market IDs must be strictly ascending (required by `PublicAllocator.reallocateTo`).
|
|
247
261
|
*
|
|
248
262
|
* @param reallocations - The reallocations to validate.
|
|
249
|
-
* @param targetMarketId - The ID of the
|
|
263
|
+
* @param targetMarketId - The ID of the operation's target market. No withdrawal may reference this market.
|
|
250
264
|
*/
|
|
251
265
|
const validateReallocations = (reallocations, targetMarketId) => {
|
|
252
266
|
for (const r of reallocations) {
|
|
@@ -264,7 +278,8 @@ const validateReallocations = (reallocations, targetMarketId) => {
|
|
|
264
278
|
if (w.marketParams.id === targetMarketId) {
|
|
265
279
|
throw new index_js_1.ReallocationWithdrawalOnTargetMarketError(r.vault, w.marketParams.id);
|
|
266
280
|
}
|
|
267
|
-
if (prevId !== undefined &&
|
|
281
|
+
if (prevId !== undefined &&
|
|
282
|
+
(0, exports.compareMarketIds)(w.marketParams.id, prevId) <= 0) {
|
|
268
283
|
throw new index_js_1.UnsortedReallocationWithdrawalsError(r.vault, w.marketParams.id);
|
|
269
284
|
}
|
|
270
285
|
prevId = w.marketParams.id;
|
|
@@ -289,3 +304,43 @@ const validateSlippageTolerance = (slippageTolerance) => {
|
|
|
289
304
|
}
|
|
290
305
|
};
|
|
291
306
|
exports.validateSlippageTolerance = validateSlippageTolerance;
|
|
307
|
+
/**
|
|
308
|
+
* Validates that the withdraw assets do not exceed the user's supplied assets in the market.
|
|
309
|
+
*
|
|
310
|
+
* @param params - Validation parameters.
|
|
311
|
+
* @param params.positionData - The current accrual position.
|
|
312
|
+
* @param params.withdrawAssets - The amount of assets to withdraw.
|
|
313
|
+
* @param params.marketId - The market identifier (for error messages).
|
|
314
|
+
* @throws {WithdrawExceedsSupplyError} when `withdrawAssets > positionData.supplyAssets`.
|
|
315
|
+
*/
|
|
316
|
+
const validateWithdrawAmount = (params) => {
|
|
317
|
+
const { positionData, withdrawAssets, marketId } = params;
|
|
318
|
+
if (withdrawAssets > positionData.supplyAssets) {
|
|
319
|
+
throw new index_js_1.WithdrawExceedsSupplyError({
|
|
320
|
+
withdrawAmount: withdrawAssets,
|
|
321
|
+
available: positionData.supplyAssets,
|
|
322
|
+
market: marketId,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
exports.validateWithdrawAmount = validateWithdrawAmount;
|
|
327
|
+
/**
|
|
328
|
+
* Validates that the withdraw shares do not exceed the user's owned supply shares in the market.
|
|
329
|
+
*
|
|
330
|
+
* @param params - Validation parameters.
|
|
331
|
+
* @param params.positionData - The current accrual position.
|
|
332
|
+
* @param params.withdrawShares - The amount of shares to withdraw.
|
|
333
|
+
* @param params.marketId - The market identifier (for error messages).
|
|
334
|
+
* @throws {WithdrawSharesExceedSupplyError} when `withdrawShares > positionData.supplyShares`.
|
|
335
|
+
*/
|
|
336
|
+
const validateWithdrawShares = (params) => {
|
|
337
|
+
const { positionData, withdrawShares, marketId } = params;
|
|
338
|
+
if (withdrawShares > positionData.supplyShares) {
|
|
339
|
+
throw new index_js_1.WithdrawSharesExceedSupplyError({
|
|
340
|
+
withdrawShares,
|
|
341
|
+
supplyShares: positionData.supplyShares,
|
|
342
|
+
market: marketId,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
exports.validateWithdrawShares = validateWithdrawShares;
|
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -16,6 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./actions/index.js"), exports);
|
|
18
18
|
__exportStar(require("./client/index.js"), exports);
|
|
19
|
-
__exportStar(require("./entities/index.js"), exports);
|
|
20
19
|
__exportStar(require("./helpers/index.js"), exports);
|
|
21
20
|
__exportStar(require("./types/index.js"), exports);
|
|
@@ -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/cjs/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);
|