@gearbox-protocol/sdk 16.0.0-next.41 → 16.0.0-next.42
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 +1 -0
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +1 -1
- package/dist/cjs/sdk/execute/ExecuteApi.js +4 -4
- package/dist/cjs/sdk/index.js +5 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +326 -93
- package/dist/cjs/sdk/prepare/errors.js +90 -0
- package/dist/cjs/sdk/prepare/index.js +5 -0
- package/dist/esm/model/errors.js +1 -0
- package/dist/esm/model/index.js +1 -0
- package/dist/esm/onchain/accounts/intents/open-strategy.js +1 -1
- package/dist/esm/sdk/execute/ExecuteApi.js +4 -4
- package/dist/esm/sdk/index.js +2 -1
- package/dist/esm/sdk/prepare/PrepareApi.js +327 -94
- package/dist/esm/sdk/prepare/errors.js +86 -0
- package/dist/esm/sdk/prepare/index.js +2 -1
- package/dist/types/model/errors.d.ts +74 -0
- package/dist/types/model/index.d.ts +2 -1
- 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/sdk/execute/types.d.ts +6 -6
- package/dist/types/sdk/index.d.ts +3 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +11 -6
- package/dist/types/sdk/prepare/errors.d.ts +280 -0
- package/dist/types/sdk/prepare/index.d.ts +3 -2
- package/dist/types/sdk/prepare/types.d.ts +73 -46
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Bps } from "../../model/primitives.js";
|
|
2
|
+
import { WithError } from "../../model/errors.js";
|
|
2
3
|
import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
|
|
3
4
|
import { PositionCollateral, StrategyPosition, StrategyPositionKey } from "../../model/positions.js";
|
|
4
5
|
import { DataResponse } from "../../model/response.js";
|
|
@@ -13,18 +14,18 @@ import { AccountCalculatorOperation } from "../../onchain/accounts/intents/opera
|
|
|
13
14
|
import { DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteRefusals } from "../../onchain/accounts/intents/types.js";
|
|
14
15
|
import { OpenStrategyState } from "../../onchain/accounts/intents/open-strategy.js";
|
|
15
16
|
import "../../onchain/index.js";
|
|
17
|
+
import { PrepareError, RoutesPrepareError } from "./errors.js";
|
|
16
18
|
import { Address } from "viem";
|
|
17
19
|
//#region src/sdk/prepare/types.d.ts
|
|
18
20
|
/**
|
|
19
|
-
* What a pool deposit or withdrawal
|
|
21
|
+
* What a pool deposit or withdrawal comes to.
|
|
20
22
|
*
|
|
21
|
-
* Shaped like {@link
|
|
23
|
+
* Shaped like {@link StrategyPlan} so both kinds of result are consumed the
|
|
22
24
|
* same way, with the pool's own numbers as the state: the ERC-4626
|
|
23
25
|
* conversion applied to the amount, at the rate of the block the market was
|
|
24
26
|
* loaded at.
|
|
25
27
|
**/
|
|
26
|
-
|
|
27
|
-
ok: true;
|
|
28
|
+
interface LpPlan {
|
|
28
29
|
/**
|
|
29
30
|
* Always empty: a pool operation is a single transaction, so there is no
|
|
30
31
|
* chain of steps to show. Present so callers can treat both kinds of
|
|
@@ -41,16 +42,15 @@ type LpPrepare = {
|
|
|
41
42
|
* operation is a single call on the pool or on its zapper.
|
|
42
43
|
**/
|
|
43
44
|
calls: MultiCall[];
|
|
44
|
-
}
|
|
45
|
+
}
|
|
45
46
|
/**
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*
|
|
47
|
+
* {@link LpPlan}, or why the pool cannot serve the request.
|
|
48
|
+
**/
|
|
49
|
+
type LpPrepare = WithError<LpPlan, PrepareError>;
|
|
50
|
+
/**
|
|
51
|
+
* What an operation on an existing credit account comes to.
|
|
51
52
|
**/
|
|
52
|
-
|
|
53
|
-
ok: true;
|
|
53
|
+
interface StrategyPlan {
|
|
54
54
|
/**
|
|
55
55
|
* The logical steps, each carrying the amounts it was computed from.
|
|
56
56
|
* Useful for showing the user what will happen, and for pinning behaviour
|
|
@@ -67,20 +67,29 @@ type StrategyPrepare = {
|
|
|
67
67
|
* through `sdk.accounts`.
|
|
68
68
|
**/
|
|
69
69
|
calls: MultiCall[];
|
|
70
|
-
}
|
|
70
|
+
}
|
|
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>;
|
|
71
81
|
/**
|
|
72
|
-
* What the leading half of a delayed operation
|
|
82
|
+
* What the leading half of a delayed operation comes to: the request
|
|
73
83
|
* transaction, plus what it recorded for the tail and where that tail leads.
|
|
74
84
|
*
|
|
75
|
-
* Shaped like {@link
|
|
85
|
+
* Shaped like {@link StrategyPlan} with one field more, so the instant and
|
|
76
86
|
* the delayed route of the same request are compared side by side — and they
|
|
77
87
|
* are meant to be compared on the same footing, so `state` is the end of the
|
|
78
88
|
* operation in both, not the end of the transaction.
|
|
79
89
|
**/
|
|
80
|
-
|
|
81
|
-
ok: true;
|
|
90
|
+
interface DelayedStrategyPlan {
|
|
82
91
|
/**
|
|
83
|
-
* {@inheritDoc
|
|
92
|
+
* {@inheritDoc StrategyPlan.operations}
|
|
84
93
|
**/
|
|
85
94
|
operations: AccountCalculatorOperation[];
|
|
86
95
|
/**
|
|
@@ -95,7 +104,7 @@ type DelayedStrategyPrepare = {
|
|
|
95
104
|
**/
|
|
96
105
|
state: OperationState;
|
|
97
106
|
/**
|
|
98
|
-
* {@inheritDoc
|
|
107
|
+
* {@inheritDoc StrategyPlan.calls}
|
|
99
108
|
**/
|
|
100
109
|
calls: MultiCall[];
|
|
101
110
|
/**
|
|
@@ -103,7 +112,11 @@ type DelayedStrategyPrepare = {
|
|
|
103
112
|
* {@link DelayedStart}.
|
|
104
113
|
**/
|
|
105
114
|
delayed: DelayedStart;
|
|
106
|
-
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* {@link DelayedStrategyPlan}, or why the redemption route cannot be taken.
|
|
118
|
+
**/
|
|
119
|
+
type DelayedStrategyPrepare = WithError<DelayedStrategyPlan, PrepareError>;
|
|
107
120
|
/**
|
|
108
121
|
* What one of the two flows that sell a position asset —
|
|
109
122
|
* {@link IOpportunitiesPrepare.withdrawStrategy} and
|
|
@@ -114,51 +127,56 @@ type DelayedStrategyPrepare = {
|
|
|
114
127
|
* issuer, or both, is not something the caller can know up front, so both routes
|
|
115
128
|
* are quoted from one request. A route the account cannot take is `undefined`
|
|
116
129
|
* with its refusal in `refused`, which is what lets a form offer exactly the
|
|
117
|
-
* routes that exist;
|
|
130
|
+
* routes that exist; a failure means neither does, and the error still carries
|
|
131
|
+
* `refused`, see {@link RoutesPrepareError}.
|
|
118
132
|
**/
|
|
119
|
-
|
|
120
|
-
ok: true;
|
|
133
|
+
interface StrategyRoutes {
|
|
121
134
|
/**
|
|
122
135
|
* The router route: one transaction, settled on the spot. `undefined`
|
|
123
136
|
* when the asset cannot be sold, see `refused.instant`.
|
|
124
137
|
**/
|
|
125
|
-
instant:
|
|
126
|
-
ok: true;
|
|
127
|
-
}> | undefined;
|
|
138
|
+
instant: StrategyPlan | undefined;
|
|
128
139
|
/**
|
|
129
140
|
* The request half of the redemption route, which
|
|
130
141
|
* {@link IOpportunitiesPrepare.finalize} completes once it matures.
|
|
131
142
|
* `undefined` when the route does not exist — no redemption venue for the
|
|
132
143
|
* asset, or a request that settles at once anyway — see `refused.delayed`.
|
|
133
144
|
**/
|
|
134
|
-
delayed:
|
|
135
|
-
ok: true;
|
|
136
|
-
}> | undefined;
|
|
145
|
+
delayed: DelayedStrategyPlan | undefined;
|
|
137
146
|
/**
|
|
138
147
|
* Why a missing route was refused, see {@link RouteRefusals}.
|
|
139
148
|
**/
|
|
140
149
|
refused: RouteRefusals;
|
|
141
|
-
}
|
|
150
|
+
}
|
|
142
151
|
/**
|
|
143
|
-
*
|
|
144
|
-
* the delayed route's when the instant one did not even get that far.
|
|
152
|
+
* {@link StrategyRoutes}, or the refusal of both routes at once.
|
|
145
153
|
**/
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* {@inheritDoc StrategyRoutesPrepare.refused}
|
|
149
|
-
**/
|
|
150
|
-
refused: RouteRefusals;
|
|
151
|
-
});
|
|
154
|
+
type StrategyRoutesPrepare = WithError<StrategyRoutes, RoutesPrepareError>;
|
|
152
155
|
/**
|
|
153
|
-
* What opening a new leveraged position
|
|
156
|
+
* What opening a new leveraged position comes to.
|
|
154
157
|
*
|
|
155
158
|
* The only result that reports both an expected and a floor branch: opening
|
|
156
159
|
* takes both from a single pathfinder call, and `openCA` consumes both.
|
|
157
160
|
**/
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
interface OpenStrategyPlan {
|
|
162
|
+
/**
|
|
163
|
+
* Everything the opening arrives at: the projection, both branches of the
|
|
164
|
+
* post-open balances and quotas, and the router path `openCA` is handed.
|
|
165
|
+
**/
|
|
160
166
|
state: OpenStrategyState;
|
|
161
|
-
}
|
|
167
|
+
}
|
|
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>;
|
|
162
180
|
/**
|
|
163
181
|
* Shared knobs. Both default to the SDK's own defaults when omitted.
|
|
164
182
|
**/
|
|
@@ -346,6 +364,15 @@ interface FinalizeParams extends PrepareOptions {
|
|
|
346
364
|
*
|
|
347
365
|
* Not to be confused with `src/preview`, which goes the other way: it takes
|
|
348
366
|
* calldata that already exists and reports what it would do.
|
|
367
|
+
*
|
|
368
|
+
* Every method that can fail answers in the error envelope and none of them
|
|
369
|
+
* throws: a market that refuses, an account that is not there, a chain that
|
|
370
|
+
* cannot be reached — all of it arrives as `{ success: false, error }` with a
|
|
371
|
+
* code, see {@link PrepareError}. The two synchronous readers
|
|
372
|
+
* ({@link leverageBand}, {@link withdrawableCollaterals}) stay outside the
|
|
373
|
+
* envelope: they weigh state already loaded and say "nothing available" with
|
|
374
|
+
* `undefined` or an empty list, so their only failure is being handed a chain
|
|
375
|
+
* this SDK was never connected to — an argument error, which throws.
|
|
349
376
|
**/
|
|
350
377
|
interface IOpportunitiesPrepare {
|
|
351
378
|
/**
|
|
@@ -418,7 +445,7 @@ interface IOpportunitiesPrepare {
|
|
|
418
445
|
* Taking everything out needs none of this arithmetic: send `MAX_UINT256` to
|
|
419
446
|
* {@link withdrawStrategy} and the exit is what runs.
|
|
420
447
|
**/
|
|
421
|
-
maxWithdraw(position: PositionInput): Promise<DataResponse<
|
|
448
|
+
maxWithdraw(position: PositionInput): Promise<DataResponse<AmountPrepare>>;
|
|
422
449
|
/**
|
|
423
450
|
* Paying debt down with funds from the wallet: collateral stays where it is,
|
|
424
451
|
* so net value grows by what was repaid, leverage falls and the health factor
|
|
@@ -441,7 +468,7 @@ interface IOpportunitiesPrepare {
|
|
|
441
468
|
* underlying units: principal, interest and fees as of this read. Interest
|
|
442
469
|
* keeps accruing, so a wallet meaning to settle sends this with a buffer.
|
|
443
470
|
**/
|
|
444
|
-
maxRepay(position: PositionInput): Promise<DataResponse<
|
|
471
|
+
maxRepay(position: PositionInput): Promise<DataResponse<AmountPrepare>>;
|
|
445
472
|
/**
|
|
446
473
|
* Retargeting leverage at fixed collateral: debt moves, own funds do not.
|
|
447
474
|
*
|
|
@@ -514,7 +541,7 @@ interface IOpportunitiesPrepare {
|
|
|
514
541
|
* `targetHF` names the health factor to leave the account at, in basis
|
|
515
542
|
* points; omitted, the SDK holds it to the bar a form would.
|
|
516
543
|
**/
|
|
517
|
-
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<DataResponse<
|
|
544
|
+
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<DataResponse<AmountPrepare>>;
|
|
518
545
|
/**
|
|
519
546
|
* The tail of a delayed route: claim the matured withdrawal, then whatever the
|
|
520
547
|
* operation that requested it still owes — repaying debt and paying the wallet
|
|
@@ -535,4 +562,4 @@ interface IOpportunitiesPrepare {
|
|
|
535
562
|
finalize(position: PositionInput, params: FinalizeParams): Promise<DataResponse<StrategyPrepare>>;
|
|
536
563
|
}
|
|
537
564
|
//#endregion
|
|
538
|
-
export { AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding, DelayedStrategyPrepare, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, IntentPreviewError, type LeverageBand, LpParams, LpPrepare, LpRedeemParams, OpenStrategyParams, OpenStrategyPrepare, type OperationState, type PathLossRate, PoolInput, PositionInput, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, RepayStrategyParams, StrategyInput, StrategyPrepare, StrategyRoutesPrepare, WithdrawCollateralParams, WithdrawStrategyParams, raise, refuse };
|
|
565
|
+
export { AddCollateralParams, AdjustLeverageParams, AmountPrepare, BorrowLimitBinding, DelayedStrategyPlan, DelayedStrategyPrepare, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, IntentPreviewError, type LeverageBand, LpParams, LpPlan, LpPrepare, LpRedeemParams, OpenStrategyParams, OpenStrategyPlan, OpenStrategyPrepare, type OperationState, type PathLossRate, PoolInput, PositionInput, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, RepayStrategyParams, StrategyInput, StrategyPlan, StrategyPrepare, StrategyRoutes, StrategyRoutesPrepare, WithdrawCollateralParams, WithdrawStrategyParams, raise, refuse };
|