@instadapp/interop-x 0.0.0-dev.d2e8d37 → 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 (63) hide show
  1. package/dist/package.json +2 -2
  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 +3 -0
  6. package/dist/src/config/index.js +10 -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 +31 -21
  15. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
  16. package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +2 -0
  17. package/dist/src/net/protocol/index.js +17 -7
  18. package/dist/src/tasks/AutoUpdateTask.js +11 -8
  19. package/dist/src/tasks/BaseTask.js +4 -0
  20. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +17 -1
  21. package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -8
  22. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  23. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +16 -1
  24. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -2
  25. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  26. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
  27. package/dist/src/tasks/index.js +16 -5
  28. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
  29. package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
  30. package/dist/src/utils/index.js +1 -82
  31. package/package.json +2 -2
  32. package/src/abi/interopBridgeToken.json +21 -9
  33. package/src/abi/interopXGateway.json +11 -11
  34. package/src/alias.ts +6 -0
  35. package/src/api/index.ts +3 -0
  36. package/src/config/index.ts +9 -1
  37. package/src/constants/addresses.ts +1 -1
  38. package/src/constants/itokens.ts +1 -1
  39. package/src/db/models/transaction.ts +10 -0
  40. package/src/gnosis/actions/deposit.ts +63 -0
  41. package/src/gnosis/actions/index.ts +7 -0
  42. package/src/gnosis/actions/withdraw.ts +67 -0
  43. package/src/gnosis/index.ts +19 -0
  44. package/src/index.ts +44 -25
  45. package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
  46. package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +3 -1
  47. package/src/net/protocol/index.ts +17 -7
  48. package/src/tasks/AutoUpdateTask.ts +15 -14
  49. package/src/tasks/BaseTask.ts +5 -0
  50. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +24 -6
  51. package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -13
  52. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  53. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +22 -5
  54. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -2
  55. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  56. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
  57. package/src/tasks/index.ts +24 -5
  58. package/src/typechain/InteropBridgeToken.ts +23 -17
  59. package/src/typechain/InteropXGateway.ts +13 -13
  60. package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
  61. package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
  62. package/src/utils/index.ts +1 -122
  63. 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.d2e8d37",
3
+ "version": "0.0.0-dev.de23e71",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -28,7 +28,6 @@
28
28
  "await-spawn": "^4.0.2",
29
29
  "axios": "^0.27.1",
30
30
  "axios-retry": "^3.2.4",
31
- "bignumber.js": "^9.0.2",
32
31
  "chalk": "4.1.2",
33
32
  "dotenv": "^16.0.0",
34
33
  "ethereumjs-util": "^7.1.4",
@@ -36,6 +35,7 @@
36
35
  "ethers-multisend": "^2.1.1",
37
36
  "expand-home-dir": "^0.0.3",
38
37
  "fastify": "^3.28.0",
38
+ "fs-extra": "^10.1.0",
39
39
  "libp2p": "^0.36.2",
40
40
  "libp2p-bootstrap": "^0.14.0",
41
41
  "libp2p-kad-dht": "^0.28.6",
@@ -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)();
@@ -20,6 +20,9 @@ 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);
@@ -1,16 +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';
11
16
  this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
12
17
  this.wallet = new ethers_1.Wallet(this.privateKey);
13
18
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
19
+ this.baseConfigPath = (0, expand_home_dir_1.default)(`~/.interop-x`);
14
20
  }
15
21
  get publicAddress() {
16
22
  return this.wallet.address;
@@ -18,5 +24,8 @@ class Config {
18
24
  isLeadNode() {
19
25
  return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
20
26
  }
27
+ isMaintenanceMode() {
28
+ return fs_extra_1.default.existsSync(this.baseConfigPath + '/maintenance');
29
+ }
21
30
  }
22
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,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,18 +13,39 @@ 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 = 'de23e71';
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
  }
40
- const GIT_SHORT_HASH = 'd2e8d37';
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
+ }
41
49
  if (process.argv.at(-1) === 'version') {
42
50
  console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
43
51
  process.exit(0);
@@ -82,9 +90,11 @@ async function main() {
82
90
  transaction.sourceStatus = payload.data.sourceStatus;
83
91
  transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
84
92
  transaction.sourceErrors = payload.data.sourceErrors;
93
+ transaction.sourceLogs = payload.data.sourceLogs;
85
94
  transaction.targetStatus = payload.data.targetStatus;
86
95
  transaction.targetTransactionHash = payload.data.targetTransactionHash;
87
96
  transaction.targetErrors = payload.data.targetErrors;
97
+ transaction.targetLogs = payload.data.targetLogs;
88
98
  transaction.status = payload.data.status;
89
99
  await transaction.save();
90
100
  });
@@ -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,
@@ -18,9 +18,11 @@ class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol
18
18
  sourceStatus: transaction.sourceStatus,
19
19
  sourceTransactionHash: transaction.sourceTransactionHash,
20
20
  sourceErrors: transaction.sourceErrors,
21
+ sourceLogs: transaction.sourceLogs,
21
22
  targetStatus: transaction.targetStatus,
22
23
  targetTransactionHash: transaction.targetTransactionHash,
23
24
  targetErrors: transaction.targetErrors,
25
+ targetLogs: transaction.targetLogs,
24
26
  status: transaction.status,
25
27
  };
26
28
  }
@@ -10,7 +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 SignatureDialProtocol_1_1 = require("./dial/SignatureDialProtocol.1");
13
+ const TransactionStatusDialProtocol_1 = require("./dial/TransactionStatusDialProtocol");
14
14
  class Protocol extends stream_1.EventEmitter {
15
15
  constructor() {
16
16
  super(...arguments);
@@ -31,21 +31,31 @@ class Protocol extends stream_1.EventEmitter {
31
31
  encode: (transaction) => [
32
32
  Buffer.from(transaction.transactionHash),
33
33
  Buffer.from(transaction.sourceStatus),
34
- Buffer.from(transaction.sourceTransactionHash),
34
+ Buffer.from(transaction.sourceTransactionHash || ''),
35
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)]) : [],
36
37
  Buffer.from(transaction.targetStatus),
37
- Buffer.from(transaction.targetTransactionHash),
38
+ Buffer.from(transaction.targetTransactionHash || ''),
38
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)]) : [],
39
41
  Buffer.from(transaction.status),
40
42
  ],
41
- decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
43
+ decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
42
44
  transactionHash: transactionHash.toString(),
43
45
  sourceStatus: sourceStatus.toString(),
44
- sourceTransactionHash: sourceTransactionHash.toString(),
46
+ sourceTransactionHash: sourceTransactionHash.toString() || null,
45
47
  sourceErrors: sourceErrors.map((e) => e.toString()),
48
+ sourceLogs: sourceLogs.map(e => ({
49
+ type: e[0].toString(),
50
+ message: e[1].toString(),
51
+ })),
46
52
  targetStatus: targetStatus.toString(),
47
- targetTransactionHash: targetTransactionHash.toString(),
53
+ targetTransactionHash: targetTransactionHash.toString() || null,
48
54
  targetErrors: targetErrors.map((e) => e.toString()),
55
+ targetLogs: targetLogs.map(e => ({
56
+ type: e[0].toString(),
57
+ message: e[1].toString(),
58
+ })),
49
59
  status: status.toString(),
50
60
  }),
51
61
  },
@@ -65,7 +75,7 @@ class Protocol extends stream_1.EventEmitter {
65
75
  });
66
76
  });
67
77
  this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
68
- this.transactionStatus = new SignatureDialProtocol_1_1.TransactionStatusDialProtocol(this.libp2p);
78
+ this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
69
79
  }
70
80
  init() {
71
81
  this.libp2p.pubsub.subscribe(this.topic);
@@ -6,16 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const BaseTask_1 = require("./BaseTask");
7
7
  const logger_1 = __importDefault(require("@/logger"));
8
8
  const await_spawn_1 = __importDefault(require("await-spawn"));
9
+ const child_process_1 = require("child_process");
9
10
  const config_1 = __importDefault(require("@/config"));
10
11
  const waait_1 = __importDefault(require("waait"));
11
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 * 5 * 1000;
20
+ this.pollIntervalMs = 60 * 10 * 1000;
19
21
  }
20
22
  prePollHandler() {
21
23
  return config_1.default.autoUpdate && !config_1.default.isLeadNode();
@@ -32,8 +34,8 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
32
34
  }
33
35
  async getLatestVersion() {
34
36
  try {
35
- const stdout = await (0, await_spawn_1.default)('npm', ['view', package_json_1.default.name, 'version']);
36
- return stdout.toString();
37
+ const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
38
+ return stdout.toString().trim();
37
39
  }
38
40
  catch (error) {
39
41
  this.logger.error(error);
@@ -47,9 +49,7 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
47
49
  }
48
50
  this.logger.warn(`New version ${version} available.`);
49
51
  this.logger.info('Updating...');
50
- const spawner = (0, await_spawn_1.default)('npm', ['-g', 'install', '@instadapp/interop-x@latest']);
51
- spawner.child.on(console.log);
52
- await spawner;
52
+ await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
53
53
  await (0, waait_1.default)(5000);
54
54
  if (version !== await this.getInstalledVersion()) {
55
55
  this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
@@ -57,10 +57,13 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
57
57
  }
58
58
  this.logger.warn(`Installed version ${version}`);
59
59
  this.logger.warn(`Restarting...`);
60
- (0, await_spawn_1.default)(process.argv[0], process.argv.slice(1), {
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), {
61
62
  cwd: process.cwd(),
62
- stdio: "inherit"
63
+ stdio: "inherit",
64
+ // shell: process.env.SHELL,
63
65
  });
66
+ subprocess.unref();
64
67
  process.exit();
65
68
  }
66
69
  }
@@ -35,6 +35,10 @@ class BaseTask extends events_1.default {
35
35
  }
36
36
  }
37
37
  prePollHandler() {
38
+ if (config_1.default.isMaintenanceMode()) {
39
+ this.logger.warn('Maintenance mode is enabled. Skipping task.');
40
+ return false;
41
+ }
38
42
  if (this.exceptLeadNode) {
39
43
  return !config_1.default.isLeadNode();
40
44
  }