@gearbox-protocol/sdk 16.0.0-next.45 → 16.0.0-next.46
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 +1 -0
- package/dist/cjs/model/withdrawals.schema.js +7 -2
- package/dist/cjs/onchain/accounts/intents/index.js +38 -13
- package/dist/cjs/onchain/accounts/intents/tail.js +112 -5
- package/dist/cjs/onchain/pools/PoolService.js +20 -4
- package/dist/cjs/onchain/positions/PositionsService.js +8 -2
- package/dist/cjs/sdk/prepare/PrepareApi.js +133 -82
- package/dist/esm/model/index.js +2 -2
- package/dist/esm/model/withdrawals.schema.js +7 -3
- package/dist/esm/onchain/accounts/intents/index.js +38 -13
- package/dist/esm/onchain/accounts/intents/tail.js +112 -5
- package/dist/esm/onchain/pools/PoolService.js +20 -4
- package/dist/esm/onchain/positions/PositionsService.js +8 -2
- package/dist/esm/sdk/prepare/PrepareApi.js +133 -82
- package/dist/types/model/index.d.ts +3 -3
- package/dist/types/model/withdrawals.d.ts +24 -5
- package/dist/types/model/withdrawals.schema.d.ts +21 -1
- package/dist/types/onchain/accounts/index.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/index.d.ts +19 -11
- package/dist/types/onchain/accounts/intents/tail.d.ts +13 -3
- package/dist/types/onchain/accounts/intents/types.d.ts +74 -1
- package/dist/types/onchain/index.d.ts +3 -3
- package/dist/types/onchain/pools/PoolService.d.ts +10 -1
- package/dist/types/onchain/pools/index.d.ts +2 -2
- package/dist/types/onchain/pools/types.d.ts +40 -1
- package/dist/types/sdk/index.d.ts +3 -3
- package/dist/types/sdk/prepare/PrepareApi.d.ts +8 -7
- package/dist/types/sdk/prepare/index.d.ts +3 -3
- package/dist/types/sdk/prepare/types.d.ts +85 -28
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Bps, Timestamp } from "../../model/primitives.js";
|
|
1
|
+
import { Bps, Timestamp, TokenAmount } from "../../model/primitives.js";
|
|
2
|
+
import { Curator } from "../../model/curators.js";
|
|
2
3
|
import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
|
|
3
4
|
import { PositionCollateral, StrategyPosition, StrategyPositionKey } from "../../model/positions.js";
|
|
4
5
|
import { SDKReturn } from "../../model/result.js";
|
|
@@ -10,12 +11,35 @@ import { PoolSimulation } from "../../onchain/pools/types.js";
|
|
|
10
11
|
import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, raise, refuse } from "../../onchain/validation/refusal.js";
|
|
11
12
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
12
13
|
import { AccountCalculatorOperation } from "../../onchain/accounts/intents/operations.js";
|
|
13
|
-
import { DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteRefusals } from "../../onchain/accounts/intents/types.js";
|
|
14
|
+
import { ClaimRemainder, DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteRefusals, WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
|
|
14
15
|
import { OpenStrategyState } from "../../onchain/accounts/intents/open-strategy.js";
|
|
15
16
|
import "../../onchain/index.js";
|
|
16
|
-
import { AccountFlowError, DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
|
|
17
|
+
import { AccountFlowError, DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
|
|
17
18
|
import { Address } from "viem";
|
|
18
19
|
//#region src/sdk/prepare/types.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* Where a pool operation leaves the wallet: the two sides of the trade as
|
|
22
|
+
* `sdk.pools` prices them, plus what a screen needs beside them and the raw
|
|
23
|
+
* simulation cannot know — whose market this is, and how large the position
|
|
24
|
+
* ends up.
|
|
25
|
+
**/
|
|
26
|
+
interface LpState extends PoolSimulation {
|
|
27
|
+
/**
|
|
28
|
+
* Curator of the market the pool belongs to, in the same shape
|
|
29
|
+
* {@link PoolOpportunity} and {@link CreditOperationMarket} report it.
|
|
30
|
+
**/
|
|
31
|
+
curator: Curator;
|
|
32
|
+
/**
|
|
33
|
+
* The wallet's position in this pool once the operation has run, in the
|
|
34
|
+
* market's underlying: what it holds now, moved by what this operation mints
|
|
35
|
+
* or burns. A first deposit lands at the size of the deposit itself.
|
|
36
|
+
*
|
|
37
|
+
* Denominated like {@link PoolPosition.netValue}, so a screen showing both
|
|
38
|
+
* reads one token: on an RWA market that is the unwrapped asset — USDC
|
|
39
|
+
* rather than the dcUSDC the pool actually holds.
|
|
40
|
+
**/
|
|
41
|
+
positionAfter: TokenAmount;
|
|
42
|
+
}
|
|
19
43
|
/**
|
|
20
44
|
* What a pool deposit or withdrawal comes to.
|
|
21
45
|
*
|
|
@@ -32,10 +56,11 @@ interface LpResult {
|
|
|
32
56
|
**/
|
|
33
57
|
operations: [];
|
|
34
58
|
/**
|
|
35
|
-
* What the wallet parts with and what it receives,
|
|
36
|
-
* transaction goes through when one is involved
|
|
59
|
+
* What the wallet parts with and what it receives, the zapper the
|
|
60
|
+
* transaction goes through when one is involved, and where the position ends
|
|
61
|
+
* up, see {@link LpState}.
|
|
37
62
|
**/
|
|
38
|
-
state:
|
|
63
|
+
state: LpState;
|
|
39
64
|
/**
|
|
40
65
|
* The transaction implementing the operation: exactly one, since a pool
|
|
41
66
|
* operation is a single call on the pool or on its zapper.
|
|
@@ -71,6 +96,24 @@ interface StrategyResult {
|
|
|
71
96
|
/** Unix seconds of {@link blockNumber}. */
|
|
72
97
|
timestamp: Timestamp;
|
|
73
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* What the tail of a delayed operation comes to: {@link StrategyResult}, plus
|
|
101
|
+
* whether the claim it was built on settled the withdrawal whole.
|
|
102
|
+
**/
|
|
103
|
+
interface FinalizeResult extends StrategyResult {
|
|
104
|
+
/**
|
|
105
|
+
* What the claim did not bring, when the venue paid out part of the matured
|
|
106
|
+
* withdrawal and left the rest of it queued — only a legacy Mellow multivault
|
|
107
|
+
* does. `undefined` everywhere else, which is the normal case: one request,
|
|
108
|
+
* one claim, one tail.
|
|
109
|
+
*
|
|
110
|
+
* When it is set, the result beside it serves only the share that arrived,
|
|
111
|
+
* and the operation is not over: pass `remainder.intent` back to
|
|
112
|
+
* {@link IOpportunitiesPrepare.finalize} with the next claim, see
|
|
113
|
+
* {@link ClaimRemainder}.
|
|
114
|
+
**/
|
|
115
|
+
remainder: ClaimRemainder | undefined;
|
|
116
|
+
}
|
|
74
117
|
/**
|
|
75
118
|
* What the leading half of a delayed operation comes to: the request
|
|
76
119
|
* transaction, plus what it recorded for the tail and where that tail leads.
|
|
@@ -336,7 +379,10 @@ interface FinalizeParams extends PrepareOptions {
|
|
|
336
379
|
* The operation to resume. Defaults to the one the request recorded in the
|
|
337
380
|
* withdrawal's `extraData`, which is what
|
|
338
381
|
* {@link PositionClaimableWithdrawal.intent} decodes; pass it explicitly
|
|
339
|
-
* when the compressor is too old to report it
|
|
382
|
+
* when the compressor is too old to report it — as a Mellow one is, since a
|
|
383
|
+
* Mellow request cannot carry an intent at all — or when a previous claim
|
|
384
|
+
* served only part of the operation and left one in
|
|
385
|
+
* {@link FinalizeResult.remainder}.
|
|
340
386
|
**/
|
|
341
387
|
intent?: ResumableIntent;
|
|
342
388
|
}
|
|
@@ -352,11 +398,9 @@ interface FinalizeParams extends PrepareOptions {
|
|
|
352
398
|
*
|
|
353
399
|
* Every refusable method answers `SDKReturn` and names, in its own signature,
|
|
354
400
|
* 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.
|
|
356
|
-
*
|
|
357
|
-
*
|
|
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.
|
|
401
|
+
* everything a caller has to handle, checked by the compiler. None of them
|
|
402
|
+
* throws: a chain that cannot be reached or a crash on the way arrives as
|
|
403
|
+
* `unexpectedFailure` with the cause attached.
|
|
360
404
|
*
|
|
361
405
|
* The bare readers stay outside the envelope: the `max*` ceilings answer their
|
|
362
406
|
* number and throw on an account or chain the SDK does not hold, and the two
|
|
@@ -368,10 +412,11 @@ interface IOpportunitiesPrepare {
|
|
|
368
412
|
/**
|
|
369
413
|
* Depositing into a pool: underlying in, shares out.
|
|
370
414
|
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
415
|
+
* The trade itself is the pool's share rate applied to the amount, which is
|
|
416
|
+
* loaded already; the wait is for the one thing that is not, the shares the
|
|
417
|
+
* wallet holds, without which {@link LpState.positionAfter} cannot be said.
|
|
373
418
|
**/
|
|
374
|
-
deposit(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError
|
|
419
|
+
deposit(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
|
|
375
420
|
/**
|
|
376
421
|
* Taking underlying out of a pool: `amount` is the `tokenOut` the wallet
|
|
377
422
|
* wants back, and the pool burns whatever shares that costs.
|
|
@@ -379,12 +424,12 @@ interface IOpportunitiesPrepare {
|
|
|
379
424
|
* The LP counterpart of {@link withdrawStrategy} / {@link withdrawCollateral},
|
|
380
425
|
* which act on credit accounts.
|
|
381
426
|
**/
|
|
382
|
-
withdraw(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError
|
|
427
|
+
withdraw(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
|
|
383
428
|
/**
|
|
384
429
|
* Redeeming pool shares: `amount` is the `tokenIn` the wallet parts with,
|
|
385
430
|
* and the reported state is the underlying it converts to.
|
|
386
431
|
**/
|
|
387
|
-
redeem(pool: PoolInput, params: LpRedeemParams): SDKReturn<LpResult, UnsupportedTokenPairError
|
|
432
|
+
redeem(pool: PoolInput, params: LpRedeemParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
|
|
388
433
|
/**
|
|
389
434
|
* Opening a leveraged position from wallet collateral.
|
|
390
435
|
*
|
|
@@ -426,19 +471,26 @@ interface IOpportunitiesPrepare {
|
|
|
426
471
|
**/
|
|
427
472
|
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError) & WithRouteRefusals>>;
|
|
428
473
|
/**
|
|
429
|
-
*
|
|
430
|
-
* units:
|
|
431
|
-
* credit manager's `minDebt
|
|
432
|
-
*
|
|
433
|
-
* value it turns into an exit.
|
|
474
|
+
* How much {@link withdrawStrategy} can take out, both ends of it, in
|
|
475
|
+
* underlying units: `partial` is the largest withdrawal that keeps leverage
|
|
476
|
+
* and leaves the debt at the credit manager's `minDebt`, `exit` is the net
|
|
477
|
+
* value leaving entirely hands over.
|
|
434
478
|
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
479
|
+
* Two numbers rather than one because the range has a hole in it: between
|
|
480
|
+
* them the flow refuses with `debtOutOfRange`, since the leftover loan would
|
|
481
|
+
* sit below the floor. A form driving a slider off `partial` and a Max
|
|
482
|
+
* button off `exit` describes what the account can actually do; a form using
|
|
483
|
+
* either alone will misstate one of them — see {@link WithdrawCeilings},
|
|
484
|
+
* which spells out how far apart they can be.
|
|
437
485
|
*
|
|
438
|
-
*
|
|
486
|
+
* Taking everything out needs neither figure: send `MAX_UINT256` to
|
|
487
|
+
* {@link withdrawStrategy} and the exit is what runs, named rather than
|
|
488
|
+
* priced.
|
|
489
|
+
*
|
|
490
|
+
* A bare read: it answers its numbers, and throws on an account or a chain
|
|
439
491
|
* the SDK does not hold.
|
|
440
492
|
**/
|
|
441
|
-
maxWithdraw(position: PositionInput): Promise<
|
|
493
|
+
maxWithdraw(position: PositionInput): Promise<WithdrawCeilings>;
|
|
442
494
|
/**
|
|
443
495
|
* Paying debt down with funds from the wallet: collateral stays where it is,
|
|
444
496
|
* so net value grows by what was repaid, leverage falls and the health factor
|
|
@@ -557,8 +609,13 @@ interface IOpportunitiesPrepare {
|
|
|
557
609
|
*
|
|
558
610
|
* Answers like the instant flows, so both halves are consumed the same way.
|
|
559
611
|
* Reports `noRecordedIntent` when the claim names no operation to resume.
|
|
612
|
+
*
|
|
613
|
+
* A claim can settle only part of what was queued — a legacy Mellow
|
|
614
|
+
* multivault pays out what it holds liquid and re-queues the rest — and then
|
|
615
|
+
* the result serves that share and `remainder` says what is left, see
|
|
616
|
+
* {@link FinalizeResult.remainder}.
|
|
560
617
|
**/
|
|
561
|
-
finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<
|
|
618
|
+
finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<FinalizeResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
|
|
562
619
|
}
|
|
563
620
|
//#endregion
|
|
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 };
|
|
621
|
+
export { AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, IntentPreviewError, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, PositionInput, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, raise, refuse };
|