@gearbox-protocol/sdk 16.0.0-next.42 → 16.0.0-next.44
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/index.js +0 -2
- package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
- package/dist/cjs/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +13 -7
- package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +0 -19
- package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +1 -2
- package/dist/cjs/onchain/index.js +0 -5
- package/dist/cjs/onchain/market/index.js +0 -2
- package/dist/cjs/onchain/market/zapper/ZapperContract.js +15 -8
- package/dist/cjs/onchain/market/zapper/errors.js +0 -17
- package/dist/cjs/onchain/market/zapper/index.js +1 -2
- package/dist/cjs/onchain/validation/checks.js +1 -1
- package/dist/cjs/onchain/validation/index.js +0 -1
- package/dist/cjs/preview/index.js +2 -8
- package/dist/cjs/preview/parse/errors.js +0 -32
- package/dist/cjs/preview/parse/index.js +1 -5
- package/dist/cjs/preview/parse/parseOperationCalldata.js +28 -17
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +17 -11
- package/dist/cjs/preview/prerequisites/checkPrerequisites.js +5 -2
- package/dist/cjs/preview/preview/detectDelayedClaim.js +9 -7
- package/dist/cjs/preview/preview/detectDelayedOperation.js +11 -4
- package/dist/cjs/preview/preview/errors.js +0 -16
- package/dist/cjs/preview/preview/index.js +1 -2
- package/dist/cjs/preview/preview/previewOperation.js +30 -11
- package/dist/cjs/preview/preview/previewPoolPositionOperation.js +7 -3
- package/dist/cjs/preview/simulate/errors.js +15 -24
- package/dist/cjs/preview/simulate/index.js +1 -1
- package/dist/cjs/preview/simulate/simulateOperation.js +6 -4
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +6 -3
- 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/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/index.js +2 -1
- package/dist/esm/model/result.js +24 -0
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/index.js +1 -2
- package/dist/esm/onchain/accounts/intents/tail.js +1 -1
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +14 -8
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +1 -19
- package/dist/esm/onchain/accounts/withdrawal-compressor/index.js +2 -2
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/index.js +2 -4
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/index.js +1 -2
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +16 -9
- package/dist/esm/onchain/market/zapper/errors.js +1 -17
- package/dist/esm/onchain/market/zapper/index.js +2 -2
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/onchain/validation/checks.js +1 -1
- package/dist/esm/onchain/validation/index.js +2 -2
- package/dist/esm/preview/index.js +3 -5
- package/dist/esm/preview/parse/errors.js +1 -30
- package/dist/esm/preview/parse/index.js +2 -3
- package/dist/esm/preview/parse/parseOperationCalldata.js +28 -17
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +17 -11
- package/dist/esm/preview/prerequisites/checkPrerequisites.js +5 -2
- package/dist/esm/preview/preview/detectDelayedClaim.js +9 -7
- package/dist/esm/preview/preview/detectDelayedOperation.js +11 -4
- package/dist/esm/preview/preview/errors.js +1 -16
- package/dist/esm/preview/preview/index.js +2 -2
- package/dist/esm/preview/preview/previewOperation.js +30 -11
- package/dist/esm/preview/preview/previewPoolPositionOperation.js +7 -3
- package/dist/esm/preview/simulate/errors.js +16 -24
- package/dist/esm/preview/simulate/index.js +2 -2
- package/dist/esm/preview/simulate/simulateOperation.js +6 -4
- package/dist/esm/preview/simulate/simulatePoolOperation.js +7 -4
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- 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 +4 -32
- package/dist/types/model/index.d.ts +3 -2
- package/dist/types/model/result.d.ts +48 -0
- package/dist/types/onchain/accounts/index.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.d.ts +6 -4
- package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +9 -5
- package/dist/types/onchain/accounts/withdrawal-compressor/index.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/types.d.ts +6 -4
- package/dist/types/onchain/index.d.ts +4 -4
- package/dist/types/onchain/market/index.d.ts +1 -1
- package/dist/types/onchain/market/zapper/ZapperContract.d.ts +7 -3
- package/dist/types/onchain/market/zapper/errors.d.ts +11 -6
- package/dist/types/onchain/market/zapper/index.d.ts +1 -1
- package/dist/types/onchain/market/zapper/types.d.ts +4 -1
- package/dist/types/onchain/validation/checks.d.ts +1 -1
- 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 +19 -12
- package/dist/types/preview/parse/index.d.ts +1 -1
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +5 -1
- package/dist/types/preview/parse/parsePoolOperationCalldata.d.ts +5 -2
- package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +6 -1
- package/dist/types/preview/preview/detectDelayedClaim.d.ts +7 -6
- package/dist/types/preview/preview/detectDelayedOperation.d.ts +3 -1
- package/dist/types/preview/preview/errors.d.ts +8 -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/preview/previewPoolPositionOperation.d.ts +3 -1
- package/dist/types/preview/simulate/errors.d.ts +12 -8
- package/dist/types/preview/simulate/index.d.ts +2 -2
- package/dist/types/preview/simulate/simulateOperation.d.ts +4 -1
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +4 -1
- 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 +57 -20
- 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/dist/types/sdk/types.d.ts +1 -3
- package/package.json +11 -2
|
@@ -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 };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Bps } from "../../model/primitives.js";
|
|
2
|
-
import { WithError } from "../../model/errors.js";
|
|
1
|
+
import { Bps, Timestamp } from "../../model/primitives.js";
|
|
3
2
|
import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
|
|
4
3
|
import { PositionCollateral, StrategyPosition, StrategyPositionKey } from "../../model/positions.js";
|
|
5
|
-
import {
|
|
4
|
+
import { SDKReturn } from "../../model/result.js";
|
|
6
5
|
import { PositionClaimableWithdrawal } from "../../model/withdrawals.js";
|
|
7
6
|
import "../../model/index.js";
|
|
8
7
|
import { Asset } from "../../onchain/base/types.js";
|
|
@@ -14,18 +13,18 @@ import { AccountCalculatorOperation } from "../../onchain/accounts/intents/opera
|
|
|
14
13
|
import { DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteRefusals } from "../../onchain/accounts/intents/types.js";
|
|
15
14
|
import { OpenStrategyState } from "../../onchain/accounts/intents/open-strategy.js";
|
|
16
15
|
import "../../onchain/index.js";
|
|
17
|
-
import {
|
|
16
|
+
import { AccountFlowError, DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
|
|
18
17
|
import { Address } from "viem";
|
|
19
18
|
//#region src/sdk/prepare/types.d.ts
|
|
20
19
|
/**
|
|
21
20
|
* What a pool deposit or withdrawal comes to.
|
|
22
21
|
*
|
|
23
|
-
* Shaped like {@link
|
|
22
|
+
* Shaped like {@link StrategyResult} so both kinds of result are consumed the
|
|
24
23
|
* same way, with the pool's own numbers as the state: the ERC-4626
|
|
25
24
|
* conversion applied to the amount, at the rate of the block the market was
|
|
26
25
|
* loaded at.
|
|
27
26
|
**/
|
|
28
|
-
interface
|
|
27
|
+
interface LpResult {
|
|
29
28
|
/**
|
|
30
29
|
* Always empty: a pool operation is a single transaction, so there is no
|
|
31
30
|
* chain of steps to show. Present so callers can treat both kinds of
|
|
@@ -42,15 +41,15 @@ interface LpPlan {
|
|
|
42
41
|
* operation is a single call on the pool or on its zapper.
|
|
43
42
|
**/
|
|
44
43
|
calls: MultiCall[];
|
|
44
|
+
/** Block of the chain state this result was computed from. */
|
|
45
|
+
blockNumber: number;
|
|
46
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
47
|
+
timestamp: Timestamp;
|
|
45
48
|
}
|
|
46
|
-
/**
|
|
47
|
-
* {@link LpPlan}, or why the pool cannot serve the request.
|
|
48
|
-
**/
|
|
49
|
-
type LpPrepare = WithError<LpPlan, PrepareError>;
|
|
50
49
|
/**
|
|
51
50
|
* What an operation on an existing credit account comes to.
|
|
52
51
|
**/
|
|
53
|
-
interface
|
|
52
|
+
interface StrategyResult {
|
|
54
53
|
/**
|
|
55
54
|
* The logical steps, each carrying the amounts it was computed from.
|
|
56
55
|
* Useful for showing the user what will happen, and for pinning behaviour
|
|
@@ -67,29 +66,23 @@ interface StrategyPlan {
|
|
|
67
66
|
* through `sdk.accounts`.
|
|
68
67
|
**/
|
|
69
68
|
calls: MultiCall[];
|
|
69
|
+
/** Block of the chain state this result was computed from. */
|
|
70
|
+
blockNumber: number;
|
|
71
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
72
|
+
timestamp: Timestamp;
|
|
70
73
|
}
|
|
71
|
-
/**
|
|
72
|
-
* {@link StrategyPlan}, or why the request cannot be served.
|
|
73
|
-
*
|
|
74
|
-
* A failure here means the request itself is not viable — not that a call
|
|
75
|
-
* failed — so it is a value rather than an exception: too much leverage, too
|
|
76
|
-
* little of the source token, a token the flow does not accept. What could not
|
|
77
|
-
* be done is `error.code`, and the limit that was missed is on the error beside
|
|
78
|
-
* it, see {@link PrepareError}.
|
|
79
|
-
**/
|
|
80
|
-
type StrategyPrepare = WithError<StrategyPlan, PrepareError>;
|
|
81
74
|
/**
|
|
82
75
|
* What the leading half of a delayed operation comes to: the request
|
|
83
76
|
* transaction, plus what it recorded for the tail and where that tail leads.
|
|
84
77
|
*
|
|
85
|
-
* Shaped like {@link
|
|
78
|
+
* Shaped like {@link StrategyResult} with one field more, so the instant and
|
|
86
79
|
* the delayed route of the same request are compared side by side — and they
|
|
87
80
|
* are meant to be compared on the same footing, so `state` is the end of the
|
|
88
81
|
* operation in both, not the end of the transaction.
|
|
89
82
|
**/
|
|
90
|
-
interface
|
|
83
|
+
interface DelayedStrategyResult {
|
|
91
84
|
/**
|
|
92
|
-
* {@inheritDoc
|
|
85
|
+
* {@inheritDoc StrategyResult.operations}
|
|
93
86
|
**/
|
|
94
87
|
operations: AccountCalculatorOperation[];
|
|
95
88
|
/**
|
|
@@ -104,7 +97,7 @@ interface DelayedStrategyPlan {
|
|
|
104
97
|
**/
|
|
105
98
|
state: OperationState;
|
|
106
99
|
/**
|
|
107
|
-
* {@inheritDoc
|
|
100
|
+
* {@inheritDoc StrategyResult.calls}
|
|
108
101
|
**/
|
|
109
102
|
calls: MultiCall[];
|
|
110
103
|
/**
|
|
@@ -112,11 +105,11 @@ interface DelayedStrategyPlan {
|
|
|
112
105
|
* {@link DelayedStart}.
|
|
113
106
|
**/
|
|
114
107
|
delayed: DelayedStart;
|
|
108
|
+
/** Block of the chain state this result was computed from. */
|
|
109
|
+
blockNumber: number;
|
|
110
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
111
|
+
timestamp: Timestamp;
|
|
115
112
|
}
|
|
116
|
-
/**
|
|
117
|
-
* {@link DelayedStrategyPlan}, or why the redemption route cannot be taken.
|
|
118
|
-
**/
|
|
119
|
-
type DelayedStrategyPrepare = WithError<DelayedStrategyPlan, PrepareError>;
|
|
120
113
|
/**
|
|
121
114
|
* What one of the two flows that sell a position asset —
|
|
122
115
|
* {@link IOpportunitiesPrepare.withdrawStrategy} and
|
|
@@ -128,55 +121,47 @@ type DelayedStrategyPrepare = WithError<DelayedStrategyPlan, PrepareError>;
|
|
|
128
121
|
* are quoted from one request. A route the account cannot take is `undefined`
|
|
129
122
|
* with its refusal in `refused`, which is what lets a form offer exactly the
|
|
130
123
|
* routes that exist; a failure means neither does, and the error still carries
|
|
131
|
-
* `refused`, see {@link
|
|
124
|
+
* `refused`, see {@link WithRouteRefusals}.
|
|
132
125
|
**/
|
|
133
|
-
interface
|
|
126
|
+
interface StrategyRoutesResult {
|
|
134
127
|
/**
|
|
135
128
|
* The router route: one transaction, settled on the spot. `undefined`
|
|
136
129
|
* when the asset cannot be sold, see `refused.instant`.
|
|
137
130
|
**/
|
|
138
|
-
instant:
|
|
131
|
+
instant: StrategyResult | undefined;
|
|
139
132
|
/**
|
|
140
133
|
* The request half of the redemption route, which
|
|
141
134
|
* {@link IOpportunitiesPrepare.finalize} completes once it matures.
|
|
142
135
|
* `undefined` when the route does not exist — no redemption venue for the
|
|
143
136
|
* asset, or a request that settles at once anyway — see `refused.delayed`.
|
|
144
137
|
**/
|
|
145
|
-
delayed:
|
|
138
|
+
delayed: DelayedStrategyResult | undefined;
|
|
146
139
|
/**
|
|
147
140
|
* Why a missing route was refused, see {@link RouteRefusals}.
|
|
148
141
|
**/
|
|
149
142
|
refused: RouteRefusals;
|
|
143
|
+
/** Block of the chain state this result was computed from. */
|
|
144
|
+
blockNumber: number;
|
|
145
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
146
|
+
timestamp: Timestamp;
|
|
150
147
|
}
|
|
151
|
-
/**
|
|
152
|
-
* {@link StrategyRoutes}, or the refusal of both routes at once.
|
|
153
|
-
**/
|
|
154
|
-
type StrategyRoutesPrepare = WithError<StrategyRoutes, RoutesPrepareError>;
|
|
155
148
|
/**
|
|
156
149
|
* What opening a new leveraged position comes to.
|
|
157
150
|
*
|
|
158
151
|
* The only result that reports both an expected and a floor branch: opening
|
|
159
152
|
* takes both from a single pathfinder call, and `openCA` consumes both.
|
|
160
153
|
**/
|
|
161
|
-
interface
|
|
154
|
+
interface OpenStrategyResult {
|
|
162
155
|
/**
|
|
163
156
|
* Everything the opening arrives at: the projection, both branches of the
|
|
164
157
|
* post-open balances and quotas, and the router path `openCA` is handed.
|
|
165
158
|
**/
|
|
166
159
|
state: OpenStrategyState;
|
|
160
|
+
/** Block of the chain state this result was computed from. */
|
|
161
|
+
blockNumber: number;
|
|
162
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
163
|
+
timestamp: Timestamp;
|
|
167
164
|
}
|
|
168
|
-
/**
|
|
169
|
-
* {@link OpenStrategyPlan}, or why the position cannot be opened.
|
|
170
|
-
**/
|
|
171
|
-
type OpenStrategyPrepare = WithError<OpenStrategyPlan, PrepareError>;
|
|
172
|
-
/**
|
|
173
|
-
* A ceiling one of the `max*` reads answers with, in the units that read names,
|
|
174
|
-
* or why the account it was asked about could not be weighed.
|
|
175
|
-
*
|
|
176
|
-
* The same envelope as a prepared operation, for the same reason: a form that
|
|
177
|
-
* cannot show a limit needs to say why as much as one that cannot prepare.
|
|
178
|
-
**/
|
|
179
|
-
type AmountPrepare = WithError<bigint, PrepareError>;
|
|
180
165
|
/**
|
|
181
166
|
* Shared knobs. Both default to the SDK's own defaults when omitted.
|
|
182
167
|
**/
|
|
@@ -365,14 +350,19 @@ interface FinalizeParams extends PrepareOptions {
|
|
|
365
350
|
* Not to be confused with `src/preview`, which goes the other way: it takes
|
|
366
351
|
* calldata that already exists and reports what it would do.
|
|
367
352
|
*
|
|
368
|
-
* Every method
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
353
|
+
* Every refusable method answers `SDKReturn` and names, in its own signature,
|
|
354
|
+
* exactly the errors its flow can refuse with — the union is the list of
|
|
355
|
+
* everything a caller has to handle, checked by the compiler. An async flow
|
|
356
|
+
* never throws: a chain that cannot be reached or a crash on the way arrives
|
|
357
|
+
* as `unexpectedFailure` with the cause attached. The synchronous LP flows
|
|
358
|
+
* only do arithmetic on loaded state, so their one refusal is the unroutable
|
|
359
|
+
* pair — anything else there is a bug or a lifecycle error, and it throws.
|
|
360
|
+
*
|
|
361
|
+
* The bare readers stay outside the envelope: the `max*` ceilings answer their
|
|
362
|
+
* number and throw on an account or chain the SDK does not hold, and the two
|
|
363
|
+
* synchronous readers ({@link leverageBand}, {@link withdrawableCollaterals})
|
|
364
|
+
* weigh state already loaded and say "nothing available" with `undefined` or
|
|
365
|
+
* an empty list.
|
|
376
366
|
**/
|
|
377
367
|
interface IOpportunitiesPrepare {
|
|
378
368
|
/**
|
|
@@ -381,7 +371,7 @@ interface IOpportunitiesPrepare {
|
|
|
381
371
|
* Synchronous, unlike every strategy method below: the answer is the pool's
|
|
382
372
|
* share rate applied to the amount, and that rate is already loaded.
|
|
383
373
|
**/
|
|
384
|
-
deposit(pool: PoolInput, params: LpParams):
|
|
374
|
+
deposit(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
385
375
|
/**
|
|
386
376
|
* Taking underlying out of a pool: `amount` is the `tokenOut` the wallet
|
|
387
377
|
* wants back, and the pool burns whatever shares that costs.
|
|
@@ -389,26 +379,26 @@ interface IOpportunitiesPrepare {
|
|
|
389
379
|
* The LP counterpart of {@link withdrawStrategy} / {@link withdrawCollateral},
|
|
390
380
|
* which act on credit accounts.
|
|
391
381
|
**/
|
|
392
|
-
withdraw(pool: PoolInput, params: LpParams):
|
|
382
|
+
withdraw(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
393
383
|
/**
|
|
394
384
|
* Redeeming pool shares: `amount` is the `tokenIn` the wallet parts with,
|
|
395
385
|
* and the reported state is the underlying it converts to.
|
|
396
386
|
**/
|
|
397
|
-
redeem(pool: PoolInput, params: LpRedeemParams):
|
|
387
|
+
redeem(pool: PoolInput, params: LpRedeemParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
398
388
|
/**
|
|
399
389
|
* Opening a leveraged position from wallet collateral.
|
|
400
390
|
*
|
|
401
391
|
* The one flow with no account yet, so the result carries no operation list —
|
|
402
392
|
* it feeds `sdk.accounts.openCA` instead.
|
|
403
393
|
**/
|
|
404
|
-
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<
|
|
394
|
+
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError>>;
|
|
405
395
|
/**
|
|
406
396
|
* Growing a position: collateral in, debt drawn on top, both converted into
|
|
407
397
|
* the position token.
|
|
408
398
|
*
|
|
409
399
|
* Leverage stays put unless `targetLeverage` asks for more.
|
|
410
400
|
**/
|
|
411
|
-
depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<
|
|
401
|
+
depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedCollateralTokenError | UnsupportedTokenPairError | InsufficientPoolLiquidityError>>;
|
|
412
402
|
/**
|
|
413
403
|
* Shrinking a position: part of its net value goes to the wallet and debt is
|
|
414
404
|
* repaid in the same proportion, so leverage is unchanged.
|
|
@@ -416,7 +406,7 @@ interface IOpportunitiesPrepare {
|
|
|
416
406
|
* Answers with both routes the withdrawal can take — sold through the router
|
|
417
407
|
* now, or redeemed through the source's issuer and finished days later — since
|
|
418
408
|
* the source token decides which of them exist, see
|
|
419
|
-
* {@link
|
|
409
|
+
* {@link StrategyRoutesResult}.
|
|
420
410
|
*
|
|
421
411
|
* `MAX_UINT256` — or any amount at or above the account's net value — is an
|
|
422
412
|
* exit instead: the quotas are dropped, the position is sold whole in one
|
|
@@ -434,7 +424,7 @@ interface IOpportunitiesPrepare {
|
|
|
434
424
|
* @see withdrawCollateral to move an asset out without touching debt, which
|
|
435
425
|
* raises leverage instead.
|
|
436
426
|
**/
|
|
437
|
-
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<
|
|
427
|
+
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError) & WithRouteRefusals>>;
|
|
438
428
|
/**
|
|
439
429
|
* Largest partial withdrawal {@link withdrawStrategy} accepts, in underlying
|
|
440
430
|
* units: the amount whose proportional repayment leaves the debt at the
|
|
@@ -444,8 +434,11 @@ interface IOpportunitiesPrepare {
|
|
|
444
434
|
*
|
|
445
435
|
* Taking everything out needs none of this arithmetic: send `MAX_UINT256` to
|
|
446
436
|
* {@link withdrawStrategy} and the exit is what runs.
|
|
437
|
+
*
|
|
438
|
+
* A bare read: it answers its number, and throws on an account or a chain
|
|
439
|
+
* the SDK does not hold.
|
|
447
440
|
**/
|
|
448
|
-
maxWithdraw(position: PositionInput): Promise<
|
|
441
|
+
maxWithdraw(position: PositionInput): Promise<bigint>;
|
|
449
442
|
/**
|
|
450
443
|
* Paying debt down with funds from the wallet: collateral stays where it is,
|
|
451
444
|
* so net value grows by what was repaid, leverage falls and the health factor
|
|
@@ -462,13 +455,16 @@ interface IOpportunitiesPrepare {
|
|
|
462
455
|
* 10bps margin for the interest still to come, and whatever the facade does
|
|
463
456
|
* not take stays on the account.
|
|
464
457
|
**/
|
|
465
|
-
repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<
|
|
458
|
+
repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | UnsupportedCollateralTokenError>>;
|
|
466
459
|
/**
|
|
467
460
|
* Debt {@link repayStrategy} would have to cover to clear the account, in
|
|
468
461
|
* underlying units: principal, interest and fees as of this read. Interest
|
|
469
462
|
* keeps accruing, so a wallet meaning to settle sends this with a buffer.
|
|
463
|
+
*
|
|
464
|
+
* A bare read: it answers its number, and throws on an account or a chain
|
|
465
|
+
* the SDK does not hold.
|
|
470
466
|
**/
|
|
471
|
-
maxRepay(position: PositionInput): Promise<
|
|
467
|
+
maxRepay(position: PositionInput): Promise<bigint>;
|
|
472
468
|
/**
|
|
473
469
|
* Retargeting leverage at fixed collateral: debt moves, own funds do not.
|
|
474
470
|
*
|
|
@@ -477,12 +473,12 @@ interface IOpportunitiesPrepare {
|
|
|
477
473
|
* buys instead, so there the delayed route is always absent with
|
|
478
474
|
* `refused.delayed: "noDelayedRoute"`.
|
|
479
475
|
**/
|
|
480
|
-
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<
|
|
476
|
+
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError | InsufficientPoolLiquidityError | LeverageOutOfRangeError) & WithRouteRefusals>>;
|
|
481
477
|
/**
|
|
482
478
|
* Putting the position token onto the account at fixed debt, which lowers
|
|
483
479
|
* leverage and raises the health factor.
|
|
484
480
|
**/
|
|
485
|
-
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<
|
|
481
|
+
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
|
|
486
482
|
/**
|
|
487
483
|
* Moving one asset that already sits on the account out to the wallet, at
|
|
488
484
|
* fixed debt — so TVL falls and leverage rises.
|
|
@@ -490,7 +486,7 @@ interface IOpportunitiesPrepare {
|
|
|
490
486
|
* @see withdrawStrategy for the deleveraging withdrawal, which repays debt in
|
|
491
487
|
* proportion and leaves leverage unchanged.
|
|
492
488
|
**/
|
|
493
|
-
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<
|
|
489
|
+
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
|
|
494
490
|
/**
|
|
495
491
|
* The leverages a deposit of a given size can reach in this market: the
|
|
496
492
|
* range a leverage slider should mark as available.
|
|
@@ -540,8 +536,11 @@ interface IOpportunitiesPrepare {
|
|
|
540
536
|
*
|
|
541
537
|
* `targetHF` names the health factor to leave the account at, in basis
|
|
542
538
|
* points; omitted, the SDK holds it to the bar a form would.
|
|
539
|
+
*
|
|
540
|
+
* A bare read: it answers its number, and throws on an account or a chain
|
|
541
|
+
* the SDK does not hold.
|
|
543
542
|
**/
|
|
544
|
-
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<
|
|
543
|
+
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<bigint>;
|
|
545
544
|
/**
|
|
546
545
|
* The tail of a delayed route: claim the matured withdrawal, then whatever the
|
|
547
546
|
* operation that requested it still owes — repaying debt and paying the wallet
|
|
@@ -559,7 +558,7 @@ interface IOpportunitiesPrepare {
|
|
|
559
558
|
* Answers like the instant flows, so both halves are consumed the same way.
|
|
560
559
|
* Reports `noRecordedIntent` when the claim names no operation to resume.
|
|
561
560
|
**/
|
|
562
|
-
finalize(position: PositionInput, params: FinalizeParams): Promise<
|
|
561
|
+
finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<StrategyResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
|
|
563
562
|
}
|
|
564
563
|
//#endregion
|
|
565
|
-
export { AddCollateralParams, AdjustLeverageParams,
|
|
564
|
+
export { AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, IntentPreviewError, type LeverageBand, LpParams, LpRedeemParams, LpResult, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, PositionInput, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithdrawCollateralParams, WithdrawStrategyParams, raise, refuse };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { OperationPreview, PreviewOperationInput, PreviewOperationOptions } from "../../model/previews.js";
|
|
2
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
3
|
import "../../model/index.js";
|
|
3
4
|
import { MultichainSDK } from "../../onchain/MultichainSDK.js";
|
|
4
5
|
import "../../onchain/index.js";
|
|
6
|
+
import { PreviewOperationError } from "../../preview/preview/previewOperation.js";
|
|
7
|
+
import "../../preview/index.js";
|
|
5
8
|
import { IPreview } from "./types.js";
|
|
6
9
|
import { NamespaceOptions } from "../types.js";
|
|
7
10
|
//#region src/sdk/preview/PreviewNamespace.d.ts
|
|
@@ -14,7 +17,7 @@ declare class PreviewNamespace implements IPreview {
|
|
|
14
17
|
/**
|
|
15
18
|
* {@inheritDoc IPreview.previewOperation}
|
|
16
19
|
**/
|
|
17
|
-
previewOperation(input: PreviewOperationInput, options?: PreviewOperationOptions): Promise<OperationPreview
|
|
20
|
+
previewOperation(input: PreviewOperationInput, options?: PreviewOperationOptions): Promise<SDKReturn<OperationPreview, PreviewOperationError>>;
|
|
18
21
|
}
|
|
19
22
|
//#endregion
|
|
20
23
|
export { PreviewNamespace };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { OperationPreview, PreviewOperationInput, PreviewOperationOptions } from "../../model/previews.js";
|
|
2
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
3
|
import "../../model/index.js";
|
|
4
|
+
import { PreviewOperationError } from "../../preview/preview/previewOperation.js";
|
|
5
|
+
import "../../preview/index.js";
|
|
3
6
|
//#region src/sdk/preview/types.d.ts
|
|
4
7
|
/**
|
|
5
8
|
* On-chain preview of a raw operation calldata.
|
|
@@ -7,10 +10,11 @@ import "../../model/index.js";
|
|
|
7
10
|
interface IPreview {
|
|
8
11
|
/**
|
|
9
12
|
* Decodes a raw operation and assembles an operation-specific,
|
|
10
|
-
* human-displayable preview.
|
|
11
|
-
*
|
|
13
|
+
* human-displayable preview. A refusal of the calldata — an unsupported
|
|
14
|
+
* target, function or operation, a foreign delayed intent, a failed
|
|
15
|
+
* simulation — is the `ok: false` half; genuine failures still throw.
|
|
12
16
|
**/
|
|
13
|
-
previewOperation(input: PreviewOperationInput, options?: PreviewOperationOptions): Promise<OperationPreview
|
|
17
|
+
previewOperation(input: PreviewOperationInput, options?: PreviewOperationOptions): Promise<SDKReturn<OperationPreview, PreviewOperationError>>;
|
|
14
18
|
}
|
|
15
19
|
/**
|
|
16
20
|
* `sdk.preview` per mode: an on-chain read, absent when the SDK reads no chain.
|
|
@@ -114,9 +114,7 @@ interface OnchainByMode {
|
|
|
114
114
|
* The banners the backend attaches to a pool opportunity or a strategy
|
|
115
115
|
* position, see {@link Notice}.
|
|
116
116
|
**/
|
|
117
|
-
|
|
118
|
-
(subject: NoticeSubject): Promise<DataResponse<Notice[]>>;
|
|
119
|
-
}
|
|
117
|
+
type INotices = (subject: NoticeSubject) => Promise<DataResponse<Notice[]>>;
|
|
120
118
|
/**
|
|
121
119
|
* `sdk.notices` per mode: a backend read, absent when the SDK reads no backend.
|
|
122
120
|
**/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "16.0.0-next.
|
|
3
|
+
"version": "16.0.0-next.44",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -90,7 +90,15 @@
|
|
|
90
90
|
"prepare": "husky",
|
|
91
91
|
"check": "biome check --write",
|
|
92
92
|
"check:ci": "biome check --diagnostic-level=error",
|
|
93
|
-
"typecheck:ci": "tsc --noEmit"
|
|
93
|
+
"typecheck:ci": "tsc --noEmit",
|
|
94
|
+
"agent:test:backend": "vitest run --project unit",
|
|
95
|
+
"agent:install": "pnpm install --frozen-lockfile",
|
|
96
|
+
"agent:test:frontend": "echo 'N/A: sdk is a library, no frontend lane'",
|
|
97
|
+
"agent:test:e2e": "vitest run --project e2e",
|
|
98
|
+
"agent:typecheck": "tsc --noEmit",
|
|
99
|
+
"agent:verify:commit": "pnpm check:ci",
|
|
100
|
+
"agent:verify:pr": "pnpm check:ci && pnpm typecheck:ci && pnpm test:unit && pnpm build",
|
|
101
|
+
"agent:verify:docs": "echo 'N/A: docs verified via planctl verify'"
|
|
94
102
|
},
|
|
95
103
|
"dependencies": {
|
|
96
104
|
"@redstone-finance/evm-connector": "^0.9.0",
|
|
@@ -115,6 +123,7 @@
|
|
|
115
123
|
"tsdown": "^0.22.14",
|
|
116
124
|
"tsx": "^4.23.2",
|
|
117
125
|
"typescript": "^7.0.2",
|
|
126
|
+
"unrun": "^0.3.1",
|
|
118
127
|
"viem-deal": "^2.0.4",
|
|
119
128
|
"vite": "^8.2.2",
|
|
120
129
|
"vitest": "^4.1.11",
|