@instadapp/interop-x 0.0.0-dev.80722d6 → 0.0.0-dev.8965b57
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/interop-x +1 -1
- package/dist/package.json +73 -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 +2 -4
- package/dist/src/abi/interopXContract.json +391 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +36 -0
- package/dist/{config → src/config}/index.js +11 -1
- package/dist/{constants → src/constants}/addresses.js +3 -11
- package/dist/{constants → src/constants}/index.js +0 -0
- package/dist/{constants → src/constants}/tokens.js +31 -1
- 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 +27 -9
- package/dist/{db → src/db}/sequelize.js +0 -0
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +55 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +119 -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 +8 -3
- package/dist/{net → src/net}/pool/index.js +32 -9
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +21 -12
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/{net → src/net}/protocol/index.js +51 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
- package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +152 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +77 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +89 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
- package/dist/src/tasks/index.js +38 -0
- package/dist/{typechain → src/typechain}/Erc20.js +0 -0
- package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
- package/dist/{typechain/InteropBridgeToken.js → src/typechain/InteropXContract.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/src/typechain/factories/InteropXContract__factory.js +526 -0
- package/dist/src/typechain/factories/index.js +12 -0
- package/dist/{typechain → src/typechain}/index.js +3 -5
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/src/utils/index.js +168 -0
- package/package.json +13 -6
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +391 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +36 -0
- package/src/config/index.ts +11 -1
- package/src/constants/addresses.ts +3 -11
- package/src/constants/tokens.ts +32 -2
- package/src/db/models/transaction.ts +68 -25
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +76 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +101 -24
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +23 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +67 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +14 -4
- package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +216 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +114 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +120 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
- package/src/tasks/index.ts +24 -5
- package/src/typechain/InteropXContract.ts +524 -0
- package/src/typechain/factories/InteropXContract__factory.ts +533 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +119 -8
- package/tsconfig.json +7 -2
- package/dist/abi/interopBridgeToken.json +0 -286
- package/dist/abi/interopXGateway.json +0 -184
- package/dist/index.js +0 -63
- package/dist/tasks/InteropXGateway/SyncDepositEvents.js +0 -79
- package/dist/tasks/index.js +0 -27
- package/dist/typechain/InteropXGateway.js +0 -2
- package/dist/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/typechain/factories/InteropXGateway__factory.js +0 -265
- package/dist/typechain/factories/index.js +0 -14
- package/dist/utils/index.js +0 -101
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -114
- package/src/typechain/InteropBridgeToken.ts +0 -686
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -4,30 +4,42 @@ exports.tokens = void 0;
|
|
4
4
|
exports.tokens = {
|
5
5
|
1: [
|
6
6
|
{
|
7
|
+
aliases: ['eth'],
|
7
8
|
symbol: "ETH",
|
8
9
|
name: "Ethereum",
|
9
10
|
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
10
11
|
decimals: 18,
|
11
12
|
},
|
12
13
|
{
|
14
|
+
aliases: ['weth'],
|
15
|
+
symbol: "WETH",
|
16
|
+
name: "Wrapped Ethereum",
|
17
|
+
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
18
|
+
decimals: 18,
|
19
|
+
},
|
20
|
+
{
|
21
|
+
aliases: ['dai'],
|
13
22
|
symbol: "DAI",
|
14
23
|
name: "DAI Stable",
|
15
24
|
address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
16
25
|
decimals: 18,
|
17
26
|
},
|
18
27
|
{
|
28
|
+
aliases: ['usdc'],
|
19
29
|
symbol: "USDC",
|
20
30
|
name: "USD Coin",
|
21
31
|
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
22
32
|
decimals: 6,
|
23
33
|
},
|
24
34
|
{
|
35
|
+
aliases: ['usdt'],
|
25
36
|
symbol: "USDT",
|
26
37
|
name: "Tether USD Coin",
|
27
38
|
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
28
39
|
decimals: 6,
|
29
40
|
},
|
30
41
|
{
|
42
|
+
aliases: ['wbtc'],
|
31
43
|
symbol: "WBTC",
|
32
44
|
name: "Wrapped BTC",
|
33
45
|
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
@@ -36,36 +48,42 @@ exports.tokens = {
|
|
36
48
|
],
|
37
49
|
137: [
|
38
50
|
{
|
51
|
+
aliases: ['eth', 'weth'],
|
39
52
|
symbol: "ETH",
|
40
53
|
name: "Ethereum",
|
41
54
|
address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
42
55
|
decimals: 18,
|
43
56
|
},
|
44
57
|
{
|
58
|
+
aliases: ['dai'],
|
45
59
|
symbol: "DAI",
|
46
60
|
name: "DAI Stable",
|
47
61
|
address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
|
48
62
|
decimals: 18,
|
49
63
|
},
|
50
64
|
{
|
65
|
+
aliases: ['usdc'],
|
51
66
|
symbol: "USDC",
|
52
67
|
name: "USD Coin",
|
53
68
|
address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
54
69
|
decimals: 6,
|
55
70
|
},
|
56
71
|
{
|
72
|
+
aliases: ['usdt'],
|
57
73
|
symbol: "USDT",
|
58
74
|
name: "Tether USD Coin",
|
59
75
|
address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
|
60
76
|
decimals: 6,
|
61
77
|
},
|
62
78
|
{
|
79
|
+
aliases: ['wbtc'],
|
63
80
|
symbol: "WBTC",
|
64
81
|
name: "Wrapped BTC",
|
65
82
|
address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
66
83
|
decimals: 8,
|
67
84
|
},
|
68
85
|
{
|
86
|
+
aliases: ['avax'],
|
69
87
|
symbol: "AVAX",
|
70
88
|
name: "Avalanche Token",
|
71
89
|
address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
|
@@ -74,30 +92,42 @@ exports.tokens = {
|
|
74
92
|
],
|
75
93
|
43114: [
|
76
94
|
{
|
95
|
+
aliases: ['eth', 'weth'],
|
77
96
|
symbol: "ETH",
|
78
97
|
name: "Ethereum",
|
79
98
|
address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
|
80
99
|
decimals: 18,
|
81
100
|
},
|
82
101
|
{
|
102
|
+
aliases: ['dai'],
|
83
103
|
symbol: "DAI",
|
84
104
|
name: "DAI Stable",
|
85
105
|
address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
|
86
106
|
decimals: 18,
|
87
107
|
},
|
88
108
|
{
|
109
|
+
aliases: ['usdc'],
|
89
110
|
symbol: "USDC",
|
90
111
|
name: "USD Coin",
|
91
112
|
address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
|
92
113
|
decimals: 6,
|
93
114
|
},
|
94
115
|
{
|
95
|
-
|
116
|
+
aliases: ['usdt'],
|
117
|
+
symbol: "USDt",
|
96
118
|
name: "Tether USD Coin",
|
119
|
+
address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
|
120
|
+
decimals: 6,
|
121
|
+
},
|
122
|
+
{
|
123
|
+
aliases: ['usdt'],
|
124
|
+
symbol: "USDT.e",
|
125
|
+
name: "Tether USD",
|
97
126
|
address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
|
98
127
|
decimals: 6,
|
99
128
|
},
|
100
129
|
{
|
130
|
+
aliases: ["wbtc"],
|
101
131
|
symbol: "WBTC",
|
102
132
|
name: "Wrapped BTC",
|
103
133
|
address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
|
File without changes
|
File without changes
|
@@ -12,18 +12,26 @@ Transaction.init({
|
|
12
12
|
autoIncrement: true,
|
13
13
|
primaryKey: true
|
14
14
|
},
|
15
|
+
requestTransactionHash: sequelize_2.DataTypes.NUMBER,
|
16
|
+
requestBlockNumber: sequelize_2.DataTypes.NUMBER,
|
15
17
|
transactionHash: sequelize_2.DataTypes.STRING,
|
16
|
-
|
17
|
-
|
18
|
-
to: sequelize_2.DataTypes.STRING,
|
18
|
+
action: sequelize_2.DataTypes.STRING,
|
19
|
+
bridger: sequelize_2.DataTypes.STRING,
|
19
20
|
sourceChainId: sequelize_2.DataTypes.NUMBER,
|
20
21
|
sourceTransactionHash: sequelize_2.DataTypes.STRING,
|
21
22
|
sourceBlockNumber: sequelize_2.DataTypes.NUMBER,
|
22
|
-
sourceStatus:
|
23
|
+
sourceStatus: {
|
24
|
+
type: sequelize_2.DataTypes.STRING,
|
25
|
+
defaultValue: 'uninitialised'
|
26
|
+
},
|
23
27
|
sourceErrors: {
|
24
28
|
type: sequelize_2.DataTypes.JSON,
|
25
29
|
// defaultValue: [],
|
26
30
|
},
|
31
|
+
sourceLogs: {
|
32
|
+
type: sequelize_2.DataTypes.JSON,
|
33
|
+
// defaultValue: [],
|
34
|
+
},
|
27
35
|
sourceCreatedAt: {
|
28
36
|
type: sequelize_2.DataTypes.DATE,
|
29
37
|
defaultValue: Date.now()
|
@@ -32,17 +40,27 @@ Transaction.init({
|
|
32
40
|
targetChainId: sequelize_2.DataTypes.NUMBER,
|
33
41
|
targetTransactionHash: sequelize_2.DataTypes.STRING,
|
34
42
|
targetBlockNumber: sequelize_2.DataTypes.NUMBER,
|
35
|
-
targetStatus:
|
43
|
+
targetStatus: {
|
44
|
+
type: sequelize_2.DataTypes.STRING,
|
45
|
+
defaultValue: 'uninitialised'
|
46
|
+
},
|
36
47
|
targetErrors: {
|
37
48
|
type: sequelize_2.DataTypes.JSON,
|
38
49
|
// defaultValue: [],
|
39
50
|
},
|
51
|
+
targetLogs: {
|
52
|
+
type: sequelize_2.DataTypes.JSON,
|
53
|
+
// defaultValue: [],
|
54
|
+
},
|
40
55
|
targetCreatedAt: sequelize_2.DataTypes.DATE,
|
41
56
|
targetDelayUntil: sequelize_2.DataTypes.DATE,
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
57
|
+
requestEvent: {
|
58
|
+
type: sequelize_2.DataTypes.JSON,
|
59
|
+
allowNull: false
|
60
|
+
},
|
61
|
+
requestSentEvent: sequelize_2.DataTypes.JSON,
|
62
|
+
committedEvent: sequelize_2.DataTypes.JSON,
|
63
|
+
completedEvent: sequelize_2.DataTypes.JSON,
|
46
64
|
status: {
|
47
65
|
type: sequelize_2.DataTypes.STRING,
|
48
66
|
defaultValue: 'pending'
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
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 withdraw_1 = __importDefault(require("./withdraw"));
|
7
|
+
exports.default = {
|
8
|
+
withdraw: withdraw_1.default,
|
9
|
+
};
|
@@ -0,0 +1,55 @@
|
|
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 (type !== 'source') {
|
19
|
+
throw new Error(`[WIP] Type not supported: ${type}`);
|
20
|
+
}
|
21
|
+
if (transaction.sourceStatus === 'pending') {
|
22
|
+
throw Error('Source transaction already processesing');
|
23
|
+
}
|
24
|
+
if (transaction.sourceStatus === 'pending') {
|
25
|
+
throw Error('Source transaction already processed');
|
26
|
+
}
|
27
|
+
if (!transaction.requestEvent) {
|
28
|
+
throw Error('Something went wrong, source transaction has no request event');
|
29
|
+
}
|
30
|
+
const { bridger, position, sourceChainId, targetChainId, metadata, } = transaction.requestEvent;
|
31
|
+
const sourceChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
32
|
+
const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
|
33
|
+
const contractAddress = constants_1.addresses[sourceChainId].interopXContract;
|
34
|
+
const contract = (0, utils_1.getContract)(contractAddress, abi_1.default.interopXContract, sourceWallet);
|
35
|
+
const sourceToken = constants_1.tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
|
36
|
+
if (!sourceToken) {
|
37
|
+
throw Error('Source token not found');
|
38
|
+
}
|
39
|
+
const targetToken = constants_1.tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
|
40
|
+
if (!targetToken) {
|
41
|
+
throw Error('Target token not found');
|
42
|
+
}
|
43
|
+
if (sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
|
44
|
+
throw Error('Source and target token must be the same');
|
45
|
+
}
|
46
|
+
const { data } = await contract.populateTransaction.withdrawRequested(bridger, position.withdraw[0].sourceToken, position.withdraw[0].targetToken, position.withdraw[0].amount, targetChainId, transaction.requestTransactionHash, metadata);
|
47
|
+
transactions.push({
|
48
|
+
to: contractAddress,
|
49
|
+
data: data,
|
50
|
+
value: '0',
|
51
|
+
operation: ethers_multisend_1.OperationType.Call,
|
52
|
+
});
|
53
|
+
return { transactions, logs };
|
54
|
+
}
|
55
|
+
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 === 'success' ? 'target' : 'source')
|
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;
|
@@ -0,0 +1,119 @@
|
|
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
|
+
require("./alias");
|
7
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
9
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
11
|
+
const ethers_1 = require("ethers");
|
12
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
13
|
+
dotenv_1.default.config();
|
14
|
+
const logger_1 = __importDefault(require("@/logger"));
|
15
|
+
const logger = new logger_1.default('Process');
|
16
|
+
const GIT_SHORT_HASH = '8965b57';
|
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();
|
21
|
+
console.log('Usage:');
|
22
|
+
console.log(' interop-x help Show this message');
|
23
|
+
console.log(' interop-x version Print out the installed version of Interop X');
|
24
|
+
console.log();
|
25
|
+
console.log(' interop-x down Put the node into maintenance mode');
|
26
|
+
console.log(' interop-x up Take the node out of maintenance mode');
|
27
|
+
console.log();
|
28
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key');
|
29
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode');
|
30
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode');
|
31
|
+
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x Start the node with custom API host and port');
|
32
|
+
console.log();
|
33
|
+
};
|
34
|
+
if (process.argv.at(-1) === 'help') {
|
35
|
+
printUsage();
|
36
|
+
process.exit(0);
|
37
|
+
}
|
38
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
39
|
+
if (process.argv.at(-1) === 'down') {
|
40
|
+
fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
|
41
|
+
console.log(chalk_1.default.red('Maintenance mode enabled'));
|
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
|
+
}
|
49
|
+
if (process.argv.at(-1) === 'version') {
|
50
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
51
|
+
process.exit(0);
|
52
|
+
}
|
53
|
+
if (!process.env.PRIVATE_KEY) {
|
54
|
+
console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
|
55
|
+
printUsage();
|
56
|
+
process.exit(1);
|
57
|
+
}
|
58
|
+
try {
|
59
|
+
new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
|
60
|
+
}
|
61
|
+
catch (e) {
|
62
|
+
console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
|
63
|
+
printUsage();
|
64
|
+
process.exit(1);
|
65
|
+
}
|
66
|
+
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
67
|
+
const tasks_1 = require("@/tasks");
|
68
|
+
const net_1 = require("@/net");
|
69
|
+
const api_1 = require("@/api");
|
70
|
+
const db_1 = require("./db");
|
71
|
+
const utils_1 = require("./utils");
|
72
|
+
async function main() {
|
73
|
+
(0, net_1.startPeer)({});
|
74
|
+
const tasks = new tasks_1.Tasks();
|
75
|
+
setTimeout(() => {
|
76
|
+
tasks.start();
|
77
|
+
}, 10000);
|
78
|
+
(0, api_1.startApiServer)();
|
79
|
+
net_1.protocol.on('TransactionStatus', async (payload) => {
|
80
|
+
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
81
|
+
const peer = net_1.peerPool.getPeer(payload.peerId);
|
82
|
+
if (!peer) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
|
89
|
+
if (!transaction) {
|
90
|
+
return;
|
91
|
+
}
|
92
|
+
transaction.sourceStatus = payload.data.sourceStatus;
|
93
|
+
transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
|
94
|
+
transaction.sourceErrors = payload.data.sourceErrors;
|
95
|
+
transaction.sourceLogs = payload.data.sourceLogs;
|
96
|
+
transaction.targetStatus = payload.data.targetStatus;
|
97
|
+
transaction.targetTransactionHash = payload.data.targetTransactionHash;
|
98
|
+
transaction.targetErrors = payload.data.targetErrors;
|
99
|
+
transaction.targetLogs = payload.data.targetLogs;
|
100
|
+
transaction.status = payload.data.status;
|
101
|
+
await transaction.save();
|
102
|
+
});
|
103
|
+
}
|
104
|
+
main()
|
105
|
+
.then(() => {
|
106
|
+
}).catch(err => {
|
107
|
+
console.error(err);
|
108
|
+
});
|
109
|
+
process.on('SIGINT', () => {
|
110
|
+
logger.debug('received SIGINT signal. exiting.');
|
111
|
+
process.exit(0);
|
112
|
+
});
|
113
|
+
process.on('SIGTERM', () => {
|
114
|
+
logger.debug('received SIGTERM signal. exiting.');
|
115
|
+
process.exit(0);
|
116
|
+
});
|
117
|
+
process.on('unhandledRejection', (reason, p) => {
|
118
|
+
logger.error('unhandled rejection: promise:', p, 'reason:', reason);
|
119
|
+
});
|
File without changes
|
File without changes
|
@@ -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,13 +78,17 @@ 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
|
84
85
|
});
|
85
|
-
node.on("peer:discovery", (peer) =>
|
86
|
-
|
86
|
+
node.on("peer:discovery", (peer) => {
|
87
|
+
// logger.log(`Discovered peer ${peer}`)
|
88
|
+
}); // peer disc.
|
89
|
+
node.connectionManager.on("peer:connect", (connection) => {
|
90
|
+
// logger.log(`Connected to ${connection.remotePeer.toB58String()}`)
|
91
|
+
});
|
87
92
|
logger.log("Peer discovery started");
|
88
93
|
await (0, waait_1.default)(1000);
|
89
94
|
setInterval(() => net_1.protocol.sendPeerInfo({
|
@@ -6,6 +6,11 @@ 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 utils_2 = require("@/utils");
|
12
|
+
const chalk_1 = __importDefault(require("chalk"));
|
13
|
+
const logger = new logger_1.default('PeerPool');
|
9
14
|
class PeerPool {
|
10
15
|
constructor() {
|
11
16
|
this.PEERS_CLEANUP_TIME_LIMIT = 1;
|
@@ -62,10 +67,14 @@ class PeerPool {
|
|
62
67
|
* @emits {@link Event.POOL_PEER_ADDED}
|
63
68
|
*/
|
64
69
|
add(peer) {
|
65
|
-
if (peer && peer.id
|
70
|
+
if (peer && peer.id) {
|
71
|
+
const newPeer = !this.pool.get(peer.id);
|
66
72
|
this.pool.set(peer.id, peer);
|
67
73
|
peer.pooled = true;
|
68
|
-
|
74
|
+
if (newPeer) {
|
75
|
+
config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
|
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`);
|
77
|
+
}
|
69
78
|
}
|
70
79
|
}
|
71
80
|
/**
|
@@ -78,6 +87,7 @@ class PeerPool {
|
|
78
87
|
if (this.pool.delete(peer.id)) {
|
79
88
|
peer.pooled = false;
|
80
89
|
config_1.default.events.emit(types_1.Event.POOL_PEER_REMOVED, peer);
|
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`);
|
81
91
|
}
|
82
92
|
}
|
83
93
|
}
|
@@ -93,14 +103,27 @@ class PeerPool {
|
|
93
103
|
get activePeerIds() {
|
94
104
|
return this.activePeers.map((p) => p.id);
|
95
105
|
}
|
106
|
+
getPeer(id) {
|
107
|
+
return this.pool.get(id);
|
108
|
+
}
|
109
|
+
isLeadNode(id) {
|
110
|
+
const peer = this.pool.get(id);
|
111
|
+
if (!peer) {
|
112
|
+
return false;
|
113
|
+
}
|
114
|
+
return (0, utils_1.getAddress)(peer.publicAddress) === (0, utils_1.getAddress)(config_1.default.leadNodeAddress);
|
115
|
+
}
|
116
|
+
getLeadPeer() {
|
117
|
+
return this.peers.find((p) => this.isLeadNode(p.id));
|
118
|
+
}
|
96
119
|
cleanup() {
|
97
|
-
let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
98
|
-
this.peers.forEach((peerInfo) => {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
})
|
120
|
+
// let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
121
|
+
// this.peers.forEach((peerInfo) => {
|
122
|
+
// if (peerInfo.updated.getTime() < compDate) {
|
123
|
+
// console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
|
124
|
+
// this.remove(peerInfo)
|
125
|
+
// }
|
126
|
+
// })
|
104
127
|
}
|
105
128
|
}
|
106
129
|
exports.PeerPool = PeerPool;
|
File without changes
|
@@ -8,38 +8,47 @@ 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");
|
13
|
+
const gnosis_1 = require("@/gnosis");
|
11
14
|
class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
12
15
|
constructor(libp2p) {
|
13
16
|
super(libp2p, '/interop-x/signatures');
|
14
17
|
this.timeout = 30000;
|
15
18
|
}
|
16
19
|
async response(data) {
|
20
|
+
console.log({
|
21
|
+
tag: 'SignatureDialProtocol',
|
22
|
+
data
|
23
|
+
});
|
17
24
|
const signer = config_1.default.wallet;
|
18
|
-
let
|
25
|
+
let transaction;
|
19
26
|
let maxTimeout = 20000;
|
20
27
|
do {
|
21
|
-
|
22
|
-
if (!
|
28
|
+
transaction = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
|
29
|
+
if (!transaction) {
|
23
30
|
await (0, waait_1.default)(1000);
|
24
31
|
maxTimeout -= 1000;
|
25
32
|
}
|
26
|
-
} while (!
|
27
|
-
if (!
|
33
|
+
} while (!transaction && maxTimeout > 0);
|
34
|
+
if (!transaction) {
|
28
35
|
return {
|
29
36
|
signer: signer.address,
|
30
37
|
data: null,
|
31
38
|
error: 'Event not found'
|
32
39
|
};
|
33
40
|
}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
|
42
|
+
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
43
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
44
|
+
data: gnosisData,
|
45
|
+
chainId: transaction.sourceChainId,
|
46
|
+
safeTxGas: data.safeTxGas,
|
47
|
+
nonce: data.safeNonce,
|
48
|
+
}, { signer });
|
40
49
|
return {
|
41
50
|
signer: signer.address,
|
42
|
-
data:
|
51
|
+
data: signedData
|
43
52
|
};
|
44
53
|
}
|
45
54
|
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TransactionStatusDialProtocol = void 0;
|
4
|
+
const BaseDialProtocol_1 = require("./BaseDialProtocol");
|
5
|
+
const db_1 = require("@/db");
|
6
|
+
class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
7
|
+
constructor(libp2p) {
|
8
|
+
super(libp2p, '/interop-x/transaction-status');
|
9
|
+
this.timeout = 30000;
|
10
|
+
}
|
11
|
+
async response(transactionHash) {
|
12
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
13
|
+
if (!transaction) {
|
14
|
+
return null;
|
15
|
+
}
|
16
|
+
return {
|
17
|
+
transactionHash: transaction.transactionHash,
|
18
|
+
sourceStatus: transaction.sourceStatus,
|
19
|
+
sourceTransactionHash: transaction.sourceTransactionHash,
|
20
|
+
sourceErrors: transaction.sourceErrors,
|
21
|
+
sourceLogs: transaction.sourceLogs,
|
22
|
+
targetStatus: transaction.targetStatus,
|
23
|
+
targetTransactionHash: transaction.targetTransactionHash,
|
24
|
+
targetErrors: transaction.targetErrors,
|
25
|
+
targetLogs: transaction.targetLogs,
|
26
|
+
status: transaction.status,
|
27
|
+
};
|
28
|
+
}
|
29
|
+
}
|
30
|
+
exports.TransactionStatusDialProtocol = TransactionStatusDialProtocol;
|