@instadapp/interop-x 0.0.0-dev.d71f27e → 0.0.0-dev.de59649

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.d71f27e",
3
+ "version": "0.0.0-dev.de59649",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -25,16 +25,17 @@
25
25
  "dependencies": {
26
26
  "@achingbrain/libp2p-gossipsub": "^0.12.2",
27
27
  "@fastify/cors": "^7.0.0",
28
+ "async-retry": "^1.3.3",
28
29
  "await-spawn": "^4.0.2",
29
- "axios": "^0.27.1",
30
- "axios-retry": "^3.2.4",
30
+ "axios": "^0.27.2",
31
+ "axios-retry": "^3.2.5",
31
32
  "chalk": "4.1.2",
32
- "dotenv": "^16.0.0",
33
+ "dotenv": "^16.0.1",
33
34
  "ethereumjs-util": "^7.1.4",
34
- "ethers": "^5.6.4",
35
+ "ethers": "^5.6.5",
35
36
  "ethers-multisend": "^2.1.1",
36
37
  "expand-home-dir": "^0.0.3",
37
- "fastify": "^3.28.0",
38
+ "fastify": "^3.29.0",
38
39
  "fs-extra": "^10.1.0",
39
40
  "libp2p": "^0.36.2",
40
41
  "libp2p-bootstrap": "^0.14.0",
@@ -45,12 +46,12 @@
45
46
  "libp2p-pubsub-peer-discovery": "^4.0.0",
46
47
  "libp2p-tcp": "^0.17.2",
47
48
  "libp2p-websockets": "^0.16.2",
48
- "luxon": "^2.3.2",
49
+ "luxon": "^2.4.0",
49
50
  "module-alias": "^2.2.2",
50
51
  "patch-package": "^6.4.7",
51
52
  "postinstall-postinstall": "^2.1.0",
52
53
  "sequelize": "6.18.0",
53
- "sqlite3": "^5.0.5",
54
+ "sqlite3": "^5.0.8",
54
55
  "waait": "^1.0.5"
55
56
  },
56
57
  "bin": {
@@ -61,13 +62,13 @@
61
62
  "@typechain/ethers-v5": "^10.0.0",
62
63
  "@types/bn.js": "^5.1.0",
63
64
  "@types/fs-extra": "^9.0.13",
64
- "@types/node": "^17.0.17",
65
- "nodemon": "^2.0.15",
65
+ "@types/node": "^17.0.33",
66
+ "nodemon": "^2.0.16",
66
67
  "replace-in-file": "^6.3.2",
67
68
  "rimraf": "^3.0.2",
68
69
  "ts-node": "^10.5.0",
69
70
  "tsconfig-paths": "^3.12.0",
70
71
  "typechain": "^8.0.0",
71
- "typescript": "^4.5.5"
72
+ "typescript": "^4.6.4"
72
73
  }
73
74
  }
@@ -2,6 +2,12 @@
2
2
  {
3
3
  "anonymous": false,
4
4
  "inputs": [
5
+ {
6
+ "indexed": false,
7
+ "internalType": "string",
8
+ "name": "actionId",
9
+ "type": "string"
10
+ },
5
11
  {
6
12
  "indexed": true,
7
13
  "internalType": "address",
@@ -83,6 +89,12 @@
83
89
  {
84
90
  "anonymous": false,
85
91
  "inputs": [
92
+ {
93
+ "indexed": false,
94
+ "internalType": "string",
95
+ "name": "actionId",
96
+ "type": "string"
97
+ },
86
98
  {
87
99
  "indexed": true,
88
100
  "internalType": "address",
@@ -170,6 +182,12 @@
170
182
  {
171
183
  "anonymous": false,
172
184
  "inputs": [
185
+ {
186
+ "indexed": false,
187
+ "internalType": "string",
188
+ "name": "actionId",
189
+ "type": "string"
190
+ },
173
191
  {
174
192
  "indexed": true,
175
193
  "internalType": "address",
@@ -245,6 +263,12 @@
245
263
  {
246
264
  "anonymous": false,
247
265
  "inputs": [
266
+ {
267
+ "indexed": false,
268
+ "internalType": "string",
269
+ "name": "actionId",
270
+ "type": "string"
271
+ },
248
272
  {
249
273
  "indexed": true,
250
274
  "internalType": "address",
@@ -323,20 +347,14 @@
323
347
  "name": "LogBridgeRequestSent",
324
348
  "type": "event"
325
349
  },
326
- {
327
- "inputs": [],
328
- "name": "_vnonce",
329
- "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
330
- "stateMutability": "view",
331
- "type": "function"
332
- },
333
350
  {
334
351
  "inputs": [
352
+ { "internalType": "string", "name": "actionId", "type": "string" },
335
353
  { "internalType": "address", "name": "to_", "type": "address" },
336
354
  { "internalType": "address", "name": "sourceToken_", "type": "address" },
337
355
  { "internalType": "address", "name": "targetToken_", "type": "address" },
338
356
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
339
- { "internalType": "uint32", "name": "targetChainId_", "type": "uint32" },
357
+ { "internalType": "uint32", "name": "sourceChainId_", "type": "uint32" },
340
358
  {
341
359
  "internalType": "bytes32",
342
360
  "name": "transactionHash_",
@@ -351,6 +369,27 @@
351
369
  },
352
370
  {
353
371
  "inputs": [
372
+ { "internalType": "address", "name": "user", "type": "address" },
373
+ { "internalType": "address[]", "name": "tokens", "type": "address[]" }
374
+ ],
375
+ "name": "getBridgeAmounts",
376
+ "outputs": [
377
+ {
378
+ "components": [
379
+ { "internalType": "uint256", "name": "deposit", "type": "uint256" },
380
+ { "internalType": "uint256", "name": "withdraw", "type": "uint256" }
381
+ ],
382
+ "internalType": "struct InteropXContractBeta.UserData[]",
383
+ "name": "userData",
384
+ "type": "tuple[]"
385
+ }
386
+ ],
387
+ "stateMutability": "view",
388
+ "type": "function"
389
+ },
390
+ {
391
+ "inputs": [
392
+ { "internalType": "string", "name": "actionId", "type": "string" },
354
393
  { "internalType": "address", "name": "sourceToken_", "type": "address" },
355
394
  { "internalType": "address", "name": "targetToken_", "type": "address" },
356
395
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
@@ -362,15 +401,39 @@
362
401
  "stateMutability": "nonpayable",
363
402
  "type": "function"
364
403
  },
404
+ {
405
+ "inputs": [
406
+ { "internalType": "address", "name": "token", "type": "address" },
407
+ { "internalType": "bool", "name": "toggle", "type": "bool" }
408
+ ],
409
+ "name": "toggleWhitelist",
410
+ "outputs": [],
411
+ "stateMutability": "nonpayable",
412
+ "type": "function"
413
+ },
414
+ {
415
+ "inputs": [
416
+ { "internalType": "address", "name": "", "type": "address" },
417
+ { "internalType": "address", "name": "", "type": "address" }
418
+ ],
419
+ "name": "userMapping",
420
+ "outputs": [
421
+ { "internalType": "uint256", "name": "deposit", "type": "uint256" },
422
+ { "internalType": "uint256", "name": "withdraw", "type": "uint256" }
423
+ ],
424
+ "stateMutability": "view",
425
+ "type": "function"
426
+ },
365
427
  {
366
428
  "inputs": [{ "internalType": "address", "name": "", "type": "address" }],
367
- "name": "whitelistedMapping",
368
- "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
429
+ "name": "whitelistedTokens",
430
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
369
431
  "stateMutability": "view",
370
432
  "type": "function"
371
433
  },
372
434
  {
373
435
  "inputs": [
436
+ { "internalType": "string", "name": "actionId", "type": "string" },
374
437
  { "internalType": "address", "name": "user_", "type": "address" },
375
438
  { "internalType": "address", "name": "sourceToken_", "type": "address" },
376
439
  { "internalType": "address", "name": "targetToken_", "type": "address" },
@@ -2,19 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addresses = void 0;
4
4
  exports.addresses = {
5
- 1: {
6
- gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
7
- multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
8
- interopXContract: '',
9
- },
5
+ // 1: {
6
+ // gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
7
+ // multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
8
+ // interopXContract: '',
9
+ // },
10
10
  137: {
11
11
  gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
12
12
  multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
13
- interopXContract: '0x2189741c8cAc1cf51570932817A7d6390646C80e',
13
+ interopXContract: '0x28f175FBEAce469c27ed587016aD7Bb72f286759',
14
14
  },
15
15
  43114: {
16
16
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
17
17
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
18
- interopXContract: '0x1867DF97Ec24bb0bbD4AD464F0Be9C6713422EAE',
18
+ interopXContract: '0x54d77C42Dae3Fc0f48b4Fdd5a193E776D07C1EEC',
19
19
  }
20
20
  };
@@ -2,102 +2,125 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tokens = void 0;
4
4
  exports.tokens = {
5
- 1: [
6
- {
7
- symbol: "ETH",
8
- name: "Ethereum",
9
- address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
10
- decimals: 18,
11
- },
12
- {
13
- symbol: "DAI",
14
- name: "DAI Stable",
15
- address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
16
- decimals: 18,
17
- },
18
- {
19
- symbol: "USDC",
20
- name: "USD Coin",
21
- address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
22
- decimals: 6,
23
- },
24
- {
25
- symbol: "USDT",
26
- name: "Tether USD Coin",
27
- address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
28
- decimals: 6,
29
- },
30
- {
31
- symbol: "WBTC",
32
- name: "Wrapped BTC",
33
- address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
34
- decimals: 8,
35
- },
36
- ],
5
+ // 1: [
6
+ // {
7
+ // aliases: ['eth'],
8
+ // symbol: "ETH",
9
+ // name: "Ethereum",
10
+ // address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
11
+ // decimals: 18,
12
+ // },
13
+ // {
14
+ // aliases: ['weth'],
15
+ // symbol: "WETH",
16
+ // name: "Wrapped Ethereum",
17
+ // address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
18
+ // decimals: 18,
19
+ // },
20
+ // {
21
+ // aliases: ['dai'],
22
+ // symbol: "DAI",
23
+ // name: "DAI Stable",
24
+ // address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
25
+ // decimals: 18,
26
+ // },
27
+ // {
28
+ // aliases: ['usdc'],
29
+ // symbol: "USDC",
30
+ // name: "USD Coin",
31
+ // address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
32
+ // decimals: 6,
33
+ // },
34
+ // {
35
+ // aliases: ['usdt'],
36
+ // symbol: "USDT",
37
+ // name: "Tether USD Coin",
38
+ // address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
39
+ // decimals: 6,
40
+ // },
41
+ // {
42
+ // aliases: ['wbtc'],
43
+ // symbol: "WBTC",
44
+ // name: "Wrapped BTC",
45
+ // address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
46
+ // decimals: 8,
47
+ // },
48
+ // ],
37
49
  137: [
38
50
  {
51
+ aliases: ['eth', 'weth'],
39
52
  symbol: "ETH",
40
53
  name: "Ethereum",
41
54
  address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
42
55
  decimals: 18,
43
56
  },
44
57
  {
58
+ aliases: ['dai'],
45
59
  symbol: "DAI",
46
60
  name: "DAI Stable",
47
61
  address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
48
62
  decimals: 18,
49
63
  },
50
64
  {
65
+ aliases: ['usdc'],
51
66
  symbol: "USDC",
52
67
  name: "USD Coin",
53
68
  address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
54
69
  decimals: 6,
55
70
  },
56
71
  {
72
+ aliases: ['usdt'],
57
73
  symbol: "USDT",
58
74
  name: "Tether USD Coin",
59
75
  address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
60
76
  decimals: 6,
61
77
  },
62
78
  {
79
+ aliases: ['wbtc'],
63
80
  symbol: "WBTC",
64
81
  name: "Wrapped BTC",
65
82
  address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
66
83
  decimals: 8,
67
84
  },
68
- {
69
- symbol: "AVAX",
70
- name: "Avalanche Token",
71
- address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
72
- decimals: 18,
73
- },
74
85
  ],
75
86
  43114: [
76
87
  {
88
+ aliases: ['eth', 'weth'],
77
89
  symbol: "ETH",
78
90
  name: "Ethereum",
79
91
  address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
80
92
  decimals: 18,
81
93
  },
82
94
  {
95
+ aliases: ['dai'],
83
96
  symbol: "DAI",
84
97
  name: "DAI Stable",
85
98
  address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
86
99
  decimals: 18,
87
100
  },
88
101
  {
102
+ aliases: ['usdc'],
89
103
  symbol: "USDC",
90
104
  name: "USD Coin",
91
105
  address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
92
106
  decimals: 6,
93
107
  },
94
108
  {
95
- symbol: "USDT",
109
+ aliases: ['usdt'],
110
+ symbol: "USDt",
96
111
  name: "Tether USD Coin",
112
+ address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
113
+ decimals: 6,
114
+ },
115
+ {
116
+ aliases: ['usdt'],
117
+ symbol: "USDT.e",
118
+ name: "Tether USD",
97
119
  address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
98
120
  decimals: 6,
99
121
  },
100
122
  {
123
+ aliases: ["wbtc"],
101
124
  symbol: "WBTC",
102
125
  name: "Wrapped BTC",
103
126
  address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
@@ -15,7 +15,7 @@ Transaction.init({
15
15
  requestTransactionHash: sequelize_2.DataTypes.NUMBER,
16
16
  requestBlockNumber: sequelize_2.DataTypes.NUMBER,
17
17
  transactionHash: sequelize_2.DataTypes.STRING,
18
- action: sequelize_2.DataTypes.STRING,
18
+ actionId: sequelize_2.DataTypes.STRING,
19
19
  bridger: sequelize_2.DataTypes.STRING,
20
20
  sourceChainId: sequelize_2.DataTypes.NUMBER,
21
21
  sourceTransactionHash: sequelize_2.DataTypes.STRING,
@@ -61,8 +61,6 @@ Transaction.init({
61
61
  requestSentEvent: sequelize_2.DataTypes.JSON,
62
62
  committedEvent: sequelize_2.DataTypes.JSON,
63
63
  completedEvent: sequelize_2.DataTypes.JSON,
64
- position: sequelize_2.DataTypes.JSON,
65
- metadata: sequelize_2.DataTypes.JSON,
66
64
  status: {
67
65
  type: sequelize_2.DataTypes.STRING,
68
66
  defaultValue: 'pending'
@@ -9,27 +9,90 @@ const constants_1 = require("@/constants");
9
9
  const utils_1 = require("@/utils");
10
10
  const ethers_1 = require("ethers");
11
11
  const ethers_multisend_1 = require("ethers-multisend");
12
+ const getBridgeAmounts = async (user, tokens, chainId) => {
13
+ const sourceChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(chainId));
14
+ const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
15
+ const contractAddress = constants_1.addresses[chainId].interopXContract;
16
+ const contract = (0, utils_1.getContract)(contractAddress, abi_1.default.interopXContract, sourceWallet);
17
+ const data = await contract.getBridgeAmounts(user, tokens);
18
+ return data.map((item, index) => ({
19
+ token: tokens[index],
20
+ deposit: item.deposit,
21
+ withdraw: item.withdraw,
22
+ }));
23
+ };
12
24
  async function default_1(transaction, type) {
13
25
  const transactions = [];
14
26
  const logs = [];
15
- if (transaction.action !== 'withdraw') {
16
- throw new Error(`Invalid action: ${transaction.action}`);
27
+ if (transaction.actionId !== 'withdraw') {
28
+ throw new Error(`Invalid action: ${transaction.actionId}`);
17
29
  }
18
30
  if (type !== 'source') {
19
- throw new Error(`Type not supported: ${type}`);
31
+ throw new Error(`[WIP] Type not supported: ${type}`);
20
32
  }
21
- if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
22
- throw Error('Cannot build data for pending withdraw transaction');
33
+ if (transaction.sourceStatus === 'pending') {
34
+ throw Error('Source transaction already processesing');
35
+ }
36
+ if (transaction.sourceStatus === 'pending') {
37
+ throw Error('Source transaction already processed');
23
38
  }
24
39
  if (!transaction.requestEvent) {
25
- throw Error('Cannot build data for transaction without requestEvent');
40
+ throw Error('Something went wrong, source transaction has no request event');
26
41
  }
27
- const { bridger, position, sourceChainId, targetChainId, metadata, } = transaction.requestEvent;
28
- const sourceChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
42
+ const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = transaction.requestEvent;
43
+ const sourceChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(sourceChainId));
29
44
  const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
30
45
  const contractAddress = constants_1.addresses[sourceChainId].interopXContract;
31
46
  const contract = (0, utils_1.getContract)(contractAddress, abi_1.default.interopXContract, sourceWallet);
32
- const { data } = await contract.populateTransaction.withdrawRequested(bridger, position.withdraw[0].sourceToken, position.withdraw[0].targetToken, position.withdraw[0].amount, targetChainId, transaction.requestTransactionHash, metadata);
47
+ const sourceToken = constants_1.tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
48
+ if (!sourceToken) {
49
+ throw Error('Source token not found');
50
+ }
51
+ const targetToken = constants_1.tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
52
+ if (!targetToken) {
53
+ throw Error('Target token not found');
54
+ }
55
+ if (!sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
56
+ throw Error('Source and target token must be the same');
57
+ }
58
+ const networks = [137, 43114];
59
+ const networkUserData = {};
60
+ for (const network of networks) {
61
+ networkUserData[network] = await getBridgeAmounts(bridger, constants_1.tokens[network].map(t => t.address), network);
62
+ }
63
+ for (const tokenSymbol of ["dai", "usdc", "usdt", "eth", "wbtc"]) {
64
+ let totalDeposit = ethers_1.BigNumber.from(0);
65
+ let totalWithdraw = ethers_1.BigNumber.from(0);
66
+ for (const network of networks) {
67
+ // on avax might we have 2 usdc/usdt tokens
68
+ const matchedTokens = constants_1.tokens[network].filter(t => t.aliases.includes(tokenSymbol));
69
+ for (const matchedToken of matchedTokens) {
70
+ const data = networkUserData[network].find(t => t.token.toLowerCase() === matchedToken.address.toLowerCase());
71
+ if (data) {
72
+ totalDeposit = totalDeposit.add(data.deposit);
73
+ totalWithdraw = totalWithdraw.add(data.withdraw);
74
+ }
75
+ }
76
+ // on Mainent add weth too
77
+ if (tokenSymbol === "eth" && network === 1) {
78
+ const weth = constants_1.tokens[1].find(t => t.symbol === 'WETH');
79
+ if (weth) {
80
+ const data = networkUserData[1].find(t => t.token.toLowerCase() === weth.address.toLowerCase());
81
+ if (data) {
82
+ totalDeposit = totalDeposit.add(data.deposit);
83
+ totalWithdraw = totalWithdraw.add(data.withdraw);
84
+ }
85
+ }
86
+ }
87
+ if (totalWithdraw.gt(totalDeposit)) {
88
+ throw Error(`if withdraw > deposit, user has debt and we can't process the withdraw and reject it`);
89
+ }
90
+ if (totalWithdraw.lt(totalDeposit)) {
91
+ throw Error('Something went wrong');
92
+ }
93
+ }
94
+ }
95
+ const { data } = await contract.populateTransaction.withdrawRequested(actionId, bridger, position.withdraw[0].sourceToken, position.withdraw[0].targetToken, position.withdraw[0].amount, targetChainId, transaction.requestTransactionHash, metadata);
33
96
  transactions.push({
34
97
  to: contractAddress,
35
98
  data: data,
@@ -8,13 +8,13 @@ const ethers_multisend_1 = require("ethers-multisend");
8
8
  const actions_1 = __importDefault(require("./actions"));
9
9
  const buildGnosisAction = async (transaction, type) => {
10
10
  // type = type || (transaction.sourceStatus === 'success' ? 'target' : 'source')
11
- if (actions_1.default.hasOwnProperty(transaction.action)) {
12
- const { transactions, logs } = await actions_1.default[transaction.action](transaction, type);
11
+ if (actions_1.default.hasOwnProperty(transaction.actionId)) {
12
+ const { transactions, logs } = await actions_1.default[transaction.actionId](transaction, type);
13
13
  return {
14
14
  data: (0, ethers_multisend_1.encodeMulti)(transactions).data,
15
15
  logs
16
16
  };
17
17
  }
18
- throw new Error(`Unknown action: ${transaction.action}`);
18
+ throw new Error(`Unknown action: ${transaction.actionId}`);
19
19
  };
20
20
  exports.buildGnosisAction = buildGnosisAction;
package/dist/src/index.js CHANGED
@@ -13,7 +13,7 @@ const package_json_1 = __importDefault(require("../package.json"));
13
13
  dotenv_1.default.config();
14
14
  const logger_1 = __importDefault(require("@/logger"));
15
15
  const logger = new logger_1.default('Process');
16
- const GIT_SHORT_HASH = 'd71f27e';
16
+ const GIT_SHORT_HASH = 'de59649';
17
17
  const printUsage = () => {
18
18
  console.log();
19
19
  console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
@@ -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;
@@ -27,9 +27,9 @@ class SyncBridgeRequestEvents extends BaseTask_1.BaseTask {
27
27
  if (!event.args) {
28
28
  continue;
29
29
  }
30
- const { bridger, position, sourceChainId, targetChainId, metadata } = event.args;
30
+ const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = event.args;
31
31
  const uniqueIdentifier = {
32
- action: 'withdraw',
32
+ actionId,
33
33
  bridger,
34
34
  requestTransactionHash: event.transactionHash,
35
35
  sourceChainId: sourceChainId.toNumber(),
@@ -40,8 +40,8 @@ class SyncBridgeRequestEvents extends BaseTask_1.BaseTask {
40
40
  if (transaction) {
41
41
  continue;
42
42
  }
43
- await db_1.Transaction.create(Object.assign(Object.assign({ transactionHash }, uniqueIdentifier), { position,
44
- metadata, requestBlockNumber: event.blockNumber, requestEvent: {
43
+ await db_1.Transaction.create(Object.assign(Object.assign({ transactionHash }, uniqueIdentifier), { requestBlockNumber: event.blockNumber, requestEvent: {
44
+ actionId,
45
45
  bridger,
46
46
  position: {
47
47
  withdraw: position.withdraw.map((v) => ({