@morpho-org/consumer-sdk 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +301 -41
- package/lib/actions/index.d.ts +2 -0
- package/lib/actions/index.js +2 -0
- package/lib/actions/marketV1/borrow.d.ts +34 -0
- package/lib/actions/marketV1/borrow.js +62 -0
- package/lib/actions/marketV1/buildReallocationActions.d.ts +17 -0
- package/lib/actions/marketV1/buildReallocationActions.js +36 -0
- package/lib/actions/marketV1/index.d.ts +6 -0
- package/lib/actions/marketV1/index.js +22 -0
- package/lib/actions/marketV1/repay.d.ts +44 -0
- package/lib/actions/marketV1/repay.js +93 -0
- package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +51 -0
- package/lib/actions/marketV1/repayWithdrawCollateral.js +108 -0
- package/lib/actions/marketV1/supplyCollateral.d.ts +28 -0
- package/lib/actions/marketV1/supplyCollateral.js +85 -0
- package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +37 -0
- package/lib/actions/marketV1/supplyCollateralBorrow.js +109 -0
- package/lib/actions/marketV1/withdrawCollateral.d.ts +28 -0
- package/lib/actions/marketV1/withdrawCollateral.js +51 -0
- package/lib/actions/requirements/encode/encodeErc20Permit.js +4 -1
- package/lib/actions/requirements/encode/encodeErc20Permit2.js +4 -1
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +21 -0
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +55 -0
- package/lib/actions/requirements/getRequirements.js +3 -0
- package/lib/actions/requirements/getRequirementsAction.d.ts +2 -2
- package/lib/actions/requirements/getRequirementsAction.js +7 -7
- package/lib/actions/requirements/index.d.ts +1 -0
- package/lib/actions/requirements/index.js +1 -0
- package/lib/actions/vaultV1/deposit.d.ts +41 -0
- package/lib/actions/vaultV1/deposit.js +116 -0
- package/lib/actions/vaultV1/index.d.ts +3 -0
- package/lib/actions/vaultV1/index.js +19 -0
- package/lib/actions/vaultV1/redeem.d.ts +29 -0
- package/lib/actions/vaultV1/redeem.js +48 -0
- package/lib/actions/vaultV1/withdraw.d.ts +29 -0
- package/lib/actions/vaultV1/withdraw.js +48 -0
- package/lib/actions/vaultV2/deposit.d.ts +20 -25
- package/lib/actions/vaultV2/deposit.js +78 -40
- package/lib/actions/vaultV2/forceRedeem.js +2 -2
- package/lib/actions/vaultV2/forceWithdraw.d.ts +2 -2
- package/lib/actions/vaultV2/forceWithdraw.js +12 -8
- package/lib/actions/vaultV2/redeem.js +2 -2
- package/lib/actions/vaultV2/withdraw.d.ts +3 -3
- package/lib/actions/vaultV2/withdraw.js +6 -6
- package/lib/client/morphoClient.d.ts +4 -1
- package/lib/client/morphoClient.js +6 -0
- package/lib/client/morphoViemExtension.d.ts +12 -9
- package/lib/client/morphoViemExtension.js +12 -9
- package/lib/entities/index.d.ts +2 -0
- package/lib/entities/index.js +2 -0
- package/lib/entities/marketV1/index.d.ts +1 -0
- package/lib/entities/marketV1/index.js +17 -0
- package/lib/entities/marketV1/marketV1.d.ts +290 -0
- package/lib/entities/marketV1/marketV1.js +528 -0
- package/lib/entities/vaultV1/index.d.ts +1 -0
- package/lib/entities/vaultV1/index.js +17 -0
- package/lib/entities/vaultV1/vaultV1.d.ts +95 -0
- package/lib/entities/vaultV1/vaultV1.js +129 -0
- package/lib/entities/vaultV2/vaultV2.d.ts +24 -21
- package/lib/entities/vaultV2/vaultV2.js +43 -16
- package/lib/helpers/computeReallocations.d.ts +23 -0
- package/lib/helpers/computeReallocations.js +98 -0
- package/lib/helpers/constant.d.ts +5 -0
- package/lib/helpers/constant.js +6 -1
- package/lib/helpers/encodeDeallocation.js +3 -3
- package/lib/helpers/index.d.ts +3 -0
- package/lib/helpers/index.js +18 -1
- package/lib/helpers/slippage.d.ts +46 -0
- package/lib/helpers/slippage.js +73 -0
- package/lib/helpers/validate.d.ts +150 -0
- package/lib/helpers/validate.js +279 -0
- package/lib/types/action.d.ts +113 -6
- package/lib/types/action.js +12 -1
- package/lib/types/client.d.ts +4 -1
- package/lib/types/deallocation.d.ts +1 -1
- package/lib/types/error.d.ts +127 -4
- package/lib/types/error.js +210 -12
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/sharedLiquidity.d.ts +41 -0
- package/lib/types/sharedLiquidity.js +2 -0
- package/package.json +1 -1
package/lib/types/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
1
2
|
import type { Address, Client } from "viem";
|
|
2
|
-
import type { VaultV2Actions } from "../entities";
|
|
3
|
+
import type { MarketV1Actions, VaultV1Actions, VaultV2Actions } from "../entities";
|
|
3
4
|
import type { Metadata } from "./index";
|
|
4
5
|
export interface MorphoClientType {
|
|
5
6
|
readonly viemClient: Client;
|
|
@@ -8,5 +9,7 @@ export interface MorphoClientType {
|
|
|
8
9
|
readonly supportDeployless?: boolean;
|
|
9
10
|
readonly metadata?: Metadata;
|
|
10
11
|
};
|
|
12
|
+
vaultV1: (vault: Address, chainId: number) => VaultV1Actions;
|
|
11
13
|
vaultV2: (vault: Address, chainId: number) => VaultV2Actions;
|
|
14
|
+
marketV1: (marketParams: MarketParams, chainId: number) => MarketV1Actions;
|
|
12
15
|
}
|
package/lib/types/error.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class NonPositiveAssetAmountError extends Error {
|
|
3
3
|
constructor(origin: Address);
|
|
4
4
|
}
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class NonPositiveSharesAmountError extends Error {
|
|
6
6
|
constructor(vault: Address);
|
|
7
7
|
}
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class NonPositiveMaxSharePriceError extends Error {
|
|
9
9
|
constructor(vault: Address);
|
|
10
10
|
}
|
|
11
11
|
export declare class AddressMismatchError extends Error {
|
|
@@ -20,6 +20,12 @@ export declare class MissingClientPropertyError extends Error {
|
|
|
20
20
|
export declare class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
21
21
|
constructor();
|
|
22
22
|
}
|
|
23
|
+
export declare class NegativeSlippageToleranceError extends Error {
|
|
24
|
+
constructor(slippageTolerance: bigint);
|
|
25
|
+
}
|
|
26
|
+
export declare class MissingAccrualPositionError extends Error {
|
|
27
|
+
constructor(market: string);
|
|
28
|
+
}
|
|
23
29
|
export declare class ExcessiveSlippageToleranceError extends Error {
|
|
24
30
|
constructor(slippageTolerance: bigint);
|
|
25
31
|
}
|
|
@@ -33,5 +39,122 @@ export declare class DepositAssetMismatchError extends Error {
|
|
|
33
39
|
constructor(depositAsset: Address, signatureAsset: Address);
|
|
34
40
|
}
|
|
35
41
|
export declare class DeallocationsExceedWithdrawError extends Error {
|
|
36
|
-
constructor(
|
|
42
|
+
constructor(params: {
|
|
43
|
+
vault: Address;
|
|
44
|
+
withdrawAmount: bigint;
|
|
45
|
+
totalDeallocated: bigint;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export declare class NativeAmountOnNonWNativeVaultError extends Error {
|
|
49
|
+
constructor(vaultAsset: Address, wNative: Address);
|
|
50
|
+
}
|
|
51
|
+
export declare class ChainWNativeMissingError extends Error {
|
|
52
|
+
constructor(chainId: number);
|
|
53
|
+
}
|
|
54
|
+
export declare class NegativeNativeAmountError extends Error {
|
|
55
|
+
constructor(nativeAmount: bigint);
|
|
56
|
+
}
|
|
57
|
+
export declare class ZeroDepositAmountError extends Error {
|
|
58
|
+
constructor(vault: Address);
|
|
59
|
+
}
|
|
60
|
+
export declare class VaultAddressMismatchError extends Error {
|
|
61
|
+
constructor(vaultAddress: Address, argsVaultAddress: Address);
|
|
62
|
+
}
|
|
63
|
+
export declare class NonPositiveBorrowAmountError extends Error {
|
|
64
|
+
constructor(market: string);
|
|
65
|
+
}
|
|
66
|
+
export declare class ZeroCollateralAmountError extends Error {
|
|
67
|
+
constructor(market: string);
|
|
68
|
+
}
|
|
69
|
+
export declare class NativeAmountOnNonWNativeCollateralError extends Error {
|
|
70
|
+
constructor(collateralToken: Address, wNative: Address);
|
|
71
|
+
}
|
|
72
|
+
export declare class BorrowExceedsSafeLtvError extends Error {
|
|
73
|
+
constructor(borrowAmount: bigint, maxSafeBorrow: bigint);
|
|
74
|
+
}
|
|
75
|
+
export declare class MissingMarketPriceError extends Error {
|
|
76
|
+
constructor(market: string);
|
|
77
|
+
}
|
|
78
|
+
export declare class MarketIdMismatchError extends Error {
|
|
79
|
+
constructor(marketId: string, expectedMarketId: string);
|
|
80
|
+
}
|
|
81
|
+
export declare class AccrualPositionUserMismatchError extends Error {
|
|
82
|
+
constructor(positionUser: string, expectedUser: string);
|
|
83
|
+
}
|
|
84
|
+
export declare class NegativeReallocationFeeError extends Error {
|
|
85
|
+
constructor(vault: string);
|
|
86
|
+
}
|
|
87
|
+
export declare class EmptyReallocationWithdrawalsError extends Error {
|
|
88
|
+
constructor(vault: string);
|
|
89
|
+
}
|
|
90
|
+
export declare class NonPositiveReallocationAmountError extends Error {
|
|
91
|
+
constructor(vault: string, market: string);
|
|
92
|
+
}
|
|
93
|
+
export declare class ReallocationWithdrawalOnTargetMarketError extends Error {
|
|
94
|
+
constructor(vault: string, marketId: string);
|
|
95
|
+
}
|
|
96
|
+
export declare class UnsortedReallocationWithdrawalsError extends Error {
|
|
97
|
+
constructor(vault: string, marketId: string);
|
|
98
|
+
}
|
|
99
|
+
export declare class NonPositiveTransferAmountError extends Error {
|
|
100
|
+
constructor(market: string);
|
|
101
|
+
}
|
|
102
|
+
export declare class TransferAmountNotEqualToAssetsError extends Error {
|
|
103
|
+
constructor(params: {
|
|
104
|
+
transferAmount: bigint;
|
|
105
|
+
assets: bigint;
|
|
106
|
+
market: string;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
export declare class MutuallyExclusiveRepayAmountsError extends Error {
|
|
110
|
+
constructor(market: string);
|
|
111
|
+
}
|
|
112
|
+
export declare class NonPositiveRepayAmountError extends Error {
|
|
113
|
+
constructor(market: string);
|
|
114
|
+
}
|
|
115
|
+
export declare class NonPositiveRepayMaxSharePriceError extends Error {
|
|
116
|
+
constructor(market: string);
|
|
117
|
+
}
|
|
118
|
+
export declare class NonPositiveWithdrawCollateralAmountError extends Error {
|
|
119
|
+
constructor(market: string);
|
|
120
|
+
}
|
|
121
|
+
export declare class WithdrawExceedsCollateralError extends Error {
|
|
122
|
+
constructor(params: {
|
|
123
|
+
withdrawAmount: bigint;
|
|
124
|
+
available: bigint;
|
|
125
|
+
market: string;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
export declare class WithdrawMakesPositionUnhealthyError extends Error {
|
|
129
|
+
constructor(params: {
|
|
130
|
+
withdrawAmount: bigint;
|
|
131
|
+
borrowAssets: bigint;
|
|
132
|
+
maxSafeBorrow: bigint;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
export declare class ShareDivideByZeroError extends Error {
|
|
136
|
+
constructor(market: string);
|
|
137
|
+
}
|
|
138
|
+
export declare class RepayExceedsDebtError extends Error {
|
|
139
|
+
constructor(params: {
|
|
140
|
+
repayAmount: bigint;
|
|
141
|
+
debt: bigint;
|
|
142
|
+
market: string;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
export declare class InvalidSignatureError extends Error {
|
|
146
|
+
constructor();
|
|
147
|
+
}
|
|
148
|
+
export declare class RepaySharesExceedDebtError extends Error {
|
|
149
|
+
constructor(params: {
|
|
150
|
+
repayShares: bigint;
|
|
151
|
+
borrowShares: bigint;
|
|
152
|
+
market: string;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
export declare class MissingPublicAllocatorConfigError extends Error {
|
|
156
|
+
constructor(vault: string);
|
|
157
|
+
}
|
|
158
|
+
export declare class NonPositiveMinBorrowSharePriceError extends Error {
|
|
159
|
+
constructor(market: string);
|
|
37
160
|
}
|
package/lib/types/error.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DeallocationsExceedWithdrawError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.
|
|
4
|
-
class
|
|
3
|
+
exports.NonPositiveMinBorrowSharePriceError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DeallocationsExceedWithdrawError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = void 0;
|
|
4
|
+
class NonPositiveAssetAmountError extends Error {
|
|
5
5
|
constructor(origin) {
|
|
6
|
-
super(`Asset amount
|
|
6
|
+
super(`Asset amount must be positive for address ${origin}`);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
exports.
|
|
10
|
-
class
|
|
9
|
+
exports.NonPositiveAssetAmountError = NonPositiveAssetAmountError;
|
|
10
|
+
class NonPositiveSharesAmountError extends Error {
|
|
11
11
|
constructor(vault) {
|
|
12
|
-
super(`Shares amount
|
|
12
|
+
super(`Shares amount must be positive for address: ${vault}`);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
exports.
|
|
16
|
-
class
|
|
15
|
+
exports.NonPositiveSharesAmountError = NonPositiveSharesAmountError;
|
|
16
|
+
class NonPositiveMaxSharePriceError extends Error {
|
|
17
17
|
constructor(vault) {
|
|
18
|
-
super(`Max share price
|
|
18
|
+
super(`Max share price must be positive for vault: ${vault}`);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
exports.
|
|
21
|
+
exports.NonPositiveMaxSharePriceError = NonPositiveMaxSharePriceError;
|
|
22
22
|
class AddressMismatchError extends Error {
|
|
23
23
|
constructor(clientAddress, argsAddress) {
|
|
24
24
|
super(`Address mismatch between client: ${clientAddress} and args: ${argsAddress}`);
|
|
@@ -43,6 +43,18 @@ class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
exports.ApprovalAmountLessThanSpendAmountError = ApprovalAmountLessThanSpendAmountError;
|
|
46
|
+
class NegativeSlippageToleranceError extends Error {
|
|
47
|
+
constructor(slippageTolerance) {
|
|
48
|
+
super(`Slippage tolerance ${slippageTolerance} must not be negative`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.NegativeSlippageToleranceError = NegativeSlippageToleranceError;
|
|
52
|
+
class MissingAccrualPositionError extends Error {
|
|
53
|
+
constructor(market) {
|
|
54
|
+
super(`Accrual position is missing for market: ${market}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.MissingAccrualPositionError = MissingAccrualPositionError;
|
|
46
58
|
class ExcessiveSlippageToleranceError extends Error {
|
|
47
59
|
constructor(slippageTolerance) {
|
|
48
60
|
super(`Slippage tolerance ${slippageTolerance} exceeds maximum allowed (10%)`);
|
|
@@ -68,8 +80,194 @@ class DepositAssetMismatchError extends Error {
|
|
|
68
80
|
}
|
|
69
81
|
exports.DepositAssetMismatchError = DepositAssetMismatchError;
|
|
70
82
|
class DeallocationsExceedWithdrawError extends Error {
|
|
71
|
-
constructor(
|
|
72
|
-
super(`Total deallocated
|
|
83
|
+
constructor(params) {
|
|
84
|
+
super(`Total deallocated amount (${params.totalDeallocated}) exceed withdraw amount (${params.withdrawAmount}) for vault: ${params.vault}`);
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
exports.DeallocationsExceedWithdrawError = DeallocationsExceedWithdrawError;
|
|
88
|
+
class NativeAmountOnNonWNativeVaultError extends Error {
|
|
89
|
+
constructor(vaultAsset, wNative) {
|
|
90
|
+
super(`Cannot use nativeAmount: vault asset ${vaultAsset} is not the wrapped native token ${wNative}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.NativeAmountOnNonWNativeVaultError = NativeAmountOnNonWNativeVaultError;
|
|
94
|
+
class ChainWNativeMissingError extends Error {
|
|
95
|
+
constructor(chainId) {
|
|
96
|
+
super(`Chain ${chainId} does not have a configured wrapped native token (wNative)`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.ChainWNativeMissingError = ChainWNativeMissingError;
|
|
100
|
+
class NegativeNativeAmountError extends Error {
|
|
101
|
+
constructor(nativeAmount) {
|
|
102
|
+
super(`Native amount must not be negative, got ${nativeAmount}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.NegativeNativeAmountError = NegativeNativeAmountError;
|
|
106
|
+
class ZeroDepositAmountError extends Error {
|
|
107
|
+
constructor(vault) {
|
|
108
|
+
super(`Total deposit amount must be positive for vault: ${vault}. Both amount and nativeAmount are zero.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.ZeroDepositAmountError = ZeroDepositAmountError;
|
|
112
|
+
class VaultAddressMismatchError extends Error {
|
|
113
|
+
constructor(vaultAddress, argsVaultAddress) {
|
|
114
|
+
super(`Vault address mismatch between vault: ${vaultAddress} and args: ${argsVaultAddress}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.VaultAddressMismatchError = VaultAddressMismatchError;
|
|
118
|
+
class NonPositiveBorrowAmountError extends Error {
|
|
119
|
+
constructor(market) {
|
|
120
|
+
super(`Borrow amount must be positive for market: ${market}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.NonPositiveBorrowAmountError = NonPositiveBorrowAmountError;
|
|
124
|
+
class ZeroCollateralAmountError extends Error {
|
|
125
|
+
constructor(market) {
|
|
126
|
+
super(`Total collateral amount must be positive for market: ${market}. Both amount and nativeAmount are zero.`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.ZeroCollateralAmountError = ZeroCollateralAmountError;
|
|
130
|
+
class NativeAmountOnNonWNativeCollateralError extends Error {
|
|
131
|
+
constructor(collateralToken, wNative) {
|
|
132
|
+
super(`Cannot use nativeAmount: collateral token ${collateralToken} is not the wrapped native token ${wNative}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.NativeAmountOnNonWNativeCollateralError = NativeAmountOnNonWNativeCollateralError;
|
|
136
|
+
class BorrowExceedsSafeLtvError extends Error {
|
|
137
|
+
constructor(borrowAmount, maxSafeBorrow) {
|
|
138
|
+
super(`Borrow amount ${borrowAmount} exceeds safe maximum ${maxSafeBorrow} (LLTV minus buffer). Reduce borrow or increase collateral.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.BorrowExceedsSafeLtvError = BorrowExceedsSafeLtvError;
|
|
142
|
+
class MissingMarketPriceError extends Error {
|
|
143
|
+
constructor(market) {
|
|
144
|
+
super(`Oracle price unavailable for market ${market}. Cannot validate position health.`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.MissingMarketPriceError = MissingMarketPriceError;
|
|
148
|
+
class MarketIdMismatchError extends Error {
|
|
149
|
+
constructor(marketId, expectedMarketId) {
|
|
150
|
+
super(`Market ${marketId} does not match expected market ${expectedMarketId}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.MarketIdMismatchError = MarketIdMismatchError;
|
|
154
|
+
class AccrualPositionUserMismatchError extends Error {
|
|
155
|
+
constructor(positionUser, expectedUser) {
|
|
156
|
+
super(`Accrual position user ${positionUser} does not match expected user ${expectedUser}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.AccrualPositionUserMismatchError = AccrualPositionUserMismatchError;
|
|
160
|
+
class NegativeReallocationFeeError extends Error {
|
|
161
|
+
constructor(vault) {
|
|
162
|
+
super(`Reallocation fee must not be negative for vault: ${vault}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.NegativeReallocationFeeError = NegativeReallocationFeeError;
|
|
166
|
+
class EmptyReallocationWithdrawalsError extends Error {
|
|
167
|
+
constructor(vault) {
|
|
168
|
+
super(`Reallocation withdrawals list cannot be empty for vault: ${vault}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.EmptyReallocationWithdrawalsError = EmptyReallocationWithdrawalsError;
|
|
172
|
+
class NonPositiveReallocationAmountError extends Error {
|
|
173
|
+
constructor(vault, market) {
|
|
174
|
+
super(`Reallocation withdrawal amount must be positive for vault ${vault} on market ${market}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.NonPositiveReallocationAmountError = NonPositiveReallocationAmountError;
|
|
178
|
+
class ReallocationWithdrawalOnTargetMarketError extends Error {
|
|
179
|
+
constructor(vault, marketId) {
|
|
180
|
+
super(`Reallocation withdrawal cannot include the borrow target market ${marketId} for vault ${vault}.`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.ReallocationWithdrawalOnTargetMarketError = ReallocationWithdrawalOnTargetMarketError;
|
|
184
|
+
class UnsortedReallocationWithdrawalsError extends Error {
|
|
185
|
+
constructor(vault, marketId) {
|
|
186
|
+
super(`Reallocation withdrawals must be strictly sorted by market ID for vault ${vault}. Market ${marketId} is out of order.`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.UnsortedReallocationWithdrawalsError = UnsortedReallocationWithdrawalsError;
|
|
190
|
+
class NonPositiveTransferAmountError extends Error {
|
|
191
|
+
constructor(market) {
|
|
192
|
+
super(`Transfer amount must be positive for market: ${market}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.NonPositiveTransferAmountError = NonPositiveTransferAmountError;
|
|
196
|
+
class TransferAmountNotEqualToAssetsError extends Error {
|
|
197
|
+
constructor(params) {
|
|
198
|
+
super(`Transfer amount ${params.transferAmount} is not equal to repay assets ${params.assets} for market: ${params.market}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.TransferAmountNotEqualToAssetsError = TransferAmountNotEqualToAssetsError;
|
|
202
|
+
class MutuallyExclusiveRepayAmountsError extends Error {
|
|
203
|
+
constructor(market) {
|
|
204
|
+
super(`Exactly one of assets or shares must be non-zero for market: ${market}. Both were provided.`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.MutuallyExclusiveRepayAmountsError = MutuallyExclusiveRepayAmountsError;
|
|
208
|
+
class NonPositiveRepayAmountError extends Error {
|
|
209
|
+
constructor(market) {
|
|
210
|
+
super(`Repay amount must be positive for market: ${market}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.NonPositiveRepayAmountError = NonPositiveRepayAmountError;
|
|
214
|
+
class NonPositiveRepayMaxSharePriceError extends Error {
|
|
215
|
+
constructor(market) {
|
|
216
|
+
super(`Max share price must be positive for market: ${market}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.NonPositiveRepayMaxSharePriceError = NonPositiveRepayMaxSharePriceError;
|
|
220
|
+
class NonPositiveWithdrawCollateralAmountError extends Error {
|
|
221
|
+
constructor(market) {
|
|
222
|
+
super(`Withdraw collateral amount must be positive for market: ${market}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.NonPositiveWithdrawCollateralAmountError = NonPositiveWithdrawCollateralAmountError;
|
|
226
|
+
class WithdrawExceedsCollateralError extends Error {
|
|
227
|
+
constructor(params) {
|
|
228
|
+
super(`Withdraw amount ${params.withdrawAmount} exceeds available collateral ${params.available} for market: ${params.market}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.WithdrawExceedsCollateralError = WithdrawExceedsCollateralError;
|
|
232
|
+
class WithdrawMakesPositionUnhealthyError extends Error {
|
|
233
|
+
constructor(params) {
|
|
234
|
+
super(`Withdrawing ${params.withdrawAmount} collateral would make position unhealthy. Max safe borrow after withdrawal: ${params.maxSafeBorrow}. Actual Borrow assets: ${params.borrowAssets}.`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.WithdrawMakesPositionUnhealthyError = WithdrawMakesPositionUnhealthyError;
|
|
238
|
+
class ShareDivideByZeroError extends Error {
|
|
239
|
+
constructor(market) {
|
|
240
|
+
super(`Share divide by zero error for market: ${market}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.ShareDivideByZeroError = ShareDivideByZeroError;
|
|
244
|
+
class RepayExceedsDebtError extends Error {
|
|
245
|
+
constructor(params) {
|
|
246
|
+
super(`Repay amount ${params.repayAmount} exceeds outstanding debt ${params.debt} for market: ${params.market}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.RepayExceedsDebtError = RepayExceedsDebtError;
|
|
250
|
+
class InvalidSignatureError extends Error {
|
|
251
|
+
constructor() {
|
|
252
|
+
super("Signature verification failed: the signed data does not match the expected signer address");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
exports.InvalidSignatureError = InvalidSignatureError;
|
|
256
|
+
class RepaySharesExceedDebtError extends Error {
|
|
257
|
+
constructor(params) {
|
|
258
|
+
super(`Repay shares ${params.repayShares} exceed outstanding borrow shares ${params.borrowShares} for market: ${params.market}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.RepaySharesExceedDebtError = RepaySharesExceedDebtError;
|
|
262
|
+
class MissingPublicAllocatorConfigError extends Error {
|
|
263
|
+
constructor(vault) {
|
|
264
|
+
super(`Vault ${vault} has no public allocator configured but was selected for reallocation`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
exports.MissingPublicAllocatorConfigError = MissingPublicAllocatorConfigError;
|
|
268
|
+
class NonPositiveMinBorrowSharePriceError extends Error {
|
|
269
|
+
constructor(market) {
|
|
270
|
+
super(`Min share price must be non-negative for market: ${market}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
exports.NonPositiveMinBorrowSharePriceError = NonPositiveMinBorrowSharePriceError;
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { MarketId, MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { PublicAllocatorOptions } from "@morpho-org/simulation-sdk";
|
|
3
|
+
import type { Address } from "viem";
|
|
4
|
+
/** A single withdrawal from a source market within a vault reallocation. */
|
|
5
|
+
export interface ReallocationWithdrawal {
|
|
6
|
+
readonly marketParams: MarketParams;
|
|
7
|
+
readonly amount: bigint;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A computed reallocation for a single vault.
|
|
11
|
+
*
|
|
12
|
+
* Maps 1:1 to a `PublicAllocator.reallocateTo()` call.
|
|
13
|
+
* Withdraws from source markets and supplies to the target market.
|
|
14
|
+
*/
|
|
15
|
+
export interface VaultReallocation {
|
|
16
|
+
readonly vault: Address;
|
|
17
|
+
/** Fee in native token (ETH) paid to the PublicAllocator for this vault. */
|
|
18
|
+
readonly fee: bigint;
|
|
19
|
+
/** Source markets to withdraw from before supplying to the target market. */
|
|
20
|
+
readonly withdrawals: readonly ReallocationWithdrawal[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options for computing vault reallocations via the public allocator.
|
|
24
|
+
*
|
|
25
|
+
* Extends {@link PublicAllocatorOptions} with supply-side utilization targets
|
|
26
|
+
* that determine when reallocation is triggered.
|
|
27
|
+
*/
|
|
28
|
+
export interface ReallocationComputeOptions extends PublicAllocatorOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Per-market target utilization above which the shared liquidity algorithm
|
|
31
|
+
* is triggered (scaled by WAD). Overrides `defaultSupplyTargetUtilization`
|
|
32
|
+
* for the specified market.
|
|
33
|
+
*/
|
|
34
|
+
readonly supplyTargetUtilization?: Record<MarketId, bigint | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* The default target utilization above which the shared liquidity algorithm
|
|
37
|
+
* is triggered (scaled by WAD).
|
|
38
|
+
* @default 90.5% (905000000000000000n)
|
|
39
|
+
*/
|
|
40
|
+
readonly defaultSupplyTargetUtilization?: bigint;
|
|
41
|
+
}
|
package/package.json
CHANGED