@gearbox-protocol/sdk 16.0.0-next.44 → 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/market/adapters/contracts/BalancerV3RouterAdapterContract.js +33 -1
- 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/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/index.js +2 -2
- package/dist/esm/model/withdrawals.schema.js +7 -3
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/intents/index.js +38 -13
- package/dist/esm/onchain/accounts/intents/tail.js +112 -5
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/BalancerV3RouterAdapterContract.js +33 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/onchain/pools/PoolService.js +20 -4
- package/dist/esm/onchain/positions/PositionsService.js +8 -2
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- 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
|
@@ -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
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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:
|
|
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,28 @@ 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 after = await sdk.pools.getShareBalance({
|
|
555
|
+
pool,
|
|
556
|
+
wallet
|
|
557
|
+
}) + (moved.mints ?? -moved.burns);
|
|
558
|
+
return {
|
|
559
|
+
...simulation,
|
|
560
|
+
curator: sdk.marketRegister.findByPool(pool).curator,
|
|
561
|
+
positionAfter: sdk.pools.sharesToUnderlying(pool, after > 0n ? after : 0n)
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
514
565
|
* A pool route the market does not offer, as the refusal a caller reads.
|
|
515
566
|
*
|
|
516
567
|
* `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 };
|
|
@@ -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
|
-
*
|
|
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:
|
|
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:
|
|
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
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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
|
|
58
|
+
* @returns The two ceilings, see {@link WithdrawCeilings} for the gap between
|
|
59
|
+
* them
|
|
57
60
|
*/
|
|
58
|
-
maxWithdraw(props: Pick<StartIntentProps, "creditAccount" | "sdk">):
|
|
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
|
|
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<
|
|
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
|
-
}):
|
|
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 };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TokenAmount } from "../../../model/primitives.js";
|
|
1
2
|
import { DelayedIntent } from "../../../model/delayed-intents.js";
|
|
2
3
|
import { AccountProjection } from "../../../model/previews.js";
|
|
3
4
|
import "../../../model/index.js";
|
|
@@ -71,6 +72,44 @@ type IntentPreviewResult = {
|
|
|
71
72
|
state: OperationState;
|
|
72
73
|
calls: MultiCall[];
|
|
73
74
|
} | PreviewRefusal;
|
|
75
|
+
/**
|
|
76
|
+
* What a claim did not bring, when the venue served part of a matured
|
|
77
|
+
* withdrawal and left the rest of it queued.
|
|
78
|
+
*
|
|
79
|
+
* Every issuer the engine was written for answers a redemption whole: one
|
|
80
|
+
* request, one claim, one tail. A legacy Mellow multivault does not — it pays
|
|
81
|
+
* out whatever its subvaults hold liquid and queues the remainder, so the claim
|
|
82
|
+
* burns the phantom it names and mints a fresh one for what is still maturing.
|
|
83
|
+
* The tail then serves the share that arrived, and this says what is left to
|
|
84
|
+
* serve later.
|
|
85
|
+
*/
|
|
86
|
+
interface ClaimRemainder {
|
|
87
|
+
/**
|
|
88
|
+
* The withdrawal position the claim left on the account: the phantom token
|
|
89
|
+
* standing for the part that has not matured.
|
|
90
|
+
*/
|
|
91
|
+
inFlight: TokenAmount;
|
|
92
|
+
/**
|
|
93
|
+
* The intent to finish with once it does — this one minus what the tail
|
|
94
|
+
* beside it already served, so finalising twice pays the wallet and the loan
|
|
95
|
+
* once between them.
|
|
96
|
+
*/
|
|
97
|
+
intent: ResumableIntent;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What finishing a delayed intent yields: {@link IntentPreviewResult}, plus
|
|
101
|
+
* whether the claim it was built on settled the withdrawal whole.
|
|
102
|
+
*/
|
|
103
|
+
type FinishIntentResult = (Extract<IntentPreviewResult, {
|
|
104
|
+
ok: true;
|
|
105
|
+
}> & {
|
|
106
|
+
/**
|
|
107
|
+
* `undefined` when the claim brought everything the request queued,
|
|
108
|
+
* which is every venue but a legacy Mellow one, see
|
|
109
|
+
* {@link ClaimRemainder}.
|
|
110
|
+
*/
|
|
111
|
+
remainder: ClaimRemainder | undefined;
|
|
112
|
+
}) | PreviewRefusal;
|
|
74
113
|
/** What the request recorded, and when the tail can be run. */
|
|
75
114
|
interface DelayedStart {
|
|
76
115
|
/**
|
|
@@ -371,6 +410,40 @@ interface WithdrawStrategyIntent {
|
|
|
371
410
|
*/
|
|
372
411
|
sourceToken?: Address;
|
|
373
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* Where a withdraw form's scale ends, in underlying units — and it ends twice.
|
|
415
|
+
*
|
|
416
|
+
* A withdrawal is not one continuous range. Holding leverage flat costs a
|
|
417
|
+
* proportional repayment, and the loan left behind has to clear the facade's
|
|
418
|
+
* `minDebt`, so the partial flow stops at {@link partial}. Leaving entirely
|
|
419
|
+
* settles the loan instead of shrinking it, so the floor does not apply and
|
|
420
|
+
* the whole net value can go. Between the two the flow refuses with
|
|
421
|
+
* `debtOutOfRange` rather than quietly rounding the request to one end.
|
|
422
|
+
*
|
|
423
|
+
* An account borrowing at the floor therefore reports a `partial` of almost
|
|
424
|
+
* nothing — only the interest accrued above `minDebt` can be repaid — beside
|
|
425
|
+
* an `exit` of its entire net value. That gap is the market's rule showing
|
|
426
|
+
* through, not a miscount: such a position frees real money only by leaving.
|
|
427
|
+
*/
|
|
428
|
+
interface WithdrawCeilings {
|
|
429
|
+
/**
|
|
430
|
+
* Largest partial withdrawal {@link WithdrawStrategyIntent} accepts: the one
|
|
431
|
+
* whose proportional repayment leaves the debt at `minDebt`. `0n` when the
|
|
432
|
+
* debt already sits below the floor, and always at least one unit under
|
|
433
|
+
* `exit` — the last unit closes the account rather than shrinking it.
|
|
434
|
+
*/
|
|
435
|
+
partial: bigint;
|
|
436
|
+
/**
|
|
437
|
+
* What leaving hands over: the account's net value, which is also the amount
|
|
438
|
+
* at which a withdrawal turns into an exit. `0n` on an account whose debt
|
|
439
|
+
* has caught up with its collateral.
|
|
440
|
+
*
|
|
441
|
+
* A Max button is better served by sending `MAX_UINT256` than this figure —
|
|
442
|
+
* the exit is then named outright, and no rounding in the payout token's
|
|
443
|
+
* price can drop the request back into the refused gap.
|
|
444
|
+
*/
|
|
445
|
+
exit: bigint;
|
|
446
|
+
}
|
|
374
447
|
type StartIntent = AddCollateralIntent | WithdrawAssetIntent | AdjustLeverageIntent | DepositStrategyIntent | RepayStrategyIntent | WithdrawStrategyIntent;
|
|
375
448
|
/**
|
|
376
449
|
* The intents that can be started as a redemption rather than a swap: the two
|
|
@@ -395,4 +468,4 @@ type FinishIntentProps = StartIntentProps & {
|
|
|
395
468
|
claimable: ClaimableWithdrawal;
|
|
396
469
|
};
|
|
397
470
|
//#endregion
|
|
398
|
-
export { AddCollateralIntent, AdjustLeverageIntent, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteRefusals, SimulationPrices, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawStrategyIntent };
|
|
471
|
+
export { AddCollateralIntent, AdjustLeverageIntent, ClaimRemainder, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, FinishIntentResult, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteRefusals, SimulationPrices, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawCeilings, WithdrawStrategyIntent };
|