@gearbox-protocol/sdk 16.0.0-next.41 → 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.
Files changed (62) hide show
  1. package/dist/cjs/model/errors.js +1 -0
  2. package/dist/cjs/model/index.js +5 -0
  3. package/dist/cjs/model/result.js +27 -0
  4. package/dist/cjs/onchain/accounts/intents/open-strategy.js +1 -1
  5. package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
  6. package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +14 -14
  7. package/dist/cjs/onchain/index.js +0 -1
  8. package/dist/cjs/onchain/market/zapper/errors.js +13 -12
  9. package/dist/cjs/onchain/validation/index.js +0 -1
  10. package/dist/cjs/preview/index.js +4 -1
  11. package/dist/cjs/preview/parse/errors.js +25 -22
  12. package/dist/cjs/preview/preview/errors.js +12 -11
  13. package/dist/cjs/preview/preview/previewOperation.js +41 -10
  14. package/dist/cjs/preview/simulate/errors.js +18 -17
  15. package/dist/cjs/sdk/execute/ExecuteApi.js +3 -3
  16. package/dist/cjs/sdk/index.js +5 -0
  17. package/dist/cjs/sdk/prepare/PrepareApi.js +254 -101
  18. package/dist/cjs/sdk/prepare/errors.js +93 -0
  19. package/dist/cjs/sdk/prepare/index.js +5 -0
  20. package/dist/esm/model/errors.js +1 -0
  21. package/dist/esm/model/index.js +3 -1
  22. package/dist/esm/model/result.js +24 -0
  23. package/dist/esm/onchain/accounts/intents/open-strategy.js +1 -1
  24. package/dist/esm/onchain/accounts/intents/tail.js +1 -1
  25. package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +14 -14
  26. package/dist/esm/onchain/index.js +2 -2
  27. package/dist/esm/onchain/market/zapper/errors.js +13 -12
  28. package/dist/esm/onchain/validation/index.js +2 -2
  29. package/dist/esm/preview/index.js +4 -2
  30. package/dist/esm/preview/parse/errors.js +25 -22
  31. package/dist/esm/preview/preview/errors.js +12 -11
  32. package/dist/esm/preview/preview/previewOperation.js +41 -10
  33. package/dist/esm/preview/simulate/errors.js +18 -17
  34. package/dist/esm/sdk/execute/ExecuteApi.js +3 -3
  35. package/dist/esm/sdk/index.js +2 -1
  36. package/dist/esm/sdk/prepare/PrepareApi.js +255 -102
  37. package/dist/esm/sdk/prepare/errors.js +89 -0
  38. package/dist/esm/sdk/prepare/index.js +2 -1
  39. package/dist/types/model/errors.d.ts +46 -0
  40. package/dist/types/model/index.d.ts +3 -1
  41. package/dist/types/model/result.d.ts +48 -0
  42. package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -3
  43. package/dist/types/onchain/accounts/intents/types.d.ts +13 -14
  44. package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +18 -5
  45. package/dist/types/onchain/index.d.ts +2 -2
  46. package/dist/types/onchain/market/zapper/errors.d.ts +20 -6
  47. package/dist/types/onchain/validation/index.d.ts +2 -2
  48. package/dist/types/preview/index.d.ts +5 -3
  49. package/dist/types/preview/parse/errors.d.ts +36 -11
  50. package/dist/types/preview/preview/errors.d.ts +17 -5
  51. package/dist/types/preview/preview/index.d.ts +2 -2
  52. package/dist/types/preview/preview/previewOperation.d.ts +21 -2
  53. package/dist/types/preview/simulate/errors.d.ts +21 -8
  54. package/dist/types/sdk/execute/types.d.ts +9 -14
  55. package/dist/types/sdk/index.d.ts +3 -2
  56. package/dist/types/sdk/prepare/PrepareApi.d.ts +30 -22
  57. package/dist/types/sdk/prepare/errors.d.ts +317 -0
  58. package/dist/types/sdk/prepare/index.d.ts +3 -2
  59. package/dist/types/sdk/prepare/types.d.ts +88 -62
  60. package/dist/types/sdk/preview/PreviewNamespace.d.ts +4 -1
  61. package/dist/types/sdk/preview/types.d.ts +7 -3
  62. package/package.json +11 -2
@@ -2,7 +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 { AddCollateralParams, AdjustLeverageParams, DelayedStrategyPrepare, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, LpParams, LpPrepare, LpRedeemParams, OpenStrategyParams, OpenStrategyPrepare, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyPrepare, StrategyRoutesPrepare, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
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";
6
7
  import { ChainOf, PrepareApi } from "./prepare/PrepareApi.js";
7
8
  import "./prepare/index.js";
8
9
  import { AccountPrepareRequest, IOpportunitiesExecute, OpenPrepareRequest, PoolPrepareRequest, PrepareRequest } from "./execute/types.js";
@@ -34,4 +35,4 @@ import { SourceUnavailableError } from "./errors/SourceUnavailableError.js";
34
35
  import { assertSameChains } from "./errors/assertSameChains.js";
35
36
  import { everyChainFailed } from "./errors/everyChainFailed.js";
36
37
  import "./errors/index.js";
37
- export { AbstractNamespace, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, BorrowLimitBinding, ChainOf, ChainRef, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DelayedStrategyPrepare, DepositStrategyParams, EnsureFreshChains, type EntityMerger, ExecuteApi, type FilterResult, FinalizeParams, 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, IntentPreviewError, type LeverageBand, LiquidationsNamespace, type ListMerger, LpParams, LpPrepare, LpRedeemParams, type MergeListResult, MergedQuery, MissingSourceError, Mode, NamespaceOptions, NoSourceServedError, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenPrepareRequest, OpenStrategyParams, OpenStrategyPrepare, type OperationState, OpportunitiesNamespace, type PathLossRate, PlainMultichainSDKOptions, PoolInput, PoolPrepareRequest, PositionInput, PositionsNamespace, PrepareApi, PrepareOptions, PrepareRequest, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewNamespace, PreviewRefusal, RepayStrategyParams, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyPrepare, StrategyRoutesPrepare, WithdrawCollateralParams, WithdrawStrategyParams, assertSameChains, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, raise, refuse };
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 { DataResponse } from "../../model/response.js";
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 { ChainQueryOneProps, MultichainConstruct } from "../../onchain/base/MultichainConstruct.js";
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 { AddCollateralParams, AdjustLeverageParams, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, LpParams, LpPrepare, LpRedeemParams, OpenStrategyParams, OpenStrategyPrepare, PoolInput, PositionInput, RepayStrategyParams, StrategyInput, StrategyPrepare, StrategyRoutesPrepare, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
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,67 +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, so it reads through
32
- * {@link MultichainConstruct.queryChain}: there is no second source to fall back
33
- * to, hence a chain the SDK does not cover, or one that fails the read, throws
34
- * rather than answering with empty metadata.
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.
36
+ *
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}.
35
44
  **/
36
45
  declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPrepare {
37
46
  #private;
38
47
  constructor(sdk: MultichainSDK, ensureFresh?: EnsureFreshChains);
39
- protected queryChain<T>(props: ChainQueryOneProps<T>): Promise<DataResponse<T>>;
40
48
  /**
41
49
  * {@inheritDoc IOpportunitiesPrepare.finalize}
42
50
  **/
43
- finalize(position: PositionInput, params: FinalizeParams): Promise<DataResponse<StrategyPrepare>>;
51
+ finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<StrategyResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
44
52
  /**
45
53
  * {@inheritDoc IOpportunitiesPrepare.deposit}
46
54
  **/
47
- deposit(pool: PoolInput, params: LpParams): LpPrepare;
55
+ deposit(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
48
56
  /**
49
57
  * {@inheritDoc IOpportunitiesPrepare.withdraw}
50
58
  **/
51
- withdraw(pool: PoolInput, params: LpParams): LpPrepare;
59
+ withdraw(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
52
60
  /**
53
61
  * {@inheritDoc IOpportunitiesPrepare.redeem}
54
62
  **/
55
- redeem(pool: PoolInput, params: LpRedeemParams): LpPrepare;
63
+ redeem(pool: PoolInput, params: LpRedeemParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
56
64
  /**
57
65
  * {@inheritDoc IOpportunitiesPrepare.openNewStrategy}
58
66
  **/
59
- openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<DataResponse<OpenStrategyPrepare>>;
67
+ openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError>>;
60
68
  /**
61
69
  * {@inheritDoc IOpportunitiesPrepare.depositStrategy}
62
70
  **/
63
- depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<DataResponse<StrategyPrepare>>;
71
+ depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedCollateralTokenError | UnsupportedTokenPairError | InsufficientPoolLiquidityError>>;
64
72
  /**
65
73
  * {@inheritDoc IOpportunitiesPrepare.withdrawStrategy}
66
74
  **/
67
- withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<DataResponse<StrategyRoutesPrepare>>;
75
+ withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError) & WithRouteRefusals>>;
68
76
  /**
69
77
  * {@inheritDoc IOpportunitiesPrepare.maxWithdraw}
70
78
  **/
71
- maxWithdraw(position: PositionInput): Promise<DataResponse<bigint>>;
79
+ maxWithdraw(position: PositionInput): Promise<bigint>;
72
80
  /**
73
81
  * {@inheritDoc IOpportunitiesPrepare.repayStrategy}
74
82
  **/
75
- repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<DataResponse<StrategyPrepare>>;
83
+ repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | UnsupportedCollateralTokenError>>;
76
84
  /**
77
85
  * {@inheritDoc IOpportunitiesPrepare.maxRepay}
78
86
  **/
79
- maxRepay(position: PositionInput): Promise<DataResponse<bigint>>;
87
+ maxRepay(position: PositionInput): Promise<bigint>;
80
88
  /**
81
89
  * {@inheritDoc IOpportunitiesPrepare.adjustLeverage}
82
90
  **/
83
- adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<DataResponse<StrategyRoutesPrepare>>;
91
+ adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError | InsufficientPoolLiquidityError | LeverageOutOfRangeError) & WithRouteRefusals>>;
84
92
  /**
85
93
  * {@inheritDoc IOpportunitiesPrepare.addCollateral}
86
94
  **/
87
- addCollateral(position: PositionInput, params: AddCollateralParams): Promise<DataResponse<StrategyPrepare>>;
95
+ addCollateral(position: PositionInput, params: AddCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
88
96
  /**
89
97
  * {@inheritDoc IOpportunitiesPrepare.withdrawCollateral}
90
98
  **/
91
- withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<DataResponse<StrategyPrepare>>;
99
+ withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
92
100
  /**
93
101
  * {@inheritDoc IOpportunitiesPrepare.leverageBand}
94
102
  **/
@@ -100,7 +108,7 @@ declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPr
100
108
  /**
101
109
  * {@inheritDoc IOpportunitiesPrepare.maxWithdrawCollateral}
102
110
  **/
103
- maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<DataResponse<bigint>>;
111
+ maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<bigint>;
104
112
  }
105
113
  //#endregion
106
114
  export { ChainOf, PrepareApi };
@@ -0,0 +1,317 @@
1
+ import { Bps, Token, TokenAmount } from "../../model/primitives.js";
2
+ import { IGearboxError } from "../../model/errors.js";
3
+ import "../../model/index.js";
4
+ import { BorrowLimitBinding, PreviewIssue } from "../../onchain/validation/refusal.js";
5
+ import { RouteRefusals } from "../../onchain/accounts/intents/types.js";
6
+ import "../../onchain/index.js";
7
+ import { Address } from "viem";
8
+ //#region src/sdk/prepare/errors.d.ts
9
+ /**
10
+ * Why a preparation was refused.
11
+ *
12
+ * One interface per reason, discriminated by `code`, each carrying the numbers
13
+ * behind that reason — so a caller reads the limit that was missed off the
14
+ * error instead of re-deriving it. Switch on `code` and the fields narrow with
15
+ * it.
16
+ *
17
+ * Most codes are the engine's `PreviewErrorReason` members, which is what keeps
18
+ * `prepare` and `preview` refusing in one vocabulary; what differs is where the
19
+ * numbers sit. The engine keeps them one level down, in `detail`, because it
20
+ * distributes them over `reason`; here they are stated outright, so it is
21
+ * `error.maxDebt` rather than `error.detail.maxDebt`.
22
+ *
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.
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;
35
+ /** The debt the request implies falls outside the facade's band. */
36
+ interface DebtOutOfRangeError extends IGearboxError {
37
+ code: "debtOutOfRange";
38
+ /** All three in the market's underlying. */
39
+ requested: TokenAmount;
40
+ minDebt: TokenAmount;
41
+ maxDebt: TokenAmount;
42
+ }
43
+ /** The leverage asked for cannot be expressed as a plan at all. */
44
+ interface LeverageOutOfRangeError extends IGearboxError {
45
+ code: "leverageOutOfRange";
46
+ /**
47
+ * Scaled by `LEVERAGE_DECIMALS` (`100n` = 1x), as the intent states it — not
48
+ * the read model's `Leverage`. Both are absent where the floor is not fixed:
49
+ * the deposit planner's is a function of the deposit.
50
+ **/
51
+ requested?: bigint;
52
+ min?: bigint;
53
+ }
54
+ /** Nothing on the account or in the wallet can fund what was asked. */
55
+ interface InsufficientSourceBalanceError extends IGearboxError {
56
+ code: "insufficientSourceBalance";
57
+ /**
58
+ * Both absent where the request never got as far as naming an amount, which
59
+ * is most of the sites that raise this.
60
+ **/
61
+ required?: TokenAmount;
62
+ held?: TokenAmount;
63
+ }
64
+ /** Input token is not accepted by the flow (e.g. deposit of a non-underlying). */
65
+ interface UnsupportedCollateralTokenError extends IGearboxError {
66
+ code: "unsupportedCollateralToken";
67
+ token: Token;
68
+ }
69
+ /**
70
+ * No route for the trade the plan needs: no pool pair between the tokens
71
+ * requested, several and none was picked, or the pathfinder itself found no
72
+ * path for the amounts involved.
73
+ **/
74
+ interface UnsupportedTokenPairError extends IGearboxError {
75
+ code: "unsupportedTokenPair";
76
+ /**
77
+ * `to` is absent where the market named no output for `from`; both are absent
78
+ * when the pathfinder reverted rather than answered.
79
+ **/
80
+ from?: Token;
81
+ to?: Token;
82
+ }
83
+ /**
84
+ * The intent cannot settle with a delay: the source has no redemption config,
85
+ * the chain has no compressor, or the payout is one the tail cannot serve.
86
+ **/
87
+ interface NoDelayedRouteError extends IGearboxError {
88
+ code: "noDelayedRoute";
89
+ /** Absent where the refusal is the intent's, not the token's. */
90
+ token?: Token;
91
+ }
92
+ /** Several redemption venues for the source, and nothing says which. */
93
+ interface MultipleDelayedWithdrawalsError extends IGearboxError {
94
+ code: "multipleDelayedWithdrawals";
95
+ token: Token;
96
+ venues: number;
97
+ }
98
+ /** A redemption of the same asset is already in flight. */
99
+ interface WithdrawalInProgressError extends IGearboxError {
100
+ code: "withdrawalInProgress";
101
+ /** The phantom token standing for the redemption already in flight. */
102
+ inFlight: TokenAmount;
103
+ }
104
+ /**
105
+ * The claim names no operation to resume: requested without an intent, or read
106
+ * through a compressor too old to report one.
107
+ **/
108
+ interface NoRecordedIntentError extends IGearboxError {
109
+ code: "noRecordedIntent";
110
+ }
111
+ /** The facade is paused: nothing can be done at all. */
112
+ interface MarketPausedError extends IGearboxError {
113
+ code: "marketPaused";
114
+ /**
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.
118
+ **/
119
+ creditManager: Address;
120
+ }
121
+ /** The facade is past its expiration date and takes no more multicalls. */
122
+ interface MarketExpiredError extends IGearboxError {
123
+ code: "marketExpired";
124
+ creditManager: Address;
125
+ /** Unix seconds, as the facade reports it. */
126
+ expirationDate: number;
127
+ }
128
+ /**
129
+ * The pool cannot lend what the plan draws right now — its free liquidity, the
130
+ * manager's debt limit or the per-block cap stands in the way.
131
+ **/
132
+ interface InsufficientPoolLiquidityError extends IGearboxError {
133
+ code: "insufficientPoolLiquidity";
134
+ /** Both in the market's underlying. */
135
+ requested: TokenAmount;
136
+ available: TokenAmount;
137
+ /**
138
+ * Which of the four ceilings ran out first, so a caller can say what would
139
+ * fix it — waiting for lenders and asking governance are opposite answers.
140
+ **/
141
+ binding: BorrowLimitBinding;
142
+ /**
143
+ * The largest position still openable, absent when even the minimum debt does
144
+ * not fit.
145
+ **/
146
+ solutionAmount?: TokenAmount;
147
+ }
148
+ /** The market takes no more quota for a token the plan wants to hold. */
149
+ interface QuotaLimitReachedError extends IGearboxError {
150
+ code: "quotaLimitReached";
151
+ /** The token whose quota is asked for. */
152
+ token: Token;
153
+ /**
154
+ * In the **underlying**, which is what a quota is measured in. `requested` is
155
+ * absent for a token the market opened no quota for at all — nothing was
156
+ * weighed against a limit.
157
+ **/
158
+ requested: TokenAmount | undefined;
159
+ available: TokenAmount;
160
+ }
161
+ /** The plan would increase the balance of a token the market forbids. */
162
+ interface ForbiddenTokenError extends IGearboxError {
163
+ code: "forbiddenToken";
164
+ token: Token;
165
+ }
166
+ /**
167
+ * The account would end the transaction owing more than its collateral is worth
168
+ * under liquidation thresholds, which the facade refuses to allow.
169
+ **/
170
+ interface InsufficientCollateralError extends IGearboxError {
171
+ code: "insufficientCollateral";
172
+ /**
173
+ * The factor that was compared, which for a call that hands funds over is the
174
+ * safe-price one; `safePrices` says which, since a projection always reports
175
+ * main prices.
176
+ **/
177
+ healthFactor: Bps;
178
+ /**
179
+ * The bar it was weighed against — the facade's own `1.0` for a check that
180
+ * asks whether the transaction lands, a form's higher bar for one that asks
181
+ * whether it is wise.
182
+ **/
183
+ required: Bps;
184
+ safePrices: boolean;
185
+ }
186
+ /** The pool is winding down: it still pays out, but takes no more deposits. */
187
+ interface PoolSunsetError extends IGearboxError {
188
+ code: "poolSunset";
189
+ pool: Address;
190
+ }
191
+ /**
192
+ * The account would end up with more quoted tokens than the facade enables at
193
+ * once. A count, not an amount — unlike {@link QuotaLimitReachedError}.
194
+ **/
195
+ interface QuotaCountExceededError extends IGearboxError {
196
+ code: "quotaCountExceeded";
197
+ count: number;
198
+ max: number;
199
+ }
200
+ /**
201
+ * The transaction could not be replayed: it is malformed, and every field
202
+ * derived from replayed balances is guesswork.
203
+ **/
204
+ interface MalformedTransactionError extends IGearboxError {
205
+ code: "malformedTransaction";
206
+ /**
207
+ * The SDK's own preview error code (the `ERROR_*` 1xxx constants). Named
208
+ * apart from `code`, which every error in the envelope spells the same way.
209
+ **/
210
+ previewCode: number;
211
+ /** What the replay reported, which is narrower than {@link message}. */
212
+ detail: string;
213
+ }
214
+ /**
215
+ * Opening asked for no target token and the market names none of its own, so
216
+ * there is nothing to put the position into.
217
+ *
218
+ * A market fact, not a bad argument: pass a `targetToken` to open against a
219
+ * manager that has no default one.
220
+ **/
221
+ interface NoStrategyTargetCollateralError extends IGearboxError {
222
+ code: "noStrategyTargetCollateral";
223
+ creditManager: Address;
224
+ }
225
+ /**
226
+ * No account at that address in the markets this SDK is connected to — closed
227
+ * since it was listed, or read on the wrong chain.
228
+ **/
229
+ interface CreditAccountNotFoundError extends IGearboxError {
230
+ code: "creditAccountNotFound";
231
+ creditAccount: Address;
232
+ }
233
+ /**
234
+ * The SDK could not answer at all: a read that failed, a chain it is not
235
+ * connected to, a market or token address it knows nothing about, a contract
236
+ * that reverted where nothing should, a bug of ours.
237
+ *
238
+ * The one code that is not a verdict on the request — everything above says
239
+ * "this cannot be done", this one says "we do not know". It exists so that a
240
+ * refusable `prepare` method always answers: the failure that used to escape
241
+ * as an exception arrives here instead, whole, under `cause`.
242
+ **/
243
+ interface UnexpectedFailureError extends IGearboxError {
244
+ code: "unexpectedFailure";
245
+ /** What actually went wrong, for a log and a bug report. */
246
+ cause: Error;
247
+ }
248
+ /**
249
+ * What every refusal of a two-route request carries on top of its own code,
250
+ * see {@link StrategyRoutesResult}.
251
+ *
252
+ * `refused` says why each route is missing, which is the answer a form needs
253
+ * even when neither exists: the error itself is the instant route's refusal —
254
+ * the one a caller can usually act on — or the delayed route's when the instant
255
+ * one did not get far enough to have a reason of its own.
256
+ **/
257
+ interface WithRouteRefusals {
258
+ refused: RouteRefusals;
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
+ }
288
+ /**
289
+ * The engine's refusal, as the error the namespace answers with.
290
+ *
291
+ * One place does the lifting, so the two shapes cannot drift: `reason` becomes
292
+ * `code`, the detail is spread onto the error, and the sentence comes from
293
+ * {@link MESSAGES}. A malformed transaction is spelled out rather than spread,
294
+ * because its detail names a `code` and a `message` of its own and they are not
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.
299
+ **/
300
+ declare function toRefusalError<I extends PreviewIssue>(issue: I): RefusalErrors[I["reason"]];
301
+ /**
302
+ * {@inheritDoc NoStrategyTargetCollateralError}
303
+ **/
304
+ declare function noStrategyTargetCollateral(creditManager: Address): NoStrategyTargetCollateralError;
305
+ /**
306
+ * {@inheritDoc CreditAccountNotFoundError}
307
+ **/
308
+ declare function creditAccountNotFound(creditAccount: Address): CreditAccountNotFoundError;
309
+ /**
310
+ * {@inheritDoc UnexpectedFailureError}
311
+ *
312
+ * Takes what was thrown, whatever that is: a `throw` is not obliged to raise an
313
+ * `Error`, and `cause` promises one.
314
+ **/
315
+ declare function unexpectedFailure(thrown: unknown): UnexpectedFailureError;
316
+ //#endregion
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,6 +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 { AddCollateralParams, AdjustLeverageParams, DelayedStrategyPrepare, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, LpParams, LpPrepare, LpRedeemParams, OpenStrategyParams, OpenStrategyPrepare, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyPrepare, StrategyRoutesPrepare, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
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";
5
6
  import { ChainOf, PrepareApi } from "./PrepareApi.js";
6
- export { AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding, ChainOf, DelayedStrategyPrepare, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, IntentPreviewError, type LeverageBand, LpParams, LpPrepare, LpRedeemParams, OpenStrategyParams, OpenStrategyPrepare, type OperationState, type PathLossRate, PoolInput, PositionInput, PrepareApi, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, RepayStrategyParams, StrategyInput, StrategyPrepare, StrategyRoutesPrepare, WithdrawCollateralParams, WithdrawStrategyParams, raise, refuse };
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 };