@instadapp/interop-x 0.0.0-dev.75809ae → 0.0.0-dev.79c1ae5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. package/.env.example +2 -1
  2. package/dist/package.json +73 -0
  3. package/dist/src/abi/erc20.json +350 -0
  4. package/dist/src/abi/gnosisSafe.json +747 -0
  5. package/dist/src/abi/index.js +15 -0
  6. package/dist/src/abi/interopBridgeToken.json +286 -0
  7. package/dist/src/abi/interopXGateway.json +184 -0
  8. package/dist/src/api/index.js +33 -0
  9. package/dist/{config → src/config}/index.js +6 -1
  10. package/dist/src/constants/addresses.js +20 -0
  11. package/dist/{constants → src/constants}/index.js +2 -0
  12. package/dist/src/constants/itokens.js +13 -0
  13. package/dist/src/constants/tokens.js +107 -0
  14. package/dist/{db → src/db}/index.js +0 -0
  15. package/dist/{db → src/db}/models/index.js +1 -1
  16. package/dist/src/db/models/transaction.js +54 -0
  17. package/dist/{db → src/db}/sequelize.js +2 -1
  18. package/dist/src/index.js +103 -0
  19. package/dist/{logger → src/logger}/index.js +0 -0
  20. package/dist/{net → src/net}/index.js +0 -0
  21. package/dist/{net → src/net}/peer/index.js +11 -7
  22. package/dist/{net → src/net}/pool/index.js +29 -11
  23. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +1 -1
  24. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +22 -14
  25. package/dist/{net → src/net}/protocol/index.js +33 -4
  26. package/dist/src/tasks/AutoUpdateTask.js +43 -0
  27. package/dist/{tasks → src/tasks}/BaseTask.js +3 -3
  28. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +147 -0
  29. package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +70 -0
  30. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +150 -0
  31. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +75 -0
  32. package/dist/src/tasks/index.js +42 -0
  33. package/dist/src/typechain/Erc20.js +2 -0
  34. package/dist/src/typechain/GnosisSafe.js +2 -0
  35. package/dist/src/typechain/InteropBridgeToken.js +2 -0
  36. package/dist/src/typechain/InteropXGateway.js +2 -0
  37. package/dist/src/typechain/common.js +2 -0
  38. package/dist/src/typechain/factories/Erc20__factory.js +367 -0
  39. package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
  40. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +459 -0
  41. package/dist/src/typechain/factories/InteropXGateway__factory.js +265 -0
  42. package/dist/src/typechain/factories/index.js +14 -0
  43. package/dist/src/typechain/index.js +35 -0
  44. package/dist/{types.js → src/types.js} +0 -0
  45. package/dist/src/utils/index.js +228 -0
  46. package/package.json +20 -6
  47. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  48. package/src/abi/erc20.json +350 -0
  49. package/src/abi/gnosisSafe.json +747 -0
  50. package/src/abi/index.ts +11 -0
  51. package/src/abi/interopBridgeToken.json +286 -0
  52. package/src/abi/interopXGateway.json +184 -0
  53. package/src/api/index.ts +33 -0
  54. package/src/config/index.ts +9 -1
  55. package/src/constants/addresses.ts +9 -2
  56. package/src/constants/index.ts +2 -0
  57. package/src/constants/itokens.ts +10 -0
  58. package/src/constants/tokens.ts +104 -0
  59. package/src/db/index.ts +1 -1
  60. package/src/db/models/index.ts +1 -1
  61. package/src/db/models/transaction.ts +96 -0
  62. package/src/db/sequelize.ts +2 -1
  63. package/src/index.ts +90 -6
  64. package/src/net/peer/index.ts +10 -9
  65. package/src/net/pool/index.ts +39 -13
  66. package/src/net/protocol/dial/BaseDialProtocol.ts +1 -1
  67. package/src/net/protocol/dial/SignatureDialProtocol.ts +26 -17
  68. package/src/net/protocol/index.ts +48 -4
  69. package/src/tasks/AutoUpdateTask.ts +55 -0
  70. package/src/tasks/BaseTask.ts +3 -4
  71. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +233 -0
  72. package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +121 -0
  73. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +245 -0
  74. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +126 -0
  75. package/src/tasks/index.ts +24 -1
  76. package/src/typechain/Erc20.ts +491 -0
  77. package/src/typechain/GnosisSafe.ts +1728 -0
  78. package/src/typechain/InteropBridgeToken.ts +686 -0
  79. package/src/typechain/InteropXGateway.ts +407 -0
  80. package/src/typechain/common.ts +44 -0
  81. package/src/typechain/factories/Erc20__factory.ts +368 -0
  82. package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
  83. package/src/typechain/factories/InteropBridgeToken__factory.ts +466 -0
  84. package/src/typechain/factories/InteropXGateway__factory.ts +272 -0
  85. package/src/typechain/factories/index.ts +7 -0
  86. package/src/typechain/index.ts +12 -0
  87. package/src/types.ts +2 -2
  88. package/src/utils/index.ts +193 -2
  89. package/tsconfig.json +3 -0
  90. package/dist/constants/addresses.js +0 -13
  91. package/dist/db/models/execution.js +0 -38
  92. package/dist/index.js +0 -34
  93. package/dist/tasks/index.js +0 -19
  94. package/dist/utils/index.js +0 -89
  95. package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tokens = void 0;
4
+ exports.tokens = {
5
+ 1: [
6
+ {
7
+ symbol: "ETH",
8
+ name: "Ethereum",
9
+ address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
10
+ decimals: 18,
11
+ },
12
+ {
13
+ symbol: "DAI",
14
+ name: "DAI Stable",
15
+ address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
16
+ decimals: 18,
17
+ },
18
+ {
19
+ symbol: "USDC",
20
+ name: "USD Coin",
21
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
22
+ decimals: 6,
23
+ },
24
+ {
25
+ symbol: "USDT",
26
+ name: "Tether USD Coin",
27
+ address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
28
+ decimals: 6,
29
+ },
30
+ {
31
+ symbol: "WBTC",
32
+ name: "Wrapped BTC",
33
+ address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
34
+ decimals: 8,
35
+ },
36
+ ],
37
+ 137: [
38
+ {
39
+ symbol: "ETH",
40
+ name: "Ethereum",
41
+ address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
42
+ decimals: 18,
43
+ },
44
+ {
45
+ symbol: "DAI",
46
+ name: "DAI Stable",
47
+ address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
48
+ decimals: 18,
49
+ },
50
+ {
51
+ symbol: "USDC",
52
+ name: "USD Coin",
53
+ address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
54
+ decimals: 6,
55
+ },
56
+ {
57
+ symbol: "USDT",
58
+ name: "Tether USD Coin",
59
+ address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
60
+ decimals: 6,
61
+ },
62
+ {
63
+ symbol: "WBTC",
64
+ name: "Wrapped BTC",
65
+ address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
66
+ decimals: 8,
67
+ },
68
+ {
69
+ symbol: "AVAX",
70
+ name: "Avalanche Token",
71
+ address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
72
+ decimals: 18,
73
+ },
74
+ ],
75
+ 43114: [
76
+ {
77
+ symbol: "ETH",
78
+ name: "Ethereum",
79
+ address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
80
+ decimals: 18,
81
+ },
82
+ {
83
+ symbol: "DAI",
84
+ name: "DAI Stable",
85
+ address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
86
+ decimals: 18,
87
+ },
88
+ {
89
+ symbol: "USDC",
90
+ name: "USD Coin",
91
+ address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
92
+ decimals: 6,
93
+ },
94
+ {
95
+ symbol: "USDT",
96
+ name: "Tether USD Coin",
97
+ address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
98
+ decimals: 6,
99
+ },
100
+ {
101
+ symbol: "WBTC",
102
+ name: "Wrapped BTC",
103
+ address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
104
+ decimals: 8,
105
+ },
106
+ ],
107
+ };
File without changes
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./execution"), exports);
17
+ __exportStar(require("./transaction"), exports);
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Transaction = void 0;
4
+ const sequelize_1 = require("@/db/sequelize");
5
+ const sequelize_2 = require("sequelize");
6
+ class Transaction extends sequelize_2.Model {
7
+ }
8
+ exports.Transaction = Transaction;
9
+ Transaction.init({
10
+ id: {
11
+ type: sequelize_2.DataTypes.INTEGER,
12
+ autoIncrement: true,
13
+ primaryKey: true
14
+ },
15
+ submitTransactionHash: sequelize_2.DataTypes.NUMBER,
16
+ submitBlockNumber: sequelize_2.DataTypes.NUMBER,
17
+ transactionHash: sequelize_2.DataTypes.STRING,
18
+ action: sequelize_2.DataTypes.STRING,
19
+ from: sequelize_2.DataTypes.STRING,
20
+ to: sequelize_2.DataTypes.STRING,
21
+ sourceChainId: sequelize_2.DataTypes.NUMBER,
22
+ sourceTransactionHash: sequelize_2.DataTypes.STRING,
23
+ sourceBlockNumber: sequelize_2.DataTypes.NUMBER,
24
+ sourceStatus: sequelize_2.DataTypes.STRING,
25
+ sourceErrors: {
26
+ type: sequelize_2.DataTypes.JSON,
27
+ // defaultValue: [],
28
+ },
29
+ sourceCreatedAt: {
30
+ type: sequelize_2.DataTypes.DATE,
31
+ defaultValue: Date.now()
32
+ },
33
+ sourceDelayUntil: sequelize_2.DataTypes.STRING,
34
+ targetChainId: sequelize_2.DataTypes.NUMBER,
35
+ targetTransactionHash: sequelize_2.DataTypes.STRING,
36
+ targetBlockNumber: sequelize_2.DataTypes.NUMBER,
37
+ targetStatus: sequelize_2.DataTypes.STRING,
38
+ targetErrors: {
39
+ type: sequelize_2.DataTypes.JSON,
40
+ // defaultValue: [],
41
+ },
42
+ targetCreatedAt: sequelize_2.DataTypes.DATE,
43
+ targetDelayUntil: sequelize_2.DataTypes.DATE,
44
+ submitEvent: sequelize_2.DataTypes.JSON,
45
+ sourceEvent: sequelize_2.DataTypes.JSON,
46
+ targetEvent: sequelize_2.DataTypes.JSON,
47
+ metadata: sequelize_2.DataTypes.JSON,
48
+ status: {
49
+ type: sequelize_2.DataTypes.STRING,
50
+ defaultValue: 'pending'
51
+ },
52
+ createdAt: sequelize_2.DataTypes.DATE,
53
+ updatedAt: sequelize_2.DataTypes.DATE,
54
+ }, { sequelize: sequelize_1.sequelize, tableName: 'transactions' });
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.sequelize = void 0;
7
7
  //@ts-ignore
8
+ const config_1 = __importDefault(require("@/config"));
8
9
  const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
9
10
  const sequelize_1 = require("sequelize");
10
- const basePath = (0, expand_home_dir_1.default)('~/.interop-x/data');
11
+ const basePath = (0, expand_home_dir_1.default)(`~/.interop-x/data/${config_1.default.publicAddress}/${config_1.default.staging ? 'staging' : ''}`);
11
12
  exports.sequelize = new sequelize_1.Sequelize({
12
13
  dialect: 'sqlite',
13
14
  storage: `${basePath}/localDB.sqlite`,
@@ -0,0 +1,103 @@
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 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)();
22
+ const dotenv_1 = __importDefault(require("dotenv"));
23
+ const chalk_1 = __importDefault(require("chalk"));
24
+ const ethers_1 = require("ethers");
25
+ const package_json_1 = __importDefault(require("../package.json"));
26
+ dotenv_1.default.config();
27
+ const logger_1 = __importDefault(require("@/logger"));
28
+ const logger = new logger_1.default('Process');
29
+ const printUsage = () => {
30
+ 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');
35
+ };
36
+ if (process.argv.at(-1) === 'help') {
37
+ printUsage();
38
+ process.exit(0);
39
+ }
40
+ const GIT_SHORT_HASH = '79c1ae5';
41
+ if (process.argv.at(-1) === 'version') {
42
+ console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
43
+ process.exit(0);
44
+ }
45
+ if (!process.env.PRIVATE_KEY) {
46
+ console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
47
+ printUsage();
48
+ process.exit(1);
49
+ }
50
+ try {
51
+ new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
52
+ }
53
+ catch (e) {
54
+ console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
55
+ printUsage();
56
+ process.exit(1);
57
+ }
58
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
59
+ const tasks_1 = require("@/tasks");
60
+ const net_1 = require("@/net");
61
+ const api_1 = require("@/api");
62
+ const db_1 = require("./db");
63
+ async function main() {
64
+ (0, net_1.startPeer)({});
65
+ const tasks = new tasks_1.Tasks();
66
+ tasks.start();
67
+ (0, api_1.startApiServer)();
68
+ net_1.protocol.on('TransactionStatus', async (payload) => {
69
+ if (!net_1.peerPool.isLeadNode(payload.peerId)) {
70
+ const peer = net_1.peerPool.getPeer(payload.peerId);
71
+ logger.info(`ignored transaction status from ${payload.peerId} ${peer === null || peer === void 0 ? void 0 : peer.publicAddress} `);
72
+ return;
73
+ }
74
+ const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
75
+ if (!transaction) {
76
+ return;
77
+ }
78
+ transaction.sourceStatus = payload.data.sourceStatus;
79
+ transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
80
+ transaction.sourceErrors = payload.data.sourceErrors;
81
+ transaction.targetStatus = payload.data.targetStatus;
82
+ transaction.targetTransactionHash = payload.data.targetTransactionHash;
83
+ transaction.targetErrors = payload.data.targetErrors;
84
+ transaction.status = payload.data.status;
85
+ await transaction.save();
86
+ });
87
+ }
88
+ main()
89
+ .then(() => {
90
+ }).catch(err => {
91
+ console.error(err);
92
+ });
93
+ process.on('SIGINT', () => {
94
+ logger.debug('received SIGINT signal. exiting.');
95
+ process.exit(0);
96
+ });
97
+ process.on('SIGTERM', () => {
98
+ logger.debug('received SIGTERM signal. exiting.');
99
+ process.exit(0);
100
+ });
101
+ process.on('unhandledRejection', (reason, p) => {
102
+ logger.error('unhandled rejection: promise:', p, 'reason:', reason);
103
+ });
File without changes
File without changes
@@ -11,7 +11,7 @@ const libp2p_websockets_1 = __importDefault(require("libp2p-websockets"));
11
11
  //@ts-ignore
12
12
  const libp2p_mplex_1 = __importDefault(require("libp2p-mplex"));
13
13
  const libp2p_noise_1 = require("libp2p-noise");
14
- const logger_1 = __importDefault(require("../../logger"));
14
+ const logger_1 = __importDefault(require("@/logger"));
15
15
  const libp2p_bootstrap_1 = __importDefault(require("libp2p-bootstrap"));
16
16
  const waait_1 = __importDefault(require("waait"));
17
17
  const libp2p_gossipsub_1 = __importDefault(require("@achingbrain/libp2p-gossipsub"));
@@ -21,8 +21,8 @@ const libp2p_mdns_1 = __importDefault(require("libp2p-mdns"));
21
21
  const libp2p_kad_dht_1 = __importDefault(require("libp2p-kad-dht"));
22
22
  //@ts-ignore
23
23
  const libp2p_pubsub_peer_discovery_1 = __importDefault(require("libp2p-pubsub-peer-discovery"));
24
- const protocol_1 = require("../protocol");
25
- const config_1 = __importDefault(require("../../config"));
24
+ const net_1 = require("@/net");
25
+ const config_1 = __importDefault(require("@/config"));
26
26
  const logger = new logger_1.default("Peer");
27
27
  let node;
28
28
  // Known peers addresses
@@ -79,14 +79,18 @@ const startPeer = async ({}) => {
79
79
  });
80
80
  logger.info("Peer ID:", node.peerId.toB58String());
81
81
  await node.start();
82
- protocol_1.protocol.start({
82
+ net_1.protocol.start({
83
83
  libp2p: node
84
84
  });
85
- node.on("peer:discovery", (peer) => logger.log(`Discovered peer ${peer}`)); // peer disc.
86
- node.connectionManager.on("peer:connect", (connection) => logger.log(`Connected to ${connection.remotePeer.toB58String()}`));
85
+ node.on("peer:discovery", (peer) => {
86
+ // logger.log(`Discovered peer ${peer}`)
87
+ }); // peer disc.
88
+ node.connectionManager.on("peer:connect", (connection) => {
89
+ // logger.log(`Connected to ${connection.remotePeer.toB58String()}`)
90
+ });
87
91
  logger.log("Peer discovery started");
88
92
  await (0, waait_1.default)(1000);
89
- setInterval(() => protocol_1.protocol.sendPeerInfo({
93
+ setInterval(() => net_1.protocol.sendPeerInfo({
90
94
  publicAddress: config_1.default.wallet.address,
91
95
  }), 5000);
92
96
  };
@@ -4,8 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.peerPool = exports.PeerPool = void 0;
7
- const types_1 = require("../../types");
8
- const config_1 = __importDefault(require("../../config"));
7
+ const types_1 = require("@/types");
8
+ const config_1 = __importDefault(require("@/config"));
9
+ const logger_1 = __importDefault(require("@/logger"));
10
+ const utils_1 = require("ethers/lib/utils");
11
+ const logger = new logger_1.default('PeerPool');
9
12
  class PeerPool {
10
13
  constructor() {
11
14
  this.PEERS_CLEANUP_TIME_LIMIT = 1;
@@ -62,10 +65,14 @@ class PeerPool {
62
65
  * @emits {@link Event.POOL_PEER_ADDED}
63
66
  */
64
67
  add(peer) {
65
- if (peer && peer.id && !this.pool.get(peer.id)) {
68
+ if (peer && peer.id) {
69
+ const newPeer = !this.pool.get(peer.id);
66
70
  this.pool.set(peer.id, peer);
67
71
  peer.pooled = true;
68
- config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
72
+ if (newPeer) {
73
+ 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`);
75
+ }
69
76
  }
70
77
  }
71
78
  /**
@@ -78,6 +85,7 @@ class PeerPool {
78
85
  if (this.pool.delete(peer.id)) {
79
86
  peer.pooled = false;
80
87
  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`);
81
89
  }
82
90
  }
83
91
  }
@@ -93,14 +101,24 @@ class PeerPool {
93
101
  get activePeerIds() {
94
102
  return this.activePeers.map((p) => p.id);
95
103
  }
104
+ getPeer(id) {
105
+ return this.pool.get(id);
106
+ }
107
+ isLeadNode(id) {
108
+ const peer = this.pool.get(id);
109
+ if (!peer) {
110
+ return false;
111
+ }
112
+ return (0, utils_1.getAddress)(peer.publicAddress) === (0, utils_1.getAddress)(config_1.default.leadNodeAddress);
113
+ }
96
114
  cleanup() {
97
- let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60;
98
- this.peers.forEach((peerInfo) => {
99
- if (peerInfo.updated.getTime() < compDate) {
100
- console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`);
101
- this.remove(peerInfo);
102
- }
103
- });
115
+ // let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
116
+ // this.peers.forEach((peerInfo) => {
117
+ // if (peerInfo.updated.getTime() < compDate) {
118
+ // console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
119
+ // this.remove(peerInfo)
120
+ // }
121
+ // })
104
122
  }
105
123
  }
106
124
  exports.PeerPool = PeerPool;
@@ -13,7 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.BaseDialProtocol = void 0;
14
14
  const it_pipe_1 = __importDefault(require("it-pipe"));
15
15
  const peer_id_1 = __importDefault(require("peer-id"));
16
- const utils_1 = require("../../../utils");
16
+ const utils_1 = require("@/utils");
17
17
  const waait_1 = __importDefault(require("waait"));
18
18
  class BaseDialProtocol {
19
19
  constructor(libp2p, protocol) {
@@ -4,44 +4,52 @@ 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
- const config_1 = __importDefault(require("config"));
11
- const constants_1 = require("../../../constants");
12
- const db_1 = require("db");
9
+ const config_1 = __importDefault(require("@/config"));
10
+ const db_1 = require("@/db");
11
+ const utils_1 = require("@/utils");
12
+ const constants_1 = require("@/constants");
13
13
  class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
14
14
  constructor(libp2p) {
15
- super(libp2p, '/signatures');
15
+ super(libp2p, '/interop-x/signatures');
16
16
  this.timeout = 30000;
17
17
  }
18
18
  async response(data) {
19
19
  const signer = config_1.default.wallet;
20
- let event;
20
+ let transaction;
21
21
  let maxTimeout = 20000;
22
22
  do {
23
- event = await db_1.Execution.findOne({ where: { vnonce: data.vnonce.toString() } });
24
- if (!event) {
23
+ transaction = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
24
+ if (!transaction) {
25
25
  await (0, waait_1.default)(1000);
26
26
  maxTimeout -= 1000;
27
27
  }
28
- } while (!event && maxTimeout > 0);
29
- if (!event) {
28
+ } while (!transaction && maxTimeout > 0);
29
+ if (!transaction) {
30
30
  return {
31
31
  signer: signer.address,
32
32
  data: null,
33
33
  error: 'Event not found'
34
34
  };
35
35
  }
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
+ });
36
43
  const signedData = await (0, utils_1.signGnosisSafeTx)({
37
- to: constants_1.addresses[event.chainId].multisend,
38
- data: 'TODO',
39
- chainId: event.chainId,
44
+ to: constants_1.addresses[transaction.targetChainId].multisend,
45
+ data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
46
+ chainId: transaction.targetChainId,
40
47
  safeTxGas: data.safeTxGas,
48
+ nonce: data.safeNonce,
41
49
  }, { signer });
42
50
  return {
43
51
  signer: signer.address,
44
- data: signedData,
52
+ data: signedData
45
53
  };
46
54
  }
47
55
  }
@@ -8,15 +8,15 @@ 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);
16
16
  this.protocolMessages = [
17
17
  {
18
18
  name: 'PeerInfo',
19
- code: 0x09,
19
+ code: 0x01,
20
20
  encode: (info) => [
21
21
  Buffer.from(info.publicAddress),
22
22
  ],
@@ -24,11 +24,35 @@ class Protocol extends stream_1.EventEmitter {
24
24
  publicAddress: publicAddress.toString(),
25
25
  }),
26
26
  },
27
+ {
28
+ name: 'TransactionStatus',
29
+ code: 0x02,
30
+ encode: (transaction) => [
31
+ Buffer.from(transaction.transactionHash),
32
+ Buffer.from(transaction.sourceStatus),
33
+ Buffer.from(transaction.sourceTransactionHash),
34
+ transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
35
+ Buffer.from(transaction.targetStatus),
36
+ Buffer.from(transaction.targetTransactionHash),
37
+ transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
38
+ Buffer.from(transaction.status),
39
+ ],
40
+ decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
41
+ transactionHash: transactionHash.toString(),
42
+ sourceStatus: sourceStatus.toString(),
43
+ sourceTransactionHash: sourceTransactionHash.toString(),
44
+ sourceErrors: sourceErrors.map((e) => e.toString()),
45
+ targetStatus: targetStatus.toString(),
46
+ targetTransactionHash: targetTransactionHash.toString(),
47
+ targetErrors: targetErrors.map((e) => e.toString()),
48
+ status: status.toString(),
49
+ }),
50
+ },
27
51
  ];
28
52
  }
29
53
  start({ libp2p, topic = null, }) {
30
54
  this.libp2p = libp2p;
31
- this.topic = topic || 'protocol';
55
+ this.topic = topic || 'itnerop-x-protocol';
32
56
  if (this.libp2p.isStarted())
33
57
  this.init();
34
58
  this.on('PeerInfo', (payload) => {
@@ -75,6 +99,11 @@ class Protocol extends stream_1.EventEmitter {
75
99
  const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(data)]);
76
100
  this.libp2p.pubsub.publish(this.topic, encoded);
77
101
  }
102
+ sendTransaction(transaction) {
103
+ const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
104
+ const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
105
+ this.libp2p.pubsub.publish(this.topic, encoded);
106
+ }
78
107
  async requestSignatures(data, peerIds) {
79
108
  try {
80
109
  peerIds = peerIds || __1.peerPool.activePeerIds;
@@ -0,0 +1,43 @@
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 package_json_1 = __importDefault(require("../../package.json"));
9
+ const utils_1 = require("@/utils");
10
+ const await_spawn_1 = __importDefault(require("await-spawn"));
11
+ const config_1 = __importDefault(require("@/config"));
12
+ const waait_1 = __importDefault(require("waait"));
13
+ const currentVersion = package_json_1.default.version;
14
+ class AutoUpdateTask extends BaseTask_1.BaseTask {
15
+ constructor() {
16
+ super({
17
+ logger: new logger_1.default("AutoUpdateTask"),
18
+ });
19
+ this.pollIntervalMs = 60 * 1000;
20
+ }
21
+ prePollHandler() {
22
+ return config_1.default.autoUpdate && !config_1.default.isLeadNode();
23
+ }
24
+ async pollHandler() {
25
+ const { data } = await utils_1.http.get('https://registry.npmjs.org/@instadapp/interop-x');
26
+ const version = data['dist-tags'].latest;
27
+ if (version === currentVersion) {
28
+ return;
29
+ }
30
+ this.logger.warn(`New version ${version} available.`);
31
+ await (0, await_spawn_1.default)('npm', ['-g', 'install', '@instadapp/interop-x']);
32
+ this.logger.warn(`Installed version ${version}`);
33
+ this.logger.warn(`Restarting...`);
34
+ await (0, waait_1.default)(1000);
35
+ console.log(process.argv[0], process.argv.slice(1));
36
+ (0, await_spawn_1.default)(process.argv[0], process.argv.slice(1), {
37
+ cwd: process.cwd(),
38
+ stdio: "inherit"
39
+ });
40
+ process.exit();
41
+ }
42
+ }
43
+ exports.default = AutoUpdateTask;
@@ -4,10 +4,10 @@ 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
- const logger_1 = __importDefault(require("../logger"));
10
+ const logger_1 = __importDefault(require("@/logger"));
11
11
  class BaseTask extends events_1.default {
12
12
  constructor({ logger }) {
13
13
  super();
@@ -28,7 +28,7 @@ class BaseTask extends events_1.default {
28
28
  }
29
29
  }
30
30
  catch (err) {
31
- this.logger.error(`poll check error: ${err.message}\ntrace: ${err.stack}`);
31
+ this.logger.error(`poll check error:\n${err.message}\ntrace: ${err.stack}`);
32
32
  }
33
33
  await this.postPollHandler();
34
34
  }