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

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.e33810b",
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" },
@@ -10,11 +10,11 @@ exports.addresses = {
10
10
  137: {
11
11
  gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
12
12
  multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
13
- interopXContract: '0x2189741c8cAc1cf51570932817A7d6390646C80e',
13
+ interopXContract: '0x41bd77583674B3a5c073FBb4922C0C8dA91C43cF',
14
14
  },
15
15
  43114: {
16
16
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
17
17
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
18
- interopXContract: '0x1867DF97Ec24bb0bbD4AD464F0Be9C6713422EAE',
18
+ interopXContract: '0xCF391A3057eDba541c80307aC5E3Bc1E4a9471b7',
19
19
  }
20
20
  };
@@ -4,30 +4,42 @@ exports.tokens = void 0;
4
4
  exports.tokens = {
5
5
  1: [
6
6
  {
7
+ aliases: ['eth'],
7
8
  symbol: "ETH",
8
9
  name: "Ethereum",
9
10
  address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
10
11
  decimals: 18,
11
12
  },
12
13
  {
14
+ aliases: ['weth'],
15
+ symbol: "WETH",
16
+ name: "Wrapped Ethereum",
17
+ address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
18
+ decimals: 18,
19
+ },
20
+ {
21
+ aliases: ['dai'],
13
22
  symbol: "DAI",
14
23
  name: "DAI Stable",
15
24
  address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
16
25
  decimals: 18,
17
26
  },
18
27
  {
28
+ aliases: ['usdc'],
19
29
  symbol: "USDC",
20
30
  name: "USD Coin",
21
31
  address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
22
32
  decimals: 6,
23
33
  },
24
34
  {
35
+ aliases: ['usdt'],
25
36
  symbol: "USDT",
26
37
  name: "Tether USD Coin",
27
38
  address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
28
39
  decimals: 6,
29
40
  },
30
41
  {
42
+ aliases: ['wbtc'],
31
43
  symbol: "WBTC",
32
44
  name: "Wrapped BTC",
33
45
  address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
@@ -36,36 +48,42 @@ exports.tokens = {
36
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
85
  {
86
+ aliases: ['avax'],
69
87
  symbol: "AVAX",
70
88
  name: "Avalanche Token",
71
89
  address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
@@ -74,30 +92,42 @@ exports.tokens = {
74
92
  ],
75
93
  43114: [
76
94
  {
95
+ aliases: ['eth', 'weth'],
77
96
  symbol: "ETH",
78
97
  name: "Ethereum",
79
98
  address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
80
99
  decimals: 18,
81
100
  },
82
101
  {
102
+ aliases: ['dai'],
83
103
  symbol: "DAI",
84
104
  name: "DAI Stable",
85
105
  address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
86
106
  decimals: 18,
87
107
  },
88
108
  {
109
+ aliases: ['usdc'],
89
110
  symbol: "USDC",
90
111
  name: "USD Coin",
91
112
  address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
92
113
  decimals: 6,
93
114
  },
94
115
  {
95
- symbol: "USDT",
116
+ aliases: ['usdt'],
117
+ symbol: "USDt",
96
118
  name: "Tether USD Coin",
119
+ address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
120
+ decimals: 6,
121
+ },
122
+ {
123
+ aliases: ['usdt'],
124
+ symbol: "USDT.e",
125
+ name: "Tether USD",
97
126
  address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
98
127
  decimals: 6,
99
128
  },
100
129
  {
130
+ aliases: ["wbtc"],
101
131
  symbol: "WBTC",
102
132
  name: "Wrapped BTC",
103
133
  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'
@@ -12,24 +12,38 @@ const ethers_multisend_1 = require("ethers-multisend");
12
12
  async function default_1(transaction, type) {
13
13
  const transactions = [];
14
14
  const logs = [];
15
- if (transaction.action !== 'withdraw') {
16
- throw new Error(`Invalid action: ${transaction.action}`);
15
+ if (transaction.actionId !== 'withdraw') {
16
+ throw new Error(`Invalid action: ${transaction.actionId}`);
17
17
  }
18
18
  if (type !== 'source') {
19
- throw new Error(`Type not supported: ${type}`);
19
+ throw new Error(`[WIP] Type not supported: ${type}`);
20
20
  }
21
- if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
22
- throw Error('Cannot build data for pending withdraw transaction');
21
+ if (transaction.sourceStatus === 'pending') {
22
+ throw Error('Source transaction already processesing');
23
+ }
24
+ if (transaction.sourceStatus === 'pending') {
25
+ throw Error('Source transaction already processed');
23
26
  }
24
27
  if (!transaction.requestEvent) {
25
- throw Error('Cannot build data for transaction without requestEvent');
28
+ throw Error('Something went wrong, source transaction has no request event');
26
29
  }
27
- const { bridger, position, sourceChainId, targetChainId, metadata, } = transaction.requestEvent;
30
+ const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = transaction.requestEvent;
28
31
  const sourceChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
29
32
  const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
30
33
  const contractAddress = constants_1.addresses[sourceChainId].interopXContract;
31
34
  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);
35
+ const sourceToken = constants_1.tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
36
+ if (!sourceToken) {
37
+ throw Error('Source token not found');
38
+ }
39
+ const targetToken = constants_1.tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
40
+ if (!targetToken) {
41
+ throw Error('Target token not found');
42
+ }
43
+ if (!sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
44
+ throw Error('Source and target token must be the same');
45
+ }
46
+ 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
47
  transactions.push({
34
48
  to: contractAddress,
35
49
  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 = 'e33810b';
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})`);
@@ -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) => ({
@@ -28,9 +28,9 @@ class SyncBridgeRequestSentEvents extends BaseTask_1.BaseTask {
28
28
  if (!event.args) {
29
29
  continue;
30
30
  }
31
- const { bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
31
+ const { actionId, bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
32
32
  const uniqueIdentifier = {
33
- action: 'withdraw',
33
+ actionId,
34
34
  bridger,
35
35
  requestTransactionHash,
36
36
  sourceChainId: sourceChainId,
@@ -51,6 +51,7 @@ class SyncBridgeRequestSentEvents extends BaseTask_1.BaseTask {
51
51
  transaction.sourceBlockNumber = event.blockNumber;
52
52
  transaction.sourceTransactionHash = event.transactionHash;
53
53
  transaction.requestSentEvent = {
54
+ actionId,
54
55
  bridger,
55
56
  position: {
56
57
  withdraw: position.withdraw.map((v) => ({