@gearbox-protocol/sdk 14.12.0-next.33 → 14.12.0-next.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/cjs/abi/IWithdrawalCompressorV313.js +136 -0
  2. package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +24 -33
  3. package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +39 -3
  4. package/dist/cjs/preview/prerequisites/checkPrerequisites.js +2 -1
  5. package/dist/cjs/preview/preview/buildDelayedPreview.js +6 -5
  6. package/dist/cjs/preview/preview/previewOperation.js +4 -1
  7. package/dist/cjs/sdk/MultichainSDK.js +7 -0
  8. package/dist/cjs/sdk/OnchainSDK.js +14 -4
  9. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +16 -3
  10. package/dist/cjs/sdk/accounts/index.js +2 -0
  11. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +207 -0
  12. package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +65 -0
  13. package/dist/cjs/sdk/accounts/liquidations/helpers.js +63 -0
  14. package/dist/cjs/sdk/accounts/liquidations/index.js +28 -0
  15. package/dist/cjs/sdk/accounts/liquidations/types.js +16 -0
  16. package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +142 -74
  17. package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +97 -0
  18. package/dist/cjs/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.js +1 -7
  19. package/dist/cjs/sdk/accounts/withdrawal-compressor/types.js +20 -0
  20. package/dist/esm/abi/IWithdrawalCompressorV313.js +136 -0
  21. package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +24 -33
  22. package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +43 -4
  23. package/dist/esm/preview/prerequisites/checkPrerequisites.js +2 -1
  24. package/dist/esm/preview/preview/buildDelayedPreview.js +6 -5
  25. package/dist/esm/preview/preview/previewOperation.js +4 -1
  26. package/dist/esm/sdk/MultichainSDK.js +7 -0
  27. package/dist/esm/sdk/OnchainSDK.js +16 -5
  28. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +16 -3
  29. package/dist/esm/sdk/accounts/index.js +1 -0
  30. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +188 -0
  31. package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +41 -0
  32. package/dist/esm/sdk/accounts/liquidations/helpers.js +36 -0
  33. package/dist/esm/sdk/accounts/liquidations/index.js +4 -0
  34. package/dist/esm/sdk/accounts/liquidations/types.js +0 -0
  35. package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +138 -74
  36. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +104 -1
  37. package/dist/esm/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.js +1 -7
  38. package/dist/esm/sdk/accounts/withdrawal-compressor/types.js +12 -0
  39. package/dist/types/abi/IWithdrawalCompressorV313.d.ts +200 -0
  40. package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +7 -7
  41. package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +1 -0
  42. package/dist/types/preview/prerequisites/types.d.ts +10 -2
  43. package/dist/types/preview/preview/buildDelayedPreview.d.ts +7 -2
  44. package/dist/types/sdk/MultichainSDK.d.ts +6 -0
  45. package/dist/types/sdk/OnchainSDK.d.ts +8 -5
  46. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  47. package/dist/types/sdk/accounts/index.d.ts +1 -0
  48. package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +20 -0
  49. package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +23 -0
  50. package/dist/types/sdk/accounts/liquidations/helpers.d.ts +34 -0
  51. package/dist/types/sdk/accounts/liquidations/index.d.ts +4 -0
  52. package/dist/types/sdk/accounts/liquidations/types.d.ts +172 -0
  53. package/dist/types/sdk/accounts/types.d.ts +6 -0
  54. package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +80 -6
  55. package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.d.ts +222 -0
  56. package/dist/types/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.d.ts +5 -4
  57. package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +106 -7
  58. package/dist/types/sdk/types/state.d.ts +8 -0
  59. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import { isAddressEqual } from "viem";
2
2
  import { BaseContract } from "../../base/index.js";
3
- import { decodeDelayedIntent, encodeDelayedIntent } from "./intent-codec.js";
3
+ import { AddressMap } from "../../utils/index.js";
4
+ import { decodeDelayedIntent } from "./intent-codec.js";
4
5
  const iCreditAccountAbi = [
5
6
  {
6
7
  type: "function",
@@ -10,12 +11,23 @@ const iCreditAccountAbi = [
10
11
  stateMutability: "view"
11
12
  }
12
13
  ];
14
+ const MAP_LABEL = "withdrawableAssets";
13
15
  class AbstractWithdrawalCompressorContract extends BaseContract {
14
16
  #sdk;
17
+ #withdrawableAssets;
15
18
  constructor(sdk, args) {
16
19
  super(sdk, args);
17
20
  this.#sdk = sdk;
18
21
  }
22
+ /**
23
+ * {@inheritDoc IWithdrawalCompressorContract.hydrate}
24
+ **/
25
+ hydrate(state) {
26
+ this.#withdrawableAssets = new AddressMap(
27
+ Object.entries(state.withdrawableAssets),
28
+ MAP_LABEL
29
+ );
30
+ }
19
31
  /**
20
32
  * The contract is instantiated with the actual versioned ABI,
21
33
  * this cast is type-level only (see {@link CommonAbi}).
@@ -23,18 +35,35 @@ class AbstractWithdrawalCompressorContract extends BaseContract {
23
35
  get common() {
24
36
  return this.contract;
25
37
  }
38
+ /**
39
+ * {@inheritDoc IWithdrawalCompressorContract.state}
40
+ **/
41
+ get state() {
42
+ return this.#withdrawableAssets ? { withdrawableAssets: this.#withdrawableAssets.asRecord() } : void 0;
43
+ }
26
44
  /**
27
45
  * {@inheritDoc IWithdrawalCompressorContract.getWithdrawableAssets}
28
46
  **/
29
- async getWithdrawableAssets(creditManager) {
30
- const resp = await this.common.read.getWithdrawableAssets([creditManager]);
31
- return resp.map((a) => toWithdrawableAsset(a, creditManager));
47
+ getWithdrawableAssets(...creditManagers) {
48
+ const cache = this.#withdrawableAssets;
49
+ if (!cache) {
50
+ throw new Error(
51
+ "withdrawable assets are not loaded, call loadWithdrawableAssets first"
52
+ );
53
+ }
54
+ if (creditManagers.length === 0) {
55
+ return cache.values().flat();
56
+ }
57
+ return creditManagers.flatMap((cm) => cache.get(cm) ?? []);
32
58
  }
33
59
  /**
34
- * {@inheritDoc IWithdrawalCompressorContract.getWithdrawableAssetsBatch}
60
+ * {@inheritDoc IWithdrawalCompressorContract.loadWithdrawableAssets}
35
61
  **/
36
- async getWithdrawableAssetsBatch(creditManagers) {
37
- const cms = creditManagers ?? this.#sdk.marketRegister.creditManagers.map(
62
+ async loadWithdrawableAssets(force) {
63
+ if (this.#withdrawableAssets && !force) {
64
+ return this.getWithdrawableAssets();
65
+ }
66
+ const cms = this.#sdk.marketRegister.creditManagers.map(
38
67
  (cm) => cm.creditManager.address
39
68
  );
40
69
  const resp = await this.client.multicall({
@@ -49,22 +78,48 @@ class AbstractWithdrawalCompressorContract extends BaseContract {
49
78
  allowFailure: true,
50
79
  batchSize: 0
51
80
  });
52
- return resp.flatMap((r, i) => {
81
+ const cache = new AddressMap(void 0, MAP_LABEL);
82
+ for (let i = 0; i < resp.length; i++) {
83
+ const r = resp[i];
53
84
  if (r.status !== "success") {
54
85
  this.logger?.warn(
55
86
  `failed to get withdrawable assets of credit manager ${cms[i]}: ${r.error}`
56
87
  );
57
- return [];
88
+ continue;
58
89
  }
59
- return r.result.map((a) => toWithdrawableAsset(a, cms[i]));
60
- });
90
+ if (r.result.length > 0) {
91
+ cache.upsert(
92
+ cms[i],
93
+ r.result.map((a) => toWithdrawableAsset(a, cms[i]))
94
+ );
95
+ }
96
+ }
97
+ this.#withdrawableAssets = cache;
98
+ return this.getWithdrawableAssets();
99
+ }
100
+ /**
101
+ * {@inheritDoc IWithdrawalCompressorContract.findWithdrawableAssets}
102
+ **/
103
+ async findWithdrawableAssets(creditManager, token) {
104
+ await this.loadWithdrawableAssets();
105
+ return this.getWithdrawableAssets(creditManager).filter(
106
+ (a) => isAddressEqual(a.token, token)
107
+ );
108
+ }
109
+ /**
110
+ * {@inheritDoc IWithdrawalCompressorContract.findWithdrawableAssetsByPhantomToken}
111
+ **/
112
+ async findWithdrawableAssetsByPhantomToken(withdrawalPhantomToken) {
113
+ await this.loadWithdrawableAssets();
114
+ return this.getWithdrawableAssets().filter(
115
+ (a) => isAddressEqual(a.withdrawalPhantomToken, withdrawalPhantomToken)
116
+ );
61
117
  }
62
118
  /**
63
119
  * {@inheritDoc IWithdrawalCompressorContract.getWithdrawalPhantomToken}
64
120
  **/
65
121
  async getWithdrawalPhantomToken(creditManager, token) {
66
- const assets = await this.getWithdrawableAssets(creditManager);
67
- const asset = assets.find((a) => isAddressEqual(a.token, token));
122
+ const [asset] = await this.findWithdrawableAssets(creditManager, token);
68
123
  if (!asset) {
69
124
  throw new Error(
70
125
  `token ${token} is not withdrawable from credit manager ${creditManager}`
@@ -72,6 +127,14 @@ class AbstractWithdrawalCompressorContract extends BaseContract {
72
127
  }
73
128
  return asset.withdrawalPhantomToken;
74
129
  }
130
+ /**
131
+ * {@inheritDoc IWithdrawalCompressorContract.getWithdrawalSourceToken}
132
+ **/
133
+ getWithdrawalSourceToken(withdrawalPhantomToken) {
134
+ return this.getWithdrawableAssets().find(
135
+ (a) => isAddressEqual(a.withdrawalPhantomToken, withdrawalPhantomToken)
136
+ )?.token;
137
+ }
75
138
  /**
76
139
  * {@inheritDoc IWithdrawalCompressorContract.getCurrentWithdrawals}
77
140
  **/
@@ -94,83 +157,80 @@ class AbstractWithdrawalCompressorContract extends BaseContract {
94
157
  batchSize: 0
95
158
  });
96
159
  return {
97
- claimable: claimable.map(
98
- (w) => toClaimableWithdrawal(w, creditManager, this.version >= 313)
99
- ),
100
- pending: pending.map((w) => toPendingWithdrawal(w, creditManager, this.version >= 313)).sort((a, b) => a.claimableAt < b.claimableAt ? -1 : 1)
160
+ claimable: claimable.map((w) => toClaimableWithdrawal(w, creditManager)),
161
+ pending: pending.map((w) => toPendingWithdrawal(w, creditManager)).sort((a, b) => a.claimableAt < b.claimableAt ? -1 : 1)
101
162
  };
102
163
  }
164
+ /**
165
+ * {@inheritDoc IWithdrawalCompressorContract.getExternalAccountCurrentWithdrawals}
166
+ **/
167
+ async getExternalAccountCurrentWithdrawals(_withdrawalToken, _account) {
168
+ this.#reportUnsupported("external account withdrawals");
169
+ return { claimable: [], pending: [] };
170
+ }
171
+ /**
172
+ * {@inheritDoc IWithdrawalCompressorContract.getWithdrawalStatus}
173
+ **/
174
+ async getWithdrawalStatus(...redeemers) {
175
+ if (redeemers.length === 0) {
176
+ return [];
177
+ }
178
+ this.#reportUnsupported("withdrawal status");
179
+ return redeemers.map(() => "NULL");
180
+ }
103
181
  /**
104
182
  * {@inheritDoc IWithdrawalCompressorContract.getWithdrawalRequestResult}
183
+ *
184
+ * Legacy compressors only support the 3-arg overload: `intent` and
185
+ * `withdrawalPhantomToken` are reported as unsupported (in non-strict mode
186
+ * the request is previewed without them).
105
187
  **/
106
- async getWithdrawalRequestResult(creditAccount, token, amount, intent) {
107
- const resp = intent ? await this.#getWithdrawalRequestResultWithIntent(
108
- creditAccount,
109
- token,
110
- amount,
111
- intent
112
- ) : await this.common.read.getWithdrawalRequestResult([
188
+ async getWithdrawalRequestResult({
189
+ creditAccount,
190
+ token,
191
+ amount,
192
+ withdrawalPhantomToken,
193
+ intent
194
+ }) {
195
+ if (intent) {
196
+ this.#reportUnsupported("withdrawal intents");
197
+ } else if (withdrawalPhantomToken) {
198
+ this.#reportUnsupported("withdrawal config selection");
199
+ }
200
+ const resp = await this.common.read.getWithdrawalRequestResult([
113
201
  creditAccount,
114
202
  token,
115
203
  amount
116
204
  ]);
117
- return {
118
- token: resp.token,
119
- amountIn: resp.amountIn,
120
- outputs: [...resp.outputs],
121
- requestCalls: [...resp.requestCalls],
122
- claimableAt: resp.claimableAt
123
- };
205
+ return toRequestableWithdrawal(resp);
124
206
  }
125
207
  /**
126
- * Previews a delayed withdrawal request with an intent attached as
127
- * `extraData`. Only supported on v313+ compressors; on older versions,
128
- * throws if `sdk.strictContractTypes` is `true`, otherwise logs a warning
129
- * and previews the request without the intent.
130
- *
131
- * The contract overload accepting `extraData` also requires the withdrawal
132
- * phantom token, which is resolved here the same way the 3-arg overload
133
- * does it internally: via `getWithdrawableAssets` of the account's credit
134
- * manager.
208
+ * Reports that a feature is not supported by this compressor version:
209
+ * throws if `sdk.strictContractTypes` is `true`, otherwise logs a warning.
135
210
  **/
136
- async #getWithdrawalRequestResultWithIntent(creditAccount, token, amount, intent) {
137
- if (this.version < 313) {
138
- const message = `withdrawal intents are not supported by ${this.name} v${this.version}`;
139
- if (this.#sdk.strictContractTypes) {
140
- throw new Error(message);
141
- }
142
- this.logger?.warn(`${message}, requesting withdrawal without intent`);
143
- return this.common.read.getWithdrawalRequestResult([
144
- creditAccount,
145
- token,
146
- amount
147
- ]);
211
+ #reportUnsupported(feature) {
212
+ const message = `${feature} is not supported by ${this.name} v${this.version}`;
213
+ if (this.#sdk.strictContractTypes) {
214
+ throw new Error(message);
148
215
  }
149
- const extraData = encodeDelayedIntent(intent);
150
- const creditManager = await this.client.readContract({
151
- address: creditAccount,
152
- abi: iCreditAccountAbi,
153
- functionName: "creditManager"
154
- });
155
- const withdrawalPhantomToken = await this.getWithdrawalPhantomToken(
156
- creditManager,
157
- token
158
- );
159
- return this.common.read.getWithdrawalRequestResult([
160
- creditAccount,
161
- token,
162
- withdrawalPhantomToken,
163
- amount,
164
- extraData
165
- ]);
216
+ this.logger?.warn(message);
166
217
  }
167
218
  }
168
219
  function toWithdrawableAsset(a, creditManager) {
169
220
  return { creditManager, ...a };
170
221
  }
171
- function toClaimableWithdrawal(w, creditManager, decodeIntent) {
222
+ function toRequestableWithdrawal(resp) {
223
+ return {
224
+ token: resp.token,
225
+ amountIn: resp.amountIn,
226
+ outputs: [...resp.outputs],
227
+ requestCalls: [...resp.requestCalls],
228
+ claimableAt: resp.claimableAt
229
+ };
230
+ }
231
+ function toClaimableWithdrawal(w, creditManager) {
172
232
  let intent;
173
- if (decodeIntent && w.extraData && w.extraData !== "0x") {
233
+ if (creditManager && w.extraData && w.extraData !== "0x") {
174
234
  intent = { ...decodeDelayedIntent(w.extraData), creditManager };
175
235
  }
176
236
  return {
@@ -182,9 +242,9 @@ function toClaimableWithdrawal(w, creditManager, decodeIntent) {
182
242
  intent
183
243
  };
184
244
  }
185
- function toPendingWithdrawal(w, creditManager, decodeIntent) {
245
+ function toPendingWithdrawal(w, creditManager) {
186
246
  let intent;
187
- if (decodeIntent && w.extraData && w.extraData !== "0x") {
247
+ if (creditManager && w.extraData && w.extraData !== "0x") {
188
248
  intent = { ...decodeDelayedIntent(w.extraData), creditManager };
189
249
  }
190
250
  return {
@@ -196,5 +256,9 @@ function toPendingWithdrawal(w, creditManager, decodeIntent) {
196
256
  };
197
257
  }
198
258
  export {
199
- AbstractWithdrawalCompressorContract
259
+ AbstractWithdrawalCompressorContract,
260
+ iCreditAccountAbi,
261
+ toClaimableWithdrawal,
262
+ toPendingWithdrawal,
263
+ toRequestableWithdrawal
200
264
  };
@@ -1,6 +1,27 @@
1
1
  import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
2
- import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
+ import {
3
+ AbstractWithdrawalCompressorContract,
4
+ iCreditAccountAbi,
5
+ toClaimableWithdrawal,
6
+ toPendingWithdrawal,
7
+ toRequestableWithdrawal
8
+ } from "./AbstractWithdrawalCompressorContract.js";
9
+ import { encodeDelayedIntent } from "./intent-codec.js";
10
+ import { toWithdrawalStatus } from "./types.js";
3
11
  const abi = iWithdrawalCompressorV313Abi;
12
+ const iWithdrawalStatusBatchAbi = [
13
+ {
14
+ type: "function",
15
+ name: "getWithdrawalStatus",
16
+ inputs: [
17
+ { name: "redeemers", type: "address[]", internalType: "address[]" }
18
+ ],
19
+ outputs: [
20
+ { name: "", type: "uint8[]", internalType: "enum WithdrawalStatus[]" }
21
+ ],
22
+ stateMutability: "view"
23
+ }
24
+ ];
4
25
  class WithdrawalCompressorV313Contract extends AbstractWithdrawalCompressorContract {
5
26
  constructor(sdk, address) {
6
27
  super(sdk, {
@@ -10,6 +31,88 @@ class WithdrawalCompressorV313Contract extends AbstractWithdrawalCompressorContr
10
31
  version: 313
11
32
  });
12
33
  }
34
+ /**
35
+ * {@inheritDoc IWithdrawalCompressorContract.getExternalAccountCurrentWithdrawals}
36
+ **/
37
+ async getExternalAccountCurrentWithdrawals(withdrawalToken, account) {
38
+ const [claimable, pending] = await this.contract.read.getExternalAccountCurrentWithdrawals([
39
+ withdrawalToken,
40
+ account
41
+ ]);
42
+ return {
43
+ claimable: claimable.map((w) => toClaimableWithdrawal(w, void 0)),
44
+ pending: pending.map((w) => toPendingWithdrawal(w, void 0)).sort((a, b) => a.claimableAt < b.claimableAt ? -1 : 1)
45
+ };
46
+ }
47
+ /**
48
+ * {@inheritDoc IWithdrawalCompressorContract.getWithdrawalStatus}
49
+ **/
50
+ async getWithdrawalStatus(...redeemers) {
51
+ if (redeemers.length === 0) {
52
+ return [];
53
+ }
54
+ const resp = await this.client.readContract({
55
+ address: this.address,
56
+ abi: iWithdrawalStatusBatchAbi,
57
+ functionName: "getWithdrawalStatus",
58
+ args: [redeemers]
59
+ });
60
+ return resp.map((s) => toWithdrawalStatus(s));
61
+ }
62
+ /**
63
+ * {@inheritDoc IWithdrawalCompressorContract.getWithdrawalRequestResult}
64
+ *
65
+ * When an intent is provided, it is abi-encoded and attached to the request
66
+ * as `extraData`. The contract overload accepting `extraData` also requires
67
+ * the withdrawal phantom token; when not provided by the caller, it is
68
+ * resolved the same way the 3-arg overload does it internally: via the
69
+ * withdrawable assets of the account's credit manager.
70
+ **/
71
+ async getWithdrawalRequestResult({
72
+ creditAccount,
73
+ token,
74
+ amount,
75
+ withdrawalPhantomToken,
76
+ intent
77
+ }) {
78
+ let resp;
79
+ if (intent) {
80
+ const extraData = encodeDelayedIntent(intent);
81
+ let phantomToken = withdrawalPhantomToken;
82
+ if (!phantomToken) {
83
+ const creditManager = await this.client.readContract({
84
+ address: creditAccount,
85
+ abi: iCreditAccountAbi,
86
+ functionName: "creditManager"
87
+ });
88
+ phantomToken = await this.getWithdrawalPhantomToken(
89
+ creditManager,
90
+ token
91
+ );
92
+ }
93
+ resp = await this.contract.read.getWithdrawalRequestResult([
94
+ creditAccount,
95
+ token,
96
+ phantomToken,
97
+ amount,
98
+ extraData
99
+ ]);
100
+ } else if (withdrawalPhantomToken) {
101
+ resp = await this.contract.read.getWithdrawalRequestResult([
102
+ creditAccount,
103
+ token,
104
+ withdrawalPhantomToken,
105
+ amount
106
+ ]);
107
+ } else {
108
+ resp = await this.contract.read.getWithdrawalRequestResult([
109
+ creditAccount,
110
+ token,
111
+ amount
112
+ ]);
113
+ }
114
+ return toRequestableWithdrawal(resp);
115
+ }
13
116
  }
14
117
  export {
15
118
  WithdrawalCompressorV313Contract
@@ -5,13 +5,7 @@ import { WithdrawalCompressorV313Contract } from "./WithdrawalCompressorV313Cont
5
5
  function createWithdrawalCompressor(sdk) {
6
6
  const location = getWithdrawalCompressorAddress(sdk.networkType);
7
7
  if (!location) {
8
- throw new Error(`no withdrawal compressor on ${sdk.networkType}`);
9
- }
10
- const cached = sdk.getContract(
11
- location.address
12
- );
13
- if (cached) {
14
- return cached;
8
+ return void 0;
15
9
  }
16
10
  switch (location.version) {
17
11
  case 310:
@@ -0,0 +1,12 @@
1
+ const WITHDRAWAL_STATUSES = [
2
+ "NULL",
3
+ "PENDING",
4
+ "CLAIMABLE",
5
+ "CLAIMED"
6
+ ];
7
+ function toWithdrawalStatus(status) {
8
+ return WITHDRAWAL_STATUSES[status] ?? "NULL";
9
+ }
10
+ export {
11
+ toWithdrawalStatus
12
+ };
@@ -107,6 +107,137 @@ export declare const iWithdrawalCompressorV313Abi: readonly [{
107
107
  }];
108
108
  }];
109
109
  readonly stateMutability: "view";
110
+ }, {
111
+ readonly type: "function";
112
+ readonly name: "getExternalAccountCurrentWithdrawals";
113
+ readonly inputs: readonly [{
114
+ readonly name: "withdrawalToken";
115
+ readonly type: "address";
116
+ readonly internalType: "address";
117
+ }, {
118
+ readonly name: "account";
119
+ readonly type: "address";
120
+ readonly internalType: "address";
121
+ }];
122
+ readonly outputs: readonly [{
123
+ readonly name: "";
124
+ readonly type: "tuple[]";
125
+ readonly internalType: "struct ClaimableWithdrawal[]";
126
+ readonly components: readonly [{
127
+ readonly name: "token";
128
+ readonly type: "address";
129
+ readonly internalType: "address";
130
+ }, {
131
+ readonly name: "withdrawalPhantomToken";
132
+ readonly type: "address";
133
+ readonly internalType: "address";
134
+ }, {
135
+ readonly name: "withdrawalTokenSpent";
136
+ readonly type: "uint256";
137
+ readonly internalType: "uint256";
138
+ }, {
139
+ readonly name: "outputs";
140
+ readonly type: "tuple[]";
141
+ readonly internalType: "struct WithdrawalOutput[]";
142
+ readonly components: readonly [{
143
+ readonly name: "token";
144
+ readonly type: "address";
145
+ readonly internalType: "address";
146
+ }, {
147
+ readonly name: "isDelayed";
148
+ readonly type: "bool";
149
+ readonly internalType: "bool";
150
+ }, {
151
+ readonly name: "amount";
152
+ readonly type: "uint256";
153
+ readonly internalType: "uint256";
154
+ }];
155
+ }, {
156
+ readonly name: "claimCalls";
157
+ readonly type: "tuple[]";
158
+ readonly internalType: "struct MultiCall[]";
159
+ readonly components: readonly [{
160
+ readonly name: "target";
161
+ readonly type: "address";
162
+ readonly internalType: "address";
163
+ }, {
164
+ readonly name: "callData";
165
+ readonly type: "bytes";
166
+ readonly internalType: "bytes";
167
+ }];
168
+ }, {
169
+ readonly name: "extraData";
170
+ readonly type: "bytes";
171
+ readonly internalType: "bytes";
172
+ }];
173
+ }, {
174
+ readonly name: "";
175
+ readonly type: "tuple[]";
176
+ readonly internalType: "struct PendingWithdrawal[]";
177
+ readonly components: readonly [{
178
+ readonly name: "token";
179
+ readonly type: "address";
180
+ readonly internalType: "address";
181
+ }, {
182
+ readonly name: "withdrawalPhantomToken";
183
+ readonly type: "address";
184
+ readonly internalType: "address";
185
+ }, {
186
+ readonly name: "expectedOutputs";
187
+ readonly type: "tuple[]";
188
+ readonly internalType: "struct WithdrawalOutput[]";
189
+ readonly components: readonly [{
190
+ readonly name: "token";
191
+ readonly type: "address";
192
+ readonly internalType: "address";
193
+ }, {
194
+ readonly name: "isDelayed";
195
+ readonly type: "bool";
196
+ readonly internalType: "bool";
197
+ }, {
198
+ readonly name: "amount";
199
+ readonly type: "uint256";
200
+ readonly internalType: "uint256";
201
+ }];
202
+ }, {
203
+ readonly name: "claimableAt";
204
+ readonly type: "uint256";
205
+ readonly internalType: "uint256";
206
+ }, {
207
+ readonly name: "extraData";
208
+ readonly type: "bytes";
209
+ readonly internalType: "bytes";
210
+ }];
211
+ }];
212
+ readonly stateMutability: "view";
213
+ }, {
214
+ readonly type: "function";
215
+ readonly name: "getWithdrawalStatus";
216
+ readonly inputs: readonly [{
217
+ readonly name: "redeemer";
218
+ readonly type: "address";
219
+ readonly internalType: "address";
220
+ }];
221
+ readonly outputs: readonly [{
222
+ readonly name: "";
223
+ readonly type: "uint8";
224
+ readonly internalType: "enum WithdrawalStatus";
225
+ }];
226
+ readonly stateMutability: "view";
227
+ }, {
228
+ readonly type: "function";
229
+ readonly name: "getWithdrawalStatus";
230
+ readonly inputs: readonly [{
231
+ readonly name: "redeemers";
232
+ readonly type: "address[]";
233
+ readonly internalType: "address[]";
234
+ }];
235
+ readonly outputs: readonly [{
236
+ readonly name: "";
237
+ readonly type: "uint8[]";
238
+ readonly internalType: "enum WithdrawalStatus[]";
239
+ }];
240
+ readonly stateMutability: "view";
110
241
  }, {
111
242
  readonly type: "function";
112
243
  readonly name: "getWithdrawableAssets";
@@ -215,6 +346,75 @@ export declare const iWithdrawalCompressorV313Abi: readonly [{
215
346
  }];
216
347
  }];
217
348
  readonly stateMutability: "view";
349
+ }, {
350
+ readonly type: "function";
351
+ readonly name: "getWithdrawalRequestResult";
352
+ readonly inputs: readonly [{
353
+ readonly name: "creditAccount";
354
+ readonly type: "address";
355
+ readonly internalType: "address";
356
+ }, {
357
+ readonly name: "token";
358
+ readonly type: "address";
359
+ readonly internalType: "address";
360
+ }, {
361
+ readonly name: "withdrawalToken";
362
+ readonly type: "address";
363
+ readonly internalType: "address";
364
+ }, {
365
+ readonly name: "amount";
366
+ readonly type: "uint256";
367
+ readonly internalType: "uint256";
368
+ }];
369
+ readonly outputs: readonly [{
370
+ readonly name: "";
371
+ readonly type: "tuple";
372
+ readonly internalType: "struct RequestableWithdrawal";
373
+ readonly components: readonly [{
374
+ readonly name: "token";
375
+ readonly type: "address";
376
+ readonly internalType: "address";
377
+ }, {
378
+ readonly name: "amountIn";
379
+ readonly type: "uint256";
380
+ readonly internalType: "uint256";
381
+ }, {
382
+ readonly name: "outputs";
383
+ readonly type: "tuple[]";
384
+ readonly internalType: "struct WithdrawalOutput[]";
385
+ readonly components: readonly [{
386
+ readonly name: "token";
387
+ readonly type: "address";
388
+ readonly internalType: "address";
389
+ }, {
390
+ readonly name: "isDelayed";
391
+ readonly type: "bool";
392
+ readonly internalType: "bool";
393
+ }, {
394
+ readonly name: "amount";
395
+ readonly type: "uint256";
396
+ readonly internalType: "uint256";
397
+ }];
398
+ }, {
399
+ readonly name: "requestCalls";
400
+ readonly type: "tuple[]";
401
+ readonly internalType: "struct MultiCall[]";
402
+ readonly components: readonly [{
403
+ readonly name: "target";
404
+ readonly type: "address";
405
+ readonly internalType: "address";
406
+ }, {
407
+ readonly name: "callData";
408
+ readonly type: "bytes";
409
+ readonly internalType: "bytes";
410
+ }];
411
+ }, {
412
+ readonly name: "claimableAt";
413
+ readonly type: "uint256";
414
+ readonly internalType: "uint256";
415
+ }];
416
+ }];
417
+ readonly stateMutability: "view";
218
418
  }, {
219
419
  readonly type: "function";
220
420
  readonly name: "getWithdrawalRequestResult";
@@ -1,20 +1,20 @@
1
- import type { Address } from "viem";
2
1
  import type { IOnchainSDKPlugin } from "../../sdk/index.js";
3
2
  import { AddressMap, BasePlugin } from "../../sdk/index.js";
4
3
  import type { WithdrawableAsset, WithdrawableAssetStateHuman } from "./types.js";
5
- export interface DelayedWithdrawalPluginState {
6
- withdrawableAssets: Record<Address, Array<WithdrawableAsset>>;
7
- }
4
+ /**
5
+ * The plugin holds no state of its own: withdrawable assets are cached
6
+ * (and serialized/hydrated) by the withdrawal compressor contract in the
7
+ * core SDK state (`GearboxState.withdrawals`).
8
+ **/
9
+ export type DelayedWithdrawalPluginState = Record<string, never>;
8
10
  export declare class DelayedWithdrawalPlugin extends BasePlugin<DelayedWithdrawalPluginState> implements IOnchainSDKPlugin<DelayedWithdrawalPluginState> {
9
- #private;
10
11
  load(force?: boolean): Promise<DelayedWithdrawalPluginState>;
11
12
  get loaded(): boolean;
12
13
  /**
13
14
  * Returns a map of cmAddress -> array of delayed assets
14
- * @throws if plugin is not attached
15
+ * @throws if withdrawable assets have not been loaded
15
16
  */
16
17
  get withdrawableAssets(): AddressMap<Array<WithdrawableAsset>>;
17
18
  stateHuman(_?: boolean): WithdrawableAssetStateHuman[];
18
19
  get state(): DelayedWithdrawalPluginState;
19
- hydrate(state: DelayedWithdrawalPluginState): void;
20
20
  }