@instadapp/interop-x 0.0.0-dev.80722d6 → 0.0.0-dev.8a0297a

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 (59) hide show
  1. package/bin/interop-x +1 -1
  2. package/dist/package.json +72 -0
  3. package/dist/{abi → src/abi}/erc20.json +0 -0
  4. package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
  5. package/dist/{abi → src/abi}/index.js +0 -0
  6. package/dist/{abi → src/abi}/interopBridgeToken.json +0 -0
  7. package/dist/{abi → src/abi}/interopXGateway.json +0 -0
  8. package/dist/src/api/index.js +33 -0
  9. package/dist/{config → src/config}/index.js +0 -0
  10. package/dist/{constants → src/constants}/addresses.js +0 -8
  11. package/dist/{constants → src/constants}/index.js +1 -0
  12. package/dist/src/constants/itokens.js +13 -0
  13. package/dist/{constants → src/constants}/tokens.js +0 -0
  14. package/dist/{db → src/db}/index.js +0 -0
  15. package/dist/{db → src/db}/models/index.js +0 -0
  16. package/dist/{db → src/db}/models/transaction.js +3 -1
  17. package/dist/{db → src/db}/sequelize.js +0 -0
  18. package/dist/{index.js → src/index.js} +5 -0
  19. package/dist/{logger → src/logger}/index.js +0 -0
  20. package/dist/{net → src/net}/index.js +0 -0
  21. package/dist/{net → src/net}/peer/index.js +6 -2
  22. package/dist/{net → src/net}/pool/index.js +9 -2
  23. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
  24. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +15 -12
  25. package/dist/{net → src/net}/protocol/index.js +0 -0
  26. package/dist/{tasks → src/tasks}/BaseTask.js +1 -1
  27. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +151 -0
  28. package/dist/{tasks → src/tasks}/InteropXGateway/SyncDepositEvents.js +14 -18
  29. package/dist/{tasks → src/tasks}/index.js +4 -0
  30. package/dist/{typechain → src/typechain}/Erc20.js +0 -0
  31. package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
  32. package/dist/{typechain → src/typechain}/InteropBridgeToken.js +0 -0
  33. package/dist/{typechain → src/typechain}/InteropXGateway.js +0 -0
  34. package/dist/{typechain → src/typechain}/common.js +0 -0
  35. package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
  36. package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
  37. package/dist/{typechain → src/typechain}/factories/InteropBridgeToken__factory.js +0 -0
  38. package/dist/{typechain → src/typechain}/factories/InteropXGateway__factory.js +0 -0
  39. package/dist/{typechain → src/typechain}/factories/index.js +0 -0
  40. package/dist/{typechain → src/typechain}/index.js +0 -0
  41. package/dist/{types.js → src/types.js} +0 -0
  42. package/dist/src/utils/index.js +178 -0
  43. package/package.json +9 -3
  44. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  45. package/src/api/index.ts +33 -0
  46. package/src/constants/addresses.ts +0 -8
  47. package/src/constants/index.ts +1 -0
  48. package/src/constants/itokens.ts +10 -0
  49. package/src/db/models/transaction.ts +8 -4
  50. package/src/index.ts +7 -0
  51. package/src/net/peer/index.ts +7 -6
  52. package/src/net/pool/index.ts +12 -2
  53. package/src/net/protocol/dial/SignatureDialProtocol.ts +17 -13
  54. package/src/tasks/BaseTask.ts +1 -1
  55. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +245 -0
  56. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +21 -9
  57. package/src/tasks/index.ts +7 -2
  58. package/src/utils/index.ts +113 -4
  59. package/dist/utils/index.js +0 -101
package/bin/interop-x CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require('../dist/index')
2
+ require('../dist/src/index')
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@instadapp/interop-x",
3
+ "version": "0.0.0-dev.8a0297a",
4
+ "license": "MIT",
5
+ "main": "dist/index.js",
6
+ "engines": {
7
+ "node": ">=16",
8
+ "yarn": "^1.22.0"
9
+ },
10
+ "scripts": {
11
+ "start": "yarn build && node bin/interop-x",
12
+ "build": "yarn generate-abi-types && export GIT_REF=$(git rev-parse --short HEAD) && rimraf ./dist && tsc -p tsconfig.json && replace-in-file '@GIT_SHORT_HASH@' $GIT_REF ./dist/**/*.js",
13
+ "dev": "yarn generate-abi-types && NODE_ENV=development nodemon",
14
+ "generate-abi-types": "typechain --target=ethers-v5 'src/abi/*.json' --out-dir 'src/typechain'",
15
+ "prepublishOnly": "yarn build",
16
+ "postinstall": "patch-package"
17
+ },
18
+ "nodemonConfig": {
19
+ "watch": [
20
+ "src"
21
+ ],
22
+ "ext": "ts",
23
+ "exec": "./node_modules/.bin/ts-node --files -r tsconfig-paths/register ./src/index.ts"
24
+ },
25
+ "dependencies": {
26
+ "@achingbrain/libp2p-gossipsub": "^0.12.2",
27
+ "axios": "^0.27.1",
28
+ "axios-retry": "^3.2.4",
29
+ "bignumber.js": "^9.0.2",
30
+ "chalk": "4.1.2",
31
+ "dotenv": "^16.0.0",
32
+ "ethereumjs-util": "^7.1.4",
33
+ "ethers": "^5.6.4",
34
+ "ethers-multisend": "^2.1.1",
35
+ "expand-home-dir": "^0.0.3",
36
+ "fastify": "^3.28.0",
37
+ "fastify-cors": "^6.0.3",
38
+ "libp2p": "^0.36.2",
39
+ "libp2p-bootstrap": "^0.14.0",
40
+ "libp2p-kad-dht": "^0.28.6",
41
+ "libp2p-mdns": "^0.18.0",
42
+ "libp2p-mplex": "^0.10.7",
43
+ "libp2p-noise": "^4.0.0",
44
+ "libp2p-pubsub-peer-discovery": "^4.0.0",
45
+ "libp2p-tcp": "^0.17.2",
46
+ "libp2p-websockets": "^0.16.2",
47
+ "luxon": "^2.3.2",
48
+ "module-alias": "^2.2.2",
49
+ "sequelize": "^6.19.0",
50
+ "sqlite3": "^5.0.5",
51
+ "waait": "^1.0.5"
52
+ },
53
+ "bin": {
54
+ "interop-x": "bin/interop-x",
55
+ "interopx": "bin/interop-x"
56
+ },
57
+ "devDependencies": {
58
+ "@typechain/ethers-v5": "^10.0.0",
59
+ "@types/bn.js": "^5.1.0",
60
+ "@types/fs-extra": "^9.0.13",
61
+ "@types/node": "^17.0.17",
62
+ "nodemon": "^2.0.15",
63
+ "patch-package": "^6.4.7",
64
+ "postinstall-postinstall": "^2.1.0",
65
+ "replace-in-file": "^6.3.2",
66
+ "rimraf": "^3.0.2",
67
+ "ts-node": "^10.5.0",
68
+ "tsconfig-paths": "^3.12.0",
69
+ "typechain": "^8.0.0",
70
+ "typescript": "^4.5.5"
71
+ }
72
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.startApiServer = void 0;
7
+ const fastify_1 = __importDefault(require("fastify"));
8
+ const fastify_cors_1 = __importDefault(require("fastify-cors"));
9
+ const logger_1 = __importDefault(require("@/logger"));
10
+ const db_1 = require("@/db");
11
+ const logger = new logger_1.default("RPC");
12
+ const server = (0, fastify_1.default)({ logger: false });
13
+ server.register(fastify_cors_1.default, {});
14
+ server.get('/', async () => 'Interop X API');
15
+ const startApiServer = async () => {
16
+ const HOST = process.env.API_HOST || '0.0.0.0';
17
+ const PORT = process.env.API_PORT || '8080';
18
+ try {
19
+ server.get('/transactions', async (req) => {
20
+ return await db_1.Transaction.findAndCountAll({
21
+ limit: 20,
22
+ offset: 0,
23
+ });
24
+ });
25
+ await server.listen(PORT, HOST);
26
+ logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
27
+ }
28
+ catch (err) {
29
+ logger.error(err);
30
+ process.exit(1);
31
+ }
32
+ };
33
+ exports.startApiServer = startApiServer;
File without changes
@@ -6,23 +6,15 @@ exports.addresses = {
6
6
  gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
7
7
  multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
8
8
  interopXGateway: '',
9
- interopBridgeTokens: [],
10
9
  },
11
10
  137: {
12
11
  gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
13
12
  multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
14
13
  interopXGateway: '',
15
- interopBridgeTokens: [
16
- {
17
- address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
18
- symbol: 'USDC',
19
- }
20
- ],
21
14
  },
22
15
  43114: {
23
16
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
24
17
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
25
18
  interopXGateway: '0x8D27758751BA488690974B6Ccfcda771D462945f',
26
- interopBridgeTokens: [],
27
19
  }
28
20
  };
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./addresses"), exports);
18
18
  __exportStar(require("./tokens"), exports);
19
+ __exportStar(require("./itokens"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.itokens = void 0;
4
+ exports.itokens = {
5
+ 1: [],
6
+ 137: [
7
+ {
8
+ address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
9
+ symbol: 'USDC',
10
+ }
11
+ ],
12
+ 43114: []
13
+ };
File without changes
File without changes
File without changes
@@ -12,8 +12,10 @@ Transaction.init({
12
12
  autoIncrement: true,
13
13
  primaryKey: true
14
14
  },
15
+ submitTransactionHash: sequelize_2.DataTypes.NUMBER,
16
+ submitBlockNumber: sequelize_2.DataTypes.NUMBER,
15
17
  transactionHash: sequelize_2.DataTypes.STRING,
16
- type: sequelize_2.DataTypes.STRING,
18
+ action: sequelize_2.DataTypes.STRING,
17
19
  from: sequelize_2.DataTypes.STRING,
18
20
  to: sequelize_2.DataTypes.STRING,
19
21
  sourceChainId: sequelize_2.DataTypes.NUMBER,
File without changes
@@ -9,6 +9,7 @@ module_alias_1.default.addAliases({
9
9
  "@/logger": __dirname + "/logger",
10
10
  "@/tasks": __dirname + "/tasks",
11
11
  "@/utils": __dirname + "/utils",
12
+ "@/api": __dirname + "/api",
12
13
  "@/net": __dirname + "/net",
13
14
  "@/db": __dirname + "/db",
14
15
  "@/config": __dirname + "/config",
@@ -21,6 +22,7 @@ module_alias_1.default.addAliases({
21
22
  const assert_1 = __importDefault(require("assert"));
22
23
  const dotenv_1 = __importDefault(require("dotenv"));
23
24
  const ethers_1 = require("ethers");
25
+ const package_json_1 = __importDefault(require("../package.json"));
24
26
  dotenv_1.default.config();
25
27
  const logger_1 = __importDefault(require("@/logger"));
26
28
  const logger = new logger_1.default('Process');
@@ -38,12 +40,15 @@ catch (e) {
38
40
  logger.error('Invalid private key');
39
41
  process.exit(1);
40
42
  }
43
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.8a0297a)`);
41
44
  const tasks_1 = require("@/tasks");
42
45
  const net_1 = require("@/net");
46
+ const api_1 = require("@/api");
43
47
  async function main() {
44
48
  (0, net_1.startPeer)({});
45
49
  const tasks = new tasks_1.Tasks();
46
50
  tasks.start();
51
+ (0, api_1.startApiServer)();
47
52
  }
48
53
  main()
49
54
  .then(() => {
File without changes
File without changes
@@ -82,8 +82,12 @@ const startPeer = async ({}) => {
82
82
  net_1.protocol.start({
83
83
  libp2p: node
84
84
  });
85
- node.on("peer:discovery", (peer) => logger.log(`Discovered peer ${peer}`)); // peer disc.
86
- node.connectionManager.on("peer:connect", (connection) => logger.log(`Connected to ${connection.remotePeer.toB58String()}`));
85
+ node.on("peer:discovery", (peer) => {
86
+ // logger.log(`Discovered peer ${peer}`)
87
+ }); // peer disc.
88
+ node.connectionManager.on("peer:connect", (connection) => {
89
+ // logger.log(`Connected to ${connection.remotePeer.toB58String()}`)
90
+ });
87
91
  logger.log("Peer discovery started");
88
92
  await (0, waait_1.default)(1000);
89
93
  setInterval(() => net_1.protocol.sendPeerInfo({
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.peerPool = exports.PeerPool = void 0;
7
7
  const types_1 = require("@/types");
8
8
  const config_1 = __importDefault(require("@/config"));
9
+ const logger_1 = __importDefault(require("@/logger"));
10
+ const logger = new logger_1.default('PeerPool');
9
11
  class PeerPool {
10
12
  constructor() {
11
13
  this.PEERS_CLEANUP_TIME_LIMIT = 1;
@@ -62,10 +64,14 @@ class PeerPool {
62
64
  * @emits {@link Event.POOL_PEER_ADDED}
63
65
  */
64
66
  add(peer) {
65
- if (peer && peer.id && !this.pool.get(peer.id)) {
67
+ if (peer && peer.id) {
68
+ const newPeer = !this.pool.get(peer.id);
66
69
  this.pool.set(peer.id, peer);
67
70
  peer.pooled = true;
68
- config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
71
+ if (newPeer) {
72
+ config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
73
+ logger.info(`Peer ${peer.id} with address ${peer.publicAddress} added to pool`);
74
+ }
69
75
  }
70
76
  }
71
77
  /**
@@ -78,6 +84,7 @@ class PeerPool {
78
84
  if (this.pool.delete(peer.id)) {
79
85
  peer.pooled = false;
80
86
  config_1.default.events.emit(types_1.Event.POOL_PEER_REMOVED, peer);
87
+ logger.info(`Peer ${peer.id} with address ${peer.publicAddress} removed from pool`);
81
88
  }
82
89
  }
83
90
  }
@@ -8,6 +8,8 @@ const BaseDialProtocol_1 = require("./BaseDialProtocol");
8
8
  const waait_1 = __importDefault(require("waait"));
9
9
  const config_1 = __importDefault(require("@/config"));
10
10
  const db_1 = require("@/db");
11
+ const utils_1 = require("@/utils");
12
+ const constants_1 = require("@/constants");
11
13
  class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
12
14
  constructor(libp2p) {
13
15
  super(libp2p, '/interop-x/signatures');
@@ -15,31 +17,32 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
15
17
  }
16
18
  async response(data) {
17
19
  const signer = config_1.default.wallet;
18
- let event;
20
+ let transaction;
19
21
  let maxTimeout = 20000;
20
22
  do {
21
- event = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
22
- if (!event) {
23
+ transaction = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
24
+ if (!transaction) {
23
25
  await (0, waait_1.default)(1000);
24
26
  maxTimeout -= 1000;
25
27
  }
26
- } while (!event && maxTimeout > 0);
27
- if (!event) {
28
+ } while (!transaction && maxTimeout > 0);
29
+ if (!transaction) {
28
30
  return {
29
31
  signer: signer.address,
30
32
  data: null,
31
33
  error: 'Event not found'
32
34
  };
33
35
  }
34
- // const signedData = await signGnosisSafeTx({
35
- // to: addresses[event.chainId as ChainId].multisend,
36
- // data: 'TODO',
37
- // chainId: event.chainId as ChainId,
38
- // safeTxGas: data.safeTxGas,
39
- // }, { signer });
36
+ const signedData = await (0, utils_1.signGnosisSafeTx)({
37
+ //TODO: chain id depends on event type
38
+ to: constants_1.addresses[transaction.sourceChainId].multisend,
39
+ data: (0, utils_1.buildDataForTransaction)(transaction, data.type),
40
+ chainId: transaction.sourceChainId,
41
+ safeTxGas: data.safeTxGas,
42
+ }, { signer });
40
43
  return {
41
44
  signer: signer.address,
42
- data: null, //signedData,
45
+ data: signedData
43
46
  };
44
47
  }
45
48
  }
File without changes
@@ -28,7 +28,7 @@ class BaseTask extends events_1.default {
28
28
  }
29
29
  }
30
30
  catch (err) {
31
- this.logger.error(`poll check error: ${err.message}\ntrace: ${err.stack}`);
31
+ this.logger.error(`poll check error:\n${err.message}\ntrace: ${err.stack}`);
32
32
  }
33
33
  await this.postPollHandler();
34
34
  }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseTask_1 = require("../BaseTask");
7
+ const logger_1 = __importDefault(require("@/logger"));
8
+ const ethers_1 = require("ethers");
9
+ const abi_1 = __importDefault(require("@/abi"));
10
+ const db_1 = require("@/db");
11
+ const utils_1 = require("@/utils");
12
+ const constants_1 = require("@/constants");
13
+ const config_1 = __importDefault(require("@/config"));
14
+ const sequelize_1 = require("sequelize");
15
+ const waait_1 = __importDefault(require("waait"));
16
+ const net_1 = require("@/net");
17
+ const generateGnosisTransaction = async (transactionData, safeContract) => {
18
+ console.log(transactionData);
19
+ let isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
20
+ while (isExecuted == 1) {
21
+ transactionData.safeTxGas = ethers_1.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString();
22
+ isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
23
+ }
24
+ return transactionData;
25
+ };
26
+ class ProcessDepositEvents extends BaseTask_1.BaseTask {
27
+ constructor({ chainId }) {
28
+ super({
29
+ logger: new logger_1.default("InteropXGateway::ProcessDepositEvents"),
30
+ });
31
+ this.leadNodeOnly = true;
32
+ this.chainId = chainId;
33
+ }
34
+ async pollHandler() {
35
+ var _a;
36
+ const blockNumber = await this.provider.getBlockNumber();
37
+ const transaction = await db_1.Transaction.findOne({
38
+ where: {
39
+ status: 'pending',
40
+ sourceStatus: 'success',
41
+ targetStatus: 'uninitialised',
42
+ action: 'deposit',
43
+ sourceCreatedAt: {
44
+ [sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
45
+ },
46
+ sourceBlockNumber: {
47
+ [sequelize_1.Op.lt]: blockNumber - 12,
48
+ },
49
+ sourceChainId: this.chainId,
50
+ }
51
+ });
52
+ if (!transaction) {
53
+ return;
54
+ }
55
+ transaction.targetStatus = 'pending';
56
+ await transaction.save();
57
+ // refresh event data?
58
+ const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
59
+ const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
60
+ const safeAddress = constants_1.addresses[transaction.targetChainId].gnosisSafe;
61
+ const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
62
+ const ownersThreshold = await safeContract.getThreshold();
63
+ await (0, waait_1.default)(10000);
64
+ let gnosisTx = await generateGnosisTransaction({
65
+ baseGas: "0",
66
+ data: await (0, utils_1.buildDataForTransaction)(transaction),
67
+ gasPrice: "0",
68
+ gasToken: "0x0000000000000000000000000000000000000000",
69
+ nonce: '0',
70
+ operation: "1",
71
+ refundReceiver: "0x0000000000000000000000000000000000000000",
72
+ safeAddress: safeAddress,
73
+ safeTxGas: "79668",
74
+ to: constants_1.addresses[transaction.targetChainId].multisend,
75
+ value: "0",
76
+ }, safeContract);
77
+ const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
78
+ const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
79
+ console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
80
+ const signatures = await net_1.protocol.requestSignatures({
81
+ type: 'source',
82
+ transactionHash: transaction.transactionHash,
83
+ safeTxGas: gnosisTx.safeTxGas,
84
+ safeNonce: gnosisTx.nonce
85
+ }, ownerPeerIds);
86
+ const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x');
87
+ console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
88
+ if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
89
+ await transaction.save();
90
+ transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
91
+ transaction.targetStatus = 'pending';
92
+ await transaction.save();
93
+ const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
94
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
95
+ }
96
+ const execTransactionParams = [
97
+ gnosisTx.to,
98
+ gnosisTx.value,
99
+ gnosisTx.data,
100
+ gnosisTx.operation,
101
+ gnosisTx.safeTxGas,
102
+ gnosisTx.baseGas,
103
+ gnosisTx.gasPrice,
104
+ gnosisTx.gasToken,
105
+ gnosisTx.refundReceiver,
106
+ (0, utils_1.buildSignatureBytes)(validSignatures),
107
+ ];
108
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
109
+ console.log({
110
+ execTransactionParams
111
+ });
112
+ const { data: txData } = await safeContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
113
+ console.log({
114
+ from: targetWallet.address,
115
+ gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9).toString(),
116
+ gasLimit: ethers_1.BigNumber.from(6000000).toString(),
117
+ to: safeAddress,
118
+ data: txData,
119
+ });
120
+ return;
121
+ const txSent = await targetWallet.sendTransaction({
122
+ from: targetWallet.address,
123
+ gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9),
124
+ gasLimit: ethers_1.BigNumber.from(6000000),
125
+ to: safeAddress,
126
+ data: txData,
127
+ });
128
+ const receipt = await txSent.wait();
129
+ const parsedLogs = [];
130
+ receipt.logs.forEach((log) => {
131
+ try {
132
+ parsedLogs.push(safeContract.interface.parseLog(log));
133
+ }
134
+ catch (e) { }
135
+ });
136
+ if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
137
+ console.log('ExecutionSuccess');
138
+ }
139
+ else {
140
+ console.log('ExecutionFailure');
141
+ }
142
+ }
143
+ async start() {
144
+ this.logger.info(`Starting execution watcher on interop chain`);
145
+ this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
146
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
147
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
148
+ await super.start();
149
+ }
150
+ }
151
+ exports.default = ProcessDepositEvents;
@@ -29,8 +29,8 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
29
29
  }
30
30
  const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
31
31
  const uniqueIdentifier = {
32
- type: 'desposit',
33
- sourceTransactionHash: event.transactionHash,
32
+ action: 'deposit',
33
+ submitTransactionHash: event.transactionHash,
34
34
  sourceChainId: sourceChainId.toNumber(),
35
35
  targetChainId: targetChainId.toNumber(),
36
36
  };
@@ -38,27 +38,23 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
38
38
  continue;
39
39
  }
40
40
  const tx = await event.getTransaction();
41
- await db_1.Transaction.create({
42
- transactionHash: (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier),
43
- type: 'deposit',
44
- from: tx.from,
45
- to: user,
46
- sourceChainId: sourceChainId.toNumber(),
47
- sourceTransactionHash: event.transactionHash,
48
- sourceBlockNumber: event.blockNumber,
49
- sourceStatus: "uninitialised",
50
- targetChainId: targetChainId.toNumber(),
51
- targetStatus: "uninitialised",
52
- submitEvent: {
41
+ await db_1.Transaction.create(Object.assign(Object.assign({}, uniqueIdentifier), { transactionHash: (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier), from: tx.from, to: user, submitTransactionHash: event.transactionHash, submitBlockNumber: event.blockNumber,
42
+ // submit & source are the same
43
+ sourceTransactionHash: event.transactionHash, sourceBlockNumber: event.blockNumber, sourceStatus: "success", targetStatus: "uninitialised", submitEvent: {
44
+ user,
45
+ sourceChainId: sourceChainId.toString(),
46
+ targetChainId: targetChainId.toString(),
47
+ token: token,
48
+ ammout: amount.toString(),
49
+ vnonce: vnonce.toString(),
50
+ }, sourceEvent: {
53
51
  user,
54
52
  sourceChainId: sourceChainId.toString(),
55
53
  targetChainId: targetChainId.toString(),
56
54
  token: token,
57
55
  ammout: amount.toString(),
58
56
  vnonce: vnonce.toString(),
59
- },
60
- status: "pending",
61
- });
57
+ }, status: "pending" }));
62
58
  this.logger.info(`Execution queued: ${event.transactionHash} ${event.blockNumber}`);
63
59
  }
64
60
  catch (error) {
@@ -72,7 +68,7 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
72
68
  this.logger.info(`Starting execution watcher on interop chain`);
73
69
  this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
74
70
  this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
75
- this.contract = new ethers_1.ethers.Contract(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
71
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
76
72
  await super.start();
77
73
  }
78
74
  }
@@ -4,12 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Tasks = void 0;
7
+ const ProcessDepositEvents_1 = __importDefault(require("./InteropXGateway/ProcessDepositEvents"));
7
8
  const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
8
9
  class Tasks {
9
10
  constructor() {
10
11
  this.tasks = [
11
12
  new SyncDepositEvents_1.default({
12
13
  chainId: 43114
14
+ }),
15
+ new ProcessDepositEvents_1.default({
16
+ chainId: 43114
13
17
  })
14
18
  ];
15
19
  }
File without changes
File without changes
File without changes
File without changes
File without changes