@instadapp/interop-x 0.0.0-dev.6ea4ee5 → 0.0.0-dev.733ff78

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.
Files changed (91) hide show
  1. package/bin/interop-x +1 -1
  2. package/dist/package.json +73 -0
  3. package/dist/{abi → src/abi}/erc20.json +0 -0
  4. package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
  5. package/dist/{abi → src/abi}/index.js +0 -0
  6. package/dist/{abi → src/abi}/interopBridgeToken.json +21 -9
  7. package/dist/{abi → src/abi}/interopXGateway.json +11 -11
  8. package/dist/src/api/index.js +36 -0
  9. package/dist/{config → src/config}/index.js +11 -1
  10. package/dist/{constants → src/constants}/addresses.js +1 -9
  11. package/dist/{constants → src/constants}/index.js +1 -0
  12. package/dist/src/constants/itokens.js +13 -0
  13. package/dist/{constants → src/constants}/tokens.js +0 -0
  14. package/dist/{db → src/db}/index.js +0 -0
  15. package/dist/{db → src/db}/models/index.js +0 -0
  16. package/dist/{db → src/db}/models/transaction.js +11 -1
  17. package/dist/{db → src/db}/sequelize.js +1 -1
  18. package/dist/src/gnosis/actions/deposit.js +48 -0
  19. package/dist/src/gnosis/actions/index.js +11 -0
  20. package/dist/src/gnosis/actions/withdraw.js +50 -0
  21. package/dist/src/gnosis/index.js +20 -0
  22. package/dist/src/index.js +133 -0
  23. package/dist/{logger → src/logger}/index.js +0 -0
  24. package/dist/{net → src/net}/index.js +0 -0
  25. package/dist/{net → src/net}/peer/index.js +8 -3
  26. package/dist/{net → src/net}/pool/index.js +32 -9
  27. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
  28. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +17 -12
  29. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  30. package/dist/{net → src/net}/protocol/index.js +51 -1
  31. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  32. package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
  33. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +162 -0
  34. package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +71 -0
  35. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  36. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +164 -0
  37. package/dist/{tasks → src/tasks}/InteropXGateway/SyncDepositEvents.js +18 -23
  38. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  39. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  40. package/dist/src/tasks/index.js +55 -0
  41. package/dist/{typechain → src/typechain}/Erc20.js +0 -0
  42. package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
  43. package/dist/{typechain → src/typechain}/InteropBridgeToken.js +0 -0
  44. package/dist/{typechain → src/typechain}/InteropXGateway.js +0 -0
  45. package/dist/{typechain → src/typechain}/common.js +0 -0
  46. package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
  47. package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
  48. package/dist/{typechain → src/typechain}/factories/InteropBridgeToken__factory.js +23 -11
  49. package/dist/{typechain → src/typechain}/factories/InteropXGateway__factory.js +14 -14
  50. package/dist/{typechain → src/typechain}/factories/index.js +0 -0
  51. package/dist/{typechain → src/typechain}/index.js +0 -0
  52. package/dist/{types.js → src/types.js} +0 -0
  53. package/dist/{utils → src/utils}/index.js +62 -6
  54. package/package.json +12 -5
  55. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  56. package/src/abi/interopBridgeToken.json +21 -9
  57. package/src/abi/interopXGateway.json +11 -11
  58. package/src/api/index.ts +36 -0
  59. package/src/config/index.ts +11 -1
  60. package/src/constants/addresses.ts +1 -9
  61. package/src/constants/index.ts +1 -0
  62. package/src/constants/itokens.ts +10 -0
  63. package/src/db/models/transaction.ts +18 -4
  64. package/src/db/sequelize.ts +1 -1
  65. package/src/gnosis/actions/deposit.ts +63 -0
  66. package/src/gnosis/actions/index.ts +7 -0
  67. package/src/gnosis/actions/withdraw.ts +67 -0
  68. package/src/gnosis/index.ts +19 -0
  69. package/src/index.ts +99 -8
  70. package/src/net/peer/index.ts +9 -7
  71. package/src/net/pool/index.ts +41 -11
  72. package/src/net/protocol/dial/SignatureDialProtocol.ts +19 -13
  73. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  74. package/src/net/protocol/index.ts +67 -1
  75. package/src/tasks/AutoUpdateTask.ts +82 -0
  76. package/src/tasks/BaseTask.ts +14 -4
  77. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +249 -0
  78. package/src/tasks/InteropBridge/SyncBurnEvents.ts +119 -0
  79. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  80. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +260 -0
  81. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +25 -15
  82. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  83. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  84. package/src/tasks/index.ts +43 -2
  85. package/src/typechain/InteropBridgeToken.ts +23 -17
  86. package/src/typechain/InteropXGateway.ts +13 -13
  87. package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
  88. package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
  89. package/src/utils/index.ts +76 -7
  90. package/dist/index.js +0 -63
  91. package/dist/tasks/index.js +0 -27
@@ -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;
@@ -0,0 +1,164 @@
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
+ const waait_1 = __importDefault(require("waait"));
16
+ const net_1 = require("@/net");
17
+ const gnosis_1 = require("@/gnosis");
18
+ const generateGnosisTransaction = async (transactionData, safeContract) => {
19
+ console.log(transactionData);
20
+ let isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
21
+ while (isExecuted == 1) {
22
+ transactionData.safeTxGas = ethers_1.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString();
23
+ isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
24
+ }
25
+ return transactionData;
26
+ };
27
+ class ProcessDepositEvents extends BaseTask_1.BaseTask {
28
+ constructor({ chainId }) {
29
+ super({
30
+ logger: new logger_1.default("InteropXGateway::ProcessDepositEvents"),
31
+ });
32
+ this.leadNodeOnly = true;
33
+ this.chainId = chainId;
34
+ }
35
+ async pollHandler() {
36
+ var _a;
37
+ const blockNumber = await this.provider.getBlockNumber();
38
+ const transaction = await db_1.Transaction.findOne({
39
+ where: {
40
+ status: 'pending',
41
+ sourceStatus: 'success',
42
+ targetStatus: 'uninitialised',
43
+ action: 'deposit',
44
+ sourceCreatedAt: {
45
+ [sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
46
+ },
47
+ targetDelayUntil: {
48
+ [sequelize_1.Op.or]: {
49
+ [sequelize_1.Op.is]: null,
50
+ [sequelize_1.Op.lt]: new Date(),
51
+ }
52
+ },
53
+ sourceBlockNumber: {
54
+ [sequelize_1.Op.lt]: blockNumber - 12,
55
+ },
56
+ sourceChainId: this.chainId,
57
+ }
58
+ });
59
+ if (!transaction) {
60
+ return;
61
+ }
62
+ console.log(`Processing transaction ${transaction.transactionHash}`);
63
+ transaction.targetStatus = 'pending';
64
+ await transaction.save();
65
+ // refresh event data?
66
+ const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
67
+ const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
68
+ const safeAddress = constants_1.addresses[transaction.targetChainId].gnosisSafe;
69
+ const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
70
+ const ownersThreshold = await safeContract.getThreshold();
71
+ await (0, waait_1.default)(10000);
72
+ let data, logs = [];
73
+ try {
74
+ ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction));
75
+ }
76
+ catch (error) {
77
+ console.log(error);
78
+ transaction.targetStatus = 'failed';
79
+ transaction.targetErrors = [error.message];
80
+ transaction.status = 'failed';
81
+ await transaction.save();
82
+ net_1.protocol.sendTransaction(transaction);
83
+ return;
84
+ }
85
+ let gnosisTx = await generateGnosisTransaction({
86
+ baseGas: "0",
87
+ data,
88
+ gasPrice: "0",
89
+ gasToken: "0x0000000000000000000000000000000000000000",
90
+ nonce: '0',
91
+ operation: "1",
92
+ refundReceiver: "0x0000000000000000000000000000000000000000",
93
+ safeAddress: safeAddress,
94
+ safeTxGas: "79668",
95
+ to: constants_1.addresses[transaction.targetChainId].multisend,
96
+ value: "0",
97
+ }, safeContract);
98
+ const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
99
+ const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
100
+ console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
101
+ console.log(ownerPeerIds);
102
+ const signatures = await net_1.protocol.requestSignatures({
103
+ type: 'source',
104
+ transactionHash: transaction.transactionHash,
105
+ safeTxGas: gnosisTx.safeTxGas,
106
+ safeNonce: gnosisTx.nonce
107
+ }, ownerPeerIds);
108
+ const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x');
109
+ console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
110
+ if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
111
+ await transaction.save();
112
+ transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
113
+ transaction.targetStatus = 'uninitialised';
114
+ await transaction.save();
115
+ const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
116
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
117
+ }
118
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
119
+ const { data: txData } = await 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));
120
+ console.log({
121
+ from: targetWallet.address,
122
+ gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9).toString(),
123
+ to: safeAddress,
124
+ data: txData,
125
+ });
126
+ const txSent = await targetWallet.sendTransaction({
127
+ from: targetWallet.address,
128
+ gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9),
129
+ to: safeAddress,
130
+ data: txData,
131
+ });
132
+ const receipt = await txSent.wait();
133
+ const parsedLogs = [];
134
+ receipt.logs.forEach((log) => {
135
+ try {
136
+ parsedLogs.push(safeContract.interface.parseLog(log));
137
+ }
138
+ catch (e) { }
139
+ });
140
+ if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
141
+ console.log('ExecutionSuccess');
142
+ transaction.targetStatus = 'success';
143
+ transaction.targetTransactionHash = txSent.hash;
144
+ transaction.targetLogs = logs;
145
+ transaction.status = 'success';
146
+ await transaction.save();
147
+ }
148
+ else {
149
+ console.log('ExecutionFailure');
150
+ transaction.targetStatus = 'failed';
151
+ transaction.targetTransactionHash = txSent.hash;
152
+ transaction.status = 'failed';
153
+ await transaction.save();
154
+ }
155
+ net_1.protocol.sendTransaction(transaction);
156
+ }
157
+ async start() {
158
+ this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
159
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
160
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
161
+ await super.start();
162
+ }
163
+ }
164
+ exports.default = ProcessDepositEvents;
@@ -29,37 +29,33 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
29
29
  }
30
30
  const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
31
31
  const uniqueIdentifier = {
32
- type: 'desposit',
33
- sourceTransactionHash: event.transactionHash,
34
- sourceChainId: sourceChainId.toNumber(),
35
- targetChainId: targetChainId.toNumber(),
32
+ action: 'deposit',
33
+ submitTransactionHash: event.transactionHash,
34
+ sourceChainId: sourceChainId,
35
+ targetChainId: targetChainId,
36
36
  };
37
37
  if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
38
38
  continue;
39
39
  }
40
40
  const tx = await event.getTransaction();
41
- await db_1.Transaction.create({
42
- transactionHash: (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier),
43
- type: 'deposit',
44
- from: tx.from,
45
- to: user,
46
- sourceChainId: sourceChainId.toNumber(),
47
- sourceTransactionHash: event.transactionHash,
48
- sourceBlockNumber: event.blockNumber,
49
- sourceStatus: "uninitialised",
50
- targetChainId: targetChainId.toNumber(),
51
- targetStatus: "uninitialised",
52
- submitEvent: {
41
+ await db_1.Transaction.create(Object.assign(Object.assign({}, uniqueIdentifier), { transactionHash: (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier), from: tx.from, to: user, submitTransactionHash: event.transactionHash, submitBlockNumber: event.blockNumber,
42
+ // submit & source are the same
43
+ sourceTransactionHash: event.transactionHash, sourceBlockNumber: event.blockNumber, sourceStatus: "success", targetStatus: "uninitialised", submitEvent: {
53
44
  user,
54
45
  sourceChainId: sourceChainId.toString(),
55
46
  targetChainId: targetChainId.toString(),
56
47
  token: token,
57
- ammout: amount.toString(),
48
+ amount: amount.toString(),
58
49
  vnonce: vnonce.toString(),
59
- },
60
- status: "pending",
61
- });
62
- this.logger.info(`Execution queued: ${event.transactionHash} ${event.blockNumber}`);
50
+ }, sourceEvent: {
51
+ user,
52
+ sourceChainId: sourceChainId.toString(),
53
+ targetChainId: targetChainId.toString(),
54
+ token: token,
55
+ amount: amount.toString(),
56
+ vnonce: vnonce.toString(),
57
+ }, status: "pending" }));
58
+ this.logger.info(`Deposit queued: ${event.transactionHash} ${event.blockNumber}`);
63
59
  }
64
60
  catch (error) {
65
61
  this.logger.error(error);
@@ -69,10 +65,9 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
69
65
  this.logger.info(`${processedEvents} events processed`);
70
66
  }
71
67
  async start() {
72
- this.logger.info(`Starting execution watcher on interop chain`);
73
68
  this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
74
69
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
75
- this.contract = new ethers_1.ethers.Contract(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
70
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
76
71
  await super.start();
77
72
  }
78
73
  }
@@ -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;
@@ -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;
@@ -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
+ exports.Tasks = void 0;
7
+ const ProcessDepositEvents_1 = __importDefault(require("./InteropXGateway/ProcessDepositEvents"));
8
+ const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
9
+ const SyncWithdrawtEvents_1 = __importDefault(require("./InteropXGateway/SyncWithdrawtEvents"));
10
+ const ProcessWithdrawEvents_1 = __importDefault(require("./InteropBridge/ProcessWithdrawEvents"));
11
+ const SyncBurnEvents_1 = __importDefault(require("./InteropBridge/SyncBurnEvents"));
12
+ const SyncMintEvents_1 = __importDefault(require("./InteropBridge/SyncMintEvents"));
13
+ const SyncTransactionStatusTask_1 = __importDefault(require("./Transactions/SyncTransactionStatusTask"));
14
+ const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
15
+ class Tasks {
16
+ constructor() {
17
+ this.tasks = [
18
+ new SyncTransactionStatusTask_1.default(),
19
+ new AutoUpdateTask_1.default(),
20
+ // InteropXGateway
21
+ new SyncDepositEvents_1.default({
22
+ chainId: 43114
23
+ }),
24
+ new ProcessDepositEvents_1.default({
25
+ chainId: 43114
26
+ }),
27
+ new SyncWithdrawtEvents_1.default({
28
+ chainId: 43114
29
+ }),
30
+ // InteropBridge
31
+ new ProcessWithdrawEvents_1.default({
32
+ chainId: 137,
33
+ }),
34
+ new SyncMintEvents_1.default({
35
+ chainId: 137,
36
+ itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
37
+ }),
38
+ new SyncBurnEvents_1.default({
39
+ chainId: 137,
40
+ itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
41
+ })
42
+ ];
43
+ }
44
+ async start() {
45
+ for (const task of this.tasks) {
46
+ try {
47
+ task.start();
48
+ }
49
+ catch (error) {
50
+ console.error(`Error starting task: ${task.constructor.name}`);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ exports.Tasks = Tasks;
File without changes
File without changes
File without changes
@@ -57,11 +57,17 @@ const _abi = [
57
57
  name: "amount",
58
58
  type: "uint256",
59
59
  },
60
+ {
61
+ indexed: false,
62
+ internalType: "uint32",
63
+ name: "sourceChainId",
64
+ type: "uint32",
65
+ },
60
66
  {
61
67
  indexed: true,
62
- internalType: "uint256",
63
- name: "chainId",
64
- type: "uint256",
68
+ internalType: "uint32",
69
+ name: "targetChainId",
70
+ type: "uint32",
65
71
  },
66
72
  ],
67
73
  name: "Burn",
@@ -84,14 +90,20 @@ const _abi = [
84
90
  },
85
91
  {
86
92
  indexed: true,
87
- internalType: "uint256",
88
- name: "chainId",
89
- type: "uint256",
93
+ internalType: "uint32",
94
+ name: "sourceChainId",
95
+ type: "uint32",
96
+ },
97
+ {
98
+ indexed: false,
99
+ internalType: "uint32",
100
+ name: "targetChainId",
101
+ type: "uint32",
90
102
  },
91
103
  {
92
104
  indexed: true,
93
105
  internalType: "bytes32",
94
- name: "transactionHash",
106
+ name: "submitTransactionHash",
95
107
  type: "bytes32",
96
108
  },
97
109
  ],
@@ -222,9 +234,9 @@ const _abi = [
222
234
  type: "uint256",
223
235
  },
224
236
  {
225
- internalType: "uint256",
237
+ internalType: "uint32",
226
238
  name: "chainId",
227
- type: "uint256",
239
+ type: "uint32",
228
240
  },
229
241
  ],
230
242
  name: "burn",
@@ -306,9 +318,9 @@ const _abi = [
306
318
  type: "uint256",
307
319
  },
308
320
  {
309
- internalType: "uint256",
321
+ internalType: "uint32",
310
322
  name: "chainId",
311
- type: "uint256",
323
+ type: "uint32",
312
324
  },
313
325
  {
314
326
  internalType: "bytes32",
@@ -46,15 +46,15 @@ const _abi = [
46
46
  },
47
47
  {
48
48
  indexed: false,
49
- internalType: "uint256",
49
+ internalType: "uint32",
50
50
  name: "sourceChainId",
51
- type: "uint256",
51
+ type: "uint32",
52
52
  },
53
53
  {
54
54
  indexed: true,
55
- internalType: "uint256",
55
+ internalType: "uint32",
56
56
  name: "targetChainId",
57
- type: "uint256",
57
+ type: "uint32",
58
58
  },
59
59
  ],
60
60
  name: "LogGatewayDeposit",
@@ -83,15 +83,15 @@ const _abi = [
83
83
  },
84
84
  {
85
85
  indexed: true,
86
- internalType: "uint256",
86
+ internalType: "uint32",
87
87
  name: "sourceChainId",
88
- type: "uint256",
88
+ type: "uint32",
89
89
  },
90
90
  {
91
91
  indexed: false,
92
- internalType: "uint256",
92
+ internalType: "uint32",
93
93
  name: "targetChainId",
94
- type: "uint256",
94
+ type: "uint32",
95
95
  },
96
96
  {
97
97
  indexed: true,
@@ -148,9 +148,9 @@ const _abi = [
148
148
  type: "uint256",
149
149
  },
150
150
  {
151
- internalType: "uint256",
151
+ internalType: "uint32",
152
152
  name: "chainId_",
153
- type: "uint256",
153
+ type: "uint32",
154
154
  },
155
155
  ],
156
156
  name: "deposit",
@@ -176,9 +176,9 @@ const _abi = [
176
176
  type: "uint256",
177
177
  },
178
178
  {
179
- internalType: "uint256",
179
+ internalType: "uint32",
180
180
  name: "chainId_",
181
- type: "uint256",
181
+ type: "uint32",
182
182
  },
183
183
  ],
184
184
  name: "depositFor",
@@ -224,9 +224,9 @@ const _abi = [
224
224
  type: "address",
225
225
  },
226
226
  {
227
- internalType: "uint256",
227
+ internalType: "uint32",
228
228
  name: "chainId_",
229
- type: "uint256",
229
+ type: "uint32",
230
230
  },
231
231
  {
232
232
  internalType: "bytes32",
File without changes
File without changes