@instadapp/interop-x 0.0.0-dev.f78418c → 0.0.0-dev.fbcbec6

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 (96) hide show
  1. package/.env.example +2 -1
  2. package/.github/workflows/ci.yml +19 -0
  3. package/bin/interop-x +1 -1
  4. package/dist/package.json +74 -0
  5. package/dist/{abi → src/abi}/erc20.json +0 -0
  6. package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
  7. package/dist/{abi → src/abi}/index.js +2 -4
  8. package/dist/src/abi/interopX.json +1436 -0
  9. package/dist/src/alias.js +10 -0
  10. package/dist/src/api/index.js +36 -0
  11. package/dist/src/config/index.js +31 -0
  12. package/dist/src/constants/addresses.js +15 -0
  13. package/dist/{constants → src/constants}/index.js +0 -0
  14. package/dist/{constants → src/constants}/tokens.js +62 -39
  15. package/dist/{db → src/db}/index.js +0 -0
  16. package/dist/{db → src/db}/models/index.js +0 -0
  17. package/dist/{db → src/db}/models/transaction.js +29 -9
  18. package/dist/{db → src/db}/sequelize.js +2 -1
  19. package/dist/src/gnosis/actions/index.js +9 -0
  20. package/dist/src/gnosis/actions/withdraw/index.js +114 -0
  21. package/dist/src/gnosis/index.js +20 -0
  22. package/dist/src/index.js +119 -0
  23. package/dist/{logger → src/logger}/index.js +0 -0
  24. package/dist/{net → src/net}/index.js +0 -0
  25. package/dist/{net → src/net}/peer/index.js +8 -3
  26. package/dist/{net → src/net}/pool/index.js +32 -9
  27. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
  28. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +21 -12
  29. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  30. package/dist/{net → src/net}/protocol/index.js +51 -1
  31. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  32. package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
  33. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +84 -0
  34. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +58 -0
  35. package/dist/src/tasks/index.js +34 -0
  36. package/dist/{typechain → src/typechain}/Erc20.js +0 -0
  37. package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
  38. package/dist/{typechain/InteropBridgeToken.js → src/typechain/InteropX.js} +0 -0
  39. package/dist/{typechain → src/typechain}/common.js +0 -0
  40. package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
  41. package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
  42. package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
  43. package/dist/src/typechain/factories/index.js +12 -0
  44. package/dist/{typechain → src/typechain}/index.js +3 -5
  45. package/dist/{types.js → src/types.js} +0 -0
  46. package/dist/src/utils/index.js +195 -0
  47. package/package.json +23 -28
  48. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  49. package/src/abi/index.ts +2 -4
  50. package/src/abi/interopX.json +1436 -0
  51. package/src/alias.ts +6 -0
  52. package/src/api/index.ts +36 -0
  53. package/src/config/index.ts +17 -1
  54. package/src/constants/addresses.ts +3 -16
  55. package/src/constants/tokens.ts +63 -40
  56. package/src/db/models/transaction.ts +69 -25
  57. package/src/db/sequelize.ts +2 -1
  58. package/src/gnosis/actions/index.ts +5 -0
  59. package/src/gnosis/actions/withdraw/index.ts +155 -0
  60. package/src/gnosis/index.ts +19 -0
  61. package/src/index.ts +107 -7
  62. package/src/net/peer/index.ts +9 -7
  63. package/src/net/pool/index.ts +41 -11
  64. package/src/net/protocol/dial/SignatureDialProtocol.ts +23 -13
  65. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  66. package/src/net/protocol/index.ts +67 -1
  67. package/src/tasks/AutoUpdateTask.ts +82 -0
  68. package/src/tasks/BaseTask.ts +14 -4
  69. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +136 -0
  70. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +70 -0
  71. package/src/tasks/index.ts +17 -5
  72. package/src/typechain/InteropX.ts +1216 -0
  73. package/src/typechain/factories/InteropX__factory.ts +1932 -0
  74. package/src/typechain/factories/index.ts +1 -2
  75. package/src/typechain/index.ts +2 -4
  76. package/src/utils/index.ts +170 -10
  77. package/tsconfig.json +7 -2
  78. package/dist/abi/interopBridgeToken.json +0 -286
  79. package/dist/abi/interopXGateway.json +0 -184
  80. package/dist/config/index.js +0 -17
  81. package/dist/constants/addresses.js +0 -28
  82. package/dist/index.js +0 -43
  83. package/dist/tasks/InteropXGateway/SyncDepositEvents.js +0 -79
  84. package/dist/tasks/index.js +0 -27
  85. package/dist/typechain/InteropXGateway.js +0 -2
  86. package/dist/typechain/factories/InteropBridgeToken__factory.js +0 -459
  87. package/dist/typechain/factories/InteropXGateway__factory.js +0 -265
  88. package/dist/typechain/factories/index.js +0 -14
  89. package/dist/utils/index.js +0 -101
  90. package/src/abi/interopBridgeToken.json +0 -286
  91. package/src/abi/interopXGateway.json +0 -184
  92. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -114
  93. package/src/typechain/InteropBridgeToken.ts +0 -686
  94. package/src/typechain/InteropXGateway.ts +0 -407
  95. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  96. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -0,0 +1,10 @@
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
+ });
10
+ (0, module_alias_1.default)();
@@ -0,0 +1,36 @@
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 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(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
+ order: [
24
+ ['updatedAt', 'DESC']
25
+ ]
26
+ });
27
+ });
28
+ await server.listen(PORT, HOST);
29
+ logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
30
+ }
31
+ catch (err) {
32
+ logger.error(err.message);
33
+ process.exit(1);
34
+ }
35
+ };
36
+ exports.startApiServer = startApiServer;
@@ -0,0 +1,31 @@
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 ethers_1 = require("ethers");
7
+ const types_1 = require("@/types");
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
10
+ class Config {
11
+ constructor() {
12
+ this.events = new types_1.EventBus();
13
+ this.maxPeers = 20;
14
+ this.privateKey = process.env.PRIVATE_KEY;
15
+ this.staging = !!process.env.STAGING && process.env.STAGING === 'true';
16
+ this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
17
+ this.wallet = new ethers_1.Wallet(this.privateKey);
18
+ this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
19
+ this.baseConfigPath = (0, expand_home_dir_1.default)(`~/.interop-x`);
20
+ }
21
+ get publicAddress() {
22
+ return this.wallet.address;
23
+ }
24
+ isLeadNode() {
25
+ return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
26
+ }
27
+ isMaintenanceMode() {
28
+ return fs_extra_1.default.existsSync(this.baseConfigPath + '/maintenance');
29
+ }
30
+ }
31
+ exports.default = new Config();
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addresses = void 0;
4
+ exports.addresses = {
5
+ 137: {
6
+ gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
7
+ multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
8
+ interopX: '0xDB6083df37C5F224a3dF84A4B5f9fB60b6c8670a',
9
+ },
10
+ 43114: {
11
+ gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
12
+ multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
13
+ interopX: '0xd61f55C6d9deD35B9d13243b816c4BcC1d78592b',
14
+ }
15
+ };
File without changes
@@ -2,102 +2,125 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tokens = void 0;
4
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
- ],
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
+ // ],
37
49
  137: [
38
50
  {
51
+ aliases: ['eth', 'weth'],
39
52
  symbol: "ETH",
40
53
  name: "Ethereum",
41
54
  address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
42
55
  decimals: 18,
43
56
  },
44
57
  {
58
+ aliases: ['dai'],
45
59
  symbol: "DAI",
46
60
  name: "DAI Stable",
47
61
  address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
48
62
  decimals: 18,
49
63
  },
50
64
  {
65
+ aliases: ['usdc'],
51
66
  symbol: "USDC",
52
67
  name: "USD Coin",
53
68
  address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
54
69
  decimals: 6,
55
70
  },
56
71
  {
72
+ aliases: ['usdt'],
57
73
  symbol: "USDT",
58
74
  name: "Tether USD Coin",
59
75
  address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
60
76
  decimals: 6,
61
77
  },
62
78
  {
79
+ aliases: ['wbtc'],
63
80
  symbol: "WBTC",
64
81
  name: "Wrapped BTC",
65
82
  address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
66
83
  decimals: 8,
67
84
  },
68
- {
69
- symbol: "AVAX",
70
- name: "Avalanche Token",
71
- address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
72
- decimals: 18,
73
- },
74
85
  ],
75
86
  43114: [
76
87
  {
88
+ aliases: ['eth', 'weth'],
77
89
  symbol: "ETH",
78
90
  name: "Ethereum",
79
91
  address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
80
92
  decimals: 18,
81
93
  },
82
94
  {
95
+ aliases: ['dai'],
83
96
  symbol: "DAI",
84
97
  name: "DAI Stable",
85
98
  address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
86
99
  decimals: 18,
87
100
  },
88
101
  {
102
+ aliases: ['usdc'],
89
103
  symbol: "USDC",
90
104
  name: "USD Coin",
91
105
  address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
92
106
  decimals: 6,
93
107
  },
94
108
  {
95
- symbol: "USDT",
109
+ aliases: ['usdt'],
110
+ symbol: "USDt",
96
111
  name: "Tether USD Coin",
112
+ address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
113
+ decimals: 6,
114
+ },
115
+ {
116
+ aliases: ['usdt'],
117
+ symbol: "USDT.e",
118
+ name: "Tether USD",
97
119
  address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
98
120
  decimals: 6,
99
121
  },
100
122
  {
123
+ aliases: ["wbtc"],
101
124
  symbol: "WBTC",
102
125
  name: "Wrapped BTC",
103
126
  address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
File without changes
File without changes
@@ -13,36 +13,56 @@ Transaction.init({
13
13
  primaryKey: true
14
14
  },
15
15
  transactionHash: sequelize_2.DataTypes.STRING,
16
- type: sequelize_2.DataTypes.STRING,
17
- from: sequelize_2.DataTypes.STRING,
18
- to: sequelize_2.DataTypes.STRING,
16
+ actionId: sequelize_2.DataTypes.STRING,
17
+ vnonce: sequelize_2.DataTypes.STRING,
18
+ sourceSender: sequelize_2.DataTypes.STRING,
19
+ submitChainId: sequelize_2.DataTypes.NUMBER,
20
+ submitTransactionHash: sequelize_2.DataTypes.STRING,
21
+ submitBlockNumber: sequelize_2.DataTypes.NUMBER,
22
+ submitCreatedAt: sequelize_2.DataTypes.DATE,
19
23
  sourceChainId: sequelize_2.DataTypes.NUMBER,
24
+ sourceDsaId: sequelize_2.DataTypes.STRING,
20
25
  sourceTransactionHash: sequelize_2.DataTypes.STRING,
21
26
  sourceBlockNumber: sequelize_2.DataTypes.NUMBER,
22
- sourceStatus: sequelize_2.DataTypes.STRING,
27
+ sourceStatus: {
28
+ type: sequelize_2.DataTypes.STRING,
29
+ defaultValue: 'pending'
30
+ },
23
31
  sourceErrors: {
24
32
  type: sequelize_2.DataTypes.JSON,
25
33
  // defaultValue: [],
26
34
  },
35
+ sourceLogs: {
36
+ type: sequelize_2.DataTypes.JSON,
37
+ // defaultValue: [],
38
+ },
27
39
  sourceCreatedAt: {
28
40
  type: sequelize_2.DataTypes.DATE,
29
41
  defaultValue: Date.now()
30
42
  },
31
43
  sourceDelayUntil: sequelize_2.DataTypes.STRING,
32
44
  targetChainId: sequelize_2.DataTypes.NUMBER,
45
+ targetDsaId: sequelize_2.DataTypes.STRING,
33
46
  targetTransactionHash: sequelize_2.DataTypes.STRING,
34
47
  targetBlockNumber: sequelize_2.DataTypes.NUMBER,
35
- targetStatus: sequelize_2.DataTypes.STRING,
48
+ targetStatus: {
49
+ type: sequelize_2.DataTypes.STRING,
50
+ defaultValue: 'pending'
51
+ },
36
52
  targetErrors: {
37
53
  type: sequelize_2.DataTypes.JSON,
38
54
  // defaultValue: [],
39
55
  },
56
+ targetLogs: {
57
+ type: sequelize_2.DataTypes.JSON,
58
+ // defaultValue: [],
59
+ },
40
60
  targetCreatedAt: sequelize_2.DataTypes.DATE,
41
61
  targetDelayUntil: sequelize_2.DataTypes.DATE,
42
- submitEvent: sequelize_2.DataTypes.JSON,
43
- sourceEvent: sequelize_2.DataTypes.JSON,
44
- targetEvent: sequelize_2.DataTypes.JSON,
45
- metadata: sequelize_2.DataTypes.JSON,
62
+ submitEvent: {
63
+ type: sequelize_2.DataTypes.JSON,
64
+ allowNull: false
65
+ },
46
66
  status: {
47
67
  type: sequelize_2.DataTypes.STRING,
48
68
  defaultValue: 'pending'
@@ -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,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // const getBridgeAmounts = async (user: string, tokens: string[], chainId: ChainId) => {
4
+ // const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(chainId));
5
+ // const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
6
+ // const contractAddress = addresses[chainId].interopX;
7
+ // const contract = getContract<InteropX>(contractAddress, abi.interopX, sourceWallet);
8
+ // const data = await contract.getBridgeAmounts(user, tokens);
9
+ // return data.map((item, index) => ({
10
+ // token: tokens[index],
11
+ // deposit: item.deposit,
12
+ // withdraw: item.withdraw,
13
+ // }))
14
+ // }
15
+ async function default_1(transaction, type) {
16
+ const transactions = [];
17
+ const logs = [];
18
+ // if (transaction.actionId !== 'withdraw') {
19
+ // throw new Error(`Invalid action: ${transaction.actionId}`)
20
+ // }
21
+ // if (type !== 'source') {
22
+ // throw new Error(`[WIP] Type not supported: ${type}`)
23
+ // }
24
+ // if (transaction.sourceStatus === 'pending') {
25
+ // throw Error('Source transaction already processesing')
26
+ // }
27
+ // if (transaction.sourceStatus === 'pending') {
28
+ // throw Error('Source transaction already processed')
29
+ // }
30
+ // if (!transaction.requestEvent) {
31
+ // throw Error('Something went wrong, source transaction has no request event')
32
+ // }
33
+ // const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = transaction.requestEvent;
34
+ // const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(sourceChainId as ChainId));
35
+ // const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
36
+ // const contractAddress = addresses[sourceChainId].interopX;
37
+ // const contract = getContract<InteropX>(contractAddress, abi.interopX, sourceWallet);
38
+ // const sourceToken = tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
39
+ // if (!sourceToken) {
40
+ // throw Error('Source token not found')
41
+ // }
42
+ // const targetToken = tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
43
+ // if (!targetToken) {
44
+ // throw Error('Target token not found')
45
+ // }
46
+ // if (!sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
47
+ // throw Error('Source and target token must be the same')
48
+ // }
49
+ // const networks: ChainId[] = [137, 43114];
50
+ // const networkUserData = {}
51
+ // for (const network of networks) {
52
+ // networkUserData[network] = await getBridgeAmounts(bridger, tokens[network].map(t => t.address), network)
53
+ // }
54
+ // for (const tokenSymbol of ["dai", "usdc", "usdt", "eth", "wbtc"]) {
55
+ // let totalDeposit = BigNumber.from(0)
56
+ // let totalWithdraw = BigNumber.from(0)
57
+ // for (const network of networks) {
58
+ // // on avax might we have 2 usdc/usdt tokens
59
+ // const matchedTokens = tokens[network].filter(t => t.aliases.includes(tokenSymbol));
60
+ // for (const matchedToken of matchedTokens) {
61
+ // const data = networkUserData[network].find(t => t.token.toLowerCase() === matchedToken.address.toLowerCase());
62
+ // if (data) {
63
+ // totalDeposit = totalDeposit.add(data.deposit)
64
+ // totalWithdraw = totalWithdraw.add(data.withdraw)
65
+ // }
66
+ // }
67
+ // // on Mainent add weth too
68
+ // if (tokenSymbol === "eth" && network === 1) {
69
+ // const weth = tokens[1].find(t => t.symbol === 'WETH');
70
+ // if (weth) {
71
+ // const data = networkUserData[1].find(t => t.token.toLowerCase() === weth.address.toLowerCase());
72
+ // if (data) {
73
+ // totalDeposit = totalDeposit.add(data.deposit)
74
+ // totalWithdraw = totalWithdraw.add(data.withdraw)
75
+ // }
76
+ // }
77
+ // }
78
+ // }
79
+ // if (totalWithdraw.gt(totalDeposit)) {
80
+ // throw Error(`if withdraw > deposit, user has debt and we can't process the withdraw and reject it`)
81
+ // }
82
+ // if (totalWithdraw.lt(totalDeposit)) {
83
+ // throw Error('Something went wrong')
84
+ // }
85
+ // }
86
+ // let balance = BigNumber.from(0);
87
+ // if (position.withdraw[0].sourceToken.toLowerCase() === '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'.toLowerCase()) {
88
+ // balance = await sourceChainProvider.getBalance(bridger);
89
+ // } else {
90
+ // const erc20 = getContract<Erc20>(position.withdraw[0].sourceToken, abi.erc20, sourceChainProvider);
91
+ // balance = await erc20.balanceOf(addresses[sourceChainId].gnosisSafe);
92
+ // }
93
+ // if (balance.lt(position.withdraw[0].amount)) {
94
+ // throw new LiquidityError()
95
+ // }
96
+ // const { data } = await contract.populateTransaction.withdrawRequested(
97
+ // actionId,
98
+ // bridger,
99
+ // position.withdraw[0].sourceToken,
100
+ // position.withdraw[0].targetToken,
101
+ // position.withdraw[0].amount,
102
+ // targetChainId,
103
+ // transaction.requestTransactionHash,
104
+ // metadata,
105
+ // );
106
+ // transactions.push({
107
+ // to: contractAddress,
108
+ // data: data!,
109
+ // value: '0',
110
+ // operation: OperationType.Call,
111
+ // });
112
+ return { transactions, logs };
113
+ }
114
+ 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 = 'fbcbec6';
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
@@ -23,6 +23,7 @@ const libp2p_kad_dht_1 = __importDefault(require("libp2p-kad-dht"));
23
23
  const libp2p_pubsub_peer_discovery_1 = __importDefault(require("libp2p-pubsub-peer-discovery"));
24
24
  const net_1 = require("@/net");
25
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,13 +78,17 @@ 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
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
94
  setInterval(() => net_1.protocol.sendPeerInfo({