@instadapp/interop-x 0.0.0-dev.285d847 → 0.0.0-dev.28f049d

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 (78) hide show
  1. package/dist/package.json +5 -4
  2. package/dist/src/abi/index.js +2 -4
  3. package/dist/src/abi/interopXContract.json +391 -0
  4. package/dist/src/alias.js +10 -0
  5. package/dist/src/api/index.js +6 -3
  6. package/dist/src/config/index.js +10 -1
  7. package/dist/src/constants/addresses.js +3 -3
  8. package/dist/src/constants/index.js +0 -1
  9. package/dist/src/db/models/transaction.js +27 -9
  10. package/dist/src/gnosis/actions/index.js +9 -0
  11. package/dist/src/gnosis/actions/withdraw/index.js +41 -0
  12. package/dist/src/gnosis/index.js +20 -0
  13. package/dist/src/index.js +38 -23
  14. package/dist/src/net/peer/index.js +2 -1
  15. package/dist/src/net/pool/index.js +7 -2
  16. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
  17. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  18. package/dist/src/net/protocol/index.js +26 -5
  19. package/dist/src/tasks/AutoUpdateTask.js +42 -16
  20. package/dist/src/tasks/BaseTask.js +11 -3
  21. package/dist/src/tasks/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +42 -46
  22. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  23. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  24. package/dist/src/tasks/index.js +8 -17
  25. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  26. package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
  27. package/dist/src/typechain/factories/index.js +3 -5
  28. package/dist/src/typechain/index.js +3 -5
  29. package/dist/src/utils/index.js +27 -87
  30. package/package.json +5 -4
  31. package/src/abi/index.ts +2 -4
  32. package/src/abi/interopXContract.json +391 -0
  33. package/src/alias.ts +6 -0
  34. package/src/api/index.ts +5 -2
  35. package/src/config/index.ts +9 -1
  36. package/src/constants/addresses.ts +3 -3
  37. package/src/constants/index.ts +0 -1
  38. package/src/db/models/transaction.ts +59 -21
  39. package/src/gnosis/actions/index.ts +5 -0
  40. package/src/gnosis/actions/withdraw/index.ts +56 -0
  41. package/src/gnosis/index.ts +19 -0
  42. package/src/index.ts +52 -25
  43. package/src/net/peer/index.ts +2 -1
  44. package/src/net/pool/index.ts +7 -3
  45. package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
  46. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  47. package/src/net/protocol/index.ts +28 -6
  48. package/src/tasks/AutoUpdateTask.ts +48 -20
  49. package/src/tasks/BaseTask.ts +13 -3
  50. package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +66 -91
  51. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
  52. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  53. package/src/tasks/index.ts +10 -18
  54. package/src/typechain/InteropXContract.ts +524 -0
  55. package/src/typechain/factories/InteropXContract__factory.ts +533 -0
  56. package/src/typechain/factories/index.ts +1 -2
  57. package/src/typechain/index.ts +2 -4
  58. package/src/utils/index.ts +61 -128
  59. package/tsconfig.json +7 -2
  60. package/dist/src/abi/interopBridgeToken.json +0 -286
  61. package/dist/src/abi/interopXGateway.json +0 -184
  62. package/dist/src/constants/itokens.js +0 -13
  63. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -147
  64. package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -70
  65. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
  66. package/dist/src/typechain/InteropXGateway.js +0 -2
  67. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
  68. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  69. package/src/abi/interopBridgeToken.json +0 -286
  70. package/src/abi/interopXGateway.json +0 -184
  71. package/src/constants/itokens.ts +0 -10
  72. package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -121
  73. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -245
  74. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
  75. package/src/typechain/InteropBridgeToken.ts +0 -686
  76. package/src/typechain/InteropXGateway.ts +0 -407
  77. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  78. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -0,0 +1,20 @@
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
+ exports.buildGnosisAction = void 0;
7
+ const ethers_multisend_1 = require("ethers-multisend");
8
+ const actions_1 = __importDefault(require("./actions"));
9
+ const buildGnosisAction = async (transaction, type) => {
10
+ type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
11
+ if (actions_1.default.hasOwnProperty(transaction.action)) {
12
+ const { transactions, logs } = await actions_1.default[transaction.action](transaction, type);
13
+ return {
14
+ data: (0, ethers_multisend_1.encodeMulti)(transactions).data,
15
+ logs
16
+ };
17
+ }
18
+ throw new Error(`Unknown action: ${transaction.action}`);
19
+ };
20
+ exports.buildGnosisAction = buildGnosisAction;
package/dist/src/index.js CHANGED
@@ -3,22 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const module_alias_1 = __importDefault(require("module-alias"));
7
- module_alias_1.default.addAliases({
8
- "@/": __dirname + "/",
9
- "@/logger": __dirname + "/logger",
10
- "@/tasks": __dirname + "/tasks",
11
- "@/utils": __dirname + "/utils",
12
- "@/api": __dirname + "/api",
13
- "@/net": __dirname + "/net",
14
- "@/db": __dirname + "/db",
15
- "@/config": __dirname + "/config",
16
- "@/types": __dirname + "/types",
17
- "@/abi": __dirname + "/abi",
18
- "@/constants": __dirname + "/constants",
19
- "@/typechain": __dirname + "/typechain"
20
- });
21
- (0, module_alias_1.default)();
6
+ require("./alias");
7
+ const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
22
9
  const dotenv_1 = __importDefault(require("dotenv"));
23
10
  const chalk_1 = __importDefault(require("chalk"));
24
11
  const ethers_1 = require("ethers");
@@ -26,19 +13,41 @@ const package_json_1 = __importDefault(require("../package.json"));
26
13
  dotenv_1.default.config();
27
14
  const logger_1 = __importDefault(require("@/logger"));
28
15
  const logger = new logger_1.default('Process');
16
+ const GIT_SHORT_HASH = '28f049d';
29
17
  const printUsage = () => {
18
+ console.log();
19
+ console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
20
+ console.log();
30
21
  console.log('Usage:');
31
- console.log(' PRIVATE_KEY=abcd1234 interop-x');
32
- console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x');
33
- console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x');
34
- console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x');
22
+ console.log(' interop-x help Show this message');
23
+ console.log(' interop-x version Print out the installed version of Interop X');
24
+ console.log();
25
+ console.log(' interop-x down Put the node into maintenance mode');
26
+ console.log(' interop-x up Take the node out of maintenance mode');
27
+ console.log();
28
+ console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key');
29
+ console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode');
30
+ console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode');
31
+ console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x Start the node with custom API host and port');
32
+ console.log();
35
33
  };
36
34
  if (process.argv.at(-1) === 'help') {
37
35
  printUsage();
38
36
  process.exit(0);
39
37
  }
38
+ const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
39
+ if (process.argv.at(-1) === 'down') {
40
+ fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
41
+ console.log(chalk_1.default.red('Maintenance mode enabled'));
42
+ process.exit(0);
43
+ }
44
+ if (process.argv.at(-1) === 'up') {
45
+ fs_extra_1.default.removeSync(basePath + '/maintenance');
46
+ console.log(chalk_1.default.green('Maintenance mode disabled'));
47
+ process.exit(0);
48
+ }
40
49
  if (process.argv.at(-1) === 'version') {
41
- console.log(`Interop X Node (v${package_json_1.default.version} - rev.285d847)`);
50
+ console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
42
51
  process.exit(0);
43
52
  }
44
53
  if (!process.env.PRIVATE_KEY) {
@@ -54,11 +63,12 @@ catch (e) {
54
63
  printUsage();
55
64
  process.exit(1);
56
65
  }
57
- logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.@GIT_SHORT_HASH@)`);
66
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
58
67
  const tasks_1 = require("@/tasks");
59
68
  const net_1 = require("@/net");
60
69
  const api_1 = require("@/api");
61
70
  const db_1 = require("./db");
71
+ const utils_1 = require("./utils");
62
72
  async function main() {
63
73
  (0, net_1.startPeer)({});
64
74
  const tasks = new tasks_1.Tasks();
@@ -67,7 +77,10 @@ async function main() {
67
77
  net_1.protocol.on('TransactionStatus', async (payload) => {
68
78
  if (!net_1.peerPool.isLeadNode(payload.peerId)) {
69
79
  const peer = net_1.peerPool.getPeer(payload.peerId);
70
- logger.info(`ignored transaction status from ${payload.peerId} ${peer === null || peer === void 0 ? void 0 : peer.publicAddress} `);
80
+ if (!peer) {
81
+ return;
82
+ }
83
+ logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
71
84
  return;
72
85
  }
73
86
  const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
@@ -77,9 +90,11 @@ async function main() {
77
90
  transaction.sourceStatus = payload.data.sourceStatus;
78
91
  transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
79
92
  transaction.sourceErrors = payload.data.sourceErrors;
93
+ transaction.sourceLogs = payload.data.sourceLogs;
80
94
  transaction.targetStatus = payload.data.targetStatus;
81
95
  transaction.targetTransactionHash = payload.data.targetTransactionHash;
82
96
  transaction.targetErrors = payload.data.targetErrors;
97
+ transaction.targetLogs = payload.data.targetLogs;
83
98
  transaction.status = payload.data.status;
84
99
  await transaction.save();
85
100
  });
@@ -23,6 +23,7 @@ const libp2p_kad_dht_1 = __importDefault(require("libp2p-kad-dht"));
23
23
  const libp2p_pubsub_peer_discovery_1 = __importDefault(require("libp2p-pubsub-peer-discovery"));
24
24
  const net_1 = require("@/net");
25
25
  const config_1 = __importDefault(require("@/config"));
26
+ const chalk_1 = __importDefault(require("chalk"));
26
27
  const logger = new logger_1.default("Peer");
27
28
  let node;
28
29
  // Known peers addresses
@@ -77,7 +78,7 @@ const startPeer = async ({}) => {
77
78
  persistence: true,
78
79
  },
79
80
  });
80
- logger.info("Peer ID:", node.peerId.toB58String());
81
+ logger.info("Peer ID:", chalk_1.default.bold(node.peerId.toB58String()));
81
82
  await node.start();
82
83
  net_1.protocol.start({
83
84
  libp2p: node
@@ -8,6 +8,8 @@ const types_1 = require("@/types");
8
8
  const config_1 = __importDefault(require("@/config"));
9
9
  const logger_1 = __importDefault(require("@/logger"));
10
10
  const utils_1 = require("ethers/lib/utils");
11
+ const utils_2 = require("@/utils");
12
+ const chalk_1 = __importDefault(require("chalk"));
11
13
  const logger = new logger_1.default('PeerPool');
12
14
  class PeerPool {
13
15
  constructor() {
@@ -71,7 +73,7 @@ class PeerPool {
71
73
  peer.pooled = true;
72
74
  if (newPeer) {
73
75
  config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
74
- logger.info(`Peer ${peer.id} with address ${peer.publicAddress} added to pool`);
76
+ logger.info(`Peer ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.id, 16))} with address ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.publicAddress))} added to pool`);
75
77
  }
76
78
  }
77
79
  }
@@ -85,7 +87,7 @@ class PeerPool {
85
87
  if (this.pool.delete(peer.id)) {
86
88
  peer.pooled = false;
87
89
  config_1.default.events.emit(types_1.Event.POOL_PEER_REMOVED, peer);
88
- logger.info(`Peer ${peer.id} with address ${peer.publicAddress} removed from pool`);
90
+ logger.info(`Peer ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.id, 16))} with address ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.publicAddress))} removed from pool`);
89
91
  }
90
92
  }
91
93
  }
@@ -111,6 +113,9 @@ class PeerPool {
111
113
  }
112
114
  return (0, utils_1.getAddress)(peer.publicAddress) === (0, utils_1.getAddress)(config_1.default.leadNodeAddress);
113
115
  }
116
+ getLeadPeer() {
117
+ return this.peers.find((p) => this.isLeadNode(p.id));
118
+ }
114
119
  cleanup() {
115
120
  // let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
116
121
  // this.peers.forEach((peerInfo) => {
@@ -10,6 +10,7 @@ const config_1 = __importDefault(require("@/config"));
10
10
  const db_1 = require("@/db");
11
11
  const utils_1 = require("@/utils");
12
12
  const constants_1 = require("@/constants");
13
+ const gnosis_1 = require("@/gnosis");
13
14
  class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
14
15
  constructor(libp2p) {
15
16
  super(libp2p, '/interop-x/signatures');
@@ -33,16 +34,10 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
33
34
  error: 'Event not found'
34
35
  };
35
36
  }
36
- console.log("signing:", {
37
- to: constants_1.addresses[transaction.targetChainId].multisend,
38
- data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
39
- chainId: transaction.targetChainId,
40
- safeTxGas: data.safeTxGas,
41
- nonce: data.safeNonce,
42
- });
37
+ const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
43
38
  const signedData = await (0, utils_1.signGnosisSafeTx)({
44
39
  to: constants_1.addresses[transaction.targetChainId].multisend,
45
- data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
40
+ data: gnosisData,
46
41
  chainId: transaction.targetChainId,
47
42
  safeTxGas: data.safeTxGas,
48
43
  nonce: data.safeNonce,
@@ -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,6 +10,7 @@ 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);
@@ -30,21 +31,31 @@ class Protocol extends stream_1.EventEmitter {
30
31
  encode: (transaction) => [
31
32
  Buffer.from(transaction.transactionHash),
32
33
  Buffer.from(transaction.sourceStatus),
33
- Buffer.from(transaction.sourceTransactionHash),
34
+ Buffer.from(transaction.sourceTransactionHash || ''),
34
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)]) : [],
35
37
  Buffer.from(transaction.targetStatus),
36
- Buffer.from(transaction.targetTransactionHash),
38
+ Buffer.from(transaction.targetTransactionHash || ''),
37
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)]) : [],
38
41
  Buffer.from(transaction.status),
39
42
  ],
40
- decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
43
+ decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
41
44
  transactionHash: transactionHash.toString(),
42
45
  sourceStatus: sourceStatus.toString(),
43
- sourceTransactionHash: sourceTransactionHash.toString(),
46
+ sourceTransactionHash: sourceTransactionHash.toString() || null,
44
47
  sourceErrors: sourceErrors.map((e) => e.toString()),
48
+ sourceLogs: sourceLogs.map(e => ({
49
+ type: e[0].toString(),
50
+ message: e[1].toString(),
51
+ })),
45
52
  targetStatus: targetStatus.toString(),
46
- targetTransactionHash: targetTransactionHash.toString(),
53
+ targetTransactionHash: targetTransactionHash.toString() || null,
47
54
  targetErrors: targetErrors.map((e) => e.toString()),
55
+ targetLogs: targetLogs.map(e => ({
56
+ type: e[0].toString(),
57
+ message: e[1].toString(),
58
+ })),
48
59
  status: status.toString(),
49
60
  }),
50
61
  },
@@ -64,6 +75,7 @@ class Protocol extends stream_1.EventEmitter {
64
75
  });
65
76
  });
66
77
  this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
78
+ this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
67
79
  }
68
80
  init() {
69
81
  this.libp2p.pubsub.subscribe(this.topic);
@@ -117,5 +129,14 @@ class Protocol extends stream_1.EventEmitter {
117
129
  return [];
118
130
  }
119
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
+ }
120
141
  }
121
142
  exports.protocol = new Protocol();
@@ -5,40 +5,66 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const BaseTask_1 = require("./BaseTask");
7
7
  const logger_1 = __importDefault(require("@/logger"));
8
- const package_json_1 = __importDefault(require("../../package.json"));
9
- const utils_1 = require("@/utils");
8
+ const await_spawn_1 = __importDefault(require("await-spawn"));
10
9
  const child_process_1 = require("child_process");
11
10
  const config_1 = __importDefault(require("@/config"));
11
+ const waait_1 = __importDefault(require("waait"));
12
+ const package_json_1 = __importDefault(require("../../package.json"));
12
13
  const currentVersion = package_json_1.default.version;
14
+ const tag = config_1.default.staging ? 'dev' : 'latest';
13
15
  class AutoUpdateTask extends BaseTask_1.BaseTask {
14
16
  constructor() {
15
17
  super({
16
18
  logger: new logger_1.default("AutoUpdateTask"),
17
19
  });
18
- this.pollIntervalMs = 60 * 1000;
20
+ this.pollIntervalMs = 60 * 10 * 1000;
19
21
  }
20
22
  prePollHandler() {
21
23
  return config_1.default.autoUpdate && !config_1.default.isLeadNode();
22
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
+ }
23
45
  async pollHandler() {
24
- const { data } = await utils_1.http.get('https://registry.npmjs.org/@instadapp/interop-x');
25
- const version = data['dist-tags'].latest;
46
+ const version = await this.getLatestVersion();
26
47
  if (version === currentVersion) {
27
48
  return;
28
49
  }
29
50
  this.logger.warn(`New version ${version} available.`);
30
- const update = (0, child_process_1.spawn)('npm', ['-g', 'install', '@instadapp/interop-x']);
31
- update.on("close", () => {
32
- this.logger.warn(`Installed version ${version}`);
33
- this.logger.warn(`Restarting...`);
34
- (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
35
- cwd: process.cwd(),
36
- env: Object.create(process.env),
37
- detached: true,
38
- stdio: "inherit"
39
- });
40
- process.exit();
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,
41
65
  });
66
+ subprocess.unref();
67
+ process.exit();
42
68
  }
43
69
  }
44
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');
@@ -10,23 +10,15 @@ const abi_1 = __importDefault(require("@/abi"));
10
10
  const db_1 = require("@/db");
11
11
  const utils_1 = require("@/utils");
12
12
  const constants_1 = require("@/constants");
13
- const config_1 = __importDefault(require("@/config"));
14
13
  const sequelize_1 = require("sequelize");
14
+ const config_1 = __importDefault(require("@/config"));
15
15
  const waait_1 = __importDefault(require("waait"));
16
+ const gnosis_1 = require("@/gnosis");
16
17
  const net_1 = require("@/net");
17
- const generateGnosisTransaction = async (transactionData, safeContract) => {
18
- console.log(transactionData);
19
- 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));
20
- while (isExecuted == 1) {
21
- transactionData.safeTxGas = ethers_1.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString();
22
- 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));
23
- }
24
- return transactionData;
25
- };
26
- class ProcessDepositEvents extends BaseTask_1.BaseTask {
18
+ class ProccessBridgeRequestEvents extends BaseTask_1.BaseTask {
27
19
  constructor({ chainId }) {
28
20
  super({
29
- logger: new logger_1.default("InteropXGateway::ProcessDepositEvents"),
21
+ logger: new logger_1.default("InteropXContract::ProccessBridgeRequestEvents"),
30
22
  });
31
23
  this.leadNodeOnly = true;
32
24
  this.chainId = chainId;
@@ -37,13 +29,11 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
37
29
  const transaction = await db_1.Transaction.findOne({
38
30
  where: {
39
31
  status: 'pending',
40
- sourceStatus: 'success',
41
- targetStatus: 'uninitialised',
42
- action: 'deposit',
32
+ sourceStatus: 'uninitialised',
43
33
  sourceCreatedAt: {
44
34
  [sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
45
35
  },
46
- targetDelayUntil: {
36
+ sourceDelayUntil: {
47
37
  [sequelize_1.Op.or]: {
48
38
  [sequelize_1.Op.is]: null,
49
39
  [sequelize_1.Op.lt]: new Date(),
@@ -61,27 +51,36 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
61
51
  console.log(`Processing transaction ${transaction.transactionHash}`);
62
52
  transaction.targetStatus = 'pending';
63
53
  await transaction.save();
64
- // refresh event data?
65
- const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
66
- const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
67
- const safeAddress = constants_1.addresses[transaction.targetChainId].gnosisSafe;
68
- const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
69
- const ownersThreshold = await safeContract.getThreshold();
54
+ const ownersThreshold = await this.safeContract.getThreshold();
70
55
  await (0, waait_1.default)(10000);
71
- let gnosisTx = await generateGnosisTransaction({
56
+ let data, logs = [];
57
+ try {
58
+ ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction));
59
+ }
60
+ catch (error) {
61
+ console.log(error);
62
+ transaction.sourceStatus = 'failed';
63
+ transaction.sourceErrors = [error.message];
64
+ transaction.targetStatus = 'failed';
65
+ transaction.status = 'failed';
66
+ await transaction.save();
67
+ net_1.protocol.sendTransaction(transaction);
68
+ return;
69
+ }
70
+ let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
72
71
  baseGas: "0",
73
- data: await (0, utils_1.buildDataForTransaction)(transaction),
72
+ data,
74
73
  gasPrice: "0",
75
74
  gasToken: "0x0000000000000000000000000000000000000000",
76
75
  nonce: '0',
77
76
  operation: "1",
78
77
  refundReceiver: "0x0000000000000000000000000000000000000000",
79
- safeAddress: safeAddress,
78
+ safeAddress: this.safeContractAddress,
80
79
  safeTxGas: "79668",
81
- to: constants_1.addresses[transaction.targetChainId].multisend,
80
+ to: constants_1.addresses[transaction.sourceChainId].multisend,
82
81
  value: "0",
83
- }, safeContract);
84
- const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
82
+ }, this.safeContract);
83
+ const owners = await this.safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
85
84
  const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
86
85
  console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
87
86
  console.log(ownerPeerIds);
@@ -95,31 +94,25 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
95
94
  console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
96
95
  if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
97
96
  await transaction.save();
98
- transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
99
- transaction.targetStatus = 'uninitialised';
97
+ transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
98
+ transaction.sourceStatus = 'uninitialised';
100
99
  await transaction.save();
101
100
  const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
102
101
  throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
103
102
  }
104
103
  console.log(`Executing transaction for execution ${transaction.transactionHash}`);
105
- const { data: txData } = await 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));
106
- console.log({
107
- from: targetWallet.address,
108
- gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9).toString(),
109
- to: safeAddress,
110
- data: txData,
111
- });
112
- const txSent = await targetWallet.sendTransaction({
113
- from: targetWallet.address,
114
- gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9),
115
- to: safeAddress,
104
+ 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));
105
+ const txSent = await this.sourceWallet.sendTransaction({
106
+ from: this.sourceWallet.address,
107
+ gasPrice: ethers_1.ethers.BigNumber.from(120 * 10 ** 9),
108
+ to: this.safeContractAddress,
116
109
  data: txData,
117
110
  });
118
111
  const receipt = await txSent.wait();
119
112
  const parsedLogs = [];
120
113
  receipt.logs.forEach((log) => {
121
114
  try {
122
- parsedLogs.push(safeContract.interface.parseLog(log));
115
+ parsedLogs.push(this.safeContract.interface.parseLog(log));
123
116
  }
124
117
  catch (e) { }
125
118
  });
@@ -127,6 +120,7 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
127
120
  console.log('ExecutionSuccess');
128
121
  transaction.targetStatus = 'success';
129
122
  transaction.targetTransactionHash = txSent.hash;
123
+ transaction.targetLogs = logs;
130
124
  transaction.status = 'success';
131
125
  await transaction.save();
132
126
  }
@@ -140,11 +134,13 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
140
134
  net_1.protocol.sendTransaction(transaction);
141
135
  }
142
136
  async start() {
143
- this.logger.info(`Starting execution watcher on interop chain`);
144
- this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
137
+ this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
145
138
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
146
- this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
139
+ this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider);
140
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, this.sourceWallet);
141
+ this.safeContractAddress = constants_1.addresses[this.chainId].gnosisSafe;
142
+ this.safeContract = (0, utils_1.getContract)(this.safeContractAddress, abi_1.default.gnosisSafe, this.sourceWallet);
147
143
  await super.start();
148
144
  }
149
145
  }
150
- exports.default = ProcessDepositEvents;
146
+ exports.default = ProccessBridgeRequestEvents;