@instadapp/interop-x 0.0.0-dev.ef78459 → 0.0.0-dev.f78418c

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. package/dist/abi/erc20.json +350 -0
  2. package/dist/abi/gnosisSafe.json +747 -0
  3. package/dist/abi/index.js +15 -0
  4. package/dist/abi/interopBridgeToken.json +286 -0
  5. package/dist/abi/interopXGateway.json +184 -0
  6. package/dist/constants/addresses.js +17 -2
  7. package/dist/constants/index.js +1 -0
  8. package/dist/constants/tokens.js +107 -0
  9. package/dist/db/models/index.js +1 -1
  10. package/dist/db/models/transaction.js +52 -0
  11. package/dist/index.js +1 -1
  12. package/dist/net/protocol/dial/SignatureDialProtocol.js +10 -12
  13. package/dist/net/protocol/index.js +3 -3
  14. package/dist/tasks/BaseTask.js +1 -1
  15. package/dist/tasks/InteropXGateway/SyncDepositEvents.js +79 -0
  16. package/dist/tasks/index.js +9 -1
  17. package/dist/typechain/Erc20.js +2 -0
  18. package/dist/typechain/GnosisSafe.js +2 -0
  19. package/dist/typechain/InteropBridgeToken.js +2 -0
  20. package/dist/typechain/InteropXGateway.js +2 -0
  21. package/dist/typechain/common.js +2 -0
  22. package/dist/typechain/factories/Erc20__factory.js +367 -0
  23. package/dist/typechain/factories/GnosisSafe__factory.js +1174 -0
  24. package/dist/typechain/factories/InteropBridgeToken__factory.js +459 -0
  25. package/dist/typechain/factories/InteropXGateway__factory.js +265 -0
  26. package/dist/typechain/factories/index.js +14 -0
  27. package/dist/typechain/index.js +35 -0
  28. package/dist/utils/index.js +13 -1
  29. package/package.json +18 -4
  30. package/src/abi/erc20.json +350 -0
  31. package/src/abi/gnosisSafe.json +747 -0
  32. package/src/abi/index.ts +11 -0
  33. package/src/abi/interopBridgeToken.json +286 -0
  34. package/src/abi/interopXGateway.json +184 -0
  35. package/src/constants/addresses.ts +17 -2
  36. package/src/constants/index.ts +1 -0
  37. package/src/constants/tokens.ts +104 -0
  38. package/src/db/models/index.ts +1 -1
  39. package/src/db/models/transaction.ts +92 -0
  40. package/src/index.ts +2 -1
  41. package/src/net/protocol/dial/SignatureDialProtocol.ts +12 -15
  42. package/src/net/protocol/index.ts +3 -3
  43. package/src/tasks/BaseTask.ts +1 -2
  44. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +114 -0
  45. package/src/tasks/index.ts +4 -1
  46. package/src/typechain/Erc20.ts +491 -0
  47. package/src/typechain/GnosisSafe.ts +1728 -0
  48. package/src/typechain/InteropBridgeToken.ts +686 -0
  49. package/src/typechain/InteropXGateway.ts +407 -0
  50. package/src/typechain/common.ts +44 -0
  51. package/src/typechain/factories/Erc20__factory.ts +368 -0
  52. package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
  53. package/src/typechain/factories/InteropBridgeToken__factory.ts +466 -0
  54. package/src/typechain/factories/InteropXGateway__factory.ts +272 -0
  55. package/src/typechain/factories/index.ts +7 -0
  56. package/src/typechain/index.ts +12 -0
  57. package/src/types.ts +1 -1
  58. package/src/utils/index.ts +13 -0
  59. package/dist/db/models/execution.js +0 -38
  60. package/src/db/models/execution.ts +0 -57
package/dist/index.js CHANGED
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  require("module-alias/register");
7
7
  const assert_1 = __importDefault(require("assert"));
8
8
  const dotenv_1 = __importDefault(require("dotenv"));
9
- const logger_1 = __importDefault(require("@/logger"));
10
9
  const ethers_1 = require("ethers");
11
10
  dotenv_1.default.config();
11
+ const logger_1 = __importDefault(require("@/logger"));
12
12
  const logger = new logger_1.default('Process');
13
13
  (0, assert_1.default)(process.env.PRIVATE_KEY, "PRIVATE_KEY is not defined");
14
14
  try {
@@ -4,15 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SignatureDialProtocol = void 0;
7
- const utils_1 = require("@/utils");
8
7
  const BaseDialProtocol_1 = require("./BaseDialProtocol");
9
8
  const waait_1 = __importDefault(require("waait"));
10
9
  const config_1 = __importDefault(require("@/config"));
11
- const constants_1 = require("@/constants");
12
- const db_1 = require("db");
10
+ const db_1 = require("@/db");
13
11
  class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
14
12
  constructor(libp2p) {
15
- super(libp2p, '/signatures');
13
+ super(libp2p, '/interop-x/signatures');
16
14
  this.timeout = 30000;
17
15
  }
18
16
  async response(data) {
@@ -20,7 +18,7 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
20
18
  let event;
21
19
  let maxTimeout = 20000;
22
20
  do {
23
- event = await db_1.Execution.findOne({ where: { vnonce: data.vnonce.toString() } });
21
+ event = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
24
22
  if (!event) {
25
23
  await (0, waait_1.default)(1000);
26
24
  maxTimeout -= 1000;
@@ -33,15 +31,15 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
33
31
  error: 'Event not found'
34
32
  };
35
33
  }
36
- const signedData = await (0, utils_1.signGnosisSafeTx)({
37
- to: constants_1.addresses[event.chainId].multisend,
38
- data: 'TODO',
39
- chainId: event.chainId,
40
- safeTxGas: data.safeTxGas,
41
- }, { signer });
34
+ // const signedData = await signGnosisSafeTx({
35
+ // to: addresses[event.chainId as ChainId].multisend,
36
+ // data: 'TODO',
37
+ // chainId: event.chainId as ChainId,
38
+ // safeTxGas: data.safeTxGas,
39
+ // }, { signer });
42
40
  return {
43
41
  signer: signer.address,
44
- data: signedData,
42
+ data: null, //signedData,
45
43
  };
46
44
  }
47
45
  }
@@ -8,8 +8,8 @@ const stream_1 = require("stream");
8
8
  const ethereumjs_util_1 = require("ethereumjs-util");
9
9
  const SignatureDialProtocol_1 = require("./dial/SignatureDialProtocol");
10
10
  const __1 = require("..");
11
- const config_1 = __importDefault(require("config"));
12
- const types_1 = require("types");
11
+ const config_1 = __importDefault(require("@/config"));
12
+ const types_1 = require("@/types");
13
13
  class Protocol extends stream_1.EventEmitter {
14
14
  constructor() {
15
15
  super(...arguments);
@@ -28,7 +28,7 @@ class Protocol extends stream_1.EventEmitter {
28
28
  }
29
29
  start({ libp2p, topic = null, }) {
30
30
  this.libp2p = libp2p;
31
- this.topic = topic || 'protocol';
31
+ this.topic = topic || 'itnerop-x-protocol';
32
32
  if (this.libp2p.isStarted())
33
33
  this.init();
34
34
  this.on('PeerInfo', (payload) => {
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BaseTask = void 0;
7
- const config_1 = __importDefault(require("config"));
7
+ const config_1 = __importDefault(require("@/config"));
8
8
  const events_1 = __importDefault(require("events"));
9
9
  const waait_1 = __importDefault(require("waait"));
10
10
  const logger_1 = __importDefault(require("@/logger"));
@@ -0,0 +1,79 @@
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 config_1 = __importDefault(require("@/config"));
14
+ class SyncDepositEvents extends BaseTask_1.BaseTask {
15
+ constructor({ chainId }) {
16
+ super({
17
+ logger: new logger_1.default("InteropXGateway::SyncDepositEvents"),
18
+ });
19
+ this.chainId = chainId;
20
+ }
21
+ async pollHandler() {
22
+ const currentBlock = await this.provider.getBlockNumber();
23
+ const events = await this.contract.queryFilter(this.contract.filters.LogGatewayDeposit(), currentBlock - 2000, currentBlock);
24
+ let processedEvents = 0;
25
+ for (const event of events) {
26
+ try {
27
+ if (!event.args) {
28
+ continue;
29
+ }
30
+ const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
31
+ const uniqueIdentifier = {
32
+ type: 'desposit',
33
+ sourceTransactionHash: event.transactionHash,
34
+ sourceChainId: sourceChainId.toNumber(),
35
+ targetChainId: targetChainId.toNumber(),
36
+ };
37
+ if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
38
+ continue;
39
+ }
40
+ const tx = await event.getTransaction();
41
+ await db_1.Transaction.create({
42
+ transactionHash: (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier),
43
+ type: 'deposit',
44
+ from: tx.from,
45
+ to: user,
46
+ sourceChainId: sourceChainId.toNumber(),
47
+ sourceTransactionHash: event.transactionHash,
48
+ sourceBlockNumber: event.blockNumber,
49
+ sourceStatus: "uninitialised",
50
+ targetChainId: targetChainId.toNumber(),
51
+ targetStatus: "uninitialised",
52
+ submitEvent: {
53
+ user,
54
+ sourceChainId: sourceChainId.toString(),
55
+ targetChainId: targetChainId.toString(),
56
+ token: token,
57
+ ammout: amount.toString(),
58
+ vnonce: vnonce.toString(),
59
+ },
60
+ status: "pending",
61
+ });
62
+ this.logger.info(`Execution queued: ${event.transactionHash} ${event.blockNumber}`);
63
+ }
64
+ catch (error) {
65
+ this.logger.error(error);
66
+ }
67
+ }
68
+ if (processedEvents > 0)
69
+ this.logger.info(`${processedEvents} events processed`);
70
+ }
71
+ async start() {
72
+ this.logger.info(`Starting execution watcher on interop chain`);
73
+ this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
74
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
75
+ this.contract = new ethers_1.ethers.Contract(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
76
+ await super.start();
77
+ }
78
+ }
79
+ exports.default = SyncDepositEvents;
@@ -1,9 +1,17 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Tasks = void 0;
7
+ const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
4
8
  class Tasks {
5
9
  constructor() {
6
- this.tasks = [];
10
+ this.tasks = [
11
+ new SyncDepositEvents_1.default({
12
+ chainId: 43114
13
+ })
14
+ ];
7
15
  }
8
16
  async start() {
9
17
  for (const task of this.tasks) {
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+ /* Autogenerated file. Do not edit manually. */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Erc20__factory = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const _abi = [
9
+ {
10
+ inputs: [
11
+ {
12
+ internalType: "uint256",
13
+ name: "_totalSupply",
14
+ type: "uint256",
15
+ },
16
+ ],
17
+ payable: false,
18
+ stateMutability: "nonpayable",
19
+ type: "constructor",
20
+ },
21
+ {
22
+ anonymous: false,
23
+ inputs: [
24
+ {
25
+ indexed: true,
26
+ internalType: "address",
27
+ name: "owner",
28
+ type: "address",
29
+ },
30
+ {
31
+ indexed: true,
32
+ internalType: "address",
33
+ name: "spender",
34
+ type: "address",
35
+ },
36
+ {
37
+ indexed: false,
38
+ internalType: "uint256",
39
+ name: "value",
40
+ type: "uint256",
41
+ },
42
+ ],
43
+ name: "Approval",
44
+ type: "event",
45
+ },
46
+ {
47
+ anonymous: false,
48
+ inputs: [
49
+ {
50
+ indexed: true,
51
+ internalType: "address",
52
+ name: "from",
53
+ type: "address",
54
+ },
55
+ {
56
+ indexed: true,
57
+ internalType: "address",
58
+ name: "to",
59
+ type: "address",
60
+ },
61
+ {
62
+ indexed: false,
63
+ internalType: "uint256",
64
+ name: "value",
65
+ type: "uint256",
66
+ },
67
+ ],
68
+ name: "Transfer",
69
+ type: "event",
70
+ },
71
+ {
72
+ constant: true,
73
+ inputs: [],
74
+ name: "DOMAIN_SEPARATOR",
75
+ outputs: [
76
+ {
77
+ internalType: "bytes32",
78
+ name: "",
79
+ type: "bytes32",
80
+ },
81
+ ],
82
+ payable: false,
83
+ stateMutability: "view",
84
+ type: "function",
85
+ },
86
+ {
87
+ constant: true,
88
+ inputs: [],
89
+ name: "PERMIT_TYPEHASH",
90
+ outputs: [
91
+ {
92
+ internalType: "bytes32",
93
+ name: "",
94
+ type: "bytes32",
95
+ },
96
+ ],
97
+ payable: false,
98
+ stateMutability: "view",
99
+ type: "function",
100
+ },
101
+ {
102
+ constant: true,
103
+ inputs: [
104
+ {
105
+ internalType: "address",
106
+ name: "",
107
+ type: "address",
108
+ },
109
+ {
110
+ internalType: "address",
111
+ name: "",
112
+ type: "address",
113
+ },
114
+ ],
115
+ name: "allowance",
116
+ outputs: [
117
+ {
118
+ internalType: "uint256",
119
+ name: "",
120
+ type: "uint256",
121
+ },
122
+ ],
123
+ payable: false,
124
+ stateMutability: "view",
125
+ type: "function",
126
+ },
127
+ {
128
+ constant: false,
129
+ inputs: [
130
+ {
131
+ internalType: "address",
132
+ name: "spender",
133
+ type: "address",
134
+ },
135
+ {
136
+ internalType: "uint256",
137
+ name: "value",
138
+ type: "uint256",
139
+ },
140
+ ],
141
+ name: "approve",
142
+ outputs: [
143
+ {
144
+ internalType: "bool",
145
+ name: "",
146
+ type: "bool",
147
+ },
148
+ ],
149
+ payable: false,
150
+ stateMutability: "nonpayable",
151
+ type: "function",
152
+ },
153
+ {
154
+ constant: true,
155
+ inputs: [
156
+ {
157
+ internalType: "address",
158
+ name: "",
159
+ type: "address",
160
+ },
161
+ ],
162
+ name: "balanceOf",
163
+ outputs: [
164
+ {
165
+ internalType: "uint256",
166
+ name: "",
167
+ type: "uint256",
168
+ },
169
+ ],
170
+ payable: false,
171
+ stateMutability: "view",
172
+ type: "function",
173
+ },
174
+ {
175
+ constant: true,
176
+ inputs: [],
177
+ name: "decimals",
178
+ outputs: [
179
+ {
180
+ internalType: "uint8",
181
+ name: "",
182
+ type: "uint8",
183
+ },
184
+ ],
185
+ payable: false,
186
+ stateMutability: "view",
187
+ type: "function",
188
+ },
189
+ {
190
+ constant: true,
191
+ inputs: [],
192
+ name: "name",
193
+ outputs: [
194
+ {
195
+ internalType: "string",
196
+ name: "",
197
+ type: "string",
198
+ },
199
+ ],
200
+ payable: false,
201
+ stateMutability: "view",
202
+ type: "function",
203
+ },
204
+ {
205
+ constant: true,
206
+ inputs: [
207
+ {
208
+ internalType: "address",
209
+ name: "",
210
+ type: "address",
211
+ },
212
+ ],
213
+ name: "nonces",
214
+ outputs: [
215
+ {
216
+ internalType: "uint256",
217
+ name: "",
218
+ type: "uint256",
219
+ },
220
+ ],
221
+ payable: false,
222
+ stateMutability: "view",
223
+ type: "function",
224
+ },
225
+ {
226
+ constant: false,
227
+ inputs: [
228
+ {
229
+ internalType: "address",
230
+ name: "owner",
231
+ type: "address",
232
+ },
233
+ {
234
+ internalType: "address",
235
+ name: "spender",
236
+ type: "address",
237
+ },
238
+ {
239
+ internalType: "uint256",
240
+ name: "value",
241
+ type: "uint256",
242
+ },
243
+ {
244
+ internalType: "uint256",
245
+ name: "deadline",
246
+ type: "uint256",
247
+ },
248
+ {
249
+ internalType: "uint8",
250
+ name: "v",
251
+ type: "uint8",
252
+ },
253
+ {
254
+ internalType: "bytes32",
255
+ name: "r",
256
+ type: "bytes32",
257
+ },
258
+ {
259
+ internalType: "bytes32",
260
+ name: "s",
261
+ type: "bytes32",
262
+ },
263
+ ],
264
+ name: "permit",
265
+ outputs: [],
266
+ payable: false,
267
+ stateMutability: "nonpayable",
268
+ type: "function",
269
+ },
270
+ {
271
+ constant: true,
272
+ inputs: [],
273
+ name: "symbol",
274
+ outputs: [
275
+ {
276
+ internalType: "string",
277
+ name: "",
278
+ type: "string",
279
+ },
280
+ ],
281
+ payable: false,
282
+ stateMutability: "view",
283
+ type: "function",
284
+ },
285
+ {
286
+ constant: true,
287
+ inputs: [],
288
+ name: "totalSupply",
289
+ outputs: [
290
+ {
291
+ internalType: "uint256",
292
+ name: "",
293
+ type: "uint256",
294
+ },
295
+ ],
296
+ payable: false,
297
+ stateMutability: "view",
298
+ type: "function",
299
+ },
300
+ {
301
+ constant: false,
302
+ inputs: [
303
+ {
304
+ internalType: "address",
305
+ name: "to",
306
+ type: "address",
307
+ },
308
+ {
309
+ internalType: "uint256",
310
+ name: "value",
311
+ type: "uint256",
312
+ },
313
+ ],
314
+ name: "transfer",
315
+ outputs: [
316
+ {
317
+ internalType: "bool",
318
+ name: "",
319
+ type: "bool",
320
+ },
321
+ ],
322
+ payable: false,
323
+ stateMutability: "nonpayable",
324
+ type: "function",
325
+ },
326
+ {
327
+ constant: false,
328
+ inputs: [
329
+ {
330
+ internalType: "address",
331
+ name: "from",
332
+ type: "address",
333
+ },
334
+ {
335
+ internalType: "address",
336
+ name: "to",
337
+ type: "address",
338
+ },
339
+ {
340
+ internalType: "uint256",
341
+ name: "value",
342
+ type: "uint256",
343
+ },
344
+ ],
345
+ name: "transferFrom",
346
+ outputs: [
347
+ {
348
+ internalType: "bool",
349
+ name: "",
350
+ type: "bool",
351
+ },
352
+ ],
353
+ payable: false,
354
+ stateMutability: "nonpayable",
355
+ type: "function",
356
+ },
357
+ ];
358
+ class Erc20__factory {
359
+ static createInterface() {
360
+ return new ethers_1.utils.Interface(_abi);
361
+ }
362
+ static connect(address, signerOrProvider) {
363
+ return new ethers_1.Contract(address, _abi, signerOrProvider);
364
+ }
365
+ }
366
+ exports.Erc20__factory = Erc20__factory;
367
+ Erc20__factory.abi = _abi;