@instadapp/interop-x 0.0.0-dev.fd6776c → 0.0.0-dev.fd7fd6f
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/bin/interop-x +1 -1
- package/dist/package.json +72 -0
- package/dist/{abi → src/abi}/erc20.json +0 -0
- package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
- package/dist/{abi → src/abi}/index.js +0 -0
- package/dist/{abi → src/abi}/interopBridgeToken.json +0 -0
- package/dist/{abi → src/abi}/interopXGateway.json +0 -0
- package/dist/src/api/index.js +33 -0
- package/dist/{config → src/config}/index.js +1 -0
- package/dist/{constants → src/constants}/addresses.js +0 -8
- package/dist/{constants → src/constants}/index.js +1 -0
- package/dist/src/constants/itokens.js +13 -0
- package/dist/{constants → src/constants}/tokens.js +0 -0
- package/dist/{db → src/db}/index.js +0 -0
- package/dist/{db → src/db}/models/index.js +0 -0
- package/dist/{db → src/db}/models/transaction.js +3 -1
- package/dist/{db → src/db}/sequelize.js +0 -0
- package/dist/src/index.js +103 -0
- package/dist/{logger → src/logger}/index.js +0 -0
- package/dist/{net → src/net}/index.js +0 -0
- package/dist/{net → src/net}/peer/index.js +6 -2
- package/dist/{net → src/net}/pool/index.js +27 -9
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +22 -12
- package/dist/{net → src/net}/protocol/index.js +30 -1
- package/dist/src/tasks/AutoUpdateTask.js +44 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +1 -1
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +147 -0
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +70 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +150 -0
- package/dist/{tasks → src/tasks}/InteropXGateway/SyncDepositEvents.js +16 -20
- package/dist/{tasks → src/tasks}/index.js +15 -0
- package/dist/{typechain → src/typechain}/Erc20.js +0 -0
- package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
- package/dist/{typechain → src/typechain}/InteropBridgeToken.js +0 -0
- package/dist/{typechain → src/typechain}/InteropXGateway.js +0 -0
- package/dist/{typechain → src/typechain}/common.js +0 -0
- package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/InteropBridgeToken__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/InteropXGateway__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/index.js +0 -0
- package/dist/{typechain → src/typechain}/index.js +0 -0
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/src/utils/index.js +228 -0
- package/package.json +10 -4
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/api/index.ts +33 -0
- package/src/config/index.ts +2 -0
- package/src/constants/addresses.ts +0 -8
- package/src/constants/index.ts +1 -0
- package/src/constants/itokens.ts +10 -0
- package/src/db/models/transaction.ts +8 -4
- package/src/index.ts +56 -6
- package/src/net/peer/index.ts +7 -6
- package/src/net/pool/index.ts +37 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +25 -13
- package/src/net/protocol/index.ts +45 -1
- package/src/tasks/AutoUpdateTask.ts +53 -0
- package/src/tasks/BaseTask.ts +1 -1
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +233 -0
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +121 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +245 -0
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +23 -11
- package/src/tasks/index.ts +22 -2
- package/src/utils/index.ts +182 -4
- package/dist/index.js +0 -63
- package/dist/utils/index.js +0 -101
package/bin/interop-x
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
require('../dist/index')
|
2
|
+
require('../dist/src/index')
|
@@ -0,0 +1,72 @@
|
|
1
|
+
{
|
2
|
+
"name": "@instadapp/interop-x",
|
3
|
+
"version": "0.0.0-dev.fd7fd6f",
|
4
|
+
"license": "MIT",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"engines": {
|
7
|
+
"node": ">=16",
|
8
|
+
"yarn": "^1.22.0"
|
9
|
+
},
|
10
|
+
"scripts": {
|
11
|
+
"start": "yarn build && node bin/interop-x",
|
12
|
+
"build": "yarn generate-abi-types && export GIT_REF=$(git rev-parse --short HEAD) && rimraf ./dist && tsc -p tsconfig.json && replace-in-file '@GIT_SHORT_HASH@' $GIT_REF ./dist/**/*.js",
|
13
|
+
"dev": "yarn generate-abi-types && NODE_ENV=development nodemon",
|
14
|
+
"generate-abi-types": "typechain --target=ethers-v5 'src/abi/*.json' --out-dir 'src/typechain'",
|
15
|
+
"prepublishOnly": "yarn build",
|
16
|
+
"postinstall": "patch-package"
|
17
|
+
},
|
18
|
+
"nodemonConfig": {
|
19
|
+
"watch": [
|
20
|
+
"src"
|
21
|
+
],
|
22
|
+
"ext": "ts",
|
23
|
+
"exec": "./node_modules/.bin/ts-node --files -r tsconfig-paths/register ./src/index.ts"
|
24
|
+
},
|
25
|
+
"dependencies": {
|
26
|
+
"@achingbrain/libp2p-gossipsub": "^0.12.2",
|
27
|
+
"axios": "^0.27.1",
|
28
|
+
"axios-retry": "^3.2.4",
|
29
|
+
"bignumber.js": "^9.0.2",
|
30
|
+
"chalk": "4.1.2",
|
31
|
+
"dotenv": "^16.0.0",
|
32
|
+
"ethereumjs-util": "^7.1.4",
|
33
|
+
"ethers": "^5.6.4",
|
34
|
+
"ethers-multisend": "^2.1.1",
|
35
|
+
"expand-home-dir": "^0.0.3",
|
36
|
+
"fastify": "^3.28.0",
|
37
|
+
"fastify-cors": "^6.0.3",
|
38
|
+
"libp2p": "^0.36.2",
|
39
|
+
"libp2p-bootstrap": "^0.14.0",
|
40
|
+
"libp2p-kad-dht": "^0.28.6",
|
41
|
+
"libp2p-mdns": "^0.18.0",
|
42
|
+
"libp2p-mplex": "^0.10.7",
|
43
|
+
"libp2p-noise": "^4.0.0",
|
44
|
+
"libp2p-pubsub-peer-discovery": "^4.0.0",
|
45
|
+
"libp2p-tcp": "^0.17.2",
|
46
|
+
"libp2p-websockets": "^0.16.2",
|
47
|
+
"luxon": "^2.3.2",
|
48
|
+
"module-alias": "^2.2.2",
|
49
|
+
"patch-package": "^6.4.7",
|
50
|
+
"postinstall-postinstall": "^2.1.0",
|
51
|
+
"sequelize": "6.18.0",
|
52
|
+
"sqlite3": "^5.0.5",
|
53
|
+
"waait": "^1.0.5"
|
54
|
+
},
|
55
|
+
"bin": {
|
56
|
+
"interop-x": "bin/interop-x",
|
57
|
+
"interopx": "bin/interop-x"
|
58
|
+
},
|
59
|
+
"devDependencies": {
|
60
|
+
"@typechain/ethers-v5": "^10.0.0",
|
61
|
+
"@types/bn.js": "^5.1.0",
|
62
|
+
"@types/fs-extra": "^9.0.13",
|
63
|
+
"@types/node": "^17.0.17",
|
64
|
+
"nodemon": "^2.0.15",
|
65
|
+
"replace-in-file": "^6.3.2",
|
66
|
+
"rimraf": "^3.0.2",
|
67
|
+
"ts-node": "^10.5.0",
|
68
|
+
"tsconfig-paths": "^3.12.0",
|
69
|
+
"typechain": "^8.0.0",
|
70
|
+
"typescript": "^4.5.5"
|
71
|
+
}
|
72
|
+
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,33 @@
|
|
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.startApiServer = void 0;
|
7
|
+
const fastify_1 = __importDefault(require("fastify"));
|
8
|
+
const fastify_cors_1 = __importDefault(require("fastify-cors"));
|
9
|
+
const logger_1 = __importDefault(require("@/logger"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const logger = new logger_1.default("RPC");
|
12
|
+
const server = (0, fastify_1.default)({ logger: false });
|
13
|
+
server.register(fastify_cors_1.default, {});
|
14
|
+
server.get('/', async () => 'Interop X API');
|
15
|
+
const startApiServer = async () => {
|
16
|
+
const HOST = process.env.API_HOST || '0.0.0.0';
|
17
|
+
const PORT = process.env.API_PORT || '8080';
|
18
|
+
try {
|
19
|
+
server.get('/transactions', async (req) => {
|
20
|
+
return await db_1.Transaction.findAndCountAll({
|
21
|
+
limit: 20,
|
22
|
+
offset: 0,
|
23
|
+
});
|
24
|
+
});
|
25
|
+
await server.listen(PORT, HOST);
|
26
|
+
logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
|
27
|
+
}
|
28
|
+
catch (err) {
|
29
|
+
logger.error(err);
|
30
|
+
process.exit(1);
|
31
|
+
}
|
32
|
+
};
|
33
|
+
exports.startApiServer = startApiServer;
|
@@ -8,6 +8,7 @@ class Config {
|
|
8
8
|
this.maxPeers = 10;
|
9
9
|
this.privateKey = process.env.PRIVATE_KEY;
|
10
10
|
this.staging = !!process.env.STAGING && process.env.STAGING === 'true';
|
11
|
+
this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
11
12
|
this.wallet = new ethers_1.Wallet(this.privateKey);
|
12
13
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
|
13
14
|
}
|
@@ -6,23 +6,15 @@ exports.addresses = {
|
|
6
6
|
gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
|
7
7
|
multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
|
8
8
|
interopXGateway: '',
|
9
|
-
interopBridgeTokens: [],
|
10
9
|
},
|
11
10
|
137: {
|
12
11
|
gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
|
13
12
|
multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
|
14
13
|
interopXGateway: '',
|
15
|
-
interopBridgeTokens: [
|
16
|
-
{
|
17
|
-
address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
|
18
|
-
symbol: 'USDC',
|
19
|
-
}
|
20
|
-
],
|
21
14
|
},
|
22
15
|
43114: {
|
23
16
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
24
17
|
multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
|
25
18
|
interopXGateway: '0x8D27758751BA488690974B6Ccfcda771D462945f',
|
26
|
-
interopBridgeTokens: [],
|
27
19
|
}
|
28
20
|
};
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./addresses"), exports);
|
18
18
|
__exportStar(require("./tokens"), exports);
|
19
|
+
__exportStar(require("./itokens"), exports);
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.itokens = void 0;
|
4
|
+
exports.itokens = {
|
5
|
+
1: [],
|
6
|
+
137: [
|
7
|
+
{
|
8
|
+
address: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
|
9
|
+
symbol: 'USDC',
|
10
|
+
}
|
11
|
+
],
|
12
|
+
43114: []
|
13
|
+
};
|
File without changes
|
File without changes
|
File without changes
|
@@ -12,8 +12,10 @@ Transaction.init({
|
|
12
12
|
autoIncrement: true,
|
13
13
|
primaryKey: true
|
14
14
|
},
|
15
|
+
submitTransactionHash: sequelize_2.DataTypes.NUMBER,
|
16
|
+
submitBlockNumber: sequelize_2.DataTypes.NUMBER,
|
15
17
|
transactionHash: sequelize_2.DataTypes.STRING,
|
16
|
-
|
18
|
+
action: sequelize_2.DataTypes.STRING,
|
17
19
|
from: sequelize_2.DataTypes.STRING,
|
18
20
|
to: sequelize_2.DataTypes.STRING,
|
19
21
|
sourceChainId: sequelize_2.DataTypes.NUMBER,
|
File without changes
|
@@ -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 = 'fd7fd6f';
|
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
|
@@ -82,8 +82,12 @@ const startPeer = async ({}) => {
|
|
82
82
|
net_1.protocol.start({
|
83
83
|
libp2p: node
|
84
84
|
});
|
85
|
-
node.on("peer:discovery", (peer) =>
|
86
|
-
|
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
93
|
setInterval(() => net_1.protocol.sendPeerInfo({
|
@@ -6,6 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.peerPool = exports.PeerPool = void 0;
|
7
7
|
const types_1 = require("@/types");
|
8
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
|
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
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
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;
|
File without changes
|
@@ -8,6 +8,8 @@ const BaseDialProtocol_1 = require("./BaseDialProtocol");
|
|
8
8
|
const waait_1 = __importDefault(require("waait"));
|
9
9
|
const config_1 = __importDefault(require("@/config"));
|
10
10
|
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const constants_1 = require("@/constants");
|
11
13
|
class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
12
14
|
constructor(libp2p) {
|
13
15
|
super(libp2p, '/interop-x/signatures');
|
@@ -15,31 +17,39 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
15
17
|
}
|
16
18
|
async response(data) {
|
17
19
|
const signer = config_1.default.wallet;
|
18
|
-
let
|
20
|
+
let transaction;
|
19
21
|
let maxTimeout = 20000;
|
20
22
|
do {
|
21
|
-
|
22
|
-
if (!
|
23
|
+
transaction = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
|
24
|
+
if (!transaction) {
|
23
25
|
await (0, waait_1.default)(1000);
|
24
26
|
maxTimeout -= 1000;
|
25
27
|
}
|
26
|
-
} while (!
|
27
|
-
if (!
|
28
|
+
} while (!transaction && maxTimeout > 0);
|
29
|
+
if (!transaction) {
|
28
30
|
return {
|
29
31
|
signer: signer.address,
|
30
32
|
data: null,
|
31
33
|
error: 'Event not found'
|
32
34
|
};
|
33
35
|
}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
+
});
|
43
|
+
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
44
|
+
to: constants_1.addresses[transaction.targetChainId].multisend,
|
45
|
+
data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
|
46
|
+
chainId: transaction.targetChainId,
|
47
|
+
safeTxGas: data.safeTxGas,
|
48
|
+
nonce: data.safeNonce,
|
49
|
+
}, { signer });
|
40
50
|
return {
|
41
51
|
signer: signer.address,
|
42
|
-
data:
|
52
|
+
data: signedData
|
43
53
|
};
|
44
54
|
}
|
45
55
|
}
|
@@ -16,7 +16,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
16
16
|
this.protocolMessages = [
|
17
17
|
{
|
18
18
|
name: 'PeerInfo',
|
19
|
-
code:
|
19
|
+
code: 0x01,
|
20
20
|
encode: (info) => [
|
21
21
|
Buffer.from(info.publicAddress),
|
22
22
|
],
|
@@ -24,6 +24,30 @@ 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, }) {
|
@@ -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,44 @@
|
|
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 child_process_1 = require("child_process");
|
11
|
+
const config_1 = __importDefault(require("@/config"));
|
12
|
+
const currentVersion = package_json_1.default.version;
|
13
|
+
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
14
|
+
constructor() {
|
15
|
+
super({
|
16
|
+
logger: new logger_1.default("AutoUpdateTask"),
|
17
|
+
});
|
18
|
+
this.pollIntervalMs = 60 * 1000;
|
19
|
+
}
|
20
|
+
prePollHandler() {
|
21
|
+
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
22
|
+
}
|
23
|
+
async pollHandler() {
|
24
|
+
const { data } = await utils_1.http.get('https://registry.npmjs.org/@instadapp/interop-x');
|
25
|
+
const version = data['dist-tags'].latest;
|
26
|
+
if (version === currentVersion) {
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
this.logger.warn(`New version ${version} available.`);
|
30
|
+
const update = (0, child_process_1.spawn)('npm', ['-g', 'install', '@instadapp/interop-x']);
|
31
|
+
update.on("close", () => {
|
32
|
+
this.logger.warn(`Installed version ${version}`);
|
33
|
+
this.logger.warn(`Restarting...`);
|
34
|
+
(0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
|
35
|
+
cwd: process.cwd(),
|
36
|
+
env: Object.create(process.env),
|
37
|
+
detached: true,
|
38
|
+
stdio: "inherit"
|
39
|
+
});
|
40
|
+
process.exit();
|
41
|
+
});
|
42
|
+
}
|
43
|
+
}
|
44
|
+
exports.default = AutoUpdateTask;
|
@@ -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
|
31
|
+
this.logger.error(`poll check error:\n${err.message}\ntrace: ${err.stack}`);
|
32
32
|
}
|
33
33
|
await this.postPollHandler();
|
34
34
|
}
|