@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.
- package/dist/cjs/model/errors.js +1 -0
- package/dist/cjs/model/index.js +5 -0
- package/dist/cjs/model/result.js +27 -0
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +1 -1
- 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 +3 -3
- package/dist/cjs/sdk/index.js +5 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +254 -101
- package/dist/cjs/sdk/prepare/errors.js +93 -0
- package/dist/cjs/sdk/prepare/index.js +5 -0
- package/dist/esm/model/errors.js +1 -0
- package/dist/esm/model/index.js +3 -1
- package/dist/esm/model/result.js +24 -0
- package/dist/esm/onchain/accounts/intents/open-strategy.js +1 -1
- 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 +3 -3
- package/dist/esm/sdk/index.js +2 -1
- package/dist/esm/sdk/prepare/PrepareApi.js +255 -102
- package/dist/esm/sdk/prepare/errors.js +89 -0
- package/dist/esm/sdk/prepare/index.js +2 -1
- package/dist/types/model/errors.d.ts +46 -0
- package/dist/types/model/index.d.ts +3 -1
- package/dist/types/model/result.d.ts +48 -0
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/types.d.ts +13 -14
- 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 +9 -14
- package/dist/types/sdk/index.d.ts +3 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +30 -22
- package/dist/types/sdk/prepare/errors.d.ts +317 -0
- package/dist/types/sdk/prepare/index.d.ts +3 -2
- package/dist/types/sdk/prepare/types.d.ts +88 -62
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Bps } from "../../model/primitives.js";
|
|
1
|
+
import { Bps, Timestamp } from "../../model/primitives.js";
|
|
2
2
|
import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
|
|
3
3
|
import { PositionCollateral, StrategyPosition, StrategyPositionKey } from "../../model/positions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { SDKReturn } from "../../model/result.js";
|
|
5
5
|
import { PositionClaimableWithdrawal } from "../../model/withdrawals.js";
|
|
6
6
|
import "../../model/index.js";
|
|
7
7
|
import { Asset } from "../../onchain/base/types.js";
|
|
@@ -13,18 +13,18 @@ import { AccountCalculatorOperation } from "../../onchain/accounts/intents/opera
|
|
|
13
13
|
import { DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteRefusals } from "../../onchain/accounts/intents/types.js";
|
|
14
14
|
import { OpenStrategyState } from "../../onchain/accounts/intents/open-strategy.js";
|
|
15
15
|
import "../../onchain/index.js";
|
|
16
|
+
import { AccountFlowError, DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
|
|
16
17
|
import { Address } from "viem";
|
|
17
18
|
//#region src/sdk/prepare/types.d.ts
|
|
18
19
|
/**
|
|
19
|
-
* What a pool deposit or withdrawal
|
|
20
|
+
* What a pool deposit or withdrawal comes to.
|
|
20
21
|
*
|
|
21
|
-
* Shaped like {@link
|
|
22
|
+
* Shaped like {@link StrategyResult} so both kinds of result are consumed the
|
|
22
23
|
* same way, with the pool's own numbers as the state: the ERC-4626
|
|
23
24
|
* conversion applied to the amount, at the rate of the block the market was
|
|
24
25
|
* loaded at.
|
|
25
26
|
**/
|
|
26
|
-
|
|
27
|
-
ok: true;
|
|
27
|
+
interface LpResult {
|
|
28
28
|
/**
|
|
29
29
|
* Always empty: a pool operation is a single transaction, so there is no
|
|
30
30
|
* chain of steps to show. Present so callers can treat both kinds of
|
|
@@ -41,16 +41,15 @@ type LpPrepare = {
|
|
|
41
41
|
* operation is a single call on the pool or on its zapper.
|
|
42
42
|
**/
|
|
43
43
|
calls: MultiCall[];
|
|
44
|
-
|
|
44
|
+
/** Block of the chain state this result was computed from. */
|
|
45
|
+
blockNumber: number;
|
|
46
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
47
|
+
timestamp: Timestamp;
|
|
48
|
+
}
|
|
45
49
|
/**
|
|
46
|
-
* What an operation on an existing credit account
|
|
47
|
-
*
|
|
48
|
-
* `ok: false` means the request itself is not viable — not that a call failed —
|
|
49
|
-
* so the reason is a value rather than an exception: too much leverage, too
|
|
50
|
-
* little of the source token, a token the flow does not accept.
|
|
50
|
+
* What an operation on an existing credit account comes to.
|
|
51
51
|
**/
|
|
52
|
-
|
|
53
|
-
ok: true;
|
|
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,20 +66,23 @@ type StrategyPrepare = {
|
|
|
67
66
|
* through `sdk.accounts`.
|
|
68
67
|
**/
|
|
69
68
|
calls: MultiCall[];
|
|
70
|
-
|
|
69
|
+
/** Block of the chain state this result was computed from. */
|
|
70
|
+
blockNumber: number;
|
|
71
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
72
|
+
timestamp: Timestamp;
|
|
73
|
+
}
|
|
71
74
|
/**
|
|
72
|
-
* What the leading half of a delayed operation
|
|
75
|
+
* What the leading half of a delayed operation comes to: the request
|
|
73
76
|
* transaction, plus what it recorded for the tail and where that tail leads.
|
|
74
77
|
*
|
|
75
|
-
* Shaped like {@link
|
|
78
|
+
* Shaped like {@link StrategyResult} with one field more, so the instant and
|
|
76
79
|
* the delayed route of the same request are compared side by side — and they
|
|
77
80
|
* are meant to be compared on the same footing, so `state` is the end of the
|
|
78
81
|
* operation in both, not the end of the transaction.
|
|
79
82
|
**/
|
|
80
|
-
|
|
81
|
-
ok: true;
|
|
83
|
+
interface DelayedStrategyResult {
|
|
82
84
|
/**
|
|
83
|
-
* {@inheritDoc
|
|
85
|
+
* {@inheritDoc StrategyResult.operations}
|
|
84
86
|
**/
|
|
85
87
|
operations: AccountCalculatorOperation[];
|
|
86
88
|
/**
|
|
@@ -95,7 +97,7 @@ type DelayedStrategyPrepare = {
|
|
|
95
97
|
**/
|
|
96
98
|
state: OperationState;
|
|
97
99
|
/**
|
|
98
|
-
* {@inheritDoc
|
|
100
|
+
* {@inheritDoc StrategyResult.calls}
|
|
99
101
|
**/
|
|
100
102
|
calls: MultiCall[];
|
|
101
103
|
/**
|
|
@@ -103,7 +105,11 @@ type DelayedStrategyPrepare = {
|
|
|
103
105
|
* {@link DelayedStart}.
|
|
104
106
|
**/
|
|
105
107
|
delayed: DelayedStart;
|
|
106
|
-
|
|
108
|
+
/** Block of the chain state this result was computed from. */
|
|
109
|
+
blockNumber: number;
|
|
110
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
111
|
+
timestamp: Timestamp;
|
|
112
|
+
}
|
|
107
113
|
/**
|
|
108
114
|
* What one of the two flows that sell a position asset —
|
|
109
115
|
* {@link IOpportunitiesPrepare.withdrawStrategy} and
|
|
@@ -114,51 +120,48 @@ type DelayedStrategyPrepare = {
|
|
|
114
120
|
* issuer, or both, is not something the caller can know up front, so both routes
|
|
115
121
|
* are quoted from one request. A route the account cannot take is `undefined`
|
|
116
122
|
* with its refusal in `refused`, which is what lets a form offer exactly the
|
|
117
|
-
* routes that exist;
|
|
123
|
+
* routes that exist; a failure means neither does, and the error still carries
|
|
124
|
+
* `refused`, see {@link WithRouteRefusals}.
|
|
118
125
|
**/
|
|
119
|
-
|
|
120
|
-
ok: true;
|
|
126
|
+
interface StrategyRoutesResult {
|
|
121
127
|
/**
|
|
122
128
|
* The router route: one transaction, settled on the spot. `undefined`
|
|
123
129
|
* when the asset cannot be sold, see `refused.instant`.
|
|
124
130
|
**/
|
|
125
|
-
instant:
|
|
126
|
-
ok: true;
|
|
127
|
-
}> | undefined;
|
|
131
|
+
instant: StrategyResult | undefined;
|
|
128
132
|
/**
|
|
129
133
|
* The request half of the redemption route, which
|
|
130
134
|
* {@link IOpportunitiesPrepare.finalize} completes once it matures.
|
|
131
135
|
* `undefined` when the route does not exist — no redemption venue for the
|
|
132
136
|
* asset, or a request that settles at once anyway — see `refused.delayed`.
|
|
133
137
|
**/
|
|
134
|
-
delayed:
|
|
135
|
-
ok: true;
|
|
136
|
-
}> | undefined;
|
|
138
|
+
delayed: DelayedStrategyResult | undefined;
|
|
137
139
|
/**
|
|
138
140
|
* Why a missing route was refused, see {@link RouteRefusals}.
|
|
139
141
|
**/
|
|
140
142
|
refused: RouteRefusals;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
(PreviewRefusal & {
|
|
147
|
-
/**
|
|
148
|
-
* {@inheritDoc StrategyRoutesPrepare.refused}
|
|
149
|
-
**/
|
|
150
|
-
refused: RouteRefusals;
|
|
151
|
-
});
|
|
143
|
+
/** Block of the chain state this result was computed from. */
|
|
144
|
+
blockNumber: number;
|
|
145
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
146
|
+
timestamp: Timestamp;
|
|
147
|
+
}
|
|
152
148
|
/**
|
|
153
|
-
* What opening a new leveraged position
|
|
149
|
+
* What opening a new leveraged position comes to.
|
|
154
150
|
*
|
|
155
151
|
* The only result that reports both an expected and a floor branch: opening
|
|
156
152
|
* takes both from a single pathfinder call, and `openCA` consumes both.
|
|
157
153
|
**/
|
|
158
|
-
|
|
159
|
-
|
|
154
|
+
interface OpenStrategyResult {
|
|
155
|
+
/**
|
|
156
|
+
* Everything the opening arrives at: the projection, both branches of the
|
|
157
|
+
* post-open balances and quotas, and the router path `openCA` is handed.
|
|
158
|
+
**/
|
|
160
159
|
state: OpenStrategyState;
|
|
161
|
-
|
|
160
|
+
/** Block of the chain state this result was computed from. */
|
|
161
|
+
blockNumber: number;
|
|
162
|
+
/** Unix seconds of {@link blockNumber}. */
|
|
163
|
+
timestamp: Timestamp;
|
|
164
|
+
}
|
|
162
165
|
/**
|
|
163
166
|
* Shared knobs. Both default to the SDK's own defaults when omitted.
|
|
164
167
|
**/
|
|
@@ -346,6 +349,20 @@ interface FinalizeParams extends PrepareOptions {
|
|
|
346
349
|
*
|
|
347
350
|
* Not to be confused with `src/preview`, which goes the other way: it takes
|
|
348
351
|
* calldata that already exists and reports what it would do.
|
|
352
|
+
*
|
|
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.
|
|
349
366
|
**/
|
|
350
367
|
interface IOpportunitiesPrepare {
|
|
351
368
|
/**
|
|
@@ -354,7 +371,7 @@ interface IOpportunitiesPrepare {
|
|
|
354
371
|
* Synchronous, unlike every strategy method below: the answer is the pool's
|
|
355
372
|
* share rate applied to the amount, and that rate is already loaded.
|
|
356
373
|
**/
|
|
357
|
-
deposit(pool: PoolInput, params: LpParams):
|
|
374
|
+
deposit(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
358
375
|
/**
|
|
359
376
|
* Taking underlying out of a pool: `amount` is the `tokenOut` the wallet
|
|
360
377
|
* wants back, and the pool burns whatever shares that costs.
|
|
@@ -362,26 +379,26 @@ interface IOpportunitiesPrepare {
|
|
|
362
379
|
* The LP counterpart of {@link withdrawStrategy} / {@link withdrawCollateral},
|
|
363
380
|
* which act on credit accounts.
|
|
364
381
|
**/
|
|
365
|
-
withdraw(pool: PoolInput, params: LpParams):
|
|
382
|
+
withdraw(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
366
383
|
/**
|
|
367
384
|
* Redeeming pool shares: `amount` is the `tokenIn` the wallet parts with,
|
|
368
385
|
* and the reported state is the underlying it converts to.
|
|
369
386
|
**/
|
|
370
|
-
redeem(pool: PoolInput, params: LpRedeemParams):
|
|
387
|
+
redeem(pool: PoolInput, params: LpRedeemParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
371
388
|
/**
|
|
372
389
|
* Opening a leveraged position from wallet collateral.
|
|
373
390
|
*
|
|
374
391
|
* The one flow with no account yet, so the result carries no operation list —
|
|
375
392
|
* it feeds `sdk.accounts.openCA` instead.
|
|
376
393
|
**/
|
|
377
|
-
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<
|
|
394
|
+
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError>>;
|
|
378
395
|
/**
|
|
379
396
|
* Growing a position: collateral in, debt drawn on top, both converted into
|
|
380
397
|
* the position token.
|
|
381
398
|
*
|
|
382
399
|
* Leverage stays put unless `targetLeverage` asks for more.
|
|
383
400
|
**/
|
|
384
|
-
depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<
|
|
401
|
+
depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedCollateralTokenError | UnsupportedTokenPairError | InsufficientPoolLiquidityError>>;
|
|
385
402
|
/**
|
|
386
403
|
* Shrinking a position: part of its net value goes to the wallet and debt is
|
|
387
404
|
* repaid in the same proportion, so leverage is unchanged.
|
|
@@ -389,7 +406,7 @@ interface IOpportunitiesPrepare {
|
|
|
389
406
|
* Answers with both routes the withdrawal can take — sold through the router
|
|
390
407
|
* now, or redeemed through the source's issuer and finished days later — since
|
|
391
408
|
* the source token decides which of them exist, see
|
|
392
|
-
* {@link
|
|
409
|
+
* {@link StrategyRoutesResult}.
|
|
393
410
|
*
|
|
394
411
|
* `MAX_UINT256` — or any amount at or above the account's net value — is an
|
|
395
412
|
* exit instead: the quotas are dropped, the position is sold whole in one
|
|
@@ -407,7 +424,7 @@ interface IOpportunitiesPrepare {
|
|
|
407
424
|
* @see withdrawCollateral to move an asset out without touching debt, which
|
|
408
425
|
* raises leverage instead.
|
|
409
426
|
**/
|
|
410
|
-
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<
|
|
427
|
+
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError) & WithRouteRefusals>>;
|
|
411
428
|
/**
|
|
412
429
|
* Largest partial withdrawal {@link withdrawStrategy} accepts, in underlying
|
|
413
430
|
* units: the amount whose proportional repayment leaves the debt at the
|
|
@@ -417,8 +434,11 @@ interface IOpportunitiesPrepare {
|
|
|
417
434
|
*
|
|
418
435
|
* Taking everything out needs none of this arithmetic: send `MAX_UINT256` to
|
|
419
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.
|
|
420
440
|
**/
|
|
421
|
-
maxWithdraw(position: PositionInput): Promise<
|
|
441
|
+
maxWithdraw(position: PositionInput): Promise<bigint>;
|
|
422
442
|
/**
|
|
423
443
|
* Paying debt down with funds from the wallet: collateral stays where it is,
|
|
424
444
|
* so net value grows by what was repaid, leverage falls and the health factor
|
|
@@ -435,13 +455,16 @@ interface IOpportunitiesPrepare {
|
|
|
435
455
|
* 10bps margin for the interest still to come, and whatever the facade does
|
|
436
456
|
* not take stays on the account.
|
|
437
457
|
**/
|
|
438
|
-
repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<
|
|
458
|
+
repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | UnsupportedCollateralTokenError>>;
|
|
439
459
|
/**
|
|
440
460
|
* Debt {@link repayStrategy} would have to cover to clear the account, in
|
|
441
461
|
* underlying units: principal, interest and fees as of this read. Interest
|
|
442
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.
|
|
443
466
|
**/
|
|
444
|
-
maxRepay(position: PositionInput): Promise<
|
|
467
|
+
maxRepay(position: PositionInput): Promise<bigint>;
|
|
445
468
|
/**
|
|
446
469
|
* Retargeting leverage at fixed collateral: debt moves, own funds do not.
|
|
447
470
|
*
|
|
@@ -450,12 +473,12 @@ interface IOpportunitiesPrepare {
|
|
|
450
473
|
* buys instead, so there the delayed route is always absent with
|
|
451
474
|
* `refused.delayed: "noDelayedRoute"`.
|
|
452
475
|
**/
|
|
453
|
-
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<
|
|
476
|
+
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError | InsufficientPoolLiquidityError | LeverageOutOfRangeError) & WithRouteRefusals>>;
|
|
454
477
|
/**
|
|
455
478
|
* Putting the position token onto the account at fixed debt, which lowers
|
|
456
479
|
* leverage and raises the health factor.
|
|
457
480
|
**/
|
|
458
|
-
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<
|
|
481
|
+
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
|
|
459
482
|
/**
|
|
460
483
|
* Moving one asset that already sits on the account out to the wallet, at
|
|
461
484
|
* fixed debt — so TVL falls and leverage rises.
|
|
@@ -463,7 +486,7 @@ interface IOpportunitiesPrepare {
|
|
|
463
486
|
* @see withdrawStrategy for the deleveraging withdrawal, which repays debt in
|
|
464
487
|
* proportion and leaves leverage unchanged.
|
|
465
488
|
**/
|
|
466
|
-
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<
|
|
489
|
+
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
|
|
467
490
|
/**
|
|
468
491
|
* The leverages a deposit of a given size can reach in this market: the
|
|
469
492
|
* range a leverage slider should mark as available.
|
|
@@ -513,8 +536,11 @@ interface IOpportunitiesPrepare {
|
|
|
513
536
|
*
|
|
514
537
|
* `targetHF` names the health factor to leave the account at, in basis
|
|
515
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.
|
|
516
542
|
**/
|
|
517
|
-
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<
|
|
543
|
+
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<bigint>;
|
|
518
544
|
/**
|
|
519
545
|
* The tail of a delayed route: claim the matured withdrawal, then whatever the
|
|
520
546
|
* operation that requested it still owes — repaying debt and paying the wallet
|
|
@@ -532,7 +558,7 @@ interface IOpportunitiesPrepare {
|
|
|
532
558
|
* Answers like the instant flows, so both halves are consumed the same way.
|
|
533
559
|
* Reports `noRecordedIntent` when the claim names no operation to resume.
|
|
534
560
|
**/
|
|
535
|
-
finalize(position: PositionInput, params: FinalizeParams): Promise<
|
|
561
|
+
finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<StrategyResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
|
|
536
562
|
}
|
|
537
563
|
//#endregion
|
|
538
|
-
export { AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding,
|
|
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 { PreviewVerdictError } 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, PreviewVerdictError>>;
|
|
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 { PreviewVerdictError } 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 verdict on 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, PreviewVerdictError>>;
|
|
14
18
|
}
|
|
15
19
|
/**
|
|
16
20
|
* `sdk.preview` per mode: an on-chain read, absent when the SDK reads no chain.
|
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.43",
|
|
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",
|