@instadapp/interop-x 0.0.0-dev.098229d → 0.0.0-dev.14afa72

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 +2 -2
  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 +4 -1
  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 +34 -6
  14. package/dist/src/net/peer/index.js +2 -1
  15. package/dist/src/net/pool/index.js +4 -2
  16. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
  17. package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +0 -0
  18. package/dist/src/net/protocol/index.js +6 -6
  19. package/dist/src/tasks/AutoUpdateTask.js +33 -11
  20. package/dist/src/tasks/BaseTask.js +4 -0
  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/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 +14 -85
  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/api/index.ts +4 -1
  35. package/src/config/index.ts +9 -1
  36. package/src/constants/addresses.ts +1 -1
  37. package/src/constants/itokens.ts +1 -1
  38. package/src/db/models/transaction.ts +10 -0
  39. package/src/gnosis/actions/deposit.ts +63 -0
  40. package/src/gnosis/actions/index.ts +7 -0
  41. package/src/gnosis/actions/withdraw.ts +67 -0
  42. package/src/gnosis/index.ts +19 -0
  43. package/src/index.ts +47 -8
  44. package/src/net/peer/index.ts +2 -1
  45. package/src/net/pool/index.ts +4 -2
  46. package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
  47. package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +0 -0
  48. package/src/net/protocol/index.ts +5 -5
  49. package/src/tasks/AutoUpdateTask.ts +36 -14
  50. package/src/tasks/BaseTask.ts +5 -0
  51. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +24 -8
  52. package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -15
  53. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  54. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +22 -7
  55. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -4
  56. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -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 +16 -125
@@ -17,6 +17,7 @@ import KadDHT from "libp2p-kad-dht";
17
17
  import PubsubPeerDiscovery from "libp2p-pubsub-peer-discovery";
18
18
  import { protocol } from "@/net";
19
19
  import config from "@/config";
20
+ import chalk from "chalk";
20
21
 
21
22
  const logger = new Logger("Peer");
22
23
 
@@ -80,7 +81,7 @@ export const startPeer = async ({ }: IPeerOptions) => {
80
81
  },
81
82
  });
82
83
 
83
- logger.info("Peer ID:", node.peerId.toB58String());
84
+ logger.info("Peer ID:", chalk.bold(node.peerId.toB58String()));
84
85
 
85
86
  await node.start();
86
87
 
@@ -2,6 +2,8 @@ import { Event } from "@/types";
2
2
  import config from "@/config";
3
3
  import Logger from "@/logger";
4
4
  import { getAddress } from "ethers/lib/utils";
5
+ import { shortenHash } from "@/utils";
6
+ import chalk from "chalk";
5
7
 
6
8
 
7
9
  const logger = new Logger('PeerPool')
@@ -87,7 +89,7 @@ export class PeerPool {
87
89
 
88
90
  if (newPeer) {
89
91
  config.events.emit(Event.POOL_PEER_ADDED, peer)
90
- logger.info(`Peer ${peer.id} with address ${peer.publicAddress} added to pool`)
92
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} added to pool`)
91
93
  }
92
94
  }
93
95
  }
@@ -102,7 +104,7 @@ export class PeerPool {
102
104
  if (this.pool.delete(peer.id)) {
103
105
  peer.pooled = false
104
106
  config.events.emit(Event.POOL_PEER_REMOVED, peer)
105
- logger.info(`Peer ${peer.id} with address ${peer.publicAddress} removed from pool`)
107
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} removed from pool`)
106
108
  }
107
109
  }
108
110
  }
@@ -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
@@ -46,18 +47,11 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
46
47
  error: 'Event not found'
47
48
  };
48
49
  }
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
- });
50
+ const { data: gnosisData } = await buildGnosisAction(transaction, data.type);
57
51
 
58
52
  const signedData = await signGnosisSafeTx({
59
53
  to: addresses[transaction.targetChainId].multisend,
60
- data: await buildDataForTransaction(transaction, data.type),
54
+ data: gnosisData,
61
55
  chainId: transaction.targetChainId as ChainId,
62
56
  safeTxGas: data.safeTxGas,
63
57
  nonce: data.safeNonce,
@@ -6,7 +6,7 @@ import { IPeerInfo, peerPool } from "..";
6
6
  import config from "@/config";
7
7
  import { Event } from "@/types";
8
8
  import { Transaction } from "@/db";
9
- import { TransactionStatusDialProtocol } from "./dial/SignatureDialProtocol.1";
9
+ import { TransactionStatusDialProtocol } from "./dial/TransactionStatusDialProtocol";
10
10
 
11
11
  export interface ProtocolOptions {
12
12
  /* Handshake timeout in ms (default: 8000) */
@@ -66,11 +66,11 @@ class Protocol extends EventEmitter {
66
66
  Buffer.from(transaction.transactionHash),
67
67
 
68
68
  Buffer.from(transaction.sourceStatus),
69
- Buffer.from(transaction.sourceTransactionHash),
69
+ Buffer.from(transaction.sourceTransactionHash || ''),
70
70
  transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
71
71
 
72
72
  Buffer.from(transaction.targetStatus),
73
- Buffer.from(transaction.targetTransactionHash),
73
+ Buffer.from(transaction.targetTransactionHash || ''),
74
74
  transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
75
75
 
76
76
  Buffer.from(transaction.status),
@@ -79,11 +79,11 @@ class Protocol extends EventEmitter {
79
79
  transactionHash: transactionHash.toString(),
80
80
 
81
81
  sourceStatus: sourceStatus.toString(),
82
- sourceTransactionHash: sourceTransactionHash.toString(),
82
+ sourceTransactionHash: sourceTransactionHash.toString() || null,
83
83
  sourceErrors: sourceErrors.map((e) => e.toString()),
84
84
 
85
85
  targetStatus: targetStatus.toString(),
86
- targetTransactionHash: targetTransactionHash.toString(),
86
+ targetTransactionHash: targetTransactionHash.toString()|| null,
87
87
  targetErrors: targetErrors.map((e) => e.toString()),
88
88
 
89
89
  status: status.toString(),
@@ -1,12 +1,16 @@
1
1
  import { BaseTask } from "./BaseTask";
2
2
  import Logger from '@/logger';
3
- import { http } from "@/utils";
4
- import spawn from 'await-spawn';
3
+ import spawnAsync from 'await-spawn';
4
+ import { spawn } from 'child_process'
5
5
  import config from "@/config";
6
6
  import wait from "waait";
7
+ import packageJson from "../../package.json";
8
+
9
+ const currentVersion = packageJson.version;
10
+ const tag = config.staging ? 'dev' : 'latest';
7
11
 
8
12
  class AutoUpdateTask extends BaseTask {
9
- pollIntervalMs: number = 60 * 5 * 1000
13
+ pollIntervalMs: number = 60 * 10 * 1000
10
14
 
11
15
  constructor() {
12
16
  super({
@@ -18,15 +22,28 @@ class AutoUpdateTask extends BaseTask {
18
22
  return config.autoUpdate && !config.isLeadNode();
19
23
  }
20
24
 
21
- getCurrentVersion() {
22
- return require('../../package.json').version
25
+ async getInstalledVersion() {
26
+ try {
27
+ const stdout = await spawnAsync('npm', ['-g', 'ls', '--depth=0', '--json'])
28
+ return JSON.parse(stdout.toString()).dependencies[packageJson.name].version
29
+ } catch (error) {
30
+ this.logger.error(error)
31
+ return currentVersion
32
+ }
23
33
  }
24
- async pollHandler() {
25
34
 
26
- const { data } = await http.get('https://registry.npmjs.org/@instadapp/interop-x')
35
+ async getLatestVersion() {
36
+ try {
37
+ const stdout = await spawnAsync('npm', ['view', `${packageJson.name}@${tag}`, 'version'])
38
+ return stdout.toString().trim()
39
+ } catch (error) {
40
+ this.logger.error(error)
41
+ return currentVersion
42
+ }
43
+ }
27
44
 
28
- const version = data['dist-tags'].latest
29
- const currentVersion = this.getCurrentVersion()
45
+ async pollHandler() {
46
+ const version = await this.getLatestVersion()
30
47
 
31
48
  if (version === currentVersion) {
32
49
  return;
@@ -34,13 +51,13 @@ class AutoUpdateTask extends BaseTask {
34
51
 
35
52
  this.logger.warn(`New version ${version} available.`)
36
53
 
54
+ this.logger.info('Updating...')
37
55
 
38
- await spawn('npm', ['-g', 'install', '@instadapp/interop-x', '-f']);
39
-
56
+ await spawnAsync('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
40
57
 
41
58
  await wait(5000)
42
59
 
43
- if (currentVersion === this.getCurrentVersion()) {
60
+ if (version !== await this.getInstalledVersion()) {
44
61
  this.logger.warn(`failed to install ${version}, retrying in 5 minutes`)
45
62
  return;
46
63
  }
@@ -48,11 +65,16 @@ class AutoUpdateTask extends BaseTask {
48
65
  this.logger.warn(`Installed version ${version}`)
49
66
  this.logger.warn(`Restarting...`)
50
67
 
51
- spawn(process.argv[0], process.argv.slice(1), {
68
+
69
+ // TODO: its restarting in the bg, but it should be in the fg
70
+ const subprocess = spawn(process.argv[0], process.argv.slice(1), {
52
71
  cwd: process.cwd(),
53
- stdio: "inherit"
72
+ stdio: "inherit",
73
+ // shell: process.env.SHELL,
54
74
  });
55
75
 
76
+ subprocess.unref();
77
+
56
78
  process.exit()
57
79
  }
58
80
  }
@@ -46,6 +46,11 @@ export class BaseTask extends EventEmitter implements IBaseTask {
46
46
  }
47
47
 
48
48
  prePollHandler(): boolean {
49
+ if(config.isMaintenanceMode()){
50
+ this.logger.warn('Maintenance mode is enabled. Skipping task.')
51
+ return false
52
+ }
53
+
49
54
  if (this.exceptLeadNode) {
50
55
  return !config.isLeadNode();
51
56
  }
@@ -3,19 +3,20 @@ import Logger from '@/logger';
3
3
  import { BigNumber, ethers } 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, getContract, getRpcProviderUrl, Signature } from "@/utils";
7
7
  import { addresses } from "@/constants";
8
8
  import { ChainId } from "@/types";
9
9
  import config from "@/config";
10
- import { GnosisSafe, InteropXGateway } from "@/typechain";
10
+ import { GnosisSafe } from "@/typechain";
11
11
  import { Op } from "sequelize";
12
12
  import wait from "waait";
13
13
  import { peerPool, protocol } from "@/net";
14
14
  import { LogDescription } from "ethers/lib/utils";
15
+ import { buildGnosisAction } from "@/gnosis";
15
16
 
16
17
  const generateGnosisTransaction = async (transactionData: any, safeContract: GnosisSafe) => {
17
18
  console.log(transactionData);
18
-
19
+
19
20
  let isExecuted = await safeContract.dataHashes(
20
21
  await safeContract.getTransactionHash(
21
22
  transactionData.to,
@@ -95,7 +96,7 @@ class ProcessWithdrawEvents extends BaseTask {
95
96
  }
96
97
 
97
98
  console.log(`Processing transaction ${transaction.transactionHash}`);
98
-
99
+
99
100
  transaction.targetStatus = 'pending';
100
101
  await transaction.save();
101
102
 
@@ -119,9 +120,23 @@ class ProcessWithdrawEvents extends BaseTask {
119
120
  const ownersThreshold = await safeContract.getThreshold();
120
121
  await wait(10000);
121
122
 
123
+ let data, logs = [];
124
+
125
+ try {
126
+ ({ data, logs } = await buildGnosisAction(transaction));
127
+ } catch (error) {
128
+ console.log(error);
129
+ transaction.targetStatus = 'failed';
130
+ transaction.targetErrors = [error.message];
131
+ transaction.status = 'failed'
132
+ await transaction.save();
133
+ protocol.sendTransaction(transaction)
134
+ return;
135
+ }
136
+
122
137
  let gnosisTx = await generateGnosisTransaction({
123
138
  baseGas: "0",
124
- data: await buildDataForTransaction(transaction),
139
+ data,
125
140
  gasPrice: "0",
126
141
  gasToken: "0x0000000000000000000000000000000000000000",
127
142
  nonce: '0',
@@ -140,7 +155,7 @@ class ProcessWithdrawEvents extends BaseTask {
140
155
  console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
141
156
 
142
157
  console.log(ownerPeerIds);
143
-
158
+
144
159
  const signatures = await protocol.requestSignatures({
145
160
  type: 'source',
146
161
  transactionHash: transaction.transactionHash,
@@ -208,6 +223,7 @@ class ProcessWithdrawEvents extends BaseTask {
208
223
  console.log('ExecutionSuccess')
209
224
  transaction.targetStatus = 'success'
210
225
  transaction.targetTransactionHash = txSent.hash
226
+ transaction.targetLogs = logs
211
227
  transaction.status = 'success'
212
228
  await transaction.save();
213
229
  } else {
@@ -217,11 +233,11 @@ class ProcessWithdrawEvents extends BaseTask {
217
233
  transaction.status = 'failed'
218
234
  await transaction.save();
219
235
  }
236
+
237
+ protocol.sendTransaction(transaction)
220
238
  }
221
239
 
222
240
  async start(): Promise<void> {
223
- this.logger.info(`Starting execution watcher on interop chain`);
224
-
225
241
  this.provider = new ethers.providers.JsonRpcProvider(
226
242
  getRpcProviderUrl(this.chainId)
227
243
  );
@@ -8,7 +8,7 @@ import { ChainId } from "@/types";
8
8
  import config from "@/config";
9
9
  import { InteropBridgeToken } from "@/typechain";
10
10
 
11
- class SyncWithdrawEvents extends BaseTask {
11
+ class SyncBurnEvents extends BaseTask {
12
12
  contractAddress: string;
13
13
  provider: ethers.providers.JsonRpcProvider;
14
14
  contract: InteropBridgeToken;
@@ -17,7 +17,7 @@ class SyncWithdrawEvents extends BaseTask {
17
17
 
18
18
  constructor({ chainId, itokenAddress }: { chainId: ChainId, itokenAddress: string }) {
19
19
  super({
20
- logger: new Logger("InteropBridgeToken::SyncWithdrawEvents"),
20
+ logger: new Logger("InteropBridgeToken::SyncBurnEvents"),
21
21
  })
22
22
  this.chainId = chainId;
23
23
  this.itokenAddress = itokenAddress;
@@ -41,13 +41,13 @@ class SyncWithdrawEvents extends BaseTask {
41
41
  continue;
42
42
  }
43
43
 
44
- const { to, amount, chainId } = event.args;
44
+ const { to, amount, sourceChainId, targetChainId } = event.args;
45
45
 
46
46
  const uniqueIdentifier = {
47
47
  action: 'withdraw',
48
48
  submitTransactionHash: event.transactionHash,
49
- sourceChainId:this.chainId,
50
- targetChainId: chainId.toNumber(),
49
+ sourceChainId: sourceChainId,
50
+ targetChainId: targetChainId,
51
51
  }
52
52
 
53
53
  if (await Transaction.findOne({ where: uniqueIdentifier })) {
@@ -62,7 +62,6 @@ class SyncWithdrawEvents extends BaseTask {
62
62
  from: tx.from,
63
63
  to,
64
64
 
65
-
66
65
  submitTransactionHash: event.transactionHash,
67
66
  submitBlockNumber: event.blockNumber,
68
67
 
@@ -70,21 +69,22 @@ class SyncWithdrawEvents extends BaseTask {
70
69
  sourceTransactionHash: event.transactionHash,
71
70
  sourceBlockNumber: event.blockNumber,
72
71
  sourceStatus: "success",
73
-
74
72
  targetStatus: "uninitialised",
75
73
 
76
74
  submitEvent: {
77
- to,
75
+ to,
78
76
  amount: amount.toString(),
79
77
  itoken: this.itokenAddress,
80
- chainId: chainId.toString()
78
+ sourceChainId: sourceChainId,
79
+ targetChainId: targetChainId,
81
80
  },
82
81
 
83
82
  sourceEvent: {
84
- to,
85
- amount: amount.toString(),
83
+ to,
84
+ amount: amount.toString(),
86
85
  itoken: this.itokenAddress,
87
- chainId: chainId.toString(),
86
+ sourceChainId: sourceChainId,
87
+ targetChainId: targetChainId,
88
88
  },
89
89
  status: "pending",
90
90
  })
@@ -102,8 +102,6 @@ class SyncWithdrawEvents extends BaseTask {
102
102
  }
103
103
 
104
104
  async start(): Promise<void> {
105
- this.logger.info(`Starting execution watcher on interop chain`);
106
-
107
105
  this.provider = new ethers.providers.JsonRpcProvider(
108
106
  getRpcProviderUrl(this.chainId)
109
107
  );
@@ -118,4 +116,4 @@ class SyncWithdrawEvents extends BaseTask {
118
116
  }
119
117
  }
120
118
 
121
- export default SyncWithdrawEvents;
119
+ export default SyncBurnEvents;
@@ -0,0 +1,99 @@
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 { getContract, getRpcProviderUrl } from "@/utils";
7
+ import { ChainId } from "@/types";
8
+ import config from "@/config";
9
+ import { InteropBridgeToken } from "@/typechain";
10
+
11
+ class SyncMintEvents extends BaseTask {
12
+ contractAddress: string;
13
+ provider: ethers.providers.JsonRpcProvider;
14
+ contract: InteropBridgeToken;
15
+ chainId: ChainId;
16
+ itokenAddress: string;
17
+
18
+ constructor({ chainId, itokenAddress }: { chainId: ChainId, itokenAddress: string }) {
19
+ super({
20
+ logger: new Logger("InteropBridgeToken::SyncMintEvents"),
21
+ })
22
+ this.chainId = chainId;
23
+ this.itokenAddress = itokenAddress;
24
+ }
25
+
26
+ async pollHandler() {
27
+ const currentBlock = await this.provider.getBlockNumber();
28
+
29
+ const events = await this.contract.queryFilter(
30
+ this.contract.filters.Mint(),
31
+ currentBlock - 500,
32
+ currentBlock,
33
+ );
34
+
35
+ for (const event of events) {
36
+
37
+ try {
38
+ if (!event.args) {
39
+ continue;
40
+ }
41
+
42
+ const { sourceChainId, targetChainId, amount, to, submitTransactionHash } = event.args;
43
+
44
+ const uniqueIdentifier = {
45
+ action: 'deposit',
46
+ submitTransactionHash: submitTransactionHash,
47
+ sourceChainId: sourceChainId,
48
+ targetChainId: targetChainId,
49
+
50
+ targetEvent: null
51
+ }
52
+
53
+ const transaction = await Transaction.findOne({ where: uniqueIdentifier });
54
+
55
+ if(! transaction){
56
+ return;
57
+ }
58
+
59
+ const tx = await event.getTransaction()
60
+
61
+ transaction.targetStatus = 'success'
62
+ transaction.targetErrors = []
63
+ transaction.targetTransactionHash = tx.hash
64
+ transaction.targetEvent = {
65
+ sourceChainId,
66
+ targetChainId,
67
+ amount: amount.toString(),
68
+ to,
69
+ submitTransactionHash
70
+ }
71
+ transaction.status = 'success'
72
+
73
+ await transaction.save()
74
+
75
+ this.logger.info(
76
+ `Mint confirmation received: ${transaction.transactionHash} `
77
+ );
78
+ } catch (error) {
79
+ this.logger.error(error);
80
+ }
81
+ }
82
+ }
83
+
84
+ async start(): Promise<void> {
85
+ this.provider = new ethers.providers.JsonRpcProvider(
86
+ getRpcProviderUrl(this.chainId)
87
+ );
88
+
89
+ this.contract = getContract<InteropBridgeToken>(
90
+ this.itokenAddress,
91
+ abi.interopBridgeToken,
92
+ new ethers.Wallet(config.privateKey!, this.provider)
93
+ );
94
+
95
+ await super.start()
96
+ }
97
+ }
98
+
99
+ export default SyncMintEvents;
@@ -3,7 +3,7 @@ import Logger from '@/logger';
3
3
  import { BigNumber, ethers } 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, getContract, getRpcProviderUrl, Signature } from "@/utils";
7
7
  import { addresses } from "@/constants";
8
8
  import { ChainId } from "@/types";
9
9
  import config from "@/config";
@@ -12,10 +12,11 @@ import { Op } from "sequelize";
12
12
  import wait from "waait";
13
13
  import { peerPool, protocol } from "@/net";
14
14
  import { LogDescription } from "ethers/lib/utils";
15
+ import { buildGnosisAction } from "@/gnosis";
15
16
 
16
17
  const generateGnosisTransaction = async (transactionData: any, safeContract: GnosisSafe) => {
17
18
  console.log(transactionData);
18
-
19
+
19
20
  let isExecuted = await safeContract.dataHashes(
20
21
  await safeContract.getTransactionHash(
21
22
  transactionData.to,
@@ -97,7 +98,7 @@ class ProcessDepositEvents extends BaseTask {
97
98
  }
98
99
 
99
100
  console.log(`Processing transaction ${transaction.transactionHash}`);
100
-
101
+
101
102
  transaction.targetStatus = 'pending';
102
103
  await transaction.save();
103
104
 
@@ -121,9 +122,24 @@ class ProcessDepositEvents extends BaseTask {
121
122
  const ownersThreshold = await safeContract.getThreshold();
122
123
  await wait(10000);
123
124
 
125
+ let data, logs = [];
126
+
127
+ try {
128
+ ({ data, logs } = await buildGnosisAction(transaction));
129
+
130
+ } catch (error) {
131
+ console.log(error);
132
+ transaction.targetStatus = 'failed';
133
+ transaction.targetErrors = [error.message];
134
+ transaction.status = 'failed'
135
+ await transaction.save();
136
+ protocol.sendTransaction(transaction)
137
+ return;
138
+ }
139
+
124
140
  let gnosisTx = await generateGnosisTransaction({
125
141
  baseGas: "0",
126
- data: await buildDataForTransaction(transaction),
142
+ data,
127
143
  gasPrice: "0",
128
144
  gasToken: "0x0000000000000000000000000000000000000000",
129
145
  nonce: '0',
@@ -142,7 +158,7 @@ class ProcessDepositEvents extends BaseTask {
142
158
  console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
143
159
 
144
160
  console.log(ownerPeerIds);
145
-
161
+
146
162
  const signatures = await protocol.requestSignatures({
147
163
  type: 'source',
148
164
  transactionHash: transaction.transactionHash,
@@ -210,6 +226,7 @@ class ProcessDepositEvents extends BaseTask {
210
226
  console.log('ExecutionSuccess')
211
227
  transaction.targetStatus = 'success'
212
228
  transaction.targetTransactionHash = txSent.hash
229
+ transaction.targetLogs = logs;
213
230
  transaction.status = 'success'
214
231
  await transaction.save();
215
232
  } else {
@@ -224,8 +241,6 @@ class ProcessDepositEvents extends BaseTask {
224
241
  }
225
242
 
226
243
  async start(): Promise<void> {
227
- this.logger.info(`Starting execution watcher on interop chain`);
228
-
229
244
  this.contractAddress = addresses[this.chainId].interopXGateway;
230
245
 
231
246
  this.provider = new ethers.providers.JsonRpcProvider(
@@ -45,8 +45,8 @@ class SyncDepositEvents extends BaseTask {
45
45
  const uniqueIdentifier = {
46
46
  action: 'deposit',
47
47
  submitTransactionHash: event.transactionHash,
48
- sourceChainId: sourceChainId.toNumber(),
49
- targetChainId: targetChainId.toNumber(),
48
+ sourceChainId: sourceChainId,
49
+ targetChainId: targetChainId,
50
50
  }
51
51
 
52
52
  if (await Transaction.findOne({ where: uniqueIdentifier })) {
@@ -105,8 +105,6 @@ class SyncDepositEvents extends BaseTask {
105
105
  }
106
106
 
107
107
  async start(): Promise<void> {
108
- this.logger.info(`Starting execution watcher on interop chain`);
109
-
110
108
  this.contractAddress = addresses[this.chainId].interopXGateway;
111
109
 
112
110
  this.provider = new ethers.providers.JsonRpcProvider(