@instadapp/interop-x 0.0.0-dev.fabee70 → 0.0.0-dev.fded533
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/package.json +2 -2
- package/dist/src/abi/interopBridgeToken.json +21 -9
- package/dist/src/abi/interopXGateway.json +11 -11
- 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/index.js +28 -5
- package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +0 -0
- package/dist/src/net/protocol/index.js +6 -6
- package/dist/src/tasks/AutoUpdateTask.js +20 -7
- package/dist/src/tasks/BaseTask.js +4 -0
- package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -8
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +14 -1
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -2
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
- package/dist/src/tasks/index.js +16 -5
- 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 +6 -6
- package/package.json +2 -2
- package/src/abi/interopBridgeToken.json +21 -9
- package/src/abi/interopXGateway.json +11 -11
- package/src/config/index.ts +9 -1
- package/src/constants/addresses.ts +1 -1
- package/src/constants/itokens.ts +1 -1
- package/src/index.ts +41 -9
- package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +0 -0
- package/src/net/protocol/index.ts +5 -5
- package/src/tasks/AutoUpdateTask.ts +24 -15
- package/src/tasks/BaseTask.ts +5 -0
- package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +10 -8
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +18 -4
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -2
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/index.ts +24 -5
- 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 +6 -6
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.fded533",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -28,7 +28,6 @@
|
|
28
28
|
"await-spawn": "^4.0.2",
|
29
29
|
"axios": "^0.27.1",
|
30
30
|
"axios-retry": "^3.2.4",
|
31
|
-
"bignumber.js": "^9.0.2",
|
32
31
|
"chalk": "4.1.2",
|
33
32
|
"dotenv": "^16.0.0",
|
34
33
|
"ethereumjs-util": "^7.1.4",
|
@@ -36,6 +35,7 @@
|
|
36
35
|
"ethers-multisend": "^2.1.1",
|
37
36
|
"expand-home-dir": "^0.0.3",
|
38
37
|
"fastify": "^3.28.0",
|
38
|
+
"fs-extra": "^10.1.0",
|
39
39
|
"libp2p": "^0.36.2",
|
40
40
|
"libp2p-bootstrap": "^0.14.0",
|
41
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/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
|
};
|
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",
|
@@ -26,18 +28,39 @@ 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');
|
31
|
+
const GIT_SHORT_HASH = 'fded533';
|
29
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('
|
33
|
-
console.log(
|
34
|
-
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();
|
35
48
|
};
|
36
49
|
if (process.argv.at(-1) === 'help') {
|
37
50
|
printUsage();
|
38
51
|
process.exit(0);
|
39
52
|
}
|
40
|
-
const
|
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
|
+
}
|
41
64
|
if (process.argv.at(-1) === 'version') {
|
42
65
|
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
43
66
|
process.exit(0);
|
package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js}
RENAMED
File without changes
|
@@ -10,7 +10,7 @@ const SignatureDialProtocol_1 = require("./dial/SignatureDialProtocol");
|
|
10
10
|
const __1 = require("..");
|
11
11
|
const config_1 = __importDefault(require("@/config"));
|
12
12
|
const types_1 = require("@/types");
|
13
|
-
const
|
13
|
+
const TransactionStatusDialProtocol_1 = require("./dial/TransactionStatusDialProtocol");
|
14
14
|
class Protocol extends stream_1.EventEmitter {
|
15
15
|
constructor() {
|
16
16
|
super(...arguments);
|
@@ -31,20 +31,20 @@ class Protocol extends stream_1.EventEmitter {
|
|
31
31
|
encode: (transaction) => [
|
32
32
|
Buffer.from(transaction.transactionHash),
|
33
33
|
Buffer.from(transaction.sourceStatus),
|
34
|
-
Buffer.from(transaction.sourceTransactionHash),
|
34
|
+
Buffer.from(transaction.sourceTransactionHash || ''),
|
35
35
|
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
36
36
|
Buffer.from(transaction.targetStatus),
|
37
|
-
Buffer.from(transaction.targetTransactionHash),
|
37
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
38
38
|
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
39
39
|
Buffer.from(transaction.status),
|
40
40
|
],
|
41
41
|
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
|
42
42
|
transactionHash: transactionHash.toString(),
|
43
43
|
sourceStatus: sourceStatus.toString(),
|
44
|
-
sourceTransactionHash: sourceTransactionHash.toString(),
|
44
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
45
45
|
sourceErrors: sourceErrors.map((e) => e.toString()),
|
46
46
|
targetStatus: targetStatus.toString(),
|
47
|
-
targetTransactionHash: targetTransactionHash.toString(),
|
47
|
+
targetTransactionHash: targetTransactionHash.toString() || null,
|
48
48
|
targetErrors: targetErrors.map((e) => e.toString()),
|
49
49
|
status: status.toString(),
|
50
50
|
}),
|
@@ -65,7 +65,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
65
65
|
});
|
66
66
|
});
|
67
67
|
this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
|
68
|
-
this.transactionStatus = new
|
68
|
+
this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
|
69
69
|
}
|
70
70
|
init() {
|
71
71
|
this.libp2p.pubsub.subscribe(this.topic);
|
@@ -5,18 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const BaseTask_1 = require("./BaseTask");
|
7
7
|
const logger_1 = __importDefault(require("@/logger"));
|
8
|
-
const utils_1 = require("@/utils");
|
9
8
|
const await_spawn_1 = __importDefault(require("await-spawn"));
|
9
|
+
const child_process_1 = require("child_process");
|
10
10
|
const config_1 = __importDefault(require("@/config"));
|
11
11
|
const waait_1 = __importDefault(require("waait"));
|
12
12
|
const package_json_1 = __importDefault(require("../../package.json"));
|
13
13
|
const currentVersion = package_json_1.default.version;
|
14
|
+
const tag = config_1.default.staging ? 'dev' : 'latest';
|
14
15
|
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
15
16
|
constructor() {
|
16
17
|
super({
|
17
18
|
logger: new logger_1.default("AutoUpdateTask"),
|
18
19
|
});
|
19
|
-
this.pollIntervalMs = 60 *
|
20
|
+
this.pollIntervalMs = 60 * 10 * 1000;
|
20
21
|
}
|
21
22
|
prePollHandler() {
|
22
23
|
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
@@ -31,15 +32,24 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
31
32
|
return currentVersion;
|
32
33
|
}
|
33
34
|
}
|
35
|
+
async getLatestVersion() {
|
36
|
+
try {
|
37
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
|
38
|
+
return stdout.toString().trim();
|
39
|
+
}
|
40
|
+
catch (error) {
|
41
|
+
this.logger.error(error);
|
42
|
+
return currentVersion;
|
43
|
+
}
|
44
|
+
}
|
34
45
|
async pollHandler() {
|
35
|
-
const
|
36
|
-
const version = data['dist-tags'].latest;
|
46
|
+
const version = await this.getLatestVersion();
|
37
47
|
if (version === currentVersion) {
|
38
48
|
return;
|
39
49
|
}
|
40
50
|
this.logger.warn(`New version ${version} available.`);
|
41
51
|
this.logger.info('Updating...');
|
42
|
-
await (0, await_spawn_1.default)('npm', ['-g', 'install',
|
52
|
+
await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
43
53
|
await (0, waait_1.default)(5000);
|
44
54
|
if (version !== await this.getInstalledVersion()) {
|
45
55
|
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
|
@@ -47,10 +57,13 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
47
57
|
}
|
48
58
|
this.logger.warn(`Installed version ${version}`);
|
49
59
|
this.logger.warn(`Restarting...`);
|
50
|
-
|
60
|
+
// TODO: its restarting in the bg, but it should be in the fg
|
61
|
+
const subprocess = (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
|
51
62
|
cwd: process.cwd(),
|
52
|
-
stdio: "inherit"
|
63
|
+
stdio: "inherit",
|
64
|
+
// shell: process.env.SHELL,
|
53
65
|
});
|
66
|
+
subprocess.unref();
|
54
67
|
process.exit();
|
55
68
|
}
|
56
69
|
}
|
@@ -35,6 +35,10 @@ class BaseTask extends events_1.default {
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
prePollHandler() {
|
38
|
+
if (config_1.default.isMaintenanceMode()) {
|
39
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.');
|
40
|
+
return false;
|
41
|
+
}
|
38
42
|
if (this.exceptLeadNode) {
|
39
43
|
return !config_1.default.isLeadNode();
|
40
44
|
}
|
@@ -10,10 +10,10 @@ const abi_1 = __importDefault(require("@/abi"));
|
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const utils_1 = require("@/utils");
|
12
12
|
const config_1 = __importDefault(require("@/config"));
|
13
|
-
class
|
13
|
+
class SyncBurnEvents extends BaseTask_1.BaseTask {
|
14
14
|
constructor({ chainId, itokenAddress }) {
|
15
15
|
super({
|
16
|
-
logger: new logger_1.default("InteropBridgeToken::
|
16
|
+
logger: new logger_1.default("InteropBridgeToken::SyncBurnEvents"),
|
17
17
|
});
|
18
18
|
this.chainId = chainId;
|
19
19
|
this.itokenAddress = itokenAddress;
|
@@ -27,12 +27,12 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
|
|
27
27
|
if (!event.args) {
|
28
28
|
continue;
|
29
29
|
}
|
30
|
-
const { to, amount,
|
30
|
+
const { to, amount, sourceChainId, targetChainId } = event.args;
|
31
31
|
const uniqueIdentifier = {
|
32
32
|
action: 'withdraw',
|
33
33
|
submitTransactionHash: event.transactionHash,
|
34
|
-
sourceChainId:
|
35
|
-
targetChainId:
|
34
|
+
sourceChainId: sourceChainId,
|
35
|
+
targetChainId: targetChainId,
|
36
36
|
};
|
37
37
|
if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
|
38
38
|
continue;
|
@@ -44,12 +44,14 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
|
|
44
44
|
to,
|
45
45
|
amount: amount.toString(),
|
46
46
|
itoken: this.itokenAddress,
|
47
|
-
|
47
|
+
sourceChainId: sourceChainId,
|
48
|
+
targetChainId: targetChainId,
|
48
49
|
}, sourceEvent: {
|
49
50
|
to,
|
50
51
|
amount: amount.toString(),
|
51
52
|
itoken: this.itokenAddress,
|
52
|
-
|
53
|
+
sourceChainId: sourceChainId,
|
54
|
+
targetChainId: targetChainId,
|
53
55
|
}, status: "pending" }));
|
54
56
|
this.logger.info(`Withdraw queued: ${event.transactionHash} ${event.blockNumber}`);
|
55
57
|
}
|
@@ -66,4 +68,4 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
|
|
66
68
|
await super.start();
|
67
69
|
}
|
68
70
|
}
|
69
|
-
exports.default =
|
71
|
+
exports.default = SyncBurnEvents;
|
@@ -0,0 +1,67 @@
|
|
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 ethers_1 = require("ethers");
|
9
|
+
const abi_1 = __importDefault(require("@/abi"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const config_1 = __importDefault(require("@/config"));
|
13
|
+
class SyncMintEvents extends BaseTask_1.BaseTask {
|
14
|
+
constructor({ chainId, itokenAddress }) {
|
15
|
+
super({
|
16
|
+
logger: new logger_1.default("InteropBridgeToken::SyncMintEvents"),
|
17
|
+
});
|
18
|
+
this.chainId = chainId;
|
19
|
+
this.itokenAddress = itokenAddress;
|
20
|
+
}
|
21
|
+
async pollHandler() {
|
22
|
+
const currentBlock = await this.provider.getBlockNumber();
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.Mint(), currentBlock - 500, currentBlock);
|
24
|
+
for (const event of events) {
|
25
|
+
try {
|
26
|
+
if (!event.args) {
|
27
|
+
continue;
|
28
|
+
}
|
29
|
+
const { sourceChainId, targetChainId, amount, to, submitTransactionHash } = event.args;
|
30
|
+
const uniqueIdentifier = {
|
31
|
+
action: 'deposit',
|
32
|
+
submitTransactionHash: submitTransactionHash,
|
33
|
+
sourceChainId: sourceChainId,
|
34
|
+
targetChainId: targetChainId,
|
35
|
+
targetEvent: null
|
36
|
+
};
|
37
|
+
const transaction = await db_1.Transaction.findOne({ where: uniqueIdentifier });
|
38
|
+
if (!transaction) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
const tx = await event.getTransaction();
|
42
|
+
transaction.targetStatus = 'success';
|
43
|
+
transaction.targetErrors = [];
|
44
|
+
transaction.targetTransactionHash = tx.hash;
|
45
|
+
transaction.targetEvent = {
|
46
|
+
sourceChainId,
|
47
|
+
targetChainId,
|
48
|
+
amount: amount.toString(),
|
49
|
+
to,
|
50
|
+
submitTransactionHash
|
51
|
+
};
|
52
|
+
transaction.status = 'success';
|
53
|
+
await transaction.save();
|
54
|
+
this.logger.info(`Mint confirmation received: ${transaction.transactionHash} `);
|
55
|
+
}
|
56
|
+
catch (error) {
|
57
|
+
this.logger.error(error);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
async start() {
|
62
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
63
|
+
this.contract = (0, utils_1.getContract)(this.itokenAddress, abi_1.default.interopBridgeToken, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
64
|
+
await super.start();
|
65
|
+
}
|
66
|
+
}
|
67
|
+
exports.default = SyncMintEvents;
|
@@ -68,9 +68,22 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
68
68
|
const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
|
69
69
|
const ownersThreshold = await safeContract.getThreshold();
|
70
70
|
await (0, waait_1.default)(10000);
|
71
|
+
let data;
|
72
|
+
try {
|
73
|
+
data = await (0, utils_1.buildDataForTransaction)(transaction);
|
74
|
+
}
|
75
|
+
catch (error) {
|
76
|
+
console.log(error);
|
77
|
+
transaction.targetStatus = 'failed';
|
78
|
+
transaction.targetErrors = [error.message];
|
79
|
+
transaction.status = 'failed';
|
80
|
+
await transaction.save();
|
81
|
+
net_1.protocol.sendTransaction(transaction);
|
82
|
+
return;
|
83
|
+
}
|
71
84
|
let gnosisTx = await generateGnosisTransaction({
|
72
85
|
baseGas: "0",
|
73
|
-
data
|
86
|
+
data,
|
74
87
|
gasPrice: "0",
|
75
88
|
gasToken: "0x0000000000000000000000000000000000000000",
|
76
89
|
nonce: '0',
|
@@ -31,8 +31,8 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
|
|
31
31
|
const uniqueIdentifier = {
|
32
32
|
action: 'deposit',
|
33
33
|
submitTransactionHash: event.transactionHash,
|
34
|
-
sourceChainId: sourceChainId
|
35
|
-
targetChainId: targetChainId
|
34
|
+
sourceChainId: sourceChainId,
|
35
|
+
targetChainId: targetChainId,
|
36
36
|
};
|
37
37
|
if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
|
38
38
|
continue;
|
@@ -0,0 +1,72 @@
|
|
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 ethers_1 = require("ethers");
|
9
|
+
const abi_1 = __importDefault(require("@/abi"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const constants_1 = require("@/constants");
|
13
|
+
const config_1 = __importDefault(require("@/config"));
|
14
|
+
class SyncWithdrawEvents extends BaseTask_1.BaseTask {
|
15
|
+
constructor({ chainId }) {
|
16
|
+
super({
|
17
|
+
logger: new logger_1.default("InteropXGateway::SyncWithdrawEvents"),
|
18
|
+
});
|
19
|
+
this.chainId = chainId;
|
20
|
+
}
|
21
|
+
async pollHandler() {
|
22
|
+
const currentBlock = await this.provider.getBlockNumber();
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogGatewayWithdraw(), currentBlock - 500, currentBlock);
|
24
|
+
let processedEvents = 0;
|
25
|
+
for (const event of events) {
|
26
|
+
try {
|
27
|
+
if (!event.args) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
const { user, token, amount, sourceChainId, targetChainId, transactionHash } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
action: 'withdraw',
|
33
|
+
submitTransactionHash: transactionHash,
|
34
|
+
sourceChainId: sourceChainId,
|
35
|
+
targetChainId: targetChainId,
|
36
|
+
targetEvent: null
|
37
|
+
};
|
38
|
+
const transaction = await db_1.Transaction.findOne({ where: uniqueIdentifier });
|
39
|
+
if (!transaction) {
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
const tx = await event.getTransaction();
|
43
|
+
transaction.targetStatus = 'success';
|
44
|
+
transaction.targetErrors = [];
|
45
|
+
transaction.targetTransactionHash = tx.hash;
|
46
|
+
transaction.targetEvent = {
|
47
|
+
user,
|
48
|
+
token,
|
49
|
+
amount: amount.toString(),
|
50
|
+
sourceChainId,
|
51
|
+
targetChainId,
|
52
|
+
transactionHash,
|
53
|
+
};
|
54
|
+
transaction.status = 'success';
|
55
|
+
await transaction.save();
|
56
|
+
this.logger.info(`Witdraw confirmation received: ${transaction.transactionHash} `);
|
57
|
+
}
|
58
|
+
catch (error) {
|
59
|
+
this.logger.error(error);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
if (processedEvents > 0)
|
63
|
+
this.logger.info(`${processedEvents} events processed`);
|
64
|
+
}
|
65
|
+
async start() {
|
66
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
|
67
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
68
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
69
|
+
await super.start();
|
70
|
+
}
|
71
|
+
}
|
72
|
+
exports.default = SyncWithdrawEvents;
|