@instadapp/interop-x 0.0.0-dev.75809ae → 0.0.0-dev.7a02577

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 (86) hide show
  1. package/.env.example +2 -1
  2. package/dist/package.json +69 -0
  3. package/dist/src/abi/erc20.json +350 -0
  4. package/dist/src/abi/gnosisSafe.json +747 -0
  5. package/dist/src/abi/index.js +15 -0
  6. package/dist/src/abi/interopBridgeToken.json +286 -0
  7. package/dist/src/abi/interopXGateway.json +184 -0
  8. package/dist/src/api/index.js +33 -0
  9. package/dist/{config → src/config}/index.js +5 -1
  10. package/dist/src/constants/addresses.js +20 -0
  11. package/dist/{constants → src/constants}/index.js +2 -0
  12. package/dist/src/constants/itokens.js +13 -0
  13. package/dist/src/constants/tokens.js +107 -0
  14. package/dist/{db → src/db}/index.js +0 -0
  15. package/dist/{db → src/db}/models/index.js +1 -1
  16. package/dist/src/db/models/transaction.js +54 -0
  17. package/dist/{db → src/db}/sequelize.js +2 -1
  18. package/dist/src/index.js +68 -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 +5 -5
  22. package/dist/{net → src/net}/pool/index.js +2 -2
  23. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +1 -1
  24. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +15 -14
  25. package/dist/{net → src/net}/protocol/index.js +3 -3
  26. package/dist/{tasks → src/tasks}/BaseTask.js +2 -2
  27. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +140 -0
  28. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +75 -0
  29. package/dist/{tasks → src/tasks}/index.js +9 -1
  30. package/dist/src/typechain/Erc20.js +2 -0
  31. package/dist/src/typechain/GnosisSafe.js +2 -0
  32. package/dist/src/typechain/InteropBridgeToken.js +2 -0
  33. package/dist/src/typechain/InteropXGateway.js +2 -0
  34. package/dist/src/typechain/common.js +2 -0
  35. package/dist/src/typechain/factories/Erc20__factory.js +367 -0
  36. package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
  37. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +459 -0
  38. package/dist/src/typechain/factories/InteropXGateway__factory.js +265 -0
  39. package/dist/src/typechain/factories/index.js +14 -0
  40. package/dist/src/typechain/index.js +35 -0
  41. package/dist/{types.js → src/types.js} +0 -0
  42. package/dist/{utils → src/utils}/index.js +50 -2
  43. package/package.json +14 -4
  44. package/src/abi/erc20.json +350 -0
  45. package/src/abi/gnosisSafe.json +747 -0
  46. package/src/abi/index.ts +11 -0
  47. package/src/abi/interopBridgeToken.json +286 -0
  48. package/src/abi/interopXGateway.json +184 -0
  49. package/src/api/index.ts +33 -0
  50. package/src/config/index.ts +7 -1
  51. package/src/constants/addresses.ts +9 -2
  52. package/src/constants/index.ts +2 -0
  53. package/src/constants/itokens.ts +10 -0
  54. package/src/constants/tokens.ts +104 -0
  55. package/src/db/index.ts +1 -1
  56. package/src/db/models/index.ts +1 -1
  57. package/src/db/models/transaction.ts +96 -0
  58. package/src/db/sequelize.ts +2 -1
  59. package/src/index.ts +46 -5
  60. package/src/net/peer/index.ts +3 -3
  61. package/src/net/pool/index.ts +2 -2
  62. package/src/net/protocol/dial/BaseDialProtocol.ts +1 -1
  63. package/src/net/protocol/dial/SignatureDialProtocol.ts +18 -17
  64. package/src/net/protocol/index.ts +3 -3
  65. package/src/tasks/BaseTask.ts +2 -3
  66. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +232 -0
  67. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +126 -0
  68. package/src/tasks/index.ts +4 -1
  69. package/src/typechain/Erc20.ts +491 -0
  70. package/src/typechain/GnosisSafe.ts +1728 -0
  71. package/src/typechain/InteropBridgeToken.ts +686 -0
  72. package/src/typechain/InteropXGateway.ts +407 -0
  73. package/src/typechain/common.ts +44 -0
  74. package/src/typechain/factories/Erc20__factory.ts +368 -0
  75. package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
  76. package/src/typechain/factories/InteropBridgeToken__factory.ts +466 -0
  77. package/src/typechain/factories/InteropXGateway__factory.ts +272 -0
  78. package/src/typechain/factories/index.ts +7 -0
  79. package/src/typechain/index.ts +12 -0
  80. package/src/types.ts +2 -2
  81. package/src/utils/index.ts +72 -3
  82. package/tsconfig.json +3 -0
  83. package/dist/constants/addresses.js +0 -13
  84. package/dist/db/models/execution.js +0 -38
  85. package/dist/index.js +0 -34
  86. package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tokens = void 0;
4
+ exports.tokens = {
5
+ 1: [
6
+ {
7
+ symbol: "ETH",
8
+ name: "Ethereum",
9
+ address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
10
+ decimals: 18,
11
+ },
12
+ {
13
+ symbol: "DAI",
14
+ name: "DAI Stable",
15
+ address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
16
+ decimals: 18,
17
+ },
18
+ {
19
+ symbol: "USDC",
20
+ name: "USD Coin",
21
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
22
+ decimals: 6,
23
+ },
24
+ {
25
+ symbol: "USDT",
26
+ name: "Tether USD Coin",
27
+ address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
28
+ decimals: 6,
29
+ },
30
+ {
31
+ symbol: "WBTC",
32
+ name: "Wrapped BTC",
33
+ address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
34
+ decimals: 8,
35
+ },
36
+ ],
37
+ 137: [
38
+ {
39
+ symbol: "ETH",
40
+ name: "Ethereum",
41
+ address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
42
+ decimals: 18,
43
+ },
44
+ {
45
+ symbol: "DAI",
46
+ name: "DAI Stable",
47
+ address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
48
+ decimals: 18,
49
+ },
50
+ {
51
+ symbol: "USDC",
52
+ name: "USD Coin",
53
+ address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
54
+ decimals: 6,
55
+ },
56
+ {
57
+ symbol: "USDT",
58
+ name: "Tether USD Coin",
59
+ address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
60
+ decimals: 6,
61
+ },
62
+ {
63
+ symbol: "WBTC",
64
+ name: "Wrapped BTC",
65
+ address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
66
+ decimals: 8,
67
+ },
68
+ {
69
+ symbol: "AVAX",
70
+ name: "Avalanche Token",
71
+ address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
72
+ decimals: 18,
73
+ },
74
+ ],
75
+ 43114: [
76
+ {
77
+ symbol: "ETH",
78
+ name: "Ethereum",
79
+ address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
80
+ decimals: 18,
81
+ },
82
+ {
83
+ symbol: "DAI",
84
+ name: "DAI Stable",
85
+ address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
86
+ decimals: 18,
87
+ },
88
+ {
89
+ symbol: "USDC",
90
+ name: "USD Coin",
91
+ address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
92
+ decimals: 6,
93
+ },
94
+ {
95
+ symbol: "USDT",
96
+ name: "Tether USD Coin",
97
+ address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
98
+ decimals: 6,
99
+ },
100
+ {
101
+ symbol: "WBTC",
102
+ name: "Wrapped BTC",
103
+ address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
104
+ decimals: 8,
105
+ },
106
+ ],
107
+ };
File without changes
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./execution"), exports);
17
+ __exportStar(require("./transaction"), exports);
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Transaction = void 0;
4
+ const sequelize_1 = require("@/db/sequelize");
5
+ const sequelize_2 = require("sequelize");
6
+ class Transaction extends sequelize_2.Model {
7
+ }
8
+ exports.Transaction = Transaction;
9
+ Transaction.init({
10
+ id: {
11
+ type: sequelize_2.DataTypes.INTEGER,
12
+ autoIncrement: true,
13
+ primaryKey: true
14
+ },
15
+ submitTransactionHash: sequelize_2.DataTypes.NUMBER,
16
+ submitBlockNumber: sequelize_2.DataTypes.NUMBER,
17
+ transactionHash: sequelize_2.DataTypes.STRING,
18
+ action: sequelize_2.DataTypes.STRING,
19
+ from: sequelize_2.DataTypes.STRING,
20
+ to: sequelize_2.DataTypes.STRING,
21
+ sourceChainId: sequelize_2.DataTypes.NUMBER,
22
+ sourceTransactionHash: sequelize_2.DataTypes.STRING,
23
+ sourceBlockNumber: sequelize_2.DataTypes.NUMBER,
24
+ sourceStatus: sequelize_2.DataTypes.STRING,
25
+ sourceErrors: {
26
+ type: sequelize_2.DataTypes.JSON,
27
+ // defaultValue: [],
28
+ },
29
+ sourceCreatedAt: {
30
+ type: sequelize_2.DataTypes.DATE,
31
+ defaultValue: Date.now()
32
+ },
33
+ sourceDelayUntil: sequelize_2.DataTypes.STRING,
34
+ targetChainId: sequelize_2.DataTypes.NUMBER,
35
+ targetTransactionHash: sequelize_2.DataTypes.STRING,
36
+ targetBlockNumber: sequelize_2.DataTypes.NUMBER,
37
+ targetStatus: sequelize_2.DataTypes.STRING,
38
+ targetErrors: {
39
+ type: sequelize_2.DataTypes.JSON,
40
+ // defaultValue: [],
41
+ },
42
+ targetCreatedAt: sequelize_2.DataTypes.DATE,
43
+ targetDelayUntil: sequelize_2.DataTypes.DATE,
44
+ submitEvent: sequelize_2.DataTypes.JSON,
45
+ sourceEvent: sequelize_2.DataTypes.JSON,
46
+ targetEvent: sequelize_2.DataTypes.JSON,
47
+ metadata: sequelize_2.DataTypes.JSON,
48
+ status: {
49
+ type: sequelize_2.DataTypes.STRING,
50
+ defaultValue: 'pending'
51
+ },
52
+ createdAt: sequelize_2.DataTypes.DATE,
53
+ updatedAt: sequelize_2.DataTypes.DATE,
54
+ }, { sequelize: sequelize_1.sequelize, tableName: 'transactions' });
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.sequelize = void 0;
7
7
  //@ts-ignore
8
+ const config_1 = __importDefault(require("@/config"));
8
9
  const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
9
10
  const sequelize_1 = require("sequelize");
10
- const basePath = (0, expand_home_dir_1.default)('~/.interop-x/data');
11
+ const basePath = (0, expand_home_dir_1.default)(`~/.interop-x/data/${config_1.default.publicAddress}/${config_1.default.staging ? 'staging' : ''}`);
11
12
  exports.sequelize = new sequelize_1.Sequelize({
12
13
  dialect: 'sqlite',
13
14
  storage: `${basePath}/localDB.sqlite`,
@@ -0,0 +1,68 @@
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 module_alias_1 = __importDefault(require("module-alias"));
7
+ module_alias_1.default.addAliases({
8
+ "@/": __dirname + "/",
9
+ "@/logger": __dirname + "/logger",
10
+ "@/tasks": __dirname + "/tasks",
11
+ "@/utils": __dirname + "/utils",
12
+ "@/api": __dirname + "/api",
13
+ "@/net": __dirname + "/net",
14
+ "@/db": __dirname + "/db",
15
+ "@/config": __dirname + "/config",
16
+ "@/types": __dirname + "/types",
17
+ "@/abi": __dirname + "/abi",
18
+ "@/constants": __dirname + "/constants",
19
+ "@/typechain": __dirname + "/typechain"
20
+ });
21
+ (0, module_alias_1.default)();
22
+ const assert_1 = __importDefault(require("assert"));
23
+ const dotenv_1 = __importDefault(require("dotenv"));
24
+ const ethers_1 = require("ethers");
25
+ const package_json_1 = __importDefault(require("../package.json"));
26
+ dotenv_1.default.config();
27
+ const logger_1 = __importDefault(require("@/logger"));
28
+ const logger = new logger_1.default('Process');
29
+ if (process.argv.at(-1) === 'help') {
30
+ console.log('Usage:');
31
+ console.log(' PRIVATE_KEY=abcd1234 interop-x');
32
+ console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x');
33
+ process.exit(0);
34
+ }
35
+ (0, assert_1.default)(process.env.PRIVATE_KEY, "PRIVATE_KEY is not defined");
36
+ try {
37
+ new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
38
+ }
39
+ catch (e) {
40
+ logger.error('Invalid private key');
41
+ process.exit(1);
42
+ }
43
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.7a02577)`);
44
+ const tasks_1 = require("@/tasks");
45
+ const net_1 = require("@/net");
46
+ const api_1 = require("@/api");
47
+ async function main() {
48
+ (0, net_1.startPeer)({});
49
+ const tasks = new tasks_1.Tasks();
50
+ tasks.start();
51
+ (0, api_1.startApiServer)();
52
+ }
53
+ main()
54
+ .then(() => {
55
+ }).catch(err => {
56
+ console.error(err);
57
+ });
58
+ process.on('SIGINT', () => {
59
+ logger.debug('received SIGINT signal. exiting.');
60
+ process.exit(0);
61
+ });
62
+ process.on('SIGTERM', () => {
63
+ logger.debug('received SIGTERM signal. exiting.');
64
+ process.exit(0);
65
+ });
66
+ process.on('unhandledRejection', (reason, p) => {
67
+ logger.error('unhandled rejection: promise:', p, 'reason:', reason);
68
+ });
File without changes
File without changes
@@ -11,7 +11,7 @@ const libp2p_websockets_1 = __importDefault(require("libp2p-websockets"));
11
11
  //@ts-ignore
12
12
  const libp2p_mplex_1 = __importDefault(require("libp2p-mplex"));
13
13
  const libp2p_noise_1 = require("libp2p-noise");
14
- const logger_1 = __importDefault(require("../../logger"));
14
+ const logger_1 = __importDefault(require("@/logger"));
15
15
  const libp2p_bootstrap_1 = __importDefault(require("libp2p-bootstrap"));
16
16
  const waait_1 = __importDefault(require("waait"));
17
17
  const libp2p_gossipsub_1 = __importDefault(require("@achingbrain/libp2p-gossipsub"));
@@ -21,8 +21,8 @@ const libp2p_mdns_1 = __importDefault(require("libp2p-mdns"));
21
21
  const libp2p_kad_dht_1 = __importDefault(require("libp2p-kad-dht"));
22
22
  //@ts-ignore
23
23
  const libp2p_pubsub_peer_discovery_1 = __importDefault(require("libp2p-pubsub-peer-discovery"));
24
- const protocol_1 = require("../protocol");
25
- const config_1 = __importDefault(require("../../config"));
24
+ const net_1 = require("@/net");
25
+ const config_1 = __importDefault(require("@/config"));
26
26
  const logger = new logger_1.default("Peer");
27
27
  let node;
28
28
  // Known peers addresses
@@ -79,14 +79,14 @@ const startPeer = async ({}) => {
79
79
  });
80
80
  logger.info("Peer ID:", node.peerId.toB58String());
81
81
  await node.start();
82
- protocol_1.protocol.start({
82
+ net_1.protocol.start({
83
83
  libp2p: node
84
84
  });
85
85
  node.on("peer:discovery", (peer) => logger.log(`Discovered peer ${peer}`)); // peer disc.
86
86
  node.connectionManager.on("peer:connect", (connection) => logger.log(`Connected to ${connection.remotePeer.toB58String()}`));
87
87
  logger.log("Peer discovery started");
88
88
  await (0, waait_1.default)(1000);
89
- setInterval(() => protocol_1.protocol.sendPeerInfo({
89
+ setInterval(() => net_1.protocol.sendPeerInfo({
90
90
  publicAddress: config_1.default.wallet.address,
91
91
  }), 5000);
92
92
  };
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.peerPool = exports.PeerPool = void 0;
7
- const types_1 = require("../../types");
8
- const config_1 = __importDefault(require("../../config"));
7
+ const types_1 = require("@/types");
8
+ const config_1 = __importDefault(require("@/config"));
9
9
  class PeerPool {
10
10
  constructor() {
11
11
  this.PEERS_CLEANUP_TIME_LIMIT = 1;
@@ -13,7 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.BaseDialProtocol = void 0;
14
14
  const it_pipe_1 = __importDefault(require("it-pipe"));
15
15
  const peer_id_1 = __importDefault(require("peer-id"));
16
- const utils_1 = require("../../../utils");
16
+ const utils_1 = require("@/utils");
17
17
  const waait_1 = __importDefault(require("waait"));
18
18
  class BaseDialProtocol {
19
19
  constructor(libp2p, protocol) {
@@ -4,29 +4,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SignatureDialProtocol = void 0;
7
- const utils_1 = require("../../../utils");
8
7
  const BaseDialProtocol_1 = require("./BaseDialProtocol");
9
8
  const waait_1 = __importDefault(require("waait"));
10
- const config_1 = __importDefault(require("config"));
11
- const constants_1 = require("../../../constants");
12
- const db_1 = require("db");
9
+ const config_1 = __importDefault(require("@/config"));
10
+ const db_1 = require("@/db");
11
+ const utils_1 = require("@/utils");
12
+ const constants_1 = require("@/constants");
13
13
  class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
14
14
  constructor(libp2p) {
15
- super(libp2p, '/signatures');
15
+ super(libp2p, '/interop-x/signatures');
16
16
  this.timeout = 30000;
17
17
  }
18
18
  async response(data) {
19
19
  const signer = config_1.default.wallet;
20
- let event;
20
+ let transaction;
21
21
  let maxTimeout = 20000;
22
22
  do {
23
- event = await db_1.Execution.findOne({ where: { vnonce: data.vnonce.toString() } });
24
- if (!event) {
23
+ transaction = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
24
+ if (!transaction) {
25
25
  await (0, waait_1.default)(1000);
26
26
  maxTimeout -= 1000;
27
27
  }
28
- } while (!event && maxTimeout > 0);
29
- if (!event) {
28
+ } while (!transaction && maxTimeout > 0);
29
+ if (!transaction) {
30
30
  return {
31
31
  signer: signer.address,
32
32
  data: null,
@@ -34,14 +34,15 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
34
34
  };
35
35
  }
36
36
  const signedData = await (0, utils_1.signGnosisSafeTx)({
37
- to: constants_1.addresses[event.chainId].multisend,
38
- data: 'TODO',
39
- chainId: event.chainId,
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,
40
41
  safeTxGas: data.safeTxGas,
41
42
  }, { signer });
42
43
  return {
43
44
  signer: signer.address,
44
- data: signedData,
45
+ data: signedData
45
46
  };
46
47
  }
47
48
  }
@@ -8,8 +8,8 @@ const stream_1 = require("stream");
8
8
  const ethereumjs_util_1 = require("ethereumjs-util");
9
9
  const SignatureDialProtocol_1 = require("./dial/SignatureDialProtocol");
10
10
  const __1 = require("..");
11
- const config_1 = __importDefault(require("config"));
12
- const types_1 = require("types");
11
+ const config_1 = __importDefault(require("@/config"));
12
+ const types_1 = require("@/types");
13
13
  class Protocol extends stream_1.EventEmitter {
14
14
  constructor() {
15
15
  super(...arguments);
@@ -28,7 +28,7 @@ class Protocol extends stream_1.EventEmitter {
28
28
  }
29
29
  start({ libp2p, topic = null, }) {
30
30
  this.libp2p = libp2p;
31
- this.topic = topic || 'protocol';
31
+ this.topic = topic || 'itnerop-x-protocol';
32
32
  if (this.libp2p.isStarted())
33
33
  this.init();
34
34
  this.on('PeerInfo', (payload) => {
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BaseTask = void 0;
7
- const config_1 = __importDefault(require("config"));
7
+ const config_1 = __importDefault(require("@/config"));
8
8
  const events_1 = __importDefault(require("events"));
9
9
  const waait_1 = __importDefault(require("waait"));
10
- const logger_1 = __importDefault(require("../logger"));
10
+ const logger_1 = __importDefault(require("@/logger"));
11
11
  class BaseTask extends events_1.default {
12
12
  constructor({ logger }) {
13
13
  super();
@@ -0,0 +1,140 @@
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
+ 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));
19
+ while (isExecuted == 1) {
20
+ transactionData.safeTxGas = ethers_1.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString();
21
+ 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));
22
+ }
23
+ return transactionData;
24
+ };
25
+ class ProcessDepositEvents extends BaseTask_1.BaseTask {
26
+ constructor({ chainId }) {
27
+ super({
28
+ logger: new logger_1.default("InteropXGateway::ProcessDepositEvents"),
29
+ });
30
+ this.leadNodeOnly = true;
31
+ this.chainId = chainId;
32
+ }
33
+ async pollHandler() {
34
+ var _a;
35
+ const blockNumber = await this.provider.getBlockNumber();
36
+ const transaction = await db_1.Transaction.findOne({
37
+ where: {
38
+ status: 'pending',
39
+ sourceStatus: 'success',
40
+ action: 'deposit',
41
+ sourceCreatedAt: {
42
+ [sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
43
+ },
44
+ sourceBlockNumber: {
45
+ [sequelize_1.Op.lt]: blockNumber - 12,
46
+ }
47
+ }
48
+ });
49
+ if (!transaction) {
50
+ return;
51
+ }
52
+ transaction.sourceStatus = 'pending';
53
+ await transaction.save();
54
+ // refresh event data?
55
+ const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
56
+ const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
57
+ const safeAddress = constants_1.addresses[transaction.targetChainId].gnosisSafe;
58
+ const safeContract = new ethers_1.ethers.Contract(safeAddress, abi_1.default.gnosisSafe, targetWallet);
59
+ const ownersThreshold = await safeContract.getThreshold();
60
+ await (0, waait_1.default)(10000);
61
+ let gnosisTx = await generateGnosisTransaction({
62
+ baseGas: "0",
63
+ data: (0, utils_1.buildDataForTransaction)(transaction),
64
+ gasPrice: "0",
65
+ gasToken: "0x0000000000000000000000000000000000000000",
66
+ nonce: '0',
67
+ operation: "1",
68
+ refundReceiver: "0x0000000000000000000000000000000000000000",
69
+ safeAddress: safeAddress,
70
+ safeTxGas: "79668",
71
+ to: constants_1.addresses[transaction.targetChainId].multisend,
72
+ value: "0",
73
+ }, safeContract);
74
+ const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
75
+ const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
76
+ console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
77
+ const signatures = await net_1.protocol.requestSignatures({
78
+ type: 'source',
79
+ transactionHash: transaction.transactionHash,
80
+ safeTxGas: gnosisTx.safeTxGas,
81
+ safeNonce: gnosisTx.nonce
82
+ }, ownerPeerIds);
83
+ const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x');
84
+ console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
85
+ if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
86
+ await transaction.save();
87
+ transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
88
+ transaction.sourceStatus = 'pending';
89
+ await transaction.save();
90
+ const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
91
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
92
+ }
93
+ const execTransactionParams = [
94
+ gnosisTx.to,
95
+ gnosisTx.value,
96
+ gnosisTx.data,
97
+ gnosisTx.operation,
98
+ gnosisTx.safeTxGas,
99
+ gnosisTx.baseGas,
100
+ gnosisTx.gasPrice,
101
+ gnosisTx.gasToken,
102
+ gnosisTx.refundReceiver,
103
+ (0, utils_1.buildSignatureBytes)(validSignatures),
104
+ ];
105
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
106
+ console.log({
107
+ execTransactionParams
108
+ });
109
+ 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));
110
+ const txSent = await targetWallet.sendTransaction({
111
+ from: targetWallet.address,
112
+ gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9),
113
+ gasLimit: ethers_1.BigNumber.from(6000000),
114
+ to: safeAddress,
115
+ data: txData,
116
+ });
117
+ const receipt = await txSent.wait();
118
+ const parsedLogs = [];
119
+ receipt.logs.forEach((log) => {
120
+ try {
121
+ parsedLogs.push(safeContract.interface.parseLog(log));
122
+ }
123
+ catch (e) { }
124
+ });
125
+ if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
126
+ console.log('ExecutionSuccess');
127
+ }
128
+ else {
129
+ console.log('ExecutionFailure');
130
+ }
131
+ }
132
+ async start() {
133
+ this.logger.info(`Starting execution watcher on interop chain`);
134
+ this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
135
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
136
+ this.contract = new ethers_1.ethers.Contract(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
137
+ await super.start();
138
+ }
139
+ }
140
+ exports.default = ProcessDepositEvents;
@@ -0,0 +1,75 @@
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
+ class SyncDepositEvents extends BaseTask_1.BaseTask {
15
+ constructor({ chainId }) {
16
+ super({
17
+ logger: new logger_1.default("InteropXGateway::SyncDepositEvents"),
18
+ });
19
+ this.chainId = chainId;
20
+ }
21
+ async pollHandler() {
22
+ const currentBlock = await this.provider.getBlockNumber();
23
+ const events = await this.contract.queryFilter(this.contract.filters.LogGatewayDeposit(), currentBlock - 2000, currentBlock);
24
+ let processedEvents = 0;
25
+ for (const event of events) {
26
+ try {
27
+ if (!event.args) {
28
+ continue;
29
+ }
30
+ const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
31
+ const uniqueIdentifier = {
32
+ action: 'deposit',
33
+ submitTransactionHash: event.transactionHash,
34
+ sourceChainId: sourceChainId.toNumber(),
35
+ targetChainId: targetChainId.toNumber(),
36
+ };
37
+ if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
38
+ continue;
39
+ }
40
+ const tx = await event.getTransaction();
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: {
51
+ user,
52
+ sourceChainId: sourceChainId.toString(),
53
+ targetChainId: targetChainId.toString(),
54
+ token: token,
55
+ ammout: amount.toString(),
56
+ vnonce: vnonce.toString(),
57
+ }, status: "pending" }));
58
+ this.logger.info(`Execution queued: ${event.transactionHash} ${event.blockNumber}`);
59
+ }
60
+ catch (error) {
61
+ this.logger.error(error);
62
+ }
63
+ }
64
+ if (processedEvents > 0)
65
+ this.logger.info(`${processedEvents} events processed`);
66
+ }
67
+ async start() {
68
+ this.logger.info(`Starting execution watcher on interop chain`);
69
+ this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
70
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
71
+ this.contract = new ethers_1.ethers.Contract(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
72
+ await super.start();
73
+ }
74
+ }
75
+ exports.default = SyncDepositEvents;
@@ -1,9 +1,17 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Tasks = void 0;
7
+ const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
4
8
  class Tasks {
5
9
  constructor() {
6
- this.tasks = [];
10
+ this.tasks = [
11
+ new SyncDepositEvents_1.default({
12
+ chainId: 43114
13
+ })
14
+ ];
7
15
  }
8
16
  async start() {
9
17
  for (const task of this.tasks) {
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });