@instadapp/interop-x 0.0.0-dev.d2e8d37 → 0.0.0-dev.de23e71

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 (63) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/abi/interopBridgeToken.json +21 -9
  3. package/dist/src/abi/interopXGateway.json +11 -11
  4. package/dist/src/alias.js +10 -0
  5. package/dist/src/api/index.js +3 -0
  6. package/dist/src/config/index.js +10 -1
  7. package/dist/src/constants/addresses.js +1 -1
  8. package/dist/src/constants/itokens.js +1 -1
  9. package/dist/src/db/models/transaction.js +8 -0
  10. package/dist/src/gnosis/actions/deposit.js +48 -0
  11. package/dist/src/gnosis/actions/index.js +11 -0
  12. package/dist/src/gnosis/actions/withdraw.js +50 -0
  13. package/dist/src/gnosis/index.js +20 -0
  14. package/dist/src/index.js +31 -21
  15. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
  16. package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +2 -0
  17. package/dist/src/net/protocol/index.js +17 -7
  18. package/dist/src/tasks/AutoUpdateTask.js +11 -8
  19. package/dist/src/tasks/BaseTask.js +4 -0
  20. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +17 -1
  21. package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -8
  22. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  23. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +16 -1
  24. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -2
  25. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  26. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
  27. package/dist/src/tasks/index.js +16 -5
  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 +1 -82
  31. package/package.json +2 -2
  32. package/src/abi/interopBridgeToken.json +21 -9
  33. package/src/abi/interopXGateway.json +11 -11
  34. package/src/alias.ts +6 -0
  35. package/src/api/index.ts +3 -0
  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 +44 -25
  45. package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
  46. package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +3 -1
  47. package/src/net/protocol/index.ts +17 -7
  48. package/src/tasks/AutoUpdateTask.ts +15 -14
  49. package/src/tasks/BaseTask.ts +5 -0
  50. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +24 -6
  51. package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -13
  52. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  53. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +22 -5
  54. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -2
  55. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  56. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
  57. package/src/tasks/index.ts +24 -5
  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 +1 -122
  63. package/tsconfig.json +7 -2
@@ -31,11 +31,11 @@ export interface InteropBridgeTokenInterface extends utils.Interface {
31
31
  "allowance(address,address)": FunctionFragment;
32
32
  "approve(address,uint256)": FunctionFragment;
33
33
  "balanceOf(address)": FunctionFragment;
34
- "burn(address,uint256,uint256)": FunctionFragment;
34
+ "burn(address,uint256,uint32)": FunctionFragment;
35
35
  "decimals()": FunctionFragment;
36
36
  "decreaseAllowance(address,uint256)": FunctionFragment;
37
37
  "increaseAllowance(address,uint256)": FunctionFragment;
38
- "mint(address,uint256,uint256,bytes32)": FunctionFragment;
38
+ "mint(address,uint256,uint32,bytes32)": FunctionFragment;
39
39
  "name()": FunctionFragment;
40
40
  "owner()": FunctionFragment;
41
41
  "renounceOwnership()": FunctionFragment;
@@ -153,8 +153,8 @@ export interface InteropBridgeTokenInterface extends utils.Interface {
153
153
 
154
154
  events: {
155
155
  "Approval(address,address,uint256)": EventFragment;
156
- "Burn(address,uint256,uint256)": EventFragment;
157
- "Mint(address,uint256,uint256,bytes32)": EventFragment;
156
+ "Burn(address,uint256,uint32,uint32)": EventFragment;
157
+ "Mint(address,uint256,uint32,uint32,bytes32)": EventFragment;
158
158
  "OwnershipTransferred(address,address)": EventFragment;
159
159
  "Transfer(address,address,uint256)": EventFragment;
160
160
  };
@@ -181,10 +181,11 @@ export type ApprovalEventFilter = TypedEventFilter<ApprovalEvent>;
181
181
  export interface BurnEventObject {
182
182
  to: string;
183
183
  amount: BigNumber;
184
- chainId: BigNumber;
184
+ sourceChainId: number;
185
+ targetChainId: number;
185
186
  }
186
187
  export type BurnEvent = TypedEvent<
187
- [string, BigNumber, BigNumber],
188
+ [string, BigNumber, number, number],
188
189
  BurnEventObject
189
190
  >;
190
191
 
@@ -193,11 +194,12 @@ export type BurnEventFilter = TypedEventFilter<BurnEvent>;
193
194
  export interface MintEventObject {
194
195
  to: string;
195
196
  amount: BigNumber;
196
- chainId: BigNumber;
197
- transactionHash: string;
197
+ sourceChainId: number;
198
+ targetChainId: number;
199
+ submitTransactionHash: string;
198
200
  }
199
201
  export type MintEvent = TypedEvent<
200
- [string, BigNumber, BigNumber, string],
202
+ [string, BigNumber, number, number, string],
201
203
  MintEventObject
202
204
  >;
203
205
 
@@ -486,28 +488,32 @@ export interface InteropBridgeToken extends BaseContract {
486
488
  value?: null
487
489
  ): ApprovalEventFilter;
488
490
 
489
- "Burn(address,uint256,uint256)"(
491
+ "Burn(address,uint256,uint32,uint32)"(
490
492
  to?: string | null,
491
493
  amount?: null,
492
- chainId?: BigNumberish | null
494
+ sourceChainId?: null,
495
+ targetChainId?: BigNumberish | null
493
496
  ): BurnEventFilter;
494
497
  Burn(
495
498
  to?: string | null,
496
499
  amount?: null,
497
- chainId?: BigNumberish | null
500
+ sourceChainId?: null,
501
+ targetChainId?: BigNumberish | null
498
502
  ): BurnEventFilter;
499
503
 
500
- "Mint(address,uint256,uint256,bytes32)"(
504
+ "Mint(address,uint256,uint32,uint32,bytes32)"(
501
505
  to?: string | null,
502
506
  amount?: null,
503
- chainId?: BigNumberish | null,
504
- transactionHash?: BytesLike | null
507
+ sourceChainId?: BigNumberish | null,
508
+ targetChainId?: null,
509
+ submitTransactionHash?: BytesLike | null
505
510
  ): MintEventFilter;
506
511
  Mint(
507
512
  to?: string | null,
508
513
  amount?: null,
509
- chainId?: BigNumberish | null,
510
- transactionHash?: BytesLike | null
514
+ sourceChainId?: BigNumberish | null,
515
+ targetChainId?: null,
516
+ submitTransactionHash?: BytesLike | null
511
517
  ): MintEventFilter;
512
518
 
513
519
  "OwnershipTransferred(address,address)"(
@@ -29,11 +29,11 @@ import type {
29
29
  export interface InteropXGatewayInterface extends utils.Interface {
30
30
  functions: {
31
31
  "_vnonce()": FunctionFragment;
32
- "deposit(address,uint256,uint256)": FunctionFragment;
33
- "depositFor(address,address,uint256,uint256)": FunctionFragment;
32
+ "deposit(address,uint256,uint32)": FunctionFragment;
33
+ "depositFor(address,address,uint256,uint32)": FunctionFragment;
34
34
  "owner()": FunctionFragment;
35
35
  "renounceOwnership()": FunctionFragment;
36
- "systemWithdraw(uint256,address,address,uint256,bytes32)": FunctionFragment;
36
+ "systemWithdraw(uint256,address,address,uint32,bytes32)": FunctionFragment;
37
37
  "transferOwnership(address)": FunctionFragment;
38
38
  };
39
39
 
@@ -89,8 +89,8 @@ export interface InteropXGatewayInterface extends utils.Interface {
89
89
  ): Result;
90
90
 
91
91
  events: {
92
- "LogGatewayDeposit(address,address,uint256,uint256,uint256,uint256)": EventFragment;
93
- "LogGatewayWithdraw(address,address,uint256,uint256,uint256,bytes32)": EventFragment;
92
+ "LogGatewayDeposit(address,address,uint256,uint256,uint32,uint32)": EventFragment;
93
+ "LogGatewayWithdraw(address,address,uint256,uint32,uint32,bytes32)": EventFragment;
94
94
  "OwnershipTransferred(address,address)": EventFragment;
95
95
  };
96
96
 
@@ -104,11 +104,11 @@ export interface LogGatewayDepositEventObject {
104
104
  token: string;
105
105
  amount: BigNumber;
106
106
  vnonce: BigNumber;
107
- sourceChainId: BigNumber;
108
- targetChainId: BigNumber;
107
+ sourceChainId: number;
108
+ targetChainId: number;
109
109
  }
110
110
  export type LogGatewayDepositEvent = TypedEvent<
111
- [string, string, BigNumber, BigNumber, BigNumber, BigNumber],
111
+ [string, string, BigNumber, BigNumber, number, number],
112
112
  LogGatewayDepositEventObject
113
113
  >;
114
114
 
@@ -119,12 +119,12 @@ export interface LogGatewayWithdrawEventObject {
119
119
  user: string;
120
120
  token: string;
121
121
  amount: BigNumber;
122
- sourceChainId: BigNumber;
123
- targetChainId: BigNumber;
122
+ sourceChainId: number;
123
+ targetChainId: number;
124
124
  transactionHash: string;
125
125
  }
126
126
  export type LogGatewayWithdrawEvent = TypedEvent<
127
- [string, string, BigNumber, BigNumber, BigNumber, string],
127
+ [string, string, BigNumber, number, number, string],
128
128
  LogGatewayWithdrawEventObject
129
129
  >;
130
130
 
@@ -283,7 +283,7 @@ export interface InteropXGateway extends BaseContract {
283
283
  };
284
284
 
285
285
  filters: {
286
- "LogGatewayDeposit(address,address,uint256,uint256,uint256,uint256)"(
286
+ "LogGatewayDeposit(address,address,uint256,uint256,uint32,uint32)"(
287
287
  user?: null,
288
288
  token?: string | null,
289
289
  amount?: null,
@@ -300,7 +300,7 @@ export interface InteropXGateway extends BaseContract {
300
300
  targetChainId?: BigNumberish | null
301
301
  ): LogGatewayDepositEventFilter;
302
302
 
303
- "LogGatewayWithdraw(address,address,uint256,uint256,uint256,bytes32)"(
303
+ "LogGatewayWithdraw(address,address,uint256,uint32,uint32,bytes32)"(
304
304
  user?: null,
305
305
  token?: string | null,
306
306
  amount?: null,
@@ -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,15 +3,9 @@
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 });
@@ -145,121 +139,6 @@ export const generateInteropTransactionHash = (data: { action: string, submitTra
145
139
  ]);
146
140
  }
147
141
 
148
- export const buildDataForTransaction = async (transaction: Transaction, type?: 'source' | 'target') => {
149
- type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
150
-
151
- switch (transaction.action) {
152
- case "deposit":
153
- return await buildDepositDataForTransaction(transaction, type);
154
- case "withdraw":
155
- return await buildWithdrawDataForTransaction(transaction, type);
156
- default:
157
- throw new Error(`Unknown action: ${transaction.action}`);
158
- }
159
- }
160
-
161
- export const buildDepositDataForTransaction = async (transaction: Transaction, type: 'source' | 'target') => {
162
- const transactions: MetaTransaction[] = [];
163
-
164
- if (transaction.action !== 'deposit') {
165
- throw new Error(`Invalid action: ${transaction.action}`)
166
- }
167
-
168
- if (transaction.action === 'deposit' && transaction.sourceStatus === 'pending') {
169
- throw Error('Cannot build data for pending deposit transaction');
170
- }
171
-
172
- if (!transaction.submitEvent) {
173
- throw Error('Cannot build data for transaction without submitEvent');
174
- }
175
-
176
-
177
- const token = tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
178
-
179
- if (!token) {
180
- throw Error('Cannot build data for transaction without token');
181
- }
182
-
183
- const itoken = itokens[transaction.targetChainId].find(itoken => itoken.symbol.toLowerCase() === token.symbol.toLowerCase());
184
-
185
- if (!itoken) {
186
- throw Error('Cannot build data for transaction without itoken');
187
- }
188
-
189
- const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
190
- const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
191
- const interopBridgeContract = getContract<InteropBridgeToken>(itoken.address, abi.interopBridgeToken, targetWallet);
192
-
193
- const { data } = await interopBridgeContract.populateTransaction.mint(
194
- transaction.submitEvent.user,
195
- ethers.BigNumber.from(transaction.submitEvent.amount.toString()),
196
- ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()),
197
- transaction.submitTransactionHash,
198
- );
199
-
200
- transactions.push({
201
- to: itoken.address,
202
- data: data!,
203
- value: '0',
204
- operation: OperationType.Call,
205
- });
206
-
207
- return encodeMulti(transactions).data
208
- }
209
-
210
- export const buildWithdrawDataForTransaction = async (transaction: Transaction, type: 'source' | 'target') => {
211
- const transactions: MetaTransaction[] = [];
212
-
213
- if (transaction.action !== 'withdraw') {
214
- throw new Error(`Invalid action: ${transaction.action}`)
215
- }
216
-
217
- if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
218
- throw Error('Cannot build data for pending withdraw transaction');
219
- }
220
-
221
- if (!transaction.submitEvent) {
222
- throw Error('Cannot build data for transaction without submitEvent');
223
- }
224
-
225
- const { to, amount, chainId, itoken: itokenAddress } = transaction.submitEvent;
226
-
227
- const itoken = itokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
228
-
229
- if (!itoken) {
230
- throw Error('Cannot build data for transaction without itoken');
231
- }
232
-
233
- const token = tokens[chainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
234
-
235
- if (!token) {
236
- throw Error('Cannot build data for transaction without token');
237
- }
238
-
239
- const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
240
- const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
241
- const gatewayAddress = addresses[chainId].interopXGateway;
242
- const interopBridgeContract = getContract<InteropXGateway>(gatewayAddress, abi.interopXGateway, targetWallet);
243
-
244
- const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(
245
- ethers.BigNumber.from(amount.toString()),
246
- to,
247
- token.address,
248
- ethers.BigNumber.from(transaction.sourceChainId.toString()),
249
- transaction.submitTransactionHash,
250
- );
251
-
252
- transactions.push({
253
- to: gatewayAddress,
254
- data: data!,
255
- value: '0',
256
- operation: OperationType.Call,
257
- });
258
-
259
- return encodeMulti(transactions).data
260
- }
261
-
262
-
263
142
  export function getContract<TContract extends ethers.Contract>(address: string, contractInterface: ethers.ContractInterface | any, signerOrProvider?: ethers.Signer | ethers.providers.Provider) {
264
143
  if (!ethers.utils.getAddress(address) || address === ethers.constants.AddressZero) {
265
144
  throw Error(`Invalid 'address' parameter '${address}'.`)
package/tsconfig.json CHANGED
@@ -16,8 +16,13 @@
16
16
  "noEmit": false,
17
17
  "outDir": "dist",
18
18
  "baseUrl": "src",
19
- "paths": {
20
- "@/*" : ["./*" ]
19
+ "paths": {
20
+ "@/*": [
21
+ "*"
22
+ ],
23
+ "@": [
24
+ "/"
25
+ ]
21
26
  },
22
27
  "typeRoots": [
23
28
  "./node_modules/@types",