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