@gearbox-protocol/sdk 14.12.0-next.40 → 14.12.0-next.41

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.
@@ -121,6 +121,27 @@ class LiquidationsService extends import_base.SDKConstruct {
121
121
  }
122
122
  return { ...account, receivedAssets };
123
123
  }
124
+ /**
125
+ * {@inheritDoc ILiquidationsService.getLiquidatorWithdrawals}
126
+ **/
127
+ async getLiquidatorWithdrawals(props) {
128
+ if (props.networks && !props.networks.includes(this.sdk.networkType)) {
129
+ return [];
130
+ }
131
+ const compressor = this.sdk.withdrawalCompressor;
132
+ if (!compressor) {
133
+ return [];
134
+ }
135
+ await compressor.loadWithdrawableAssets();
136
+ const phantomTokens = new import_utils.AddressSet(
137
+ compressor.getWithdrawableAssets().map((a) => a.withdrawalPhantomToken)
138
+ );
139
+ const current = await compressor.getExternalAccountCurrentWithdrawals(
140
+ props.liquidator,
141
+ ...phantomTokens.asArray()
142
+ );
143
+ return (0, import_helpers.toLiquidatorWithdrawals)(current, this.sdk.networkType);
144
+ }
124
145
  /**
125
146
  * Accounts of expired credit managers with outstanding debt are liquidatable
126
147
  * regardless of their health factor.
@@ -58,6 +58,32 @@ class MultichainLiquidationsService {
58
58
  async getLiquidationDetails(props) {
59
59
  return this.#sdk.chain(props.network).liquidations.getLiquidationDetails(props);
60
60
  }
61
+ /**
62
+ * {@inheritDoc ILiquidationsService.getLiquidatorWithdrawals}
63
+ **/
64
+ async getLiquidatorWithdrawals(props) {
65
+ const chains = [...this.#sdk.chains.entries()].filter(
66
+ ([network]) => !props.networks || props.networks.includes(network)
67
+ );
68
+ const results = await Promise.allSettled(
69
+ chains.map(
70
+ ([, chainSdk]) => chainSdk.liquidations.getLiquidatorWithdrawals(props)
71
+ )
72
+ );
73
+ const withdrawals = [];
74
+ results.forEach((result, i) => {
75
+ const [network, chainSdk] = chains[i];
76
+ if (result.status === "fulfilled") {
77
+ withdrawals.push(...result.value);
78
+ } else {
79
+ chainSdk.logger?.warn(
80
+ result.reason,
81
+ `failed to get liquidator withdrawals on ${network}`
82
+ );
83
+ }
84
+ });
85
+ return withdrawals;
86
+ }
61
87
  }
62
88
  // Annotate the CommonJS export names for ESM import in node:
63
89
  0 && (module.exports = {
@@ -21,7 +21,8 @@ __export(helpers_exports, {
21
21
  DUST_THRESHOLD: () => DUST_THRESHOLD,
22
22
  calcEstimatedProfit: () => calcEstimatedProfit,
23
23
  calcRepaymentAmount: () => calcRepaymentAmount,
24
- pickMainAsset: () => pickMainAsset
24
+ pickMainAsset: () => pickMainAsset,
25
+ toLiquidatorWithdrawals: () => toLiquidatorWithdrawals
25
26
  });
26
27
  module.exports = __toCommonJS(helpers_exports);
27
28
  var import_constants = require("../../constants/index.js");
@@ -54,10 +55,36 @@ function pickMainAsset(ca, convert) {
54
55
  }
55
56
  return bestToken;
56
57
  }
58
+ function toLiquidatorWithdrawals(current, network) {
59
+ const rows = [];
60
+ for (const w of current.claimable) {
61
+ for (const o of w.outputs) {
62
+ rows.push({
63
+ network,
64
+ sourceToken: w.token,
65
+ token: o.token,
66
+ amount: o.amount
67
+ });
68
+ }
69
+ }
70
+ for (const w of current.pending) {
71
+ for (const o of w.expectedOutputs) {
72
+ rows.push({
73
+ network,
74
+ sourceToken: w.token,
75
+ token: o.token,
76
+ amount: o.amount,
77
+ claimableAt: w.claimableAt
78
+ });
79
+ }
80
+ }
81
+ return rows;
82
+ }
57
83
  // Annotate the CommonJS export names for ESM import in node:
58
84
  0 && (module.exports = {
59
85
  DUST_THRESHOLD,
60
86
  calcEstimatedProfit,
61
87
  calcRepaymentAmount,
62
- pickMainAsset
88
+ pickMainAsset,
89
+ toLiquidatorWithdrawals
63
90
  });
@@ -5,7 +5,8 @@ import {
5
5
  calcEstimatedProfit,
6
6
  calcRepaymentAmount,
7
7
  DUST_THRESHOLD,
8
- pickMainAsset
8
+ pickMainAsset,
9
+ toLiquidatorWithdrawals
9
10
  } from "./helpers.js";
10
11
  class LiquidationsService extends SDKConstruct {
11
12
  /**
@@ -103,6 +104,27 @@ class LiquidationsService extends SDKConstruct {
103
104
  }
104
105
  return { ...account, receivedAssets };
105
106
  }
107
+ /**
108
+ * {@inheritDoc ILiquidationsService.getLiquidatorWithdrawals}
109
+ **/
110
+ async getLiquidatorWithdrawals(props) {
111
+ if (props.networks && !props.networks.includes(this.sdk.networkType)) {
112
+ return [];
113
+ }
114
+ const compressor = this.sdk.withdrawalCompressor;
115
+ if (!compressor) {
116
+ return [];
117
+ }
118
+ await compressor.loadWithdrawableAssets();
119
+ const phantomTokens = new AddressSet(
120
+ compressor.getWithdrawableAssets().map((a) => a.withdrawalPhantomToken)
121
+ );
122
+ const current = await compressor.getExternalAccountCurrentWithdrawals(
123
+ props.liquidator,
124
+ ...phantomTokens.asArray()
125
+ );
126
+ return toLiquidatorWithdrawals(current, this.sdk.networkType);
127
+ }
106
128
  /**
107
129
  * Accounts of expired credit managers with outstanding debt are liquidatable
108
130
  * regardless of their health factor.
@@ -35,6 +35,32 @@ class MultichainLiquidationsService {
35
35
  async getLiquidationDetails(props) {
36
36
  return this.#sdk.chain(props.network).liquidations.getLiquidationDetails(props);
37
37
  }
38
+ /**
39
+ * {@inheritDoc ILiquidationsService.getLiquidatorWithdrawals}
40
+ **/
41
+ async getLiquidatorWithdrawals(props) {
42
+ const chains = [...this.#sdk.chains.entries()].filter(
43
+ ([network]) => !props.networks || props.networks.includes(network)
44
+ );
45
+ const results = await Promise.allSettled(
46
+ chains.map(
47
+ ([, chainSdk]) => chainSdk.liquidations.getLiquidatorWithdrawals(props)
48
+ )
49
+ );
50
+ const withdrawals = [];
51
+ results.forEach((result, i) => {
52
+ const [network, chainSdk] = chains[i];
53
+ if (result.status === "fulfilled") {
54
+ withdrawals.push(...result.value);
55
+ } else {
56
+ chainSdk.logger?.warn(
57
+ result.reason,
58
+ `failed to get liquidator withdrawals on ${network}`
59
+ );
60
+ }
61
+ });
62
+ return withdrawals;
63
+ }
38
64
  }
39
65
  export {
40
66
  MultichainLiquidationsService
@@ -28,9 +28,35 @@ function pickMainAsset(ca, convert) {
28
28
  }
29
29
  return bestToken;
30
30
  }
31
+ function toLiquidatorWithdrawals(current, network) {
32
+ const rows = [];
33
+ for (const w of current.claimable) {
34
+ for (const o of w.outputs) {
35
+ rows.push({
36
+ network,
37
+ sourceToken: w.token,
38
+ token: o.token,
39
+ amount: o.amount
40
+ });
41
+ }
42
+ }
43
+ for (const w of current.pending) {
44
+ for (const o of w.expectedOutputs) {
45
+ rows.push({
46
+ network,
47
+ sourceToken: w.token,
48
+ token: o.token,
49
+ amount: o.amount,
50
+ claimableAt: w.claimableAt
51
+ });
52
+ }
53
+ }
54
+ return rows;
55
+ }
31
56
  export {
32
57
  DUST_THRESHOLD,
33
58
  calcEstimatedProfit,
34
59
  calcRepaymentAmount,
35
- pickMainAsset
60
+ pickMainAsset,
61
+ toLiquidatorWithdrawals
36
62
  };
@@ -1,5 +1,5 @@
1
1
  import { SDKConstruct } from "../../base/index.js";
2
- import type { GetLiquidatableAccountsProps, GetLiquidationDetailsProps, ILiquidationsService, LiquidatableAccount, LiquidationDetails } from "./types.js";
2
+ import type { GetLiquidatableAccountsProps, GetLiquidationDetailsProps, GetLiquidatorWithdrawalsProps, ILiquidationsService, LiquidatableAccount, LiquidationDetails, LiquidatorWithdrawal } from "./types.js";
3
3
  /**
4
4
  * Per-chain implementation of {@link ILiquidationsService}.
5
5
  *
@@ -17,4 +17,8 @@ export declare class LiquidationsService extends SDKConstruct implements ILiquid
17
17
  * {@inheritDoc ILiquidationsService.getLiquidationDetails}
18
18
  **/
19
19
  getLiquidationDetails(props: GetLiquidationDetailsProps): Promise<LiquidationDetails>;
20
+ /**
21
+ * {@inheritDoc ILiquidationsService.getLiquidatorWithdrawals}
22
+ **/
23
+ getLiquidatorWithdrawals(props: GetLiquidatorWithdrawalsProps): Promise<LiquidatorWithdrawal[]>;
20
24
  }
@@ -1,6 +1,6 @@
1
1
  import type { MultichainSDK } from "../../MultichainSDK.js";
2
2
  import type { PluginsMap } from "../../plugins/index.js";
3
- import type { GetLiquidatableAccountsProps, GetLiquidationDetailsProps, ILiquidationsService, LiquidatableAccount, LiquidationDetails } from "./types.js";
3
+ import type { GetLiquidatableAccountsProps, GetLiquidationDetailsProps, GetLiquidatorWithdrawalsProps, ILiquidationsService, LiquidatableAccount, LiquidationDetails, LiquidatorWithdrawal } from "./types.js";
4
4
  /**
5
5
  * Cross-chain implementation of {@link ILiquidationsService}.
6
6
  *
@@ -20,4 +20,8 @@ export declare class MultichainLiquidationsService<const Plugins extends Plugins
20
20
  * {@inheritDoc ILiquidationsService.getLiquidationDetails}
21
21
  **/
22
22
  getLiquidationDetails(props: GetLiquidationDetailsProps): Promise<LiquidationDetails>;
23
+ /**
24
+ * {@inheritDoc ILiquidationsService.getLiquidatorWithdrawals}
25
+ **/
26
+ getLiquidatorWithdrawals(props: GetLiquidatorWithdrawalsProps): Promise<LiquidatorWithdrawal[]>;
23
27
  }
@@ -1,5 +1,8 @@
1
1
  import type { Address } from "viem";
2
2
  import type { CreditAccountData } from "../../base/index.js";
3
+ import type { NetworkType } from "../../chain/index.js";
4
+ import type { CurrentWithdrawals } from "../withdrawal-compressor/index.js";
5
+ import type { LiquidatorWithdrawal } from "./types.js";
3
6
  /**
4
7
  * Token balances at or below this threshold are treated as dust and ignored,
5
8
  * consistent with the rest of the SDK (see `filterDust`).
@@ -32,3 +35,12 @@ export declare function calcEstimatedProfit(totalValue: bigint, liquidationDisco
32
35
  * must return `0n` when the price is unavailable
33
36
  **/
34
37
  export declare function pickMainAsset(ca: CreditAccountData, convert: (token: Address, balance: bigint) => bigint): Address | undefined;
38
+ /**
39
+ * Flattens delayed withdrawals of a liquidator into per-output rows:
40
+ * claimable outputs have no `claimableAt` (claimable now), pending outputs
41
+ * carry the estimated claim timestamp.
42
+ *
43
+ * @param current - Claimable and pending withdrawals from the withdrawal compressor
44
+ * @param network - Network the withdrawals live on
45
+ **/
46
+ export declare function toLiquidatorWithdrawals(current: CurrentWithdrawals, network: NetworkType): LiquidatorWithdrawal[];
@@ -135,6 +135,53 @@ export interface DelayedReceivedAsset {
135
135
  * A single asset the liquidator receives when fully liquidating an account.
136
136
  **/
137
137
  export type ReceivedAsset = InstantReceivedAsset | DelayedReceivedAsset;
138
+ /**
139
+ * Props for {@link ILiquidationsService.getLiquidatorWithdrawals}.
140
+ **/
141
+ export interface GetLiquidatorWithdrawalsProps {
142
+ /**
143
+ * Networks to query. On {@link MultichainLiquidationsService} selects which
144
+ * chains to query; a single-chain service returns an empty list when its
145
+ * own network is excluded.
146
+ **/
147
+ networks?: NetworkType[];
148
+ /**
149
+ * Liquidator wallet that owns the redemption receipts (redeemer contracts
150
+ * received as a result of liquidations).
151
+ **/
152
+ liquidator: Address;
153
+ }
154
+ /**
155
+ * A single delayed-withdrawal position owned by the liquidator.
156
+ *
157
+ * The redeemer contract address is not included: it is not part of the
158
+ * on-chain withdrawal structs returned by the withdrawal compressor. It can
159
+ * be surfaced later if the compressor structs are extended.
160
+ **/
161
+ export interface LiquidatorWithdrawal {
162
+ /**
163
+ * Network the withdrawal lives on.
164
+ **/
165
+ network: NetworkType;
166
+ /**
167
+ * Source asset spent by the delayed withdrawal (e.g. ACRED).
168
+ **/
169
+ sourceToken: Address;
170
+ /**
171
+ * Receivable asset (e.g. USDC).
172
+ **/
173
+ token: Address;
174
+ /**
175
+ * Amount of `token` receivable: exact for claimable withdrawals, estimated
176
+ * for pending ones.
177
+ **/
178
+ amount: bigint;
179
+ /**
180
+ * Estimated unix timestamp (in seconds) when a pending withdrawal becomes
181
+ * claimable. `undefined` means the withdrawal is claimable now.
182
+ **/
183
+ claimableAt?: bigint;
184
+ }
138
185
  /**
139
186
  * Detailed information about a liquidatable credit account, extending the
140
187
  * list row with the full breakdown of assets the liquidator receives.
@@ -169,4 +216,12 @@ export interface ILiquidationsService {
169
216
  * @throws When the account is not found or its collateral computation fails.
170
217
  **/
171
218
  getLiquidationDetails(props: GetLiquidationDetailsProps): Promise<LiquidationDetails>;
219
+ /**
220
+ * Returns the status of delayed-withdrawal positions (redemption receipts)
221
+ * owned by a liquidator wallet: what is receivable, how much, and when it
222
+ * becomes claimable.
223
+ *
224
+ * @param props - See {@link GetLiquidatorWithdrawalsProps}
225
+ **/
226
+ getLiquidatorWithdrawals(props: GetLiquidatorWithdrawalsProps): Promise<LiquidatorWithdrawal[]>;
172
227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.12.0-next.40",
3
+ "version": "14.12.0-next.41",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {