@gearbox-protocol/sdk 16.0.0-next.35 → 16.0.0-next.37
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/delayed-intent.schema.js +35 -0
- package/dist/cjs/model/index.js +5 -0
- package/dist/cjs/model/withdrawals.js +1 -0
- package/dist/cjs/model/withdrawals.schema.js +39 -0
- package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +0 -10
- package/dist/cjs/onchain/positions/MultichainPositionsService.js +14 -0
- package/dist/cjs/onchain/positions/PositionsService.js +60 -0
- package/dist/cjs/preview/index.js +2 -0
- package/dist/cjs/preview/preview/estimateClaimableAt.js +21 -0
- package/dist/cjs/preview/preview/index.js +2 -0
- package/dist/cjs/preview/preview/previewOperation.js +2 -0
- package/dist/cjs/sdk/positions/PositionsNamespace.js +6 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +22 -1
- package/dist/esm/model/delayed-intent.schema.js +34 -0
- package/dist/esm/model/index.js +3 -1
- package/dist/esm/model/withdrawals.js +1 -0
- package/dist/esm/model/withdrawals.schema.js +36 -0
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +0 -10
- package/dist/esm/onchain/positions/MultichainPositionsService.js +14 -0
- package/dist/esm/onchain/positions/PositionsService.js +60 -0
- package/dist/esm/preview/index.js +2 -1
- package/dist/esm/preview/preview/estimateClaimableAt.js +20 -0
- package/dist/esm/preview/preview/index.js +2 -1
- package/dist/esm/preview/preview/previewOperation.js +2 -0
- package/dist/esm/sdk/positions/PositionsNamespace.js +6 -0
- package/dist/esm/sdk/prepare/PrepareApi.js +22 -1
- package/dist/types/model/delayed-intent.schema.d.ts +28 -0
- package/dist/types/model/index.d.ts +3 -1
- package/dist/types/model/previews.d.ts +7 -1
- package/dist/types/model/withdrawals.d.ts +87 -0
- package/dist/types/model/withdrawals.schema.d.ts +243 -0
- package/dist/types/onchain/accounts/CreditAccountsServiceV310.d.ts +1 -5
- package/dist/types/onchain/accounts/index.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/types.d.ts +2 -1
- package/dist/types/onchain/accounts/types.d.ts +2 -27
- package/dist/types/onchain/index.d.ts +3 -3
- package/dist/types/onchain/positions/MultichainPositionsService.d.ts +7 -1
- package/dist/types/onchain/positions/PositionsService.d.ts +9 -1
- package/dist/types/onchain/positions/index.d.ts +2 -2
- package/dist/types/onchain/positions/types.d.ts +31 -2
- package/dist/types/preview/index.d.ts +2 -1
- package/dist/types/preview/preview/estimateClaimableAt.d.ts +19 -0
- package/dist/types/preview/preview/index.d.ts +2 -1
- package/dist/types/sdk/positions/PositionsNamespace.d.ts +8 -2
- package/dist/types/sdk/positions/types.d.ts +11 -3
- package/dist/types/sdk/prepare/types.d.ts +6 -5
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_utils_zod = require("../onchain/utils/zod.js");
|
|
3
|
+
let zod_v4 = require("zod/v4");
|
|
4
|
+
//#region src/model/delayed-intent.schema.ts
|
|
5
|
+
const delayedIncreaseLeverageIntentSchema = zod_v4.z.object({ type: zod_v4.z.literal("INCREASE_LEVERAGE") });
|
|
6
|
+
const delayedDepositIntentSchema = zod_v4.z.object({ type: zod_v4.z.literal("DEPOSIT") });
|
|
7
|
+
const delayedDepositAndIncreaseLeverageIntentSchema = zod_v4.z.object({ type: zod_v4.z.literal("DEPOSIT_AND_INCREASE_LEVERAGE") });
|
|
8
|
+
const delayedWithdrawCollateralIntentSchema = zod_v4.z.object({
|
|
9
|
+
type: zod_v4.z.literal("WITHDRAW_COLLATERAL"),
|
|
10
|
+
to: require_onchain_utils_zod.ZodAddress(),
|
|
11
|
+
withdrawToken: require_onchain_utils_zod.ZodAddress(),
|
|
12
|
+
withdrawAmount: require_onchain_utils_zod.ZodBigInt(),
|
|
13
|
+
sourceToken: require_onchain_utils_zod.ZodAddress(),
|
|
14
|
+
debtRepaid: require_onchain_utils_zod.ZodBigInt()
|
|
15
|
+
});
|
|
16
|
+
const delayedCloseAccountIntentSchema = zod_v4.z.object({
|
|
17
|
+
type: zod_v4.z.literal("CLOSE_ACCOUNT"),
|
|
18
|
+
to: require_onchain_utils_zod.ZodAddress()
|
|
19
|
+
});
|
|
20
|
+
const delayedAddCollateralIntentSchema = zod_v4.z.object({ type: zod_v4.z.literal("ADD_COLLATERAL") });
|
|
21
|
+
const delayedDecreaseLeverageIntentSchema = zod_v4.z.object({ type: zod_v4.z.literal("DECREASE_LEVERAGE") });
|
|
22
|
+
/**
|
|
23
|
+
* {@link DelayedIntent}
|
|
24
|
+
**/
|
|
25
|
+
const delayedIntentSchema = zod_v4.z.discriminatedUnion("type", [
|
|
26
|
+
delayedIncreaseLeverageIntentSchema,
|
|
27
|
+
delayedDepositIntentSchema,
|
|
28
|
+
delayedDepositAndIncreaseLeverageIntentSchema,
|
|
29
|
+
delayedWithdrawCollateralIntentSchema,
|
|
30
|
+
delayedCloseAccountIntentSchema,
|
|
31
|
+
delayedAddCollateralIntentSchema,
|
|
32
|
+
delayedDecreaseLeverageIntentSchema
|
|
33
|
+
]);
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.delayedIntentSchema = delayedIntentSchema;
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -20,6 +20,8 @@ const require_model_previews = require("./previews.js");
|
|
|
20
20
|
require("./primitives.js");
|
|
21
21
|
require("./response.js");
|
|
22
22
|
const require_model_response_schema = require("./response.schema.js");
|
|
23
|
+
require("./withdrawals.js");
|
|
24
|
+
const require_model_withdrawals_schema = require("./withdrawals.schema.js");
|
|
23
25
|
exports.CHART_METRIC_UNITS = require_model_charts.CHART_METRIC_UNITS;
|
|
24
26
|
exports.CHART_RANGES = require_model_charts.CHART_RANGES;
|
|
25
27
|
exports.CHART_UNAVAILABLE_CODES = require_model_charts.CHART_UNAVAILABLE_CODES;
|
|
@@ -106,6 +108,7 @@ exports.poolPositionChartMetricSchema = require_model_charts_schema.poolPosition
|
|
|
106
108
|
exports.poolPositionId = require_model_positions.poolPositionId;
|
|
107
109
|
exports.poolPositionKeySchema = require_model_positions_schema.poolPositionKeySchema;
|
|
108
110
|
exports.poolPositionSchema = require_model_positions_schema.poolPositionSchema;
|
|
111
|
+
exports.positionClaimableWithdrawalSchema = require_model_withdrawals_schema.positionClaimableWithdrawalSchema;
|
|
109
112
|
exports.positionCollateralSchema = require_model_positions_schema.positionCollateralSchema;
|
|
110
113
|
exports.positionFilterQueryParamsSchema = require_model_positions_schema.positionFilterQueryParamsSchema;
|
|
111
114
|
exports.positionFilterQuerySchema = require_model_positions_schema.positionFilterQuerySchema;
|
|
@@ -113,9 +116,11 @@ exports.positionFilterSchema = require_model_positions_schema.positionFilterSche
|
|
|
113
116
|
exports.positionId = require_model_positions.positionId;
|
|
114
117
|
exports.positionKeySchema = require_model_positions_schema.positionKeySchema;
|
|
115
118
|
exports.positionKindSchema = require_model_positions_schema.positionKindSchema;
|
|
119
|
+
exports.positionPendingWithdrawalSchema = require_model_withdrawals_schema.positionPendingWithdrawalSchema;
|
|
116
120
|
exports.positionSchema = require_model_positions_schema.positionSchema;
|
|
117
121
|
exports.positionTransactionKindSchema = require_model_positions_schema.positionTransactionKindSchema;
|
|
118
122
|
exports.positionTransactionSchema = require_model_positions_schema.positionTransactionSchema;
|
|
123
|
+
exports.positionWithdrawalsSchema = require_model_withdrawals_schema.positionWithdrawalsSchema;
|
|
119
124
|
exports.positionsTotalsSchema = require_model_positions_schema.positionsTotalsSchema;
|
|
120
125
|
exports.priceFeedDataSchema = require_model_opportunities_schema.priceFeedDataSchema;
|
|
121
126
|
exports.priceFeedSummarySchema = require_model_opportunities_schema.priceFeedSummarySchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_utils_zod = require("../onchain/utils/zod.js");
|
|
3
|
+
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
4
|
+
const require_model_delayed_intent_schema = require("./delayed-intent.schema.js");
|
|
5
|
+
let zod_v4 = require("zod/v4");
|
|
6
|
+
//#region src/model/withdrawals.schema.ts
|
|
7
|
+
/**
|
|
8
|
+
* {@link PositionClaimableWithdrawal}
|
|
9
|
+
**/
|
|
10
|
+
const positionClaimableWithdrawalSchema = zod_v4.z.object({
|
|
11
|
+
sourceToken: require_model_primitives_schema.tokenSchema,
|
|
12
|
+
withdrawalPhantomToken: require_model_primitives_schema.tokenAmountSchema,
|
|
13
|
+
outputs: zod_v4.z.array(require_model_primitives_schema.tokenAmountSchema),
|
|
14
|
+
claimCall: require_model_primitives_schema.txCallSchema,
|
|
15
|
+
redeemer: require_onchain_utils_zod.ZodAddress().optional(),
|
|
16
|
+
intent: require_model_delayed_intent_schema.delayedIntentSchema.optional()
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* {@link PositionPendingWithdrawal}
|
|
20
|
+
**/
|
|
21
|
+
const positionPendingWithdrawalSchema = zod_v4.z.object({
|
|
22
|
+
sourceToken: require_model_primitives_schema.tokenSchema,
|
|
23
|
+
withdrawalPhantomToken: require_model_primitives_schema.tokenSchema,
|
|
24
|
+
expectedOutputs: zod_v4.z.array(require_model_primitives_schema.tokenAmountSchema),
|
|
25
|
+
claimableAt: require_model_primitives_schema.timestampSchema,
|
|
26
|
+
redeemer: require_onchain_utils_zod.ZodAddress().optional(),
|
|
27
|
+
intent: require_model_delayed_intent_schema.delayedIntentSchema.optional()
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* {@link PositionWithdrawals}
|
|
31
|
+
**/
|
|
32
|
+
const positionWithdrawalsSchema = zod_v4.z.object({
|
|
33
|
+
claimable: zod_v4.z.array(positionClaimableWithdrawalSchema),
|
|
34
|
+
pending: zod_v4.z.array(positionPendingWithdrawalSchema)
|
|
35
|
+
});
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.positionClaimableWithdrawalSchema = positionClaimableWithdrawalSchema;
|
|
38
|
+
exports.positionPendingWithdrawalSchema = positionPendingWithdrawalSchema;
|
|
39
|
+
exports.positionWithdrawalsSchema = positionWithdrawalsSchema;
|
|
@@ -158,16 +158,6 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
|
-
* {@inheritDoc ICreditAccountsService.getPendingWithdrawals}
|
|
162
|
-
**/
|
|
163
|
-
async getPendingWithdrawals({ creditAccount }) {
|
|
164
|
-
const { claimable, pending } = await this.#withdrawalCompressor.getCurrentWithdrawals(creditAccount);
|
|
165
|
-
return {
|
|
166
|
-
claimableNow: claimable,
|
|
167
|
-
pending
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
161
|
* {@inheritDoc ICreditAccountsService.assembleStartDelayedWithdrawalCalls}
|
|
172
162
|
**/
|
|
173
163
|
assembleStartDelayedWithdrawalCalls({ creditFacade, preview }) {
|
|
@@ -23,6 +23,20 @@ var MultichainPositionsService = class extends require_onchain_base_MultichainCo
|
|
|
23
23
|
})
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Delayed withdrawals of one credit account, see
|
|
28
|
+
* {@link PositionsService.getCurrentWithdrawals}.
|
|
29
|
+
**/
|
|
30
|
+
async getCurrentWithdrawals(props) {
|
|
31
|
+
return this.queryChain({
|
|
32
|
+
network: props.chainId,
|
|
33
|
+
block: props.blockNumber ?? "latest",
|
|
34
|
+
run: (sdk, block) => sdk.positions.getCurrentWithdrawals({
|
|
35
|
+
creditAccount: props.creditAccount,
|
|
36
|
+
blockNumber: block.blockNumber
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
}
|
|
26
40
|
};
|
|
27
41
|
//#endregion
|
|
28
42
|
exports.MultichainPositionsService = MultichainPositionsService;
|
|
@@ -71,6 +71,25 @@ var PositionsService = class extends require_onchain_base_SDKConstruct.SDKConstr
|
|
|
71
71
|
return accounts.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new require_onchain_utils_AddressMap.AddressMap()));
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
+
* Returns delayed withdrawals of a strategy position
|
|
75
|
+
*
|
|
76
|
+
* Empty when this chain has no withdrawal compressor, or the account does
|
|
77
|
+
* not exist.
|
|
78
|
+
**/
|
|
79
|
+
async getCurrentWithdrawals(props) {
|
|
80
|
+
const { creditAccount, blockNumber } = props;
|
|
81
|
+
const empty = {
|
|
82
|
+
claimable: [],
|
|
83
|
+
pending: []
|
|
84
|
+
};
|
|
85
|
+
const compressor = this.sdk.withdrawalCompressor;
|
|
86
|
+
if (!compressor) return empty;
|
|
87
|
+
const ca = await this.sdk.accounts.getCreditAccountData(creditAccount, blockNumber);
|
|
88
|
+
if (!ca) return empty;
|
|
89
|
+
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
90
|
+
return this.#toPositionWithdrawals(await compressor.getCurrentWithdrawals(creditAccount, blockNumber), priceOracle);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
74
93
|
* Health factor of an account state, in basis points (`10000` = 1.0).
|
|
75
94
|
**/
|
|
76
95
|
healthFactor(snapshot, options) {
|
|
@@ -351,6 +370,47 @@ var PositionsService = class extends require_onchain_base_SDKConstruct.SDKConstr
|
|
|
351
370
|
return byPhantomToken;
|
|
352
371
|
}
|
|
353
372
|
/**
|
|
373
|
+
* Maps compressor withdrawals into the read model's vocabulary.
|
|
374
|
+
**/
|
|
375
|
+
#toPositionWithdrawals(raw, priceOracle) {
|
|
376
|
+
return {
|
|
377
|
+
claimable: raw.claimable.map((w) => this.#toPositionClaimableWithdrawal(w, priceOracle)),
|
|
378
|
+
pending: raw.pending.map((w) => this.#toPositionPendingWithdrawal(w, priceOracle))
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
#toPositionClaimableWithdrawal(w, priceOracle) {
|
|
382
|
+
return {
|
|
383
|
+
sourceToken: this.sdk.tokensMeta.mustGetToken(w.token),
|
|
384
|
+
withdrawalPhantomToken: priceOracle.toTokenAmount(w.withdrawalPhantomToken, w.withdrawalTokenSpent),
|
|
385
|
+
outputs: w.outputs.map((o) => priceOracle.toTokenAmount(o.token, o.amount)),
|
|
386
|
+
claimCall: this.#claimTx(w.claimCalls, w.token),
|
|
387
|
+
redeemer: w.redeemer,
|
|
388
|
+
intent: w.intent
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
#toPositionPendingWithdrawal(w, priceOracle) {
|
|
392
|
+
return {
|
|
393
|
+
sourceToken: this.sdk.tokensMeta.mustGetToken(w.token),
|
|
394
|
+
withdrawalPhantomToken: this.sdk.tokensMeta.mustGetToken(w.withdrawalPhantomToken),
|
|
395
|
+
expectedOutputs: w.expectedOutputs.map((o) => priceOracle.toTokenAmount(o.token, o.amount)),
|
|
396
|
+
claimableAt: Number(w.claimableAt),
|
|
397
|
+
redeemer: w.redeemer,
|
|
398
|
+
intent: w.intent
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Subcompressors always report exactly one adapter call per claimable
|
|
403
|
+
* withdrawal.
|
|
404
|
+
**/
|
|
405
|
+
#claimTx(claimCalls, sourceToken) {
|
|
406
|
+
const call = claimCalls[0];
|
|
407
|
+
if (claimCalls.length !== 1 || !call) throw new Error(`expected exactly one claim call for withdrawal of ${sourceToken}, got ${claimCalls.length}`);
|
|
408
|
+
return {
|
|
409
|
+
to: call.target,
|
|
410
|
+
callData: call.callData
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
354
414
|
* Collects decimals, prices and thresholds for the snapshot's tokens plus
|
|
355
415
|
* the market underlying, even when the account holds no underlying balance.
|
|
356
416
|
**/
|
|
@@ -26,6 +26,7 @@ const require_preview_preview_detectCloseOrRepay = require("./preview/detectClos
|
|
|
26
26
|
const require_preview_preview_detectDelayedClaim = require("./preview/detectDelayedClaim.js");
|
|
27
27
|
const require_preview_preview_detectDelayedOperation = require("./preview/detectDelayedOperation.js");
|
|
28
28
|
const require_preview_preview_errors = require("./preview/errors.js");
|
|
29
|
+
const require_preview_preview_estimateClaimableAt = require("./preview/estimateClaimableAt.js");
|
|
29
30
|
const require_preview_preview_replayInnerOperations = require("./preview/replayInnerOperations.js");
|
|
30
31
|
const require_preview_preview_replayMulticall = require("./preview/replayMulticall.js");
|
|
31
32
|
const require_preview_preview_previewAdjustStrategyPosition = require("./preview/previewAdjustStrategyPosition.js");
|
|
@@ -60,6 +61,7 @@ exports.classifyInnerOperations = require_preview_parse_classifyInnerOperations.
|
|
|
60
61
|
exports.collateralIssue = require_preview_validate_checkOperation.collateralIssue;
|
|
61
62
|
exports.detectDelayedClaim = require_preview_preview_detectDelayedClaim.detectDelayedClaim;
|
|
62
63
|
exports.detectDelayedOperation = require_preview_preview_detectDelayedOperation.detectDelayedOperation;
|
|
64
|
+
exports.estimateClaimableAt = require_preview_preview_estimateClaimableAt.estimateClaimableAt;
|
|
63
65
|
exports.extractAdapterCallTraces = require_preview_trace_extractAdapterCallTraces.extractAdapterCallTraces;
|
|
64
66
|
exports.extractTransfers = require_preview_trace_extractTransfers.extractTransfers;
|
|
65
67
|
exports.findFacadeCalls = require_preview_trace_findFacadeCalls.findFacadeCalls;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let viem = require("viem");
|
|
3
|
+
//#region src/preview/preview/estimateClaimableAt.ts
|
|
4
|
+
/**
|
|
5
|
+
* Estimates when a newly requested delayed withdrawal becomes claimable:
|
|
6
|
+
* `now + withdrawalLength` of the cached withdrawable asset whose phantom
|
|
7
|
+
* token matches `phantomToken`. Same formula as
|
|
8
|
+
* `getWithdrawalRequestResult().claimableAt`.
|
|
9
|
+
*
|
|
10
|
+
* Returns `undefined` when the withdrawal compressor is missing, its assets
|
|
11
|
+
* cache is not loaded, or no asset matches the phantom token.
|
|
12
|
+
*/
|
|
13
|
+
function estimateClaimableAt(sdk, phantomToken) {
|
|
14
|
+
const compressor = sdk.withdrawalCompressor;
|
|
15
|
+
if (!compressor?.state) return;
|
|
16
|
+
const asset = compressor.getWithdrawableAssets().find((a) => (0, viem.isAddressEqual)(a.withdrawalPhantomToken, phantomToken));
|
|
17
|
+
if (!asset) return;
|
|
18
|
+
return Math.floor(Date.now() / 1e3) + Number(asset.withdrawalLength);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.estimateClaimableAt = estimateClaimableAt;
|
|
@@ -5,6 +5,7 @@ const require_preview_preview_detectCloseOrRepay = require("./detectCloseOrRepay
|
|
|
5
5
|
const require_preview_preview_detectDelayedClaim = require("./detectDelayedClaim.js");
|
|
6
6
|
const require_preview_preview_detectDelayedOperation = require("./detectDelayedOperation.js");
|
|
7
7
|
const require_preview_preview_errors = require("./errors.js");
|
|
8
|
+
const require_preview_preview_estimateClaimableAt = require("./estimateClaimableAt.js");
|
|
8
9
|
const require_preview_preview_replayInnerOperations = require("./replayInnerOperations.js");
|
|
9
10
|
const require_preview_preview_replayMulticall = require("./replayMulticall.js");
|
|
10
11
|
const require_preview_preview_previewAdjustStrategyPosition = require("./previewAdjustStrategyPosition.js");
|
|
@@ -16,6 +17,7 @@ exports.buildDelayedStrategyPositionOperationPreview = require_preview_preview_b
|
|
|
16
17
|
exports.classifyCloseOrRepay = require_preview_preview_detectCloseOrRepay.classifyCloseOrRepay;
|
|
17
18
|
exports.detectDelayedClaim = require_preview_preview_detectDelayedClaim.detectDelayedClaim;
|
|
18
19
|
exports.detectDelayedOperation = require_preview_preview_detectDelayedOperation.detectDelayedOperation;
|
|
20
|
+
exports.estimateClaimableAt = require_preview_preview_estimateClaimableAt.estimateClaimableAt;
|
|
19
21
|
exports.isCloseOrRepay = require_preview_preview_detectCloseOrRepay.isCloseOrRepay;
|
|
20
22
|
exports.makeReplayState = require_preview_preview_replayInnerOperations.makeReplayState;
|
|
21
23
|
exports.previewAdjustStrategyPosition = require_preview_preview_previewAdjustStrategyPosition.previewAdjustStrategyPosition;
|
|
@@ -9,6 +9,7 @@ const require_preview_preview_detectCloseOrRepay = require("./detectCloseOrRepay
|
|
|
9
9
|
const require_preview_preview_detectDelayedClaim = require("./detectDelayedClaim.js");
|
|
10
10
|
const require_preview_preview_detectDelayedOperation = require("./detectDelayedOperation.js");
|
|
11
11
|
const require_preview_preview_errors = require("./errors.js");
|
|
12
|
+
const require_preview_preview_estimateClaimableAt = require("./estimateClaimableAt.js");
|
|
12
13
|
const require_preview_preview_replayMulticall = require("./replayMulticall.js");
|
|
13
14
|
const require_preview_preview_previewAdjustStrategyPosition = require("./previewAdjustStrategyPosition.js");
|
|
14
15
|
const require_preview_preview_previewExitOrRepayStrategyPosition = require("./previewExitOrRepayStrategyPosition.js");
|
|
@@ -71,6 +72,7 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
71
72
|
creditAccount: operation.creditAccount,
|
|
72
73
|
...require_onchain_market_credit_creditOperationMarket.creditOperationMarket(sdk.marketRegister.findCreditManager(operation.creditManager)),
|
|
73
74
|
intent: delayed.intent,
|
|
75
|
+
estClaimableAt: require_preview_preview_estimateClaimableAt.estimateClaimableAt(sdk, delayed.request.phantomToken),
|
|
74
76
|
instantPreview,
|
|
75
77
|
delayedPreview: require_preview_preview_buildDelayedStrategyPositionOperationPreview.buildDelayedStrategyPositionOperationPreview(after.account, before, delayed, convert, receivedToken, sdk)
|
|
76
78
|
};
|
|
@@ -50,6 +50,12 @@ var PositionsNamespace = class extends require_sdk_AbstractNamespace.AbstractNam
|
|
|
50
50
|
async charts(key, metrics, range) {
|
|
51
51
|
return this.offchain.getCharts(key, metrics, range);
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* {@inheritDoc IPositionsOnchainOnly.getCurrentWithdrawals}
|
|
55
|
+
**/
|
|
56
|
+
async getCurrentWithdrawals(props) {
|
|
57
|
+
return this.onchain.getCurrentWithdrawals(props);
|
|
58
|
+
}
|
|
53
59
|
};
|
|
54
60
|
//#endregion
|
|
55
61
|
exports.PositionsNamespace = PositionsNamespace;
|
|
@@ -42,7 +42,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
42
42
|
if (!intent) return require_onchain_validation_refusal.refuse("noRecordedIntent", void 0);
|
|
43
43
|
return service(sdk).finishIntent({
|
|
44
44
|
intent,
|
|
45
|
-
claimable: params.claimable,
|
|
45
|
+
claimable: toClaimableWithdrawal(params.claimable),
|
|
46
46
|
creditAccount: await slice(sdk, position.creditAccount),
|
|
47
47
|
sdk,
|
|
48
48
|
slippage: params.slippage,
|
|
@@ -341,6 +341,27 @@ function resumable(intent) {
|
|
|
341
341
|
return intent ?? void 0;
|
|
342
342
|
}
|
|
343
343
|
/**
|
|
344
|
+
* Unwraps a read-model claimable withdrawal into the compressor shape the
|
|
345
|
+
* intents engine plans from.
|
|
346
|
+
**/
|
|
347
|
+
function toClaimableWithdrawal(claimable) {
|
|
348
|
+
return {
|
|
349
|
+
token: claimable.sourceToken.address,
|
|
350
|
+
withdrawalPhantomToken: claimable.withdrawalPhantomToken.token.address,
|
|
351
|
+
withdrawalTokenSpent: claimable.withdrawalPhantomToken.value,
|
|
352
|
+
outputs: claimable.outputs.map((o) => ({
|
|
353
|
+
token: o.token.address,
|
|
354
|
+
amount: o.value,
|
|
355
|
+
isDelayed: false
|
|
356
|
+
})),
|
|
357
|
+
claimCalls: [{
|
|
358
|
+
target: claimable.claimCall.to,
|
|
359
|
+
callData: claimable.claimCall.callData
|
|
360
|
+
}],
|
|
361
|
+
redeemer: claimable.redeemer
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
344
365
|
* A pool route the market does not offer, as the refusal a caller reads.
|
|
345
366
|
*
|
|
346
367
|
* `to` is absent where {@link lpRoute} found no output to name at all, which
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ZodAddress, ZodBigInt } from "../onchain/utils/zod.js";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
//#region src/model/delayed-intent.schema.ts
|
|
4
|
+
const delayedIncreaseLeverageIntentSchema = z.object({ type: z.literal("INCREASE_LEVERAGE") });
|
|
5
|
+
const delayedDepositIntentSchema = z.object({ type: z.literal("DEPOSIT") });
|
|
6
|
+
const delayedDepositAndIncreaseLeverageIntentSchema = z.object({ type: z.literal("DEPOSIT_AND_INCREASE_LEVERAGE") });
|
|
7
|
+
const delayedWithdrawCollateralIntentSchema = z.object({
|
|
8
|
+
type: z.literal("WITHDRAW_COLLATERAL"),
|
|
9
|
+
to: ZodAddress(),
|
|
10
|
+
withdrawToken: ZodAddress(),
|
|
11
|
+
withdrawAmount: ZodBigInt(),
|
|
12
|
+
sourceToken: ZodAddress(),
|
|
13
|
+
debtRepaid: ZodBigInt()
|
|
14
|
+
});
|
|
15
|
+
const delayedCloseAccountIntentSchema = z.object({
|
|
16
|
+
type: z.literal("CLOSE_ACCOUNT"),
|
|
17
|
+
to: ZodAddress()
|
|
18
|
+
});
|
|
19
|
+
const delayedAddCollateralIntentSchema = z.object({ type: z.literal("ADD_COLLATERAL") });
|
|
20
|
+
const delayedDecreaseLeverageIntentSchema = z.object({ type: z.literal("DECREASE_LEVERAGE") });
|
|
21
|
+
/**
|
|
22
|
+
* {@link DelayedIntent}
|
|
23
|
+
**/
|
|
24
|
+
const delayedIntentSchema = z.discriminatedUnion("type", [
|
|
25
|
+
delayedIncreaseLeverageIntentSchema,
|
|
26
|
+
delayedDepositIntentSchema,
|
|
27
|
+
delayedDepositAndIncreaseLeverageIntentSchema,
|
|
28
|
+
delayedWithdrawCollateralIntentSchema,
|
|
29
|
+
delayedCloseAccountIntentSchema,
|
|
30
|
+
delayedAddCollateralIntentSchema,
|
|
31
|
+
delayedDecreaseLeverageIntentSchema
|
|
32
|
+
]);
|
|
33
|
+
//#endregion
|
|
34
|
+
export { delayedIntentSchema };
|
package/dist/esm/model/index.js
CHANGED
|
@@ -19,4 +19,6 @@ import { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ER
|
|
|
19
19
|
import "./primitives.js";
|
|
20
20
|
import "./response.js";
|
|
21
21
|
import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
|
|
22
|
-
|
|
22
|
+
import "./withdrawals.js";
|
|
23
|
+
import { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema } from "./withdrawals.schema.js";
|
|
24
|
+
export { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, 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, FILTER_ALL, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, 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, 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, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ZodAddress } from "../onchain/utils/zod.js";
|
|
2
|
+
import { timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
3
|
+
import { delayedIntentSchema } from "./delayed-intent.schema.js";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
//#region src/model/withdrawals.schema.ts
|
|
6
|
+
/**
|
|
7
|
+
* {@link PositionClaimableWithdrawal}
|
|
8
|
+
**/
|
|
9
|
+
const positionClaimableWithdrawalSchema = z.object({
|
|
10
|
+
sourceToken: tokenSchema,
|
|
11
|
+
withdrawalPhantomToken: tokenAmountSchema,
|
|
12
|
+
outputs: z.array(tokenAmountSchema),
|
|
13
|
+
claimCall: txCallSchema,
|
|
14
|
+
redeemer: ZodAddress().optional(),
|
|
15
|
+
intent: delayedIntentSchema.optional()
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* {@link PositionPendingWithdrawal}
|
|
19
|
+
**/
|
|
20
|
+
const positionPendingWithdrawalSchema = z.object({
|
|
21
|
+
sourceToken: tokenSchema,
|
|
22
|
+
withdrawalPhantomToken: tokenSchema,
|
|
23
|
+
expectedOutputs: z.array(tokenAmountSchema),
|
|
24
|
+
claimableAt: timestampSchema,
|
|
25
|
+
redeemer: ZodAddress().optional(),
|
|
26
|
+
intent: delayedIntentSchema.optional()
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* {@link PositionWithdrawals}
|
|
30
|
+
**/
|
|
31
|
+
const positionWithdrawalsSchema = z.object({
|
|
32
|
+
claimable: z.array(positionClaimableWithdrawalSchema),
|
|
33
|
+
pending: z.array(positionPendingWithdrawalSchema)
|
|
34
|
+
});
|
|
35
|
+
//#endregion
|
|
36
|
+
export { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema };
|
|
@@ -157,16 +157,6 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
|
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
|
-
* {@inheritDoc ICreditAccountsService.getPendingWithdrawals}
|
|
161
|
-
**/
|
|
162
|
-
async getPendingWithdrawals({ creditAccount }) {
|
|
163
|
-
const { claimable, pending } = await this.#withdrawalCompressor.getCurrentWithdrawals(creditAccount);
|
|
164
|
-
return {
|
|
165
|
-
claimableNow: claimable,
|
|
166
|
-
pending
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
160
|
* {@inheritDoc ICreditAccountsService.assembleStartDelayedWithdrawalCalls}
|
|
171
161
|
**/
|
|
172
162
|
assembleStartDelayedWithdrawalCalls({ creditFacade, preview }) {
|
|
@@ -22,6 +22,20 @@ var MultichainPositionsService = class extends MultichainConstruct {
|
|
|
22
22
|
})
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Delayed withdrawals of one credit account, see
|
|
27
|
+
* {@link PositionsService.getCurrentWithdrawals}.
|
|
28
|
+
**/
|
|
29
|
+
async getCurrentWithdrawals(props) {
|
|
30
|
+
return this.queryChain({
|
|
31
|
+
network: props.chainId,
|
|
32
|
+
block: props.blockNumber ?? "latest",
|
|
33
|
+
run: (sdk, block) => sdk.positions.getCurrentWithdrawals({
|
|
34
|
+
creditAccount: props.creditAccount,
|
|
35
|
+
blockNumber: block.blockNumber
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
25
39
|
};
|
|
26
40
|
//#endregion
|
|
27
41
|
export { MultichainPositionsService };
|
|
@@ -70,6 +70,25 @@ var PositionsService = class extends SDKConstruct {
|
|
|
70
70
|
return accounts.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new AddressMap()));
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
+
* Returns delayed withdrawals of a strategy position
|
|
74
|
+
*
|
|
75
|
+
* Empty when this chain has no withdrawal compressor, or the account does
|
|
76
|
+
* not exist.
|
|
77
|
+
**/
|
|
78
|
+
async getCurrentWithdrawals(props) {
|
|
79
|
+
const { creditAccount, blockNumber } = props;
|
|
80
|
+
const empty = {
|
|
81
|
+
claimable: [],
|
|
82
|
+
pending: []
|
|
83
|
+
};
|
|
84
|
+
const compressor = this.sdk.withdrawalCompressor;
|
|
85
|
+
if (!compressor) return empty;
|
|
86
|
+
const ca = await this.sdk.accounts.getCreditAccountData(creditAccount, blockNumber);
|
|
87
|
+
if (!ca) return empty;
|
|
88
|
+
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
89
|
+
return this.#toPositionWithdrawals(await compressor.getCurrentWithdrawals(creditAccount, blockNumber), priceOracle);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
73
92
|
* Health factor of an account state, in basis points (`10000` = 1.0).
|
|
74
93
|
**/
|
|
75
94
|
healthFactor(snapshot, options) {
|
|
@@ -350,6 +369,47 @@ var PositionsService = class extends SDKConstruct {
|
|
|
350
369
|
return byPhantomToken;
|
|
351
370
|
}
|
|
352
371
|
/**
|
|
372
|
+
* Maps compressor withdrawals into the read model's vocabulary.
|
|
373
|
+
**/
|
|
374
|
+
#toPositionWithdrawals(raw, priceOracle) {
|
|
375
|
+
return {
|
|
376
|
+
claimable: raw.claimable.map((w) => this.#toPositionClaimableWithdrawal(w, priceOracle)),
|
|
377
|
+
pending: raw.pending.map((w) => this.#toPositionPendingWithdrawal(w, priceOracle))
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
#toPositionClaimableWithdrawal(w, priceOracle) {
|
|
381
|
+
return {
|
|
382
|
+
sourceToken: this.sdk.tokensMeta.mustGetToken(w.token),
|
|
383
|
+
withdrawalPhantomToken: priceOracle.toTokenAmount(w.withdrawalPhantomToken, w.withdrawalTokenSpent),
|
|
384
|
+
outputs: w.outputs.map((o) => priceOracle.toTokenAmount(o.token, o.amount)),
|
|
385
|
+
claimCall: this.#claimTx(w.claimCalls, w.token),
|
|
386
|
+
redeemer: w.redeemer,
|
|
387
|
+
intent: w.intent
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
#toPositionPendingWithdrawal(w, priceOracle) {
|
|
391
|
+
return {
|
|
392
|
+
sourceToken: this.sdk.tokensMeta.mustGetToken(w.token),
|
|
393
|
+
withdrawalPhantomToken: this.sdk.tokensMeta.mustGetToken(w.withdrawalPhantomToken),
|
|
394
|
+
expectedOutputs: w.expectedOutputs.map((o) => priceOracle.toTokenAmount(o.token, o.amount)),
|
|
395
|
+
claimableAt: Number(w.claimableAt),
|
|
396
|
+
redeemer: w.redeemer,
|
|
397
|
+
intent: w.intent
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Subcompressors always report exactly one adapter call per claimable
|
|
402
|
+
* withdrawal.
|
|
403
|
+
**/
|
|
404
|
+
#claimTx(claimCalls, sourceToken) {
|
|
405
|
+
const call = claimCalls[0];
|
|
406
|
+
if (claimCalls.length !== 1 || !call) throw new Error(`expected exactly one claim call for withdrawal of ${sourceToken}, got ${claimCalls.length}`);
|
|
407
|
+
return {
|
|
408
|
+
to: call.target,
|
|
409
|
+
callData: call.callData
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
353
413
|
* Collects decimals, prices and thresholds for the snapshot's tokens plus
|
|
354
414
|
* the market underlying, even when the account holds no underlying balance.
|
|
355
415
|
**/
|
|
@@ -25,6 +25,7 @@ import { classifyCloseOrRepay, isCloseOrRepay } from "./preview/detectCloseOrRep
|
|
|
25
25
|
import { detectDelayedClaim, resolveDelayedClaimIntent } from "./preview/detectDelayedClaim.js";
|
|
26
26
|
import { detectDelayedOperation } from "./preview/detectDelayedOperation.js";
|
|
27
27
|
import { UnsupportedOperationError } from "./preview/errors.js";
|
|
28
|
+
import { estimateClaimableAt } from "./preview/estimateClaimableAt.js";
|
|
28
29
|
import { makeReplayState, replayInnerOperations } from "./preview/replayInnerOperations.js";
|
|
29
30
|
import { replayMulticall } from "./preview/replayMulticall.js";
|
|
30
31
|
import { previewAdjustStrategyPosition } from "./preview/previewAdjustStrategyPosition.js";
|
|
@@ -35,4 +36,4 @@ import "./types.js";
|
|
|
35
36
|
import { checkOperation, collateralIssue, marketIssues, quotaCountIssue } from "./validate/checkOperation.js";
|
|
36
37
|
import { checkSimulation } from "./validate/checkSimulation.js";
|
|
37
38
|
import "./validate/index.js";
|
|
38
|
-
export { AllowancePrerequisite, BalancePrerequisite, CreditAccountState, IntentPreviewError, Prerequisite, RWAOpenRequirementsPrerequisite, TransferAlignmentError, UnexpectedFacadeEventOrderError, UnknownAdapterError, UnknownFacadeCallError, UnsupportedOperationError, UnsupportedPoolFunctionError, UnsupportedTargetError, UnsupportedZapperFunctionError, WithdrawCollateralAlignmentError, buildDelayedStrategyPositionOperationPreview, checkOperation, checkPrerequisites, checkSimulation, classifyCloseOrRepay, classifyInnerOperations, collateralIssue, detectDelayedClaim, detectDelayedOperation, extractAdapterCallTraces, extractTransfers, findFacadeCalls, isCloseOrRepay, isPoolOperation, isRWAOperation, makeReplayState, marketIssues, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parseRWAFactoryOperationCalldata, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, quotaCountIssue, raise, refuse, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
|
|
39
|
+
export { AllowancePrerequisite, BalancePrerequisite, CreditAccountState, IntentPreviewError, Prerequisite, RWAOpenRequirementsPrerequisite, TransferAlignmentError, UnexpectedFacadeEventOrderError, UnknownAdapterError, UnknownFacadeCallError, UnsupportedOperationError, UnsupportedPoolFunctionError, UnsupportedTargetError, UnsupportedZapperFunctionError, WithdrawCollateralAlignmentError, buildDelayedStrategyPositionOperationPreview, checkOperation, checkPrerequisites, checkSimulation, classifyCloseOrRepay, classifyInnerOperations, collateralIssue, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, extractAdapterCallTraces, extractTransfers, findFacadeCalls, isCloseOrRepay, isPoolOperation, isRWAOperation, makeReplayState, marketIssues, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parseRWAFactoryOperationCalldata, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, quotaCountIssue, raise, refuse, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isAddressEqual } from "viem";
|
|
2
|
+
//#region src/preview/preview/estimateClaimableAt.ts
|
|
3
|
+
/**
|
|
4
|
+
* Estimates when a newly requested delayed withdrawal becomes claimable:
|
|
5
|
+
* `now + withdrawalLength` of the cached withdrawable asset whose phantom
|
|
6
|
+
* token matches `phantomToken`. Same formula as
|
|
7
|
+
* `getWithdrawalRequestResult().claimableAt`.
|
|
8
|
+
*
|
|
9
|
+
* Returns `undefined` when the withdrawal compressor is missing, its assets
|
|
10
|
+
* cache is not loaded, or no asset matches the phantom token.
|
|
11
|
+
*/
|
|
12
|
+
function estimateClaimableAt(sdk, phantomToken) {
|
|
13
|
+
const compressor = sdk.withdrawalCompressor;
|
|
14
|
+
if (!compressor?.state) return;
|
|
15
|
+
const asset = compressor.getWithdrawableAssets().find((a) => isAddressEqual(a.withdrawalPhantomToken, phantomToken));
|
|
16
|
+
if (!asset) return;
|
|
17
|
+
return Math.floor(Date.now() / 1e3) + Number(asset.withdrawalLength);
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { estimateClaimableAt };
|
|
@@ -4,9 +4,10 @@ import { classifyCloseOrRepay, isCloseOrRepay } from "./detectCloseOrRepay.js";
|
|
|
4
4
|
import { detectDelayedClaim, resolveDelayedClaimIntent } from "./detectDelayedClaim.js";
|
|
5
5
|
import { detectDelayedOperation } from "./detectDelayedOperation.js";
|
|
6
6
|
import { UnsupportedOperationError } from "./errors.js";
|
|
7
|
+
import { estimateClaimableAt } from "./estimateClaimableAt.js";
|
|
7
8
|
import { makeReplayState, replayInnerOperations } from "./replayInnerOperations.js";
|
|
8
9
|
import { replayMulticall } from "./replayMulticall.js";
|
|
9
10
|
import { previewAdjustStrategyPosition } from "./previewAdjustStrategyPosition.js";
|
|
10
11
|
import { previewExitOrRepayStrategyPosition } from "./previewExitOrRepayStrategyPosition.js";
|
|
11
12
|
import { previewOperation } from "./previewOperation.js";
|
|
12
|
-
export { CreditAccountState, UnsupportedOperationError, buildDelayedStrategyPositionOperationPreview, classifyCloseOrRepay, detectDelayedClaim, detectDelayedOperation, isCloseOrRepay, makeReplayState, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
|
|
13
|
+
export { CreditAccountState, UnsupportedOperationError, buildDelayedStrategyPositionOperationPreview, classifyCloseOrRepay, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, isCloseOrRepay, makeReplayState, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
|
|
@@ -8,6 +8,7 @@ import { isCloseOrRepay } from "./detectCloseOrRepay.js";
|
|
|
8
8
|
import { resolveDelayedClaimIntent } from "./detectDelayedClaim.js";
|
|
9
9
|
import { detectDelayedOperation } from "./detectDelayedOperation.js";
|
|
10
10
|
import { UnsupportedOperationError } from "./errors.js";
|
|
11
|
+
import { estimateClaimableAt } from "./estimateClaimableAt.js";
|
|
11
12
|
import { replayMulticall } from "./replayMulticall.js";
|
|
12
13
|
import { previewAdjustStrategyPosition } from "./previewAdjustStrategyPosition.js";
|
|
13
14
|
import { previewExitOrRepayStrategyPosition } from "./previewExitOrRepayStrategyPosition.js";
|
|
@@ -70,6 +71,7 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
70
71
|
creditAccount: operation.creditAccount,
|
|
71
72
|
...creditOperationMarket(sdk.marketRegister.findCreditManager(operation.creditManager)),
|
|
72
73
|
intent: delayed.intent,
|
|
74
|
+
estClaimableAt: estimateClaimableAt(sdk, delayed.request.phantomToken),
|
|
73
75
|
instantPreview,
|
|
74
76
|
delayedPreview: buildDelayedStrategyPositionOperationPreview(after.account, before, delayed, convert, receivedToken, sdk)
|
|
75
77
|
};
|
|
@@ -49,6 +49,12 @@ var PositionsNamespace = class extends AbstractNamespace {
|
|
|
49
49
|
async charts(key, metrics, range) {
|
|
50
50
|
return this.offchain.getCharts(key, metrics, range);
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* {@inheritDoc IPositionsOnchainOnly.getCurrentWithdrawals}
|
|
54
|
+
**/
|
|
55
|
+
async getCurrentWithdrawals(props) {
|
|
56
|
+
return this.onchain.getCurrentWithdrawals(props);
|
|
57
|
+
}
|
|
52
58
|
};
|
|
53
59
|
//#endregion
|
|
54
60
|
export { PositionsNamespace };
|