@gearbox-protocol/sdk 14.12.0-next.34 → 14.12.0-next.36
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/abi/IWithdrawalCompressorV313.js +136 -0
- package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +24 -33
- package/dist/cjs/sdk/MultichainSDK.js +7 -0
- package/dist/cjs/sdk/OnchainSDK.js +14 -4
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +16 -3
- package/dist/cjs/sdk/accounts/index.js +2 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +207 -0
- package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +65 -0
- package/dist/cjs/sdk/accounts/liquidations/helpers.js +63 -0
- package/dist/cjs/sdk/accounts/liquidations/index.js +28 -0
- package/dist/cjs/sdk/accounts/liquidations/types.js +16 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +142 -74
- package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +97 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/addresses.js +1 -1
- package/dist/cjs/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.js +1 -7
- package/dist/cjs/sdk/accounts/withdrawal-compressor/types.js +20 -0
- package/dist/esm/abi/IWithdrawalCompressorV313.js +136 -0
- package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +24 -33
- package/dist/esm/sdk/MultichainSDK.js +7 -0
- package/dist/esm/sdk/OnchainSDK.js +16 -5
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +16 -3
- package/dist/esm/sdk/accounts/index.js +1 -0
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +188 -0
- package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +41 -0
- package/dist/esm/sdk/accounts/liquidations/helpers.js +36 -0
- package/dist/esm/sdk/accounts/liquidations/index.js +4 -0
- package/dist/esm/sdk/accounts/liquidations/types.js +0 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +138 -74
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +104 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/addresses.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.js +1 -7
- package/dist/esm/sdk/accounts/withdrawal-compressor/types.js +12 -0
- package/dist/types/abi/IWithdrawalCompressorV313.d.ts +200 -0
- package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +7 -7
- package/dist/types/sdk/MultichainSDK.d.ts +6 -0
- package/dist/types/sdk/OnchainSDK.d.ts +8 -5
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
- package/dist/types/sdk/accounts/index.d.ts +1 -0
- package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +20 -0
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +23 -0
- package/dist/types/sdk/accounts/liquidations/helpers.d.ts +34 -0
- package/dist/types/sdk/accounts/liquidations/index.d.ts +4 -0
- package/dist/types/sdk/accounts/liquidations/types.d.ts +172 -0
- package/dist/types/sdk/accounts/types.d.ts +6 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +80 -6
- package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.d.ts +222 -0
- package/dist/types/sdk/accounts/withdrawal-compressor/createWithdrawalCompressor.d.ts +5 -4
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +106 -7
- package/dist/types/sdk/types/state.d.ts +8 -0
- 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 {
|
|
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
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
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.
|
|
60
|
+
* {@inheritDoc IWithdrawalCompressorContract.loadWithdrawableAssets}
|
|
35
61
|
**/
|
|
36
|
-
async
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
88
|
+
continue;
|
|
58
89
|
}
|
|
59
|
-
|
|
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
|
|
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
|
-
|
|
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(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
*
|
|
127
|
-
*
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
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
|
|
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 (
|
|
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
|
|
245
|
+
function toPendingWithdrawal(w, creditManager) {
|
|
186
246
|
let intent;
|
|
187
|
-
if (
|
|
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 {
|
|
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
|
-
|
|
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:
|
|
@@ -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";
|