@instadapp/interop-x 0.0.0-dev.9b1fcb8 → 0.0.0-dev.9e91661
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/package.json +6 -5
- package/dist/src/abi/interopBridgeToken.json +21 -9
- package/dist/src/abi/interopXGateway.json +11 -11
- package/dist/src/api/index.js +6 -3
- package/dist/src/config/index.js +11 -1
- package/dist/src/constants/addresses.js +1 -1
- package/dist/src/constants/itokens.js +1 -1
- package/dist/src/gnosis/actions/deposit.js +40 -0
- package/dist/src/gnosis/actions/index.js +11 -0
- package/dist/src/gnosis/actions/withdraw.js +45 -0
- package/dist/src/gnosis/index.js +16 -0
- package/dist/src/index.js +69 -7
- package/dist/src/net/peer/index.js +2 -1
- package/dist/src/net/pool/index.js +18 -2
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +2 -8
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
- package/dist/src/net/protocol/index.js +41 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/src/tasks/BaseTask.js +11 -3
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +147 -0
- package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +12 -9
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +18 -2
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -3
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
- package/dist/src/tasks/index.js +22 -3
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
- package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
- package/dist/src/utils/index.js +19 -40
- package/package.json +6 -5
- package/src/abi/interopBridgeToken.json +21 -9
- package/src/abi/interopXGateway.json +11 -11
- package/src/api/index.ts +5 -2
- package/src/config/index.ts +11 -1
- package/src/constants/addresses.ts +1 -1
- package/src/constants/itokens.ts +1 -1
- package/src/gnosis/actions/deposit.ts +54 -0
- package/src/gnosis/actions/index.ts +7 -0
- package/src/gnosis/actions/withdraw.ts +61 -0
- package/src/gnosis/index.ts +13 -0
- package/src/index.ts +90 -9
- package/src/net/peer/index.ts +2 -1
- package/src/net/pool/index.ts +25 -5
- package/src/net/protocol/dial/SignatureDialProtocol.ts +3 -10
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
- package/src/net/protocol/index.ts +57 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +13 -3
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +232 -0
- package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -11
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +24 -7
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -4
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
- package/src/tasks/index.ts +33 -3
- package/src/typechain/InteropBridgeToken.ts +23 -17
- package/src/typechain/InteropXGateway.ts +13 -13
- package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
- package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
- package/src/utils/index.ts +22 -62
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instadapp/interop-x",
|
3
|
-
"version": "0.0.0-dev.
|
3
|
+
"version": "0.0.0-dev.9e91661",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -24,9 +24,10 @@
|
|
24
24
|
},
|
25
25
|
"dependencies": {
|
26
26
|
"@achingbrain/libp2p-gossipsub": "^0.12.2",
|
27
|
+
"@fastify/cors": "^7.0.0",
|
28
|
+
"await-spawn": "^4.0.2",
|
27
29
|
"axios": "^0.27.1",
|
28
30
|
"axios-retry": "^3.2.4",
|
29
|
-
"bignumber.js": "^9.0.2",
|
30
31
|
"chalk": "4.1.2",
|
31
32
|
"dotenv": "^16.0.0",
|
32
33
|
"ethereumjs-util": "^7.1.4",
|
@@ -34,7 +35,7 @@
|
|
34
35
|
"ethers-multisend": "^2.1.1",
|
35
36
|
"expand-home-dir": "^0.0.3",
|
36
37
|
"fastify": "^3.28.0",
|
37
|
-
"
|
38
|
+
"fs-extra": "^10.1.0",
|
38
39
|
"libp2p": "^0.36.2",
|
39
40
|
"libp2p-bootstrap": "^0.14.0",
|
40
41
|
"libp2p-kad-dht": "^0.28.6",
|
@@ -46,6 +47,8 @@
|
|
46
47
|
"libp2p-websockets": "^0.16.2",
|
47
48
|
"luxon": "^2.3.2",
|
48
49
|
"module-alias": "^2.2.2",
|
50
|
+
"patch-package": "^6.4.7",
|
51
|
+
"postinstall-postinstall": "^2.1.0",
|
49
52
|
"sequelize": "6.18.0",
|
50
53
|
"sqlite3": "^5.0.5",
|
51
54
|
"waait": "^1.0.5"
|
@@ -60,8 +63,6 @@
|
|
60
63
|
"@types/fs-extra": "^9.0.13",
|
61
64
|
"@types/node": "^17.0.17",
|
62
65
|
"nodemon": "^2.0.15",
|
63
|
-
"patch-package": "^6.4.7",
|
64
|
-
"postinstall-postinstall": "^2.1.0",
|
65
66
|
"replace-in-file": "^6.3.2",
|
66
67
|
"rimraf": "^3.0.2",
|
67
68
|
"ts-node": "^10.5.0",
|
@@ -46,11 +46,17 @@
|
|
46
46
|
"name": "amount",
|
47
47
|
"type": "uint256"
|
48
48
|
},
|
49
|
+
{
|
50
|
+
"indexed": false,
|
51
|
+
"internalType": "uint32",
|
52
|
+
"name": "sourceChainId",
|
53
|
+
"type": "uint32"
|
54
|
+
},
|
49
55
|
{
|
50
56
|
"indexed": true,
|
51
|
-
"internalType": "
|
52
|
-
"name": "
|
53
|
-
"type": "
|
57
|
+
"internalType": "uint32",
|
58
|
+
"name": "targetChainId",
|
59
|
+
"type": "uint32"
|
54
60
|
}
|
55
61
|
],
|
56
62
|
"name": "Burn",
|
@@ -73,14 +79,20 @@
|
|
73
79
|
},
|
74
80
|
{
|
75
81
|
"indexed": true,
|
76
|
-
"internalType": "
|
77
|
-
"name": "
|
78
|
-
"type": "
|
82
|
+
"internalType": "uint32",
|
83
|
+
"name": "sourceChainId",
|
84
|
+
"type": "uint32"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"indexed": false,
|
88
|
+
"internalType": "uint32",
|
89
|
+
"name": "targetChainId",
|
90
|
+
"type": "uint32"
|
79
91
|
},
|
80
92
|
{
|
81
93
|
"indexed": true,
|
82
94
|
"internalType": "bytes32",
|
83
|
-
"name": "
|
95
|
+
"name": "submitTransactionHash",
|
84
96
|
"type": "bytes32"
|
85
97
|
}
|
86
98
|
],
|
@@ -164,7 +176,7 @@
|
|
164
176
|
"inputs": [
|
165
177
|
{ "internalType": "address", "name": "to", "type": "address" },
|
166
178
|
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
|
167
|
-
{ "internalType": "
|
179
|
+
{ "internalType": "uint32", "name": "chainId", "type": "uint32" }
|
168
180
|
],
|
169
181
|
"name": "burn",
|
170
182
|
"outputs": [],
|
@@ -206,7 +218,7 @@
|
|
206
218
|
"inputs": [
|
207
219
|
{ "internalType": "address", "name": "to", "type": "address" },
|
208
220
|
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
|
209
|
-
{ "internalType": "
|
221
|
+
{ "internalType": "uint32", "name": "chainId", "type": "uint32" },
|
210
222
|
{
|
211
223
|
"internalType": "bytes32",
|
212
224
|
"name": "transactionHash",
|
@@ -35,15 +35,15 @@
|
|
35
35
|
},
|
36
36
|
{
|
37
37
|
"indexed": false,
|
38
|
-
"internalType": "
|
38
|
+
"internalType": "uint32",
|
39
39
|
"name": "sourceChainId",
|
40
|
-
"type": "
|
40
|
+
"type": "uint32"
|
41
41
|
},
|
42
42
|
{
|
43
43
|
"indexed": true,
|
44
|
-
"internalType": "
|
44
|
+
"internalType": "uint32",
|
45
45
|
"name": "targetChainId",
|
46
|
-
"type": "
|
46
|
+
"type": "uint32"
|
47
47
|
}
|
48
48
|
],
|
49
49
|
"name": "LogGatewayDeposit",
|
@@ -72,15 +72,15 @@
|
|
72
72
|
},
|
73
73
|
{
|
74
74
|
"indexed": true,
|
75
|
-
"internalType": "
|
75
|
+
"internalType": "uint32",
|
76
76
|
"name": "sourceChainId",
|
77
|
-
"type": "
|
77
|
+
"type": "uint32"
|
78
78
|
},
|
79
79
|
{
|
80
80
|
"indexed": false,
|
81
|
-
"internalType": "
|
81
|
+
"internalType": "uint32",
|
82
82
|
"name": "targetChainId",
|
83
|
-
"type": "
|
83
|
+
"type": "uint32"
|
84
84
|
},
|
85
85
|
{
|
86
86
|
"indexed": true,
|
@@ -122,7 +122,7 @@
|
|
122
122
|
"inputs": [
|
123
123
|
{ "internalType": "address", "name": "token_", "type": "address" },
|
124
124
|
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
125
|
-
{ "internalType": "
|
125
|
+
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" }
|
126
126
|
],
|
127
127
|
"name": "deposit",
|
128
128
|
"outputs": [],
|
@@ -134,7 +134,7 @@
|
|
134
134
|
{ "internalType": "address", "name": "to_", "type": "address" },
|
135
135
|
{ "internalType": "address", "name": "token_", "type": "address" },
|
136
136
|
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
137
|
-
{ "internalType": "
|
137
|
+
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" }
|
138
138
|
],
|
139
139
|
"name": "depositFor",
|
140
140
|
"outputs": [],
|
@@ -160,7 +160,7 @@
|
|
160
160
|
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
161
161
|
{ "internalType": "address", "name": "user_", "type": "address" },
|
162
162
|
{ "internalType": "address", "name": "token_", "type": "address" },
|
163
|
-
{ "internalType": "
|
163
|
+
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" },
|
164
164
|
{
|
165
165
|
"internalType": "bytes32",
|
166
166
|
"name": "transactionHash_",
|
package/dist/src/api/index.js
CHANGED
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.startApiServer = void 0;
|
7
7
|
const fastify_1 = __importDefault(require("fastify"));
|
8
|
-
const
|
8
|
+
const cors_1 = __importDefault(require("@fastify/cors"));
|
9
9
|
const logger_1 = __importDefault(require("@/logger"));
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const logger = new logger_1.default("RPC");
|
12
12
|
const server = (0, fastify_1.default)({ logger: false });
|
13
|
-
server.register(
|
13
|
+
server.register(cors_1.default, {});
|
14
14
|
server.get('/', async () => 'Interop X API');
|
15
15
|
const startApiServer = async () => {
|
16
16
|
const HOST = process.env.API_HOST || '0.0.0.0';
|
@@ -20,13 +20,16 @@ const startApiServer = async () => {
|
|
20
20
|
return await db_1.Transaction.findAndCountAll({
|
21
21
|
limit: 20,
|
22
22
|
offset: 0,
|
23
|
+
order: [
|
24
|
+
['createdAt', 'DESC']
|
25
|
+
]
|
23
26
|
});
|
24
27
|
});
|
25
28
|
await server.listen(PORT, HOST);
|
26
29
|
logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
|
27
30
|
}
|
28
31
|
catch (err) {
|
29
|
-
logger.error(err);
|
32
|
+
logger.error(err.message);
|
30
33
|
process.exit(1);
|
31
34
|
}
|
32
35
|
};
|
package/dist/src/config/index.js
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
const ethers_1 = require("ethers");
|
4
7
|
const types_1 = require("@/types");
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
9
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
5
10
|
class Config {
|
6
11
|
constructor() {
|
7
12
|
this.events = new types_1.EventBus();
|
8
|
-
this.maxPeers =
|
13
|
+
this.maxPeers = 20;
|
9
14
|
this.privateKey = process.env.PRIVATE_KEY;
|
10
15
|
this.staging = !!process.env.STAGING && process.env.STAGING === 'true';
|
16
|
+
this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
11
17
|
this.wallet = new ethers_1.Wallet(this.privateKey);
|
12
18
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
|
19
|
+
this.baseConfigPath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
13
20
|
}
|
14
21
|
get publicAddress() {
|
15
22
|
return this.wallet.address;
|
@@ -17,5 +24,8 @@ class Config {
|
|
17
24
|
isLeadNode() {
|
18
25
|
return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
|
19
26
|
}
|
27
|
+
isMaintenanceMode() {
|
28
|
+
return fs_extra_1.default.existsSync(this.baseConfigPath + '/maintenance');
|
29
|
+
}
|
20
30
|
}
|
21
31
|
exports.default = new Config();
|
@@ -15,6 +15,6 @@ exports.addresses = {
|
|
15
15
|
43114: {
|
16
16
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
17
17
|
multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
|
18
|
-
interopXGateway: '
|
18
|
+
interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
|
19
19
|
}
|
20
20
|
};
|
@@ -0,0 +1,40 @@
|
|
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
|
+
if (transaction.sourceStatus === 'pending') {
|
15
|
+
throw Error('Cannot build data for pending deposit transaction');
|
16
|
+
}
|
17
|
+
if (!transaction.submitEvent) {
|
18
|
+
throw Error('Cannot build data for transaction without submitEvent');
|
19
|
+
}
|
20
|
+
const token = constants_1.tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
|
21
|
+
if (!token) {
|
22
|
+
throw Error(`Unsupported token ${transaction.submitEvent.token}`);
|
23
|
+
}
|
24
|
+
const itoken = constants_1.itokens[transaction.targetChainId].find(t => t.symbol.toLowerCase() === token.symbol.toLowerCase());
|
25
|
+
if (!itoken) {
|
26
|
+
throw Error(`Unsupported itoken ${token.symbol}`);
|
27
|
+
}
|
28
|
+
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
|
29
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
30
|
+
const interopBridgeContract = (0, utils_1.getContract)(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
|
31
|
+
const { data } = await interopBridgeContract.populateTransaction.mint(transaction.submitEvent.user, ethers_1.ethers.BigNumber.from(transaction.submitEvent.amount.toString()), ethers_1.ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()), transaction.submitTransactionHash);
|
32
|
+
transactions.push({
|
33
|
+
to: itoken.address,
|
34
|
+
data: data,
|
35
|
+
value: '0',
|
36
|
+
operation: ethers_multisend_1.OperationType.Call,
|
37
|
+
});
|
38
|
+
return transactions;
|
39
|
+
}
|
40
|
+
exports.default = default_1;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const deposit_1 = __importDefault(require("./deposit"));
|
7
|
+
const withdraw_1 = __importDefault(require("./withdraw"));
|
8
|
+
exports.default = {
|
9
|
+
deposit: deposit_1.default,
|
10
|
+
withdraw: withdraw_1.default,
|
11
|
+
};
|
@@ -0,0 +1,45 @@
|
|
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
|
+
if (transaction.action !== 'withdraw') {
|
15
|
+
throw new Error(`Invalid action: ${transaction.action}`);
|
16
|
+
}
|
17
|
+
if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
18
|
+
throw Error('Cannot build data for pending withdraw transaction');
|
19
|
+
}
|
20
|
+
if (!transaction.submitEvent) {
|
21
|
+
throw Error('Cannot build data for transaction without submitEvent');
|
22
|
+
}
|
23
|
+
const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
|
24
|
+
const itoken = constants_1.itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
|
25
|
+
if (!itoken) {
|
26
|
+
throw Error(`Unsupported itoken ${itokenAddress}`);
|
27
|
+
}
|
28
|
+
const token = constants_1.tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
|
29
|
+
if (!token) {
|
30
|
+
throw Error(`Unsupported token ${itoken.symbol}`);
|
31
|
+
}
|
32
|
+
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
33
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
34
|
+
const gatewayAddress = constants_1.addresses[targetChainId].interopXGateway;
|
35
|
+
const interopBridgeContract = (0, utils_1.getContract)(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
|
36
|
+
const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(sourceChainId.toString()), transaction.submitTransactionHash);
|
37
|
+
transactions.push({
|
38
|
+
to: gatewayAddress,
|
39
|
+
data: data,
|
40
|
+
value: '0',
|
41
|
+
operation: ethers_multisend_1.OperationType.Call,
|
42
|
+
});
|
43
|
+
return transactions;
|
44
|
+
}
|
45
|
+
exports.default = default_1;
|
@@ -0,0 +1,16 @@
|
|
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.buildGnosisData = void 0;
|
7
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
8
|
+
const actions_1 = __importDefault(require("./actions"));
|
9
|
+
const buildGnosisData = async (transaction, type) => {
|
10
|
+
type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
|
11
|
+
if (actions_1.default.hasOwnProperty(transaction.action)) {
|
12
|
+
return (0, ethers_multisend_1.encodeMulti)(actions_1.default[transaction.action](transaction, type)).data;
|
13
|
+
}
|
14
|
+
throw new Error(`Unknown action: ${transaction.action}`);
|
15
|
+
};
|
16
|
+
exports.buildGnosisData = buildGnosisData;
|
package/dist/src/index.js
CHANGED
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const module_alias_1 = __importDefault(require("module-alias"));
|
7
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
7
9
|
module_alias_1.default.addAliases({
|
8
10
|
"@/": __dirname + "/",
|
9
11
|
"@/logger": __dirname + "/logger",
|
@@ -19,36 +21,96 @@ module_alias_1.default.addAliases({
|
|
19
21
|
"@/typechain": __dirname + "/typechain"
|
20
22
|
});
|
21
23
|
(0, module_alias_1.default)();
|
22
|
-
const assert_1 = __importDefault(require("assert"));
|
23
24
|
const dotenv_1 = __importDefault(require("dotenv"));
|
25
|
+
const chalk_1 = __importDefault(require("chalk"));
|
24
26
|
const ethers_1 = require("ethers");
|
25
27
|
const package_json_1 = __importDefault(require("../package.json"));
|
26
28
|
dotenv_1.default.config();
|
27
29
|
const logger_1 = __importDefault(require("@/logger"));
|
28
30
|
const logger = new logger_1.default('Process');
|
29
|
-
|
31
|
+
const GIT_SHORT_HASH = '9e91661';
|
32
|
+
const printUsage = () => {
|
33
|
+
console.log();
|
34
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
35
|
+
console.log();
|
30
36
|
console.log('Usage:');
|
31
|
-
console.log('
|
32
|
-
console.log('
|
37
|
+
console.log(' interop-x help Show this message');
|
38
|
+
console.log(' interop-x version Print out the installed version of Interop X');
|
39
|
+
console.log();
|
40
|
+
console.log(' interop-x down Put the node into maintenance mode');
|
41
|
+
console.log(' interop-x up Take the node out of maintenance mode');
|
42
|
+
console.log();
|
43
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key');
|
44
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode');
|
45
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode');
|
46
|
+
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');
|
47
|
+
console.log();
|
48
|
+
};
|
49
|
+
if (process.argv.at(-1) === 'help') {
|
50
|
+
printUsage();
|
33
51
|
process.exit(0);
|
34
52
|
}
|
35
|
-
(0,
|
53
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
54
|
+
if (process.argv.at(-1) === 'down') {
|
55
|
+
fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
|
56
|
+
console.log(chalk_1.default.red('Maintenance mode enabled'));
|
57
|
+
process.exit(0);
|
58
|
+
}
|
59
|
+
if (process.argv.at(-1) === 'up') {
|
60
|
+
fs_extra_1.default.removeSync(basePath + '/maintenance');
|
61
|
+
console.log(chalk_1.default.green('Maintenance mode disabled'));
|
62
|
+
process.exit(0);
|
63
|
+
}
|
64
|
+
if (process.argv.at(-1) === 'version') {
|
65
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
66
|
+
process.exit(0);
|
67
|
+
}
|
68
|
+
if (!process.env.PRIVATE_KEY) {
|
69
|
+
console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
|
70
|
+
printUsage();
|
71
|
+
process.exit(1);
|
72
|
+
}
|
36
73
|
try {
|
37
74
|
new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
|
38
75
|
}
|
39
76
|
catch (e) {
|
40
|
-
|
77
|
+
console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
|
78
|
+
printUsage();
|
41
79
|
process.exit(1);
|
42
80
|
}
|
43
|
-
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev
|
81
|
+
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
44
82
|
const tasks_1 = require("@/tasks");
|
45
83
|
const net_1 = require("@/net");
|
46
84
|
const api_1 = require("@/api");
|
85
|
+
const db_1 = require("./db");
|
86
|
+
const utils_1 = require("./utils");
|
47
87
|
async function main() {
|
48
88
|
(0, net_1.startPeer)({});
|
49
89
|
const tasks = new tasks_1.Tasks();
|
50
90
|
tasks.start();
|
51
91
|
(0, api_1.startApiServer)();
|
92
|
+
net_1.protocol.on('TransactionStatus', async (payload) => {
|
93
|
+
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
94
|
+
const peer = net_1.peerPool.getPeer(payload.peerId);
|
95
|
+
if (!peer) {
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
|
102
|
+
if (!transaction) {
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
transaction.sourceStatus = payload.data.sourceStatus;
|
106
|
+
transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
|
107
|
+
transaction.sourceErrors = payload.data.sourceErrors;
|
108
|
+
transaction.targetStatus = payload.data.targetStatus;
|
109
|
+
transaction.targetTransactionHash = payload.data.targetTransactionHash;
|
110
|
+
transaction.targetErrors = payload.data.targetErrors;
|
111
|
+
transaction.status = payload.data.status;
|
112
|
+
await transaction.save();
|
113
|
+
});
|
52
114
|
}
|
53
115
|
main()
|
54
116
|
.then(() => {
|
@@ -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
|
@@ -7,6 +7,9 @@ exports.peerPool = exports.PeerPool = void 0;
|
|
7
7
|
const types_1 = require("@/types");
|
8
8
|
const config_1 = __importDefault(require("@/config"));
|
9
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"));
|
10
13
|
const logger = new logger_1.default('PeerPool');
|
11
14
|
class PeerPool {
|
12
15
|
constructor() {
|
@@ -70,7 +73,7 @@ class PeerPool {
|
|
70
73
|
peer.pooled = true;
|
71
74
|
if (newPeer) {
|
72
75
|
config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
|
73
|
-
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`);
|
74
77
|
}
|
75
78
|
}
|
76
79
|
}
|
@@ -84,7 +87,7 @@ class PeerPool {
|
|
84
87
|
if (this.pool.delete(peer.id)) {
|
85
88
|
peer.pooled = false;
|
86
89
|
config_1.default.events.emit(types_1.Event.POOL_PEER_REMOVED, peer);
|
87
|
-
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`);
|
88
91
|
}
|
89
92
|
}
|
90
93
|
}
|
@@ -100,6 +103,19 @@ class PeerPool {
|
|
100
103
|
get activePeerIds() {
|
101
104
|
return this.activePeers.map((p) => p.id);
|
102
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
|
+
}
|
103
119
|
cleanup() {
|
104
120
|
// let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
105
121
|
// this.peers.forEach((peerInfo) => {
|
@@ -10,6 +10,7 @@ const config_1 = __importDefault(require("@/config"));
|
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const utils_1 = require("@/utils");
|
12
12
|
const constants_1 = require("@/constants");
|
13
|
+
const gnosis_1 = require("@/gnosis");
|
13
14
|
class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
14
15
|
constructor(libp2p) {
|
15
16
|
super(libp2p, '/interop-x/signatures');
|
@@ -33,16 +34,9 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
33
34
|
error: 'Event not found'
|
34
35
|
};
|
35
36
|
}
|
36
|
-
console.log("signing:", {
|
37
|
-
to: constants_1.addresses[transaction.targetChainId].multisend,
|
38
|
-
data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
|
39
|
-
chainId: transaction.targetChainId,
|
40
|
-
safeTxGas: data.safeTxGas,
|
41
|
-
nonce: data.safeNonce,
|
42
|
-
});
|
43
37
|
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
44
38
|
to: constants_1.addresses[transaction.targetChainId].multisend,
|
45
|
-
data: await (0,
|
39
|
+
data: await (0, gnosis_1.buildGnosisData)(transaction, data.type),
|
46
40
|
chainId: transaction.targetChainId,
|
47
41
|
safeTxGas: data.safeTxGas,
|
48
42
|
nonce: data.safeNonce,
|
@@ -0,0 +1,28 @@
|
|
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
|
+
targetStatus: transaction.targetStatus,
|
22
|
+
targetTransactionHash: transaction.targetTransactionHash,
|
23
|
+
targetErrors: transaction.targetErrors,
|
24
|
+
status: transaction.status,
|
25
|
+
};
|
26
|
+
}
|
27
|
+
}
|
28
|
+
exports.TransactionStatusDialProtocol = TransactionStatusDialProtocol;
|