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

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 (80) hide show
  1. package/dist/package.json +3 -3
  2. package/dist/src/abi/index.js +2 -4
  3. package/dist/src/abi/interopXContract.json +391 -0
  4. package/dist/src/alias.js +10 -0
  5. package/dist/src/api/index.js +4 -1
  6. package/dist/src/config/index.js +10 -1
  7. package/dist/src/constants/addresses.js +3 -3
  8. package/dist/src/constants/index.js +0 -1
  9. package/dist/src/db/models/transaction.js +27 -9
  10. package/dist/src/gnosis/actions/index.js +9 -0
  11. package/dist/src/gnosis/actions/withdraw/index.js +41 -0
  12. package/dist/src/gnosis/index.js +20 -0
  13. package/dist/src/index.js +39 -23
  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 +9 -10
  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 +33 -11
  20. package/dist/src/tasks/BaseTask.js +11 -3
  21. package/dist/src/tasks/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +54 -52
  22. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  23. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +89 -0
  24. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  25. package/dist/src/tasks/index.js +13 -17
  26. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  27. package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
  28. package/dist/src/typechain/factories/index.js +3 -5
  29. package/dist/src/typechain/index.js +3 -5
  30. package/dist/src/utils/index.js +27 -87
  31. package/package.json +3 -3
  32. package/src/abi/index.ts +2 -4
  33. package/src/abi/interopXContract.json +391 -0
  34. package/src/alias.ts +6 -0
  35. package/src/api/index.ts +4 -1
  36. package/src/config/index.ts +9 -1
  37. package/src/constants/addresses.ts +3 -3
  38. package/src/constants/index.ts +0 -1
  39. package/src/db/models/transaction.ts +66 -21
  40. package/src/gnosis/actions/index.ts +5 -0
  41. package/src/gnosis/actions/withdraw/index.ts +56 -0
  42. package/src/gnosis/index.ts +19 -0
  43. package/src/index.ts +52 -25
  44. package/src/net/peer/index.ts +2 -1
  45. package/src/net/pool/index.ts +7 -3
  46. package/src/net/protocol/dial/SignatureDialProtocol.ts +11 -13
  47. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  48. package/src/net/protocol/index.ts +28 -6
  49. package/src/tasks/AutoUpdateTask.ts +36 -14
  50. package/src/tasks/BaseTask.ts +13 -3
  51. package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +78 -95
  52. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
  53. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +120 -0
  54. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  55. package/src/tasks/index.ts +17 -18
  56. package/src/typechain/InteropXContract.ts +524 -0
  57. package/src/typechain/factories/InteropXContract__factory.ts +533 -0
  58. package/src/typechain/factories/index.ts +1 -2
  59. package/src/typechain/index.ts +2 -4
  60. package/src/utils/index.ts +61 -128
  61. package/tsconfig.json +7 -2
  62. package/dist/src/abi/interopBridgeToken.json +0 -286
  63. package/dist/src/abi/interopXGateway.json +0 -184
  64. package/dist/src/constants/itokens.js +0 -13
  65. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -147
  66. package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -70
  67. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
  68. package/dist/src/typechain/InteropXGateway.js +0 -2
  69. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
  70. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  71. package/src/abi/interopBridgeToken.json +0 -286
  72. package/src/abi/interopXGateway.json +0 -184
  73. package/src/constants/itokens.ts +0 -10
  74. package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -121
  75. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -245
  76. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
  77. package/src/typechain/InteropBridgeToken.ts +0 -686
  78. package/src/typechain/InteropXGateway.ts +0 -407
  79. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  80. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -1,245 +0,0 @@
1
- import { BaseTask } from "../BaseTask";
2
- import Logger from '@/logger';
3
- import { BigNumber, ethers } from "ethers";
4
- import abi from "@/abi";
5
- import { Transaction } from "@/db";
6
- import { buildDataForTransaction, buildSignatureBytes, getContract, getRpcProviderUrl, Signature } from "@/utils";
7
- import { addresses } from "@/constants";
8
- import { ChainId } from "@/types";
9
- import config from "@/config";
10
- import { GnosisSafe, InteropXGateway } from "@/typechain";
11
- import { Op } from "sequelize";
12
- import wait from "waait";
13
- import { peerPool, protocol } from "@/net";
14
- import { LogDescription } from "ethers/lib/utils";
15
-
16
- const generateGnosisTransaction = async (transactionData: any, safeContract: GnosisSafe) => {
17
- console.log(transactionData);
18
-
19
- let isExecuted = await safeContract.dataHashes(
20
- await safeContract.getTransactionHash(
21
- transactionData.to,
22
- transactionData.value,
23
- transactionData.data,
24
- transactionData.operation,
25
- transactionData.safeTxGas,
26
- transactionData.baseGas,
27
- transactionData.gasPrice,
28
- transactionData.gasToken,
29
- transactionData.refundReceiver,
30
- transactionData.nonce
31
- )
32
- )
33
-
34
- while (isExecuted == 1) {
35
- transactionData.safeTxGas = BigNumber.from(String(transactionData.safeTxGas)).add(1).toString()
36
-
37
- isExecuted = await safeContract.dataHashes(
38
- await safeContract.getTransactionHash(
39
- transactionData.to,
40
- transactionData.value,
41
- transactionData.data,
42
- transactionData.operation,
43
- transactionData.safeTxGas,
44
- transactionData.baseGas,
45
- transactionData.gasPrice,
46
- transactionData.gasToken,
47
- transactionData.refundReceiver,
48
- transactionData.nonce
49
- )
50
- )
51
- }
52
-
53
- return transactionData
54
- }
55
-
56
- class ProcessDepositEvents extends BaseTask {
57
- contractAddress: string;
58
- provider: ethers.providers.JsonRpcProvider;
59
- contract: InteropXGateway;
60
- chainId: ChainId;
61
- leadNodeOnly = true
62
-
63
- constructor({ chainId }: { chainId: ChainId }) {
64
- super({
65
- logger: new Logger("InteropXGateway::ProcessDepositEvents"),
66
- })
67
- this.chainId = chainId;
68
- }
69
-
70
- async pollHandler() {
71
- const blockNumber = await this.provider.getBlockNumber()
72
-
73
- const transaction = await Transaction.findOne({
74
- where: {
75
- status: 'pending',
76
- sourceStatus: 'success',
77
- targetStatus: 'uninitialised',
78
- action: 'deposit',
79
- sourceCreatedAt: {
80
- [Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
81
- },
82
- targetDelayUntil: {
83
- [Op.or]: {
84
- [Op.is]: null,
85
- [Op.lt]: new Date(),
86
- }
87
- },
88
- sourceBlockNumber: {
89
- [Op.lt]: blockNumber - 12,
90
- },
91
- sourceChainId: this.chainId,
92
- }
93
- })
94
-
95
- if (!transaction) {
96
- return;
97
- }
98
-
99
- console.log(`Processing transaction ${transaction.transactionHash}`);
100
-
101
- transaction.targetStatus = 'pending';
102
- await transaction.save();
103
-
104
- // refresh event data?
105
-
106
- const targetChainProvider = new ethers.providers.JsonRpcProvider(
107
- getRpcProviderUrl(transaction.targetChainId as ChainId)
108
- );
109
-
110
- const targetWallet = new ethers.Wallet(config.privateKey!, targetChainProvider);
111
-
112
- const safeAddress = addresses[transaction.targetChainId].gnosisSafe;
113
-
114
-
115
- const safeContract = getContract<GnosisSafe>(
116
- safeAddress,
117
- abi.gnosisSafe,
118
- targetWallet
119
- )
120
-
121
- const ownersThreshold = await safeContract.getThreshold();
122
- await wait(10000);
123
-
124
- let gnosisTx = await generateGnosisTransaction({
125
- baseGas: "0",
126
- data: await buildDataForTransaction(transaction),
127
- gasPrice: "0",
128
- gasToken: "0x0000000000000000000000000000000000000000",
129
- nonce: '0',
130
- operation: "1",
131
- refundReceiver: "0x0000000000000000000000000000000000000000",
132
- safeAddress: safeAddress,
133
- safeTxGas: "79668",
134
- to: addresses[transaction.targetChainId].multisend,
135
- value: "0",
136
- }, safeContract);
137
-
138
- const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
139
-
140
- const ownerPeerIds = peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id)
141
-
142
- console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
143
-
144
- console.log(ownerPeerIds);
145
-
146
- const signatures = await protocol.requestSignatures({
147
- type: 'source',
148
- transactionHash: transaction.transactionHash,
149
- safeTxGas: gnosisTx.safeTxGas,
150
- safeNonce: gnosisTx.nonce
151
- }, ownerPeerIds)
152
-
153
-
154
- const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x') as Signature[];
155
-
156
- console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
157
-
158
- if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
159
- await transaction.save();
160
- transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
161
- transaction.targetStatus = 'uninitialised'
162
-
163
- await transaction.save();
164
- const errorMessage = signatures.find(s => !!s.error)?.error;
165
- throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
166
- }
167
-
168
-
169
- console.log(`Executing transaction for execution ${transaction.transactionHash}`)
170
-
171
- const { data: txData } = await safeContract.populateTransaction.execTransaction(
172
- gnosisTx.to,
173
- gnosisTx.value,
174
- gnosisTx.data,
175
- gnosisTx.operation,
176
- gnosisTx.safeTxGas,
177
- gnosisTx.baseGas,
178
- gnosisTx.gasPrice,
179
- gnosisTx.gasToken,
180
- gnosisTx.refundReceiver,
181
- buildSignatureBytes(validSignatures)
182
- );
183
-
184
- console.log({
185
- from: targetWallet.address,
186
- gasPrice: BigNumber.from(120 * 10 ** 9).toString(),
187
- to: safeAddress,
188
- data: txData,
189
- })
190
-
191
-
192
- const txSent = await targetWallet.sendTransaction({
193
- from: targetWallet.address,
194
- gasPrice: BigNumber.from(120 * 10 ** 9),
195
- to: safeAddress,
196
- data: txData,
197
- })
198
-
199
- const receipt = await txSent.wait();
200
-
201
- const parsedLogs: LogDescription[] = [];
202
-
203
- receipt.logs.forEach((log) => {
204
- try {
205
- parsedLogs.push(safeContract.interface.parseLog(log));
206
- } catch (e) { }
207
- });
208
-
209
- if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
210
- console.log('ExecutionSuccess')
211
- transaction.targetStatus = 'success'
212
- transaction.targetTransactionHash = txSent.hash
213
- transaction.status = 'success'
214
- await transaction.save();
215
- } else {
216
- console.log('ExecutionFailure')
217
- transaction.targetStatus = 'failed'
218
- transaction.targetTransactionHash = txSent.hash
219
- transaction.status = 'failed'
220
- await transaction.save();
221
- }
222
-
223
- protocol.sendTransaction(transaction)
224
- }
225
-
226
- async start(): Promise<void> {
227
- this.logger.info(`Starting execution watcher on interop chain`);
228
-
229
- this.contractAddress = addresses[this.chainId].interopXGateway;
230
-
231
- this.provider = new ethers.providers.JsonRpcProvider(
232
- getRpcProviderUrl(this.chainId)
233
- );
234
-
235
- this.contract = getContract<InteropXGateway>(
236
- this.contractAddress,
237
- abi.interopXGateway,
238
- new ethers.Wallet(config.privateKey!, this.provider)
239
- );
240
-
241
- await super.start()
242
- }
243
- }
244
-
245
- export default ProcessDepositEvents;
@@ -1,126 +0,0 @@
1
- import { BaseTask } from "../BaseTask";
2
- import Logger from '@/logger';
3
- import { ethers } from "ethers";
4
- import abi from "@/abi";
5
- import { Transaction } from "@/db";
6
- import { generateInteropTransactionHash, getContract, getRpcProviderUrl } from "@/utils";
7
- import { addresses } from "@/constants";
8
- import { ChainId } from "@/types";
9
- import config from "@/config";
10
- import { InteropXGateway } from "@/typechain";
11
-
12
- class SyncDepositEvents extends BaseTask {
13
- contractAddress: string;
14
- provider: ethers.providers.JsonRpcProvider;
15
- contract: InteropXGateway;
16
- chainId: ChainId;
17
-
18
- constructor({ chainId }: { chainId: ChainId }) {
19
- super({
20
- logger: new Logger("InteropXGateway::SyncDepositEvents"),
21
- })
22
- this.chainId = chainId;
23
- }
24
-
25
- async pollHandler() {
26
- const currentBlock = await this.provider.getBlockNumber();
27
-
28
- const events = await this.contract.queryFilter(
29
- this.contract.filters.LogGatewayDeposit(),
30
- currentBlock - 2000,
31
- currentBlock,
32
- );
33
-
34
- let processedEvents = 0;
35
-
36
- for (const event of events) {
37
-
38
- try {
39
- if (!event.args) {
40
- continue;
41
- }
42
-
43
- const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
44
-
45
- const uniqueIdentifier = {
46
- action: 'deposit',
47
- submitTransactionHash: event.transactionHash,
48
- sourceChainId: sourceChainId.toNumber(),
49
- targetChainId: targetChainId.toNumber(),
50
- }
51
-
52
- if (await Transaction.findOne({ where: uniqueIdentifier })) {
53
- continue;
54
- }
55
-
56
- const tx = await event.getTransaction()
57
-
58
- await Transaction.create({
59
- ...uniqueIdentifier,
60
- transactionHash: generateInteropTransactionHash(uniqueIdentifier),
61
- from: tx.from,
62
- to: user,
63
-
64
-
65
- submitTransactionHash: event.transactionHash,
66
- submitBlockNumber: event.blockNumber,
67
-
68
- // submit & source are the same
69
- sourceTransactionHash: event.transactionHash,
70
- sourceBlockNumber: event.blockNumber,
71
- sourceStatus: "success",
72
-
73
- targetStatus: "uninitialised",
74
-
75
- submitEvent: {
76
- user,
77
- sourceChainId: sourceChainId.toString(),
78
- targetChainId: targetChainId.toString(),
79
- token: token,
80
- amount: amount.toString(),
81
- vnonce: vnonce.toString(),
82
- },
83
-
84
- sourceEvent: {
85
- user,
86
- sourceChainId: sourceChainId.toString(),
87
- targetChainId: targetChainId.toString(),
88
- token: token,
89
- amount: amount.toString(),
90
- vnonce: vnonce.toString(),
91
- },
92
- status: "pending",
93
- })
94
-
95
- this.logger.info(
96
- `Deposit queued: ${event.transactionHash} ${event.blockNumber}`
97
- );
98
- } catch (error) {
99
- this.logger.error(error);
100
- }
101
- }
102
-
103
- if (processedEvents > 0)
104
- this.logger.info(`${processedEvents} events processed`);
105
- }
106
-
107
- async start(): Promise<void> {
108
- this.logger.info(`Starting execution watcher on interop chain`);
109
-
110
- this.contractAddress = addresses[this.chainId].interopXGateway;
111
-
112
- this.provider = new ethers.providers.JsonRpcProvider(
113
- getRpcProviderUrl(this.chainId)
114
- );
115
-
116
- this.contract = getContract<InteropXGateway>(
117
- this.contractAddress,
118
- abi.interopXGateway,
119
- new ethers.Wallet(config.privateKey!, this.provider)
120
- );
121
-
122
- await super.start()
123
- }
124
- }
125
-
126
- export default SyncDepositEvents;