@instadapp/interop-x 0.0.0-dev.92afe89 → 0.0.0-dev.99c6cb0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. package/.env.example +2 -1
  2. package/dist/package.json +74 -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 +13 -0
  6. package/dist/src/abi/interopXContract.json +454 -0
  7. package/dist/src/alias.js +10 -0
  8. package/dist/src/api/index.js +36 -0
  9. package/dist/src/config/index.js +31 -0
  10. package/dist/src/constants/addresses.js +20 -0
  11. package/dist/{constants → src/constants}/index.js +1 -0
  12. package/dist/src/constants/tokens.js +137 -0
  13. package/dist/{db → src/db}/index.js +0 -0
  14. package/dist/{db → src/db}/models/index.js +1 -1
  15. package/dist/src/db/models/transaction.js +70 -0
  16. package/dist/{db → src/db}/sequelize.js +2 -1
  17. package/dist/src/gnosis/actions/index.js +9 -0
  18. package/dist/src/gnosis/actions/withdraw/index.js +55 -0
  19. package/dist/src/gnosis/index.js +20 -0
  20. package/dist/src/index.js +119 -0
  21. package/dist/{logger → src/logger}/index.js +0 -0
  22. package/dist/{net → src/net}/index.js +0 -0
  23. package/dist/{net → src/net}/peer/index.js +13 -8
  24. package/dist/{net → src/net}/pool/index.js +34 -11
  25. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +1 -1
  26. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +21 -14
  27. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  28. package/dist/{net → src/net}/protocol/index.js +54 -4
  29. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  30. package/dist/{tasks → src/tasks}/BaseTask.js +14 -6
  31. package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +152 -0
  32. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  33. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
  34. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  35. package/dist/src/tasks/index.js +38 -0
  36. package/dist/src/typechain/Erc20.js +2 -0
  37. package/dist/src/typechain/GnosisSafe.js +2 -0
  38. package/dist/src/typechain/InteropXContract.js +2 -0
  39. package/dist/src/typechain/common.js +2 -0
  40. package/dist/src/typechain/factories/Erc20__factory.js +367 -0
  41. package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
  42. package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
  43. package/dist/src/typechain/factories/index.js +12 -0
  44. package/dist/src/typechain/index.js +33 -0
  45. package/dist/{types.js → src/types.js} +0 -0
  46. package/dist/src/utils/index.js +186 -0
  47. package/package.json +30 -15
  48. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  49. package/src/abi/erc20.json +350 -0
  50. package/src/abi/gnosisSafe.json +747 -0
  51. package/src/abi/index.ts +9 -0
  52. package/src/abi/interopXContract.json +454 -0
  53. package/src/alias.ts +6 -0
  54. package/src/api/index.ts +36 -0
  55. package/src/config/index.ts +18 -2
  56. package/src/constants/addresses.ts +10 -3
  57. package/src/constants/index.ts +1 -0
  58. package/src/constants/tokens.ts +134 -0
  59. package/src/db/index.ts +1 -1
  60. package/src/db/models/index.ts +1 -1
  61. package/src/db/models/transaction.ts +137 -0
  62. package/src/db/sequelize.ts +2 -1
  63. package/src/gnosis/actions/index.ts +5 -0
  64. package/src/gnosis/actions/withdraw/index.ts +77 -0
  65. package/src/gnosis/index.ts +19 -0
  66. package/src/index.ts +118 -7
  67. package/src/net/peer/index.ts +12 -10
  68. package/src/net/pool/index.ts +43 -13
  69. package/src/net/protocol/dial/BaseDialProtocol.ts +1 -1
  70. package/src/net/protocol/dial/SignatureDialProtocol.ts +24 -17
  71. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  72. package/src/net/protocol/index.ts +70 -4
  73. package/src/tasks/AutoUpdateTask.ts +82 -0
  74. package/src/tasks/BaseTask.ts +16 -7
  75. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +216 -0
  76. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
  77. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
  78. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  79. package/src/tasks/index.ts +24 -2
  80. package/src/typechain/Erc20.ts +491 -0
  81. package/src/typechain/GnosisSafe.ts +1728 -0
  82. package/src/typechain/InteropXContract.ts +680 -0
  83. package/src/typechain/common.ts +44 -0
  84. package/src/typechain/factories/Erc20__factory.ts +368 -0
  85. package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
  86. package/src/typechain/factories/InteropXContract__factory.ts +642 -0
  87. package/src/typechain/factories/index.ts +6 -0
  88. package/src/typechain/index.ts +10 -0
  89. package/src/types.ts +2 -2
  90. package/src/utils/index.ts +156 -4
  91. package/tsconfig.json +8 -0
  92. package/dist/config/index.js +0 -17
  93. package/dist/constants/addresses.js +0 -13
  94. package/dist/db/models/execution.js +0 -38
  95. package/dist/index.js +0 -34
  96. package/dist/tasks/index.js +0 -19
  97. package/dist/utils/index.js +0 -89
  98. package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tokens = void 0;
4
+ exports.tokens = {
5
+ 1: [
6
+ {
7
+ aliases: ['eth'],
8
+ symbol: "ETH",
9
+ name: "Ethereum",
10
+ address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
11
+ decimals: 18,
12
+ },
13
+ {
14
+ aliases: ['weth'],
15
+ symbol: "WETH",
16
+ name: "Wrapped Ethereum",
17
+ address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
18
+ decimals: 18,
19
+ },
20
+ {
21
+ aliases: ['dai'],
22
+ symbol: "DAI",
23
+ name: "DAI Stable",
24
+ address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
25
+ decimals: 18,
26
+ },
27
+ {
28
+ aliases: ['usdc'],
29
+ symbol: "USDC",
30
+ name: "USD Coin",
31
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
32
+ decimals: 6,
33
+ },
34
+ {
35
+ aliases: ['usdt'],
36
+ symbol: "USDT",
37
+ name: "Tether USD Coin",
38
+ address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
39
+ decimals: 6,
40
+ },
41
+ {
42
+ aliases: ['wbtc'],
43
+ symbol: "WBTC",
44
+ name: "Wrapped BTC",
45
+ address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
46
+ decimals: 8,
47
+ },
48
+ ],
49
+ 137: [
50
+ {
51
+ aliases: ['eth', 'weth'],
52
+ symbol: "ETH",
53
+ name: "Ethereum",
54
+ address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
55
+ decimals: 18,
56
+ },
57
+ {
58
+ aliases: ['dai'],
59
+ symbol: "DAI",
60
+ name: "DAI Stable",
61
+ address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
62
+ decimals: 18,
63
+ },
64
+ {
65
+ aliases: ['usdc'],
66
+ symbol: "USDC",
67
+ name: "USD Coin",
68
+ address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
69
+ decimals: 6,
70
+ },
71
+ {
72
+ aliases: ['usdt'],
73
+ symbol: "USDT",
74
+ name: "Tether USD Coin",
75
+ address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
76
+ decimals: 6,
77
+ },
78
+ {
79
+ aliases: ['wbtc'],
80
+ symbol: "WBTC",
81
+ name: "Wrapped BTC",
82
+ address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
83
+ decimals: 8,
84
+ },
85
+ {
86
+ aliases: ['avax'],
87
+ symbol: "AVAX",
88
+ name: "Avalanche Token",
89
+ address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
90
+ decimals: 18,
91
+ },
92
+ ],
93
+ 43114: [
94
+ {
95
+ aliases: ['eth', 'weth'],
96
+ symbol: "ETH",
97
+ name: "Ethereum",
98
+ address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
99
+ decimals: 18,
100
+ },
101
+ {
102
+ aliases: ['dai'],
103
+ symbol: "DAI",
104
+ name: "DAI Stable",
105
+ address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
106
+ decimals: 18,
107
+ },
108
+ {
109
+ aliases: ['usdc'],
110
+ symbol: "USDC",
111
+ name: "USD Coin",
112
+ address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
113
+ decimals: 6,
114
+ },
115
+ {
116
+ aliases: ['usdt'],
117
+ symbol: "USDt",
118
+ name: "Tether USD Coin",
119
+ address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
120
+ decimals: 6,
121
+ },
122
+ {
123
+ aliases: ['usdt'],
124
+ symbol: "USDT.e",
125
+ name: "Tether USD",
126
+ address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
127
+ decimals: 6,
128
+ },
129
+ {
130
+ aliases: ["wbtc"],
131
+ symbol: "WBTC",
132
+ name: "Wrapped BTC",
133
+ address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
134
+ decimals: 8,
135
+ },
136
+ ],
137
+ };
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,70 @@
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
+ requestTransactionHash: sequelize_2.DataTypes.NUMBER,
16
+ requestBlockNumber: sequelize_2.DataTypes.NUMBER,
17
+ transactionHash: sequelize_2.DataTypes.STRING,
18
+ actionId: sequelize_2.DataTypes.STRING,
19
+ bridger: sequelize_2.DataTypes.STRING,
20
+ sourceChainId: sequelize_2.DataTypes.NUMBER,
21
+ sourceTransactionHash: sequelize_2.DataTypes.STRING,
22
+ sourceBlockNumber: sequelize_2.DataTypes.NUMBER,
23
+ sourceStatus: {
24
+ type: sequelize_2.DataTypes.STRING,
25
+ defaultValue: 'uninitialised'
26
+ },
27
+ sourceErrors: {
28
+ type: sequelize_2.DataTypes.JSON,
29
+ // defaultValue: [],
30
+ },
31
+ sourceLogs: {
32
+ type: sequelize_2.DataTypes.JSON,
33
+ // defaultValue: [],
34
+ },
35
+ sourceCreatedAt: {
36
+ type: sequelize_2.DataTypes.DATE,
37
+ defaultValue: Date.now()
38
+ },
39
+ sourceDelayUntil: sequelize_2.DataTypes.STRING,
40
+ targetChainId: sequelize_2.DataTypes.NUMBER,
41
+ targetTransactionHash: sequelize_2.DataTypes.STRING,
42
+ targetBlockNumber: sequelize_2.DataTypes.NUMBER,
43
+ targetStatus: {
44
+ type: sequelize_2.DataTypes.STRING,
45
+ defaultValue: 'uninitialised'
46
+ },
47
+ targetErrors: {
48
+ type: sequelize_2.DataTypes.JSON,
49
+ // defaultValue: [],
50
+ },
51
+ targetLogs: {
52
+ type: sequelize_2.DataTypes.JSON,
53
+ // defaultValue: [],
54
+ },
55
+ targetCreatedAt: sequelize_2.DataTypes.DATE,
56
+ targetDelayUntil: sequelize_2.DataTypes.DATE,
57
+ requestEvent: {
58
+ type: sequelize_2.DataTypes.JSON,
59
+ allowNull: false
60
+ },
61
+ requestSentEvent: sequelize_2.DataTypes.JSON,
62
+ committedEvent: sequelize_2.DataTypes.JSON,
63
+ completedEvent: sequelize_2.DataTypes.JSON,
64
+ status: {
65
+ type: sequelize_2.DataTypes.STRING,
66
+ defaultValue: 'pending'
67
+ },
68
+ createdAt: sequelize_2.DataTypes.DATE,
69
+ updatedAt: sequelize_2.DataTypes.DATE,
70
+ }, { 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,9 @@
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 withdraw_1 = __importDefault(require("./withdraw"));
7
+ exports.default = {
8
+ withdraw: withdraw_1.default,
9
+ };
@@ -0,0 +1,55 @@
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 abi_1 = __importDefault(require("@/abi"));
7
+ const config_1 = __importDefault(require("@/config"));
8
+ const constants_1 = require("@/constants");
9
+ const utils_1 = require("@/utils");
10
+ const ethers_1 = require("ethers");
11
+ const ethers_multisend_1 = require("ethers-multisend");
12
+ async function default_1(transaction, type) {
13
+ const transactions = [];
14
+ const logs = [];
15
+ if (transaction.actionId !== 'withdraw') {
16
+ throw new Error(`Invalid action: ${transaction.actionId}`);
17
+ }
18
+ if (type !== 'source') {
19
+ throw new Error(`[WIP] Type not supported: ${type}`);
20
+ }
21
+ if (transaction.sourceStatus === 'pending') {
22
+ throw Error('Source transaction already processesing');
23
+ }
24
+ if (transaction.sourceStatus === 'pending') {
25
+ throw Error('Source transaction already processed');
26
+ }
27
+ if (!transaction.requestEvent) {
28
+ throw Error('Something went wrong, source transaction has no request event');
29
+ }
30
+ const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = transaction.requestEvent;
31
+ const sourceChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
32
+ const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
33
+ const contractAddress = constants_1.addresses[sourceChainId].interopXContract;
34
+ const contract = (0, utils_1.getContract)(contractAddress, abi_1.default.interopXContract, sourceWallet);
35
+ const sourceToken = constants_1.tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
36
+ if (!sourceToken) {
37
+ throw Error('Source token not found');
38
+ }
39
+ const targetToken = constants_1.tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
40
+ if (!targetToken) {
41
+ throw Error('Target token not found');
42
+ }
43
+ if (sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
44
+ throw Error('Source and target token must be the same');
45
+ }
46
+ const { data } = await contract.populateTransaction.withdrawRequested(actionId, bridger, position.withdraw[0].sourceToken, position.withdraw[0].targetToken, position.withdraw[0].amount, targetChainId, transaction.requestTransactionHash, metadata);
47
+ transactions.push({
48
+ to: contractAddress,
49
+ data: data,
50
+ value: '0',
51
+ operation: ethers_multisend_1.OperationType.Call,
52
+ });
53
+ return { transactions, logs };
54
+ }
55
+ exports.default = default_1;
@@ -0,0 +1,20 @@
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.buildGnosisAction = void 0;
7
+ const ethers_multisend_1 = require("ethers-multisend");
8
+ const actions_1 = __importDefault(require("./actions"));
9
+ const buildGnosisAction = async (transaction, type) => {
10
+ // type = type || (transaction.sourceStatus === 'success' ? 'target' : 'source')
11
+ if (actions_1.default.hasOwnProperty(transaction.actionId)) {
12
+ const { transactions, logs } = await actions_1.default[transaction.actionId](transaction, type);
13
+ return {
14
+ data: (0, ethers_multisend_1.encodeMulti)(transactions).data,
15
+ logs
16
+ };
17
+ }
18
+ throw new Error(`Unknown action: ${transaction.actionId}`);
19
+ };
20
+ exports.buildGnosisAction = buildGnosisAction;
@@ -0,0 +1,119 @@
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
+ require("./alias");
7
+ const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const dotenv_1 = __importDefault(require("dotenv"));
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ const ethers_1 = require("ethers");
12
+ const package_json_1 = __importDefault(require("../package.json"));
13
+ dotenv_1.default.config();
14
+ const logger_1 = __importDefault(require("@/logger"));
15
+ const logger = new logger_1.default('Process');
16
+ const GIT_SHORT_HASH = '99c6cb0';
17
+ const printUsage = () => {
18
+ console.log();
19
+ console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
20
+ console.log();
21
+ console.log('Usage:');
22
+ console.log(' interop-x help Show this message');
23
+ console.log(' interop-x version Print out the installed version of Interop X');
24
+ console.log();
25
+ console.log(' interop-x down Put the node into maintenance mode');
26
+ console.log(' interop-x up Take the node out of maintenance mode');
27
+ console.log();
28
+ console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key');
29
+ console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode');
30
+ console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode');
31
+ console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x Start the node with custom API host and port');
32
+ console.log();
33
+ };
34
+ if (process.argv.at(-1) === 'help') {
35
+ printUsage();
36
+ process.exit(0);
37
+ }
38
+ const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
39
+ if (process.argv.at(-1) === 'down') {
40
+ fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
41
+ console.log(chalk_1.default.red('Maintenance mode enabled'));
42
+ process.exit(0);
43
+ }
44
+ if (process.argv.at(-1) === 'up') {
45
+ fs_extra_1.default.removeSync(basePath + '/maintenance');
46
+ console.log(chalk_1.default.green('Maintenance mode disabled'));
47
+ process.exit(0);
48
+ }
49
+ if (process.argv.at(-1) === 'version') {
50
+ console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
51
+ process.exit(0);
52
+ }
53
+ if (!process.env.PRIVATE_KEY) {
54
+ console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
55
+ printUsage();
56
+ process.exit(1);
57
+ }
58
+ try {
59
+ new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
60
+ }
61
+ catch (e) {
62
+ console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
63
+ printUsage();
64
+ process.exit(1);
65
+ }
66
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
67
+ const tasks_1 = require("@/tasks");
68
+ const net_1 = require("@/net");
69
+ const api_1 = require("@/api");
70
+ const db_1 = require("./db");
71
+ const utils_1 = require("./utils");
72
+ async function main() {
73
+ (0, net_1.startPeer)({});
74
+ const tasks = new tasks_1.Tasks();
75
+ setTimeout(() => {
76
+ tasks.start();
77
+ }, 10000);
78
+ (0, api_1.startApiServer)();
79
+ net_1.protocol.on('TransactionStatus', async (payload) => {
80
+ if (!net_1.peerPool.isLeadNode(payload.peerId)) {
81
+ const peer = net_1.peerPool.getPeer(payload.peerId);
82
+ if (!peer) {
83
+ return;
84
+ }
85
+ logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
86
+ return;
87
+ }
88
+ const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
89
+ if (!transaction) {
90
+ return;
91
+ }
92
+ transaction.sourceStatus = payload.data.sourceStatus;
93
+ transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
94
+ transaction.sourceErrors = payload.data.sourceErrors;
95
+ transaction.sourceLogs = payload.data.sourceLogs;
96
+ transaction.targetStatus = payload.data.targetStatus;
97
+ transaction.targetTransactionHash = payload.data.targetTransactionHash;
98
+ transaction.targetErrors = payload.data.targetErrors;
99
+ transaction.targetLogs = payload.data.targetLogs;
100
+ transaction.status = payload.data.status;
101
+ await transaction.save();
102
+ });
103
+ }
104
+ main()
105
+ .then(() => {
106
+ }).catch(err => {
107
+ console.error(err);
108
+ });
109
+ process.on('SIGINT', () => {
110
+ logger.debug('received SIGINT signal. exiting.');
111
+ process.exit(0);
112
+ });
113
+ process.on('SIGTERM', () => {
114
+ logger.debug('received SIGTERM signal. exiting.');
115
+ process.exit(0);
116
+ });
117
+ process.on('unhandledRejection', (reason, p) => {
118
+ logger.error('unhandled rejection: promise:', p, 'reason:', reason);
119
+ });
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,9 @@ 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
+ const chalk_1 = __importDefault(require("chalk"));
26
27
  const logger = new logger_1.default("Peer");
27
28
  let node;
28
29
  // Known peers addresses
@@ -77,16 +78,20 @@ const startPeer = async ({}) => {
77
78
  persistence: true,
78
79
  },
79
80
  });
80
- logger.info("Peer ID:", node.peerId.toB58String());
81
+ logger.info("Peer ID:", chalk_1.default.bold(node.peerId.toB58String()));
81
82
  await node.start();
82
- protocol_1.protocol.start({
83
+ net_1.protocol.start({
83
84
  libp2p: node
84
85
  });
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()}`));
86
+ node.on("peer:discovery", (peer) => {
87
+ // logger.log(`Discovered peer ${peer}`)
88
+ }); // peer disc.
89
+ node.connectionManager.on("peer:connect", (connection) => {
90
+ // logger.log(`Connected to ${connection.remotePeer.toB58String()}`)
91
+ });
87
92
  logger.log("Peer discovery started");
88
93
  await (0, waait_1.default)(1000);
89
- setInterval(() => protocol_1.protocol.sendPeerInfo({
94
+ setInterval(() => net_1.protocol.sendPeerInfo({
90
95
  publicAddress: config_1.default.wallet.address,
91
96
  }), 5000);
92
97
  };
@@ -4,8 +4,13 @@ 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
+ const logger_1 = __importDefault(require("@/logger"));
10
+ const utils_1 = require("ethers/lib/utils");
11
+ const utils_2 = require("@/utils");
12
+ const chalk_1 = __importDefault(require("chalk"));
13
+ const logger = new logger_1.default('PeerPool');
9
14
  class PeerPool {
10
15
  constructor() {
11
16
  this.PEERS_CLEANUP_TIME_LIMIT = 1;
@@ -62,10 +67,14 @@ class PeerPool {
62
67
  * @emits {@link Event.POOL_PEER_ADDED}
63
68
  */
64
69
  add(peer) {
65
- if (peer && peer.id && !this.pool.get(peer.id)) {
70
+ if (peer && peer.id) {
71
+ const newPeer = !this.pool.get(peer.id);
66
72
  this.pool.set(peer.id, peer);
67
73
  peer.pooled = true;
68
- config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
74
+ if (newPeer) {
75
+ config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
76
+ logger.info(`Peer ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.id, 16))} with address ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.publicAddress))} added to pool`);
77
+ }
69
78
  }
70
79
  }
71
80
  /**
@@ -78,6 +87,7 @@ class PeerPool {
78
87
  if (this.pool.delete(peer.id)) {
79
88
  peer.pooled = false;
80
89
  config_1.default.events.emit(types_1.Event.POOL_PEER_REMOVED, peer);
90
+ logger.info(`Peer ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.id, 16))} with address ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.publicAddress))} removed from pool`);
81
91
  }
82
92
  }
83
93
  }
@@ -93,14 +103,27 @@ class PeerPool {
93
103
  get activePeerIds() {
94
104
  return this.activePeers.map((p) => p.id);
95
105
  }
106
+ getPeer(id) {
107
+ return this.pool.get(id);
108
+ }
109
+ isLeadNode(id) {
110
+ const peer = this.pool.get(id);
111
+ if (!peer) {
112
+ return false;
113
+ }
114
+ return (0, utils_1.getAddress)(peer.publicAddress) === (0, utils_1.getAddress)(config_1.default.leadNodeAddress);
115
+ }
116
+ getLeadPeer() {
117
+ return this.peers.find((p) => this.isLeadNode(p.id));
118
+ }
96
119
  cleanup() {
97
- let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60;
98
- this.peers.forEach((peerInfo) => {
99
- if (peerInfo.updated.getTime() < compDate) {
100
- console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`);
101
- this.remove(peerInfo);
102
- }
103
- });
120
+ // let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
121
+ // this.peers.forEach((peerInfo) => {
122
+ // if (peerInfo.updated.getTime() < compDate) {
123
+ // console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
124
+ // this.remove(peerInfo)
125
+ // }
126
+ // })
104
127
  }
105
128
  }
106
129
  exports.PeerPool = PeerPool;
@@ -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,44 +4,51 @@ 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
+ const gnosis_1 = require("@/gnosis");
13
14
  class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
14
15
  constructor(libp2p) {
15
- super(libp2p, '/signatures');
16
+ super(libp2p, '/interop-x/signatures');
16
17
  this.timeout = 30000;
17
18
  }
18
19
  async response(data) {
20
+ console.log({
21
+ tag: 'SignatureDialProtocol',
22
+ data
23
+ });
19
24
  const signer = config_1.default.wallet;
20
- let event;
25
+ let transaction;
21
26
  let maxTimeout = 20000;
22
27
  do {
23
- event = await db_1.Execution.findOne({ where: { vnonce: data.vnonce.toString() } });
24
- if (!event) {
28
+ transaction = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
29
+ if (!transaction) {
25
30
  await (0, waait_1.default)(1000);
26
31
  maxTimeout -= 1000;
27
32
  }
28
- } while (!event && maxTimeout > 0);
29
- if (!event) {
33
+ } while (!transaction && maxTimeout > 0);
34
+ if (!transaction) {
30
35
  return {
31
36
  signer: signer.address,
32
37
  data: null,
33
38
  error: 'Event not found'
34
39
  };
35
40
  }
41
+ const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
36
42
  const signedData = await (0, utils_1.signGnosisSafeTx)({
37
- to: constants_1.addresses[event.chainId].multisend,
38
- data: 'TODO',
39
- chainId: event.chainId,
43
+ to: constants_1.addresses[transaction.sourceChainId].multisend,
44
+ data: gnosisData,
45
+ chainId: transaction.sourceChainId,
40
46
  safeTxGas: data.safeTxGas,
47
+ nonce: data.safeNonce,
41
48
  }, { signer });
42
49
  return {
43
50
  signer: signer.address,
44
- data: signedData,
51
+ data: signedData
45
52
  };
46
53
  }
47
54
  }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionStatusDialProtocol = void 0;
4
+ const BaseDialProtocol_1 = require("./BaseDialProtocol");
5
+ const db_1 = require("@/db");
6
+ class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
7
+ constructor(libp2p) {
8
+ super(libp2p, '/interop-x/transaction-status');
9
+ this.timeout = 30000;
10
+ }
11
+ async response(transactionHash) {
12
+ const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
13
+ if (!transaction) {
14
+ return null;
15
+ }
16
+ return {
17
+ transactionHash: transaction.transactionHash,
18
+ sourceStatus: transaction.sourceStatus,
19
+ sourceTransactionHash: transaction.sourceTransactionHash,
20
+ sourceErrors: transaction.sourceErrors,
21
+ sourceLogs: transaction.sourceLogs,
22
+ targetStatus: transaction.targetStatus,
23
+ targetTransactionHash: transaction.targetTransactionHash,
24
+ targetErrors: transaction.targetErrors,
25
+ targetLogs: transaction.targetLogs,
26
+ status: transaction.status,
27
+ };
28
+ }
29
+ }
30
+ exports.TransactionStatusDialProtocol = TransactionStatusDialProtocol;