@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
@@ -58,7 +58,7 @@ var PrepareApi = class extends MultichainConstruct {
58
58
  }));
59
59
  const creditAccount = await slice(sdk, position.creditAccount);
60
60
  if (!creditAccount) return sdkErr(creditAccountNotFound(position.creditAccount));
61
- return planned(await service(sdk).finishIntent({
61
+ return finalized(await service(sdk).finishIntent({
62
62
  intent,
63
63
  claimable: toClaimableWithdrawal(params.claimable),
64
64
  creditAccount,
@@ -73,94 +73,106 @@ var PrepareApi = class extends MultichainConstruct {
73
73
  /**
74
74
  * {@inheritDoc IOpportunitiesPrepare.deposit}
75
75
  **/
76
- deposit(pool, params) {
77
- const chain = this.sdk.chain(pool.chainId);
78
- const { marketRegister, pools } = chain;
79
- const tokenIn = params.tokenIn ?? marketRegister.findByPool(pool.pool).pool.underlying;
80
- const tokenOut = lpRoute(params.tokenOut, () => pools.getDepositTokensOut(pool.pool, tokenIn));
81
- if (!tokenOut) return unroutable(chain, tokenIn, void 0);
82
- const state = pools.simulateDeposit({
83
- pool: pool.pool,
84
- amount: params.amount,
85
- tokenIn,
86
- tokenOut
87
- });
88
- const call = pools.addLiquidity({
89
- collateral: {
90
- token: state.tokenIn.token.address,
91
- balance: state.tokenIn.value
92
- },
93
- pool: pool.pool,
94
- wallet: params.wallet,
95
- meta: pools.getDepositMetadata(pool.pool, tokenIn, tokenOut)
96
- });
97
- if (!call) return unroutable(chain, tokenIn, tokenOut);
98
- return sdkOk({
99
- operations: [],
100
- state,
101
- calls: call.calls,
102
- ...stateBlock(chain)
103
- });
76
+ async deposit(pool, params) {
77
+ try {
78
+ const chain = await this.#chain(pool.chainId);
79
+ const { marketRegister, pools } = chain;
80
+ const tokenIn = params.tokenIn ?? marketRegister.findByPool(pool.pool).pool.underlying;
81
+ const tokenOut = lpRoute(params.tokenOut, () => pools.getDepositTokensOut(pool.pool, tokenIn));
82
+ if (!tokenOut) return unroutable(chain, tokenIn, void 0);
83
+ const state = pools.simulateDeposit({
84
+ pool: pool.pool,
85
+ amount: params.amount,
86
+ tokenIn,
87
+ tokenOut
88
+ });
89
+ const call = pools.addLiquidity({
90
+ collateral: {
91
+ token: state.tokenIn.token.address,
92
+ balance: state.tokenIn.value
93
+ },
94
+ pool: pool.pool,
95
+ wallet: params.wallet,
96
+ meta: pools.getDepositMetadata(pool.pool, tokenIn, tokenOut)
97
+ });
98
+ if (!call) return unroutable(chain, tokenIn, tokenOut);
99
+ return sdkOk({
100
+ operations: [],
101
+ state: await lpState(chain, pool.pool, params.wallet, state, { mints: state.tokenOut.value }),
102
+ calls: call.calls,
103
+ ...stateBlock(chain)
104
+ });
105
+ } catch (e) {
106
+ return sdkErr(unexpectedFailure(e));
107
+ }
104
108
  }
105
109
  /**
106
110
  * {@inheritDoc IOpportunitiesPrepare.withdraw}
107
111
  **/
108
- withdraw(pool, params) {
109
- const chain = this.sdk.chain(pool.chainId);
110
- const { pools } = chain;
111
- const tokenIn = params.tokenIn ?? pool.pool;
112
- const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
113
- if (!tokenOut) return unroutable(chain, tokenIn, void 0);
114
- const state = pools.simulateWithdraw({
115
- pool: pool.pool,
116
- amount: params.amount,
117
- tokenIn,
118
- tokenOut
119
- });
120
- const { calls } = pools.removeLiquidity({
121
- pool: pool.pool,
122
- amount: params.amount,
123
- wallet: params.wallet,
124
- permit: void 0,
125
- meta: pools.getWithdrawalMetadata(pool.pool, tokenIn, tokenOut),
126
- mode: "withdraw"
127
- });
128
- return sdkOk({
129
- operations: [],
130
- state,
131
- calls,
132
- ...stateBlock(chain)
133
- });
112
+ async withdraw(pool, params) {
113
+ try {
114
+ const chain = await this.#chain(pool.chainId);
115
+ const { pools } = chain;
116
+ const tokenIn = params.tokenIn ?? pool.pool;
117
+ const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
118
+ if (!tokenOut) return unroutable(chain, tokenIn, void 0);
119
+ const state = pools.simulateWithdraw({
120
+ pool: pool.pool,
121
+ amount: params.amount,
122
+ tokenIn,
123
+ tokenOut
124
+ });
125
+ const { calls } = pools.removeLiquidity({
126
+ pool: pool.pool,
127
+ amount: params.amount,
128
+ wallet: params.wallet,
129
+ permit: void 0,
130
+ meta: pools.getWithdrawalMetadata(pool.pool, tokenIn, tokenOut),
131
+ mode: "withdraw"
132
+ });
133
+ return sdkOk({
134
+ operations: [],
135
+ state: await lpState(chain, pool.pool, params.wallet, state, { burns: state.tokenIn.value }),
136
+ calls,
137
+ ...stateBlock(chain)
138
+ });
139
+ } catch (e) {
140
+ return sdkErr(unexpectedFailure(e));
141
+ }
134
142
  }
135
143
  /**
136
144
  * {@inheritDoc IOpportunitiesPrepare.redeem}
137
145
  **/
138
- redeem(pool, params) {
139
- const chain = this.sdk.chain(pool.chainId);
140
- const { pools } = chain;
141
- const tokenIn = params.tokenIn ?? pool.pool;
142
- const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
143
- if (!tokenOut) return unroutable(chain, tokenIn, void 0);
144
- const state = pools.simulateRedeem({
145
- pool: pool.pool,
146
- amount: params.amount,
147
- tokenIn,
148
- tokenOut
149
- });
150
- const { calls } = pools.removeLiquidity({
151
- pool: pool.pool,
152
- amount: params.amount,
153
- wallet: params.wallet,
154
- permit: void 0,
155
- meta: pools.getWithdrawalMetadata(pool.pool, tokenIn, tokenOut),
156
- mode: "redeem"
157
- });
158
- return sdkOk({
159
- operations: [],
160
- state,
161
- calls,
162
- ...stateBlock(chain)
163
- });
146
+ async redeem(pool, params) {
147
+ try {
148
+ const chain = await this.#chain(pool.chainId);
149
+ const { pools } = chain;
150
+ const tokenIn = params.tokenIn ?? pool.pool;
151
+ const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
152
+ if (!tokenOut) return unroutable(chain, tokenIn, void 0);
153
+ const state = pools.simulateRedeem({
154
+ pool: pool.pool,
155
+ amount: params.amount,
156
+ tokenIn,
157
+ tokenOut
158
+ });
159
+ const { calls } = pools.removeLiquidity({
160
+ pool: pool.pool,
161
+ amount: params.amount,
162
+ wallet: params.wallet,
163
+ permit: void 0,
164
+ meta: pools.getWithdrawalMetadata(pool.pool, tokenIn, tokenOut),
165
+ mode: "redeem"
166
+ });
167
+ return sdkOk({
168
+ operations: [],
169
+ state: await lpState(chain, pool.pool, params.wallet, state, { burns: state.tokenIn.value }),
170
+ calls,
171
+ ...stateBlock(chain)
172
+ });
173
+ } catch (e) {
174
+ return sdkErr(unexpectedFailure(e));
175
+ }
164
176
  }
165
177
  /**
166
178
  * {@inheritDoc IOpportunitiesPrepare.openNewStrategy}
@@ -412,7 +424,7 @@ function toClaimableWithdrawal(claimable) {
412
424
  outputs: claimable.outputs.map((o) => ({
413
425
  token: o.token.address,
414
426
  amount: o.value,
415
- isDelayed: false
427
+ isDelayed: o.isDelayed
416
428
  })),
417
429
  claimCalls: [{
418
430
  target: claimable.claimCall.to,
@@ -469,6 +481,23 @@ function planned(result, at) {
469
481
  }
470
482
  /**
471
483
  * {@inheritDoc planned}
484
+ *
485
+ * A tail carries one thing the other results do not: whether the claim it was
486
+ * built on finished the withdrawal, or left part of it queued for another one.
487
+ **/
488
+ function finalized(result, at) {
489
+ if (!result.ok) return refusal(result);
490
+ const { operations, state, calls, remainder } = result;
491
+ return sdkOk({
492
+ operations,
493
+ state,
494
+ calls,
495
+ remainder,
496
+ ...at
497
+ });
498
+ }
499
+ /**
500
+ * {@inheritDoc planned}
472
501
  **/
473
502
  function opened(result, at) {
474
503
  return result.ok ? sdkOk({
@@ -511,6 +540,27 @@ function routed(result, at) {
511
540
  });
512
541
  }
513
542
  /**
543
+ * The pool's own numbers as the namespace reports them: the trade the service
544
+ * priced, the market it belongs to, and where the wallet's position lands.
545
+ *
546
+ * The position is measured in shares and converted once, rather than added up
547
+ * in underlying, so the figure is exactly what a later
548
+ * `sdk.positions.list()` will report — the same balance through the same rate.
549
+ * A withdrawal larger than the position floors at nothing: the transaction
550
+ * would revert long before it got there, and a negative holding is not a thing
551
+ * a screen can show.
552
+ **/
553
+ async function lpState(sdk, pool, wallet, simulation, moved) {
554
+ const market = sdk.marketRegister.findByPool(pool);
555
+ const poolContract = market.pool.pool;
556
+ const after = await poolContract.getShareBalance(wallet) + (moved.mints ?? -moved.burns);
557
+ return {
558
+ ...simulation,
559
+ curator: market.curator,
560
+ netValue: market.toUnderlyingAmount(poolContract.sharesToUnderlying(after > 0n ? after : 0n))
561
+ };
562
+ }
563
+ /**
514
564
  * A pool route the market does not offer, as the refusal a caller reads.
515
565
  *
516
566
  * `to` is absent where {@link lpRoute} found no output to name at all, which
@@ -21,6 +21,6 @@ import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema
21
21
  import { ChainFailed, ChainMetadata, ChainScoped, ChainSucceeded, DataResponse, DataSource, ResponseMetadata } from "./response.js";
22
22
  import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
23
23
  import { SDKError, SDKResult, SDKReturn, isSDKError, sdkErr, sdkOk } from "./result.js";
24
- import { PositionClaimableWithdrawal, PositionPendingWithdrawal, PositionWithdrawals } from "./withdrawals.js";
25
- import { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema } from "./withdrawals.schema.js";
26
- export { AccountHoldings, AccountMetrics, AccountProjection, AccountStateChange, AdjustStrategyPositionPreview, Amount, ApyBreakdown, Asset, AssetType, BorrowRateBreakdown, Bps, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ChainFailed, ChainId, ChainMetadata, ChainScoped, ChainScopedFilter, ChainSucceeded, ChartBundle, ChartDenomination, ChartMetric, ChartQuery, ChartRange, ChartSeries, ChartSeriesOk, ChartSeriesUnavailable, ChartUnavailableCode, ChartUnit, ChartValue, ChartWindow, CompareTag, CompareTolerance, CreditOperationMarket, Curator, CuratorName, DataResponse, DataSource, DelayedAddCollateralIntent, DelayedCloseAccountIntent, DelayedDecreaseLeverageIntent, DelayedDepositAndIncreaseLeverageIntent, DelayedDepositIntent, DelayedIncreaseLeverageIntent, DelayedIntent, DelayedReceivedAsset, DelayedStrategyPositionOperationPreview, DelayedWithdrawCollateralIntent, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL, Estimated, EstimatedProjection, ExitStrategyPositionPreview, FILTER_ALL, FilterAll, Filterable, GridSampling, IGearboxError, InstantReceivedAsset, InstantStrategyPositionOperationPreview, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Notice, NoticeKind, NoticeSubject, OpenStrategyPositionPreview, OperationPreview, OperationPreviewError, Opportunity, OpportunityBase, OpportunityChartMetric, OpportunityDetail, OpportunityFilter, OpportunityId, OpportunityKey, OpportunityKind, OpportunityTotals, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolOperationType, PoolOpportunity, PoolOpportunityChartMetric, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, PoolPositionChartMetric, PoolPositionKey, PoolPositionOperationPreview, PoolPositionRef, Position, PositionChartMetric, PositionClaimableWithdrawal, PositionCollateral, PositionFilter, PositionId, PositionKey, PositionKind, PositionPendingWithdrawal, PositionTransaction, PositionTransactionKind, PositionWithdrawals, PositionsTotals, PreviewOperationInput, PreviewOperationOptions, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, RepayStrategyPositionPreview, ResponseMetadata, Rewards, RewardsPnL, RoutedField, SDKError, SDKResult, SDKReturn, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, StrategyOpportunity, StrategyOpportunityChartMetric, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, StrategyPositionChartMetric, StrategyPositionKey, StrategyPositionRef, Timestamp, Token, TokenAmount, TokenQuotaRate, TokenRewards, TokenRewardsPnL, ToleranceCompareTag, TxCall, UnderlyingToken, amountSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, isSDKError, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema };
24
+ import { PositionClaimableWithdrawal, PositionPendingWithdrawal, PositionWithdrawals, WithdrawalOutputAmount } from "./withdrawals.js";
25
+ import { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema, withdrawalOutputAmountSchema } from "./withdrawals.schema.js";
26
+ export { AccountHoldings, AccountMetrics, AccountProjection, AccountStateChange, AdjustStrategyPositionPreview, Amount, ApyBreakdown, Asset, AssetType, BorrowRateBreakdown, Bps, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ChainFailed, ChainId, ChainMetadata, ChainScoped, ChainScopedFilter, ChainSucceeded, ChartBundle, ChartDenomination, ChartMetric, ChartQuery, ChartRange, ChartSeries, ChartSeriesOk, ChartSeriesUnavailable, ChartUnavailableCode, ChartUnit, ChartValue, ChartWindow, CompareTag, CompareTolerance, CreditOperationMarket, Curator, CuratorName, DataResponse, DataSource, DelayedAddCollateralIntent, DelayedCloseAccountIntent, DelayedDecreaseLeverageIntent, DelayedDepositAndIncreaseLeverageIntent, DelayedDepositIntent, DelayedIncreaseLeverageIntent, DelayedIntent, DelayedReceivedAsset, DelayedStrategyPositionOperationPreview, DelayedWithdrawCollateralIntent, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPRICEABLE_TOKEN, ERROR_UNSUPPORTED_OUT_OF_BRACKET_CALL, Estimated, EstimatedProjection, ExitStrategyPositionPreview, FILTER_ALL, FilterAll, Filterable, GridSampling, IGearboxError, InstantReceivedAsset, InstantStrategyPositionOperationPreview, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Notice, NoticeKind, NoticeSubject, OpenStrategyPositionPreview, OperationPreview, OperationPreviewError, Opportunity, OpportunityBase, OpportunityChartMetric, OpportunityDetail, OpportunityFilter, OpportunityId, OpportunityKey, OpportunityKind, OpportunityTotals, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolOperationType, PoolOpportunity, PoolOpportunityChartMetric, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, PoolPositionChartMetric, PoolPositionKey, PoolPositionOperationPreview, PoolPositionRef, Position, PositionChartMetric, PositionClaimableWithdrawal, PositionCollateral, PositionFilter, PositionId, PositionKey, PositionKind, PositionPendingWithdrawal, PositionTransaction, PositionTransactionKind, PositionWithdrawals, PositionsTotals, PreviewOperationInput, PreviewOperationOptions, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, RepayStrategyPositionPreview, ResponseMetadata, Rewards, RewardsPnL, RoutedField, SDKError, SDKResult, SDKReturn, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, StrategyOpportunity, StrategyOpportunityChartMetric, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, StrategyPositionChartMetric, StrategyPositionKey, StrategyPositionRef, Timestamp, Token, TokenAmount, TokenQuotaRate, TokenRewards, TokenRewardsPnL, ToleranceCompareTag, TxCall, UnderlyingToken, WithdrawalOutputAmount, amountSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, isSDKError, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, withdrawalOutputAmountSchema };
@@ -122,7 +122,10 @@ interface PoolPosition {
122
122
  underlyingToken: UnderlyingToken;
123
123
  /**
124
124
  * Underlying the held shares are worth at the current share rate, i.e.
125
- * `pool.convertToAssets(pool.balanceOf(wallet))`.
125
+ * `pool.sharesToUnderlying(pool.getShareBalance(wallet))`.
126
+ *
127
+ * Does not account for withdraw fee: this is what the shares are worth,
128
+ * not what leaving with them would pay.
126
129
  **/
127
130
  netValue: TokenAmount;
128
131
  /**
@@ -120,23 +120,24 @@ interface PoolPositionOperationPreview {
120
120
  */
121
121
  underlyingToken: UnderlyingToken;
122
122
  /**
123
- * Token that goes from user to pool
124
- * In case of deposit, underlying for direct deposit, zapper input for zapper-routed deposit
125
- * In case of withdraw, pool shares (diesel token) for direct withdraw or zapper token out
123
+ * Token that goes from user to pool.
124
+ * In case of deposit, underlying for direct deposit, zapper input for zapper-routed deposit.
125
+ * In case of withdraw, pool shares (diesel token) for direct withdraw or zapper token out.
126
126
  *
127
- * For mint/withdraw the amount of tokenIn cannot be determined from
128
- * transaction calldata alone and requires an additional async call
129
- * (previewMint/previewWithdraw).
127
+ * On withdraw, this is the amount of shares burend that covers both the requested payout
128
+ * and the fee.
129
+ *
130
+ * On redeem this is the shares from calldata, fee-free.
130
131
  */
131
132
  tokenIn: TokenAmount;
132
133
  /**
133
- * Token that goes from pool to user
134
- * In case of deposit, pool shares (diesel token) for direct deposit or zapper token out
135
- * In case of withdraw, underlying for direct withdraw or zapper token in
134
+ * Token that goes from pool to user.
135
+ * In case of deposit, pool shares (diesel token) for direct deposit or zapper token out.
136
+ * In case of withdraw, underlying for direct withdraw or zapper token in.
136
137
  *
137
- * For deposit/redeem the amount of tokenOut cannot be determined from
138
- * transaction calldata alone and requires an additional async call
139
- * (previewDeposit/previewRedeem).
138
+ * On withdraw this is the requested underlying.
139
+ * On redeem this is the underlying after `withdrawFee`, so less than
140
+ * the burned shares are worth.
140
141
  */
141
142
  tokenOut: TokenAmount;
142
143
  /**
@@ -144,6 +145,21 @@ interface PoolPositionOperationPreview {
144
145
  * (`1e27`).
145
146
  */
146
147
  shareRate: bigint;
148
+ /**
149
+ * Curator of the market this pool belongs to
150
+ */
151
+ curator: Curator;
152
+ /**
153
+ * Remaining LP after this transaction: the same quantity
154
+ * {@link PoolPosition.netValue} reports for a live position, denominated in
155
+ * the market's unwrapped underlying. For RWA markets this is USDC rather than
156
+ * dcUSDC (the pool's on-chain underlying) or diesel shares.
157
+ *
158
+ * Does not account for withdraw fee: this is what the remaining shares are worth, not
159
+ * what leaving with them would pay. The fee shows up on {@link tokenIn} /
160
+ * {@link tokenOut} instead.
161
+ */
162
+ netValue: TokenAmount;
147
163
  /**
148
164
  * Set when preview encountered non-fatal errors, all fields are
149
165
  * still computed best-effort
@@ -2,6 +2,21 @@ import { Timestamp, Token, TokenAmount, TxCall } from "./primitives.js";
2
2
  import { DelayedIntent } from "./delayed-intents.js";
3
3
  import { Address } from "viem";
4
4
  //#region src/model/withdrawals.d.ts
5
+ /**
6
+ * One token amount a delayed withdrawal produces, and when.
7
+ **/
8
+ interface WithdrawalOutputAmount extends TokenAmount {
9
+ /**
10
+ * `false` when the amount lands on the credit account as the withdrawal is
11
+ * requested or claimed. `true` when it does not: the token is then the
12
+ * withdrawal phantom standing for a part that has not matured, and another
13
+ * claim is needed for it.
14
+ *
15
+ * A withdrawal that produces both at once is a legacy Mellow multivault: it
16
+ * serves whatever its subvaults hold liquid and queues the remainder.
17
+ **/
18
+ isDelayed: boolean;
19
+ }
5
20
  /**
6
21
  * A delayed withdrawal of a strategy position that has matured and can be claimed.
7
22
  **/
@@ -16,9 +31,12 @@ interface PositionClaimableWithdrawal {
16
31
  **/
17
32
  withdrawalPhantomToken: TokenAmount;
18
33
  /**
19
- * Tokens received by the credit account upon claiming.
34
+ * What the claim credits the account with. Everything a venue that answers
35
+ * whole produces lands at once; one that pays in instalments credits part of
36
+ * it as a fresh withdrawal position, see
37
+ * {@link WithdrawalOutputAmount.isDelayed}.
20
38
  **/
21
- outputs: TokenAmount[];
39
+ outputs: WithdrawalOutputAmount[];
22
40
  /**
23
41
  * Adapter call that executes the claim. Subcompressors always report exactly
24
42
  * one call; it is wrapped into a facade multicall by `assembleClaimDelayedCalls`.
@@ -50,9 +68,10 @@ interface PositionPendingWithdrawal {
50
68
  withdrawalPhantomToken: Token;
51
69
  /**
52
70
  * Estimated tokens the position will receive once the withdrawal
53
- * matures and is claimed.
71
+ * matures and is claimed, see {@link WithdrawalOutputAmount.isDelayed} for
72
+ * the ones a single claim will not bring.
54
73
  **/
55
- expectedOutputs: TokenAmount[];
74
+ expectedOutputs: WithdrawalOutputAmount[];
56
75
  /**
57
76
  * Unix timestamp (in seconds) when the withdrawal becomes claimable.
58
77
  **/
@@ -84,4 +103,4 @@ interface PositionWithdrawals {
84
103
  pending: PositionPendingWithdrawal[];
85
104
  }
86
105
  //#endregion
87
- export { PositionClaimableWithdrawal, PositionPendingWithdrawal, PositionWithdrawals };
106
+ export { PositionClaimableWithdrawal, PositionPendingWithdrawal, PositionWithdrawals, WithdrawalOutputAmount };
@@ -1,5 +1,21 @@
1
1
  import { z } from "zod/v4";
2
2
  //#region src/model/withdrawals.schema.d.ts
3
+ /**
4
+ * {@link WithdrawalOutputAmount}
5
+ **/
6
+ declare const withdrawalOutputAmountSchema: z.ZodObject<{
7
+ value: z.ZodCodec<z.ZodUnion<[z.ZodString, z.ZodBigInt]>, z.ZodBigInt>;
8
+ valueUsd: z.ZodNullable<z.ZodNumber>;
9
+ token: z.ZodObject<{
10
+ chainId: z.ZodNumber;
11
+ address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
12
+ symbol: z.ZodString;
13
+ name: z.ZodString;
14
+ decimals: z.ZodNumber;
15
+ assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
16
+ }, z.core.$strip>;
17
+ isDelayed: z.ZodBoolean;
18
+ }, z.core.$strip>;
3
19
  /**
4
20
  * {@link PositionClaimableWithdrawal}
5
21
  **/
@@ -35,6 +51,7 @@ declare const positionClaimableWithdrawalSchema: z.ZodObject<{
35
51
  decimals: z.ZodNumber;
36
52
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
37
53
  }, z.core.$strip>;
54
+ isDelayed: z.ZodBoolean;
38
55
  }, z.core.$strip>>;
39
56
  claimCall: z.ZodObject<{
40
57
  to: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
@@ -95,6 +112,7 @@ declare const positionPendingWithdrawalSchema: z.ZodObject<{
95
112
  decimals: z.ZodNumber;
96
113
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
97
114
  }, z.core.$strip>;
115
+ isDelayed: z.ZodBoolean;
98
116
  }, z.core.$strip>>;
99
117
  claimableAt: z.ZodNumber;
100
118
  redeemer: z.ZodOptional<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
@@ -156,6 +174,7 @@ declare const positionWithdrawalsSchema: z.ZodObject<{
156
174
  decimals: z.ZodNumber;
157
175
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
158
176
  }, z.core.$strip>;
177
+ isDelayed: z.ZodBoolean;
159
178
  }, z.core.$strip>>;
160
179
  claimCall: z.ZodObject<{
161
180
  to: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
@@ -213,6 +232,7 @@ declare const positionWithdrawalsSchema: z.ZodObject<{
213
232
  decimals: z.ZodNumber;
214
233
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
215
234
  }, z.core.$strip>;
235
+ isDelayed: z.ZodBoolean;
216
236
  }, z.core.$strip>>;
217
237
  claimableAt: z.ZodNumber;
218
238
  redeemer: z.ZodOptional<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
@@ -240,4 +260,4 @@ declare const positionWithdrawalsSchema: z.ZodObject<{
240
260
  }, z.core.$strip>>;
241
261
  }, z.core.$strip>;
242
262
  //#endregion
243
- export { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema };
263
+ export { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema, withdrawalOutputAmountSchema };
@@ -24,7 +24,7 @@ import { borrowable } from "./intents/guards.js";
24
24
  import { LeverageBand } from "./intents/leverage-band.js";
25
25
  import { CalcDefaultQuotaProps, CalcQuotaUpdateProps, CalcRecommendedQuotaProps, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./quota-utils.js";
26
26
  import { AccountCalculatorOperation } from "./intents/operations.js";
27
- import { AddCollateralIntent, AdjustLeverageIntent, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, WithdrawAssetIntent, WithdrawStrategyIntent } from "./intents/types.js";
27
+ import { AddCollateralIntent, AdjustLeverageIntent, ClaimRemainder, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, FinishIntentResult, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, WithdrawAssetIntent, WithdrawCeilings, WithdrawStrategyIntent } from "./intents/types.js";
28
28
  import { OpenStrategyProps, OpenStrategyState } from "./intents/open-strategy.js";
29
29
  import { fetchCreditAccountSlice, toCreditAccountSlice } from "./intents/utils/credit-account-slice.js";
30
30
  import { isPhantomToken } from "./intents/utils/pick-token.js";
@@ -34,4 +34,4 @@ import { BuildLiquidationTxProps, BuildLiquidationTxPropsBase, GetLiquidatableAc
34
34
  import { LiquidationsService } from "./liquidations/LiquidationsService.js";
35
35
  import { MultichainLiquidationsService } from "./liquidations/MultichainLiquidationsService.js";
36
36
  import "./liquidations/index.js";
37
- export { AbstractWithdrawalCompressorContract, AccountBotsService, type AccountCalculatorOperation, AccountToCheck, type AddCollateralIntent, type AdjustLeverageIntent, AssembleCaOperationsProps, AssembleClaimDelayedCallsProps, AssembleCloseCreditAccountCallsProps, AssembleRepayCreditAccountCallsProps, AssembleStartDelayedWithdrawalCallsProps, BotStatusCall, BotsDirectResponse, BuildLiquidationTxProps, BuildLiquidationTxPropsBase, CMSlice, CalcDefaultQuotaProps, CalcQuotaUpdateProps, CalcRecommendedQuotaProps, ClaimFarmRewardsProps, ClaimableWithdrawal, CloseCreditAccountResult, ConnectedBotsCall, ConnectedBotsPerAccount, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountDataCall, CreditAccountFilter, CreditAccountOperationResult, CreditAccountOperationsService, CreditAccountReadOptions, type CreditAccountSlice, CreditAccountsCall, CreditAccountsQuery, CreditAccountsReadOptions, CreditAccountsServiceV310, CreditAccountsTarget, CreditManagerFilter, CreditManagerOperationResult, CurrentWithdrawals, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, type DelayableIntent, DelayedIntentExtended, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, EncodableCreditAccountOperation, type FinishIntentProps, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResponse, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsArgs, GetCreditAccountsOptions, GetExternalAccountCurrentWithdrawalsProps, GetLiquidatableAccountsProps, GetLiquidationDetailsProps, GetLiquidationDetailsPropsBase, GetLiquidationPositionsProps, GetLiquidationPositionsPropsBase, GetWithdrawalRequestResultProps, ICreditAccountsService, IRedemptionLoggerContract, IWithdrawalCompressorContract, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, type LeverageBand, LiquidationsService, LoadRWALiquidatorsProps, MulticallWithFailure, MultichainLiquidationsService, OnchainLiquidationCall, OnchainLiquidationData, OnchainLiquidationOutput, OnchainRequestableWithdrawal, OpenCAProps, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, PartiallyLiquidateProps, type PathLossRate, PendingWithdrawal, PeripheryCompressorV310Contract, PreviewDelayedWithdrawalProps, RWALiquidatorInfo, RedemptionLog, RedemptionLoggerV310Contract, type RepayStrategyIntent, RequestableWithdrawal, type ResumableIntent, Rewards, type RouteRefusals, SetBotProps, SetBotResult, type StartIntent, type WithdrawAssetIntent, type WithdrawStrategyIntent, WithdrawableAsset, WithdrawalCompressorLocation, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WithdrawalCompressorVersion, WithdrawalOutput, WithdrawalStatus, WithdrawalsState, borrowable, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, isPhantomToken, roundUpQuota, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
37
+ export { AbstractWithdrawalCompressorContract, AccountBotsService, type AccountCalculatorOperation, AccountToCheck, type AddCollateralIntent, type AdjustLeverageIntent, AssembleCaOperationsProps, AssembleClaimDelayedCallsProps, AssembleCloseCreditAccountCallsProps, AssembleRepayCreditAccountCallsProps, AssembleStartDelayedWithdrawalCallsProps, BotStatusCall, BotsDirectResponse, BuildLiquidationTxProps, BuildLiquidationTxPropsBase, CMSlice, CalcDefaultQuotaProps, CalcQuotaUpdateProps, CalcRecommendedQuotaProps, ClaimFarmRewardsProps, type ClaimRemainder, ClaimableWithdrawal, CloseCreditAccountResult, ConnectedBotsCall, ConnectedBotsPerAccount, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountDataCall, CreditAccountFilter, CreditAccountOperationResult, CreditAccountOperationsService, CreditAccountReadOptions, type CreditAccountSlice, CreditAccountsCall, CreditAccountsQuery, CreditAccountsReadOptions, CreditAccountsServiceV310, CreditAccountsTarget, CreditManagerFilter, CreditManagerOperationResult, CurrentWithdrawals, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, type DelayableIntent, DelayedIntentExtended, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, EncodableCreditAccountOperation, type FinishIntentProps, type FinishIntentResult, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResponse, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsArgs, GetCreditAccountsOptions, GetExternalAccountCurrentWithdrawalsProps, GetLiquidatableAccountsProps, GetLiquidationDetailsProps, GetLiquidationDetailsPropsBase, GetLiquidationPositionsProps, GetLiquidationPositionsPropsBase, GetWithdrawalRequestResultProps, ICreditAccountsService, IRedemptionLoggerContract, IWithdrawalCompressorContract, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, type LeverageBand, LiquidationsService, LoadRWALiquidatorsProps, MulticallWithFailure, MultichainLiquidationsService, OnchainLiquidationCall, OnchainLiquidationData, OnchainLiquidationOutput, OnchainRequestableWithdrawal, OpenCAProps, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, PartiallyLiquidateProps, type PathLossRate, PendingWithdrawal, PeripheryCompressorV310Contract, PreviewDelayedWithdrawalProps, RWALiquidatorInfo, RedemptionLog, RedemptionLoggerV310Contract, type RepayStrategyIntent, RequestableWithdrawal, type ResumableIntent, Rewards, type RouteRefusals, SetBotProps, SetBotResult, type StartIntent, type WithdrawAssetIntent, type WithdrawCeilings, type WithdrawStrategyIntent, WithdrawableAsset, WithdrawalCompressorLocation, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WithdrawalCompressorVersion, WithdrawalOutput, WithdrawalStatus, WithdrawalsState, borrowable, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, isPhantomToken, roundUpQuota, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
@@ -3,7 +3,7 @@ import { PreviewRefusal } from "../../validation/refusal.js";
3
3
  import { borrowable } from "./guards.js";
4
4
  import { LeverageBand, LeverageBandProps } from "./leverage-band.js";
5
5
  import { AccountCalculatorOperation } from "./operations.js";
6
- import { AddCollateralIntent, AdjustLeverageIntent, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawStrategyIntent } from "./types.js";
6
+ import { AddCollateralIntent, AdjustLeverageIntent, ClaimRemainder, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, FinishIntentResult, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawCeilings, WithdrawStrategyIntent } from "./types.js";
7
7
  import { OpenStrategyProps, OpenStrategyState } from "./open-strategy.js";
8
8
  import { fetchCreditAccountSlice, toCreditAccountSlice } from "./utils/credit-account-slice.js";
9
9
  import { isPhantomToken } from "./utils/pick-token.js";
@@ -43,19 +43,22 @@ declare class CreditAccountOperationsService extends SDKConstruct {
43
43
  */
44
44
  startIntent(props: StartProps): Promise<IntentPreviewResult>;
45
45
  /**
46
- * Largest `WITHDRAW` amount (in underlying) the account can take out while
47
- * keeping leverage and staying inside the facade's debt band — the ceiling a
48
- * withdraw form should offer. Taking everything out is the same intent with
49
- * `MAX_UINT256` for an amount, and needs none of this arithmetic.
46
+ * Both ends of what a `WITHDRAW` can take out, in underlying: the largest
47
+ * partial withdrawal that keeps leverage and stays inside the facade's debt
48
+ * band, and the net value an exit hands over. They are reported together
49
+ * because a withdraw form needs both the range it may offer, and the one
50
+ * amount past it that is allowed — and because the distance between them is
51
+ * the account's own, not a constant a caller could assume.
50
52
  *
51
53
  * Takes no target health factor, unlike {@link maxWithdrawCollateral}: a
52
54
  * proportional withdrawal leaves the factor where it found it, and the
53
55
  * facade's `minDebt` is what bounds it.
54
56
  *
55
57
  * @param props - Account slice and the SDK holding its market
56
- * @returns Amount in underlying units; `0n` when nothing can leave
58
+ * @returns The two ceilings, see {@link WithdrawCeilings} for the gap between
59
+ * them
57
60
  */
58
- maxWithdraw(props: Pick<StartIntentProps, "creditAccount" | "sdk">): bigint;
61
+ maxWithdraw(props: Pick<StartIntentProps, "creditAccount" | "sdk">): WithdrawCeilings;
59
62
  /**
60
63
  * Debt a `REPAY` would have to cover to settle the account, in underlying
61
64
  * units: principal plus the interest and fees accrued as of the read.
@@ -162,12 +165,17 @@ declare class CreditAccountOperationsService extends SDKConstruct {
162
165
  * whole tail: the tokens land on the account and only their quota has to
163
166
  * catch up.
164
167
  *
168
+ * A claim that brought only part of what the request queued — a legacy Mellow
169
+ * multivault, which pays out what it holds liquid and re-queues the rest — is
170
+ * served in proportion, and what it did not settle comes back as `remainder`:
171
+ * the withdrawal still in flight and the intent to finish it with.
172
+ *
165
173
  * @param props - The recorded intent, the account slice as it stands now, and
166
174
  * the matured claimable
167
- * @returns Shaped exactly like {@link startIntent}'s result, so both halves of
168
- * an operation are consumed the same way
175
+ * @returns Shaped exactly like {@link startIntent}'s result with the remainder
176
+ * beside it, so both halves of an operation are consumed the same way
169
177
  */
170
- finishIntent(props: FinishIntentProps): Promise<IntentPreviewResult>;
178
+ finishIntent(props: FinishIntentProps): Promise<FinishIntentResult>;
171
179
  /**
172
180
  * Previews opening a brand-new leveraged position.
173
181
  *
@@ -183,4 +191,4 @@ declare class CreditAccountOperationsService extends SDKConstruct {
183
191
  openStrategyIntent(props: OpenStrategyProps): Promise<OpenStrategyPreviewResult>;
184
192
  }
185
193
  //#endregion
186
- export { type AccountCalculatorOperation, type AddCollateralIntent, type AdjustLeverageIntent, CreditAccountOperationsService, type CreditAccountSlice, type DelayableIntent, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, type FinishIntentProps, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, type LeverageBand, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, type PathLossRate, type RepayStrategyIntent, type ResumableIntent, type RouteRefusals, type StartIntent, type WithdrawAssetIntent, type WithdrawStrategyIntent, borrowable, fetchCreditAccountSlice, isPhantomToken, toCreditAccountSlice };
194
+ export { type AccountCalculatorOperation, type AddCollateralIntent, type AdjustLeverageIntent, type ClaimRemainder, CreditAccountOperationsService, type CreditAccountSlice, type DelayableIntent, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, type FinishIntentProps, type FinishIntentResult, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, type LeverageBand, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, type PathLossRate, type RepayStrategyIntent, type ResumableIntent, type RouteRefusals, type StartIntent, type WithdrawAssetIntent, type WithdrawCeilings, type WithdrawStrategyIntent, borrowable, fetchCreditAccountSlice, isPhantomToken, toCreditAccountSlice };
@@ -1,10 +1,16 @@
1
1
  import { ClaimableWithdrawal } from "../withdrawal-compressor/types.js";
2
2
  import { OnchainSDK } from "../../OnchainSDK.js";
3
3
  import { AccountCalculatorOperation, StartDelayedWithdrawalOperation } from "./operations.js";
4
- import { CreditAccountSlice, DelayedStart, OperationState, ResumableIntent } from "./types.js";
4
+ import { ClaimRemainder, CreditAccountSlice, DelayedStart, OperationState, ResumableIntent } from "./types.js";
5
5
  import "../../index.js";
6
6
  import { AccountView, Step } from "./plan.js";
7
7
  //#region src/onchain/accounts/intents/tail.d.ts
8
+ /** The steps a claim leads to, and what it left behind for a later one. */
9
+ interface TailPlan {
10
+ steps: Step[];
11
+ /** {@inheritDoc ClaimRemainder} */
12
+ remainder: ClaimRemainder | undefined;
13
+ }
8
14
  /**
9
15
  * The second half of a delayed intent: the claim, then whatever the intent
10
16
  * still owes.
@@ -12,12 +18,16 @@ import { AccountView, Step } from "./plan.js";
12
18
  * Shared by the two callers that need it and must not disagree — the tail as
13
19
  * it is previewed days later against the account that really exists, and the
14
20
  * tail as it is projected the moment the request is made.
21
+ *
22
+ * A claim that brought only part of what was queued is served in proportion,
23
+ * see {@link partialTail}: the intent's payout and its repayment are cut to the
24
+ * share that arrived, and the rest of both is handed to the next claim.
15
25
  */
16
26
  declare function planTail(args: {
17
27
  intent: ResumableIntent;
18
28
  claimable: ClaimableWithdrawal;
19
29
  view: AccountView;
20
- }): Step[];
30
+ }): TailPlan;
21
31
  /**
22
32
  * Where a delayed intent ends up, worked out at the moment it is started.
23
33
  *
@@ -49,4 +59,4 @@ declare function projectTail(args: {
49
59
  operations: AccountCalculatorOperation[];
50
60
  }>;
51
61
  //#endregion
52
- export { planTail, projectTail };
62
+ export { TailPlan, planTail, projectTail };