@gearbox-protocol/sdk 16.0.0-next.42 → 16.0.0-next.43
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/dist/cjs/model/index.js +4 -0
- package/dist/cjs/model/result.js +27 -0
- package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
- package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +14 -14
- package/dist/cjs/onchain/index.js +0 -1
- package/dist/cjs/onchain/market/zapper/errors.js +13 -12
- package/dist/cjs/onchain/validation/index.js +0 -1
- package/dist/cjs/preview/index.js +4 -1
- package/dist/cjs/preview/parse/errors.js +25 -22
- package/dist/cjs/preview/preview/errors.js +12 -11
- package/dist/cjs/preview/preview/previewOperation.js +41 -10
- package/dist/cjs/preview/simulate/errors.js +18 -17
- package/dist/cjs/sdk/execute/ExecuteApi.js +1 -1
- package/dist/cjs/sdk/index.js +1 -1
- package/dist/cjs/sdk/prepare/PrepareApi.js +198 -278
- package/dist/cjs/sdk/prepare/errors.js +5 -2
- package/dist/cjs/sdk/prepare/index.js +1 -1
- package/dist/esm/model/index.js +2 -1
- package/dist/esm/model/result.js +24 -0
- package/dist/esm/onchain/accounts/intents/tail.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +14 -14
- package/dist/esm/onchain/index.js +2 -2
- package/dist/esm/onchain/market/zapper/errors.js +13 -12
- package/dist/esm/onchain/validation/index.js +2 -2
- package/dist/esm/preview/index.js +4 -2
- package/dist/esm/preview/parse/errors.js +25 -22
- package/dist/esm/preview/preview/errors.js +12 -11
- package/dist/esm/preview/preview/previewOperation.js +41 -10
- package/dist/esm/preview/simulate/errors.js +18 -17
- package/dist/esm/sdk/execute/ExecuteApi.js +1 -1
- package/dist/esm/sdk/index.js +2 -2
- package/dist/esm/sdk/prepare/PrepareApi.js +199 -279
- package/dist/esm/sdk/prepare/errors.js +5 -2
- package/dist/esm/sdk/prepare/index.js +2 -2
- package/dist/types/model/errors.d.ts +3 -31
- package/dist/types/model/index.d.ts +3 -2
- package/dist/types/model/result.d.ts +48 -0
- package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +18 -5
- package/dist/types/onchain/index.d.ts +2 -2
- package/dist/types/onchain/market/zapper/errors.d.ts +20 -6
- package/dist/types/onchain/validation/index.d.ts +2 -2
- package/dist/types/preview/index.d.ts +5 -3
- package/dist/types/preview/parse/errors.d.ts +36 -11
- package/dist/types/preview/preview/errors.d.ts +17 -5
- package/dist/types/preview/preview/index.d.ts +2 -2
- package/dist/types/preview/preview/previewOperation.d.ts +21 -2
- package/dist/types/preview/simulate/errors.d.ts +21 -8
- package/dist/types/sdk/execute/types.d.ts +6 -11
- package/dist/types/sdk/index.d.ts +3 -3
- package/dist/types/sdk/prepare/PrepareApi.d.ts +29 -26
- package/dist/types/sdk/prepare/errors.d.ts +56 -19
- package/dist/types/sdk/prepare/index.d.ts +3 -3
- package/dist/types/sdk/prepare/types.d.ts +73 -74
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +4 -1
- package/dist/types/sdk/preview/types.d.ts +7 -3
- package/package.json +11 -2
|
@@ -2,8 +2,8 @@ import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErr
|
|
|
2
2
|
import { LeverageBand } from "../onchain/accounts/intents/leverage-band.js";
|
|
3
3
|
import { OperationState, PathLossRate } from "../onchain/accounts/intents/types.js";
|
|
4
4
|
import { ILiquidations, ILiquidationsByMode } from "./liquidations/types.js";
|
|
5
|
-
import { CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError,
|
|
6
|
-
import { AddCollateralParams, AdjustLeverageParams,
|
|
5
|
+
import { AccountFlowError, CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, toRefusalError, unexpectedFailure } from "./prepare/errors.js";
|
|
6
|
+
import { AddCollateralParams, AdjustLeverageParams, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
|
|
7
7
|
import { ChainOf, PrepareApi } from "./prepare/PrepareApi.js";
|
|
8
8
|
import "./prepare/index.js";
|
|
9
9
|
import { AccountPrepareRequest, IOpportunitiesExecute, OpenPrepareRequest, PoolPrepareRequest, PrepareRequest } from "./execute/types.js";
|
|
@@ -35,4 +35,4 @@ import { SourceUnavailableError } from "./errors/SourceUnavailableError.js";
|
|
|
35
35
|
import { assertSameChains } from "./errors/assertSameChains.js";
|
|
36
36
|
import { everyChainFailed } from "./errors/everyChainFailed.js";
|
|
37
37
|
import "./errors/index.js";
|
|
38
|
-
export { AbstractNamespace, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError,
|
|
38
|
+
export { AbstractNamespace, AccountFlowError, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, BorrowLimitBinding, ChainOf, ChainRef, CreditAccountNotFoundError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DebtOutOfRangeError, DelayedStrategyResult, DepositStrategyParams, EnsureFreshChains, type EntityMerger, ExecuteApi, type FilterResult, FinalizeParams, ForbiddenTokenError, GearboxSDK, GearboxSDKOptions, IGearboxSDK, ILiquidations, ILiquidationsByMode, INotices, INoticesByMode, IOpportunities, IOpportunitiesBase, IOpportunitiesByMode, IOpportunitiesExecute, IOpportunitiesOffchainBranch, IOpportunitiesOffchainOnly, IOpportunitiesOnchainBranch, IOpportunitiesOnchainOnly, IOpportunitiesPrepare, IOpportunityMergers, IPositionMergers, IPositions, IPositionsBase, IPositionsByMode, IPositionsOffchainBranch, IPositionsOffchainOnly, IPositionsOnchainBranch, IPositionsOnchainOnly, IPreview, IPreviewByMode, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, IntentPreviewError, type LeverageBand, LeverageOutOfRangeError, LiquidationsNamespace, type ListMerger, LpParams, LpRedeemParams, LpResult, MalformedTransactionError, MarketExpiredError, MarketPausedError, type MergeListResult, MergedQuery, MissingSourceError, Mode, MultipleDelayedWithdrawalsError, NamespaceOptions, NoDelayedRouteError, NoRecordedIntentError, NoSourceServedError, NoStrategyTargetCollateralError, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenFlowError, OpenPrepareRequest, OpenStrategyParams, OpenStrategyResult, type OperationState, OpportunitiesNamespace, type PathLossRate, PlainMultichainSDKOptions, PoolInput, PoolPrepareRequest, PoolSunsetError, PositionInput, PositionsNamespace, PrepareApi, PrepareOptions, PrepareRequest, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewNamespace, PreviewRefusal, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, RepayStrategyParams, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyResult, StrategyRoutesResult, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawCollateralParams, WithdrawStrategyParams, WithdrawalInProgressError, assertSameChains, creditAccountNotFound, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, raise, refuse, toRefusalError, unexpectedFailure };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Bps, ChainId } from "../../model/primitives.js";
|
|
2
2
|
import { PositionCollateral, StrategyPosition } from "../../model/positions.js";
|
|
3
|
-
import {
|
|
3
|
+
import { SDKReturn } from "../../model/result.js";
|
|
4
4
|
import "../../model/index.js";
|
|
5
5
|
import { Asset } from "../../onchain/base/types.js";
|
|
6
6
|
import { OnchainSDK } from "../../onchain/OnchainSDK.js";
|
|
7
7
|
import { MultichainSDK } from "../../onchain/MultichainSDK.js";
|
|
8
|
-
import {
|
|
8
|
+
import { MultichainConstruct } from "../../onchain/base/MultichainConstruct.js";
|
|
9
9
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
10
10
|
import "../../onchain/index.js";
|
|
11
|
-
import {
|
|
11
|
+
import { AccountFlowError, DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
|
|
12
|
+
import { AddCollateralParams, AdjustLeverageParams, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
12
13
|
import { EnsureFreshChains } from "../types.js";
|
|
13
14
|
import { Address } from "viem";
|
|
14
15
|
//#region src/sdk/prepare/PrepareApi.d.ts
|
|
@@ -28,72 +29,74 @@ type ChainOf = (chainId: ChainId) => OnchainSDK;
|
|
|
28
29
|
* protocol knowledge stays in `CreditAccountOperationsService` and
|
|
29
30
|
* `PoolService`.
|
|
30
31
|
*
|
|
31
|
-
* A prepared operation names one chain
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* A prepared operation names one chain and reads it directly: there is no
|
|
33
|
+
* second source to fall back to, so a chain the SDK does not cover, or one
|
|
34
|
+
* that fails the read, is a failure of the whole request rather than a thinner
|
|
35
|
+
* answer.
|
|
35
36
|
*
|
|
36
|
-
* No method here throws. Every way a preparation can
|
|
37
|
-
* refusals, the
|
|
38
|
-
* engine raises — comes back
|
|
39
|
-
*
|
|
37
|
+
* No refusable async method here throws. Every way such a preparation can
|
|
38
|
+
* fail — the market's own refusals, the ones the namespace decides itself, and
|
|
39
|
+
* anything the chain or the engine raises — comes back in the failure half of
|
|
40
|
+
* its `SDKReturn`, under the codes that method's signature names. A caller
|
|
41
|
+
* writes one branch, not a branch and a `try`. The synchronous LP methods and
|
|
42
|
+
* the bare `max*` reads throw on bugs and lifecycle errors instead, see
|
|
43
|
+
* {@link IOpportunitiesPrepare}.
|
|
40
44
|
**/
|
|
41
45
|
declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPrepare {
|
|
42
46
|
#private;
|
|
43
47
|
constructor(sdk: MultichainSDK, ensureFresh?: EnsureFreshChains);
|
|
44
|
-
protected queryChain<T>(props: ChainQueryOneProps<T>): Promise<DataResponse<T>>;
|
|
45
48
|
/**
|
|
46
49
|
* {@inheritDoc IOpportunitiesPrepare.finalize}
|
|
47
50
|
**/
|
|
48
|
-
finalize(position: PositionInput, params: FinalizeParams): Promise<
|
|
51
|
+
finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<StrategyResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
|
|
49
52
|
/**
|
|
50
53
|
* {@inheritDoc IOpportunitiesPrepare.deposit}
|
|
51
54
|
**/
|
|
52
|
-
deposit(pool: PoolInput, params: LpParams):
|
|
55
|
+
deposit(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
53
56
|
/**
|
|
54
57
|
* {@inheritDoc IOpportunitiesPrepare.withdraw}
|
|
55
58
|
**/
|
|
56
|
-
withdraw(pool: PoolInput, params: LpParams):
|
|
59
|
+
withdraw(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
57
60
|
/**
|
|
58
61
|
* {@inheritDoc IOpportunitiesPrepare.redeem}
|
|
59
62
|
**/
|
|
60
|
-
redeem(pool: PoolInput, params: LpRedeemParams):
|
|
63
|
+
redeem(pool: PoolInput, params: LpRedeemParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
61
64
|
/**
|
|
62
65
|
* {@inheritDoc IOpportunitiesPrepare.openNewStrategy}
|
|
63
66
|
**/
|
|
64
|
-
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<
|
|
67
|
+
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError>>;
|
|
65
68
|
/**
|
|
66
69
|
* {@inheritDoc IOpportunitiesPrepare.depositStrategy}
|
|
67
70
|
**/
|
|
68
|
-
depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<
|
|
71
|
+
depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedCollateralTokenError | UnsupportedTokenPairError | InsufficientPoolLiquidityError>>;
|
|
69
72
|
/**
|
|
70
73
|
* {@inheritDoc IOpportunitiesPrepare.withdrawStrategy}
|
|
71
74
|
**/
|
|
72
|
-
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<
|
|
75
|
+
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError) & WithRouteRefusals>>;
|
|
73
76
|
/**
|
|
74
77
|
* {@inheritDoc IOpportunitiesPrepare.maxWithdraw}
|
|
75
78
|
**/
|
|
76
|
-
maxWithdraw(position: PositionInput): Promise<
|
|
79
|
+
maxWithdraw(position: PositionInput): Promise<bigint>;
|
|
77
80
|
/**
|
|
78
81
|
* {@inheritDoc IOpportunitiesPrepare.repayStrategy}
|
|
79
82
|
**/
|
|
80
|
-
repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<
|
|
83
|
+
repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | UnsupportedCollateralTokenError>>;
|
|
81
84
|
/**
|
|
82
85
|
* {@inheritDoc IOpportunitiesPrepare.maxRepay}
|
|
83
86
|
**/
|
|
84
|
-
maxRepay(position: PositionInput): Promise<
|
|
87
|
+
maxRepay(position: PositionInput): Promise<bigint>;
|
|
85
88
|
/**
|
|
86
89
|
* {@inheritDoc IOpportunitiesPrepare.adjustLeverage}
|
|
87
90
|
**/
|
|
88
|
-
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<
|
|
91
|
+
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError | InsufficientPoolLiquidityError | LeverageOutOfRangeError) & WithRouteRefusals>>;
|
|
89
92
|
/**
|
|
90
93
|
* {@inheritDoc IOpportunitiesPrepare.addCollateral}
|
|
91
94
|
**/
|
|
92
|
-
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<
|
|
95
|
+
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
|
|
93
96
|
/**
|
|
94
97
|
* {@inheritDoc IOpportunitiesPrepare.withdrawCollateral}
|
|
95
98
|
**/
|
|
96
|
-
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<
|
|
99
|
+
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
|
|
97
100
|
/**
|
|
98
101
|
* {@inheritDoc IOpportunitiesPrepare.leverageBand}
|
|
99
102
|
**/
|
|
@@ -105,7 +108,7 @@ declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPr
|
|
|
105
108
|
/**
|
|
106
109
|
* {@inheritDoc IOpportunitiesPrepare.maxWithdrawCollateral}
|
|
107
110
|
**/
|
|
108
|
-
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<
|
|
111
|
+
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<bigint>;
|
|
109
112
|
}
|
|
110
113
|
//#endregion
|
|
111
114
|
export { ChainOf, PrepareApi };
|
|
@@ -18,13 +18,20 @@ import { Address } from "viem";
|
|
|
18
18
|
* `prepare` and `preview` refusing in one vocabulary; what differs is where the
|
|
19
19
|
* numbers sit. The engine keeps them one level down, in `detail`, because it
|
|
20
20
|
* distributes them over `reason`; here they are stated outright, so it is
|
|
21
|
-
* `error.maxDebt` rather than `error.detail.maxDebt`.
|
|
22
|
-
* namespace's own, raised before or around the engine.
|
|
21
|
+
* `error.maxDebt` rather than `error.detail.maxDebt`.
|
|
23
22
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* There is deliberately no union of all of them: each `prepare` method names
|
|
24
|
+
* exactly the codes its own flow can raise, see the signatures in
|
|
25
|
+
* {@link IOpportunitiesPrepare}. What is shared is the plumbing every flow
|
|
26
|
+
* goes through, and that is the two base unions below.
|
|
26
27
|
**/
|
|
27
|
-
|
|
28
|
+
/**
|
|
29
|
+
* What ANY operation on an existing account can refuse with: the engine's
|
|
30
|
+
* shared guards, the missing account, and a wrapped crash.
|
|
31
|
+
**/
|
|
32
|
+
type AccountFlowError = MarketPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | InsufficientSourceBalanceError | CreditAccountNotFoundError | UnexpectedFailureError;
|
|
33
|
+
/** Same guards for the account-less open flow. */
|
|
34
|
+
type OpenFlowError = MarketPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | InsufficientSourceBalanceError | UnexpectedFailureError;
|
|
28
35
|
/** The debt the request implies falls outside the facade's band. */
|
|
29
36
|
interface DebtOutOfRangeError extends IGearboxError {
|
|
30
37
|
code: "debtOutOfRange";
|
|
@@ -101,15 +108,15 @@ interface WithdrawalInProgressError extends IGearboxError {
|
|
|
101
108
|
interface NoRecordedIntentError extends IGearboxError {
|
|
102
109
|
code: "noRecordedIntent";
|
|
103
110
|
}
|
|
104
|
-
/** The facade
|
|
111
|
+
/** The facade is paused: nothing can be done at all. */
|
|
105
112
|
interface MarketPausedError extends IGearboxError {
|
|
106
113
|
code: "marketPaused";
|
|
107
114
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
115
|
+
* The paused credit manager. Always present from `prepare`: the engine's
|
|
116
|
+
* shared guards check the manager, and the pool-paused variant is raised
|
|
117
|
+
* only by the preview-side `checkOperation` — it never reaches this union.
|
|
110
118
|
**/
|
|
111
|
-
creditManager
|
|
112
|
-
pool?: Address;
|
|
119
|
+
creditManager: Address;
|
|
113
120
|
}
|
|
114
121
|
/** The facade is past its expiration date and takes no more multicalls. */
|
|
115
122
|
interface MarketExpiredError extends IGearboxError {
|
|
@@ -230,9 +237,8 @@ interface CreditAccountNotFoundError extends IGearboxError {
|
|
|
230
237
|
*
|
|
231
238
|
* The one code that is not a verdict on the request — everything above says
|
|
232
239
|
* "this cannot be done", this one says "we do not know". It exists so that a
|
|
233
|
-
* `prepare` method always answers: the failure that used to escape
|
|
234
|
-
* exception arrives here instead, whole, under `cause`.
|
|
235
|
-
* chain as failed alongside it.
|
|
240
|
+
* refusable `prepare` method always answers: the failure that used to escape
|
|
241
|
+
* as an exception arrives here instead, whole, under `cause`.
|
|
236
242
|
**/
|
|
237
243
|
interface UnexpectedFailureError extends IGearboxError {
|
|
238
244
|
code: "unexpectedFailure";
|
|
@@ -240,17 +246,45 @@ interface UnexpectedFailureError extends IGearboxError {
|
|
|
240
246
|
cause: Error;
|
|
241
247
|
}
|
|
242
248
|
/**
|
|
243
|
-
*
|
|
244
|
-
* {@link
|
|
249
|
+
* What every refusal of a two-route request carries on top of its own code,
|
|
250
|
+
* see {@link StrategyRoutesResult}.
|
|
245
251
|
*
|
|
246
252
|
* `refused` says why each route is missing, which is the answer a form needs
|
|
247
253
|
* even when neither exists: the error itself is the instant route's refusal —
|
|
248
254
|
* the one a caller can usually act on — or the delayed route's when the instant
|
|
249
255
|
* one did not get far enough to have a reason of its own.
|
|
250
256
|
**/
|
|
251
|
-
|
|
257
|
+
interface WithRouteRefusals {
|
|
252
258
|
refused: RouteRefusals;
|
|
253
|
-
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The error each engine reason maps to — the range of {@link toRefusalError},
|
|
262
|
+
* spelled reason by reason so a narrow issue arrives as a narrow error.
|
|
263
|
+
*
|
|
264
|
+
* A lookup table, not a vocabulary: nothing answers with `RefusalErrors[R]`
|
|
265
|
+
* as a union. The unions callers see are the ones each method's signature
|
|
266
|
+
* spells out.
|
|
267
|
+
**/
|
|
268
|
+
interface RefusalErrors {
|
|
269
|
+
debtOutOfRange: DebtOutOfRangeError;
|
|
270
|
+
leverageOutOfRange: LeverageOutOfRangeError;
|
|
271
|
+
insufficientSourceBalance: InsufficientSourceBalanceError;
|
|
272
|
+
unsupportedCollateralToken: UnsupportedCollateralTokenError;
|
|
273
|
+
unsupportedTokenPair: UnsupportedTokenPairError;
|
|
274
|
+
noDelayedRoute: NoDelayedRouteError;
|
|
275
|
+
multipleDelayedWithdrawals: MultipleDelayedWithdrawalsError;
|
|
276
|
+
withdrawalInProgress: WithdrawalInProgressError;
|
|
277
|
+
noRecordedIntent: NoRecordedIntentError;
|
|
278
|
+
marketPaused: MarketPausedError;
|
|
279
|
+
marketExpired: MarketExpiredError;
|
|
280
|
+
insufficientPoolLiquidity: InsufficientPoolLiquidityError;
|
|
281
|
+
quotaLimitReached: QuotaLimitReachedError;
|
|
282
|
+
forbiddenToken: ForbiddenTokenError;
|
|
283
|
+
insufficientCollateral: InsufficientCollateralError;
|
|
284
|
+
poolSunset: PoolSunsetError;
|
|
285
|
+
quotaCountExceeded: QuotaCountExceededError;
|
|
286
|
+
malformedTransaction: MalformedTransactionError;
|
|
287
|
+
}
|
|
254
288
|
/**
|
|
255
289
|
* The engine's refusal, as the error the namespace answers with.
|
|
256
290
|
*
|
|
@@ -259,8 +293,11 @@ type RoutesPrepareError = PrepareError & {
|
|
|
259
293
|
* {@link MESSAGES}. A malformed transaction is spelled out rather than spread,
|
|
260
294
|
* because its detail names a `code` and a `message` of its own and they are not
|
|
261
295
|
* the envelope's.
|
|
296
|
+
*
|
|
297
|
+
* Generic over the issue it is handed, so a call site that already knows the
|
|
298
|
+
* reason gets that reason's error back rather than a union to narrow again.
|
|
262
299
|
**/
|
|
263
|
-
declare function
|
|
300
|
+
declare function toRefusalError<I extends PreviewIssue>(issue: I): RefusalErrors[I["reason"]];
|
|
264
301
|
/**
|
|
265
302
|
* {@inheritDoc NoStrategyTargetCollateralError}
|
|
266
303
|
**/
|
|
@@ -277,4 +314,4 @@ declare function creditAccountNotFound(creditAccount: Address): CreditAccountNot
|
|
|
277
314
|
**/
|
|
278
315
|
declare function unexpectedFailure(thrown: unknown): UnexpectedFailureError;
|
|
279
316
|
//#endregion
|
|
280
|
-
export { CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError,
|
|
317
|
+
export { AccountFlowError, CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, toRefusalError, unexpectedFailure };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, raise, refuse } from "../../onchain/validation/refusal.js";
|
|
2
2
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
3
3
|
import { OperationState, PathLossRate } from "../../onchain/accounts/intents/types.js";
|
|
4
|
-
import { CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError,
|
|
5
|
-
import { AddCollateralParams, AdjustLeverageParams,
|
|
4
|
+
import { AccountFlowError, CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, toRefusalError, unexpectedFailure } from "./errors.js";
|
|
5
|
+
import { AddCollateralParams, AdjustLeverageParams, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
6
6
|
import { ChainOf, PrepareApi } from "./PrepareApi.js";
|
|
7
|
-
export { AddCollateralParams, AdjustLeverageParams,
|
|
7
|
+
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding, ChainOf, CreditAccountNotFoundError, DebtOutOfRangeError, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, ForbiddenTokenError, IOpportunitiesPrepare, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, IntentPreviewError, type LeverageBand, LeverageOutOfRangeError, LpParams, LpRedeemParams, LpResult, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, PoolSunsetError, PositionInput, PrepareApi, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawCollateralParams, WithdrawStrategyParams, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, raise, refuse, toRefusalError, unexpectedFailure };
|