@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
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.dc4f10a",
3
+ "version": "0.0.0-dev.de23e71",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -24,9 +24,10 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@achingbrain/libp2p-gossipsub": "^0.12.2",
27
+ "@fastify/cors": "^7.0.0",
28
+ "await-spawn": "^4.0.2",
27
29
  "axios": "^0.27.1",
28
30
  "axios-retry": "^3.2.4",
29
- "bignumber.js": "^9.0.2",
30
31
  "chalk": "4.1.2",
31
32
  "dotenv": "^16.0.0",
32
33
  "ethereumjs-util": "^7.1.4",
@@ -34,7 +35,7 @@
34
35
  "ethers-multisend": "^2.1.1",
35
36
  "expand-home-dir": "^0.0.3",
36
37
  "fastify": "^3.28.0",
37
- "fastify-cors": "^6.0.3",
38
+ "fs-extra": "^10.1.0",
38
39
  "libp2p": "^0.36.2",
39
40
  "libp2p-bootstrap": "^0.14.0",
40
41
  "libp2p-kad-dht": "^0.28.6",
@@ -46,6 +47,8 @@
46
47
  "libp2p-websockets": "^0.16.2",
47
48
  "luxon": "^2.3.2",
48
49
  "module-alias": "^2.2.2",
50
+ "patch-package": "^6.4.7",
51
+ "postinstall-postinstall": "^2.1.0",
49
52
  "sequelize": "6.18.0",
50
53
  "sqlite3": "^5.0.5",
51
54
  "waait": "^1.0.5"
@@ -60,8 +63,6 @@
60
63
  "@types/fs-extra": "^9.0.13",
61
64
  "@types/node": "^17.0.17",
62
65
  "nodemon": "^2.0.15",
63
- "patch-package": "^6.4.7",
64
- "postinstall-postinstall": "^2.1.0",
65
66
  "replace-in-file": "^6.3.2",
66
67
  "rimraf": "^3.0.2",
67
68
  "ts-node": "^10.5.0",
@@ -46,11 +46,17 @@
46
46
  "name": "amount",
47
47
  "type": "uint256"
48
48
  },
49
+ {
50
+ "indexed": false,
51
+ "internalType": "uint32",
52
+ "name": "sourceChainId",
53
+ "type": "uint32"
54
+ },
49
55
  {
50
56
  "indexed": true,
51
- "internalType": "uint256",
52
- "name": "chainId",
53
- "type": "uint256"
57
+ "internalType": "uint32",
58
+ "name": "targetChainId",
59
+ "type": "uint32"
54
60
  }
55
61
  ],
56
62
  "name": "Burn",
@@ -73,14 +79,20 @@
73
79
  },
74
80
  {
75
81
  "indexed": true,
76
- "internalType": "uint256",
77
- "name": "chainId",
78
- "type": "uint256"
82
+ "internalType": "uint32",
83
+ "name": "sourceChainId",
84
+ "type": "uint32"
85
+ },
86
+ {
87
+ "indexed": false,
88
+ "internalType": "uint32",
89
+ "name": "targetChainId",
90
+ "type": "uint32"
79
91
  },
80
92
  {
81
93
  "indexed": true,
82
94
  "internalType": "bytes32",
83
- "name": "transactionHash",
95
+ "name": "submitTransactionHash",
84
96
  "type": "bytes32"
85
97
  }
86
98
  ],
@@ -164,7 +176,7 @@
164
176
  "inputs": [
165
177
  { "internalType": "address", "name": "to", "type": "address" },
166
178
  { "internalType": "uint256", "name": "amount", "type": "uint256" },
167
- { "internalType": "uint256", "name": "chainId", "type": "uint256" }
179
+ { "internalType": "uint32", "name": "chainId", "type": "uint32" }
168
180
  ],
169
181
  "name": "burn",
170
182
  "outputs": [],
@@ -206,7 +218,7 @@
206
218
  "inputs": [
207
219
  { "internalType": "address", "name": "to", "type": "address" },
208
220
  { "internalType": "uint256", "name": "amount", "type": "uint256" },
209
- { "internalType": "uint256", "name": "chainId", "type": "uint256" },
221
+ { "internalType": "uint32", "name": "chainId", "type": "uint32" },
210
222
  {
211
223
  "internalType": "bytes32",
212
224
  "name": "transactionHash",
@@ -35,15 +35,15 @@
35
35
  },
36
36
  {
37
37
  "indexed": false,
38
- "internalType": "uint256",
38
+ "internalType": "uint32",
39
39
  "name": "sourceChainId",
40
- "type": "uint256"
40
+ "type": "uint32"
41
41
  },
42
42
  {
43
43
  "indexed": true,
44
- "internalType": "uint256",
44
+ "internalType": "uint32",
45
45
  "name": "targetChainId",
46
- "type": "uint256"
46
+ "type": "uint32"
47
47
  }
48
48
  ],
49
49
  "name": "LogGatewayDeposit",
@@ -72,15 +72,15 @@
72
72
  },
73
73
  {
74
74
  "indexed": true,
75
- "internalType": "uint256",
75
+ "internalType": "uint32",
76
76
  "name": "sourceChainId",
77
- "type": "uint256"
77
+ "type": "uint32"
78
78
  },
79
79
  {
80
80
  "indexed": false,
81
- "internalType": "uint256",
81
+ "internalType": "uint32",
82
82
  "name": "targetChainId",
83
- "type": "uint256"
83
+ "type": "uint32"
84
84
  },
85
85
  {
86
86
  "indexed": true,
@@ -122,7 +122,7 @@
122
122
  "inputs": [
123
123
  { "internalType": "address", "name": "token_", "type": "address" },
124
124
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
125
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
125
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" }
126
126
  ],
127
127
  "name": "deposit",
128
128
  "outputs": [],
@@ -134,7 +134,7 @@
134
134
  { "internalType": "address", "name": "to_", "type": "address" },
135
135
  { "internalType": "address", "name": "token_", "type": "address" },
136
136
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
137
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
137
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" }
138
138
  ],
139
139
  "name": "depositFor",
140
140
  "outputs": [],
@@ -160,7 +160,7 @@
160
160
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
161
161
  { "internalType": "address", "name": "user_", "type": "address" },
162
162
  { "internalType": "address", "name": "token_", "type": "address" },
163
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" },
163
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" },
164
164
  {
165
165
  "internalType": "bytes32",
166
166
  "name": "transactionHash_",
@@ -0,0 +1,10 @@
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
+ });
10
+ (0, module_alias_1.default)();
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.startApiServer = void 0;
7
7
  const fastify_1 = __importDefault(require("fastify"));
8
- const fastify_cors_1 = __importDefault(require("fastify-cors"));
8
+ const cors_1 = __importDefault(require("@fastify/cors"));
9
9
  const logger_1 = __importDefault(require("@/logger"));
10
10
  const db_1 = require("@/db");
11
11
  const logger = new logger_1.default("RPC");
12
12
  const server = (0, fastify_1.default)({ logger: false });
13
- server.register(fastify_cors_1.default, {});
13
+ server.register(cors_1.default, {});
14
14
  server.get('/', async () => 'Interop X API');
15
15
  const startApiServer = async () => {
16
16
  const HOST = process.env.API_HOST || '0.0.0.0';
@@ -20,13 +20,16 @@ const startApiServer = async () => {
20
20
  return await db_1.Transaction.findAndCountAll({
21
21
  limit: 20,
22
22
  offset: 0,
23
+ order: [
24
+ ['createdAt', 'DESC']
25
+ ]
23
26
  });
24
27
  });
25
28
  await server.listen(PORT, HOST);
26
29
  logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
27
30
  }
28
31
  catch (err) {
29
- logger.error(err);
32
+ logger.error(err.message);
30
33
  process.exit(1);
31
34
  }
32
35
  };
@@ -1,15 +1,22 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const ethers_1 = require("ethers");
4
7
  const types_1 = require("@/types");
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
5
10
  class Config {
6
11
  constructor() {
7
12
  this.events = new types_1.EventBus();
8
- this.maxPeers = 10;
13
+ this.maxPeers = 20;
9
14
  this.privateKey = process.env.PRIVATE_KEY;
10
15
  this.staging = !!process.env.STAGING && process.env.STAGING === 'true';
16
+ this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
11
17
  this.wallet = new ethers_1.Wallet(this.privateKey);
12
18
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
19
+ this.baseConfigPath = (0, expand_home_dir_1.default)(`~/.interop-x`);
13
20
  }
14
21
  get publicAddress() {
15
22
  return this.wallet.address;
@@ -17,5 +24,8 @@ class Config {
17
24
  isLeadNode() {
18
25
  return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
19
26
  }
27
+ isMaintenanceMode() {
28
+ return fs_extra_1.default.existsSync(this.baseConfigPath + '/maintenance');
29
+ }
20
30
  }
21
31
  exports.default = new Config();
@@ -15,6 +15,6 @@ exports.addresses = {
15
15
  43114: {
16
16
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
17
17
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
18
- interopXGateway: '0x8D27758751BA488690974B6Ccfcda771D462945f',
18
+ interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
19
19
  }
20
20
  };
@@ -5,7 +5,7 @@ exports.itokens = {
5
5
  1: [],
6
6
  137: [
7
7
  {
8
- address: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
8
+ address: '0x62C0045f3277E7067cAcad3c8038eEaBB1Bd92D1',
9
9
  symbol: 'USDC',
10
10
  }
11
11
  ],
@@ -26,6 +26,10 @@ Transaction.init({
26
26
  type: sequelize_2.DataTypes.JSON,
27
27
  // defaultValue: [],
28
28
  },
29
+ sourceLogs: {
30
+ type: sequelize_2.DataTypes.JSON,
31
+ // defaultValue: [],
32
+ },
29
33
  sourceCreatedAt: {
30
34
  type: sequelize_2.DataTypes.DATE,
31
35
  defaultValue: Date.now()
@@ -39,6 +43,10 @@ Transaction.init({
39
43
  type: sequelize_2.DataTypes.JSON,
40
44
  // defaultValue: [],
41
45
  },
46
+ targetLogs: {
47
+ type: sequelize_2.DataTypes.JSON,
48
+ // defaultValue: [],
49
+ },
42
50
  targetCreatedAt: sequelize_2.DataTypes.DATE,
43
51
  targetDelayUntil: sequelize_2.DataTypes.DATE,
44
52
  submitEvent: sequelize_2.DataTypes.JSON,
@@ -0,0 +1,48 @@
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 abi_1 = __importDefault(require("@/abi"));
7
+ const config_1 = __importDefault(require("@/config"));
8
+ const constants_1 = require("@/constants");
9
+ const utils_1 = require("@/utils");
10
+ const ethers_1 = require("ethers");
11
+ const ethers_multisend_1 = require("ethers-multisend");
12
+ async function default_1(transaction, type) {
13
+ const transactions = [];
14
+ const logs = [];
15
+ if (transaction.sourceStatus === 'pending') {
16
+ throw Error('Cannot build data for pending deposit transaction');
17
+ }
18
+ if (!transaction.submitEvent) {
19
+ throw Error('Cannot build data for transaction without submitEvent');
20
+ }
21
+ const token = constants_1.tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
22
+ if (!token) {
23
+ throw Error(`Unsupported token ${transaction.submitEvent.token}`);
24
+ }
25
+ const itoken = constants_1.itokens[transaction.targetChainId].find(t => t.symbol.toLowerCase() === token.symbol.toLowerCase());
26
+ if (!itoken) {
27
+ throw Error(`Unsupported itoken ${token.symbol}`);
28
+ }
29
+ const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
30
+ const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
31
+ const interopBridgeContract = (0, utils_1.getContract)(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
32
+ const { data } = await interopBridgeContract.populateTransaction.mint(transaction.submitEvent.user, ethers_1.ethers.BigNumber.from(transaction.submitEvent.amount.toString()), ethers_1.ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()), transaction.submitTransactionHash);
33
+ transactions.push({
34
+ to: itoken.address,
35
+ data: data,
36
+ value: '0',
37
+ operation: ethers_multisend_1.OperationType.Call,
38
+ });
39
+ logs.push({
40
+ type: 'mint',
41
+ message: `Minted ${transaction.submitEvent.amount / 10 ** token.decimals} ${token.symbol} to ${transaction.submitEvent.user}`,
42
+ });
43
+ return {
44
+ transactions,
45
+ logs,
46
+ };
47
+ }
48
+ exports.default = default_1;
@@ -0,0 +1,11 @@
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 deposit_1 = __importDefault(require("./deposit"));
7
+ const withdraw_1 = __importDefault(require("./withdraw"));
8
+ exports.default = {
9
+ deposit: deposit_1.default,
10
+ withdraw: withdraw_1.default,
11
+ };
@@ -0,0 +1,50 @@
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 abi_1 = __importDefault(require("@/abi"));
7
+ const config_1 = __importDefault(require("@/config"));
8
+ const constants_1 = require("@/constants");
9
+ const utils_1 = require("@/utils");
10
+ const ethers_1 = require("ethers");
11
+ const ethers_multisend_1 = require("ethers-multisend");
12
+ async function default_1(transaction, type) {
13
+ const transactions = [];
14
+ const logs = [];
15
+ if (transaction.action !== 'withdraw') {
16
+ throw new Error(`Invalid action: ${transaction.action}`);
17
+ }
18
+ if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
19
+ throw Error('Cannot build data for pending withdraw transaction');
20
+ }
21
+ if (!transaction.submitEvent) {
22
+ throw Error('Cannot build data for transaction without submitEvent');
23
+ }
24
+ const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
25
+ const itoken = constants_1.itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
26
+ if (!itoken) {
27
+ throw Error(`Unsupported itoken ${itokenAddress}`);
28
+ }
29
+ const token = constants_1.tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
30
+ if (!token) {
31
+ throw Error(`Unsupported token ${itoken.symbol}`);
32
+ }
33
+ const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
34
+ const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
35
+ const gatewayAddress = constants_1.addresses[targetChainId].interopXGateway;
36
+ const interopBridgeContract = (0, utils_1.getContract)(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
37
+ const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(sourceChainId.toString()), transaction.submitTransactionHash);
38
+ transactions.push({
39
+ to: gatewayAddress,
40
+ data: data,
41
+ value: '0',
42
+ operation: ethers_multisend_1.OperationType.Call,
43
+ });
44
+ logs.push({
45
+ type: 'transfer',
46
+ message: `Transfer ${amount / 10 ** token.decimals} ${token.symbol} to ${to}`,
47
+ });
48
+ return { transactions, logs };
49
+ }
50
+ exports.default = default_1;
@@ -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,52 +3,101 @@ 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)();
22
- const assert_1 = __importDefault(require("assert"));
6
+ require("./alias");
7
+ const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
23
9
  const dotenv_1 = __importDefault(require("dotenv"));
10
+ const chalk_1 = __importDefault(require("chalk"));
24
11
  const ethers_1 = require("ethers");
25
12
  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');
29
- if (process.argv.at(-1) === 'help') {
16
+ const GIT_SHORT_HASH = 'de23e71';
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');
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();
33
+ };
34
+ if (process.argv.at(-1) === 'help') {
35
+ printUsage();
36
+ process.exit(0);
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'));
33
42
  process.exit(0);
34
43
  }
35
- (0, assert_1.default)(process.env.PRIVATE_KEY, "PRIVATE_KEY is not defined");
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
+ }
49
+ if (process.argv.at(-1) === 'version') {
50
+ console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
51
+ process.exit(0);
52
+ }
53
+ if (!process.env.PRIVATE_KEY) {
54
+ console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
55
+ printUsage();
56
+ process.exit(1);
57
+ }
36
58
  try {
37
59
  new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
38
60
  }
39
61
  catch (e) {
40
- logger.error('Invalid private key');
62
+ console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
63
+ printUsage();
41
64
  process.exit(1);
42
65
  }
43
- logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.dc4f10a)`);
66
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
44
67
  const tasks_1 = require("@/tasks");
45
68
  const net_1 = require("@/net");
46
69
  const api_1 = require("@/api");
70
+ const db_1 = require("./db");
71
+ const utils_1 = require("./utils");
47
72
  async function main() {
48
73
  (0, net_1.startPeer)({});
49
74
  const tasks = new tasks_1.Tasks();
50
75
  tasks.start();
51
76
  (0, api_1.startApiServer)();
77
+ net_1.protocol.on('TransactionStatus', async (payload) => {
78
+ if (!net_1.peerPool.isLeadNode(payload.peerId)) {
79
+ const peer = net_1.peerPool.getPeer(payload.peerId);
80
+ if (!peer) {
81
+ return;
82
+ }
83
+ logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
84
+ return;
85
+ }
86
+ const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
87
+ if (!transaction) {
88
+ return;
89
+ }
90
+ transaction.sourceStatus = payload.data.sourceStatus;
91
+ transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
92
+ transaction.sourceErrors = payload.data.sourceErrors;
93
+ transaction.sourceLogs = payload.data.sourceLogs;
94
+ transaction.targetStatus = payload.data.targetStatus;
95
+ transaction.targetTransactionHash = payload.data.targetTransactionHash;
96
+ transaction.targetErrors = payload.data.targetErrors;
97
+ transaction.targetLogs = payload.data.targetLogs;
98
+ transaction.status = payload.data.status;
99
+ await transaction.save();
100
+ });
52
101
  }
53
102
  main()
54
103
  .then(() => {
@@ -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
@@ -7,6 +7,9 @@ exports.peerPool = exports.PeerPool = void 0;
7
7
  const types_1 = require("@/types");
8
8
  const config_1 = __importDefault(require("@/config"));
9
9
  const logger_1 = __importDefault(require("@/logger"));
10
+ const utils_1 = require("ethers/lib/utils");
11
+ const utils_2 = require("@/utils");
12
+ const chalk_1 = __importDefault(require("chalk"));
10
13
  const logger = new logger_1.default('PeerPool');
11
14
  class PeerPool {
12
15
  constructor() {
@@ -70,7 +73,7 @@ class PeerPool {
70
73
  peer.pooled = true;
71
74
  if (newPeer) {
72
75
  config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
73
- 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`);
74
77
  }
75
78
  }
76
79
  }
@@ -84,7 +87,7 @@ class PeerPool {
84
87
  if (this.pool.delete(peer.id)) {
85
88
  peer.pooled = false;
86
89
  config_1.default.events.emit(types_1.Event.POOL_PEER_REMOVED, peer);
87
- 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`);
88
91
  }
89
92
  }
90
93
  }
@@ -100,6 +103,19 @@ class PeerPool {
100
103
  get activePeerIds() {
101
104
  return this.activePeers.map((p) => p.id);
102
105
  }
106
+ getPeer(id) {
107
+ return this.pool.get(id);
108
+ }
109
+ isLeadNode(id) {
110
+ const peer = this.pool.get(id);
111
+ if (!peer) {
112
+ return false;
113
+ }
114
+ return (0, utils_1.getAddress)(peer.publicAddress) === (0, utils_1.getAddress)(config_1.default.leadNodeAddress);
115
+ }
116
+ getLeadPeer() {
117
+ return this.peers.find((p) => this.isLeadNode(p.id));
118
+ }
103
119
  cleanup() {
104
120
  // let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
105
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,