@instadapp/interop-x 0.0.0-dev.d4e8223 → 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 (72) hide show
  1. package/dist/package.json +2 -2
  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/constants/addresses.js +3 -3
  6. package/dist/src/constants/index.js +0 -1
  7. package/dist/src/db/models/transaction.js +27 -9
  8. package/dist/src/gnosis/actions/index.js +9 -0
  9. package/dist/src/gnosis/actions/withdraw/index.js +41 -0
  10. package/dist/src/gnosis/index.js +20 -0
  11. package/dist/src/index.js +7 -18
  12. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
  13. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +2 -0
  14. package/dist/src/net/protocol/index.js +11 -1
  15. package/dist/src/tasks/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +43 -53
  16. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  17. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +89 -0
  18. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
  19. package/dist/src/tasks/index.js +13 -30
  20. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  21. package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
  22. package/dist/src/typechain/factories/index.js +3 -5
  23. package/dist/src/typechain/index.js +3 -5
  24. package/dist/src/utils/index.js +14 -84
  25. package/package.json +2 -2
  26. package/src/abi/index.ts +2 -4
  27. package/src/abi/interopXContract.json +391 -0
  28. package/src/alias.ts +6 -0
  29. package/src/constants/addresses.ts +3 -3
  30. package/src/constants/index.ts +0 -1
  31. package/src/db/models/transaction.ts +66 -21
  32. package/src/gnosis/actions/index.ts +5 -0
  33. package/src/gnosis/actions/withdraw/index.ts +56 -0
  34. package/src/gnosis/index.ts +19 -0
  35. package/src/index.ts +6 -17
  36. package/src/net/protocol/dial/SignatureDialProtocol.ts +11 -13
  37. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +3 -1
  38. package/src/net/protocol/index.ts +13 -3
  39. package/src/tasks/{InteropXGateway/ProcessDepositEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +62 -103
  40. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
  41. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +120 -0
  42. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
  43. package/src/tasks/index.ts +15 -37
  44. package/src/typechain/InteropXContract.ts +524 -0
  45. package/src/typechain/factories/InteropXContract__factory.ts +533 -0
  46. package/src/typechain/factories/index.ts +1 -2
  47. package/src/typechain/index.ts +2 -4
  48. package/src/utils/index.ts +46 -125
  49. package/tsconfig.json +7 -2
  50. package/dist/src/abi/interopBridgeToken.json +0 -298
  51. package/dist/src/abi/interopXGateway.json +0 -184
  52. package/dist/src/constants/itokens.js +0 -13
  53. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -146
  54. package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +0 -71
  55. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +0 -67
  56. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
  57. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +0 -72
  58. package/dist/src/typechain/InteropXGateway.js +0 -2
  59. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -471
  60. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  61. package/src/abi/interopBridgeToken.json +0 -298
  62. package/src/abi/interopXGateway.json +0 -184
  63. package/src/constants/itokens.ts +0 -10
  64. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +0 -231
  65. package/src/tasks/InteropBridge/SyncBurnEvents.ts +0 -121
  66. package/src/tasks/InteropBridge/SyncMintEvents.ts +0 -99
  67. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
  68. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +0 -105
  69. package/src/typechain/InteropBridgeToken.ts +0 -692
  70. package/src/typechain/InteropXGateway.ts +0 -407
  71. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -478
  72. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
package/src/index.ts CHANGED
@@ -1,22 +1,7 @@
1
- import moduleAlias from 'module-alias';
1
+ import './alias'
2
2
  import expandHomeDir from "expand-home-dir";
3
3
  import fs from 'fs-extra'
4
- moduleAlias.addAliases({
5
- "@/": __dirname + "/",
6
- "@/logger": __dirname + "/logger",
7
- "@/tasks": __dirname + "/tasks",
8
- "@/utils": __dirname + "/utils",
9
- "@/api": __dirname + "/api",
10
- "@/net": __dirname + "/net",
11
- "@/db": __dirname + "/db",
12
- "@/config": __dirname + "/config",
13
- "@/types": __dirname + "/types",
14
- "@/abi": __dirname + "/abi",
15
- "@/constants": __dirname + "/constants",
16
- "@/typechain": __dirname + "/typechain"
17
- })
18
4
 
19
- moduleAlias();
20
5
  import dotenv from "dotenv";
21
6
  import chalk from 'chalk';
22
7
  import { ethers } from "ethers";
@@ -104,7 +89,9 @@ async function main() {
104
89
 
105
90
  const tasks = new Tasks()
106
91
 
107
- tasks.start();
92
+ setTimeout(() => {
93
+ tasks.start();
94
+ }, 10000)
108
95
 
109
96
  startApiServer()
110
97
 
@@ -129,10 +116,12 @@ async function main() {
129
116
  transaction.sourceStatus = payload.data.sourceStatus
130
117
  transaction.sourceTransactionHash = payload.data.sourceTransactionHash
131
118
  transaction.sourceErrors = payload.data.sourceErrors
119
+ transaction.sourceLogs = payload.data.sourceLogs
132
120
 
133
121
  transaction.targetStatus = payload.data.targetStatus
134
122
  transaction.targetTransactionHash = payload.data.targetTransactionHash
135
123
  transaction.targetErrors = payload.data.targetErrors
124
+ transaction.targetLogs = payload.data.targetLogs
136
125
 
137
126
  transaction.status = payload.data.status
138
127
 
@@ -2,12 +2,13 @@ import { BaseDialProtocol } from "./BaseDialProtocol";
2
2
  import wait from "waait";
3
3
  import config from "@/config";
4
4
  import { Transaction } from "@/db";
5
- import { buildDataForTransaction, signGnosisSafeTx } from "@/utils";
5
+ import { signGnosisSafeTx } from "@/utils";
6
6
  import { addresses } from "@/constants";
7
7
  import { ChainId } from "@/types";
8
+ import { buildGnosisAction } from "@/gnosis";
8
9
 
9
10
  export interface ISignatureRequest {
10
- type: 'source' | 'target' ,
11
+ type: 'source' | 'target',
11
12
  transactionHash: string
12
13
  safeTxGas: string
13
14
  safeNonce: string
@@ -25,6 +26,10 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
25
26
  }
26
27
 
27
28
  async response(data: ISignatureRequest): Promise<ISignatureResponse> {
29
+ console.log({
30
+ tag: 'SignatureDialProtocol',
31
+ data
32
+ })
28
33
  const signer = config.wallet;
29
34
 
30
35
  let transaction: Transaction | null;
@@ -46,19 +51,12 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
46
51
  error: 'Event not found'
47
52
  };
48
53
  }
49
-
50
- console.log("signing:", {
51
- to: addresses[transaction.targetChainId].multisend,
52
- data: await buildDataForTransaction(transaction, data.type),
53
- chainId: transaction.targetChainId as ChainId,
54
- safeTxGas: data.safeTxGas,
55
- nonce: data.safeNonce,
56
- });
54
+ const { data: gnosisData } = await buildGnosisAction(transaction, data.type);
57
55
 
58
56
  const signedData = await signGnosisSafeTx({
59
- to: addresses[transaction.targetChainId].multisend,
60
- data: await buildDataForTransaction(transaction, data.type),
61
- chainId: transaction.targetChainId as ChainId,
57
+ to: addresses[transaction.sourceChainId].multisend,
58
+ data: gnosisData,
59
+ chainId: transaction.sourceChainId as ChainId,
62
60
  safeTxGas: data.safeTxGas,
63
61
  nonce: data.safeNonce,
64
62
  }, { signer });
@@ -1,7 +1,7 @@
1
1
  import { BaseDialProtocol } from "./BaseDialProtocol";
2
2
  import { Transaction } from "@/db";
3
3
 
4
- export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'> | null> {
4
+ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'> | null> {
5
5
  protected timeout = 30000;
6
6
 
7
7
  constructor(libp2p) {
@@ -20,10 +20,12 @@ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick
20
20
  sourceStatus: transaction.sourceStatus,
21
21
  sourceTransactionHash: transaction.sourceTransactionHash,
22
22
  sourceErrors: transaction.sourceErrors,
23
+ sourceLogs: transaction.sourceLogs,
23
24
 
24
25
  targetStatus: transaction.targetStatus,
25
26
  targetTransactionHash: transaction.targetTransactionHash,
26
27
  targetErrors: transaction.targetErrors,
28
+ targetLogs: transaction.targetLogs,
27
29
 
28
30
  status: transaction.status,
29
31
  }
@@ -36,7 +36,7 @@ interface PeerInfoEvent extends BaseMessageEvent {
36
36
  }
37
37
 
38
38
  interface TransactionStatusEvent extends BaseMessageEvent {
39
- data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'>
39
+ data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'>
40
40
  }
41
41
 
42
42
  declare interface Protocol {
@@ -68,23 +68,33 @@ class Protocol extends EventEmitter {
68
68
  Buffer.from(transaction.sourceStatus),
69
69
  Buffer.from(transaction.sourceTransactionHash || ''),
70
70
  transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
71
+ transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
71
72
 
72
73
  Buffer.from(transaction.targetStatus),
73
74
  Buffer.from(transaction.targetTransactionHash || ''),
74
75
  transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
76
+ transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
75
77
 
76
78
  Buffer.from(transaction.status),
77
79
  ],
78
- decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]: [Buffer, Buffer, Buffer, Buffer[], Buffer, Buffer, Buffer[], Buffer]) => ({
80
+ decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]: [Buffer, Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer]) => ({
79
81
  transactionHash: transactionHash.toString(),
80
82
 
81
83
  sourceStatus: sourceStatus.toString(),
82
84
  sourceTransactionHash: sourceTransactionHash.toString() || null,
83
85
  sourceErrors: sourceErrors.map((e) => e.toString()),
86
+ sourceLogs: sourceLogs.map(e => ({
87
+ type: e[0].toString(),
88
+ message: e[1].toString(),
89
+ })),
84
90
 
85
91
  targetStatus: targetStatus.toString(),
86
- targetTransactionHash: targetTransactionHash.toString()|| null,
92
+ targetTransactionHash: targetTransactionHash.toString() || null,
87
93
  targetErrors: targetErrors.map((e) => e.toString()),
94
+ targetLogs: targetLogs.map(e => ({
95
+ type: e[0].toString(),
96
+ message: e[1].toString(),
97
+ })),
88
98
 
89
99
  status: status.toString(),
90
100
  }),
@@ -1,68 +1,33 @@
1
1
  import { BaseTask } from "../BaseTask";
2
2
  import Logger from '@/logger';
3
- import { BigNumber, ethers } from "ethers";
3
+ import { ethers, Wallet } from "ethers";
4
4
  import abi from "@/abi";
5
5
  import { Transaction } from "@/db";
6
- import { buildDataForTransaction, buildSignatureBytes, getContract, getRpcProviderUrl, Signature } from "@/utils";
6
+ import { buildSignatureBytes, generateGnosisTransaction, generateInteropTransactionHash, getContract, getRpcProviderUrl, Signature } from "@/utils";
7
7
  import { addresses } from "@/constants";
8
+ import { Op } from "sequelize";
8
9
  import { ChainId } from "@/types";
9
10
  import config from "@/config";
10
- import { GnosisSafe, InteropXGateway } from "@/typechain";
11
- import { Op } from "sequelize";
11
+ import { GnosisSafe, InteropXContract } from "@/typechain";
12
12
  import wait from "waait";
13
+ import { buildGnosisAction } from "@/gnosis";
13
14
  import { peerPool, protocol } from "@/net";
14
15
  import { LogDescription } from "ethers/lib/utils";
15
16
 
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 {
17
+ class ProccessBridgeRequestEvents extends BaseTask {
57
18
  contractAddress: string;
19
+ safeContractAddress: string;
58
20
  provider: ethers.providers.JsonRpcProvider;
59
- contract: InteropXGateway;
21
+ contract: InteropXContract;
22
+ safeContract: GnosisSafe;
60
23
  chainId: ChainId;
61
- leadNodeOnly = true
24
+ sourceWallet: Wallet;
25
+
26
+ leadNodeOnly: boolean = true;
62
27
 
63
28
  constructor({ chainId }: { chainId: ChainId }) {
64
29
  super({
65
- logger: new Logger("InteropXGateway::ProcessDepositEvents"),
30
+ logger: new Logger("InteropXContract::ProccessBridgeRequestEvents"),
66
31
  })
67
32
  this.chainId = chainId;
68
33
  }
@@ -73,19 +38,17 @@ class ProcessDepositEvents extends BaseTask {
73
38
  const transaction = await Transaction.findOne({
74
39
  where: {
75
40
  status: 'pending',
76
- sourceStatus: 'success',
77
- targetStatus: 'uninitialised',
78
- action: 'deposit',
79
- sourceCreatedAt: {
41
+ sourceStatus: 'uninitialised',
42
+ createdAt: {
80
43
  [Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
81
44
  },
82
- targetDelayUntil: {
45
+ sourceDelayUntil: {
83
46
  [Op.or]: {
84
47
  [Op.is]: null,
85
48
  [Op.lt]: new Date(),
86
49
  }
87
50
  },
88
- sourceBlockNumber: {
51
+ requestBlockNumber: {
89
52
  [Op.lt]: blockNumber - 12,
90
53
  },
91
54
  sourceChainId: this.chainId,
@@ -101,34 +64,21 @@ class ProcessDepositEvents extends BaseTask {
101
64
  transaction.targetStatus = 'pending';
102
65
  await transaction.save();
103
66
 
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();
67
+ const ownersThreshold = await this.safeContract.getThreshold();
122
68
  await wait(10000);
123
69
 
124
- let data;
70
+
71
+ let data, logs = [];
125
72
 
126
73
  try {
127
- data = await buildDataForTransaction(transaction);
74
+ ({ data, logs } = await buildGnosisAction(transaction, 'source'));
75
+
128
76
  } catch (error) {
129
77
  console.log(error);
78
+ transaction.sourceStatus = 'failed';
79
+ transaction.sourceErrors = [error.message];
130
80
  transaction.targetStatus = 'failed';
131
- transaction.targetErrors = [error.message];
81
+
132
82
  transaction.status = 'failed'
133
83
  await transaction.save();
134
84
  protocol.sendTransaction(transaction)
@@ -143,13 +93,13 @@ class ProcessDepositEvents extends BaseTask {
143
93
  nonce: '0',
144
94
  operation: "1",
145
95
  refundReceiver: "0x0000000000000000000000000000000000000000",
146
- safeAddress: safeAddress,
96
+ safeAddress: this.safeContractAddress,
147
97
  safeTxGas: "79668",
148
- to: addresses[transaction.targetChainId].multisend,
98
+ to: addresses[transaction.sourceChainId].multisend,
149
99
  value: "0",
150
- }, safeContract);
100
+ }, this.safeContract);
151
101
 
152
- const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
102
+ const owners = await this.safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
153
103
 
154
104
  const ownerPeerIds = peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id)
155
105
 
@@ -171,18 +121,17 @@ class ProcessDepositEvents extends BaseTask {
171
121
 
172
122
  if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
173
123
  await transaction.save();
174
- transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
175
- transaction.targetStatus = 'uninitialised'
124
+ transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
125
+ transaction.sourceStatus = 'uninitialised'
176
126
 
177
127
  await transaction.save();
178
128
  const errorMessage = signatures.find(s => !!s.error)?.error;
179
129
  throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
180
130
  }
181
131
 
182
-
183
132
  console.log(`Executing transaction for execution ${transaction.transactionHash}`)
184
133
 
185
- const { data: txData } = await safeContract.populateTransaction.execTransaction(
134
+ const { data: txData } = await this.safeContract.populateTransaction.execTransaction(
186
135
  gnosisTx.to,
187
136
  gnosisTx.value,
188
137
  gnosisTx.data,
@@ -195,20 +144,15 @@ class ProcessDepositEvents extends BaseTask {
195
144
  buildSignatureBytes(validSignatures)
196
145
  );
197
146
 
198
- console.log({
199
- from: targetWallet.address,
200
- gasPrice: BigNumber.from(120 * 10 ** 9).toString(),
201
- to: safeAddress,
147
+ const txSent = await this.sourceWallet.sendTransaction({
148
+ from: this.sourceWallet.address,
149
+ gasPrice: ethers.BigNumber.from(120 * 10 ** 9),
150
+ to: this.safeContractAddress,
202
151
  data: txData,
203
152
  })
204
153
 
154
+ console.log(txSent);
205
155
 
206
- const txSent = await targetWallet.sendTransaction({
207
- from: targetWallet.address,
208
- gasPrice: BigNumber.from(120 * 10 ** 9),
209
- to: safeAddress,
210
- data: txData,
211
- })
212
156
 
213
157
  const receipt = await txSent.wait();
214
158
 
@@ -216,20 +160,26 @@ class ProcessDepositEvents extends BaseTask {
216
160
 
217
161
  receipt.logs.forEach((log) => {
218
162
  try {
219
- parsedLogs.push(safeContract.interface.parseLog(log));
163
+ parsedLogs.push(this.safeContract.interface.parseLog(log));
220
164
  } catch (e) { }
221
165
  });
222
166
 
223
167
  if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
224
168
  console.log('ExecutionSuccess')
225
- transaction.targetStatus = 'success'
226
- transaction.targetTransactionHash = txSent.hash
169
+ transaction.sourceStatus = 'success'
170
+ if (txSent.blockNumber)
171
+ transaction.sourceBlockNumber = txSent.blockNumber;
172
+ transaction.sourceTransactionHash = txSent.hash
173
+ transaction.sourceLogs = logs;
227
174
  transaction.status = 'success'
228
175
  await transaction.save();
229
176
  } else {
230
177
  console.log('ExecutionFailure')
231
- transaction.targetStatus = 'failed'
232
- transaction.targetTransactionHash = txSent.hash
178
+ transaction.sourceStatus = 'failed'
179
+ if (txSent.blockNumber)
180
+ transaction.sourceBlockNumber = txSent.blockNumber;
181
+ transaction.sourceTransactionHash = txSent.hash
182
+ transaction.sourceTransactionHash = txSent.hash
233
183
  transaction.status = 'failed'
234
184
  await transaction.save();
235
185
  }
@@ -238,20 +188,29 @@ class ProcessDepositEvents extends BaseTask {
238
188
  }
239
189
 
240
190
  async start(): Promise<void> {
241
- this.contractAddress = addresses[this.chainId].interopXGateway;
191
+ this.contractAddress = addresses[this.chainId].interopXContract;
242
192
 
243
193
  this.provider = new ethers.providers.JsonRpcProvider(
244
194
  getRpcProviderUrl(this.chainId)
245
195
  );
246
196
 
247
- this.contract = getContract<InteropXGateway>(
197
+ this.sourceWallet = new ethers.Wallet(config.privateKey!, this.provider);
198
+
199
+ this.contract = getContract<InteropXContract>(
248
200
  this.contractAddress,
249
- abi.interopXGateway,
250
- new ethers.Wallet(config.privateKey!, this.provider)
201
+ abi.interopXContract,
202
+ this.sourceWallet
203
+ );
204
+
205
+ this.safeContractAddress = addresses[this.chainId].gnosisSafe;
206
+ this.safeContract = getContract<GnosisSafe>(
207
+ this.safeContractAddress,
208
+ abi.gnosisSafe,
209
+ this.sourceWallet
251
210
  );
252
211
 
253
212
  await super.start()
254
213
  }
255
214
  }
256
215
 
257
- export default ProcessDepositEvents;
216
+ export default ProccessBridgeRequestEvents;
@@ -0,0 +1,116 @@
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 { InteropXContract } from "@/typechain";
11
+
12
+ class SyncBridgeRequestEvents extends BaseTask {
13
+ contractAddress: string;
14
+ provider: ethers.providers.JsonRpcProvider;
15
+ contract: InteropXContract;
16
+ chainId: ChainId;
17
+
18
+ constructor({ chainId }: { chainId: ChainId }) {
19
+ super({
20
+ logger: new Logger("InteropXContract::SyncBridgeRequestEvents"),
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.LogBridgeRequest(),
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 { bridger, position, sourceChainId, targetChainId, metadata } = event.args;
44
+
45
+ const uniqueIdentifier = {
46
+ action: 'withdraw', //todo
47
+ bridger,
48
+ requestTransactionHash: event.transactionHash,
49
+ sourceChainId: sourceChainId.toNumber(),
50
+ targetChainId: targetChainId.toNumber(),
51
+ }
52
+
53
+ let transactionHash = generateInteropTransactionHash(uniqueIdentifier);
54
+
55
+ const transaction = await Transaction.findOne({ where: { transactionHash } });
56
+
57
+ if (transaction) {
58
+ continue;
59
+ }
60
+
61
+ await Transaction.create({
62
+ transactionHash,
63
+ ...uniqueIdentifier,
64
+ position,
65
+ metadata,
66
+ requestBlockNumber: event.blockNumber,
67
+ requestEvent: {
68
+ bridger,
69
+ position: {
70
+ withdraw: position.withdraw.map((v) => ({
71
+ sourceToken: v.sourceToken,
72
+ targetToken: v.targetToken,
73
+ amount: v.amount.toString()
74
+ })),
75
+ supply: position.supply.map((v) => ({
76
+ sourceToken: v.sourceToken,
77
+ targetToken: v.targetToken,
78
+ amount: v.amount.toString()
79
+ })),
80
+ },
81
+ sourceChainId: sourceChainId.toNumber(),
82
+ targetChainId: targetChainId.toNumber(),
83
+ metadata,
84
+ }
85
+ })
86
+
87
+ this.logger.info(
88
+ `New bridge request received: ${transactionHash} `
89
+ );
90
+ } catch (error) {
91
+ this.logger.error(error);
92
+ }
93
+ }
94
+
95
+ if (processedEvents > 0)
96
+ this.logger.info(`${processedEvents} events processed`);
97
+ }
98
+
99
+ async start(): Promise<void> {
100
+ this.contractAddress = addresses[this.chainId].interopXContract;
101
+
102
+ this.provider = new ethers.providers.JsonRpcProvider(
103
+ getRpcProviderUrl(this.chainId)
104
+ );
105
+
106
+ this.contract = getContract<InteropXContract>(
107
+ this.contractAddress,
108
+ abi.interopXContract,
109
+ new ethers.Wallet(config.privateKey!, this.provider)
110
+ );
111
+
112
+ await super.start()
113
+ }
114
+ }
115
+
116
+ export default SyncBridgeRequestEvents;
@@ -0,0 +1,120 @@
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 { InteropXContract } from "@/typechain";
11
+ import { Op } from "sequelize";
12
+
13
+ class SyncBridgeRequestSentEvents extends BaseTask {
14
+ contractAddress: string;
15
+ provider: ethers.providers.JsonRpcProvider;
16
+ contract: InteropXContract;
17
+ chainId: ChainId;
18
+
19
+ constructor({ chainId }: { chainId: ChainId }) {
20
+ super({
21
+ logger: new Logger("InteropXContract::SyncBridgeRequestSentEvents"),
22
+ })
23
+ this.chainId = chainId;
24
+ }
25
+
26
+ async pollHandler() {
27
+ const currentBlock = await this.provider.getBlockNumber();
28
+
29
+ const events = await this.contract.queryFilter(
30
+ this.contract.filters.LogBridgeRequestSent(),
31
+ currentBlock - 2000,
32
+ currentBlock,
33
+ );
34
+
35
+ let processedEvents = 0;
36
+
37
+ for (const event of events) {
38
+
39
+ try {
40
+ if (!event.args) {
41
+ continue;
42
+ }
43
+
44
+ const { bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
45
+
46
+ const uniqueIdentifier = {
47
+ action: 'withdraw',
48
+ bridger,
49
+ requestTransactionHash,
50
+ sourceChainId: sourceChainId,
51
+ targetChainId: targetChainId,
52
+ }
53
+
54
+ let transactionHash = generateInteropTransactionHash(uniqueIdentifier);
55
+
56
+ const transaction = await Transaction.findOne({
57
+ where: {
58
+ transactionHash, sourceStatus: {
59
+ [Op.ne]: 'success',
60
+ }
61
+ }
62
+ });
63
+
64
+ if (!transaction) {
65
+ continue;
66
+ }
67
+ transaction.sourceStatus = 'success'
68
+ transaction.sourceBlockNumber = event.blockNumber;
69
+ transaction.sourceTransactionHash = event.transactionHash
70
+ transaction.requestSentEvent = {
71
+ bridger,
72
+ position: {
73
+ withdraw: position.withdraw.map((v) => ({
74
+ sourceToken: v.sourceToken,
75
+ targetToken: v.targetToken,
76
+ amount: v.amount.toString()
77
+ })),
78
+ supply: position.supply.map((v) => ({
79
+ sourceToken: v.sourceToken,
80
+ targetToken: v.targetToken,
81
+ amount: v.amount.toString()
82
+ })),
83
+ },
84
+ sourceChainId: sourceChainId,
85
+ targetChainId: targetChainId,
86
+ metadata,
87
+ requestTransactionHash,
88
+ }
89
+ await transaction.save()
90
+
91
+ this.logger.info(
92
+ `New bridge request sent received: ${transactionHash} `
93
+ );
94
+ } catch (error) {
95
+ this.logger.error(error);
96
+ }
97
+ }
98
+
99
+ if (processedEvents > 0)
100
+ this.logger.info(`${processedEvents} events processed`);
101
+ }
102
+
103
+ async start(): Promise<void> {
104
+ this.contractAddress = addresses[this.chainId].interopXContract;
105
+
106
+ this.provider = new ethers.providers.JsonRpcProvider(
107
+ getRpcProviderUrl(this.chainId)
108
+ );
109
+
110
+ this.contract = getContract<InteropXContract>(
111
+ this.contractAddress,
112
+ abi.interopXContract,
113
+ new ethers.Wallet(config.privateKey!, this.provider)
114
+ );
115
+
116
+ await super.start()
117
+ }
118
+ }
119
+
120
+ export default SyncBridgeRequestSentEvents;