@instadapp/interop-x 0.0.0-dev.73da8c9 → 0.0.0-dev.73e5298
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +18 -16
- package/dist/src/abi/index.js +2 -4
- package/dist/src/abi/interopXContract.json +454 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +6 -3
- package/dist/src/config/index.js +11 -1
- package/dist/src/constants/addresses.js +7 -7
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +62 -39
- package/dist/src/db/models/transaction.js +27 -11
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +115 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +75 -24
- 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 +8 -2
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/src/net/protocol/index.js +51 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/src/tasks/BaseTask.js +11 -3
- package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +158 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +93 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +57 -0
- package/dist/src/tasks/index.js +18 -8
- package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +62 -47
- package/package.json +18 -16
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +454 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +5 -2
- package/src/config/index.ts +11 -1
- package/src/constants/addresses.ts +8 -8
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +63 -40
- package/src/db/models/transaction.ts +76 -27
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +155 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +96 -26
- package/src/net/peer/index.ts +2 -1
- package/src/net/pool/index.ts +25 -5
- package/src/net/protocol/dial/SignatureDialProtocol.ts +10 -4
- 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 +13 -3
- package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +226 -0
- package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +125 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +69 -0
- package/src/tasks/index.ts +27 -9
- package/src/typechain/InteropXContract.ts +680 -0
- package/src/typechain/factories/InteropXContract__factory.ts +642 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +103 -66
- package/tsconfig.json +7 -2
- package/dist/src/abi/interopBridgeToken.json +0 -286
- package/dist/src/abi/interopXGateway.json +0 -184
- package/dist/src/constants/itokens.js +0 -13
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -158
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
- package/dist/src/typechain/InteropXGateway.js +0 -2
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -253
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
- 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
@@ -10,13 +10,14 @@ 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 TransactionStatusDialProtocol_1 = require("./dial/TransactionStatusDialProtocol");
|
13
14
|
class Protocol extends stream_1.EventEmitter {
|
14
15
|
constructor() {
|
15
16
|
super(...arguments);
|
16
17
|
this.protocolMessages = [
|
17
18
|
{
|
18
19
|
name: 'PeerInfo',
|
19
|
-
code:
|
20
|
+
code: 0x01,
|
20
21
|
encode: (info) => [
|
21
22
|
Buffer.from(info.publicAddress),
|
22
23
|
],
|
@@ -24,6 +25,40 @@ class Protocol extends stream_1.EventEmitter {
|
|
24
25
|
publicAddress: publicAddress.toString(),
|
25
26
|
}),
|
26
27
|
},
|
28
|
+
{
|
29
|
+
name: 'TransactionStatus',
|
30
|
+
code: 0x02,
|
31
|
+
encode: (transaction) => [
|
32
|
+
Buffer.from(transaction.transactionHash),
|
33
|
+
Buffer.from(transaction.sourceStatus),
|
34
|
+
Buffer.from(transaction.sourceTransactionHash || ''),
|
35
|
+
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
36
|
+
transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
37
|
+
Buffer.from(transaction.targetStatus),
|
38
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
39
|
+
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
40
|
+
transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
41
|
+
Buffer.from(transaction.status),
|
42
|
+
],
|
43
|
+
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
|
44
|
+
transactionHash: transactionHash.toString(),
|
45
|
+
sourceStatus: sourceStatus.toString(),
|
46
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
47
|
+
sourceErrors: sourceErrors.map((e) => e.toString()),
|
48
|
+
sourceLogs: sourceLogs.map(e => ({
|
49
|
+
type: e[0].toString(),
|
50
|
+
message: e[1].toString(),
|
51
|
+
})),
|
52
|
+
targetStatus: targetStatus.toString(),
|
53
|
+
targetTransactionHash: targetTransactionHash.toString() || null,
|
54
|
+
targetErrors: targetErrors.map((e) => e.toString()),
|
55
|
+
targetLogs: targetLogs.map(e => ({
|
56
|
+
type: e[0].toString(),
|
57
|
+
message: e[1].toString(),
|
58
|
+
})),
|
59
|
+
status: status.toString(),
|
60
|
+
}),
|
61
|
+
},
|
27
62
|
];
|
28
63
|
}
|
29
64
|
start({ libp2p, topic = null, }) {
|
@@ -40,6 +75,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
40
75
|
});
|
41
76
|
});
|
42
77
|
this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
|
78
|
+
this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
|
43
79
|
}
|
44
80
|
init() {
|
45
81
|
this.libp2p.pubsub.subscribe(this.topic);
|
@@ -75,6 +111,11 @@ class Protocol extends stream_1.EventEmitter {
|
|
75
111
|
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(data)]);
|
76
112
|
this.libp2p.pubsub.publish(this.topic, encoded);
|
77
113
|
}
|
114
|
+
sendTransaction(transaction) {
|
115
|
+
const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
|
116
|
+
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
|
117
|
+
this.libp2p.pubsub.publish(this.topic, encoded);
|
118
|
+
}
|
78
119
|
async requestSignatures(data, peerIds) {
|
79
120
|
try {
|
80
121
|
peerIds = peerIds || __1.peerPool.activePeerIds;
|
@@ -88,5 +129,14 @@ class Protocol extends stream_1.EventEmitter {
|
|
88
129
|
return [];
|
89
130
|
}
|
90
131
|
}
|
132
|
+
async requestTransactionStatus(transactionHash, peerId) {
|
133
|
+
try {
|
134
|
+
return await this.transactionStatus.send(transactionHash, peerId);
|
135
|
+
}
|
136
|
+
catch (error) {
|
137
|
+
console.log(error);
|
138
|
+
return null;
|
139
|
+
}
|
140
|
+
}
|
91
141
|
}
|
92
142
|
exports.protocol = new Protocol();
|
@@ -0,0 +1,70 @@
|
|
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 await_spawn_1 = __importDefault(require("await-spawn"));
|
9
|
+
const child_process_1 = require("child_process");
|
10
|
+
const config_1 = __importDefault(require("@/config"));
|
11
|
+
const waait_1 = __importDefault(require("waait"));
|
12
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
13
|
+
const currentVersion = package_json_1.default.version;
|
14
|
+
const tag = config_1.default.staging ? 'dev' : 'latest';
|
15
|
+
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
16
|
+
constructor() {
|
17
|
+
super({
|
18
|
+
logger: new logger_1.default("AutoUpdateTask"),
|
19
|
+
});
|
20
|
+
this.pollIntervalMs = 60 * 10 * 1000;
|
21
|
+
}
|
22
|
+
prePollHandler() {
|
23
|
+
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
24
|
+
}
|
25
|
+
async getInstalledVersion() {
|
26
|
+
try {
|
27
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['-g', 'ls', '--depth=0', '--json']);
|
28
|
+
return JSON.parse(stdout.toString()).dependencies[package_json_1.default.name].version;
|
29
|
+
}
|
30
|
+
catch (error) {
|
31
|
+
this.logger.error(error);
|
32
|
+
return currentVersion;
|
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
|
+
}
|
45
|
+
async pollHandler() {
|
46
|
+
const version = await this.getLatestVersion();
|
47
|
+
if (version === currentVersion) {
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
this.logger.warn(`New version ${version} available.`);
|
51
|
+
this.logger.info('Updating...');
|
52
|
+
await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
53
|
+
await (0, waait_1.default)(5000);
|
54
|
+
if (version !== await this.getInstalledVersion()) {
|
55
|
+
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
this.logger.warn(`Installed version ${version}`);
|
59
|
+
this.logger.warn(`Restarting...`);
|
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), {
|
62
|
+
cwd: process.cwd(),
|
63
|
+
stdio: "inherit",
|
64
|
+
// shell: process.env.SHELL,
|
65
|
+
});
|
66
|
+
subprocess.unref();
|
67
|
+
process.exit();
|
68
|
+
}
|
69
|
+
}
|
70
|
+
exports.default = AutoUpdateTask;
|
@@ -14,6 +14,7 @@ class BaseTask extends events_1.default {
|
|
14
14
|
this.started = false;
|
15
15
|
this.pollIntervalMs = 10 * 1000;
|
16
16
|
this.leadNodeOnly = false;
|
17
|
+
this.exceptLeadNode = false;
|
17
18
|
this.logger = logger !== null && logger !== void 0 ? logger : new logger_1.default('BaseTask');
|
18
19
|
}
|
19
20
|
async pollCheck() {
|
@@ -34,10 +35,17 @@ class BaseTask extends events_1.default {
|
|
34
35
|
}
|
35
36
|
}
|
36
37
|
prePollHandler() {
|
37
|
-
if (
|
38
|
-
|
38
|
+
if (config_1.default.isMaintenanceMode()) {
|
39
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.');
|
40
|
+
return false;
|
39
41
|
}
|
40
|
-
|
42
|
+
if (this.exceptLeadNode) {
|
43
|
+
return !config_1.default.isLeadNode();
|
44
|
+
}
|
45
|
+
if (this.leadNodeOnly) {
|
46
|
+
return config_1.default.isLeadNode();
|
47
|
+
}
|
48
|
+
return true;
|
41
49
|
}
|
42
50
|
async pollHandler() {
|
43
51
|
this.logger.warn('pollHandler not implemented');
|
@@ -0,0 +1,158 @@
|
|
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 sequelize_1 = require("sequelize");
|
14
|
+
const config_1 = __importDefault(require("@/config"));
|
15
|
+
const waait_1 = __importDefault(require("waait"));
|
16
|
+
const gnosis_1 = require("@/gnosis");
|
17
|
+
const net_1 = require("@/net");
|
18
|
+
class ProccessBridgeRequestEvents extends BaseTask_1.BaseTask {
|
19
|
+
constructor({ chainId }) {
|
20
|
+
super({
|
21
|
+
logger: new logger_1.default("InteropXContract::ProccessBridgeRequestEvents"),
|
22
|
+
});
|
23
|
+
this.leadNodeOnly = true;
|
24
|
+
this.chainId = chainId;
|
25
|
+
}
|
26
|
+
async pollHandler() {
|
27
|
+
var _a;
|
28
|
+
const blockNumber = await this.provider.getBlockNumber();
|
29
|
+
const transaction = await db_1.Transaction.findOne({
|
30
|
+
where: {
|
31
|
+
status: 'pending',
|
32
|
+
sourceStatus: 'uninitialised',
|
33
|
+
createdAt: {
|
34
|
+
[sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
35
|
+
},
|
36
|
+
sourceDelayUntil: {
|
37
|
+
[sequelize_1.Op.or]: {
|
38
|
+
[sequelize_1.Op.is]: null,
|
39
|
+
[sequelize_1.Op.lt]: new Date(),
|
40
|
+
}
|
41
|
+
},
|
42
|
+
requestBlockNumber: {
|
43
|
+
[sequelize_1.Op.lt]: blockNumber - 12,
|
44
|
+
},
|
45
|
+
sourceChainId: this.chainId,
|
46
|
+
}
|
47
|
+
});
|
48
|
+
if (!transaction) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
console.log(`Processing transaction ${transaction.transactionHash}`);
|
52
|
+
transaction.targetStatus = 'pending';
|
53
|
+
await transaction.save();
|
54
|
+
const ownersThreshold = await this.safeContract.getThreshold();
|
55
|
+
await (0, waait_1.default)(10000);
|
56
|
+
let data, logs = [];
|
57
|
+
try {
|
58
|
+
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, 'source'));
|
59
|
+
}
|
60
|
+
catch (error) {
|
61
|
+
if (error instanceof utils_1.LiquidityError) {
|
62
|
+
await transaction.save();
|
63
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
64
|
+
transaction.sourceStatus = 'uninitialised';
|
65
|
+
await transaction.save();
|
66
|
+
throw error;
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
transaction.sourceStatus = 'failed';
|
70
|
+
transaction.sourceErrors = [error.message];
|
71
|
+
transaction.targetStatus = 'failed';
|
72
|
+
transaction.status = 'failed';
|
73
|
+
await transaction.save();
|
74
|
+
net_1.protocol.sendTransaction(transaction);
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
78
|
+
baseGas: "0",
|
79
|
+
data,
|
80
|
+
gasPrice: "0",
|
81
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
82
|
+
nonce: '0',
|
83
|
+
operation: "1",
|
84
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
85
|
+
safeAddress: this.safeContractAddress,
|
86
|
+
safeTxGas: "79668",
|
87
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
88
|
+
value: "0",
|
89
|
+
}, this.safeContract);
|
90
|
+
const owners = await this.safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
91
|
+
const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
|
92
|
+
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
93
|
+
console.log(ownerPeerIds);
|
94
|
+
const signatures = await net_1.protocol.requestSignatures({
|
95
|
+
type: 'source',
|
96
|
+
transactionHash: transaction.transactionHash,
|
97
|
+
safeTxGas: gnosisTx.safeTxGas,
|
98
|
+
safeNonce: gnosisTx.nonce
|
99
|
+
}, ownerPeerIds);
|
100
|
+
const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x');
|
101
|
+
console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
|
102
|
+
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
103
|
+
await transaction.save();
|
104
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
105
|
+
transaction.sourceStatus = 'uninitialised';
|
106
|
+
await transaction.save();
|
107
|
+
const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
108
|
+
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
109
|
+
}
|
110
|
+
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
111
|
+
const { data: txData } = await this.safeContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
|
112
|
+
const txSent = await this.sourceWallet.sendTransaction({
|
113
|
+
from: this.sourceWallet.address,
|
114
|
+
gasPrice: ethers_1.ethers.BigNumber.from(120 * 10 ** 9),
|
115
|
+
to: this.safeContractAddress,
|
116
|
+
data: txData,
|
117
|
+
});
|
118
|
+
console.log(txSent);
|
119
|
+
const receipt = await txSent.wait();
|
120
|
+
const parsedLogs = [];
|
121
|
+
receipt.logs.forEach((log) => {
|
122
|
+
try {
|
123
|
+
parsedLogs.push(this.safeContract.interface.parseLog(log));
|
124
|
+
}
|
125
|
+
catch (e) { }
|
126
|
+
});
|
127
|
+
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
128
|
+
console.log('ExecutionSuccess');
|
129
|
+
transaction.sourceStatus = 'success';
|
130
|
+
if (txSent.blockNumber)
|
131
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
132
|
+
transaction.sourceTransactionHash = txSent.hash;
|
133
|
+
transaction.sourceLogs = logs;
|
134
|
+
await transaction.save();
|
135
|
+
}
|
136
|
+
else {
|
137
|
+
console.log('ExecutionFailure');
|
138
|
+
transaction.sourceStatus = 'failed';
|
139
|
+
if (txSent.blockNumber)
|
140
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
141
|
+
transaction.sourceTransactionHash = txSent.hash;
|
142
|
+
transaction.sourceTransactionHash = txSent.hash;
|
143
|
+
transaction.status = 'failed';
|
144
|
+
await transaction.save();
|
145
|
+
}
|
146
|
+
net_1.protocol.sendTransaction(transaction);
|
147
|
+
}
|
148
|
+
async start() {
|
149
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
150
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
151
|
+
this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider);
|
152
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, this.sourceWallet);
|
153
|
+
this.safeContractAddress = constants_1.addresses[this.chainId].gnosisSafe;
|
154
|
+
this.safeContract = (0, utils_1.getContract)(this.safeContractAddress, abi_1.default.gnosisSafe, this.sourceWallet);
|
155
|
+
await super.start();
|
156
|
+
}
|
157
|
+
}
|
158
|
+
exports.default = ProccessBridgeRequestEvents;
|
@@ -0,0 +1,93 @@
|
|
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
|
+
const sequelize_1 = require("sequelize");
|
15
|
+
class SyncBridgeCommittedEvents extends BaseTask_1.BaseTask {
|
16
|
+
constructor({ chainId }) {
|
17
|
+
super({
|
18
|
+
logger: new logger_1.default("InteropXContract::SyncBridgeCommittedEvents"),
|
19
|
+
});
|
20
|
+
this.chainId = chainId;
|
21
|
+
}
|
22
|
+
async pollHandler() {
|
23
|
+
const currentBlock = await this.provider.getBlockNumber();
|
24
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogBridgeCommitted(), currentBlock - 2000, currentBlock);
|
25
|
+
let processedEvents = 0;
|
26
|
+
for (const event of events) {
|
27
|
+
try {
|
28
|
+
if (!event.args) {
|
29
|
+
continue;
|
30
|
+
}
|
31
|
+
const { actionId, bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
|
32
|
+
const uniqueIdentifier = {
|
33
|
+
actionId,
|
34
|
+
bridger,
|
35
|
+
requestTransactionHash,
|
36
|
+
sourceChainId: sourceChainId,
|
37
|
+
targetChainId: targetChainId,
|
38
|
+
};
|
39
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
40
|
+
const transaction = await db_1.Transaction.findOne({
|
41
|
+
where: {
|
42
|
+
transactionHash,
|
43
|
+
sourceStatus: 'success',
|
44
|
+
committedEvent: {
|
45
|
+
[sequelize_1.Op.eq]: null,
|
46
|
+
}
|
47
|
+
}
|
48
|
+
});
|
49
|
+
if (!transaction) {
|
50
|
+
continue;
|
51
|
+
}
|
52
|
+
transaction.targetStatus = 'success';
|
53
|
+
transaction.targetBlockNumber = event.blockNumber;
|
54
|
+
transaction.targetTransactionHash = event.transactionHash;
|
55
|
+
transaction.committedEvent = {
|
56
|
+
actionId,
|
57
|
+
bridger,
|
58
|
+
position: {
|
59
|
+
withdraw: position.withdraw.map((v) => ({
|
60
|
+
sourceToken: v.sourceToken,
|
61
|
+
targetToken: v.targetToken,
|
62
|
+
amount: v.amount.toString()
|
63
|
+
})),
|
64
|
+
supply: position.supply.map((v) => ({
|
65
|
+
sourceToken: v.sourceToken,
|
66
|
+
targetToken: v.targetToken,
|
67
|
+
amount: v.amount.toString()
|
68
|
+
})),
|
69
|
+
},
|
70
|
+
sourceChainId: sourceChainId,
|
71
|
+
targetChainId: targetChainId,
|
72
|
+
metadata,
|
73
|
+
requestTransactionHash,
|
74
|
+
};
|
75
|
+
transaction.status = 'success';
|
76
|
+
await transaction.save();
|
77
|
+
this.logger.info(`New bridge committed received: ${transactionHash} `);
|
78
|
+
}
|
79
|
+
catch (error) {
|
80
|
+
this.logger.error(error);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
if (processedEvents > 0)
|
84
|
+
this.logger.info(`${processedEvents} events processed`);
|
85
|
+
}
|
86
|
+
async start() {
|
87
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
88
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
89
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
90
|
+
await super.start();
|
91
|
+
}
|
92
|
+
}
|
93
|
+
exports.default = SyncBridgeCommittedEvents;
|
@@ -0,0 +1,78 @@
|
|
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 SyncBridgeRequestEvents extends BaseTask_1.BaseTask {
|
15
|
+
constructor({ chainId }) {
|
16
|
+
super({
|
17
|
+
logger: new logger_1.default("InteropXContract::SyncBridgeRequestEvents"),
|
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.LogBridgeRequest(), currentBlock - 2000, currentBlock);
|
24
|
+
let processedEvents = 0;
|
25
|
+
for (const event of events) {
|
26
|
+
try {
|
27
|
+
if (!event.args) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
actionId,
|
33
|
+
bridger,
|
34
|
+
requestTransactionHash: event.transactionHash,
|
35
|
+
sourceChainId: sourceChainId.toNumber(),
|
36
|
+
targetChainId: targetChainId.toNumber(),
|
37
|
+
};
|
38
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
39
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
40
|
+
if (transaction) {
|
41
|
+
continue;
|
42
|
+
}
|
43
|
+
await db_1.Transaction.create(Object.assign(Object.assign({ transactionHash }, uniqueIdentifier), { requestBlockNumber: event.blockNumber, requestEvent: {
|
44
|
+
actionId,
|
45
|
+
bridger,
|
46
|
+
position: {
|
47
|
+
withdraw: position.withdraw.map((v) => ({
|
48
|
+
sourceToken: v.sourceToken,
|
49
|
+
targetToken: v.targetToken,
|
50
|
+
amount: v.amount.toString()
|
51
|
+
})),
|
52
|
+
supply: position.supply.map((v) => ({
|
53
|
+
sourceToken: v.sourceToken,
|
54
|
+
targetToken: v.targetToken,
|
55
|
+
amount: v.amount.toString()
|
56
|
+
})),
|
57
|
+
},
|
58
|
+
sourceChainId: sourceChainId.toNumber(),
|
59
|
+
targetChainId: targetChainId.toNumber(),
|
60
|
+
metadata,
|
61
|
+
} }));
|
62
|
+
this.logger.info(`New bridge request received: ${transactionHash} `);
|
63
|
+
}
|
64
|
+
catch (error) {
|
65
|
+
this.logger.error(error);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
if (processedEvents > 0)
|
69
|
+
this.logger.info(`${processedEvents} events processed`);
|
70
|
+
}
|
71
|
+
async start() {
|
72
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
73
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
74
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
75
|
+
await super.start();
|
76
|
+
}
|
77
|
+
}
|
78
|
+
exports.default = SyncBridgeRequestEvents;
|
@@ -0,0 +1,90 @@
|
|
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
|
+
const sequelize_1 = require("sequelize");
|
15
|
+
class SyncBridgeRequestSentEvents extends BaseTask_1.BaseTask {
|
16
|
+
constructor({ chainId }) {
|
17
|
+
super({
|
18
|
+
logger: new logger_1.default("InteropXContract::SyncBridgeRequestSentEvents"),
|
19
|
+
});
|
20
|
+
this.chainId = chainId;
|
21
|
+
}
|
22
|
+
async pollHandler() {
|
23
|
+
const currentBlock = await this.provider.getBlockNumber();
|
24
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogBridgeRequestSent(), currentBlock - 2000, currentBlock);
|
25
|
+
let processedEvents = 0;
|
26
|
+
for (const event of events) {
|
27
|
+
try {
|
28
|
+
if (!event.args) {
|
29
|
+
continue;
|
30
|
+
}
|
31
|
+
const { actionId, bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
|
32
|
+
const uniqueIdentifier = {
|
33
|
+
actionId,
|
34
|
+
bridger,
|
35
|
+
requestTransactionHash,
|
36
|
+
sourceChainId: sourceChainId,
|
37
|
+
targetChainId: targetChainId,
|
38
|
+
};
|
39
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
40
|
+
const transaction = await db_1.Transaction.findOne({
|
41
|
+
where: {
|
42
|
+
transactionHash, requestSentEvent: {
|
43
|
+
[sequelize_1.Op.eq]: null,
|
44
|
+
}
|
45
|
+
}
|
46
|
+
});
|
47
|
+
if (!transaction) {
|
48
|
+
continue;
|
49
|
+
}
|
50
|
+
transaction.sourceStatus = 'success';
|
51
|
+
transaction.sourceBlockNumber = event.blockNumber;
|
52
|
+
transaction.sourceTransactionHash = event.transactionHash;
|
53
|
+
transaction.requestSentEvent = {
|
54
|
+
actionId,
|
55
|
+
bridger,
|
56
|
+
position: {
|
57
|
+
withdraw: position.withdraw.map((v) => ({
|
58
|
+
sourceToken: v.sourceToken,
|
59
|
+
targetToken: v.targetToken,
|
60
|
+
amount: v.amount.toString()
|
61
|
+
})),
|
62
|
+
supply: position.supply.map((v) => ({
|
63
|
+
sourceToken: v.sourceToken,
|
64
|
+
targetToken: v.targetToken,
|
65
|
+
amount: v.amount.toString()
|
66
|
+
})),
|
67
|
+
},
|
68
|
+
sourceChainId: sourceChainId,
|
69
|
+
targetChainId: targetChainId,
|
70
|
+
metadata,
|
71
|
+
requestTransactionHash,
|
72
|
+
};
|
73
|
+
await transaction.save();
|
74
|
+
this.logger.info(`New bridge request sent received: ${transactionHash} `);
|
75
|
+
}
|
76
|
+
catch (error) {
|
77
|
+
this.logger.error(error);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
if (processedEvents > 0)
|
81
|
+
this.logger.info(`${processedEvents} events processed`);
|
82
|
+
}
|
83
|
+
async start() {
|
84
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
85
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
86
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
87
|
+
await super.start();
|
88
|
+
}
|
89
|
+
}
|
90
|
+
exports.default = SyncBridgeRequestSentEvents;
|
@@ -0,0 +1,57 @@
|
|
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 net_1 = require("@/net");
|
9
|
+
const db_1 = require("@/db");
|
10
|
+
const sequelize_1 = require("sequelize");
|
11
|
+
class SyncTransactionStatusTask extends BaseTask_1.BaseTask {
|
12
|
+
constructor() {
|
13
|
+
super({
|
14
|
+
logger: new logger_1.default("SyncTransactionStatusTask"),
|
15
|
+
});
|
16
|
+
this.pollIntervalMs = 60 * 1000;
|
17
|
+
this.exceptLeadNode = true;
|
18
|
+
}
|
19
|
+
async pollHandler() {
|
20
|
+
// if transaction is pending for more than 1 hour, check lead node for status
|
21
|
+
const leadNode = net_1.peerPool.getLeadPeer();
|
22
|
+
if (!leadNode) {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
const transaction = await db_1.Transaction.findOne({
|
26
|
+
where: {
|
27
|
+
status: {
|
28
|
+
[sequelize_1.Op.ne]: 'success'
|
29
|
+
},
|
30
|
+
sourceCreatedAt: {
|
31
|
+
[sequelize_1.Op.gte]: new Date(Date.now() - 60 * 60 * 1000),
|
32
|
+
},
|
33
|
+
}
|
34
|
+
});
|
35
|
+
if (!transaction) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
this.logger.info(`Requesting transaction status for ${transaction.transactionHash}`);
|
39
|
+
const transactionStatus = await net_1.protocol.requestTransactionStatus(transaction.transactionHash, leadNode.id);
|
40
|
+
if (!transactionStatus) {
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
this.logger.info(`Received transaction status for ${transaction.transactionHash}`);
|
44
|
+
transaction.sourceStatus = transactionStatus.sourceStatus;
|
45
|
+
transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash;
|
46
|
+
transaction.sourceErrors = transactionStatus.sourceErrors;
|
47
|
+
transaction.sourceLogs = transactionStatus.sourceLogs;
|
48
|
+
transaction.targetStatus = transactionStatus.targetStatus;
|
49
|
+
transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
|
50
|
+
transaction.targetErrors = transactionStatus.targetErrors;
|
51
|
+
transaction.targetLogs = transactionStatus.targetLogs;
|
52
|
+
transaction.status = transactionStatus.status;
|
53
|
+
await transaction.save();
|
54
|
+
this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
exports.default = SyncTransactionStatusTask;
|