@instadapp/interop-x 0.0.0-dev.868731f → 0.0.0-dev.8965b57

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. package/dist/package.json +8 -7
  2. package/dist/src/abi/index.js +2 -4
  3. package/dist/src/abi/interopXContract.json +391 -0
  4. package/dist/src/alias.js +10 -0
  5. package/dist/src/api/index.js +6 -3
  6. package/dist/src/config/index.js +11 -1
  7. package/dist/src/constants/addresses.js +3 -3
  8. package/dist/src/constants/index.js +0 -1
  9. package/dist/src/constants/tokens.js +31 -1
  10. package/dist/src/db/models/transaction.js +26 -10
  11. package/dist/src/gnosis/actions/index.js +9 -0
  12. package/dist/src/gnosis/actions/withdraw/index.js +55 -0
  13. package/dist/src/gnosis/index.js +20 -0
  14. package/dist/src/index.js +75 -24
  15. package/dist/src/net/peer/index.js +2 -1
  16. package/dist/src/net/pool/index.js +25 -9
  17. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +8 -2
  18. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  19. package/dist/src/net/protocol/index.js +51 -1
  20. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  21. package/dist/src/tasks/BaseTask.js +11 -3
  22. package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +152 -0
  23. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +77 -0
  24. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +89 -0
  25. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  26. package/dist/src/tasks/index.js +15 -8
  27. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  28. package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
  29. package/dist/src/typechain/factories/index.js +3 -5
  30. package/dist/src/typechain/index.js +3 -5
  31. package/dist/src/utils/index.js +32 -42
  32. package/package.json +8 -7
  33. package/src/abi/index.ts +2 -4
  34. package/src/abi/interopXContract.json +391 -0
  35. package/src/alias.ts +6 -0
  36. package/src/api/index.ts +5 -2
  37. package/src/config/index.ts +11 -1
  38. package/src/constants/addresses.ts +3 -3
  39. package/src/constants/index.ts +0 -1
  40. package/src/constants/tokens.ts +32 -2
  41. package/src/db/models/transaction.ts +64 -25
  42. package/src/gnosis/actions/index.ts +5 -0
  43. package/src/gnosis/actions/withdraw/index.ts +76 -0
  44. package/src/gnosis/index.ts +19 -0
  45. package/src/index.ts +96 -26
  46. package/src/net/peer/index.ts +2 -1
  47. package/src/net/pool/index.ts +33 -13
  48. package/src/net/protocol/dial/SignatureDialProtocol.ts +10 -4
  49. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  50. package/src/net/protocol/index.ts +67 -1
  51. package/src/tasks/AutoUpdateTask.ts +82 -0
  52. package/src/tasks/BaseTask.ts +13 -3
  53. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +216 -0
  54. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +114 -0
  55. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +120 -0
  56. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  57. package/src/tasks/index.ts +23 -9
  58. package/src/typechain/InteropXContract.ts +524 -0
  59. package/src/typechain/factories/InteropXContract__factory.ts +533 -0
  60. package/src/typechain/factories/index.ts +1 -2
  61. package/src/typechain/index.ts +2 -4
  62. package/src/utils/index.ts +67 -65
  63. package/tsconfig.json +7 -2
  64. package/dist/src/abi/interopBridgeToken.json +0 -286
  65. package/dist/src/abi/interopXGateway.json +0 -184
  66. package/dist/src/constants/itokens.js +0 -13
  67. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -152
  68. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
  69. package/dist/src/typechain/InteropXGateway.js +0 -2
  70. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
  71. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  72. package/src/abi/interopBridgeToken.json +0 -286
  73. package/src/abi/interopXGateway.json +0 -184
  74. package/src/constants/itokens.ts +0 -10
  75. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -247
  76. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
  77. package/src/typechain/InteropBridgeToken.ts +0 -686
  78. package/src/typechain/InteropXGateway.ts +0 -407
  79. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  80. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -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 (!this.leadNodeOnly) {
38
- return true;
38
+ if (config_1.default.isMaintenanceMode()) {
39
+ this.logger.warn('Maintenance mode is enabled. Skipping task.');
40
+ return false;
39
41
  }
40
- return config_1.default.isLeadNode();
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,152 @@
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
+ console.log(error);
62
+ transaction.sourceStatus = 'failed';
63
+ transaction.sourceErrors = [error.message];
64
+ transaction.targetStatus = 'failed';
65
+ transaction.status = 'failed';
66
+ await transaction.save();
67
+ net_1.protocol.sendTransaction(transaction);
68
+ return;
69
+ }
70
+ let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
71
+ baseGas: "0",
72
+ data,
73
+ gasPrice: "0",
74
+ gasToken: "0x0000000000000000000000000000000000000000",
75
+ nonce: '0',
76
+ operation: "1",
77
+ refundReceiver: "0x0000000000000000000000000000000000000000",
78
+ safeAddress: this.safeContractAddress,
79
+ safeTxGas: "79668",
80
+ to: constants_1.addresses[transaction.sourceChainId].multisend,
81
+ value: "0",
82
+ }, this.safeContract);
83
+ const owners = await this.safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
84
+ const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
85
+ console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
86
+ console.log(ownerPeerIds);
87
+ const signatures = await net_1.protocol.requestSignatures({
88
+ type: 'source',
89
+ transactionHash: transaction.transactionHash,
90
+ safeTxGas: gnosisTx.safeTxGas,
91
+ safeNonce: gnosisTx.nonce
92
+ }, ownerPeerIds);
93
+ const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x');
94
+ console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
95
+ if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
96
+ await transaction.save();
97
+ transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
98
+ transaction.sourceStatus = 'uninitialised';
99
+ await transaction.save();
100
+ const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
101
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
102
+ }
103
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
104
+ 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));
105
+ const txSent = await this.sourceWallet.sendTransaction({
106
+ from: this.sourceWallet.address,
107
+ gasPrice: ethers_1.ethers.BigNumber.from(120 * 10 ** 9),
108
+ to: this.safeContractAddress,
109
+ data: txData,
110
+ });
111
+ console.log(txSent);
112
+ const receipt = await txSent.wait();
113
+ const parsedLogs = [];
114
+ receipt.logs.forEach((log) => {
115
+ try {
116
+ parsedLogs.push(this.safeContract.interface.parseLog(log));
117
+ }
118
+ catch (e) { }
119
+ });
120
+ if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
121
+ console.log('ExecutionSuccess');
122
+ transaction.sourceStatus = 'success';
123
+ if (txSent.blockNumber)
124
+ transaction.sourceBlockNumber = txSent.blockNumber;
125
+ transaction.sourceTransactionHash = txSent.hash;
126
+ transaction.sourceLogs = logs;
127
+ transaction.status = 'success';
128
+ await transaction.save();
129
+ }
130
+ else {
131
+ console.log('ExecutionFailure');
132
+ transaction.sourceStatus = 'failed';
133
+ if (txSent.blockNumber)
134
+ transaction.sourceBlockNumber = txSent.blockNumber;
135
+ transaction.sourceTransactionHash = txSent.hash;
136
+ transaction.sourceTransactionHash = txSent.hash;
137
+ transaction.status = 'failed';
138
+ await transaction.save();
139
+ }
140
+ net_1.protocol.sendTransaction(transaction);
141
+ }
142
+ async start() {
143
+ this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
144
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
145
+ this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider);
146
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, this.sourceWallet);
147
+ this.safeContractAddress = constants_1.addresses[this.chainId].gnosisSafe;
148
+ this.safeContract = (0, utils_1.getContract)(this.safeContractAddress, abi_1.default.gnosisSafe, this.sourceWallet);
149
+ await super.start();
150
+ }
151
+ }
152
+ exports.default = ProccessBridgeRequestEvents;
@@ -0,0 +1,77 @@
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 { bridger, position, sourceChainId, targetChainId, metadata } = event.args;
31
+ const uniqueIdentifier = {
32
+ action: 'withdraw',
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
+ bridger,
45
+ position: {
46
+ withdraw: position.withdraw.map((v) => ({
47
+ sourceToken: v.sourceToken,
48
+ targetToken: v.targetToken,
49
+ amount: v.amount.toString()
50
+ })),
51
+ supply: position.supply.map((v) => ({
52
+ sourceToken: v.sourceToken,
53
+ targetToken: v.targetToken,
54
+ amount: v.amount.toString()
55
+ })),
56
+ },
57
+ sourceChainId: sourceChainId.toNumber(),
58
+ targetChainId: targetChainId.toNumber(),
59
+ metadata,
60
+ } }));
61
+ this.logger.info(`New bridge request received: ${transactionHash} `);
62
+ }
63
+ catch (error) {
64
+ this.logger.error(error);
65
+ }
66
+ }
67
+ if (processedEvents > 0)
68
+ this.logger.info(`${processedEvents} events processed`);
69
+ }
70
+ async start() {
71
+ this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
72
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
73
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
74
+ await super.start();
75
+ }
76
+ }
77
+ exports.default = SyncBridgeRequestEvents;
@@ -0,0 +1,89 @@
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 { bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
32
+ const uniqueIdentifier = {
33
+ action: 'withdraw',
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, sourceStatus: {
43
+ [sequelize_1.Op.ne]: 'success',
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
+ bridger,
55
+ position: {
56
+ withdraw: position.withdraw.map((v) => ({
57
+ sourceToken: v.sourceToken,
58
+ targetToken: v.targetToken,
59
+ amount: v.amount.toString()
60
+ })),
61
+ supply: position.supply.map((v) => ({
62
+ sourceToken: v.sourceToken,
63
+ targetToken: v.targetToken,
64
+ amount: v.amount.toString()
65
+ })),
66
+ },
67
+ sourceChainId: sourceChainId,
68
+ targetChainId: targetChainId,
69
+ metadata,
70
+ requestTransactionHash,
71
+ };
72
+ await transaction.save();
73
+ this.logger.info(`New bridge request sent received: ${transactionHash} `);
74
+ }
75
+ catch (error) {
76
+ this.logger.error(error);
77
+ }
78
+ }
79
+ if (processedEvents > 0)
80
+ this.logger.info(`${processedEvents} events processed`);
81
+ }
82
+ async start() {
83
+ this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
84
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
85
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
86
+ await super.start();
87
+ }
88
+ }
89
+ exports.default = SyncBridgeRequestSentEvents;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const 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: 'pending',
28
+ sourceCreatedAt: {
29
+ [sequelize_1.Op.gte]: new Date(Date.now() - 60 * 60 * 1000),
30
+ },
31
+ }
32
+ });
33
+ if (!transaction) {
34
+ return;
35
+ }
36
+ this.logger.info(`Requesting transaction status for ${transaction.transactionHash}`);
37
+ const transactionStatus = await net_1.protocol.requestTransactionStatus(transaction.transactionHash, leadNode.id);
38
+ if (!transactionStatus) {
39
+ return;
40
+ }
41
+ this.logger.info(`Received transaction status for ${transaction.transactionHash}`);
42
+ transaction.sourceStatus = transactionStatus.sourceStatus;
43
+ transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash;
44
+ transaction.sourceErrors = transactionStatus.sourceErrors;
45
+ transaction.sourceLogs = transactionStatus.sourceLogs;
46
+ transaction.targetStatus = transactionStatus.targetStatus;
47
+ transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
48
+ transaction.targetErrors = transactionStatus.targetErrors;
49
+ transaction.targetLogs = transactionStatus.targetLogs;
50
+ transaction.status = transactionStatus.status;
51
+ await transaction.save();
52
+ this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
53
+ }
54
+ }
55
+ exports.default = SyncTransactionStatusTask;
@@ -4,23 +4,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Tasks = void 0;
7
- const ProcessDepositEvents_1 = __importDefault(require("./InteropXGateway/ProcessDepositEvents"));
8
- const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
7
+ const waait_1 = __importDefault(require("waait"));
8
+ const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
9
+ const SyncBridgeRequestEvents_1 = __importDefault(require("./InteropXContract/SyncBridgeRequestEvents"));
10
+ const ProcessBridgeRequestEvents_1 = __importDefault(require("./InteropXContract/ProcessBridgeRequestEvents"));
11
+ const SyncBridgeRequestSentEvents_1 = __importDefault(require("./InteropXContract/SyncBridgeRequestSentEvents"));
9
12
  class Tasks {
10
13
  constructor() {
11
14
  this.tasks = [
12
- new SyncDepositEvents_1.default({
13
- chainId: 43114
14
- }),
15
- new ProcessDepositEvents_1.default({
16
- chainId: 43114
17
- })
15
+ // new SyncTransactionStatusTask(),
16
+ new AutoUpdateTask_1.default(),
17
+ // InteropXContract
18
+ new SyncBridgeRequestEvents_1.default({ chainId: 137 }),
19
+ new SyncBridgeRequestEvents_1.default({ chainId: 43114 }),
20
+ new SyncBridgeRequestSentEvents_1.default({ chainId: 137 }),
21
+ new SyncBridgeRequestSentEvents_1.default({ chainId: 43114 }),
22
+ new ProcessBridgeRequestEvents_1.default({ chainId: 137 }),
23
+ new ProcessBridgeRequestEvents_1.default({ chainId: 43114 }),
18
24
  ];
19
25
  }
20
26
  async start() {
21
27
  for (const task of this.tasks) {
22
28
  try {
23
29
  task.start();
30
+ await (0, waait_1.default)(1000);
24
31
  }
25
32
  catch (error) {
26
33
  console.error(`Error starting task: ${task.constructor.name}`);