@instadapp/interop-x 0.0.0-dev.76d0265 → 0.0.0-dev.7738003
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/ci.yml +19 -0
- package/dist/package.json +1 -1
- package/dist/src/abi/index.js +2 -2
- package/dist/src/abi/interopX.json +1436 -0
- package/dist/src/api/index.js +1 -1
- package/dist/src/constants/addresses.js +2 -7
- package/dist/src/db/models/transaction.js +11 -9
- package/dist/src/gnosis/actions/withdraw/index.js +106 -107
- package/dist/src/index.js +1 -1
- package/dist/src/tasks/{InteropXContract/SyncBridgeRequestEvents.js → InteropX/SyncLogSubmitEvents.js} +18 -12
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +4 -2
- package/dist/src/tasks/index.js +4 -13
- package/dist/src/typechain/{InteropXContract.js → InteropX.js} +0 -0
- package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
- package/dist/src/typechain/factories/index.js +3 -3
- package/dist/src/typechain/index.js +3 -3
- package/dist/src/utils/index.js +5 -3
- package/package.json +1 -1
- package/src/abi/index.ts +2 -2
- package/src/abi/interopX.json +1436 -0
- package/src/api/index.ts +1 -1
- package/src/constants/addresses.ts +3 -8
- package/src/db/models/transaction.ts +28 -37
- package/src/gnosis/actions/withdraw/index.ts +131 -131
- package/src/tasks/{InteropXContract/SyncBridgeRequestEvents.ts → InteropX/SyncLogSubmitEvents.ts} +37 -16
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +4 -2
- package/src/tasks/index.ts +5 -17
- package/src/typechain/InteropX.ts +1216 -0
- package/src/typechain/factories/InteropX__factory.ts +1932 -0
- package/src/typechain/factories/index.ts +1 -1
- package/src/typechain/index.ts +2 -2
- package/src/utils/index.ts +22 -8
- package/dist/src/abi/interopXContract.json +0 -454
- package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +0 -159
- package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +0 -93
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +0 -90
- package/dist/src/typechain/factories/InteropXContract__factory.js +0 -635
- package/src/abi/interopXContract.json +0 -454
- package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +0 -227
- package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +0 -125
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +0 -121
- package/src/typechain/InteropXContract.ts +0 -680
- package/src/typechain/factories/InteropXContract__factory.ts +0 -642
package/src/typechain/index.ts
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
/* eslint-disable */
|
4
4
|
export type { Erc20 } from "./Erc20";
|
5
5
|
export type { GnosisSafe } from "./GnosisSafe";
|
6
|
-
export type {
|
6
|
+
export type { InteropX } from "./InteropX";
|
7
7
|
export * as factories from "./factories";
|
8
8
|
export { Erc20__factory } from "./factories/Erc20__factory";
|
9
9
|
export { GnosisSafe__factory } from "./factories/GnosisSafe__factory";
|
10
|
-
export {
|
10
|
+
export { InteropX__factory } from "./factories/InteropX__factory";
|
package/src/utils/index.ts
CHANGED
@@ -133,14 +133,28 @@ export const asyncCallWithTimeout = async <T>(asyncPromise: Promise<T>, timeout:
|
|
133
133
|
}
|
134
134
|
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
136
|
+
type GenerateInteropTransactionHashParam = {
|
137
|
+
actionId: string,
|
138
|
+
vnonce: string,
|
139
|
+
sourceSender: string,
|
140
|
+
sourceChainId: string | number,
|
141
|
+
sourceDsaId: string,
|
142
|
+
targetChainId: string | number,
|
143
|
+
targetDsaId: string,
|
144
|
+
};
|
145
|
+
|
146
|
+
export const generateInteropTransactionHash = (data: GenerateInteropTransactionHashParam) => {
|
147
|
+
return ethers.utils.solidityKeccak256(
|
148
|
+
Array.from({ length : 7 }, () => 'string'),
|
149
|
+
[
|
150
|
+
String(data.actionId),
|
151
|
+
String(data.vnonce),
|
152
|
+
String(data.sourceSender),
|
153
|
+
String(data.sourceChainId),
|
154
|
+
String(data.sourceDsaId),
|
155
|
+
String(data.targetChainId),
|
156
|
+
String(data.targetDsaId),
|
157
|
+
]);
|
144
158
|
}
|
145
159
|
|
146
160
|
|
@@ -1,454 +0,0 @@
|
|
1
|
-
[
|
2
|
-
{
|
3
|
-
"anonymous": false,
|
4
|
-
"inputs": [
|
5
|
-
{
|
6
|
-
"indexed": false,
|
7
|
-
"internalType": "string",
|
8
|
-
"name": "actionId",
|
9
|
-
"type": "string"
|
10
|
-
},
|
11
|
-
{
|
12
|
-
"indexed": true,
|
13
|
-
"internalType": "address",
|
14
|
-
"name": "bridger",
|
15
|
-
"type": "address"
|
16
|
-
},
|
17
|
-
{
|
18
|
-
"components": [
|
19
|
-
{
|
20
|
-
"components": [
|
21
|
-
{
|
22
|
-
"internalType": "address",
|
23
|
-
"name": "sourceToken",
|
24
|
-
"type": "address"
|
25
|
-
},
|
26
|
-
{
|
27
|
-
"internalType": "address",
|
28
|
-
"name": "targetToken",
|
29
|
-
"type": "address"
|
30
|
-
},
|
31
|
-
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
|
32
|
-
],
|
33
|
-
"internalType": "struct InteropXContractBeta.TokenInfo[]",
|
34
|
-
"name": "supply",
|
35
|
-
"type": "tuple[]"
|
36
|
-
},
|
37
|
-
{
|
38
|
-
"components": [
|
39
|
-
{
|
40
|
-
"internalType": "address",
|
41
|
-
"name": "sourceToken",
|
42
|
-
"type": "address"
|
43
|
-
},
|
44
|
-
{
|
45
|
-
"internalType": "address",
|
46
|
-
"name": "targetToken",
|
47
|
-
"type": "address"
|
48
|
-
},
|
49
|
-
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
|
50
|
-
],
|
51
|
-
"internalType": "struct InteropXContractBeta.TokenInfo[]",
|
52
|
-
"name": "withdraw",
|
53
|
-
"type": "tuple[]"
|
54
|
-
}
|
55
|
-
],
|
56
|
-
"indexed": false,
|
57
|
-
"internalType": "struct InteropXContractBeta.Position",
|
58
|
-
"name": "position",
|
59
|
-
"type": "tuple"
|
60
|
-
},
|
61
|
-
{
|
62
|
-
"indexed": true,
|
63
|
-
"internalType": "uint32",
|
64
|
-
"name": "sourceChainId",
|
65
|
-
"type": "uint32"
|
66
|
-
},
|
67
|
-
{
|
68
|
-
"indexed": false,
|
69
|
-
"internalType": "uint32",
|
70
|
-
"name": "targetChainId",
|
71
|
-
"type": "uint32"
|
72
|
-
},
|
73
|
-
{
|
74
|
-
"indexed": true,
|
75
|
-
"internalType": "bytes32",
|
76
|
-
"name": "requestTransactionHash",
|
77
|
-
"type": "bytes32"
|
78
|
-
},
|
79
|
-
{
|
80
|
-
"indexed": false,
|
81
|
-
"internalType": "bytes",
|
82
|
-
"name": "metadata",
|
83
|
-
"type": "bytes"
|
84
|
-
}
|
85
|
-
],
|
86
|
-
"name": "LogBridgeCommitted",
|
87
|
-
"type": "event"
|
88
|
-
},
|
89
|
-
{
|
90
|
-
"anonymous": false,
|
91
|
-
"inputs": [
|
92
|
-
{
|
93
|
-
"indexed": false,
|
94
|
-
"internalType": "string",
|
95
|
-
"name": "actionId",
|
96
|
-
"type": "string"
|
97
|
-
},
|
98
|
-
{
|
99
|
-
"indexed": true,
|
100
|
-
"internalType": "address",
|
101
|
-
"name": "bridger",
|
102
|
-
"type": "address"
|
103
|
-
},
|
104
|
-
{
|
105
|
-
"components": [
|
106
|
-
{
|
107
|
-
"components": [
|
108
|
-
{
|
109
|
-
"internalType": "address",
|
110
|
-
"name": "sourceToken",
|
111
|
-
"type": "address"
|
112
|
-
},
|
113
|
-
{
|
114
|
-
"internalType": "address",
|
115
|
-
"name": "targetToken",
|
116
|
-
"type": "address"
|
117
|
-
},
|
118
|
-
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
|
119
|
-
],
|
120
|
-
"internalType": "struct InteropXContractBeta.TokenInfo[]",
|
121
|
-
"name": "supply",
|
122
|
-
"type": "tuple[]"
|
123
|
-
},
|
124
|
-
{
|
125
|
-
"components": [
|
126
|
-
{
|
127
|
-
"internalType": "address",
|
128
|
-
"name": "sourceToken",
|
129
|
-
"type": "address"
|
130
|
-
},
|
131
|
-
{
|
132
|
-
"internalType": "address",
|
133
|
-
"name": "targetToken",
|
134
|
-
"type": "address"
|
135
|
-
},
|
136
|
-
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
|
137
|
-
],
|
138
|
-
"internalType": "struct InteropXContractBeta.TokenInfo[]",
|
139
|
-
"name": "withdraw",
|
140
|
-
"type": "tuple[]"
|
141
|
-
}
|
142
|
-
],
|
143
|
-
"indexed": false,
|
144
|
-
"internalType": "struct InteropXContractBeta.Position",
|
145
|
-
"name": "position",
|
146
|
-
"type": "tuple"
|
147
|
-
},
|
148
|
-
{
|
149
|
-
"indexed": false,
|
150
|
-
"internalType": "uint256",
|
151
|
-
"name": "sourceChainId",
|
152
|
-
"type": "uint256"
|
153
|
-
},
|
154
|
-
{
|
155
|
-
"indexed": true,
|
156
|
-
"internalType": "uint256",
|
157
|
-
"name": "targetChainId",
|
158
|
-
"type": "uint256"
|
159
|
-
},
|
160
|
-
{
|
161
|
-
"indexed": true,
|
162
|
-
"internalType": "bytes32",
|
163
|
-
"name": "requestTransactionHash",
|
164
|
-
"type": "bytes32"
|
165
|
-
},
|
166
|
-
{
|
167
|
-
"indexed": false,
|
168
|
-
"internalType": "bytes32",
|
169
|
-
"name": "targetCommittedTransactionHash",
|
170
|
-
"type": "bytes32"
|
171
|
-
},
|
172
|
-
{
|
173
|
-
"indexed": false,
|
174
|
-
"internalType": "bytes",
|
175
|
-
"name": "metadata",
|
176
|
-
"type": "bytes"
|
177
|
-
}
|
178
|
-
],
|
179
|
-
"name": "LogBridgeCompleted",
|
180
|
-
"type": "event"
|
181
|
-
},
|
182
|
-
{
|
183
|
-
"anonymous": false,
|
184
|
-
"inputs": [
|
185
|
-
{
|
186
|
-
"indexed": false,
|
187
|
-
"internalType": "string",
|
188
|
-
"name": "actionId",
|
189
|
-
"type": "string"
|
190
|
-
},
|
191
|
-
{
|
192
|
-
"indexed": true,
|
193
|
-
"internalType": "address",
|
194
|
-
"name": "bridger",
|
195
|
-
"type": "address"
|
196
|
-
},
|
197
|
-
{
|
198
|
-
"components": [
|
199
|
-
{
|
200
|
-
"components": [
|
201
|
-
{
|
202
|
-
"internalType": "address",
|
203
|
-
"name": "sourceToken",
|
204
|
-
"type": "address"
|
205
|
-
},
|
206
|
-
{
|
207
|
-
"internalType": "address",
|
208
|
-
"name": "targetToken",
|
209
|
-
"type": "address"
|
210
|
-
},
|
211
|
-
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
|
212
|
-
],
|
213
|
-
"internalType": "struct InteropXContractBeta.TokenInfo[]",
|
214
|
-
"name": "supply",
|
215
|
-
"type": "tuple[]"
|
216
|
-
},
|
217
|
-
{
|
218
|
-
"components": [
|
219
|
-
{
|
220
|
-
"internalType": "address",
|
221
|
-
"name": "sourceToken",
|
222
|
-
"type": "address"
|
223
|
-
},
|
224
|
-
{
|
225
|
-
"internalType": "address",
|
226
|
-
"name": "targetToken",
|
227
|
-
"type": "address"
|
228
|
-
},
|
229
|
-
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
|
230
|
-
],
|
231
|
-
"internalType": "struct InteropXContractBeta.TokenInfo[]",
|
232
|
-
"name": "withdraw",
|
233
|
-
"type": "tuple[]"
|
234
|
-
}
|
235
|
-
],
|
236
|
-
"indexed": false,
|
237
|
-
"internalType": "struct InteropXContractBeta.Position",
|
238
|
-
"name": "position",
|
239
|
-
"type": "tuple"
|
240
|
-
},
|
241
|
-
{
|
242
|
-
"indexed": false,
|
243
|
-
"internalType": "uint256",
|
244
|
-
"name": "sourceChainId",
|
245
|
-
"type": "uint256"
|
246
|
-
},
|
247
|
-
{
|
248
|
-
"indexed": true,
|
249
|
-
"internalType": "uint256",
|
250
|
-
"name": "targetChainId",
|
251
|
-
"type": "uint256"
|
252
|
-
},
|
253
|
-
{
|
254
|
-
"indexed": false,
|
255
|
-
"internalType": "bytes",
|
256
|
-
"name": "metadata",
|
257
|
-
"type": "bytes"
|
258
|
-
}
|
259
|
-
],
|
260
|
-
"name": "LogBridgeRequest",
|
261
|
-
"type": "event"
|
262
|
-
},
|
263
|
-
{
|
264
|
-
"anonymous": false,
|
265
|
-
"inputs": [
|
266
|
-
{
|
267
|
-
"indexed": false,
|
268
|
-
"internalType": "string",
|
269
|
-
"name": "actionId",
|
270
|
-
"type": "string"
|
271
|
-
},
|
272
|
-
{
|
273
|
-
"indexed": true,
|
274
|
-
"internalType": "address",
|
275
|
-
"name": "bridger",
|
276
|
-
"type": "address"
|
277
|
-
},
|
278
|
-
{
|
279
|
-
"components": [
|
280
|
-
{
|
281
|
-
"components": [
|
282
|
-
{
|
283
|
-
"internalType": "address",
|
284
|
-
"name": "sourceToken",
|
285
|
-
"type": "address"
|
286
|
-
},
|
287
|
-
{
|
288
|
-
"internalType": "address",
|
289
|
-
"name": "targetToken",
|
290
|
-
"type": "address"
|
291
|
-
},
|
292
|
-
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
|
293
|
-
],
|
294
|
-
"internalType": "struct InteropXContractBeta.TokenInfo[]",
|
295
|
-
"name": "supply",
|
296
|
-
"type": "tuple[]"
|
297
|
-
},
|
298
|
-
{
|
299
|
-
"components": [
|
300
|
-
{
|
301
|
-
"internalType": "address",
|
302
|
-
"name": "sourceToken",
|
303
|
-
"type": "address"
|
304
|
-
},
|
305
|
-
{
|
306
|
-
"internalType": "address",
|
307
|
-
"name": "targetToken",
|
308
|
-
"type": "address"
|
309
|
-
},
|
310
|
-
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
|
311
|
-
],
|
312
|
-
"internalType": "struct InteropXContractBeta.TokenInfo[]",
|
313
|
-
"name": "withdraw",
|
314
|
-
"type": "tuple[]"
|
315
|
-
}
|
316
|
-
],
|
317
|
-
"indexed": false,
|
318
|
-
"internalType": "struct InteropXContractBeta.Position",
|
319
|
-
"name": "position",
|
320
|
-
"type": "tuple"
|
321
|
-
},
|
322
|
-
{
|
323
|
-
"indexed": false,
|
324
|
-
"internalType": "uint32",
|
325
|
-
"name": "sourceChainId",
|
326
|
-
"type": "uint32"
|
327
|
-
},
|
328
|
-
{
|
329
|
-
"indexed": true,
|
330
|
-
"internalType": "uint32",
|
331
|
-
"name": "targetChainId",
|
332
|
-
"type": "uint32"
|
333
|
-
},
|
334
|
-
{
|
335
|
-
"indexed": true,
|
336
|
-
"internalType": "bytes32",
|
337
|
-
"name": "requestTransactionHash",
|
338
|
-
"type": "bytes32"
|
339
|
-
},
|
340
|
-
{
|
341
|
-
"indexed": false,
|
342
|
-
"internalType": "bytes",
|
343
|
-
"name": "metadata",
|
344
|
-
"type": "bytes"
|
345
|
-
}
|
346
|
-
],
|
347
|
-
"name": "LogBridgeRequestSent",
|
348
|
-
"type": "event"
|
349
|
-
},
|
350
|
-
{
|
351
|
-
"inputs": [
|
352
|
-
{ "internalType": "string", "name": "actionId", "type": "string" },
|
353
|
-
{ "internalType": "address", "name": "to_", "type": "address" },
|
354
|
-
{ "internalType": "address", "name": "sourceToken_", "type": "address" },
|
355
|
-
{ "internalType": "address", "name": "targetToken_", "type": "address" },
|
356
|
-
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
357
|
-
{ "internalType": "uint32", "name": "sourceChainId_", "type": "uint32" },
|
358
|
-
{
|
359
|
-
"internalType": "bytes32",
|
360
|
-
"name": "transactionHash_",
|
361
|
-
"type": "bytes32"
|
362
|
-
},
|
363
|
-
{ "internalType": "bytes", "name": "metadata_", "type": "bytes" }
|
364
|
-
],
|
365
|
-
"name": "completeBridge",
|
366
|
-
"outputs": [],
|
367
|
-
"stateMutability": "nonpayable",
|
368
|
-
"type": "function"
|
369
|
-
},
|
370
|
-
{
|
371
|
-
"inputs": [
|
372
|
-
{ "internalType": "address", "name": "user", "type": "address" },
|
373
|
-
{ "internalType": "address[]", "name": "tokens", "type": "address[]" }
|
374
|
-
],
|
375
|
-
"name": "getBridgeAmounts",
|
376
|
-
"outputs": [
|
377
|
-
{
|
378
|
-
"components": [
|
379
|
-
{ "internalType": "uint256", "name": "deposit", "type": "uint256" },
|
380
|
-
{ "internalType": "uint256", "name": "withdraw", "type": "uint256" }
|
381
|
-
],
|
382
|
-
"internalType": "struct InteropXContractBeta.UserData[]",
|
383
|
-
"name": "userData",
|
384
|
-
"type": "tuple[]"
|
385
|
-
}
|
386
|
-
],
|
387
|
-
"stateMutability": "view",
|
388
|
-
"type": "function"
|
389
|
-
},
|
390
|
-
{
|
391
|
-
"inputs": [
|
392
|
-
{ "internalType": "string", "name": "actionId", "type": "string" },
|
393
|
-
{ "internalType": "address", "name": "sourceToken_", "type": "address" },
|
394
|
-
{ "internalType": "address", "name": "targetToken_", "type": "address" },
|
395
|
-
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
396
|
-
{ "internalType": "uint32", "name": "targetChainId_", "type": "uint32" },
|
397
|
-
{ "internalType": "bytes", "name": "metadata_", "type": "bytes" }
|
398
|
-
],
|
399
|
-
"name": "requestWithdraw",
|
400
|
-
"outputs": [],
|
401
|
-
"stateMutability": "nonpayable",
|
402
|
-
"type": "function"
|
403
|
-
},
|
404
|
-
{
|
405
|
-
"inputs": [
|
406
|
-
{ "internalType": "address", "name": "token", "type": "address" },
|
407
|
-
{ "internalType": "bool", "name": "toggle", "type": "bool" }
|
408
|
-
],
|
409
|
-
"name": "toggleWhitelist",
|
410
|
-
"outputs": [],
|
411
|
-
"stateMutability": "nonpayable",
|
412
|
-
"type": "function"
|
413
|
-
},
|
414
|
-
{
|
415
|
-
"inputs": [
|
416
|
-
{ "internalType": "address", "name": "", "type": "address" },
|
417
|
-
{ "internalType": "address", "name": "", "type": "address" }
|
418
|
-
],
|
419
|
-
"name": "userMapping",
|
420
|
-
"outputs": [
|
421
|
-
{ "internalType": "uint256", "name": "deposit", "type": "uint256" },
|
422
|
-
{ "internalType": "uint256", "name": "withdraw", "type": "uint256" }
|
423
|
-
],
|
424
|
-
"stateMutability": "view",
|
425
|
-
"type": "function"
|
426
|
-
},
|
427
|
-
{
|
428
|
-
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
429
|
-
"name": "whitelistedTokens",
|
430
|
-
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
|
431
|
-
"stateMutability": "view",
|
432
|
-
"type": "function"
|
433
|
-
},
|
434
|
-
{
|
435
|
-
"inputs": [
|
436
|
-
{ "internalType": "string", "name": "actionId", "type": "string" },
|
437
|
-
{ "internalType": "address", "name": "user_", "type": "address" },
|
438
|
-
{ "internalType": "address", "name": "sourceToken_", "type": "address" },
|
439
|
-
{ "internalType": "address", "name": "targetToken_", "type": "address" },
|
440
|
-
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
441
|
-
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" },
|
442
|
-
{
|
443
|
-
"internalType": "bytes32",
|
444
|
-
"name": "transactionHash_",
|
445
|
-
"type": "bytes32"
|
446
|
-
},
|
447
|
-
{ "internalType": "bytes", "name": "metadata_", "type": "bytes" }
|
448
|
-
],
|
449
|
-
"name": "withdrawRequested",
|
450
|
-
"outputs": [],
|
451
|
-
"stateMutability": "nonpayable",
|
452
|
-
"type": "function"
|
453
|
-
}
|
454
|
-
]
|
@@ -1,159 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const BaseTask_1 = require("../BaseTask");
|
7
|
-
const logger_1 = __importDefault(require("@/logger"));
|
8
|
-
const ethers_1 = require("ethers");
|
9
|
-
const abi_1 = __importDefault(require("@/abi"));
|
10
|
-
const db_1 = require("@/db");
|
11
|
-
const utils_1 = require("@/utils");
|
12
|
-
const constants_1 = require("@/constants");
|
13
|
-
const sequelize_1 = require("sequelize");
|
14
|
-
const config_1 = __importDefault(require("@/config"));
|
15
|
-
const waait_1 = __importDefault(require("waait"));
|
16
|
-
const gnosis_1 = require("@/gnosis");
|
17
|
-
const net_1 = require("@/net");
|
18
|
-
class ProccessBridgeRequestEvents extends BaseTask_1.BaseTask {
|
19
|
-
constructor({ chainId }) {
|
20
|
-
super({
|
21
|
-
logger: new logger_1.default("InteropXContract::ProccessBridgeRequestEvents"),
|
22
|
-
});
|
23
|
-
this.leadNodeOnly = true;
|
24
|
-
this.chainId = chainId;
|
25
|
-
}
|
26
|
-
async pollHandler() {
|
27
|
-
var _a;
|
28
|
-
const blockNumber = await this.provider.getBlockNumber();
|
29
|
-
const transaction = await db_1.Transaction.findOne({
|
30
|
-
where: {
|
31
|
-
status: 'pending',
|
32
|
-
sourceStatus: 'uninitialised',
|
33
|
-
createdAt: {
|
34
|
-
[sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
35
|
-
},
|
36
|
-
sourceDelayUntil: {
|
37
|
-
[sequelize_1.Op.or]: {
|
38
|
-
[sequelize_1.Op.is]: null,
|
39
|
-
[sequelize_1.Op.lt]: new Date(),
|
40
|
-
}
|
41
|
-
},
|
42
|
-
requestBlockNumber: {
|
43
|
-
[sequelize_1.Op.lt]: blockNumber - 12,
|
44
|
-
},
|
45
|
-
sourceChainId: this.chainId,
|
46
|
-
}
|
47
|
-
});
|
48
|
-
if (!transaction) {
|
49
|
-
return;
|
50
|
-
}
|
51
|
-
console.log(`Processing transaction ${transaction.transactionHash}`);
|
52
|
-
transaction.targetStatus = 'pending';
|
53
|
-
await transaction.save();
|
54
|
-
const ownersThreshold = await this.safeContract.getThreshold();
|
55
|
-
await (0, waait_1.default)(10000);
|
56
|
-
let data, logs = [];
|
57
|
-
try {
|
58
|
-
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, 'source'));
|
59
|
-
}
|
60
|
-
catch (error) {
|
61
|
-
if (error instanceof utils_1.LiquidityError) {
|
62
|
-
await transaction.save();
|
63
|
-
transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
64
|
-
transaction.sourceStatus = 'uninitialised';
|
65
|
-
await transaction.save();
|
66
|
-
throw error;
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
transaction.sourceStatus = 'failed';
|
70
|
-
transaction.sourceErrors = [error.message];
|
71
|
-
transaction.targetStatus = 'failed';
|
72
|
-
transaction.status = 'failed';
|
73
|
-
await transaction.save();
|
74
|
-
net_1.protocol.sendTransaction(transaction);
|
75
|
-
return;
|
76
|
-
}
|
77
|
-
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
78
|
-
baseGas: "0",
|
79
|
-
data,
|
80
|
-
gasPrice: "0",
|
81
|
-
gasToken: "0x0000000000000000000000000000000000000000",
|
82
|
-
nonce: '0',
|
83
|
-
operation: "1",
|
84
|
-
refundReceiver: "0x0000000000000000000000000000000000000000",
|
85
|
-
safeAddress: this.safeContractAddress,
|
86
|
-
safeTxGas: "79668",
|
87
|
-
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
88
|
-
value: "0",
|
89
|
-
}, this.safeContract);
|
90
|
-
const owners = await this.safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
91
|
-
const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
|
92
|
-
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
93
|
-
console.log(ownerPeerIds);
|
94
|
-
const signatures = await net_1.protocol.requestSignatures({
|
95
|
-
type: 'source',
|
96
|
-
transactionHash: transaction.transactionHash,
|
97
|
-
safeTxGas: gnosisTx.safeTxGas,
|
98
|
-
safeNonce: gnosisTx.nonce
|
99
|
-
}, ownerPeerIds);
|
100
|
-
const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x');
|
101
|
-
console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
|
102
|
-
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
103
|
-
await transaction.save();
|
104
|
-
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
105
|
-
transaction.sourceStatus = 'uninitialised';
|
106
|
-
await transaction.save();
|
107
|
-
const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
108
|
-
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
109
|
-
}
|
110
|
-
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
111
|
-
const { data: txData } = await this.safeContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
|
112
|
-
const txSent = await this.sourceWallet.sendTransaction({
|
113
|
-
from: this.sourceWallet.address,
|
114
|
-
gasPrice: ethers_1.ethers.BigNumber.from(120 * 10 ** 9),
|
115
|
-
to: this.safeContractAddress,
|
116
|
-
data: txData,
|
117
|
-
});
|
118
|
-
console.log(txSent);
|
119
|
-
const receipt = await txSent.wait();
|
120
|
-
const parsedLogs = [];
|
121
|
-
receipt.logs.forEach((log) => {
|
122
|
-
try {
|
123
|
-
parsedLogs.push(this.safeContract.interface.parseLog(log));
|
124
|
-
}
|
125
|
-
catch (e) { }
|
126
|
-
});
|
127
|
-
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
128
|
-
console.log('ExecutionSuccess');
|
129
|
-
transaction.sourceStatus = 'success';
|
130
|
-
if (txSent.blockNumber)
|
131
|
-
transaction.sourceBlockNumber = txSent.blockNumber;
|
132
|
-
transaction.sourceTransactionHash = txSent.hash;
|
133
|
-
transaction.sourceLogs = logs;
|
134
|
-
transaction.status = 'success';
|
135
|
-
await transaction.save();
|
136
|
-
}
|
137
|
-
else {
|
138
|
-
console.log('ExecutionFailure');
|
139
|
-
transaction.sourceStatus = 'failed';
|
140
|
-
if (txSent.blockNumber)
|
141
|
-
transaction.sourceBlockNumber = txSent.blockNumber;
|
142
|
-
transaction.sourceTransactionHash = txSent.hash;
|
143
|
-
transaction.sourceTransactionHash = txSent.hash;
|
144
|
-
transaction.status = 'failed';
|
145
|
-
await transaction.save();
|
146
|
-
}
|
147
|
-
net_1.protocol.sendTransaction(transaction);
|
148
|
-
}
|
149
|
-
async start() {
|
150
|
-
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
151
|
-
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
152
|
-
this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider);
|
153
|
-
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, this.sourceWallet);
|
154
|
-
this.safeContractAddress = constants_1.addresses[this.chainId].gnosisSafe;
|
155
|
-
this.safeContract = (0, utils_1.getContract)(this.safeContractAddress, abi_1.default.gnosisSafe, this.sourceWallet);
|
156
|
-
await super.start();
|
157
|
-
}
|
158
|
-
}
|
159
|
-
exports.default = ProccessBridgeRequestEvents;
|