@gearbox-protocol/sdk 16.0.0-next.45 → 16.0.0-next.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/cjs/model/index.js +1 -0
  2. package/dist/cjs/model/withdrawals.schema.js +7 -2
  3. package/dist/cjs/onchain/accounts/intents/index.js +38 -13
  4. package/dist/cjs/onchain/accounts/intents/tail.js +112 -5
  5. package/dist/cjs/onchain/index.js +0 -2
  6. package/dist/cjs/onchain/market/MarketSuite.js +9 -1
  7. package/dist/cjs/onchain/market/credit/CreditSuite.js +1 -2
  8. package/dist/cjs/onchain/market/pool/PoolV310Contract.js +25 -0
  9. package/dist/cjs/onchain/pools/PoolService.js +5 -40
  10. package/dist/cjs/onchain/pools/index.js +0 -2
  11. package/dist/cjs/onchain/positions/PositionsService.js +8 -2
  12. package/dist/cjs/preview/preview/previewPoolPositionOperation.js +31 -12
  13. package/dist/cjs/preview/simulate/index.js +1 -1
  14. package/dist/cjs/preview/simulate/simulateOperation.js +1 -1
  15. package/dist/cjs/preview/simulate/simulatePoolOperation.js +2 -0
  16. package/dist/cjs/sdk/prepare/PrepareApi.js +132 -82
  17. package/dist/esm/dev/AccountOpener.js +1 -1
  18. package/dist/esm/dev/withdrawalUtils.js +1 -1
  19. package/dist/esm/model/index.js +2 -2
  20. package/dist/esm/model/withdrawals.schema.js +7 -3
  21. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
  22. package/dist/esm/onchain/accounts/intents/index.js +38 -13
  23. package/dist/esm/onchain/accounts/intents/tail.js +112 -5
  24. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  25. package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  26. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  27. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  28. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  29. package/dist/esm/onchain/base/TokensMeta.js +3 -3
  30. package/dist/esm/onchain/core/createAddressProvider.js +1 -1
  31. package/dist/esm/onchain/index.js +2 -2
  32. package/dist/esm/onchain/market/MarketSuite.js +9 -1
  33. package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  34. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  35. package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
  36. package/dist/esm/onchain/market/credit/CreditSuite.js +1 -2
  37. package/dist/esm/onchain/market/pool/PoolV310Contract.js +26 -1
  38. package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
  39. package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
  40. package/dist/esm/onchain/pools/PoolService.js +7 -40
  41. package/dist/esm/onchain/pools/index.js +2 -2
  42. package/dist/esm/onchain/positions/PositionsService.js +8 -2
  43. package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
  44. package/dist/esm/preview/preview/previewPoolPositionOperation.js +33 -14
  45. package/dist/esm/preview/simulate/index.js +1 -1
  46. package/dist/esm/preview/simulate/simulateOperation.js +1 -1
  47. package/dist/esm/preview/simulate/simulatePoolOperation.js +2 -2
  48. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  49. package/dist/esm/sdk/prepare/PrepareApi.js +132 -82
  50. package/dist/types/model/index.d.ts +3 -3
  51. package/dist/types/model/positions.d.ts +4 -1
  52. package/dist/types/model/previews.d.ts +28 -12
  53. package/dist/types/model/withdrawals.d.ts +24 -5
  54. package/dist/types/model/withdrawals.schema.d.ts +21 -1
  55. package/dist/types/onchain/accounts/index.d.ts +2 -2
  56. package/dist/types/onchain/accounts/intents/index.d.ts +19 -11
  57. package/dist/types/onchain/accounts/intents/tail.d.ts +13 -3
  58. package/dist/types/onchain/accounts/intents/types.d.ts +74 -1
  59. package/dist/types/onchain/index.d.ts +3 -3
  60. package/dist/types/onchain/market/MarketSuite.d.ts +6 -0
  61. package/dist/types/onchain/market/pool/PoolV310Contract.d.ts +12 -0
  62. package/dist/types/onchain/market/pool/types.d.ts +18 -0
  63. package/dist/types/onchain/pools/PoolService.d.ts +1 -19
  64. package/dist/types/onchain/pools/index.d.ts +2 -2
  65. package/dist/types/preview/simulate/simulatePoolOperation.d.ts +18 -1
  66. package/dist/types/preview/simulate/types.d.ts +12 -4
  67. package/dist/types/sdk/index.d.ts +3 -3
  68. package/dist/types/sdk/prepare/PrepareApi.d.ts +8 -7
  69. package/dist/types/sdk/prepare/index.d.ts +3 -3
  70. package/dist/types/sdk/prepare/types.d.ts +87 -28
  71. 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,37 @@ 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.
35
+ *
36
+ * Denominated like {@link PoolPosition.netValue}, so a screen showing both
37
+ * reads one token: on an RWA market that is the unwrapped asset — USDC
38
+ * rather than the dcUSDC the pool actually holds.
39
+ *
40
+ * Does not account for withdrawal fee: this is what the remaining shares
41
+ * are worth, not what leaving with them would pay.
42
+ **/
43
+ netValue: TokenAmount;
44
+ }
19
45
  /**
20
46
  * What a pool deposit or withdrawal comes to.
21
47
  *
@@ -32,10 +58,11 @@ interface LpResult {
32
58
  **/
33
59
  operations: [];
34
60
  /**
35
- * What the wallet parts with and what it receives, plus the zapper the
36
- * transaction goes through when one is involved.
61
+ * What the wallet parts with and what it receives, the zapper the
62
+ * transaction goes through when one is involved, and where the position ends
63
+ * up, see {@link LpState}.
37
64
  **/
38
- state: PoolSimulation;
65
+ state: LpState;
39
66
  /**
40
67
  * The transaction implementing the operation: exactly one, since a pool
41
68
  * operation is a single call on the pool or on its zapper.
@@ -71,6 +98,24 @@ interface StrategyResult {
71
98
  /** Unix seconds of {@link blockNumber}. */
72
99
  timestamp: Timestamp;
73
100
  }
101
+ /**
102
+ * What the tail of a delayed operation comes to: {@link StrategyResult}, plus
103
+ * whether the claim it was built on settled the withdrawal whole.
104
+ **/
105
+ interface FinalizeResult extends StrategyResult {
106
+ /**
107
+ * What the claim did not bring, when the venue paid out part of the matured
108
+ * withdrawal and left the rest of it queued — only a legacy Mellow multivault
109
+ * does. `undefined` everywhere else, which is the normal case: one request,
110
+ * one claim, one tail.
111
+ *
112
+ * When it is set, the result beside it serves only the share that arrived,
113
+ * and the operation is not over: pass `remainder.intent` back to
114
+ * {@link IOpportunitiesPrepare.finalize} with the next claim, see
115
+ * {@link ClaimRemainder}.
116
+ **/
117
+ remainder: ClaimRemainder | undefined;
118
+ }
74
119
  /**
75
120
  * What the leading half of a delayed operation comes to: the request
76
121
  * transaction, plus what it recorded for the tail and where that tail leads.
@@ -336,7 +381,10 @@ interface FinalizeParams extends PrepareOptions {
336
381
  * The operation to resume. Defaults to the one the request recorded in the
337
382
  * withdrawal's `extraData`, which is what
338
383
  * {@link PositionClaimableWithdrawal.intent} decodes; pass it explicitly
339
- * when the compressor is too old to report it.
384
+ * when the compressor is too old to report it — as a Mellow one is, since a
385
+ * Mellow request cannot carry an intent at all — or when a previous claim
386
+ * served only part of the operation and left one in
387
+ * {@link FinalizeResult.remainder}.
340
388
  **/
341
389
  intent?: ResumableIntent;
342
390
  }
@@ -352,11 +400,9 @@ interface FinalizeParams extends PrepareOptions {
352
400
  *
353
401
  * Every refusable method answers `SDKReturn` and names, in its own signature,
354
402
  * 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.
403
+ * everything a caller has to handle, checked by the compiler. None of them
404
+ * throws: a chain that cannot be reached or a crash on the way arrives as
405
+ * `unexpectedFailure` with the cause attached.
360
406
  *
361
407
  * The bare readers stay outside the envelope: the `max*` ceilings answer their
362
408
  * number and throw on an account or chain the SDK does not hold, and the two
@@ -368,10 +414,11 @@ interface IOpportunitiesPrepare {
368
414
  /**
369
415
  * Depositing into a pool: underlying in, shares out.
370
416
  *
371
- * Synchronous, unlike every strategy method below: the answer is the pool's
372
- * share rate applied to the amount, and that rate is already loaded.
417
+ * The trade itself is the pool's share rate applied to the amount, which is
418
+ * loaded already; the wait is for the one thing that is not, the shares the
419
+ * wallet holds, without which {@link LpState.netValue} cannot be said.
373
420
  **/
374
- deposit(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
421
+ deposit(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
375
422
  /**
376
423
  * Taking underlying out of a pool: `amount` is the `tokenOut` the wallet
377
424
  * wants back, and the pool burns whatever shares that costs.
@@ -379,12 +426,12 @@ interface IOpportunitiesPrepare {
379
426
  * The LP counterpart of {@link withdrawStrategy} / {@link withdrawCollateral},
380
427
  * which act on credit accounts.
381
428
  **/
382
- withdraw(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
429
+ withdraw(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
383
430
  /**
384
431
  * Redeeming pool shares: `amount` is the `tokenIn` the wallet parts with,
385
432
  * and the reported state is the underlying it converts to.
386
433
  **/
387
- redeem(pool: PoolInput, params: LpRedeemParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
434
+ redeem(pool: PoolInput, params: LpRedeemParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
388
435
  /**
389
436
  * Opening a leveraged position from wallet collateral.
390
437
  *
@@ -426,19 +473,26 @@ interface IOpportunitiesPrepare {
426
473
  **/
427
474
  withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError) & WithRouteRefusals>>;
428
475
  /**
429
- * Largest partial withdrawal {@link withdrawStrategy} accepts, in underlying
430
- * units: the amount whose proportional repayment leaves the debt at the
431
- * credit manager's `minDebt`. Between this and the account's net value the
432
- * flow refuses the leftover loan would sit below `minDebt` — and at the net
433
- * value it turns into an exit.
476
+ * How much {@link withdrawStrategy} can take out, both ends of it, in
477
+ * underlying units: `partial` is the largest withdrawal that keeps leverage
478
+ * and leaves the debt at the credit manager's `minDebt`, `exit` is the net
479
+ * value leaving entirely hands over.
434
480
  *
435
- * Taking everything out needs none of this arithmetic: send `MAX_UINT256` to
436
- * {@link withdrawStrategy} and the exit is what runs.
481
+ * Two numbers rather than one because the range has a hole in it: between
482
+ * them the flow refuses with `debtOutOfRange`, since the leftover loan would
483
+ * sit below the floor. A form driving a slider off `partial` and a Max
484
+ * button off `exit` describes what the account can actually do; a form using
485
+ * either alone will misstate one of them — see {@link WithdrawCeilings},
486
+ * which spells out how far apart they can be.
437
487
  *
438
- * A bare read: it answers its number, and throws on an account or a chain
488
+ * Taking everything out needs neither figure: send `MAX_UINT256` to
489
+ * {@link withdrawStrategy} and the exit is what runs, named rather than
490
+ * priced.
491
+ *
492
+ * A bare read: it answers its numbers, and throws on an account or a chain
439
493
  * the SDK does not hold.
440
494
  **/
441
- maxWithdraw(position: PositionInput): Promise<bigint>;
495
+ maxWithdraw(position: PositionInput): Promise<WithdrawCeilings>;
442
496
  /**
443
497
  * Paying debt down with funds from the wallet: collateral stays where it is,
444
498
  * so net value grows by what was repaid, leverage falls and the health factor
@@ -557,8 +611,13 @@ interface IOpportunitiesPrepare {
557
611
  *
558
612
  * Answers like the instant flows, so both halves are consumed the same way.
559
613
  * Reports `noRecordedIntent` when the claim names no operation to resume.
614
+ *
615
+ * A claim can settle only part of what was queued — a legacy Mellow
616
+ * multivault pays out what it holds liquid and re-queues the rest — and then
617
+ * the result serves that share and `remainder` says what is left, see
618
+ * {@link FinalizeResult.remainder}.
560
619
  **/
561
- finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<StrategyResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
620
+ finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<FinalizeResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
562
621
  }
563
622
  //#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 };
623
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "16.0.0-next.45",
3
+ "version": "16.0.0-next.47",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {