@instadapp/interop-x 0.0.0-dev.67e7c3a → 0.0.0-dev.733ff78
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/package.json +4 -3
- 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 +10 -1
- package/dist/src/constants/addresses.js +1 -1
- package/dist/src/constants/itokens.js +1 -1
- package/dist/src/db/models/transaction.js +8 -0
- package/dist/src/gnosis/actions/deposit.js +48 -0
- package/dist/src/gnosis/actions/index.js +11 -0
- package/dist/src/gnosis/actions/withdraw.js +50 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +36 -6
- package/dist/src/net/peer/index.js +2 -1
- package/dist/src/net/pool/index.js +7 -2
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/src/net/protocol/index.js +26 -5
- package/dist/src/tasks/AutoUpdateTask.js +42 -16
- package/dist/src/tasks/BaseTask.js +11 -3
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +17 -2
- package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -9
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +16 -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 +55 -0
- package/dist/src/tasks/index.js +17 -4
- 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 +14 -85
- package/package.json +4 -3
- 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 +9 -1
- package/src/constants/addresses.ts +1 -1
- package/src/constants/itokens.ts +1 -1
- package/src/db/models/transaction.ts +10 -0
- package/src/gnosis/actions/deposit.ts +63 -0
- package/src/gnosis/actions/index.ts +7 -0
- package/src/gnosis/actions/withdraw.ts +67 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +49 -8
- package/src/net/peer/index.ts +2 -1
- package/src/net/pool/index.ts +7 -3
- package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +28 -6
- package/src/tasks/AutoUpdateTask.ts +48 -20
- package/src/tasks/BaseTask.ts +13 -3
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +24 -8
- package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -15
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +22 -7
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -4
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
- package/src/tasks/index.ts +25 -4
- 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 +16 -125
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.733ff78",
|
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,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,16 +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';
|
11
16
|
this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
12
17
|
this.wallet = new ethers_1.Wallet(this.privateKey);
|
13
18
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
|
19
|
+
this.baseConfigPath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
14
20
|
}
|
15
21
|
get publicAddress() {
|
16
22
|
return this.wallet.address;
|
@@ -18,5 +24,8 @@ class Config {
|
|
18
24
|
isLeadNode() {
|
19
25
|
return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
|
20
26
|
}
|
27
|
+
isMaintenanceMode() {
|
28
|
+
return fs_extra_1.default.existsSync(this.baseConfigPath + '/maintenance');
|
29
|
+
}
|
21
30
|
}
|
22
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
|
};
|
@@ -26,6 +26,10 @@ Transaction.init({
|
|
26
26
|
type: sequelize_2.DataTypes.JSON,
|
27
27
|
// defaultValue: [],
|
28
28
|
},
|
29
|
+
sourceLogs: {
|
30
|
+
type: sequelize_2.DataTypes.JSON,
|
31
|
+
// defaultValue: [],
|
32
|
+
},
|
29
33
|
sourceCreatedAt: {
|
30
34
|
type: sequelize_2.DataTypes.DATE,
|
31
35
|
defaultValue: Date.now()
|
@@ -39,6 +43,10 @@ Transaction.init({
|
|
39
43
|
type: sequelize_2.DataTypes.JSON,
|
40
44
|
// defaultValue: [],
|
41
45
|
},
|
46
|
+
targetLogs: {
|
47
|
+
type: sequelize_2.DataTypes.JSON,
|
48
|
+
// defaultValue: [],
|
49
|
+
},
|
42
50
|
targetCreatedAt: sequelize_2.DataTypes.DATE,
|
43
51
|
targetDelayUntil: sequelize_2.DataTypes.DATE,
|
44
52
|
submitEvent: sequelize_2.DataTypes.JSON,
|
@@ -0,0 +1,48 @@
|
|
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.sourceStatus === 'pending') {
|
16
|
+
throw Error('Cannot build data for pending deposit transaction');
|
17
|
+
}
|
18
|
+
if (!transaction.submitEvent) {
|
19
|
+
throw Error('Cannot build data for transaction without submitEvent');
|
20
|
+
}
|
21
|
+
const token = constants_1.tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
|
22
|
+
if (!token) {
|
23
|
+
throw Error(`Unsupported token ${transaction.submitEvent.token}`);
|
24
|
+
}
|
25
|
+
const itoken = constants_1.itokens[transaction.targetChainId].find(t => t.symbol.toLowerCase() === token.symbol.toLowerCase());
|
26
|
+
if (!itoken) {
|
27
|
+
throw Error(`Unsupported itoken ${token.symbol}`);
|
28
|
+
}
|
29
|
+
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
|
30
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
31
|
+
const interopBridgeContract = (0, utils_1.getContract)(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
|
32
|
+
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);
|
33
|
+
transactions.push({
|
34
|
+
to: itoken.address,
|
35
|
+
data: data,
|
36
|
+
value: '0',
|
37
|
+
operation: ethers_multisend_1.OperationType.Call,
|
38
|
+
});
|
39
|
+
logs.push({
|
40
|
+
type: 'mint',
|
41
|
+
message: `Minted ${transaction.submitEvent.amount / 10 ** token.decimals} ${token.symbol} to ${transaction.submitEvent.user}`,
|
42
|
+
});
|
43
|
+
return {
|
44
|
+
transactions,
|
45
|
+
logs,
|
46
|
+
};
|
47
|
+
}
|
48
|
+
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,50 @@
|
|
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 (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
19
|
+
throw Error('Cannot build data for pending withdraw transaction');
|
20
|
+
}
|
21
|
+
if (!transaction.submitEvent) {
|
22
|
+
throw Error('Cannot build data for transaction without submitEvent');
|
23
|
+
}
|
24
|
+
const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
|
25
|
+
const itoken = constants_1.itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
|
26
|
+
if (!itoken) {
|
27
|
+
throw Error(`Unsupported itoken ${itokenAddress}`);
|
28
|
+
}
|
29
|
+
const token = constants_1.tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
|
30
|
+
if (!token) {
|
31
|
+
throw Error(`Unsupported token ${itoken.symbol}`);
|
32
|
+
}
|
33
|
+
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
34
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
35
|
+
const gatewayAddress = constants_1.addresses[targetChainId].interopXGateway;
|
36
|
+
const interopBridgeContract = (0, utils_1.getContract)(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
|
37
|
+
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);
|
38
|
+
transactions.push({
|
39
|
+
to: gatewayAddress,
|
40
|
+
data: data,
|
41
|
+
value: '0',
|
42
|
+
operation: ethers_multisend_1.OperationType.Call,
|
43
|
+
});
|
44
|
+
logs.push({
|
45
|
+
type: 'transfer',
|
46
|
+
message: `Transfer ${amount / 10 ** token.decimals} ${token.symbol} to ${to}`,
|
47
|
+
});
|
48
|
+
return { transactions, logs };
|
49
|
+
}
|
50
|
+
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 === 'pending' ? 'source' : 'target';
|
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;
|
package/dist/src/index.js
CHANGED
@@ -4,10 +4,13 @@ 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",
|
10
12
|
"@/tasks": __dirname + "/tasks",
|
13
|
+
"@/gnosis": __dirname + "/gnosis",
|
11
14
|
"@/utils": __dirname + "/utils",
|
12
15
|
"@/api": __dirname + "/api",
|
13
16
|
"@/net": __dirname + "/net",
|
@@ -26,18 +29,39 @@ const package_json_1 = __importDefault(require("../package.json"));
|
|
26
29
|
dotenv_1.default.config();
|
27
30
|
const logger_1 = __importDefault(require("@/logger"));
|
28
31
|
const logger = new logger_1.default('Process');
|
32
|
+
const GIT_SHORT_HASH = '733ff78';
|
29
33
|
const printUsage = () => {
|
34
|
+
console.log();
|
35
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
36
|
+
console.log();
|
30
37
|
console.log('Usage:');
|
31
|
-
console.log('
|
32
|
-
console.log('
|
33
|
-
console.log(
|
34
|
-
console.log('
|
38
|
+
console.log(' interop-x help Show this message');
|
39
|
+
console.log(' interop-x version Print out the installed version of Interop X');
|
40
|
+
console.log();
|
41
|
+
console.log(' interop-x down Put the node into maintenance mode');
|
42
|
+
console.log(' interop-x up Take the node out of maintenance mode');
|
43
|
+
console.log();
|
44
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key');
|
45
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode');
|
46
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode');
|
47
|
+
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');
|
48
|
+
console.log();
|
35
49
|
};
|
36
50
|
if (process.argv.at(-1) === 'help') {
|
37
51
|
printUsage();
|
38
52
|
process.exit(0);
|
39
53
|
}
|
40
|
-
const
|
54
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
55
|
+
if (process.argv.at(-1) === 'down') {
|
56
|
+
fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
|
57
|
+
console.log(chalk_1.default.red('Maintenance mode enabled'));
|
58
|
+
process.exit(0);
|
59
|
+
}
|
60
|
+
if (process.argv.at(-1) === 'up') {
|
61
|
+
fs_extra_1.default.removeSync(basePath + '/maintenance');
|
62
|
+
console.log(chalk_1.default.green('Maintenance mode disabled'));
|
63
|
+
process.exit(0);
|
64
|
+
}
|
41
65
|
if (process.argv.at(-1) === 'version') {
|
42
66
|
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
43
67
|
process.exit(0);
|
@@ -60,6 +84,7 @@ const tasks_1 = require("@/tasks");
|
|
60
84
|
const net_1 = require("@/net");
|
61
85
|
const api_1 = require("@/api");
|
62
86
|
const db_1 = require("./db");
|
87
|
+
const utils_1 = require("./utils");
|
63
88
|
async function main() {
|
64
89
|
(0, net_1.startPeer)({});
|
65
90
|
const tasks = new tasks_1.Tasks();
|
@@ -68,7 +93,10 @@ async function main() {
|
|
68
93
|
net_1.protocol.on('TransactionStatus', async (payload) => {
|
69
94
|
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
70
95
|
const peer = net_1.peerPool.getPeer(payload.peerId);
|
71
|
-
|
96
|
+
if (!peer) {
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
|
72
100
|
return;
|
73
101
|
}
|
74
102
|
const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
|
@@ -78,9 +106,11 @@ async function main() {
|
|
78
106
|
transaction.sourceStatus = payload.data.sourceStatus;
|
79
107
|
transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
|
80
108
|
transaction.sourceErrors = payload.data.sourceErrors;
|
109
|
+
transaction.sourceLogs = payload.data.sourceLogs;
|
81
110
|
transaction.targetStatus = payload.data.targetStatus;
|
82
111
|
transaction.targetTransactionHash = payload.data.targetTransactionHash;
|
83
112
|
transaction.targetErrors = payload.data.targetErrors;
|
113
|
+
transaction.targetLogs = payload.data.targetLogs;
|
84
114
|
transaction.status = payload.data.status;
|
85
115
|
await transaction.save();
|
86
116
|
});
|
@@ -23,6 +23,7 @@ const libp2p_kad_dht_1 = __importDefault(require("libp2p-kad-dht"));
|
|
23
23
|
const libp2p_pubsub_peer_discovery_1 = __importDefault(require("libp2p-pubsub-peer-discovery"));
|
24
24
|
const net_1 = require("@/net");
|
25
25
|
const config_1 = __importDefault(require("@/config"));
|
26
|
+
const chalk_1 = __importDefault(require("chalk"));
|
26
27
|
const logger = new logger_1.default("Peer");
|
27
28
|
let node;
|
28
29
|
// Known peers addresses
|
@@ -77,7 +78,7 @@ const startPeer = async ({}) => {
|
|
77
78
|
persistence: true,
|
78
79
|
},
|
79
80
|
});
|
80
|
-
logger.info("Peer ID:", node.peerId.toB58String());
|
81
|
+
logger.info("Peer ID:", chalk_1.default.bold(node.peerId.toB58String()));
|
81
82
|
await node.start();
|
82
83
|
net_1.protocol.start({
|
83
84
|
libp2p: node
|
@@ -8,6 +8,8 @@ const types_1 = require("@/types");
|
|
8
8
|
const config_1 = __importDefault(require("@/config"));
|
9
9
|
const logger_1 = __importDefault(require("@/logger"));
|
10
10
|
const utils_1 = require("ethers/lib/utils");
|
11
|
+
const utils_2 = require("@/utils");
|
12
|
+
const chalk_1 = __importDefault(require("chalk"));
|
11
13
|
const logger = new logger_1.default('PeerPool');
|
12
14
|
class PeerPool {
|
13
15
|
constructor() {
|
@@ -71,7 +73,7 @@ class PeerPool {
|
|
71
73
|
peer.pooled = true;
|
72
74
|
if (newPeer) {
|
73
75
|
config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
|
74
|
-
logger.info(`Peer ${peer.id} with address ${peer.publicAddress} added to pool`);
|
76
|
+
logger.info(`Peer ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.id, 16))} with address ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.publicAddress))} added to pool`);
|
75
77
|
}
|
76
78
|
}
|
77
79
|
}
|
@@ -85,7 +87,7 @@ class PeerPool {
|
|
85
87
|
if (this.pool.delete(peer.id)) {
|
86
88
|
peer.pooled = false;
|
87
89
|
config_1.default.events.emit(types_1.Event.POOL_PEER_REMOVED, peer);
|
88
|
-
logger.info(`Peer ${peer.id} with address ${peer.publicAddress} removed from pool`);
|
90
|
+
logger.info(`Peer ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.id, 16))} with address ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.publicAddress))} removed from pool`);
|
89
91
|
}
|
90
92
|
}
|
91
93
|
}
|
@@ -111,6 +113,9 @@ class PeerPool {
|
|
111
113
|
}
|
112
114
|
return (0, utils_1.getAddress)(peer.publicAddress) === (0, utils_1.getAddress)(config_1.default.leadNodeAddress);
|
113
115
|
}
|
116
|
+
getLeadPeer() {
|
117
|
+
return this.peers.find((p) => this.isLeadNode(p.id));
|
118
|
+
}
|
114
119
|
cleanup() {
|
115
120
|
// let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
116
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,10 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
33
34
|
error: 'Event not found'
|
34
35
|
};
|
35
36
|
}
|
36
|
-
|
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
|
-
});
|
37
|
+
const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
|
43
38
|
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
44
39
|
to: constants_1.addresses[transaction.targetChainId].multisend,
|
45
|
-
data:
|
40
|
+
data: gnosisData,
|
46
41
|
chainId: transaction.targetChainId,
|
47
42
|
safeTxGas: data.safeTxGas,
|
48
43
|
nonce: data.safeNonce,
|
@@ -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;
|