@instadapp/interop-x 0.0.0-dev.fd7fd6f → 0.0.0-dev.fded533

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 (52) hide show
  1. package/dist/package.json +4 -3
  2. package/dist/src/abi/interopBridgeToken.json +21 -9
  3. package/dist/src/abi/interopXGateway.json +11 -11
  4. package/dist/src/api/index.js +3 -3
  5. package/dist/src/config/index.js +10 -1
  6. package/dist/src/constants/addresses.js +1 -1
  7. package/dist/src/constants/itokens.js +1 -1
  8. package/dist/src/index.js +33 -6
  9. package/dist/src/net/peer/index.js +2 -1
  10. package/dist/src/net/pool/index.js +7 -2
  11. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
  12. package/dist/src/net/protocol/index.js +15 -4
  13. package/dist/src/tasks/AutoUpdateTask.js +42 -16
  14. package/dist/src/tasks/BaseTask.js +11 -3
  15. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -1
  16. package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -9
  17. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  18. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +14 -2
  19. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -3
  20. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  21. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
  22. package/dist/src/tasks/index.js +17 -4
  23. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
  24. package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
  25. package/dist/src/utils/index.js +20 -10
  26. package/package.json +4 -3
  27. package/src/abi/interopBridgeToken.json +21 -9
  28. package/src/abi/interopXGateway.json +11 -11
  29. package/src/api/index.ts +2 -2
  30. package/src/config/index.ts +9 -1
  31. package/src/constants/addresses.ts +1 -1
  32. package/src/constants/itokens.ts +1 -1
  33. package/src/index.ts +46 -8
  34. package/src/net/peer/index.ts +2 -1
  35. package/src/net/pool/index.ts +7 -3
  36. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
  37. package/src/net/protocol/index.ts +16 -4
  38. package/src/tasks/AutoUpdateTask.ts +48 -19
  39. package/src/tasks/BaseTask.ts +13 -3
  40. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +0 -2
  41. package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +10 -10
  42. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  43. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +18 -6
  44. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -4
  45. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  46. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
  47. package/src/tasks/index.ts +25 -4
  48. package/src/typechain/InteropBridgeToken.ts +23 -17
  49. package/src/typechain/InteropXGateway.ts +13 -13
  50. package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
  51. package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
  52. package/src/utils/index.ts +21 -9
@@ -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: await (0, utils_1.buildDataForTransaction)(transaction),
86
+ data,
74
87
  gasPrice: "0",
75
88
  gasToken: "0x0000000000000000000000000000000000000000",
76
89
  nonce: '0',
@@ -140,7 +153,6 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
140
153
  net_1.protocol.sendTransaction(transaction);
141
154
  }
142
155
  async start() {
143
- this.logger.info(`Starting execution watcher on interop chain`);
144
156
  this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
145
157
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
146
158
  this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
@@ -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.toNumber(),
35
- targetChainId: targetChainId.toNumber(),
34
+ sourceChainId: sourceChainId,
35
+ targetChainId: targetChainId,
36
36
  };
37
37
  if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
38
38
  continue;
@@ -65,7 +65,6 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
65
65
  this.logger.info(`${processedEvents} events processed`);
66
66
  }
67
67
  async start() {
68
- this.logger.info(`Starting execution watcher on interop chain`);
69
68
  this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
70
69
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
71
70
  this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
@@ -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,53 @@
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.targetStatus = transactionStatus.targetStatus;
46
+ transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
47
+ transaction.targetErrors = transactionStatus.targetErrors;
48
+ transaction.status = transactionStatus.status;
49
+ await transaction.save();
50
+ this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
51
+ }
52
+ }
53
+ exports.default = SyncTransactionStatusTask;
@@ -6,25 +6,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Tasks = void 0;
7
7
  const ProcessDepositEvents_1 = __importDefault(require("./InteropXGateway/ProcessDepositEvents"));
8
8
  const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
9
- const SyncWithdrawEvents_1 = __importDefault(require("./InteropBridge/SyncWithdrawEvents"));
9
+ const SyncWithdrawtEvents_1 = __importDefault(require("./InteropXGateway/SyncWithdrawtEvents"));
10
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"));
11
14
  const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
12
15
  class Tasks {
13
16
  constructor() {
14
17
  this.tasks = [
18
+ new SyncTransactionStatusTask_1.default(),
15
19
  new AutoUpdateTask_1.default(),
20
+ // InteropXGateway
16
21
  new SyncDepositEvents_1.default({
17
22
  chainId: 43114
18
23
  }),
19
24
  new ProcessDepositEvents_1.default({
20
25
  chainId: 43114
21
26
  }),
22
- new SyncWithdrawEvents_1.default({
23
- chainId: 137,
24
- itokenAddress: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
27
+ new SyncWithdrawtEvents_1.default({
28
+ chainId: 43114
25
29
  }),
30
+ // InteropBridge
26
31
  new ProcessWithdrawEvents_1.default({
27
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',
28
41
  })
29
42
  ];
30
43
  }
@@ -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",
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getContract = exports.buildWithdrawDataForTransaction = exports.buildDepositDataForTransaction = exports.buildDataForTransaction = exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.http = void 0;
6
+ exports.getContract = exports.buildWithdrawDataForTransaction = exports.buildDepositDataForTransaction = exports.buildDataForTransaction = exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.shortenHash = exports.http = void 0;
7
7
  /**
8
8
  * @module util
9
9
  */
@@ -16,6 +16,16 @@ const config_1 = __importDefault(require("@/config"));
16
16
  const abi_1 = __importDefault(require("@/abi"));
17
17
  exports.http = axios_1.default.create();
18
18
  (0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
19
+ function shortenHash(hash, length = 4) {
20
+ if (!hash)
21
+ return;
22
+ if (hash.length < 12)
23
+ return hash;
24
+ const beginningChars = hash.startsWith("0x") ? length + 2 : length;
25
+ const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
26
+ return shortened;
27
+ }
28
+ exports.shortenHash = shortenHash;
19
29
  function short(buffer) {
20
30
  return buffer.toString('hex').slice(0, 8) + '...';
21
31
  }
@@ -59,11 +69,11 @@ exports.signGnosisSafeTx = signGnosisSafeTx;
59
69
  const getRpcProviderUrl = (chainId) => {
60
70
  switch (chainId) {
61
71
  case 1:
62
- return 'https://rpc.instadapp.io/mainnet';
72
+ return 'https://rpc.ankr.com/eth';
63
73
  case 137:
64
- return 'https://rpc.instadapp.io/polygon';
74
+ return 'https://rpc.ankr.com/polygon';
65
75
  case 43114:
66
- return 'https://rpc.instadapp.io/avalanche';
76
+ return 'https://rpc.ankr.com/avalanche';
67
77
  default:
68
78
  throw new Error(`Unknown chainId: ${chainId}`);
69
79
  }
@@ -157,20 +167,20 @@ const buildWithdrawDataForTransaction = async (transaction, type) => {
157
167
  if (!transaction.submitEvent) {
158
168
  throw Error('Cannot build data for transaction without submitEvent');
159
169
  }
160
- const { to, amount, chainId, itoken: itokenAddress } = transaction.submitEvent;
161
- const itoken = constants_1.itokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
170
+ const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
171
+ const itoken = constants_1.itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
162
172
  if (!itoken) {
163
173
  throw Error('Cannot build data for transaction without itoken');
164
174
  }
165
- const token = constants_1.tokens[chainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
175
+ const token = constants_1.tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
166
176
  if (!token) {
167
177
  throw Error('Cannot build data for transaction without token');
168
178
  }
169
- const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
179
+ const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(targetChainId));
170
180
  const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
171
- const gatewayAddress = constants_1.addresses[chainId].interopXGateway;
181
+ const gatewayAddress = constants_1.addresses[targetChainId].interopXGateway;
172
182
  const interopBridgeContract = getContract(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
173
- const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(transaction.sourceChainId.toString()), transaction.submitTransactionHash);
183
+ const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(sourceChainId.toString()), transaction.submitTransactionHash);
174
184
  transactions.push({
175
185
  to: gatewayAddress,
176
186
  data: data,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.fd7fd6f",
3
+ "version": "0.0.0-dev.fded533",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -24,9 +24,10 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@achingbrain/libp2p-gossipsub": "^0.12.2",
27
+ "@fastify/cors": "^7.0.0",
28
+ "await-spawn": "^4.0.2",
27
29
  "axios": "^0.27.1",
28
30
  "axios-retry": "^3.2.4",
29
- "bignumber.js": "^9.0.2",
30
31
  "chalk": "4.1.2",
31
32
  "dotenv": "^16.0.0",
32
33
  "ethereumjs-util": "^7.1.4",
@@ -34,7 +35,7 @@
34
35
  "ethers-multisend": "^2.1.1",
35
36
  "expand-home-dir": "^0.0.3",
36
37
  "fastify": "^3.28.0",
37
- "fastify-cors": "^6.0.3",
38
+ "fs-extra": "^10.1.0",
38
39
  "libp2p": "^0.36.2",
39
40
  "libp2p-bootstrap": "^0.14.0",
40
41
  "libp2p-kad-dht": "^0.28.6",
@@ -46,11 +46,17 @@
46
46
  "name": "amount",
47
47
  "type": "uint256"
48
48
  },
49
+ {
50
+ "indexed": false,
51
+ "internalType": "uint32",
52
+ "name": "sourceChainId",
53
+ "type": "uint32"
54
+ },
49
55
  {
50
56
  "indexed": true,
51
- "internalType": "uint256",
52
- "name": "chainId",
53
- "type": "uint256"
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": "uint256",
77
- "name": "chainId",
78
- "type": "uint256"
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": "transactionHash",
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": "uint256", "name": "chainId", "type": "uint256" }
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": "uint256", "name": "chainId", "type": "uint256" },
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": "uint256",
38
+ "internalType": "uint32",
39
39
  "name": "sourceChainId",
40
- "type": "uint256"
40
+ "type": "uint32"
41
41
  },
42
42
  {
43
43
  "indexed": true,
44
- "internalType": "uint256",
44
+ "internalType": "uint32",
45
45
  "name": "targetChainId",
46
- "type": "uint256"
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": "uint256",
75
+ "internalType": "uint32",
76
76
  "name": "sourceChainId",
77
- "type": "uint256"
77
+ "type": "uint32"
78
78
  },
79
79
  {
80
80
  "indexed": false,
81
- "internalType": "uint256",
81
+ "internalType": "uint32",
82
82
  "name": "targetChainId",
83
- "type": "uint256"
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": "uint256", "name": "chainId_", "type": "uint256" }
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": "uint256", "name": "chainId_", "type": "uint256" }
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": "uint256", "name": "chainId_", "type": "uint256" },
163
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" },
164
164
  {
165
165
  "internalType": "bytes32",
166
166
  "name": "transactionHash_",