@instadapp/interop-x 0.0.0-dev.098229d → 0.0.0-dev.160118e

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.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.098229d",
3
+ "version": "0.0.0-dev.160118e",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -26,7 +26,7 @@ const startApiServer = async () => {
26
26
  logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
27
27
  }
28
28
  catch (err) {
29
- logger.error(err);
29
+ logger.error(err.message);
30
30
  process.exit(1);
31
31
  }
32
32
  };
package/dist/src/index.js CHANGED
@@ -37,7 +37,7 @@ if (process.argv.at(-1) === 'help') {
37
37
  printUsage();
38
38
  process.exit(0);
39
39
  }
40
- const GIT_SHORT_HASH = '098229d';
40
+ const GIT_SHORT_HASH = '160118e';
41
41
  if (process.argv.at(-1) === 'version') {
42
42
  console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
43
43
  process.exit(0);
@@ -60,6 +60,7 @@ const tasks_1 = require("@/tasks");
60
60
  const net_1 = require("@/net");
61
61
  const api_1 = require("@/api");
62
62
  const db_1 = require("./db");
63
+ const utils_1 = require("./utils");
63
64
  async function main() {
64
65
  (0, net_1.startPeer)({});
65
66
  const tasks = new tasks_1.Tasks();
@@ -68,7 +69,10 @@ async function main() {
68
69
  net_1.protocol.on('TransactionStatus', async (payload) => {
69
70
  if (!net_1.peerPool.isLeadNode(payload.peerId)) {
70
71
  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
+ if (!peer) {
73
+ return;
74
+ }
75
+ logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
72
76
  return;
73
77
  }
74
78
  const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
@@ -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
  }
@@ -9,6 +9,8 @@ const utils_1 = require("@/utils");
9
9
  const await_spawn_1 = __importDefault(require("await-spawn"));
10
10
  const config_1 = __importDefault(require("@/config"));
11
11
  const waait_1 = __importDefault(require("waait"));
12
+ const getCurrentVersion = () => require('../../package.json').version;
13
+ const currentVersion = getCurrentVersion();
12
14
  class AutoUpdateTask extends BaseTask_1.BaseTask {
13
15
  constructor() {
14
16
  super({
@@ -19,20 +21,17 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
19
21
  prePollHandler() {
20
22
  return config_1.default.autoUpdate && !config_1.default.isLeadNode();
21
23
  }
22
- getCurrentVersion() {
23
- return require('../../package.json').version;
24
- }
25
24
  async pollHandler() {
26
25
  const { data } = await utils_1.http.get('https://registry.npmjs.org/@instadapp/interop-x');
27
26
  const version = data['dist-tags'].latest;
28
- const currentVersion = this.getCurrentVersion();
29
27
  if (version === currentVersion) {
30
28
  return;
31
29
  }
32
30
  this.logger.warn(`New version ${version} available.`);
31
+ this.logger.info('Updating...');
33
32
  await (0, await_spawn_1.default)('npm', ['-g', 'install', '@instadapp/interop-x', '-f']);
34
33
  await (0, waait_1.default)(5000);
35
- if (currentVersion === this.getCurrentVersion()) {
34
+ if (currentVersion === getCurrentVersion()) {
36
35
  this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
37
36
  return;
38
37
  }
@@ -139,7 +139,6 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
139
139
  }
140
140
  }
141
141
  async start() {
142
- this.logger.info(`Starting execution watcher on interop chain`);
143
142
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
144
143
  await super.start();
145
144
  }
@@ -61,7 +61,6 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
61
61
  this.logger.info(`${processedEvents} events processed`);
62
62
  }
63
63
  async start() {
64
- this.logger.info(`Starting execution watcher on interop chain`);
65
64
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
66
65
  this.contract = (0, utils_1.getContract)(this.itokenAddress, abi_1.default.interopBridgeToken, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
67
66
  await super.start();
@@ -140,7 +140,6 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
140
140
  net_1.protocol.sendTransaction(transaction);
141
141
  }
142
142
  async start() {
143
- this.logger.info(`Starting execution watcher on interop chain`);
144
143
  this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
145
144
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
146
145
  this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
@@ -65,7 +65,6 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
65
65
  this.logger.info(`${processedEvents} events processed`);
66
66
  }
67
67
  async start() {
68
- this.logger.info(`Starting execution watcher on interop chain`);
69
68
  this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
70
69
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
71
70
  this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
@@ -3,7 +3,7 @@ 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
- exports.getContract = exports.buildWithdrawDataForTransaction = exports.buildDepositDataForTransaction = exports.buildDataForTransaction = exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.http = void 0;
6
+ exports.getContract = exports.buildWithdrawDataForTransaction = exports.buildDepositDataForTransaction = exports.buildDataForTransaction = exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.shortenHash = exports.http = void 0;
7
7
  /**
8
8
  * @module util
9
9
  */
@@ -16,6 +16,16 @@ const config_1 = __importDefault(require("@/config"));
16
16
  const abi_1 = __importDefault(require("@/abi"));
17
17
  exports.http = axios_1.default.create();
18
18
  (0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
19
+ function shortenHash(hash, length = 4) {
20
+ if (!hash)
21
+ return;
22
+ if (hash.length < 12)
23
+ return hash;
24
+ const beginningChars = hash.startsWith("0x") ? length + 2 : length;
25
+ const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
26
+ return shortened;
27
+ }
28
+ exports.shortenHash = shortenHash;
19
29
  function short(buffer) {
20
30
  return buffer.toString('hex').slice(0, 8) + '...';
21
31
  }
@@ -59,11 +69,11 @@ exports.signGnosisSafeTx = signGnosisSafeTx;
59
69
  const getRpcProviderUrl = (chainId) => {
60
70
  switch (chainId) {
61
71
  case 1:
62
- return 'https://rpc.instadapp.io/mainnet';
72
+ return 'https://rpc.ankr.com/eth';
63
73
  case 137:
64
- return 'https://rpc.instadapp.io/polygon';
74
+ return 'https://rpc.ankr.com/polygon';
65
75
  case 43114:
66
- return 'https://rpc.instadapp.io/avalanche';
76
+ return 'https://rpc.ankr.com/avalanche';
67
77
  default:
68
78
  throw new Error(`Unknown chainId: ${chainId}`);
69
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.098229d",
3
+ "version": "0.0.0-dev.160118e",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
package/src/api/index.ts CHANGED
@@ -27,7 +27,7 @@ export const startApiServer = async () => {
27
27
 
28
28
  logger.log(`RPC Server listening at http://${HOST}:${PORT}`)
29
29
  } catch (err) {
30
- logger.error(err)
30
+ logger.error(err.message)
31
31
  process.exit(1)
32
32
  }
33
33
  }
package/src/index.ts CHANGED
@@ -64,6 +64,7 @@ import { Tasks } from "@/tasks";
64
64
  import { startPeer, protocol, peerPool } from "@/net";
65
65
  import { startApiServer } from '@/api';
66
66
  import { Transaction } from './db';
67
+ import { shortenHash } from './utils';
67
68
 
68
69
  async function main() {
69
70
 
@@ -78,7 +79,12 @@ async function main() {
78
79
  protocol.on('TransactionStatus', async (payload) => {
79
80
  if (!peerPool.isLeadNode(payload.peerId)) {
80
81
  const peer = peerPool.getPeer(payload.peerId)
81
- logger.info(`ignored transaction status from ${payload.peerId} ${peer?.publicAddress} `)
82
+
83
+ if(! peer) {
84
+ return;
85
+ }
86
+
87
+ logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
82
88
  return;
83
89
  }
84
90
 
@@ -17,6 +17,7 @@ import KadDHT from "libp2p-kad-dht";
17
17
  import PubsubPeerDiscovery from "libp2p-pubsub-peer-discovery";
18
18
  import { protocol } from "@/net";
19
19
  import config from "@/config";
20
+ import chalk from "chalk";
20
21
 
21
22
  const logger = new Logger("Peer");
22
23
 
@@ -80,7 +81,7 @@ export const startPeer = async ({ }: IPeerOptions) => {
80
81
  },
81
82
  });
82
83
 
83
- logger.info("Peer ID:", node.peerId.toB58String());
84
+ logger.info("Peer ID:", chalk.bold(node.peerId.toB58String()));
84
85
 
85
86
  await node.start();
86
87
 
@@ -2,6 +2,8 @@ import { Event } from "@/types";
2
2
  import config from "@/config";
3
3
  import Logger from "@/logger";
4
4
  import { getAddress } from "ethers/lib/utils";
5
+ import { shortenHash } from "@/utils";
6
+ import chalk from "chalk";
5
7
 
6
8
 
7
9
  const logger = new Logger('PeerPool')
@@ -87,7 +89,7 @@ export class PeerPool {
87
89
 
88
90
  if (newPeer) {
89
91
  config.events.emit(Event.POOL_PEER_ADDED, peer)
90
- logger.info(`Peer ${peer.id} with address ${peer.publicAddress} added to pool`)
92
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} added to pool`)
91
93
  }
92
94
  }
93
95
  }
@@ -102,7 +104,7 @@ export class PeerPool {
102
104
  if (this.pool.delete(peer.id)) {
103
105
  peer.pooled = false
104
106
  config.events.emit(Event.POOL_PEER_REMOVED, peer)
105
- logger.info(`Peer ${peer.id} with address ${peer.publicAddress} removed from pool`)
107
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} removed from pool`)
106
108
  }
107
109
  }
108
110
  }
@@ -5,6 +5,10 @@ import spawn from 'await-spawn';
5
5
  import config from "@/config";
6
6
  import wait from "waait";
7
7
 
8
+ const getCurrentVersion = () => require('../../package.json').version
9
+
10
+ const currentVersion = getCurrentVersion()
11
+
8
12
  class AutoUpdateTask extends BaseTask {
9
13
  pollIntervalMs: number = 60 * 5 * 1000
10
14
 
@@ -18,15 +22,11 @@ class AutoUpdateTask extends BaseTask {
18
22
  return config.autoUpdate && !config.isLeadNode();
19
23
  }
20
24
 
21
- getCurrentVersion() {
22
- return require('../../package.json').version
23
- }
24
25
  async pollHandler() {
25
26
 
26
27
  const { data } = await http.get('https://registry.npmjs.org/@instadapp/interop-x')
27
28
 
28
29
  const version = data['dist-tags'].latest
29
- const currentVersion = this.getCurrentVersion()
30
30
 
31
31
  if (version === currentVersion) {
32
32
  return;
@@ -35,12 +35,13 @@ class AutoUpdateTask extends BaseTask {
35
35
  this.logger.warn(`New version ${version} available.`)
36
36
 
37
37
 
38
- await spawn('npm', ['-g', 'install', '@instadapp/interop-x', '-f']);
38
+ this.logger.info('Updating...')
39
39
 
40
+ await spawn('npm', ['-g', 'install', '@instadapp/interop-x', '-f']);
40
41
 
41
42
  await wait(5000)
42
43
 
43
- if (currentVersion === this.getCurrentVersion()) {
44
+ if (currentVersion === getCurrentVersion()) {
44
45
  this.logger.warn(`failed to install ${version}, retrying in 5 minutes`)
45
46
  return;
46
47
  }
@@ -220,8 +220,6 @@ class ProcessWithdrawEvents extends BaseTask {
220
220
  }
221
221
 
222
222
  async start(): Promise<void> {
223
- this.logger.info(`Starting execution watcher on interop chain`);
224
-
225
223
  this.provider = new ethers.providers.JsonRpcProvider(
226
224
  getRpcProviderUrl(this.chainId)
227
225
  );
@@ -102,8 +102,6 @@ class SyncWithdrawEvents extends BaseTask {
102
102
  }
103
103
 
104
104
  async start(): Promise<void> {
105
- this.logger.info(`Starting execution watcher on interop chain`);
106
-
107
105
  this.provider = new ethers.providers.JsonRpcProvider(
108
106
  getRpcProviderUrl(this.chainId)
109
107
  );
@@ -224,8 +224,6 @@ class ProcessDepositEvents extends BaseTask {
224
224
  }
225
225
 
226
226
  async start(): Promise<void> {
227
- this.logger.info(`Starting execution watcher on interop chain`);
228
-
229
227
  this.contractAddress = addresses[this.chainId].interopXGateway;
230
228
 
231
229
  this.provider = new ethers.providers.JsonRpcProvider(
@@ -105,8 +105,6 @@ class SyncDepositEvents extends BaseTask {
105
105
  }
106
106
 
107
107
  async start(): Promise<void> {
108
- this.logger.info(`Starting execution watcher on interop chain`);
109
-
110
108
  this.contractAddress = addresses[this.chainId].interopXGateway;
111
109
 
112
110
  this.provider = new ethers.providers.JsonRpcProvider(
@@ -17,6 +17,18 @@ export const http = axios.create();
17
17
  axiosRetry(http, { retries: 3, retryDelay: axiosRetry.exponentialDelay });
18
18
 
19
19
 
20
+ export function shortenHash(hash: string, length: number = 4) {
21
+ if (!hash) return;
22
+
23
+ if (hash.length < 12) return hash;
24
+
25
+ const beginningChars = hash.startsWith("0x") ? length + 2 : length;
26
+
27
+ const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
28
+
29
+ return shortened;
30
+ }
31
+
20
32
  export function short(buffer: Buffer): string {
21
33
  return buffer.toString('hex').slice(0, 8) + '...'
22
34
  }
@@ -76,11 +88,11 @@ export const signGnosisSafeTx = async ({
76
88
  export const getRpcProviderUrl = (chainId: ChainId) => {
77
89
  switch (chainId) {
78
90
  case 1:
79
- return 'https://rpc.instadapp.io/mainnet';
91
+ return 'https://rpc.ankr.com/eth';
80
92
  case 137:
81
- return 'https://rpc.instadapp.io/polygon';
93
+ return 'https://rpc.ankr.com/polygon';
82
94
  case 43114:
83
- return 'https://rpc.instadapp.io/avalanche';
95
+ return 'https://rpc.ankr.com/avalanche';
84
96
  default:
85
97
  throw new Error(`Unknown chainId: ${chainId}`);
86
98
  }