@instadapp/interop-x 0.0.0-dev.dc4f10a → 0.0.0-dev.de23e71

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 (67) hide show
  1. package/dist/package.json +6 -5
  2. package/dist/src/abi/interopBridgeToken.json +21 -9
  3. package/dist/src/abi/interopXGateway.json +11 -11
  4. package/dist/src/alias.js +10 -0
  5. package/dist/src/api/index.js +6 -3
  6. package/dist/src/config/index.js +11 -1
  7. package/dist/src/constants/addresses.js +1 -1
  8. package/dist/src/constants/itokens.js +1 -1
  9. package/dist/src/db/models/transaction.js +8 -0
  10. package/dist/src/gnosis/actions/deposit.js +48 -0
  11. package/dist/src/gnosis/actions/index.js +11 -0
  12. package/dist/src/gnosis/actions/withdraw.js +50 -0
  13. package/dist/src/gnosis/index.js +20 -0
  14. package/dist/src/index.js +72 -23
  15. package/dist/src/net/peer/index.js +2 -1
  16. package/dist/src/net/pool/index.js +18 -2
  17. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
  18. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  19. package/dist/src/net/protocol/index.js +51 -1
  20. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  21. package/dist/src/tasks/BaseTask.js +11 -3
  22. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +19 -4
  23. package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -9
  24. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  25. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +19 -2
  26. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -3
  27. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  28. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  29. package/dist/src/tasks/index.js +19 -4
  30. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
  31. package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
  32. package/dist/src/utils/index.js +19 -85
  33. package/package.json +6 -5
  34. package/src/abi/interopBridgeToken.json +21 -9
  35. package/src/abi/interopXGateway.json +11 -11
  36. package/src/alias.ts +6 -0
  37. package/src/api/index.ts +5 -2
  38. package/src/config/index.ts +11 -1
  39. package/src/constants/addresses.ts +1 -1
  40. package/src/constants/itokens.ts +1 -1
  41. package/src/db/models/transaction.ts +10 -0
  42. package/src/gnosis/actions/deposit.ts +63 -0
  43. package/src/gnosis/actions/index.ts +7 -0
  44. package/src/gnosis/actions/withdraw.ts +67 -0
  45. package/src/gnosis/index.ts +19 -0
  46. package/src/index.ts +93 -25
  47. package/src/net/peer/index.ts +2 -1
  48. package/src/net/pool/index.ts +25 -5
  49. package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
  50. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  51. package/src/net/protocol/index.ts +67 -1
  52. package/src/tasks/AutoUpdateTask.ts +82 -0
  53. package/src/tasks/BaseTask.ts +13 -3
  54. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +26 -18
  55. package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -15
  56. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  57. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +26 -7
  58. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -4
  59. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  60. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  61. package/src/tasks/index.ts +28 -4
  62. package/src/typechain/InteropBridgeToken.ts +23 -17
  63. package/src/typechain/InteropXGateway.ts +13 -13
  64. package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
  65. package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
  66. package/src/utils/index.ts +22 -125
  67. package/tsconfig.json +7 -2
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionStatusDialProtocol = void 0;
4
+ const BaseDialProtocol_1 = require("./BaseDialProtocol");
5
+ const db_1 = require("@/db");
6
+ class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
7
+ constructor(libp2p) {
8
+ super(libp2p, '/interop-x/transaction-status');
9
+ this.timeout = 30000;
10
+ }
11
+ async response(transactionHash) {
12
+ const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
13
+ if (!transaction) {
14
+ return null;
15
+ }
16
+ return {
17
+ transactionHash: transaction.transactionHash,
18
+ sourceStatus: transaction.sourceStatus,
19
+ sourceTransactionHash: transaction.sourceTransactionHash,
20
+ sourceErrors: transaction.sourceErrors,
21
+ sourceLogs: transaction.sourceLogs,
22
+ targetStatus: transaction.targetStatus,
23
+ targetTransactionHash: transaction.targetTransactionHash,
24
+ targetErrors: transaction.targetErrors,
25
+ targetLogs: transaction.targetLogs,
26
+ status: transaction.status,
27
+ };
28
+ }
29
+ }
30
+ exports.TransactionStatusDialProtocol = TransactionStatusDialProtocol;
@@ -10,13 +10,14 @@ const SignatureDialProtocol_1 = require("./dial/SignatureDialProtocol");
10
10
  const __1 = require("..");
11
11
  const config_1 = __importDefault(require("@/config"));
12
12
  const types_1 = require("@/types");
13
+ const TransactionStatusDialProtocol_1 = require("./dial/TransactionStatusDialProtocol");
13
14
  class Protocol extends stream_1.EventEmitter {
14
15
  constructor() {
15
16
  super(...arguments);
16
17
  this.protocolMessages = [
17
18
  {
18
19
  name: 'PeerInfo',
19
- code: 0x09,
20
+ code: 0x01,
20
21
  encode: (info) => [
21
22
  Buffer.from(info.publicAddress),
22
23
  ],
@@ -24,6 +25,40 @@ class Protocol extends stream_1.EventEmitter {
24
25
  publicAddress: publicAddress.toString(),
25
26
  }),
26
27
  },
28
+ {
29
+ name: 'TransactionStatus',
30
+ code: 0x02,
31
+ encode: (transaction) => [
32
+ Buffer.from(transaction.transactionHash),
33
+ Buffer.from(transaction.sourceStatus),
34
+ Buffer.from(transaction.sourceTransactionHash || ''),
35
+ transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
36
+ transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
37
+ Buffer.from(transaction.targetStatus),
38
+ Buffer.from(transaction.targetTransactionHash || ''),
39
+ transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
40
+ transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
41
+ Buffer.from(transaction.status),
42
+ ],
43
+ decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
44
+ transactionHash: transactionHash.toString(),
45
+ sourceStatus: sourceStatus.toString(),
46
+ sourceTransactionHash: sourceTransactionHash.toString() || null,
47
+ sourceErrors: sourceErrors.map((e) => e.toString()),
48
+ sourceLogs: sourceLogs.map(e => ({
49
+ type: e[0].toString(),
50
+ message: e[1].toString(),
51
+ })),
52
+ targetStatus: targetStatus.toString(),
53
+ targetTransactionHash: targetTransactionHash.toString() || null,
54
+ targetErrors: targetErrors.map((e) => e.toString()),
55
+ targetLogs: targetLogs.map(e => ({
56
+ type: e[0].toString(),
57
+ message: e[1].toString(),
58
+ })),
59
+ status: status.toString(),
60
+ }),
61
+ },
27
62
  ];
28
63
  }
29
64
  start({ libp2p, topic = null, }) {
@@ -40,6 +75,7 @@ class Protocol extends stream_1.EventEmitter {
40
75
  });
41
76
  });
42
77
  this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
78
+ this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
43
79
  }
44
80
  init() {
45
81
  this.libp2p.pubsub.subscribe(this.topic);
@@ -75,6 +111,11 @@ class Protocol extends stream_1.EventEmitter {
75
111
  const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(data)]);
76
112
  this.libp2p.pubsub.publish(this.topic, encoded);
77
113
  }
114
+ sendTransaction(transaction) {
115
+ const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
116
+ const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
117
+ this.libp2p.pubsub.publish(this.topic, encoded);
118
+ }
78
119
  async requestSignatures(data, peerIds) {
79
120
  try {
80
121
  peerIds = peerIds || __1.peerPool.activePeerIds;
@@ -88,5 +129,14 @@ class Protocol extends stream_1.EventEmitter {
88
129
  return [];
89
130
  }
90
131
  }
132
+ async requestTransactionStatus(transactionHash, peerId) {
133
+ try {
134
+ return await this.transactionStatus.send(transactionHash, peerId);
135
+ }
136
+ catch (error) {
137
+ console.log(error);
138
+ return null;
139
+ }
140
+ }
91
141
  }
92
142
  exports.protocol = new Protocol();
@@ -0,0 +1,70 @@
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 await_spawn_1 = __importDefault(require("await-spawn"));
9
+ const child_process_1 = require("child_process");
10
+ const config_1 = __importDefault(require("@/config"));
11
+ const waait_1 = __importDefault(require("waait"));
12
+ const package_json_1 = __importDefault(require("../../package.json"));
13
+ const currentVersion = package_json_1.default.version;
14
+ const tag = config_1.default.staging ? 'dev' : 'latest';
15
+ class AutoUpdateTask extends BaseTask_1.BaseTask {
16
+ constructor() {
17
+ super({
18
+ logger: new logger_1.default("AutoUpdateTask"),
19
+ });
20
+ this.pollIntervalMs = 60 * 10 * 1000;
21
+ }
22
+ prePollHandler() {
23
+ return config_1.default.autoUpdate && !config_1.default.isLeadNode();
24
+ }
25
+ async getInstalledVersion() {
26
+ try {
27
+ const stdout = await (0, await_spawn_1.default)('npm', ['-g', 'ls', '--depth=0', '--json']);
28
+ return JSON.parse(stdout.toString()).dependencies[package_json_1.default.name].version;
29
+ }
30
+ catch (error) {
31
+ this.logger.error(error);
32
+ return currentVersion;
33
+ }
34
+ }
35
+ async getLatestVersion() {
36
+ try {
37
+ const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
38
+ return stdout.toString().trim();
39
+ }
40
+ catch (error) {
41
+ this.logger.error(error);
42
+ return currentVersion;
43
+ }
44
+ }
45
+ async pollHandler() {
46
+ const version = await this.getLatestVersion();
47
+ if (version === currentVersion) {
48
+ return;
49
+ }
50
+ this.logger.warn(`New version ${version} available.`);
51
+ this.logger.info('Updating...');
52
+ await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
53
+ await (0, waait_1.default)(5000);
54
+ if (version !== await this.getInstalledVersion()) {
55
+ this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
56
+ return;
57
+ }
58
+ this.logger.warn(`Installed version ${version}`);
59
+ this.logger.warn(`Restarting...`);
60
+ // TODO: its restarting in the bg, but it should be in the fg
61
+ const subprocess = (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
62
+ cwd: process.cwd(),
63
+ stdio: "inherit",
64
+ // shell: process.env.SHELL,
65
+ });
66
+ subprocess.unref();
67
+ process.exit();
68
+ }
69
+ }
70
+ exports.default = AutoUpdateTask;
@@ -14,6 +14,7 @@ class BaseTask extends events_1.default {
14
14
  this.started = false;
15
15
  this.pollIntervalMs = 10 * 1000;
16
16
  this.leadNodeOnly = false;
17
+ this.exceptLeadNode = false;
17
18
  this.logger = logger !== null && logger !== void 0 ? logger : new logger_1.default('BaseTask');
18
19
  }
19
20
  async pollCheck() {
@@ -34,10 +35,17 @@ class BaseTask extends events_1.default {
34
35
  }
35
36
  }
36
37
  prePollHandler() {
37
- if (!this.leadNodeOnly) {
38
- return true;
38
+ if (config_1.default.isMaintenanceMode()) {
39
+ this.logger.warn('Maintenance mode is enabled. Skipping task.');
40
+ return false;
39
41
  }
40
- return config_1.default.isLeadNode();
42
+ if (this.exceptLeadNode) {
43
+ return !config_1.default.isLeadNode();
44
+ }
45
+ if (this.leadNodeOnly) {
46
+ return config_1.default.isLeadNode();
47
+ }
48
+ return true;
41
49
  }
42
50
  async pollHandler() {
43
51
  this.logger.warn('pollHandler not implemented');
@@ -14,6 +14,7 @@ const config_1 = __importDefault(require("@/config"));
14
14
  const sequelize_1 = require("sequelize");
15
15
  const waait_1 = __importDefault(require("waait"));
16
16
  const net_1 = require("@/net");
17
+ const gnosis_1 = require("@/gnosis");
17
18
  const generateGnosisTransaction = async (transactionData, safeContract) => {
18
19
  console.log(transactionData);
19
20
  let isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
@@ -68,9 +69,22 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
68
69
  const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
69
70
  const ownersThreshold = await safeContract.getThreshold();
70
71
  await (0, waait_1.default)(10000);
72
+ let data, logs = [];
73
+ try {
74
+ ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction));
75
+ }
76
+ catch (error) {
77
+ console.log(error);
78
+ transaction.targetStatus = 'failed';
79
+ transaction.targetErrors = [error.message];
80
+ transaction.status = 'failed';
81
+ await transaction.save();
82
+ net_1.protocol.sendTransaction(transaction);
83
+ return;
84
+ }
71
85
  let gnosisTx = await generateGnosisTransaction({
72
86
  baseGas: "0",
73
- data: await (0, utils_1.buildDataForTransaction)(transaction),
87
+ data,
74
88
  gasPrice: "0",
75
89
  gasToken: "0x0000000000000000000000000000000000000000",
76
90
  nonce: '0',
@@ -126,21 +140,22 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
126
140
  if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
127
141
  console.log('ExecutionSuccess');
128
142
  transaction.targetStatus = 'success';
143
+ transaction.targetTransactionHash = txSent.hash;
144
+ transaction.targetLogs = logs;
129
145
  transaction.status = 'success';
130
146
  await transaction.save();
131
147
  }
132
148
  else {
133
149
  console.log('ExecutionFailure');
134
150
  transaction.targetStatus = 'failed';
151
+ transaction.targetTransactionHash = txSent.hash;
135
152
  transaction.status = 'failed';
136
153
  await transaction.save();
137
154
  }
155
+ net_1.protocol.sendTransaction(transaction);
138
156
  }
139
157
  async start() {
140
- this.logger.info(`Starting execution watcher on interop chain`);
141
- this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
142
158
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
143
- this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
144
159
  await super.start();
145
160
  }
146
161
  }
@@ -10,10 +10,10 @@ const abi_1 = __importDefault(require("@/abi"));
10
10
  const db_1 = require("@/db");
11
11
  const utils_1 = require("@/utils");
12
12
  const config_1 = __importDefault(require("@/config"));
13
- class SyncWithdrawEvents extends BaseTask_1.BaseTask {
13
+ class SyncBurnEvents extends BaseTask_1.BaseTask {
14
14
  constructor({ chainId, itokenAddress }) {
15
15
  super({
16
- logger: new logger_1.default("InteropBridgeToken::SyncWithdrawEvents"),
16
+ logger: new logger_1.default("InteropBridgeToken::SyncBurnEvents"),
17
17
  });
18
18
  this.chainId = chainId;
19
19
  this.itokenAddress = itokenAddress;
@@ -27,12 +27,12 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
27
27
  if (!event.args) {
28
28
  continue;
29
29
  }
30
- const { to, amount, chainId } = event.args;
30
+ const { to, amount, sourceChainId, targetChainId } = event.args;
31
31
  const uniqueIdentifier = {
32
32
  action: 'withdraw',
33
33
  submitTransactionHash: event.transactionHash,
34
- sourceChainId: this.chainId,
35
- targetChainId: chainId.toNumber(),
34
+ sourceChainId: sourceChainId,
35
+ targetChainId: targetChainId,
36
36
  };
37
37
  if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
38
38
  continue;
@@ -44,12 +44,14 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
44
44
  to,
45
45
  amount: amount.toString(),
46
46
  itoken: this.itokenAddress,
47
- chainId: chainId.toString()
47
+ sourceChainId: sourceChainId,
48
+ targetChainId: targetChainId,
48
49
  }, sourceEvent: {
49
50
  to,
50
51
  amount: amount.toString(),
51
52
  itoken: this.itokenAddress,
52
- chainId: chainId.toString(),
53
+ sourceChainId: sourceChainId,
54
+ targetChainId: targetChainId,
53
55
  }, status: "pending" }));
54
56
  this.logger.info(`Withdraw queued: ${event.transactionHash} ${event.blockNumber}`);
55
57
  }
@@ -61,10 +63,9 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
61
63
  this.logger.info(`${processedEvents} events processed`);
62
64
  }
63
65
  async start() {
64
- this.logger.info(`Starting execution watcher on interop chain`);
65
66
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
66
67
  this.contract = (0, utils_1.getContract)(this.itokenAddress, abi_1.default.interopBridgeToken, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
67
68
  await super.start();
68
69
  }
69
70
  }
70
- exports.default = SyncWithdrawEvents;
71
+ exports.default = SyncBurnEvents;
@@ -0,0 +1,67 @@
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 config_1 = __importDefault(require("@/config"));
13
+ class SyncMintEvents extends BaseTask_1.BaseTask {
14
+ constructor({ chainId, itokenAddress }) {
15
+ super({
16
+ logger: new logger_1.default("InteropBridgeToken::SyncMintEvents"),
17
+ });
18
+ this.chainId = chainId;
19
+ this.itokenAddress = itokenAddress;
20
+ }
21
+ async pollHandler() {
22
+ const currentBlock = await this.provider.getBlockNumber();
23
+ const events = await this.contract.queryFilter(this.contract.filters.Mint(), currentBlock - 500, currentBlock);
24
+ for (const event of events) {
25
+ try {
26
+ if (!event.args) {
27
+ continue;
28
+ }
29
+ const { sourceChainId, targetChainId, amount, to, submitTransactionHash } = event.args;
30
+ const uniqueIdentifier = {
31
+ action: 'deposit',
32
+ submitTransactionHash: submitTransactionHash,
33
+ sourceChainId: sourceChainId,
34
+ targetChainId: targetChainId,
35
+ targetEvent: null
36
+ };
37
+ const transaction = await db_1.Transaction.findOne({ where: uniqueIdentifier });
38
+ if (!transaction) {
39
+ return;
40
+ }
41
+ const tx = await event.getTransaction();
42
+ transaction.targetStatus = 'success';
43
+ transaction.targetErrors = [];
44
+ transaction.targetTransactionHash = tx.hash;
45
+ transaction.targetEvent = {
46
+ sourceChainId,
47
+ targetChainId,
48
+ amount: amount.toString(),
49
+ to,
50
+ submitTransactionHash
51
+ };
52
+ transaction.status = 'success';
53
+ await transaction.save();
54
+ this.logger.info(`Mint confirmation received: ${transaction.transactionHash} `);
55
+ }
56
+ catch (error) {
57
+ this.logger.error(error);
58
+ }
59
+ }
60
+ }
61
+ async start() {
62
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
63
+ this.contract = (0, utils_1.getContract)(this.itokenAddress, abi_1.default.interopBridgeToken, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
64
+ await super.start();
65
+ }
66
+ }
67
+ exports.default = SyncMintEvents;
@@ -14,6 +14,7 @@ const config_1 = __importDefault(require("@/config"));
14
14
  const sequelize_1 = require("sequelize");
15
15
  const waait_1 = __importDefault(require("waait"));
16
16
  const net_1 = require("@/net");
17
+ const gnosis_1 = require("@/gnosis");
17
18
  const generateGnosisTransaction = async (transactionData, safeContract) => {
18
19
  console.log(transactionData);
19
20
  let isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
@@ -68,9 +69,22 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
68
69
  const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
69
70
  const ownersThreshold = await safeContract.getThreshold();
70
71
  await (0, waait_1.default)(10000);
72
+ let data, logs = [];
73
+ try {
74
+ ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction));
75
+ }
76
+ catch (error) {
77
+ console.log(error);
78
+ transaction.targetStatus = 'failed';
79
+ transaction.targetErrors = [error.message];
80
+ transaction.status = 'failed';
81
+ await transaction.save();
82
+ net_1.protocol.sendTransaction(transaction);
83
+ return;
84
+ }
71
85
  let gnosisTx = await generateGnosisTransaction({
72
86
  baseGas: "0",
73
- data: await (0, utils_1.buildDataForTransaction)(transaction),
87
+ data,
74
88
  gasPrice: "0",
75
89
  gasToken: "0x0000000000000000000000000000000000000000",
76
90
  nonce: '0',
@@ -126,18 +140,21 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
126
140
  if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
127
141
  console.log('ExecutionSuccess');
128
142
  transaction.targetStatus = 'success';
143
+ transaction.targetTransactionHash = txSent.hash;
144
+ transaction.targetLogs = logs;
129
145
  transaction.status = 'success';
130
146
  await transaction.save();
131
147
  }
132
148
  else {
133
149
  console.log('ExecutionFailure');
134
150
  transaction.targetStatus = 'failed';
151
+ transaction.targetTransactionHash = txSent.hash;
135
152
  transaction.status = 'failed';
136
153
  await transaction.save();
137
154
  }
155
+ net_1.protocol.sendTransaction(transaction);
138
156
  }
139
157
  async start() {
140
- this.logger.info(`Starting execution watcher on interop chain`);
141
158
  this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
142
159
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
143
160
  this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
@@ -31,8 +31,8 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
31
31
  const uniqueIdentifier = {
32
32
  action: 'deposit',
33
33
  submitTransactionHash: event.transactionHash,
34
- sourceChainId: sourceChainId.toNumber(),
35
- targetChainId: targetChainId.toNumber(),
34
+ sourceChainId: sourceChainId,
35
+ targetChainId: targetChainId,
36
36
  };
37
37
  if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
38
38
  continue;
@@ -65,7 +65,6 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
65
65
  this.logger.info(`${processedEvents} events processed`);
66
66
  }
67
67
  async start() {
68
- this.logger.info(`Starting execution watcher on interop chain`);
69
68
  this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
70
69
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
71
70
  this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
@@ -0,0 +1,72 @@
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 SyncWithdrawEvents extends BaseTask_1.BaseTask {
15
+ constructor({ chainId }) {
16
+ super({
17
+ logger: new logger_1.default("InteropXGateway::SyncWithdrawEvents"),
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.LogGatewayWithdraw(), currentBlock - 500, currentBlock);
24
+ let processedEvents = 0;
25
+ for (const event of events) {
26
+ try {
27
+ if (!event.args) {
28
+ continue;
29
+ }
30
+ const { user, token, amount, sourceChainId, targetChainId, transactionHash } = event.args;
31
+ const uniqueIdentifier = {
32
+ action: 'withdraw',
33
+ submitTransactionHash: transactionHash,
34
+ sourceChainId: sourceChainId,
35
+ targetChainId: targetChainId,
36
+ targetEvent: null
37
+ };
38
+ const transaction = await db_1.Transaction.findOne({ where: uniqueIdentifier });
39
+ if (!transaction) {
40
+ return;
41
+ }
42
+ const tx = await event.getTransaction();
43
+ transaction.targetStatus = 'success';
44
+ transaction.targetErrors = [];
45
+ transaction.targetTransactionHash = tx.hash;
46
+ transaction.targetEvent = {
47
+ user,
48
+ token,
49
+ amount: amount.toString(),
50
+ sourceChainId,
51
+ targetChainId,
52
+ transactionHash,
53
+ };
54
+ transaction.status = 'success';
55
+ await transaction.save();
56
+ this.logger.info(`Witdraw confirmation received: ${transaction.transactionHash} `);
57
+ }
58
+ catch (error) {
59
+ this.logger.error(error);
60
+ }
61
+ }
62
+ if (processedEvents > 0)
63
+ this.logger.info(`${processedEvents} events processed`);
64
+ }
65
+ async start() {
66
+ this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
67
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
68
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
69
+ await super.start();
70
+ }
71
+ }
72
+ exports.default = SyncWithdrawEvents;
@@ -0,0 +1,55 @@
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 net_1 = require("@/net");
9
+ const db_1 = require("@/db");
10
+ const sequelize_1 = require("sequelize");
11
+ class SyncTransactionStatusTask extends BaseTask_1.BaseTask {
12
+ constructor() {
13
+ super({
14
+ logger: new logger_1.default("SyncTransactionStatusTask"),
15
+ });
16
+ this.pollIntervalMs = 60 * 1000;
17
+ this.exceptLeadNode = true;
18
+ }
19
+ async pollHandler() {
20
+ // if transaction is pending for more than 1 hour, check lead node for status
21
+ const leadNode = net_1.peerPool.getLeadPeer();
22
+ if (!leadNode) {
23
+ return;
24
+ }
25
+ const transaction = await db_1.Transaction.findOne({
26
+ where: {
27
+ status: 'pending',
28
+ sourceCreatedAt: {
29
+ [sequelize_1.Op.gte]: new Date(Date.now() - 60 * 60 * 1000),
30
+ },
31
+ }
32
+ });
33
+ if (!transaction) {
34
+ return;
35
+ }
36
+ this.logger.info(`Requesting transaction status for ${transaction.transactionHash}`);
37
+ const transactionStatus = await net_1.protocol.requestTransactionStatus(transaction.transactionHash, leadNode.id);
38
+ if (!transactionStatus) {
39
+ return;
40
+ }
41
+ this.logger.info(`Received transaction status for ${transaction.transactionHash}`);
42
+ transaction.sourceStatus = transactionStatus.sourceStatus;
43
+ transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash;
44
+ transaction.sourceErrors = transactionStatus.sourceErrors;
45
+ transaction.sourceLogs = transactionStatus.sourceLogs;
46
+ transaction.targetStatus = transactionStatus.targetStatus;
47
+ transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
48
+ transaction.targetErrors = transactionStatus.targetErrors;
49
+ transaction.targetLogs = transactionStatus.targetLogs;
50
+ transaction.status = transactionStatus.status;
51
+ await transaction.save();
52
+ this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
53
+ }
54
+ }
55
+ exports.default = SyncTransactionStatusTask;
@@ -6,23 +6,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Tasks = void 0;
7
7
  const ProcessDepositEvents_1 = __importDefault(require("./InteropXGateway/ProcessDepositEvents"));
8
8
  const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
9
- const SyncWithdrawEvents_1 = __importDefault(require("./InteropBridge/SyncWithdrawEvents"));
9
+ const SyncWithdrawtEvents_1 = __importDefault(require("./InteropXGateway/SyncWithdrawtEvents"));
10
10
  const ProcessWithdrawEvents_1 = __importDefault(require("./InteropBridge/ProcessWithdrawEvents"));
11
+ const SyncBurnEvents_1 = __importDefault(require("./InteropBridge/SyncBurnEvents"));
12
+ const SyncMintEvents_1 = __importDefault(require("./InteropBridge/SyncMintEvents"));
13
+ const SyncTransactionStatusTask_1 = __importDefault(require("./Transactions/SyncTransactionStatusTask"));
14
+ const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
11
15
  class Tasks {
12
16
  constructor() {
13
17
  this.tasks = [
18
+ new SyncTransactionStatusTask_1.default(),
19
+ new AutoUpdateTask_1.default(),
20
+ // InteropXGateway
14
21
  new SyncDepositEvents_1.default({
15
22
  chainId: 43114
16
23
  }),
17
24
  new ProcessDepositEvents_1.default({
18
25
  chainId: 43114
19
26
  }),
20
- new SyncWithdrawEvents_1.default({
21
- chainId: 137,
22
- itokenAddress: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
27
+ new SyncWithdrawtEvents_1.default({
28
+ chainId: 43114
23
29
  }),
30
+ // InteropBridge
24
31
  new ProcessWithdrawEvents_1.default({
25
32
  chainId: 137,
33
+ }),
34
+ new SyncMintEvents_1.default({
35
+ chainId: 137,
36
+ itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
37
+ }),
38
+ new SyncBurnEvents_1.default({
39
+ chainId: 137,
40
+ itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
26
41
  })
27
42
  ];
28
43
  }