@instadapp/interop-x 0.0.0-dev.9b1fcb8 → 0.0.0-dev.9e91661

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 (62) hide show
  1. package/dist/package.json +6 -5
  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 +6 -3
  5. package/dist/src/config/index.js +11 -1
  6. package/dist/src/constants/addresses.js +1 -1
  7. package/dist/src/constants/itokens.js +1 -1
  8. package/dist/src/gnosis/actions/deposit.js +40 -0
  9. package/dist/src/gnosis/actions/index.js +11 -0
  10. package/dist/src/gnosis/actions/withdraw.js +45 -0
  11. package/dist/src/gnosis/index.js +16 -0
  12. package/dist/src/index.js +69 -7
  13. package/dist/src/net/peer/index.js +2 -1
  14. package/dist/src/net/pool/index.js +18 -2
  15. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +2 -8
  16. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
  17. package/dist/src/net/protocol/index.js +41 -1
  18. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  19. package/dist/src/tasks/BaseTask.js +11 -3
  20. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +147 -0
  21. package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +12 -9
  22. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  23. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +18 -2
  24. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -3
  25. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  26. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
  27. package/dist/src/tasks/index.js +22 -3
  28. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
  29. package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
  30. package/dist/src/utils/index.js +19 -40
  31. package/package.json +6 -5
  32. package/src/abi/interopBridgeToken.json +21 -9
  33. package/src/abi/interopXGateway.json +11 -11
  34. package/src/api/index.ts +5 -2
  35. package/src/config/index.ts +11 -1
  36. package/src/constants/addresses.ts +1 -1
  37. package/src/constants/itokens.ts +1 -1
  38. package/src/gnosis/actions/deposit.ts +54 -0
  39. package/src/gnosis/actions/index.ts +7 -0
  40. package/src/gnosis/actions/withdraw.ts +61 -0
  41. package/src/gnosis/index.ts +13 -0
  42. package/src/index.ts +90 -9
  43. package/src/net/peer/index.ts +2 -1
  44. package/src/net/pool/index.ts +25 -5
  45. package/src/net/protocol/dial/SignatureDialProtocol.ts +3 -10
  46. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
  47. package/src/net/protocol/index.ts +57 -1
  48. package/src/tasks/AutoUpdateTask.ts +82 -0
  49. package/src/tasks/BaseTask.ts +13 -3
  50. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +232 -0
  51. package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -11
  52. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  53. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +24 -7
  54. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -4
  55. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  56. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
  57. package/src/tasks/index.ts +33 -3
  58. package/src/typechain/InteropBridgeToken.ts +23 -17
  59. package/src/typechain/InteropXGateway.ts +13 -13
  60. package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
  61. package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
  62. package/src/utils/index.ts +22 -62
@@ -6,19 +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
+ 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"));
10
15
  class Tasks {
11
16
  constructor() {
12
17
  this.tasks = [
18
+ new SyncTransactionStatusTask_1.default(),
19
+ new AutoUpdateTask_1.default(),
20
+ // InteropXGateway
13
21
  new SyncDepositEvents_1.default({
14
22
  chainId: 43114
15
23
  }),
16
24
  new ProcessDepositEvents_1.default({
17
25
  chainId: 43114
18
26
  }),
19
- new SyncWithdrawEvents_1.default({
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({
20
39
  chainId: 137,
21
- itokenAddress: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
40
+ itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
22
41
  })
23
42
  ];
24
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.buildDataForTransaction = exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.http = void 0;
6
+ exports.getContract = 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
  */
@@ -11,11 +11,18 @@ const axios_1 = __importDefault(require("axios"));
11
11
  const axios_retry_1 = __importDefault(require("axios-retry"));
12
12
  const constants_1 = require("@/constants");
13
13
  const ethers_1 = require("ethers");
14
- const ethers_multisend_1 = require("ethers-multisend");
15
- const config_1 = __importDefault(require("@/config"));
16
- const abi_1 = __importDefault(require("@/abi"));
17
14
  exports.http = axios_1.default.create();
18
15
  (0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
16
+ function shortenHash(hash, length = 4) {
17
+ if (!hash)
18
+ return;
19
+ if (hash.length < 12)
20
+ return hash;
21
+ const beginningChars = hash.startsWith("0x") ? length + 2 : length;
22
+ const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
23
+ return shortened;
24
+ }
25
+ exports.shortenHash = shortenHash;
19
26
  function short(buffer) {
20
27
  return buffer.toString('hex').slice(0, 8) + '...';
21
28
  }
@@ -59,11 +66,11 @@ exports.signGnosisSafeTx = signGnosisSafeTx;
59
66
  const getRpcProviderUrl = (chainId) => {
60
67
  switch (chainId) {
61
68
  case 1:
62
- return 'https://rpc.instadapp.io/mainnet';
69
+ return 'https://rpc.ankr.com/eth';
63
70
  case 137:
64
- return 'https://rpc.instadapp.io/polygon';
71
+ return 'https://rpc.ankr.com/polygon';
65
72
  case 43114:
66
- return 'https://rpc.instadapp.io/avalanche';
73
+ return 'https://rpc.ankr.com/avalanche';
67
74
  default:
68
75
  throw new Error(`Unknown chainId: ${chainId}`);
69
76
  }
@@ -102,44 +109,16 @@ const generateInteropTransactionHash = (data) => {
102
109
  ]);
103
110
  };
104
111
  exports.generateInteropTransactionHash = generateInteropTransactionHash;
105
- const buildDataForTransaction = async (transaction, type) => {
106
- type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
107
- const transactions = [];
108
- if (transaction.action != 'deposit') {
109
- throw new Error('Invalid action');
110
- }
111
- if (transaction.action === 'deposit' && transaction.sourceStatus === 'pending') {
112
- throw Error('Cannot build data for pending deposit transaction');
113
- }
114
- if (!transaction.submitEvent) {
115
- throw Error('Cannot build data for transaction without submitEvent');
116
- }
117
- const token = constants_1.tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
118
- if (!token) {
119
- throw Error('Cannot build data for transaction without token');
120
- }
121
- const itoken = constants_1.itokens[transaction.targetChainId].find(itoken => itoken.symbol.toLowerCase() === token.symbol.toLowerCase());
122
- if (!itoken) {
123
- throw Error('Cannot build data for transaction without itoken');
124
- }
125
- const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
126
- const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
127
- const interopBridgeContract = getContract(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
128
- const { data } = await interopBridgeContract.populateTransaction.mint(transaction.submitEvent.user, ethers_1.ethers.BigNumber.from(transaction.submitEvent.amount.toString()), ethers_1.ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()), transaction.sourceTransactionHash);
129
- transactions.push({
130
- to: itoken.address,
131
- data: data,
132
- value: '0',
133
- operation: ethers_multisend_1.OperationType.Call,
134
- });
135
- return (0, ethers_multisend_1.encodeMulti)(transactions).data;
136
- };
137
- exports.buildDataForTransaction = buildDataForTransaction;
138
112
  function getContract(address, contractInterface, signerOrProvider) {
139
113
  if (!ethers_1.ethers.utils.getAddress(address) || address === ethers_1.ethers.constants.AddressZero) {
140
114
  throw Error(`Invalid 'address' parameter '${address}'.`);
141
115
  }
142
116
  const contract = new ethers_1.ethers.Contract(address, contractInterface, signerOrProvider);
117
+ // Make sure the contract properties is writable
118
+ const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
119
+ if (!desc || desc.writable !== true) {
120
+ return contract;
121
+ }
143
122
  return new Proxy(contract, {
144
123
  get(target, prop, receiver) {
145
124
  const value = Reflect.get(target, prop, receiver);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.9b1fcb8",
3
+ "version": "0.0.0-dev.9e91661",
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,6 +47,8 @@
46
47
  "libp2p-websockets": "^0.16.2",
47
48
  "luxon": "^2.3.2",
48
49
  "module-alias": "^2.2.2",
50
+ "patch-package": "^6.4.7",
51
+ "postinstall-postinstall": "^2.1.0",
49
52
  "sequelize": "6.18.0",
50
53
  "sqlite3": "^5.0.5",
51
54
  "waait": "^1.0.5"
@@ -60,8 +63,6 @@
60
63
  "@types/fs-extra": "^9.0.13",
61
64
  "@types/node": "^17.0.17",
62
65
  "nodemon": "^2.0.15",
63
- "patch-package": "^6.4.7",
64
- "postinstall-postinstall": "^2.1.0",
65
66
  "replace-in-file": "^6.3.2",
66
67
  "rimraf": "^3.0.2",
67
68
  "ts-node": "^10.5.0",
@@ -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_",
package/src/api/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import fastify from "fastify"
2
- import cors from 'fastify-cors'
2
+ import cors from '@fastify/cors'
3
3
  import Logger from "@/logger"
4
4
  import { Transaction } from "@/db";
5
5
 
@@ -20,6 +20,9 @@ export const startApiServer = async () => {
20
20
  return await Transaction.findAndCountAll({
21
21
  limit: 20,
22
22
  offset: 0,
23
+ order: [
24
+ ['createdAt', 'DESC']
25
+ ]
23
26
  })
24
27
  })
25
28
 
@@ -27,7 +30,7 @@ export const startApiServer = async () => {
27
30
 
28
31
  logger.log(`RPC Server listening at http://${HOST}:${PORT}`)
29
32
  } catch (err) {
30
- logger.error(err)
33
+ logger.error(err.message)
31
34
  process.exit(1)
32
35
  }
33
36
  }
@@ -1,5 +1,7 @@
1
1
  import { ethers, Wallet } from "ethers"
2
2
  import { EventBus, EventBusType } from "@/types"
3
+ import fs from 'fs-extra'
4
+ import expandHomeDir from "expand-home-dir";
3
5
 
4
6
  class Config {
5
7
  public readonly events: EventBusType
@@ -8,14 +10,18 @@ class Config {
8
10
  public readonly privateKey: string
9
11
  public readonly wallet: Wallet
10
12
  public readonly staging: boolean
13
+ public readonly autoUpdate: boolean
14
+ public readonly baseConfigPath: string
11
15
 
12
16
  constructor() {
13
17
  this.events = new EventBus() as EventBusType
14
- this.maxPeers = 10
18
+ this.maxPeers = 20
15
19
  this.privateKey = process.env.PRIVATE_KEY as string;
16
20
  this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
21
+ this.autoUpdate = !! process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
17
22
  this.wallet = new Wallet(this.privateKey);
18
23
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
24
+ this.baseConfigPath = expandHomeDir(`~/.interop-x`);
19
25
  }
20
26
 
21
27
  get publicAddress(){
@@ -25,6 +31,10 @@ class Config {
25
31
  isLeadNode() {
26
32
  return ethers.utils.getAddress(this.leadNodeAddress) === ethers.utils.getAddress(this.wallet.address)
27
33
  }
34
+
35
+ isMaintenanceMode(){
36
+ return fs.existsSync(this.baseConfigPath + '/maintenance')
37
+ }
28
38
  }
29
39
 
30
40
  export default new Config()
@@ -12,6 +12,6 @@ export const addresses = {
12
12
  43114: {
13
13
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
14
14
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
15
- interopXGateway: '0x8D27758751BA488690974B6Ccfcda771D462945f',
15
+ interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
16
16
  }
17
17
  }
@@ -2,7 +2,7 @@ export const itokens = {
2
2
  1: [],
3
3
  137: [
4
4
  {
5
- address: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
5
+ address: '0x62C0045f3277E7067cAcad3c8038eEaBB1Bd92D1',
6
6
  symbol: 'USDC',
7
7
  }
8
8
  ],
@@ -0,0 +1,54 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { itokens, tokens } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { InteropBridgeToken } from "@/typechain";
6
+ import { ChainId } from "@/types";
7
+ import { getContract, getRpcProviderUrl } from "@/utils";
8
+ import { ethers } from "ethers";
9
+ import { MetaTransaction, OperationType } from "ethers-multisend";
10
+
11
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
12
+ const transactions: MetaTransaction[] = [];
13
+
14
+ if (transaction.sourceStatus === 'pending') {
15
+ throw Error('Cannot build data for pending deposit transaction');
16
+ }
17
+
18
+ if (!transaction.submitEvent) {
19
+ throw Error('Cannot build data for transaction without submitEvent');
20
+ }
21
+
22
+
23
+ const token = tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
24
+
25
+ if (!token) {
26
+ throw Error(`Unsupported token ${transaction.submitEvent.token}`);
27
+ }
28
+
29
+ const itoken = itokens[transaction.targetChainId].find(t => t.symbol.toLowerCase() === token.symbol.toLowerCase());
30
+
31
+ if (!itoken) {
32
+ throw Error(`Unsupported itoken ${token.symbol}`);
33
+ }
34
+
35
+ const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
36
+ const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
37
+ const interopBridgeContract = getContract<InteropBridgeToken>(itoken.address, abi.interopBridgeToken, targetWallet);
38
+
39
+ const { data } = await interopBridgeContract.populateTransaction.mint(
40
+ transaction.submitEvent.user,
41
+ ethers.BigNumber.from(transaction.submitEvent.amount.toString()),
42
+ ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()),
43
+ transaction.submitTransactionHash,
44
+ );
45
+
46
+ transactions.push({
47
+ to: itoken.address,
48
+ data: data!,
49
+ value: '0',
50
+ operation: OperationType.Call,
51
+ });
52
+
53
+ return transactions
54
+ }
@@ -0,0 +1,7 @@
1
+ import deposit from "./deposit"
2
+ import withdraw from "./withdraw"
3
+
4
+ export default {
5
+ deposit,
6
+ withdraw,
7
+ }
@@ -0,0 +1,61 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { addresses, itokens, tokens } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { InteropXGateway } from "@/typechain";
6
+ import { ChainId } from "@/types";
7
+ import { getContract, getRpcProviderUrl } from "@/utils";
8
+ import { ethers } from "ethers";
9
+ import { MetaTransaction, OperationType } from "ethers-multisend";
10
+
11
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
12
+ const transactions: MetaTransaction[] = [];
13
+
14
+ if (transaction.action !== 'withdraw') {
15
+ throw new Error(`Invalid action: ${transaction.action}`)
16
+ }
17
+
18
+ if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
19
+ throw Error('Cannot build data for pending withdraw transaction');
20
+ }
21
+
22
+ if (!transaction.submitEvent) {
23
+ throw Error('Cannot build data for transaction without submitEvent');
24
+ }
25
+
26
+ const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
27
+
28
+ const itoken = itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
29
+
30
+ if (!itoken) {
31
+ throw Error(`Unsupported itoken ${itokenAddress}`);
32
+ }
33
+
34
+ const token = tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
35
+
36
+ if (!token) {
37
+ throw Error(`Unsupported token ${itoken.symbol}`);
38
+ }
39
+
40
+ const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
41
+ const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
42
+ const gatewayAddress = addresses[targetChainId].interopXGateway;
43
+ const interopBridgeContract = getContract<InteropXGateway>(gatewayAddress, abi.interopXGateway, targetWallet);
44
+
45
+ const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(
46
+ ethers.BigNumber.from(amount.toString()),
47
+ to,
48
+ token.address,
49
+ ethers.BigNumber.from(sourceChainId.toString()),
50
+ transaction.submitTransactionHash,
51
+ );
52
+
53
+ transactions.push({
54
+ to: gatewayAddress,
55
+ data: data!,
56
+ value: '0',
57
+ operation: OperationType.Call,
58
+ });
59
+
60
+ return transactions
61
+ }