@instadapp/interop-x 0.0.0-dev.67e7c3a → 0.0.0-dev.733ff78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) 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 +6 -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/db/models/transaction.js +8 -0
  9. package/dist/src/gnosis/actions/deposit.js +48 -0
  10. package/dist/src/gnosis/actions/index.js +11 -0
  11. package/dist/src/gnosis/actions/withdraw.js +50 -0
  12. package/dist/src/gnosis/index.js +20 -0
  13. package/dist/src/index.js +36 -6
  14. package/dist/src/net/peer/index.js +2 -1
  15. package/dist/src/net/pool/index.js +7 -2
  16. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
  17. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  18. package/dist/src/net/protocol/index.js +26 -5
  19. package/dist/src/tasks/AutoUpdateTask.js +42 -16
  20. package/dist/src/tasks/BaseTask.js +11 -3
  21. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +17 -2
  22. package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -9
  23. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  24. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +16 -2
  25. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -3
  26. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  27. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  28. package/dist/src/tasks/index.js +17 -4
  29. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
  30. package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
  31. package/dist/src/utils/index.js +14 -85
  32. package/package.json +4 -3
  33. package/src/abi/interopBridgeToken.json +21 -9
  34. package/src/abi/interopXGateway.json +11 -11
  35. package/src/api/index.ts +5 -2
  36. package/src/config/index.ts +9 -1
  37. package/src/constants/addresses.ts +1 -1
  38. package/src/constants/itokens.ts +1 -1
  39. package/src/db/models/transaction.ts +10 -0
  40. package/src/gnosis/actions/deposit.ts +63 -0
  41. package/src/gnosis/actions/index.ts +7 -0
  42. package/src/gnosis/actions/withdraw.ts +67 -0
  43. package/src/gnosis/index.ts +19 -0
  44. package/src/index.ts +49 -8
  45. package/src/net/peer/index.ts +2 -1
  46. package/src/net/pool/index.ts +7 -3
  47. package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
  48. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  49. package/src/net/protocol/index.ts +28 -6
  50. package/src/tasks/AutoUpdateTask.ts +48 -20
  51. package/src/tasks/BaseTask.ts +13 -3
  52. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +24 -8
  53. package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -15
  54. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  55. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +22 -7
  56. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -4
  57. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  58. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  59. package/src/tasks/index.ts +25 -4
  60. package/src/typechain/InteropBridgeToken.ts +23 -17
  61. package/src/typechain/InteropXGateway.ts +13 -13
  62. package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
  63. package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
  64. package/src/utils/index.ts +16 -125
@@ -61,11 +61,17 @@ const _abi = [
61
61
  name: "amount",
62
62
  type: "uint256",
63
63
  },
64
+ {
65
+ indexed: false,
66
+ internalType: "uint32",
67
+ name: "sourceChainId",
68
+ type: "uint32",
69
+ },
64
70
  {
65
71
  indexed: true,
66
- internalType: "uint256",
67
- name: "chainId",
68
- type: "uint256",
72
+ internalType: "uint32",
73
+ name: "targetChainId",
74
+ type: "uint32",
69
75
  },
70
76
  ],
71
77
  name: "Burn",
@@ -88,14 +94,20 @@ const _abi = [
88
94
  },
89
95
  {
90
96
  indexed: true,
91
- internalType: "uint256",
92
- name: "chainId",
93
- type: "uint256",
97
+ internalType: "uint32",
98
+ name: "sourceChainId",
99
+ type: "uint32",
100
+ },
101
+ {
102
+ indexed: false,
103
+ internalType: "uint32",
104
+ name: "targetChainId",
105
+ type: "uint32",
94
106
  },
95
107
  {
96
108
  indexed: true,
97
109
  internalType: "bytes32",
98
- name: "transactionHash",
110
+ name: "submitTransactionHash",
99
111
  type: "bytes32",
100
112
  },
101
113
  ],
@@ -226,9 +238,9 @@ const _abi = [
226
238
  type: "uint256",
227
239
  },
228
240
  {
229
- internalType: "uint256",
241
+ internalType: "uint32",
230
242
  name: "chainId",
231
- type: "uint256",
243
+ type: "uint32",
232
244
  },
233
245
  ],
234
246
  name: "burn",
@@ -310,9 +322,9 @@ const _abi = [
310
322
  type: "uint256",
311
323
  },
312
324
  {
313
- internalType: "uint256",
325
+ internalType: "uint32",
314
326
  name: "chainId",
315
- type: "uint256",
327
+ type: "uint32",
316
328
  },
317
329
  {
318
330
  internalType: "bytes32",
@@ -50,15 +50,15 @@ const _abi = [
50
50
  },
51
51
  {
52
52
  indexed: false,
53
- internalType: "uint256",
53
+ internalType: "uint32",
54
54
  name: "sourceChainId",
55
- type: "uint256",
55
+ type: "uint32",
56
56
  },
57
57
  {
58
58
  indexed: true,
59
- internalType: "uint256",
59
+ internalType: "uint32",
60
60
  name: "targetChainId",
61
- type: "uint256",
61
+ type: "uint32",
62
62
  },
63
63
  ],
64
64
  name: "LogGatewayDeposit",
@@ -87,15 +87,15 @@ const _abi = [
87
87
  },
88
88
  {
89
89
  indexed: true,
90
- internalType: "uint256",
90
+ internalType: "uint32",
91
91
  name: "sourceChainId",
92
- type: "uint256",
92
+ type: "uint32",
93
93
  },
94
94
  {
95
95
  indexed: false,
96
- internalType: "uint256",
96
+ internalType: "uint32",
97
97
  name: "targetChainId",
98
- type: "uint256",
98
+ type: "uint32",
99
99
  },
100
100
  {
101
101
  indexed: true,
@@ -152,9 +152,9 @@ const _abi = [
152
152
  type: "uint256",
153
153
  },
154
154
  {
155
- internalType: "uint256",
155
+ internalType: "uint32",
156
156
  name: "chainId_",
157
- type: "uint256",
157
+ type: "uint32",
158
158
  },
159
159
  ],
160
160
  name: "deposit",
@@ -180,9 +180,9 @@ const _abi = [
180
180
  type: "uint256",
181
181
  },
182
182
  {
183
- internalType: "uint256",
183
+ internalType: "uint32",
184
184
  name: "chainId_",
185
- type: "uint256",
185
+ type: "uint32",
186
186
  },
187
187
  ],
188
188
  name: "depositFor",
@@ -228,9 +228,9 @@ const _abi = [
228
228
  type: "address",
229
229
  },
230
230
  {
231
- internalType: "uint256",
231
+ internalType: "uint32",
232
232
  name: "chainId_",
233
- type: "uint256",
233
+ type: "uint32",
234
234
  },
235
235
  {
236
236
  internalType: "bytes32",
@@ -3,20 +3,26 @@
3
3
  */
4
4
  import axios from 'axios'
5
5
  import axiosRetry from "axios-retry";
6
- import { addresses, itokens, tokens } from '@/constants';
6
+ import { addresses } from '@/constants';
7
7
  import { ChainId } from '@/types'
8
8
  import { ethers } from 'ethers';
9
- import { encodeMulti, MetaTransaction, OperationType } from 'ethers-multisend';
10
- import { Transaction } from '@/db';
11
- import config from '@/config';
12
- import abi from '@/abi';
13
- import { InteropBridgeToken, InteropXGateway } from '@/typechain';
14
-
15
9
  export const http = axios.create();
16
10
 
17
11
  axiosRetry(http, { retries: 3, retryDelay: axiosRetry.exponentialDelay });
18
12
 
19
13
 
14
+ export function shortenHash(hash: string, length: number = 4) {
15
+ if (!hash) return;
16
+
17
+ if (hash.length < 12) return hash;
18
+
19
+ const beginningChars = hash.startsWith("0x") ? length + 2 : length;
20
+
21
+ const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
22
+
23
+ return shortened;
24
+ }
25
+
20
26
  export function short(buffer: Buffer): string {
21
27
  return buffer.toString('hex').slice(0, 8) + '...'
22
28
  }
@@ -76,11 +82,11 @@ export const signGnosisSafeTx = async ({
76
82
  export const getRpcProviderUrl = (chainId: ChainId) => {
77
83
  switch (chainId) {
78
84
  case 1:
79
- return 'https://rpc.instadapp.io/mainnet';
85
+ return 'https://rpc.ankr.com/eth';
80
86
  case 137:
81
- return 'https://rpc.instadapp.io/polygon';
87
+ return 'https://rpc.ankr.com/polygon';
82
88
  case 43114:
83
- return 'https://rpc.instadapp.io/avalanche';
89
+ return 'https://rpc.ankr.com/avalanche';
84
90
  default:
85
91
  throw new Error(`Unknown chainId: ${chainId}`);
86
92
  }
@@ -133,121 +139,6 @@ export const generateInteropTransactionHash = (data: { action: string, submitTra
133
139
  ]);
134
140
  }
135
141
 
136
- export const buildDataForTransaction = async (transaction: Transaction, type?: 'source' | 'target') => {
137
- type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
138
-
139
- switch (transaction.action) {
140
- case "deposit":
141
- return await buildDepositDataForTransaction(transaction, type);
142
- case "withdraw":
143
- return await buildWithdrawDataForTransaction(transaction, type);
144
- default:
145
- throw new Error(`Unknown action: ${transaction.action}`);
146
- }
147
- }
148
-
149
- export const buildDepositDataForTransaction = async (transaction: Transaction, type: 'source' | 'target') => {
150
- const transactions: MetaTransaction[] = [];
151
-
152
- if (transaction.action !== 'deposit') {
153
- throw new Error(`Invalid action: ${transaction.action}`)
154
- }
155
-
156
- if (transaction.action === 'deposit' && transaction.sourceStatus === 'pending') {
157
- throw Error('Cannot build data for pending deposit transaction');
158
- }
159
-
160
- if (!transaction.submitEvent) {
161
- throw Error('Cannot build data for transaction without submitEvent');
162
- }
163
-
164
-
165
- const token = tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
166
-
167
- if (!token) {
168
- throw Error('Cannot build data for transaction without token');
169
- }
170
-
171
- const itoken = itokens[transaction.targetChainId].find(itoken => itoken.symbol.toLowerCase() === token.symbol.toLowerCase());
172
-
173
- if (!itoken) {
174
- throw Error('Cannot build data for transaction without itoken');
175
- }
176
-
177
- const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
178
- const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
179
- const interopBridgeContract = getContract<InteropBridgeToken>(itoken.address, abi.interopBridgeToken, targetWallet);
180
-
181
- const { data } = await interopBridgeContract.populateTransaction.mint(
182
- transaction.submitEvent.user,
183
- ethers.BigNumber.from(transaction.submitEvent.amount.toString()),
184
- ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()),
185
- transaction.submitTransactionHash,
186
- );
187
-
188
- transactions.push({
189
- to: itoken.address,
190
- data: data!,
191
- value: '0',
192
- operation: OperationType.Call,
193
- });
194
-
195
- return encodeMulti(transactions).data
196
- }
197
-
198
- export const buildWithdrawDataForTransaction = async (transaction: Transaction, type: 'source' | 'target') => {
199
- const transactions: MetaTransaction[] = [];
200
-
201
- if (transaction.action !== 'withdraw') {
202
- throw new Error(`Invalid action: ${transaction.action}`)
203
- }
204
-
205
- if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
206
- throw Error('Cannot build data for pending withdraw transaction');
207
- }
208
-
209
- if (!transaction.submitEvent) {
210
- throw Error('Cannot build data for transaction without submitEvent');
211
- }
212
-
213
- const { to, amount, chainId, itoken: itokenAddress } = transaction.submitEvent;
214
-
215
- const itoken = itokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
216
-
217
- if (!itoken) {
218
- throw Error('Cannot build data for transaction without itoken');
219
- }
220
-
221
- const token = tokens[chainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
222
-
223
- if (!token) {
224
- throw Error('Cannot build data for transaction without token');
225
- }
226
-
227
- const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
228
- const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
229
- const gatewayAddress = addresses[chainId].interopXGateway;
230
- const interopBridgeContract = getContract<InteropXGateway>(gatewayAddress, abi.interopXGateway, targetWallet);
231
-
232
- const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(
233
- ethers.BigNumber.from(amount.toString()),
234
- to,
235
- token.address,
236
- ethers.BigNumber.from(transaction.sourceChainId.toString()),
237
- transaction.submitTransactionHash,
238
- );
239
-
240
- transactions.push({
241
- to: gatewayAddress,
242
- data: data!,
243
- value: '0',
244
- operation: OperationType.Call,
245
- });
246
-
247
- return encodeMulti(transactions).data
248
- }
249
-
250
-
251
142
  export function getContract<TContract extends ethers.Contract>(address: string, contractInterface: ethers.ContractInterface | any, signerOrProvider?: ethers.Signer | ethers.providers.Provider) {
252
143
  if (!ethers.utils.getAddress(address) || address === ethers.constants.AddressZero) {
253
144
  throw Error(`Invalid 'address' parameter '${address}'.`)