@morpho-org/morpho-sdk 10.5.0 → 10.6.0-next.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 +44 -1
- package/lib/cjs/abis.d.ts +794 -1
- package/lib/cjs/abis.js +815 -1
- package/lib/cjs/actions/blue/close.d.ts +169 -0
- package/lib/cjs/actions/blue/close.js +270 -0
- package/lib/cjs/actions/blue/common.js +2 -2
- package/lib/cjs/actions/blue/delever.d.ts +156 -0
- package/lib/cjs/actions/blue/delever.js +223 -0
- package/lib/cjs/actions/blue/index.d.ts +3 -0
- package/lib/cjs/actions/blue/index.js +3 -0
- package/lib/cjs/actions/blue/lever.d.ts +184 -0
- package/lib/cjs/actions/blue/lever.js +272 -0
- package/lib/cjs/actions/blue/leverageIntent.d.ts +65 -0
- package/lib/cjs/actions/blue/leverageIntent.js +103 -0
- package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
- package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.js +59 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirements.js +193 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.js +66 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/blue/index.js +17 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +11 -6
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +29 -5
- package/lib/cjs/addresses.d.ts +1 -1
- package/lib/cjs/addresses.js +6 -1
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/addresses.d.ts +1 -1
- package/lib/cjs/blue/addresses.js +6 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +6 -2
- package/lib/cjs/entities/blue/blue.d.ts +486 -2
- package/lib/cjs/entities/blue/blue.js +529 -34
- package/lib/cjs/entities/index.d.ts +5 -5
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/requirements/assertContractCode.d.ts +0 -23
- package/lib/cjs/entities/requirements/assertContractCode.js +3 -28
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/cjs/entities/vaultV2/vaultV2.js +39 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +120 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +232 -4
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -1
- package/lib/cjs/helpers/constant.d.ts +34 -0
- package/lib/cjs/helpers/constant.js +35 -1
- package/lib/cjs/helpers/deadShares.js +3 -0
- package/lib/cjs/helpers/getZeroExLeverageBundle.d.ts +13 -0
- package/lib/cjs/helpers/getZeroExLeverageBundle.js +27 -0
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +28 -1
- package/lib/cjs/helpers/leverage/index.d.ts +1 -0
- package/lib/cjs/helpers/leverage/index.js +11 -0
- package/lib/cjs/helpers/leverage/limits.d.ts +472 -0
- package/lib/cjs/helpers/leverage/limits.js +715 -0
- package/lib/cjs/helpers/leverage/positionMarket.d.ts +17 -0
- package/lib/cjs/helpers/leverage/positionMarket.js +28 -0
- package/lib/cjs/helpers/leverage/reallocations.d.ts +159 -0
- package/lib/cjs/helpers/leverage/reallocations.js +276 -0
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +4 -0
- package/lib/cjs/helpers/zeroExQuote.d.ts +250 -0
- package/lib/cjs/helpers/zeroExQuote.js +763 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +5 -2
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/reads/assertContractCode.d.ts +25 -0
- package/lib/cjs/reads/assertContractCode.js +30 -0
- package/lib/cjs/reads/fetchZeroExQuote.d.ts +123 -0
- package/lib/cjs/reads/fetchZeroExQuote.js +330 -0
- package/lib/cjs/types/action.d.ts +130 -1
- package/lib/cjs/types/error.d.ts +59 -0
- package/lib/cjs/types/error.js +82 -3
- package/lib/cjs/types/index.d.ts +2 -0
- package/lib/cjs/types/index.js +2 -0
- package/lib/cjs/types/leverageError.d.ts +1552 -0
- package/lib/cjs/types/leverageError.js +1711 -0
- package/lib/cjs/types/zeroEx.d.ts +171 -0
- package/lib/cjs/types/zeroEx.js +2 -0
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +794 -1
- package/lib/esm/abis.js +810 -1
- package/lib/esm/actions/blue/close.d.ts +169 -0
- package/lib/esm/actions/blue/close.js +266 -0
- package/lib/esm/actions/blue/common.js +3 -3
- package/lib/esm/actions/blue/delever.d.ts +156 -0
- package/lib/esm/actions/blue/delever.js +219 -0
- package/lib/esm/actions/blue/index.d.ts +3 -0
- package/lib/esm/actions/blue/index.js +3 -0
- package/lib/esm/actions/blue/lever.d.ts +184 -0
- package/lib/esm/actions/blue/lever.js +268 -0
- package/lib/esm/actions/blue/leverageIntent.d.ts +65 -0
- package/lib/esm/actions/blue/leverageIntent.js +96 -0
- package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
- package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.js +55 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirements.js +189 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.js +62 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +3 -0
- package/lib/esm/actions/requirements/blue/index.js +3 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +11 -6
- package/lib/esm/actions/requirements/getRequirementsApproval.js +29 -5
- package/lib/esm/addresses.d.ts +1 -1
- package/lib/esm/addresses.js +1 -1
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/addresses.d.ts +1 -1
- package/lib/esm/blue/addresses.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +486 -2
- package/lib/esm/entities/blue/blue.js +501 -6
- package/lib/esm/entities/index.d.ts +5 -5
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/requirements/assertContractCode.d.ts +0 -23
- package/lib/esm/entities/requirements/assertContractCode.js +1 -25
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/esm/entities/vaultV2/vaultV2.js +40 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +120 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +233 -5
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/constant.d.ts +34 -0
- package/lib/esm/helpers/constant.js +34 -0
- package/lib/esm/helpers/deadShares.js +4 -1
- package/lib/esm/helpers/getZeroExLeverageBundle.d.ts +13 -0
- package/lib/esm/helpers/getZeroExLeverageBundle.js +23 -0
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- package/lib/esm/helpers/leverage/index.d.ts +1 -0
- package/lib/esm/helpers/leverage/index.js +1 -0
- package/lib/esm/helpers/leverage/limits.d.ts +472 -0
- package/lib/esm/helpers/leverage/limits.js +705 -0
- package/lib/esm/helpers/leverage/positionMarket.d.ts +17 -0
- package/lib/esm/helpers/leverage/positionMarket.js +24 -0
- package/lib/esm/helpers/leverage/reallocations.d.ts +159 -0
- package/lib/esm/helpers/leverage/reallocations.js +271 -0
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +5 -1
- package/lib/esm/helpers/zeroExQuote.d.ts +250 -0
- package/lib/esm/helpers/zeroExQuote.js +754 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/reads/assertContractCode.d.ts +25 -0
- package/lib/esm/reads/assertContractCode.js +26 -0
- package/lib/esm/reads/fetchZeroExQuote.d.ts +123 -0
- package/lib/esm/reads/fetchZeroExQuote.js +326 -0
- package/lib/esm/types/action.d.ts +130 -1
- package/lib/esm/types/error.d.ts +59 -0
- package/lib/esm/types/error.js +76 -0
- package/lib/esm/types/index.d.ts +2 -0
- package/lib/esm/types/index.js +2 -0
- package/lib/esm/types/leverageError.d.ts +1552 -0
- package/lib/esm/types/leverageError.js +1660 -0
- package/lib/esm/types/zeroEx.d.ts +171 -0
- package/lib/esm/types/zeroEx.js +1 -0
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,1552 @@
|
|
|
1
|
+
import type { MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address, Hex } from "viem";
|
|
3
|
+
type LeverageOperation = "lever" | "delever" | "close";
|
|
4
|
+
/**
|
|
5
|
+
* Base class for leverage refusals caused by an unusable 0x quote or swap calldata.
|
|
6
|
+
* Fallback: fetch a new 0x quote and build again, except for five errors a new quote alone does not clear:
|
|
7
|
+
* {@link ZeroExExactOutputUnsupportedError}, refused before any request for a
|
|
8
|
+
* native and wrapped-native exact-output pair, {@link ZeroExQuoteNoLiquidityError}, which calls for a smaller
|
|
9
|
+
* amount or a no-swap exit, {@link ZeroExQuoteRequestError}, which a retry clears only when no response arrived,
|
|
10
|
+
* a 2xx response's body failed to download, or 0x answered 429 or 5xx, {@link ZeroExUnknownSwapKindError}, refused for an invalid action kind, and
|
|
11
|
+
* {@link ZeroExInvalidTxOriginError}, refused for a malformed `txOrigin`. Handle them before the generic requote
|
|
12
|
+
* branch. The leverage builders never throw {@link ZeroExSettlerPausedError} or {@link ZeroExSettlerNotOfficialError}:
|
|
13
|
+
* the `@morpho-org/evm-simulation` 0x Settler registry check reports the same conditions as non-blocking
|
|
14
|
+
* `ZERO_EX_SETTLER_UNVERIFIED` entries in `report.warnings`, with `reason` `"paused"` or `"notOfficial"`, read from
|
|
15
|
+
* the registry at the simulation block. The simulation still runs, and it returns no instance of these classes: read
|
|
16
|
+
* the warning's `code` and `reason`, not `instanceof`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import {
|
|
21
|
+
* ZeroExExactOutputUnsupportedError,
|
|
22
|
+
* ZeroExInvalidTxOriginError,
|
|
23
|
+
* ZeroExQuoteChainMismatchError,
|
|
24
|
+
* ZeroExQuoteError,
|
|
25
|
+
* ZeroExQuoteNoLiquidityError,
|
|
26
|
+
* ZeroExQuoteRequestError,
|
|
27
|
+
* ZeroExQuoteShortTimeBoundError,
|
|
28
|
+
* ZeroExUnknownSwapKindError,
|
|
29
|
+
* } from "@morpho-org/morpho-sdk";
|
|
30
|
+
*
|
|
31
|
+
* const controller = new AbortController(); // the caller aborts it to cancel the quote request
|
|
32
|
+
*
|
|
33
|
+
* function build(): never {
|
|
34
|
+
* throw new ZeroExQuoteChainMismatchError({ expected: 1, actual: 8453 });
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* try {
|
|
38
|
+
* build();
|
|
39
|
+
* } catch (error) {
|
|
40
|
+
* if (controller.signal.aborted) {
|
|
41
|
+
* // The caller cancelled the request (a fetch then fails with status null): do not retry.
|
|
42
|
+
* } else if (error instanceof ZeroExExactOutputUnsupportedError) {
|
|
43
|
+
* // 0x cannot buy an exact amount across a native and wrapped-native pair: offer an exit that needs no swap.
|
|
44
|
+
* } else if (error instanceof ZeroExQuoteNoLiquidityError) {
|
|
45
|
+
* // 0x has no route for this size: offer a smaller amount or an exit that needs no swap.
|
|
46
|
+
* } else if (
|
|
47
|
+
* error instanceof ZeroExQuoteRequestError &&
|
|
48
|
+
* error.status !== null &&
|
|
49
|
+
* error.status !== 429 &&
|
|
50
|
+
* error.status < 500
|
|
51
|
+
* ) {
|
|
52
|
+
* // 0x refused the request itself: fix the API key or the request; requoting hits the same refusal.
|
|
53
|
+
* } else if (error instanceof ZeroExUnknownSwapKindError) {
|
|
54
|
+
* // Fix the action kind; requoting hits the same refusal.
|
|
55
|
+
* } else if (error instanceof ZeroExInvalidTxOriginError) {
|
|
56
|
+
* // Pass a valid txOrigin, or omit it; requoting hits the same refusal.
|
|
57
|
+
* } else if (error instanceof ZeroExQuoteShortTimeBoundError) {
|
|
58
|
+
* // Fetch a new 0x quote; if the same word is refused again, offer a different amount, retry later or an exit
|
|
59
|
+
* // that needs no swap.
|
|
60
|
+
* } else if (error instanceof ZeroExQuoteError) {
|
|
61
|
+
* // Fetch a new 0x quote and build again.
|
|
62
|
+
* } else {
|
|
63
|
+
* throw error;
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare abstract class ZeroExQuoteError extends Error {
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Base class for leverage refusals where the action is unsafe at current prices or outside an SDK bound.
|
|
72
|
+
* Fallback: offer a no-swap exit (`repay` or `supplyCollateral`), a smaller action or a new quote. Five
|
|
73
|
+
* subclasses are exceptions: for {@link LeverageSlippageAboveLimitError}, the limit depends on neither the size
|
|
74
|
+
* nor the quote, so lower the slippage to `error.max` or less and build again, fetching a new quote with that
|
|
75
|
+
* slippage. For {@link LeverageCloseEmptyPositionError}, the position holds nothing, so there is no transaction to
|
|
76
|
+
* offer: tell the user there is nothing to close. For {@link LeverageCloseWithoutDebtError}, the position has
|
|
77
|
+
* collateral but no debt: offer `withdrawCollateral` instead. For {@link LeverageUnsupportedChainError},
|
|
78
|
+
* leverage is not available on the chain: offer only the no-swap actions, if Blue is available on the chain. For
|
|
79
|
+
* {@link LeverageOraclePriceUnavailableError}, the market has no usable oracle price, so a smaller action or a new
|
|
80
|
+
* quote fails the same way: on a Lever, read the leverage data again once the oracle answers; on a Delever or a
|
|
81
|
+
* Close, offer only the no-swap exits.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import {
|
|
86
|
+
* InsufficientSharedLiquidityError,
|
|
87
|
+
* LeverageCloseEmptyPositionError,
|
|
88
|
+
* LeverageCloseWithoutDebtError,
|
|
89
|
+
* LeverageLimitError,
|
|
90
|
+
* LeverageOraclePriceUnavailableError,
|
|
91
|
+
* LeverageSlippageAboveLimitError,
|
|
92
|
+
* LeverageUnsupportedChainError,
|
|
93
|
+
* } from "@morpho-org/morpho-sdk";
|
|
94
|
+
*
|
|
95
|
+
* function build(): never {
|
|
96
|
+
* throw new LeverageSlippageAboveLimitError({
|
|
97
|
+
* operation: "lever",
|
|
98
|
+
* slippage: 20_000_000_000_000_000n,
|
|
99
|
+
* max: 10_000_000_000_000_000n,
|
|
100
|
+
* });
|
|
101
|
+
* }
|
|
102
|
+
*
|
|
103
|
+
* try {
|
|
104
|
+
* build();
|
|
105
|
+
* } catch (error) {
|
|
106
|
+
* if (error instanceof LeverageSlippageAboveLimitError) {
|
|
107
|
+
* // Lower the slippage to error.max or less and build again; fetch a new quote only if the action swaps.
|
|
108
|
+
* } else if (error instanceof LeverageCloseEmptyPositionError) {
|
|
109
|
+
* // Nothing to close: tell the user instead of offering another transaction.
|
|
110
|
+
* } else if (error instanceof LeverageCloseWithoutDebtError) {
|
|
111
|
+
* // Collateral but no debt: offer withdrawCollateral instead of a Close.
|
|
112
|
+
* } else if (error instanceof LeverageUnsupportedChainError) {
|
|
113
|
+
* // No leverage on this chain: if Blue is available here, offer repay, supplyCollateral or withdrawCollateral.
|
|
114
|
+
* } else if (error instanceof LeverageOraclePriceUnavailableError) {
|
|
115
|
+
* // No oracle price: on a Lever, read the leverage data again once the oracle answers; on a Delever or a
|
|
116
|
+
* // Close, offer only repay, supplyCollateral or repayWithdrawCollateral.
|
|
117
|
+
* } else if (error instanceof LeverageLimitError) {
|
|
118
|
+
* // Offer a smaller action, a no-swap exit or a new quote.
|
|
119
|
+
* } else if (error instanceof InsufficientSharedLiquidityError) {
|
|
120
|
+
* // Outside this base: a Lever's planned reallocations cannot fund the borrow, the shortfall the pure
|
|
121
|
+
* // builder reports as LeverageInsufficientLiquidityError. Offer a smaller Lever or other reallocations.
|
|
122
|
+
* } else {
|
|
123
|
+
* throw error;
|
|
124
|
+
* }
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare abstract class LeverageLimitError extends Error {
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Base class for leverage refusals caused by an unsafe public-allocator liquidity route.
|
|
132
|
+
* Fallback: drop or replace the reallocations and build again.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import {
|
|
137
|
+
* InconsistentReallocationPenaltyError,
|
|
138
|
+
* LeverageReallocationError,
|
|
139
|
+
* LeverageReallocationExceedsBorrowError,
|
|
140
|
+
* ReallocationLoanTokenMismatchError,
|
|
141
|
+
* ReallocationWithdrawalOnTargetMarketError,
|
|
142
|
+
* } from "@morpho-org/morpho-sdk";
|
|
143
|
+
*
|
|
144
|
+
* function build(): never {
|
|
145
|
+
* throw new LeverageReallocationExceedsBorrowError({
|
|
146
|
+
* total: 101n,
|
|
147
|
+
* maxBorrowAssets: 100n,
|
|
148
|
+
* });
|
|
149
|
+
* }
|
|
150
|
+
*
|
|
151
|
+
* try {
|
|
152
|
+
* build();
|
|
153
|
+
* } catch (error) {
|
|
154
|
+
* // Three existing classes outside this base also call for other reallocations: a penalty that differs
|
|
155
|
+
* // from the vault's configured one, a source market with another loan token, and a source that is
|
|
156
|
+
* // the Lever's own market.
|
|
157
|
+
* if (
|
|
158
|
+
* !(error instanceof LeverageReallocationError) &&
|
|
159
|
+
* !(error instanceof InconsistentReallocationPenaltyError) &&
|
|
160
|
+
* !(error instanceof ReallocationLoanTokenMismatchError) &&
|
|
161
|
+
* !(error instanceof ReallocationWithdrawalOnTargetMarketError)
|
|
162
|
+
* ) {
|
|
163
|
+
* throw error;
|
|
164
|
+
* }
|
|
165
|
+
* // Build again with other reallocations or none.
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare abstract class LeverageReallocationError extends Error {
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Thrown when a 0x quote was built for another chain than the leverage action's market.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { ZeroExQuoteChainMismatchError } from "@morpho-org/morpho-sdk";
|
|
177
|
+
*
|
|
178
|
+
* const error = new ZeroExQuoteChainMismatchError({ expected: 1, actual: 8453 });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export declare class ZeroExQuoteChainMismatchError extends ZeroExQuoteError {
|
|
182
|
+
/**
|
|
183
|
+
* @param params - Chain comparison.
|
|
184
|
+
* @param params.expected - Chain id of the action's market.
|
|
185
|
+
* @param params.actual - Chain id of the quote.
|
|
186
|
+
*/
|
|
187
|
+
constructor(params: {
|
|
188
|
+
readonly expected: number;
|
|
189
|
+
readonly actual: number;
|
|
190
|
+
});
|
|
191
|
+
/** Chain id of the action's market. */
|
|
192
|
+
readonly expected: number;
|
|
193
|
+
/** Chain id of the quote. */
|
|
194
|
+
readonly actual: number;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Thrown when a 0x quote sells or buys another token than the leverage action swaps, in its `sellToken` or `buyToken`
|
|
198
|
+
* field or in its calldata: the AllowanceHolder sell token or Settler's buy token.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* import { ZeroExQuoteTokenMismatchError } from "@morpho-org/morpho-sdk";
|
|
203
|
+
*
|
|
204
|
+
* const error = new ZeroExQuoteTokenMismatchError({
|
|
205
|
+
* field: "sellToken",
|
|
206
|
+
* expected: weth,
|
|
207
|
+
* actual: quotedSellToken,
|
|
208
|
+
* });
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export declare class ZeroExQuoteTokenMismatchError extends ZeroExQuoteError {
|
|
212
|
+
/**
|
|
213
|
+
* @param params - Token comparison.
|
|
214
|
+
* @param params.field - Swap side that differs: the input (`sellToken`) or output (`buyToken`), in the quote's fields or
|
|
215
|
+
* its calldata.
|
|
216
|
+
* @param params.expected - Token the action swaps on that side.
|
|
217
|
+
* @param params.actual - Token the quote's fields or calldata use on that side.
|
|
218
|
+
*/
|
|
219
|
+
constructor(params: {
|
|
220
|
+
readonly field: "sellToken" | "buyToken";
|
|
221
|
+
readonly expected: Address;
|
|
222
|
+
readonly actual: Address;
|
|
223
|
+
});
|
|
224
|
+
/** Swap side that differs, in the quote's fields or its calldata. */
|
|
225
|
+
readonly field: "sellToken" | "buyToken";
|
|
226
|
+
/** Token the action swaps on that side. */
|
|
227
|
+
readonly expected: Address;
|
|
228
|
+
/** Token the quote's fields or calldata use on that side. */
|
|
229
|
+
readonly actual: Address;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Thrown when a 0x quote fixes the wrong side of the swap for the leverage action:
|
|
233
|
+
* Lever and Close need an exact-output (`buyAmount`) quote, Delever an exact-input
|
|
234
|
+
* (`sellAmount`) quote.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* import { ZeroExQuoteTypeMismatchError } from "@morpho-org/morpho-sdk";
|
|
239
|
+
*
|
|
240
|
+
* const error = new ZeroExQuoteTypeMismatchError({
|
|
241
|
+
* expected: "exactOutput",
|
|
242
|
+
* actual: "exactInput",
|
|
243
|
+
* });
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export declare class ZeroExQuoteTypeMismatchError extends ZeroExQuoteError {
|
|
247
|
+
/**
|
|
248
|
+
* @param params - Quote type comparison.
|
|
249
|
+
* @param params.expected - Quote type the action requires.
|
|
250
|
+
* @param params.actual - Quote type supplied.
|
|
251
|
+
*/
|
|
252
|
+
constructor(params: {
|
|
253
|
+
readonly expected: "exactInput" | "exactOutput";
|
|
254
|
+
readonly actual: "exactInput" | "exactOutput";
|
|
255
|
+
});
|
|
256
|
+
/** Quote type the action requires. */
|
|
257
|
+
readonly expected: "exactInput" | "exactOutput";
|
|
258
|
+
/** Quote type supplied. */
|
|
259
|
+
readonly actual: "exactInput" | "exactOutput";
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Thrown when a 0x quote's taker is not the leverage bundle that executes the swap.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* import { ZeroExQuoteTakerMismatchError } from "@morpho-org/morpho-sdk";
|
|
267
|
+
*
|
|
268
|
+
* const error = new ZeroExQuoteTakerMismatchError({
|
|
269
|
+
* expected: zeroExLeverageBundle,
|
|
270
|
+
* actual: quotedTaker,
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
export declare class ZeroExQuoteTakerMismatchError extends ZeroExQuoteError {
|
|
275
|
+
/**
|
|
276
|
+
* @param params - Taker comparison.
|
|
277
|
+
* @param params.expected - Leverage bundle address.
|
|
278
|
+
* @param params.actual - Taker the quote was built for.
|
|
279
|
+
*/
|
|
280
|
+
constructor(params: {
|
|
281
|
+
readonly expected: Address;
|
|
282
|
+
readonly actual: Address;
|
|
283
|
+
});
|
|
284
|
+
/** Leverage bundle address. */
|
|
285
|
+
readonly expected: Address;
|
|
286
|
+
/** Taker the quote was built for. */
|
|
287
|
+
readonly actual: Address;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Thrown when a 0x quote's transaction carries native value; leverage swaps are ERC-20 only.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* import { ZeroExQuoteNonZeroValueError } from "@morpho-org/morpho-sdk";
|
|
295
|
+
*
|
|
296
|
+
* const error = new ZeroExQuoteNonZeroValueError(1n);
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
export declare class ZeroExQuoteNonZeroValueError extends ZeroExQuoteError {
|
|
300
|
+
readonly value: bigint;
|
|
301
|
+
/**
|
|
302
|
+
* @param value - Native value carried by the quote's transaction.
|
|
303
|
+
*/
|
|
304
|
+
constructor(value: bigint);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Thrown when a 0x quote's transaction does not call the chain's AllowanceHolder.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* import { ZeroExQuoteTargetMismatchError } from "@morpho-org/morpho-sdk";
|
|
312
|
+
* import { ZERO_EX_ALLOWANCE_HOLDER_ADDRESS } from "@morpho-org/morpho-sdk/addresses";
|
|
313
|
+
*
|
|
314
|
+
* const error = new ZeroExQuoteTargetMismatchError({
|
|
315
|
+
* expected: ZERO_EX_ALLOWANCE_HOLDER_ADDRESS,
|
|
316
|
+
* actual: quotedTarget,
|
|
317
|
+
* });
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export declare class ZeroExQuoteTargetMismatchError extends ZeroExQuoteError {
|
|
321
|
+
/**
|
|
322
|
+
* @param params - Transaction target comparison.
|
|
323
|
+
* @param params.expected - AllowanceHolder address.
|
|
324
|
+
* @param params.actual - Address the quote's transaction calls.
|
|
325
|
+
*/
|
|
326
|
+
constructor(params: {
|
|
327
|
+
readonly expected: Address;
|
|
328
|
+
readonly actual: Address;
|
|
329
|
+
});
|
|
330
|
+
/** AllowanceHolder address. */
|
|
331
|
+
readonly expected: Address;
|
|
332
|
+
/** Address the quote's transaction calls. */
|
|
333
|
+
readonly actual: Address;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Raised when the AllowanceHolder call's operator is not a Settler the 0x registry names for the taker
|
|
337
|
+
* feature (current, or previous during rotation). The leverage builders never throw it: the
|
|
338
|
+
* `@morpho-org/evm-simulation` 0x Settler registry check reports the same condition as a non-blocking
|
|
339
|
+
* `ZERO_EX_SETTLER_UNVERIFIED` entry in `report.warnings` with `reason: "notOfficial"`, from the registry state at
|
|
340
|
+
* the simulation block, not as an instance of this class; the simulation still runs. A new quote clears it once the registry names an eligible
|
|
341
|
+
* Settler; reading the leverage data again does not, because the leverage data holds no registry state.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* import { ZeroExSettlerNotOfficialError } from "@morpho-org/morpho-sdk";
|
|
346
|
+
*
|
|
347
|
+
* const error = new ZeroExSettlerNotOfficialError({
|
|
348
|
+
* field: "operator",
|
|
349
|
+
* actual: quotedOperator,
|
|
350
|
+
* official: [currentSettler],
|
|
351
|
+
* });
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
export declare class ZeroExSettlerNotOfficialError extends ZeroExQuoteError {
|
|
355
|
+
/**
|
|
356
|
+
* @param params - Settler comparison.
|
|
357
|
+
* @param params.field - AllowanceHolder `exec` argument that differs.
|
|
358
|
+
* @param params.actual - Address found in the calldata.
|
|
359
|
+
* @param params.official - Settlers the registry accepts at the block it was read.
|
|
360
|
+
*/
|
|
361
|
+
constructor(params: {
|
|
362
|
+
readonly field: "operator";
|
|
363
|
+
readonly actual: Address;
|
|
364
|
+
readonly official: readonly Address[];
|
|
365
|
+
});
|
|
366
|
+
/** AllowanceHolder `exec` argument that differs. */
|
|
367
|
+
readonly field: "operator";
|
|
368
|
+
/** Address found in the calldata. */
|
|
369
|
+
readonly actual: Address;
|
|
370
|
+
/** Settlers the registry accepts at the block it was read. */
|
|
371
|
+
readonly official: readonly Address[];
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Thrown when the AllowanceHolder call's target is not its operator: an address mismatch only. Neither
|
|
375
|
+
* address is checked against the 0x Settler registry here, so this refusal says nothing about whether the
|
|
376
|
+
* operator is an official Settler. Fetch a new quote.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* import { ZeroExSettlerOperatorTargetMismatchError } from "@morpho-org/morpho-sdk";
|
|
381
|
+
*
|
|
382
|
+
* const error = new ZeroExSettlerOperatorTargetMismatchError({
|
|
383
|
+
* operator: currentSettler,
|
|
384
|
+
* target: previousSettler,
|
|
385
|
+
* });
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
export declare class ZeroExSettlerOperatorTargetMismatchError extends ZeroExQuoteError {
|
|
389
|
+
/**
|
|
390
|
+
* @param params - AllowanceHolder `exec` arguments.
|
|
391
|
+
* @param params.operator - Settler AllowanceHolder approves for the swap.
|
|
392
|
+
* @param params.target - Contract AllowanceHolder calls.
|
|
393
|
+
*/
|
|
394
|
+
constructor(params: {
|
|
395
|
+
readonly operator: Address;
|
|
396
|
+
readonly target: Address;
|
|
397
|
+
});
|
|
398
|
+
/** Settler AllowanceHolder approves for the swap. */
|
|
399
|
+
readonly operator: Address;
|
|
400
|
+
/** Contract AllowanceHolder calls. */
|
|
401
|
+
readonly target: Address;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Raised when the 0x registry lookup for the taker Settler reverts, which means 0x paused it. The leverage
|
|
405
|
+
* builders never throw it: the `@morpho-org/evm-simulation` 0x Settler registry check reports the same condition as
|
|
406
|
+
* a non-blocking `ZERO_EX_SETTLER_UNVERIFIED` entry in `report.warnings` with `reason: "paused"`, from the registry
|
|
407
|
+
* state at the simulation block, not as an instance of this class; the simulation still runs. Unlike the other
|
|
408
|
+
* {@link ZeroExQuoteError} subclasses, a new quote cannot clear it. Offer the no-swap exits instead (`repay`,
|
|
409
|
+
* `supplyCollateral`, `repayWithdrawCollateral`), or retry the swap once the registry shows 0x resumed it.
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```ts
|
|
413
|
+
* import { ZeroExSettlerPausedError } from "@morpho-org/morpho-sdk";
|
|
414
|
+
* import { ZERO_EX_SETTLER_REGISTRY_ADDRESS } from "@morpho-org/morpho-sdk/addresses";
|
|
415
|
+
*
|
|
416
|
+
* const error = new ZeroExSettlerPausedError({
|
|
417
|
+
* registry: ZERO_EX_SETTLER_REGISTRY_ADDRESS,
|
|
418
|
+
* });
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
export declare class ZeroExSettlerPausedError extends ZeroExQuoteError {
|
|
422
|
+
/**
|
|
423
|
+
* @param params - Registry details.
|
|
424
|
+
* @param params.registry - 0x Settler registry address whose lookup reverted.
|
|
425
|
+
* @param options - Standard error options; `cause` carries the revert.
|
|
426
|
+
*/
|
|
427
|
+
constructor(params: {
|
|
428
|
+
readonly registry: Address;
|
|
429
|
+
}, options?: ErrorOptions);
|
|
430
|
+
/** 0x Settler registry address whose lookup reverted. */
|
|
431
|
+
readonly registry: Address;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Thrown when the 0x swap pays its output to anyone but the leverage bundle.
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```ts
|
|
438
|
+
* import { ZeroExQuoteRecipientMismatchError } from "@morpho-org/morpho-sdk";
|
|
439
|
+
*
|
|
440
|
+
* const error = new ZeroExQuoteRecipientMismatchError({
|
|
441
|
+
* expected: zeroExLeverageBundle,
|
|
442
|
+
* actual: quotedRecipient,
|
|
443
|
+
* });
|
|
444
|
+
* ```
|
|
445
|
+
*/
|
|
446
|
+
export declare class ZeroExQuoteRecipientMismatchError extends ZeroExQuoteError {
|
|
447
|
+
/**
|
|
448
|
+
* @param params - Recipient comparison.
|
|
449
|
+
* @param params.expected - Leverage bundle address.
|
|
450
|
+
* @param params.actual - Recipient found in the swap calldata. A zero recipient means the Settler slippage is only
|
|
451
|
+
* partly zero (a nonzero buy token or minimum output), since only an all-zero slippage skips the recipient check;
|
|
452
|
+
* the message says so.
|
|
453
|
+
*/
|
|
454
|
+
constructor(params: {
|
|
455
|
+
readonly expected: Address;
|
|
456
|
+
readonly actual: Address;
|
|
457
|
+
});
|
|
458
|
+
/** Leverage bundle address. */
|
|
459
|
+
readonly expected: Address;
|
|
460
|
+
/** Recipient found in the swap calldata. */
|
|
461
|
+
readonly actual: Address;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Thrown when the amount the AllowanceHolder call may pull exceeds the action's swap input cap.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```ts
|
|
468
|
+
* import { ZeroExQuoteAmountExceedsCapError } from "@morpho-org/morpho-sdk";
|
|
469
|
+
*
|
|
470
|
+
* const error = new ZeroExQuoteAmountExceedsCapError({ amount: 101n, cap: 100n });
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
export declare class ZeroExQuoteAmountExceedsCapError extends ZeroExQuoteError {
|
|
474
|
+
/**
|
|
475
|
+
* @param params - Amount comparison.
|
|
476
|
+
* @param params.amount - Amount in the AllowanceHolder `exec` call.
|
|
477
|
+
* @param params.cap - Largest swap input the action signs.
|
|
478
|
+
*/
|
|
479
|
+
constructor(params: {
|
|
480
|
+
readonly amount: bigint;
|
|
481
|
+
readonly cap: bigint;
|
|
482
|
+
});
|
|
483
|
+
/** Amount in the AllowanceHolder `exec` call. */
|
|
484
|
+
readonly amount: bigint;
|
|
485
|
+
/** Largest swap input the action signs. */
|
|
486
|
+
readonly cap: bigint;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Thrown when the amount the AllowanceHolder call pulls is not the amount the quote sells: `sellAmount` for an
|
|
490
|
+
* exact-input quote, `maxSellAmount` for an exact-output quote. The calldata does not match the quote's amounts.
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```ts
|
|
494
|
+
* import { ZeroExQuoteSellAmountMismatchError } from "@morpho-org/morpho-sdk";
|
|
495
|
+
*
|
|
496
|
+
* const error = new ZeroExQuoteSellAmountMismatchError({ expected: 100n, actual: 99n });
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
export declare class ZeroExQuoteSellAmountMismatchError extends ZeroExQuoteError {
|
|
500
|
+
/**
|
|
501
|
+
* @param params - Amount comparison.
|
|
502
|
+
* @param params.expected - Sell amount the quote reports.
|
|
503
|
+
* @param params.actual - Amount in the AllowanceHolder `exec` call.
|
|
504
|
+
*/
|
|
505
|
+
constructor(params: {
|
|
506
|
+
readonly expected: bigint;
|
|
507
|
+
readonly actual: bigint;
|
|
508
|
+
});
|
|
509
|
+
/** Sell amount the quote reports. */
|
|
510
|
+
readonly expected: bigint;
|
|
511
|
+
/** Amount in the AllowanceHolder `exec` call. */
|
|
512
|
+
readonly actual: bigint;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Thrown when the Settler `execute` slippage asks for a minimum output that is zero or below the quote's own floor:
|
|
516
|
+
* `minBuyAmount` for an exact-input quote, `buyAmount` for an exact-output quote. An all-zero slippage struct is not
|
|
517
|
+
* this error: Settler then checks nothing and the bundle's onchain output check protects the swap.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```ts
|
|
521
|
+
* import { ZeroExQuoteMinAmountOutMismatchError } from "@morpho-org/morpho-sdk";
|
|
522
|
+
*
|
|
523
|
+
* const error = new ZeroExQuoteMinAmountOutMismatchError({ expected: 100n, actual: 0n });
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
export declare class ZeroExQuoteMinAmountOutMismatchError extends ZeroExQuoteError {
|
|
527
|
+
/**
|
|
528
|
+
* @param params - Minimum output comparison.
|
|
529
|
+
* @param params.expected - Smallest minimum output the quote allows.
|
|
530
|
+
* @param params.actual - Minimum output in the Settler `execute` slippage.
|
|
531
|
+
*/
|
|
532
|
+
constructor(params: {
|
|
533
|
+
readonly expected: bigint;
|
|
534
|
+
readonly actual: bigint;
|
|
535
|
+
});
|
|
536
|
+
/** Smallest minimum output the quote allows. */
|
|
537
|
+
readonly expected: bigint;
|
|
538
|
+
/** Minimum output in the Settler `execute` slippage. */
|
|
539
|
+
readonly actual: bigint;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Thrown when a Delever quote's `minBuyAmount` is zero or below `buyAmount × (1 − slippage)`, with the caller's
|
|
543
|
+
* slippage rounded down to whole parts per million as 0x rounds it. The Delever signs the quote's `minBuyAmount`
|
|
544
|
+
* as is, so a lower floor would let the swap lose more than the caller's slippage. 0x builds its floor from the
|
|
545
|
+
* slippage it was sent: fetch a new quote with the caller's slippage.
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```ts
|
|
549
|
+
* import { ZeroExQuoteMinBuyAmountBelowSlippageError } from "@morpho-org/morpho-sdk";
|
|
550
|
+
*
|
|
551
|
+
* const error = new ZeroExQuoteMinBuyAmountBelowSlippageError({
|
|
552
|
+
* buyAmount: 1_658_936n,
|
|
553
|
+
* minBuyAmount: 1_650_640n,
|
|
554
|
+
* slippage: 5_000_000_000_000_000n,
|
|
555
|
+
* slippageFloor: 1_650_641n,
|
|
556
|
+
* });
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
export declare class ZeroExQuoteMinBuyAmountBelowSlippageError extends ZeroExQuoteError {
|
|
560
|
+
/**
|
|
561
|
+
* @param params - Floor comparison, in the buy token's smallest unit.
|
|
562
|
+
* @param params.buyAmount - Quote's expected output before slippage.
|
|
563
|
+
* @param params.minBuyAmount - Quote's minimum output.
|
|
564
|
+
* @param params.slippage - Slippage supplied by the caller, WAD-scaled.
|
|
565
|
+
* @param params.slippageFloor - Smallest `minBuyAmount` the caller's slippage accepts: `buyAmount` reduced by
|
|
566
|
+
* the slippage rounded down to whole parts per million, rounded down.
|
|
567
|
+
*/
|
|
568
|
+
constructor(params: {
|
|
569
|
+
readonly buyAmount: bigint;
|
|
570
|
+
readonly minBuyAmount: bigint;
|
|
571
|
+
readonly slippage: bigint;
|
|
572
|
+
readonly slippageFloor: bigint;
|
|
573
|
+
});
|
|
574
|
+
/** Quote's expected output before slippage. */
|
|
575
|
+
readonly buyAmount: bigint;
|
|
576
|
+
/** Quote's minimum output. */
|
|
577
|
+
readonly minBuyAmount: bigint;
|
|
578
|
+
/** Slippage supplied by the caller, WAD-scaled. */
|
|
579
|
+
readonly slippage: bigint;
|
|
580
|
+
/** Smallest `minBuyAmount` the caller's slippage accepts. */
|
|
581
|
+
readonly slippageFloor: bigint;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Thrown when 0x quote calldata decodes as a call the leverage bundle cannot run, such as a Settler entry point
|
|
585
|
+
* other than the taker-submitted `execute` (`executeWithPermit` or a metatransaction). It is also thrown for a
|
|
586
|
+
* Settler `SELECT` that does not decode or is nested more than three levels deep, since its candidates would go
|
|
587
|
+
* unchecked, and for a time-bound action (`BASIC`, `BASIC_PUSH`, a permit action, `NATIVE_CHECK` or `ATTEST`) too
|
|
588
|
+
* short or malformed to read. `validateZeroExQuote` throws {@link ZeroExQuoteUndecodableCalldataError} instead for a
|
|
589
|
+
* calldata layer that does not decode at all.
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts
|
|
593
|
+
* import { ZeroExQuoteMalformedCalldataError } from "@morpho-org/morpho-sdk";
|
|
594
|
+
*
|
|
595
|
+
* const error = new ZeroExQuoteMalformedCalldataError({
|
|
596
|
+
* reason: "Settler entry point is executeWithPermit, not execute",
|
|
597
|
+
* });
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
export declare class ZeroExQuoteMalformedCalldataError extends ZeroExQuoteError {
|
|
601
|
+
/**
|
|
602
|
+
* @param params - Decoding details.
|
|
603
|
+
* @param params.reason - What failed to decode.
|
|
604
|
+
* @param options - Standard error options; `cause` carries the decoding error.
|
|
605
|
+
*/
|
|
606
|
+
constructor(params: {
|
|
607
|
+
readonly reason: string;
|
|
608
|
+
}, options?: ErrorOptions);
|
|
609
|
+
/** What failed to decode. */
|
|
610
|
+
readonly reason: string;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Thrown when a layer of 0x quote calldata does not decode, whichever leverage bundle takes the quote: calldata the SDK
|
|
614
|
+
* cannot read cannot be shown to carry no signed order or short time bound, so every layer must decode.
|
|
615
|
+
* `layer` is `"allowanceHolder"` when the calldata is not an AllowanceHolder `exec` call, `"settler"` when the
|
|
616
|
+
* `exec` data is not a Settler `execute` call.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```ts
|
|
620
|
+
* import { ZeroExQuoteUndecodableCalldataError } from "@morpho-org/morpho-sdk";
|
|
621
|
+
*
|
|
622
|
+
* const error = new ZeroExQuoteUndecodableCalldataError({
|
|
623
|
+
* layer: "settler",
|
|
624
|
+
* bundle: "0x000000000000000000000000000000000000bE01",
|
|
625
|
+
* });
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
export declare class ZeroExQuoteUndecodableCalldataError extends ZeroExQuoteError {
|
|
629
|
+
/**
|
|
630
|
+
* @param params - Decoding details.
|
|
631
|
+
* @param params.layer - Calldata layer that does not decode.
|
|
632
|
+
* @param params.bundle - Leverage bundle taking the quote.
|
|
633
|
+
* @param options - Standard error options.
|
|
634
|
+
*/
|
|
635
|
+
constructor(params: {
|
|
636
|
+
readonly layer: "allowanceHolder" | "settler";
|
|
637
|
+
readonly bundle: Address;
|
|
638
|
+
}, options?: ErrorOptions);
|
|
639
|
+
/** Calldata layer that does not decode. */
|
|
640
|
+
readonly layer: "allowanceHolder" | "settler";
|
|
641
|
+
/** Leverage bundle taking the quote. */
|
|
642
|
+
readonly bundle: Address;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Thrown when decoded 0x Settler calldata fills a signed order instead of onchain AMM liquidity: an RFQ order (`RFQ`,
|
|
646
|
+
* `RFQ_VIP`), a Bebop order (`BEBOP`) or any metatransaction action (`METATXN_*`), at the top level of Settler's
|
|
647
|
+
* `execute` or in a candidate of a `SELECT` action at any depth. A signed order carries its maker's own expiry, which
|
|
648
|
+
* can fall before the leverage deadline, so the SDK refuses the quote. `path` names the action: `[1]` is
|
|
649
|
+
* the second top-level action, `[1].candidates[0][2]` the third action of the first candidate of that `SELECT`.
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```ts
|
|
653
|
+
* import { ZeroExQuoteSignedOrderActionError } from "@morpho-org/morpho-sdk";
|
|
654
|
+
*
|
|
655
|
+
* const error = new ZeroExQuoteSignedOrderActionError({ action: "BEBOP", path: "[1]" });
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
658
|
+
export declare class ZeroExQuoteSignedOrderActionError extends ZeroExQuoteError {
|
|
659
|
+
/**
|
|
660
|
+
* @param params - Signed-order action details.
|
|
661
|
+
* @param params.action - Settler action that fills the signed order.
|
|
662
|
+
* @param params.path - Position of the action in Settler's `execute` actions and `SELECT` candidates.
|
|
663
|
+
*/
|
|
664
|
+
constructor(params: {
|
|
665
|
+
readonly action: string;
|
|
666
|
+
readonly path: string;
|
|
667
|
+
});
|
|
668
|
+
/** Settler action that fills the signed order. */
|
|
669
|
+
readonly action: string;
|
|
670
|
+
/** Position of the action in Settler's `execute` actions and `SELECT` candidates. */
|
|
671
|
+
readonly path: string;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Thrown when a decoded 0x Settler `BASIC` or `BASIC_PUSH` action, an opaque call to a venue, holds a 32-byte word
|
|
675
|
+
* that looks like a deadline shorter than the leverage deadline: a value from one hour and one day before `deadline`
|
|
676
|
+
* up to, but not including, `deadline`. The SDK cannot tell whether the word is a deadline. 0x writes router
|
|
677
|
+
* deadlines equal to `deadline`, so such a word may be a venue's own expiry, such as a signed quote, after which the
|
|
678
|
+
* swap would revert; the SDK refuses it as one. An ordinary value that falls in that window, such as an amount, is
|
|
679
|
+
* refused too. A new quote clears it only when it returns different calldata: a word that depends on the route,
|
|
680
|
+
* such as a minimum output, may move, but a fixed value such as the caller's own amount keeps refusing for up to a
|
|
681
|
+
* day, so offer a different amount, a retry later, or a no-swap exit. `word` is the index of the word in the call's
|
|
682
|
+
* data after its selector.
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* import { ZeroExQuoteShortTimeBoundError } from "@morpho-org/morpho-sdk";
|
|
687
|
+
*
|
|
688
|
+
* const error = new ZeroExQuoteShortTimeBoundError({
|
|
689
|
+
* path: "[5]",
|
|
690
|
+
* word: 7,
|
|
691
|
+
* value: 1_700_000_060n,
|
|
692
|
+
* deadline: 1_700_003_600n,
|
|
693
|
+
* });
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
696
|
+
export declare class ZeroExQuoteShortTimeBoundError extends ZeroExQuoteError {
|
|
697
|
+
/**
|
|
698
|
+
* @param params - Time bound details.
|
|
699
|
+
* @param params.path - Position of the action in Settler's `execute` actions and `SELECT` candidates.
|
|
700
|
+
* @param params.word - Index of the word in the call's data after its selector.
|
|
701
|
+
* @param params.value - Value of the word, in seconds.
|
|
702
|
+
* @param params.deadline - Leverage bundle deadline the action signs, in seconds.
|
|
703
|
+
*/
|
|
704
|
+
constructor(params: {
|
|
705
|
+
readonly path: string;
|
|
706
|
+
readonly word: number;
|
|
707
|
+
readonly value: bigint;
|
|
708
|
+
readonly deadline: bigint;
|
|
709
|
+
});
|
|
710
|
+
/** Position of the action in Settler's `execute` actions and `SELECT` candidates. */
|
|
711
|
+
readonly path: string;
|
|
712
|
+
/** Index of the word in the call's data after its selector. */
|
|
713
|
+
readonly word: number;
|
|
714
|
+
/** Value of the word, in seconds. */
|
|
715
|
+
readonly value: bigint;
|
|
716
|
+
/** Leverage bundle deadline the action signs, in seconds. */
|
|
717
|
+
readonly deadline: bigint;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Thrown when decoded 0x Settler calldata holds an action leverage does not accept where it stands: a selector that is
|
|
721
|
+
* no AMM, permit, time-check or opaque-call action of the deployed Settlers, a permit action anywhere but the first
|
|
722
|
+
* top-level action (Settler only runs one there), or a `NATIVE_CHECK` or `ATTEST` inside a `SELECT` candidate.
|
|
723
|
+
* Leverage refuses what it cannot classify rather than pass it unchecked.
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* ```ts
|
|
727
|
+
* import { ZeroExQuoteUnsupportedActionError } from "@morpho-org/morpho-sdk";
|
|
728
|
+
*
|
|
729
|
+
* const error = new ZeroExQuoteUnsupportedActionError({ selector: "0xdeadbeef", path: "[2]" });
|
|
730
|
+
* ```
|
|
731
|
+
*/
|
|
732
|
+
export declare class ZeroExQuoteUnsupportedActionError extends ZeroExQuoteError {
|
|
733
|
+
/**
|
|
734
|
+
* @param params - Action details.
|
|
735
|
+
* @param params.selector - Four-byte selector of the action.
|
|
736
|
+
* @param params.path - Position of the action in Settler's `execute` actions and `SELECT` candidates.
|
|
737
|
+
*/
|
|
738
|
+
constructor(params: {
|
|
739
|
+
readonly selector: Hex;
|
|
740
|
+
readonly path: string;
|
|
741
|
+
});
|
|
742
|
+
/** Four-byte selector of the action. */
|
|
743
|
+
readonly selector: Hex;
|
|
744
|
+
/** Position of the action in Settler's `execute` actions and `SELECT` candidates. */
|
|
745
|
+
readonly path: string;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Thrown when a decoded Settler time bound does not match the leverage bundle deadline the action signs: the permit
|
|
749
|
+
* of the first top-level action (`TRANSFER_FROM` or a `*_VIP` action) must equal it, and a top-level `NATIVE_CHECK`
|
|
750
|
+
* or `ATTEST` deadline must be at least it. Settler reverts once either has passed, so the quote must be fetched with
|
|
751
|
+
* `deadline` set to the bundle deadline; 0x otherwise sets the permit deadline to its quote block's timestamp plus
|
|
752
|
+
* 300 seconds.
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* ```ts
|
|
756
|
+
* import { ZeroExQuoteDeadlineMismatchError } from "@morpho-org/morpho-sdk";
|
|
757
|
+
*
|
|
758
|
+
* const error = new ZeroExQuoteDeadlineMismatchError({
|
|
759
|
+
* expected: 1_700_003_600n,
|
|
760
|
+
* actual: 1_700_000_300n,
|
|
761
|
+
* action: "UNISWAPV3_VIP",
|
|
762
|
+
* });
|
|
763
|
+
* ```
|
|
764
|
+
*/
|
|
765
|
+
export declare class ZeroExQuoteDeadlineMismatchError extends ZeroExQuoteError {
|
|
766
|
+
/**
|
|
767
|
+
* @param params - Deadline comparison.
|
|
768
|
+
* @param params.expected - Leverage bundle deadline the action signs, in seconds.
|
|
769
|
+
* @param params.actual - Deadline in the Settler action, in seconds.
|
|
770
|
+
* @param params.action - Settler action that carries the deadline.
|
|
771
|
+
*/
|
|
772
|
+
constructor(params: {
|
|
773
|
+
readonly expected: bigint;
|
|
774
|
+
readonly actual: bigint;
|
|
775
|
+
readonly action: string;
|
|
776
|
+
});
|
|
777
|
+
/** Leverage bundle deadline the action signs, in seconds. */
|
|
778
|
+
readonly expected: bigint;
|
|
779
|
+
/** Deadline in the Settler action, in seconds. */
|
|
780
|
+
readonly actual: bigint;
|
|
781
|
+
/** Settler action that carries the deadline. */
|
|
782
|
+
readonly action: string;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Thrown when the 0x quote was requested for another transaction origin than the action expects: the
|
|
786
|
+
* `txOrigin` the action is built with, or the user when none is given.
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* ```ts
|
|
790
|
+
* import { ZeroExQuoteTxOriginMismatchError } from "@morpho-org/morpho-sdk";
|
|
791
|
+
*
|
|
792
|
+
* const error = new ZeroExQuoteTxOriginMismatchError({
|
|
793
|
+
* expected: userAddress,
|
|
794
|
+
* actual: quotedTxOrigin,
|
|
795
|
+
* });
|
|
796
|
+
* ```
|
|
797
|
+
*/
|
|
798
|
+
export declare class ZeroExQuoteTxOriginMismatchError extends ZeroExQuoteError {
|
|
799
|
+
/**
|
|
800
|
+
* @param params - txOrigin comparison.
|
|
801
|
+
* @param params.expected - Expected transaction origin: the action's `txOrigin`, or the user by default.
|
|
802
|
+
* @param params.actual - txOrigin the quote was requested for.
|
|
803
|
+
*/
|
|
804
|
+
constructor(params: {
|
|
805
|
+
readonly expected: Address;
|
|
806
|
+
readonly actual: Address;
|
|
807
|
+
});
|
|
808
|
+
/** Expected transaction origin: the action's `txOrigin`, or the user by default. */
|
|
809
|
+
readonly expected: Address;
|
|
810
|
+
/** txOrigin the quote was requested for. */
|
|
811
|
+
readonly actual: Address;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Thrown when a leverage action's optional `txOrigin` is not a valid address. No new quote clears it: pass a
|
|
815
|
+
* valid address, or omit it to use the user.
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* ```ts
|
|
819
|
+
* import { ZeroExInvalidTxOriginError } from "@morpho-org/morpho-sdk";
|
|
820
|
+
*
|
|
821
|
+
* const error = new ZeroExInvalidTxOriginError("0x1234");
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
824
|
+
export declare class ZeroExInvalidTxOriginError extends ZeroExQuoteError {
|
|
825
|
+
/**
|
|
826
|
+
* @param txOrigin - Value passed as `txOrigin`.
|
|
827
|
+
*/
|
|
828
|
+
constructor(txOrigin: unknown);
|
|
829
|
+
/** Value passed as `txOrigin`. */
|
|
830
|
+
readonly txOrigin: unknown;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Thrown when an exact-output quote is requested for a native and wrapped-native pair, which 0x does not support.
|
|
834
|
+
*
|
|
835
|
+
* @example
|
|
836
|
+
* ```ts
|
|
837
|
+
* import { ZeroExExactOutputUnsupportedError } from "@morpho-org/morpho-sdk";
|
|
838
|
+
* import { NATIVE_ADDRESS } from "@morpho-org/morpho-sdk/addresses";
|
|
839
|
+
*
|
|
840
|
+
* const error = new ZeroExExactOutputUnsupportedError({
|
|
841
|
+
* sellToken: NATIVE_ADDRESS,
|
|
842
|
+
* buyToken: weth,
|
|
843
|
+
* });
|
|
844
|
+
* ```
|
|
845
|
+
*/
|
|
846
|
+
export declare class ZeroExExactOutputUnsupportedError extends ZeroExQuoteError {
|
|
847
|
+
/**
|
|
848
|
+
* @param params - Pair details.
|
|
849
|
+
* @param params.sellToken - Token the swap sells.
|
|
850
|
+
* @param params.buyToken - Token the swap buys.
|
|
851
|
+
*/
|
|
852
|
+
constructor(params: {
|
|
853
|
+
readonly sellToken: Address;
|
|
854
|
+
readonly buyToken: Address;
|
|
855
|
+
});
|
|
856
|
+
/** Token the swap sells. */
|
|
857
|
+
readonly sellToken: Address;
|
|
858
|
+
/** Token the swap buys. */
|
|
859
|
+
readonly buyToken: Address;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Thrown when a 0x swap is requested for a value that is not a leverage swap kind, before any request or
|
|
863
|
+
* validation runs.
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
* ```ts
|
|
867
|
+
* import { ZeroExUnknownSwapKindError } from "@morpho-org/morpho-sdk";
|
|
868
|
+
*
|
|
869
|
+
* const error = new ZeroExUnknownSwapKindError({ kind: "leverage" });
|
|
870
|
+
* ```
|
|
871
|
+
*/
|
|
872
|
+
export declare class ZeroExUnknownSwapKindError extends ZeroExQuoteError {
|
|
873
|
+
/**
|
|
874
|
+
* @param params - Swap kind details.
|
|
875
|
+
* @param params.kind - Value supplied as the swap kind.
|
|
876
|
+
*/
|
|
877
|
+
constructor(params: {
|
|
878
|
+
readonly kind: unknown;
|
|
879
|
+
});
|
|
880
|
+
/** Value supplied as the swap kind. */
|
|
881
|
+
readonly kind: unknown;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Thrown when the 0x quote request fails: a network error or a non-2xx response from the 0x API.
|
|
885
|
+
*
|
|
886
|
+
* @example
|
|
887
|
+
* ```ts
|
|
888
|
+
* import { ZeroExQuoteRequestError } from "@morpho-org/morpho-sdk";
|
|
889
|
+
*
|
|
890
|
+
* const error = new ZeroExQuoteRequestError({ status: 400, code: "INPUT_INVALID" });
|
|
891
|
+
* ```
|
|
892
|
+
*/
|
|
893
|
+
export declare class ZeroExQuoteRequestError extends ZeroExQuoteError {
|
|
894
|
+
/**
|
|
895
|
+
* @param params - Request failure.
|
|
896
|
+
* @param params.status - HTTP status, or `null` when no response arrived or a 2xx response's body failed to
|
|
897
|
+
* download. A non-2xx response keeps its status, with `code: null` when its body could not be read.
|
|
898
|
+
* @param params.code - 0x error name from the response body, or `null` when it has none.
|
|
899
|
+
* @param options - Standard error options; `cause` carries the underlying failure.
|
|
900
|
+
*/
|
|
901
|
+
constructor(params: {
|
|
902
|
+
readonly status: number | null;
|
|
903
|
+
readonly code: string | null;
|
|
904
|
+
}, options?: ErrorOptions);
|
|
905
|
+
/** HTTP status, or `null` when no response arrived or a 2xx response's body failed to download. */
|
|
906
|
+
readonly status: number | null;
|
|
907
|
+
/** 0x error name from the response body, or `null` when it has none. */
|
|
908
|
+
readonly code: string | null;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Thrown when 0x reports no liquidity for the requested swap.
|
|
912
|
+
*
|
|
913
|
+
* @example
|
|
914
|
+
* ```ts
|
|
915
|
+
* import { ZeroExQuoteNoLiquidityError } from "@morpho-org/morpho-sdk";
|
|
916
|
+
*
|
|
917
|
+
* const error = new ZeroExQuoteNoLiquidityError({
|
|
918
|
+
* sellToken: weth,
|
|
919
|
+
* buyToken: usdc,
|
|
920
|
+
* });
|
|
921
|
+
* ```
|
|
922
|
+
*/
|
|
923
|
+
export declare class ZeroExQuoteNoLiquidityError extends ZeroExQuoteError {
|
|
924
|
+
/**
|
|
925
|
+
* @param params - Pair details.
|
|
926
|
+
* @param params.sellToken - Token the swap sells.
|
|
927
|
+
* @param params.buyToken - Token the swap buys.
|
|
928
|
+
*/
|
|
929
|
+
constructor(params: {
|
|
930
|
+
readonly sellToken: Address;
|
|
931
|
+
readonly buyToken: Address;
|
|
932
|
+
});
|
|
933
|
+
/** Token the swap sells. */
|
|
934
|
+
readonly sellToken: Address;
|
|
935
|
+
/** Token the swap buys. */
|
|
936
|
+
readonly buyToken: Address;
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Thrown when a 0x quote response does not have the documented allowance-holder quote shape, or does not answer the request that was sent.
|
|
940
|
+
*
|
|
941
|
+
* @example
|
|
942
|
+
* ```ts
|
|
943
|
+
* import { ZeroExQuoteMalformedResponseError } from "@morpho-org/morpho-sdk";
|
|
944
|
+
*
|
|
945
|
+
* const error = new ZeroExQuoteMalformedResponseError({ reason: "buyAmount is not an integer string" });
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
export declare class ZeroExQuoteMalformedResponseError extends ZeroExQuoteError {
|
|
949
|
+
/**
|
|
950
|
+
* @param params - Parsing details.
|
|
951
|
+
* @param params.reason - What is wrong with the response.
|
|
952
|
+
* @param options - Standard error options; `cause` carries the underlying failure.
|
|
953
|
+
*/
|
|
954
|
+
constructor(params: {
|
|
955
|
+
readonly reason: string;
|
|
956
|
+
}, options?: ErrorOptions);
|
|
957
|
+
/** What is wrong with the response. */
|
|
958
|
+
readonly reason: string;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Thrown when a leverage action that swaps is built without a 0x quote, such as a Close of a
|
|
962
|
+
* position that still has debt.
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* ```ts
|
|
966
|
+
* import { ZeroExQuoteRequiredError } from "@morpho-org/morpho-sdk";
|
|
967
|
+
*
|
|
968
|
+
* const error = new ZeroExQuoteRequiredError({ operation: "close" });
|
|
969
|
+
* ```
|
|
970
|
+
*/
|
|
971
|
+
export declare class ZeroExQuoteRequiredError extends ZeroExQuoteError {
|
|
972
|
+
/**
|
|
973
|
+
* @param params - Refused action.
|
|
974
|
+
* @param params.operation - Leverage action that needs a quote.
|
|
975
|
+
*/
|
|
976
|
+
constructor(params: {
|
|
977
|
+
readonly operation: LeverageOperation;
|
|
978
|
+
});
|
|
979
|
+
/** Leverage action that needs a quote. */
|
|
980
|
+
readonly operation: LeverageOperation;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Thrown when the caller's slippage exceeds the SDK's execution-loss limit for the action.
|
|
984
|
+
*
|
|
985
|
+
* @example
|
|
986
|
+
* ```ts
|
|
987
|
+
* import { LeverageSlippageAboveLimitError } from "@morpho-org/morpho-sdk";
|
|
988
|
+
*
|
|
989
|
+
* const error = new LeverageSlippageAboveLimitError({
|
|
990
|
+
* operation: "lever",
|
|
991
|
+
* slippage: 20_000_000_000_000_000n,
|
|
992
|
+
* max: 10_000_000_000_000_000n,
|
|
993
|
+
* });
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
export declare class LeverageSlippageAboveLimitError extends LeverageLimitError {
|
|
997
|
+
/**
|
|
998
|
+
* @param params - Slippage comparison, WAD-scaled.
|
|
999
|
+
* @param params.operation - Leverage action refused.
|
|
1000
|
+
* @param params.slippage - Slippage supplied by the caller.
|
|
1001
|
+
* @param params.max - Largest slippage the SDK accepts for the action.
|
|
1002
|
+
*/
|
|
1003
|
+
constructor(params: {
|
|
1004
|
+
readonly operation: LeverageOperation;
|
|
1005
|
+
readonly slippage: bigint;
|
|
1006
|
+
readonly max: bigint;
|
|
1007
|
+
});
|
|
1008
|
+
/** Leverage action refused. */
|
|
1009
|
+
readonly operation: LeverageOperation;
|
|
1010
|
+
/** Slippage supplied by the caller, WAD-scaled. */
|
|
1011
|
+
readonly slippage: bigint;
|
|
1012
|
+
/** Largest slippage the SDK accepts for the action, WAD-scaled. */
|
|
1013
|
+
readonly max: bigint;
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Thrown when the 0x quote was fetched with a slippage other than the one the caller passes. The
|
|
1017
|
+
* quote and the build must use the same slippage, or the transaction would carry a tolerance the
|
|
1018
|
+
* caller did not choose. For an exact-output quote (Lever, Close) the signed swap
|
|
1019
|
+
* cap is the quote's `maxSellAmount`, which carries the quote's own slippage. A Delever quote's
|
|
1020
|
+
* `minBuyAmount` below the caller's slippage throws {@link ZeroExQuoteMinBuyAmountBelowSlippageError} instead.
|
|
1021
|
+
*
|
|
1022
|
+
* @example
|
|
1023
|
+
* ```ts
|
|
1024
|
+
* import { LeverageQuoteSlippageMismatchError } from "@morpho-org/morpho-sdk";
|
|
1025
|
+
*
|
|
1026
|
+
* const error = new LeverageQuoteSlippageMismatchError({
|
|
1027
|
+
* operation: "lever",
|
|
1028
|
+
* slippage: 5_000_000_000_000_000n,
|
|
1029
|
+
* quoteSlippage: 8_000_000_000_000_000n,
|
|
1030
|
+
* });
|
|
1031
|
+
* ```
|
|
1032
|
+
*/
|
|
1033
|
+
export declare class LeverageQuoteSlippageMismatchError extends LeverageLimitError {
|
|
1034
|
+
/**
|
|
1035
|
+
* @param params - Slippage comparison, WAD-scaled.
|
|
1036
|
+
* @param params.operation - Leverage action refused.
|
|
1037
|
+
* @param params.slippage - Slippage supplied by the caller.
|
|
1038
|
+
* @param params.quoteSlippage - Slippage the quote was fetched with.
|
|
1039
|
+
*/
|
|
1040
|
+
constructor(params: {
|
|
1041
|
+
readonly operation: LeverageOperation;
|
|
1042
|
+
readonly slippage: bigint;
|
|
1043
|
+
readonly quoteSlippage: bigint;
|
|
1044
|
+
});
|
|
1045
|
+
/** Leverage action refused. */
|
|
1046
|
+
readonly operation: LeverageOperation;
|
|
1047
|
+
/** Slippage supplied by the caller, WAD-scaled. */
|
|
1048
|
+
readonly slippage: bigint;
|
|
1049
|
+
/** Slippage the quote was fetched with, WAD-scaled. */
|
|
1050
|
+
readonly quoteSlippage: bigint;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Thrown when a Lever's or a Delever's position LTV at the worst fill exceeds a bound: the action's signed
|
|
1054
|
+
* `maxLtv` (`check: "maxLtv"`), or the market LLTV at Blue's health check, which the contract
|
|
1055
|
+
* runs before repaying any surplus (`check: "health"`). Close never throws it: it signs no `maxLtv`, and Blue
|
|
1056
|
+
* clears the borrow shares before the repay callback withdraws the collateral, so that withdrawal's health check
|
|
1057
|
+
* always passes.
|
|
1058
|
+
*
|
|
1059
|
+
* @example
|
|
1060
|
+
* ```ts
|
|
1061
|
+
* import { LeverageWorstFillLtvError } from "@morpho-org/morpho-sdk";
|
|
1062
|
+
*
|
|
1063
|
+
* const error = new LeverageWorstFillLtvError({
|
|
1064
|
+
* operation: "lever",
|
|
1065
|
+
* check: "maxLtv",
|
|
1066
|
+
* ltv: 860_000_000_000_000_000n,
|
|
1067
|
+
* maxLtv: 855_000_000_000_000_000n,
|
|
1068
|
+
* });
|
|
1069
|
+
* ```
|
|
1070
|
+
*/
|
|
1071
|
+
export declare class LeverageWorstFillLtvError extends LeverageLimitError {
|
|
1072
|
+
/**
|
|
1073
|
+
* @param params - LTV comparison, WAD-scaled.
|
|
1074
|
+
* @param params.operation - Leverage action refused.
|
|
1075
|
+
* @param params.check - Bound exceeded: the signed `maxLtv` or Blue's mid-flow health check.
|
|
1076
|
+
* @param params.ltv - Position LTV at the worst fill.
|
|
1077
|
+
* @param params.maxLtv - Bound for that check.
|
|
1078
|
+
*/
|
|
1079
|
+
constructor(params: {
|
|
1080
|
+
readonly operation: "lever" | "delever";
|
|
1081
|
+
readonly check: "maxLtv" | "health";
|
|
1082
|
+
readonly ltv: bigint;
|
|
1083
|
+
readonly maxLtv: bigint;
|
|
1084
|
+
});
|
|
1085
|
+
/** Leverage action refused. */
|
|
1086
|
+
readonly operation: "lever" | "delever";
|
|
1087
|
+
/** Bound exceeded: the signed `maxLtv` or Blue's mid-flow health check. */
|
|
1088
|
+
readonly check: "maxLtv" | "health";
|
|
1089
|
+
/** Position LTV at the worst fill, WAD-scaled. */
|
|
1090
|
+
readonly ltv: bigint;
|
|
1091
|
+
/** Bound for that check, WAD-scaled. */
|
|
1092
|
+
readonly maxLtv: bigint;
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Thrown when a Lever's worst swap price, the signed `maxSwapIn` per `minCollateralToBuy`, is more than
|
|
1096
|
+
* `LEVERAGE_MAX_ORACLE_DEVIATION` (15%) above the market's oracle price. A price below the oracle favours the user
|
|
1097
|
+
* and is never refused. Both prices are
|
|
1098
|
+
* loan-token units per collateral-token unit scaled by `ORACLE_PRICE_SCALE` (1e36), as Morpho oracles report
|
|
1099
|
+
* them, so token decimals are already accounted for. Only Lever checks it; Delever and Close do not. The worst price
|
|
1100
|
+
* uses `maxSwapIn`, which already includes the caller's slippage, so the room left for a gap between 0x's price and
|
|
1101
|
+
* the oracle is about 15% minus that slippage (5% at the 10% ceiling).
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* ```ts
|
|
1105
|
+
* import { LeverageOraclePriceDeviationError } from "@morpho-org/morpho-sdk";
|
|
1106
|
+
*
|
|
1107
|
+
* const error = new LeverageOraclePriceDeviationError({
|
|
1108
|
+
* quotePrice: 3_500n * 10n ** 24n,
|
|
1109
|
+
* oraclePrice: 3_000n * 10n ** 24n,
|
|
1110
|
+
* deviation: 166_666_666_666_666_667n,
|
|
1111
|
+
* max: 150_000_000_000_000_000n,
|
|
1112
|
+
* });
|
|
1113
|
+
* ```
|
|
1114
|
+
*/
|
|
1115
|
+
export declare class LeverageOraclePriceDeviationError extends LeverageLimitError {
|
|
1116
|
+
/**
|
|
1117
|
+
* @param params - Price comparison.
|
|
1118
|
+
* @param params.quotePrice - Worst swap price the Lever signs, scaled by `ORACLE_PRICE_SCALE`, rounded down.
|
|
1119
|
+
* @param params.oraclePrice - Market oracle price at the data block, scaled by `ORACLE_PRICE_SCALE`.
|
|
1120
|
+
* @param params.deviation - How far the quote price is above the oracle price, relative to it, WAD-scaled, rounded up.
|
|
1121
|
+
* @param params.max - Largest deviation accepted, WAD-scaled.
|
|
1122
|
+
*/
|
|
1123
|
+
constructor(params: {
|
|
1124
|
+
readonly quotePrice: bigint;
|
|
1125
|
+
readonly oraclePrice: bigint;
|
|
1126
|
+
readonly deviation: bigint;
|
|
1127
|
+
readonly max: bigint;
|
|
1128
|
+
});
|
|
1129
|
+
/** Worst swap price the Lever signs, scaled by `ORACLE_PRICE_SCALE`. */
|
|
1130
|
+
readonly quotePrice: bigint;
|
|
1131
|
+
/** Market oracle price at the data block, scaled by `ORACLE_PRICE_SCALE`. */
|
|
1132
|
+
readonly oraclePrice: bigint;
|
|
1133
|
+
/** Deviation from the oracle price, WAD-scaled. */
|
|
1134
|
+
readonly deviation: bigint;
|
|
1135
|
+
/** Largest deviation accepted, WAD-scaled. */
|
|
1136
|
+
readonly max: bigint;
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Thrown when a Lever, a Delever or a Close with debt is built from leverage data without a usable oracle price: the
|
|
1140
|
+
* oracle call reverted or returned zero. Without it the SDK can derive neither the oracle deviation nor `maxLtv` and
|
|
1141
|
+
* the worst-fill checks, so it never signs such a swap. A Close without debt refuses with `LeverageCloseWithoutDebtError` first. For an
|
|
1142
|
+
* exit, the fallback is a no-swap exit, which needs no price once the debt is repaid.
|
|
1143
|
+
*
|
|
1144
|
+
* @example
|
|
1145
|
+
* ```ts
|
|
1146
|
+
* import { LeverageOraclePriceUnavailableError } from "@morpho-org/morpho-sdk";
|
|
1147
|
+
*
|
|
1148
|
+
* // `marketParams`: the market's `MarketParams`.
|
|
1149
|
+
* const error = new LeverageOraclePriceUnavailableError({
|
|
1150
|
+
* operation: "delever",
|
|
1151
|
+
* marketId: marketParams.id,
|
|
1152
|
+
* price: undefined,
|
|
1153
|
+
* });
|
|
1154
|
+
* ```
|
|
1155
|
+
*/
|
|
1156
|
+
export declare class LeverageOraclePriceUnavailableError extends LeverageLimitError {
|
|
1157
|
+
/**
|
|
1158
|
+
* @param params - Missing price.
|
|
1159
|
+
* @param params.operation - Leverage action refused.
|
|
1160
|
+
* @param params.marketId - Market whose oracle price is missing.
|
|
1161
|
+
* @param params.price - Price the leverage data holds: `undefined` when the oracle call reverted, else zero.
|
|
1162
|
+
*/
|
|
1163
|
+
constructor(params: {
|
|
1164
|
+
readonly operation: LeverageOperation;
|
|
1165
|
+
readonly marketId: MarketId;
|
|
1166
|
+
readonly price: bigint | undefined;
|
|
1167
|
+
});
|
|
1168
|
+
/** Leverage action refused. */
|
|
1169
|
+
readonly operation: LeverageOperation;
|
|
1170
|
+
/** Market whose oracle price is missing. */
|
|
1171
|
+
readonly marketId: MarketId;
|
|
1172
|
+
/** Price the leverage data holds: `undefined` when the oracle call reverted, else zero. */
|
|
1173
|
+
readonly price: bigint | undefined;
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Thrown when a Close's quote-based `minLoanOut` floor does not exceed the debt, or is below the debt
|
|
1177
|
+
* plus the interest buffer. The debt is never used as the floor.
|
|
1178
|
+
*
|
|
1179
|
+
* @example
|
|
1180
|
+
* ```ts
|
|
1181
|
+
* import { LeverageCloseFloorBelowDebtPlusBufferError } from "@morpho-org/morpho-sdk";
|
|
1182
|
+
*
|
|
1183
|
+
* const error = new LeverageCloseFloorBelowDebtPlusBufferError({ floor: 100n, debt: 100n });
|
|
1184
|
+
* ```
|
|
1185
|
+
*/
|
|
1186
|
+
export declare class LeverageCloseFloorBelowDebtPlusBufferError extends LeverageLimitError {
|
|
1187
|
+
/**
|
|
1188
|
+
* @param params - Floor comparison, in loan-token assets.
|
|
1189
|
+
* @param params.floor - Quote-based `minLoanOut`.
|
|
1190
|
+
* @param params.debt - Position's debt.
|
|
1191
|
+
* @param params.interestBuffer - Interest buffer the floor must also cover.
|
|
1192
|
+
*/
|
|
1193
|
+
constructor(params: {
|
|
1194
|
+
readonly floor: bigint;
|
|
1195
|
+
readonly debt: bigint;
|
|
1196
|
+
readonly interestBuffer?: bigint;
|
|
1197
|
+
});
|
|
1198
|
+
/** Quote-based `minLoanOut`, in loan-token assets. */
|
|
1199
|
+
readonly floor: bigint;
|
|
1200
|
+
/** Position's debt, in loan-token assets. */
|
|
1201
|
+
readonly debt: bigint;
|
|
1202
|
+
/**
|
|
1203
|
+
* Interest buffer the floor must also cover, in loan-token assets (`computeCloseInterestBuffer`).
|
|
1204
|
+
* `computeCloseLimits` and `blueClose` always set it.
|
|
1205
|
+
*/
|
|
1206
|
+
readonly interestBuffer: bigint | undefined;
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Thrown when a keep-collateral Close's exact-output quote buys more than the debt plus the
|
|
1210
|
+
* interest buffer. The extra loan token would come back to the user, but selling the collateral
|
|
1211
|
+
* for it costs price impact and fees, and gives up the collateral exposure the mode keeps. The
|
|
1212
|
+
* required amount moves whenever the leverage data does: a repay, accrued interest or a change in the borrow
|
|
1213
|
+
* rate (which scales the buffer) can raise or lower it, and a quote sized for another position usually
|
|
1214
|
+
* won't match it. Fetch a new quote for exactly `debt + interestBuffer` from the current leverageData.
|
|
1215
|
+
*
|
|
1216
|
+
* @example
|
|
1217
|
+
* ```ts
|
|
1218
|
+
* import { LeverageCloseBuyAboveDebtError } from "@morpho-org/morpho-sdk";
|
|
1219
|
+
*
|
|
1220
|
+
* const error = new LeverageCloseBuyAboveDebtError({ buyAmount: 70n, debt: 20n, interestBuffer: 1n });
|
|
1221
|
+
* ```
|
|
1222
|
+
*/
|
|
1223
|
+
export declare class LeverageCloseBuyAboveDebtError extends LeverageLimitError {
|
|
1224
|
+
/**
|
|
1225
|
+
* @param params - Buy comparison, in loan-token assets.
|
|
1226
|
+
* @param params.buyAmount - Quote's exact-output `buyAmount`.
|
|
1227
|
+
* @param params.debt - Position's accrued debt.
|
|
1228
|
+
* @param params.interestBuffer - Interest buffer from `computeCloseInterestBuffer`.
|
|
1229
|
+
*/
|
|
1230
|
+
constructor(params: {
|
|
1231
|
+
readonly buyAmount: bigint;
|
|
1232
|
+
readonly debt: bigint;
|
|
1233
|
+
readonly interestBuffer: bigint;
|
|
1234
|
+
});
|
|
1235
|
+
/** Quote's exact-output `buyAmount`, in loan-token assets. */
|
|
1236
|
+
readonly buyAmount: bigint;
|
|
1237
|
+
/** Position's accrued debt, in loan-token assets. */
|
|
1238
|
+
readonly debt: bigint;
|
|
1239
|
+
/** Interest buffer the quote may add to the debt, in loan-token assets. */
|
|
1240
|
+
readonly interestBuffer: bigint;
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Thrown when a Close targets a position with neither debt nor collateral. The bundle would
|
|
1244
|
+
* withdraw zero collateral, which Morpho Blue rejects, so the transaction could only revert.
|
|
1245
|
+
*
|
|
1246
|
+
* @example
|
|
1247
|
+
* ```ts
|
|
1248
|
+
* import type { MarketId } from "@morpho-org/blue-sdk";
|
|
1249
|
+
* import { LeverageCloseEmptyPositionError } from "@morpho-org/morpho-sdk";
|
|
1250
|
+
*
|
|
1251
|
+
* const error = new LeverageCloseEmptyPositionError({
|
|
1252
|
+
* marketId: "0x3b3769cfca57be2eaed03fcc5299c25691b77781a1e124e7a8d520eb9a7eabb5" as MarketId,
|
|
1253
|
+
* user: userAddress,
|
|
1254
|
+
* });
|
|
1255
|
+
* ```
|
|
1256
|
+
*/
|
|
1257
|
+
export declare class LeverageCloseEmptyPositionError extends LeverageLimitError {
|
|
1258
|
+
/**
|
|
1259
|
+
* @param params - The empty position.
|
|
1260
|
+
* @param params.marketId - Market of the position.
|
|
1261
|
+
* @param params.user - Owner of the position.
|
|
1262
|
+
*/
|
|
1263
|
+
constructor(params: {
|
|
1264
|
+
readonly marketId: MarketId;
|
|
1265
|
+
readonly user: Address;
|
|
1266
|
+
});
|
|
1267
|
+
/** Market of the position. */
|
|
1268
|
+
readonly marketId: MarketId;
|
|
1269
|
+
/** Owner of the position. */
|
|
1270
|
+
readonly user: Address;
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Thrown when a Close targets a position that has collateral but no debt. ZeroExLeverageBundlesV1 still runs the
|
|
1274
|
+
* swap on such a position, and 0x AllowanceHolder reverts on the empty swap calldata a Close without debt would
|
|
1275
|
+
* sign, so the transaction could only revert. Withdraw the collateral with `market.withdrawCollateral` (`blueWithdrawCollateral`) instead.
|
|
1276
|
+
*
|
|
1277
|
+
* @see https://github.com/morpho-org/bundles/blob/3bf53141455051f8fc7a85cd00cc15bd89459238/src/leverage/ZeroExLeverageBundlesV1.sol#L180-L188
|
|
1278
|
+
* @example
|
|
1279
|
+
* ```ts
|
|
1280
|
+
* import type { MarketId } from "@morpho-org/blue-sdk";
|
|
1281
|
+
* import { LeverageCloseWithoutDebtError } from "@morpho-org/morpho-sdk";
|
|
1282
|
+
*
|
|
1283
|
+
* const error = new LeverageCloseWithoutDebtError({
|
|
1284
|
+
* marketId: "0x3b3769cfca57be2eaed03fcc5299c25691b77781a1e124e7a8d520eb9a7eabb5" as MarketId,
|
|
1285
|
+
* user: userAddress,
|
|
1286
|
+
* collateral: 10n ** 18n,
|
|
1287
|
+
* });
|
|
1288
|
+
* ```
|
|
1289
|
+
*/
|
|
1290
|
+
export declare class LeverageCloseWithoutDebtError extends LeverageLimitError {
|
|
1291
|
+
/**
|
|
1292
|
+
* @param params - The position without debt.
|
|
1293
|
+
* @param params.marketId - Market of the position.
|
|
1294
|
+
* @param params.user - Owner of the position.
|
|
1295
|
+
* @param params.collateral - Collateral of the position, in collateral-token assets.
|
|
1296
|
+
*/
|
|
1297
|
+
constructor(params: {
|
|
1298
|
+
readonly marketId: MarketId;
|
|
1299
|
+
readonly user: Address;
|
|
1300
|
+
readonly collateral: bigint;
|
|
1301
|
+
});
|
|
1302
|
+
/** Market of the position. */
|
|
1303
|
+
readonly marketId: MarketId;
|
|
1304
|
+
/** Owner of the position. */
|
|
1305
|
+
readonly user: Address;
|
|
1306
|
+
/** Collateral of the position, in collateral-token assets. */
|
|
1307
|
+
readonly collateral: bigint;
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Thrown when a Close's quote-based `maxCollateralIn` cap exceeds the position's collateral.
|
|
1311
|
+
*
|
|
1312
|
+
* @example
|
|
1313
|
+
* ```ts
|
|
1314
|
+
* import { LeverageCloseInputExceedsCollateralError } from "@morpho-org/morpho-sdk";
|
|
1315
|
+
*
|
|
1316
|
+
* const error = new LeverageCloseInputExceedsCollateralError({ cap: 101n, collateral: 100n });
|
|
1317
|
+
* ```
|
|
1318
|
+
*/
|
|
1319
|
+
export declare class LeverageCloseInputExceedsCollateralError extends LeverageLimitError {
|
|
1320
|
+
/**
|
|
1321
|
+
* @param params - Cap comparison, in collateral-token assets.
|
|
1322
|
+
* @param params.cap - Quote-based `maxCollateralIn`.
|
|
1323
|
+
* @param params.collateral - Position's collateral.
|
|
1324
|
+
*/
|
|
1325
|
+
constructor(params: {
|
|
1326
|
+
readonly cap: bigint;
|
|
1327
|
+
readonly collateral: bigint;
|
|
1328
|
+
});
|
|
1329
|
+
/** Quote-based `maxCollateralIn`, in collateral-token assets. */
|
|
1330
|
+
readonly cap: bigint;
|
|
1331
|
+
/** Position's collateral, in collateral-token assets. */
|
|
1332
|
+
readonly collateral: bigint;
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* Thrown when leverage is requested on a chain without a registered leverage bundle, or whose
|
|
1336
|
+
* AllowanceHolder is not at its Cancun address (excluded by the SDK's chain list, or no code at
|
|
1337
|
+
* the data block).
|
|
1338
|
+
*
|
|
1339
|
+
* @example
|
|
1340
|
+
* ```ts
|
|
1341
|
+
* import { LeverageUnsupportedChainError } from "@morpho-org/morpho-sdk";
|
|
1342
|
+
*
|
|
1343
|
+
* const error = new LeverageUnsupportedChainError({ chainId: 56, reason: "noBundle" });
|
|
1344
|
+
* ```
|
|
1345
|
+
*/
|
|
1346
|
+
export declare class LeverageUnsupportedChainError extends LeverageLimitError {
|
|
1347
|
+
/**
|
|
1348
|
+
* @param params - Chain details.
|
|
1349
|
+
* @param params.chainId - Chain id requested.
|
|
1350
|
+
* @param params.reason - `noBundle` when no leverage bundle is registered; `noAllowanceHolder` when AllowanceHolder is not at its Cancun address on the chain, either because the SDK's chain list excludes the chain or because a code read at the data block found none.
|
|
1351
|
+
*/
|
|
1352
|
+
constructor(params: {
|
|
1353
|
+
readonly chainId: number;
|
|
1354
|
+
readonly reason: "noBundle" | "noAllowanceHolder";
|
|
1355
|
+
});
|
|
1356
|
+
/** Chain id requested. */
|
|
1357
|
+
readonly chainId: number;
|
|
1358
|
+
/** Why the chain is unsupported. */
|
|
1359
|
+
readonly reason: "noBundle" | "noAllowanceHolder";
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Thrown when a leverage reallocation targets another market than the action's market.
|
|
1363
|
+
* The contract checks only the loan token, so the SDK requires the exact market.
|
|
1364
|
+
*
|
|
1365
|
+
* @example
|
|
1366
|
+
* ```ts
|
|
1367
|
+
* import { LeverageReallocationMarketMismatchError } from "@morpho-org/morpho-sdk";
|
|
1368
|
+
*
|
|
1369
|
+
* const error = new LeverageReallocationMarketMismatchError({
|
|
1370
|
+
* vault: vaultAddress,
|
|
1371
|
+
* expected: leverMarketParams.id,
|
|
1372
|
+
* actual: reallocationMarketParams.id,
|
|
1373
|
+
* });
|
|
1374
|
+
* ```
|
|
1375
|
+
*/
|
|
1376
|
+
export declare class LeverageReallocationMarketMismatchError extends LeverageReallocationError {
|
|
1377
|
+
/**
|
|
1378
|
+
* @param params - Market comparison.
|
|
1379
|
+
* @param params.vault - Vault whose reallocation targets the wrong market.
|
|
1380
|
+
* @param params.expected - Action's market id.
|
|
1381
|
+
* @param params.actual - Market id the reallocation targets.
|
|
1382
|
+
*/
|
|
1383
|
+
constructor(params: {
|
|
1384
|
+
readonly vault: Address;
|
|
1385
|
+
readonly expected: MarketId;
|
|
1386
|
+
readonly actual: MarketId;
|
|
1387
|
+
});
|
|
1388
|
+
/** Vault whose reallocation targets the wrong market. */
|
|
1389
|
+
readonly vault: Address;
|
|
1390
|
+
/** Action's market id. */
|
|
1391
|
+
readonly expected: MarketId;
|
|
1392
|
+
/** Market id the reallocation targets. */
|
|
1393
|
+
readonly actual: MarketId;
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Thrown when a leverage reallocation's route is unavailable at the data block: the vault has no
|
|
1397
|
+
* public-allocator flow into the action's market, or the selected idle or source-market leg cannot be
|
|
1398
|
+
* pulled. Another source in the same vault may still work.
|
|
1399
|
+
*
|
|
1400
|
+
* @example
|
|
1401
|
+
* ```ts
|
|
1402
|
+
* import { LeverageReallocationNoFlowError } from "@morpho-org/morpho-sdk";
|
|
1403
|
+
*
|
|
1404
|
+
* const error = new LeverageReallocationNoFlowError({
|
|
1405
|
+
* vault: vaultAddress,
|
|
1406
|
+
* marketId: leverMarketParams.id,
|
|
1407
|
+
* });
|
|
1408
|
+
* ```
|
|
1409
|
+
*/
|
|
1410
|
+
export declare class LeverageReallocationNoFlowError extends LeverageReallocationError {
|
|
1411
|
+
/**
|
|
1412
|
+
* @param params - Flow details.
|
|
1413
|
+
* @param params.vault - Vault whose selected route is unavailable.
|
|
1414
|
+
* @param params.marketId - Action's market id.
|
|
1415
|
+
*/
|
|
1416
|
+
constructor(params: {
|
|
1417
|
+
readonly vault: Address;
|
|
1418
|
+
readonly marketId: MarketId;
|
|
1419
|
+
});
|
|
1420
|
+
/** Vault whose selected route is unavailable. */
|
|
1421
|
+
readonly vault: Address;
|
|
1422
|
+
/** Action's market id. */
|
|
1423
|
+
readonly marketId: MarketId;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Thrown when a leverage reallocation's penalty rate exceeds the SDK's ceiling.
|
|
1427
|
+
*
|
|
1428
|
+
* @example
|
|
1429
|
+
* ```ts
|
|
1430
|
+
* import { LeverageReallocationPenaltyAboveLimitError } from "@morpho-org/morpho-sdk";
|
|
1431
|
+
*
|
|
1432
|
+
* const error = new LeverageReallocationPenaltyAboveLimitError({
|
|
1433
|
+
* vault: vaultAddress,
|
|
1434
|
+
* penalty: 20_000_000_000_000_000n,
|
|
1435
|
+
* max: 10_000_000_000_000_000n,
|
|
1436
|
+
* });
|
|
1437
|
+
* ```
|
|
1438
|
+
*/
|
|
1439
|
+
export declare class LeverageReallocationPenaltyAboveLimitError extends LeverageReallocationError {
|
|
1440
|
+
/**
|
|
1441
|
+
* @param params - Penalty comparison, WAD-scaled.
|
|
1442
|
+
* @param params.vault - Vault charging the penalty.
|
|
1443
|
+
* @param params.penalty - Vault's penalty rate.
|
|
1444
|
+
* @param params.max - SDK penalty ceiling.
|
|
1445
|
+
*/
|
|
1446
|
+
constructor(params: {
|
|
1447
|
+
readonly vault: Address;
|
|
1448
|
+
readonly penalty: bigint;
|
|
1449
|
+
readonly max: bigint;
|
|
1450
|
+
});
|
|
1451
|
+
/** Vault charging the penalty. */
|
|
1452
|
+
readonly vault: Address;
|
|
1453
|
+
/** Vault's penalty rate, WAD-scaled. */
|
|
1454
|
+
readonly penalty: bigint;
|
|
1455
|
+
/** SDK penalty ceiling, WAD-scaled. */
|
|
1456
|
+
readonly max: bigint;
|
|
1457
|
+
}
|
|
1458
|
+
/**
|
|
1459
|
+
* Thrown when leverage reallocations together move more liquidity than the action's borrow cap
|
|
1460
|
+
* (`maxBorrowAssets`).
|
|
1461
|
+
*
|
|
1462
|
+
* @example
|
|
1463
|
+
* ```ts
|
|
1464
|
+
* import { LeverageReallocationExceedsBorrowError } from "@morpho-org/morpho-sdk";
|
|
1465
|
+
*
|
|
1466
|
+
* const error = new LeverageReallocationExceedsBorrowError({
|
|
1467
|
+
* total: 101n,
|
|
1468
|
+
* maxBorrowAssets: 100n,
|
|
1469
|
+
* });
|
|
1470
|
+
* ```
|
|
1471
|
+
*/
|
|
1472
|
+
export declare class LeverageReallocationExceedsBorrowError extends LeverageReallocationError {
|
|
1473
|
+
/**
|
|
1474
|
+
* @param params - Liquidity comparison, in loan-token assets.
|
|
1475
|
+
* @param params.total - Assets moved by all reallocations.
|
|
1476
|
+
* @param params.maxBorrowAssets - Action's signed borrow cap.
|
|
1477
|
+
*/
|
|
1478
|
+
constructor(params: {
|
|
1479
|
+
readonly total: bigint;
|
|
1480
|
+
readonly maxBorrowAssets: bigint;
|
|
1481
|
+
});
|
|
1482
|
+
/** Assets moved by all reallocations. */
|
|
1483
|
+
readonly total: bigint;
|
|
1484
|
+
/** Action's signed borrow cap (`maxBorrowAssets`), in loan-token assets. */
|
|
1485
|
+
readonly maxBorrowAssets: bigint;
|
|
1486
|
+
}
|
|
1487
|
+
/**
|
|
1488
|
+
* Thrown when the market's liquidity at the data block plus the assets the reallocations move
|
|
1489
|
+
* into it cannot fund the action's borrow (`maxBorrowAssets`), so the transaction would revert.
|
|
1490
|
+
*
|
|
1491
|
+
* @example
|
|
1492
|
+
* ```ts
|
|
1493
|
+
* import { LeverageInsufficientLiquidityError } from "@morpho-org/morpho-sdk";
|
|
1494
|
+
*
|
|
1495
|
+
* const error = new LeverageInsufficientLiquidityError({
|
|
1496
|
+
* liquidity: 40n,
|
|
1497
|
+
* reallocatedAssets: 50n,
|
|
1498
|
+
* maxBorrowAssets: 100n,
|
|
1499
|
+
* });
|
|
1500
|
+
* ```
|
|
1501
|
+
*/
|
|
1502
|
+
export declare class LeverageInsufficientLiquidityError extends LeverageLimitError {
|
|
1503
|
+
/**
|
|
1504
|
+
* @param params - Liquidity comparison, in loan-token assets.
|
|
1505
|
+
* @param params.liquidity - Market liquidity at the data block.
|
|
1506
|
+
* @param params.reallocatedAssets - Assets moved into the market by all reallocations.
|
|
1507
|
+
* @param params.maxBorrowAssets - Action's signed borrow cap.
|
|
1508
|
+
*/
|
|
1509
|
+
constructor(params: {
|
|
1510
|
+
readonly liquidity: bigint;
|
|
1511
|
+
readonly reallocatedAssets: bigint;
|
|
1512
|
+
readonly maxBorrowAssets: bigint;
|
|
1513
|
+
});
|
|
1514
|
+
/** Market liquidity at the data block, in loan-token assets. */
|
|
1515
|
+
readonly liquidity: bigint;
|
|
1516
|
+
/** Assets moved into the market by all reallocations, in loan-token assets. */
|
|
1517
|
+
readonly reallocatedAssets: bigint;
|
|
1518
|
+
/** Action's signed borrow cap (`maxBorrowAssets`), in loan-token assets. */
|
|
1519
|
+
readonly maxBorrowAssets: bigint;
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Thrown when a Lever's planned reallocations, replayed in order at the data block, leave a
|
|
1523
|
+
* target cap of the market's vault over its cap: a leg trimmed below the amount the planner chose
|
|
1524
|
+
* failed the cap check, and the planner's own amounts no longer fit once trimming dropped other
|
|
1525
|
+
* legs. Executing the plan would revert.
|
|
1526
|
+
*
|
|
1527
|
+
* @example
|
|
1528
|
+
* ```ts
|
|
1529
|
+
* import { LeverageReallocationOutsideCapsError } from "@morpho-org/morpho-sdk";
|
|
1530
|
+
*
|
|
1531
|
+
* const error = new LeverageReallocationOutsideCapsError({
|
|
1532
|
+
* vault: vaultAddress,
|
|
1533
|
+
* assets: 100n,
|
|
1534
|
+
* });
|
|
1535
|
+
* ```
|
|
1536
|
+
*/
|
|
1537
|
+
export declare class LeverageReallocationOutsideCapsError extends LeverageReallocationError {
|
|
1538
|
+
/**
|
|
1539
|
+
* @param params - Leg that breaks a cap.
|
|
1540
|
+
* @param params.vault - Vault the leg reallocates from.
|
|
1541
|
+
* @param params.assets - Assets the leg moves, in loan-token assets.
|
|
1542
|
+
*/
|
|
1543
|
+
constructor(params: {
|
|
1544
|
+
readonly vault: Address;
|
|
1545
|
+
readonly assets: bigint;
|
|
1546
|
+
});
|
|
1547
|
+
/** Vault the leg reallocates from. */
|
|
1548
|
+
readonly vault: Address;
|
|
1549
|
+
/** Assets the leg moves, in loan-token assets. */
|
|
1550
|
+
readonly assets: bigint;
|
|
1551
|
+
}
|
|
1552
|
+
export {};
|