@instadapp/interop-x 0.0.0-dev.d2e8d37 → 0.0.0-dev.de23e71

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 (63) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/abi/interopBridgeToken.json +21 -9
  3. package/dist/src/abi/interopXGateway.json +11 -11
  4. package/dist/src/alias.js +10 -0
  5. package/dist/src/api/index.js +3 -0
  6. package/dist/src/config/index.js +10 -1
  7. package/dist/src/constants/addresses.js +1 -1
  8. package/dist/src/constants/itokens.js +1 -1
  9. package/dist/src/db/models/transaction.js +8 -0
  10. package/dist/src/gnosis/actions/deposit.js +48 -0
  11. package/dist/src/gnosis/actions/index.js +11 -0
  12. package/dist/src/gnosis/actions/withdraw.js +50 -0
  13. package/dist/src/gnosis/index.js +20 -0
  14. package/dist/src/index.js +31 -21
  15. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
  16. package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +2 -0
  17. package/dist/src/net/protocol/index.js +17 -7
  18. package/dist/src/tasks/AutoUpdateTask.js +11 -8
  19. package/dist/src/tasks/BaseTask.js +4 -0
  20. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +17 -1
  21. package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -8
  22. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
  23. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +16 -1
  24. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -2
  25. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
  26. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
  27. package/dist/src/tasks/index.js +16 -5
  28. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
  29. package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
  30. package/dist/src/utils/index.js +1 -82
  31. package/package.json +2 -2
  32. package/src/abi/interopBridgeToken.json +21 -9
  33. package/src/abi/interopXGateway.json +11 -11
  34. package/src/alias.ts +6 -0
  35. package/src/api/index.ts +3 -0
  36. package/src/config/index.ts +9 -1
  37. package/src/constants/addresses.ts +1 -1
  38. package/src/constants/itokens.ts +1 -1
  39. package/src/db/models/transaction.ts +10 -0
  40. package/src/gnosis/actions/deposit.ts +63 -0
  41. package/src/gnosis/actions/index.ts +7 -0
  42. package/src/gnosis/actions/withdraw.ts +67 -0
  43. package/src/gnosis/index.ts +19 -0
  44. package/src/index.ts +44 -25
  45. package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
  46. package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +3 -1
  47. package/src/net/protocol/index.ts +17 -7
  48. package/src/tasks/AutoUpdateTask.ts +15 -14
  49. package/src/tasks/BaseTask.ts +5 -0
  50. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +24 -6
  51. package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -13
  52. package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
  53. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +22 -5
  54. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -2
  55. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
  56. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
  57. package/src/tasks/index.ts +24 -5
  58. package/src/typechain/InteropBridgeToken.ts +23 -17
  59. package/src/typechain/InteropXGateway.ts +13 -13
  60. package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
  61. package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
  62. package/src/utils/index.ts +1 -122
  63. package/tsconfig.json +7 -2
@@ -46,11 +46,17 @@
46
46
  "name": "amount",
47
47
  "type": "uint256"
48
48
  },
49
+ {
50
+ "indexed": false,
51
+ "internalType": "uint32",
52
+ "name": "sourceChainId",
53
+ "type": "uint32"
54
+ },
49
55
  {
50
56
  "indexed": true,
51
- "internalType": "uint256",
52
- "name": "chainId",
53
- "type": "uint256"
57
+ "internalType": "uint32",
58
+ "name": "targetChainId",
59
+ "type": "uint32"
54
60
  }
55
61
  ],
56
62
  "name": "Burn",
@@ -73,14 +79,20 @@
73
79
  },
74
80
  {
75
81
  "indexed": true,
76
- "internalType": "uint256",
77
- "name": "chainId",
78
- "type": "uint256"
82
+ "internalType": "uint32",
83
+ "name": "sourceChainId",
84
+ "type": "uint32"
85
+ },
86
+ {
87
+ "indexed": false,
88
+ "internalType": "uint32",
89
+ "name": "targetChainId",
90
+ "type": "uint32"
79
91
  },
80
92
  {
81
93
  "indexed": true,
82
94
  "internalType": "bytes32",
83
- "name": "transactionHash",
95
+ "name": "submitTransactionHash",
84
96
  "type": "bytes32"
85
97
  }
86
98
  ],
@@ -164,7 +176,7 @@
164
176
  "inputs": [
165
177
  { "internalType": "address", "name": "to", "type": "address" },
166
178
  { "internalType": "uint256", "name": "amount", "type": "uint256" },
167
- { "internalType": "uint256", "name": "chainId", "type": "uint256" }
179
+ { "internalType": "uint32", "name": "chainId", "type": "uint32" }
168
180
  ],
169
181
  "name": "burn",
170
182
  "outputs": [],
@@ -206,7 +218,7 @@
206
218
  "inputs": [
207
219
  { "internalType": "address", "name": "to", "type": "address" },
208
220
  { "internalType": "uint256", "name": "amount", "type": "uint256" },
209
- { "internalType": "uint256", "name": "chainId", "type": "uint256" },
221
+ { "internalType": "uint32", "name": "chainId", "type": "uint32" },
210
222
  {
211
223
  "internalType": "bytes32",
212
224
  "name": "transactionHash",
@@ -35,15 +35,15 @@
35
35
  },
36
36
  {
37
37
  "indexed": false,
38
- "internalType": "uint256",
38
+ "internalType": "uint32",
39
39
  "name": "sourceChainId",
40
- "type": "uint256"
40
+ "type": "uint32"
41
41
  },
42
42
  {
43
43
  "indexed": true,
44
- "internalType": "uint256",
44
+ "internalType": "uint32",
45
45
  "name": "targetChainId",
46
- "type": "uint256"
46
+ "type": "uint32"
47
47
  }
48
48
  ],
49
49
  "name": "LogGatewayDeposit",
@@ -72,15 +72,15 @@
72
72
  },
73
73
  {
74
74
  "indexed": true,
75
- "internalType": "uint256",
75
+ "internalType": "uint32",
76
76
  "name": "sourceChainId",
77
- "type": "uint256"
77
+ "type": "uint32"
78
78
  },
79
79
  {
80
80
  "indexed": false,
81
- "internalType": "uint256",
81
+ "internalType": "uint32",
82
82
  "name": "targetChainId",
83
- "type": "uint256"
83
+ "type": "uint32"
84
84
  },
85
85
  {
86
86
  "indexed": true,
@@ -122,7 +122,7 @@
122
122
  "inputs": [
123
123
  { "internalType": "address", "name": "token_", "type": "address" },
124
124
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
125
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
125
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" }
126
126
  ],
127
127
  "name": "deposit",
128
128
  "outputs": [],
@@ -134,7 +134,7 @@
134
134
  { "internalType": "address", "name": "to_", "type": "address" },
135
135
  { "internalType": "address", "name": "token_", "type": "address" },
136
136
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
137
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
137
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" }
138
138
  ],
139
139
  "name": "depositFor",
140
140
  "outputs": [],
@@ -160,7 +160,7 @@
160
160
  { "internalType": "uint256", "name": "amount_", "type": "uint256" },
161
161
  { "internalType": "address", "name": "user_", "type": "address" },
162
162
  { "internalType": "address", "name": "token_", "type": "address" },
163
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" },
163
+ { "internalType": "uint32", "name": "chainId_", "type": "uint32" },
164
164
  {
165
165
  "internalType": "bytes32",
166
166
  "name": "transactionHash_",
package/src/alias.ts ADDED
@@ -0,0 +1,6 @@
1
+ import moduleAlias from 'module-alias';
2
+ moduleAlias.addAliases({
3
+ "@": __dirname,
4
+ })
5
+
6
+ moduleAlias();
package/src/api/index.ts CHANGED
@@ -20,6 +20,9 @@ export const startApiServer = async () => {
20
20
  return await Transaction.findAndCountAll({
21
21
  limit: 20,
22
22
  offset: 0,
23
+ order: [
24
+ ['createdAt', 'DESC']
25
+ ]
23
26
  })
24
27
  })
25
28
 
@@ -1,5 +1,7 @@
1
1
  import { ethers, Wallet } from "ethers"
2
2
  import { EventBus, EventBusType } from "@/types"
3
+ import fs from 'fs-extra'
4
+ import expandHomeDir from "expand-home-dir";
3
5
 
4
6
  class Config {
5
7
  public readonly events: EventBusType
@@ -9,15 +11,17 @@ class Config {
9
11
  public readonly wallet: Wallet
10
12
  public readonly staging: boolean
11
13
  public readonly autoUpdate: boolean
14
+ public readonly baseConfigPath: string
12
15
 
13
16
  constructor() {
14
17
  this.events = new EventBus() as EventBusType
15
- this.maxPeers = 10
18
+ this.maxPeers = 20
16
19
  this.privateKey = process.env.PRIVATE_KEY as string;
17
20
  this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
18
21
  this.autoUpdate = !! process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
19
22
  this.wallet = new Wallet(this.privateKey);
20
23
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
24
+ this.baseConfigPath = expandHomeDir(`~/.interop-x`);
21
25
  }
22
26
 
23
27
  get publicAddress(){
@@ -27,6 +31,10 @@ class Config {
27
31
  isLeadNode() {
28
32
  return ethers.utils.getAddress(this.leadNodeAddress) === ethers.utils.getAddress(this.wallet.address)
29
33
  }
34
+
35
+ isMaintenanceMode(){
36
+ return fs.existsSync(this.baseConfigPath + '/maintenance')
37
+ }
30
38
  }
31
39
 
32
40
  export default new Config()
@@ -12,6 +12,6 @@ export const addresses = {
12
12
  43114: {
13
13
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
14
14
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
15
- interopXGateway: '0x8D27758751BA488690974B6Ccfcda771D462945f',
15
+ interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
16
16
  }
17
17
  }
@@ -2,7 +2,7 @@ export const itokens = {
2
2
  1: [],
3
3
  137: [
4
4
  {
5
- address: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
5
+ address: '0x62C0045f3277E7067cAcad3c8038eEaBB1Bd92D1',
6
6
  symbol: 'USDC',
7
7
  }
8
8
  ],
@@ -17,6 +17,7 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
17
17
  declare sourceBlockNumber: CreationOptional<number>;
18
18
  declare sourceStatus: string;
19
19
  declare sourceErrors: CreationOptional<string[]>;
20
+ declare sourceLogs: CreationOptional<any[]>;
20
21
  declare sourceCreatedAt: CreationOptional<Date>;
21
22
  declare sourceDelayUntil: CreationOptional<Date>;
22
23
 
@@ -25,6 +26,7 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
25
26
  declare targetBlockNumber: CreationOptional<number>;
26
27
  declare targetStatus: string;
27
28
  declare targetErrors: CreationOptional<string[]>;
29
+ declare targetLogs: CreationOptional<any[]>;
28
30
  declare targetCreatedAt: CreationOptional<Date>;
29
31
  declare targetDelayUntil: CreationOptional<Date>;
30
32
 
@@ -64,6 +66,10 @@ Transaction.init({
64
66
  type: DataTypes.JSON,
65
67
  // defaultValue: [],
66
68
  },
69
+ sourceLogs: {
70
+ type: DataTypes.JSON,
71
+ // defaultValue: [],
72
+ },
67
73
  sourceCreatedAt: {
68
74
  type: DataTypes.DATE,
69
75
  defaultValue: Date.now()
@@ -78,6 +84,10 @@ Transaction.init({
78
84
  type: DataTypes.JSON,
79
85
  // defaultValue: [],
80
86
  },
87
+ targetLogs: {
88
+ type: DataTypes.JSON,
89
+ // defaultValue: [],
90
+ },
81
91
  targetCreatedAt: DataTypes.DATE,
82
92
  targetDelayUntil: DataTypes.DATE,
83
93
 
@@ -0,0 +1,63 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { itokens, tokens } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { InteropBridgeToken } from "@/typechain";
6
+ import { ChainId } from "@/types";
7
+ import { getContract, getRpcProviderUrl } from "@/utils";
8
+ import { ethers } from "ethers";
9
+ import { MetaTransaction, OperationType } from "ethers-multisend";
10
+
11
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
12
+ const transactions: MetaTransaction[] = [];
13
+ const logs: any[] = [];
14
+
15
+ if (transaction.sourceStatus === 'pending') {
16
+ throw Error('Cannot build data for pending deposit transaction');
17
+ }
18
+
19
+ if (!transaction.submitEvent) {
20
+ throw Error('Cannot build data for transaction without submitEvent');
21
+ }
22
+
23
+
24
+ const token = tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
25
+
26
+ if (!token) {
27
+ throw Error(`Unsupported token ${transaction.submitEvent.token}`);
28
+ }
29
+
30
+ const itoken = itokens[transaction.targetChainId].find(t => t.symbol.toLowerCase() === token.symbol.toLowerCase());
31
+
32
+ if (!itoken) {
33
+ throw Error(`Unsupported itoken ${token.symbol}`);
34
+ }
35
+
36
+ const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
37
+ const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
38
+ const interopBridgeContract = getContract<InteropBridgeToken>(itoken.address, abi.interopBridgeToken, targetWallet);
39
+
40
+ const { data } = await interopBridgeContract.populateTransaction.mint(
41
+ transaction.submitEvent.user,
42
+ ethers.BigNumber.from(transaction.submitEvent.amount.toString()),
43
+ ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()),
44
+ transaction.submitTransactionHash,
45
+ );
46
+
47
+ transactions.push({
48
+ to: itoken.address,
49
+ data: data!,
50
+ value: '0',
51
+ operation: OperationType.Call,
52
+ });
53
+
54
+ logs.push({
55
+ type: 'mint', // mint, approved, burn, transfer, borrow, swap, repay, collected, traded, .....
56
+ message: `Minted ${transaction.submitEvent.amount / 10 ** token.decimals} ${token.symbol} to ${transaction.submitEvent.user}`,
57
+ })
58
+
59
+ return {
60
+ transactions,
61
+ logs,
62
+ }
63
+ }
@@ -0,0 +1,7 @@
1
+ import deposit from "./deposit"
2
+ import withdraw from "./withdraw"
3
+
4
+ export default {
5
+ deposit,
6
+ withdraw,
7
+ }
@@ -0,0 +1,67 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { addresses, itokens, tokens } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { InteropXGateway } from "@/typechain";
6
+ import { ChainId } from "@/types";
7
+ import { getContract, getRpcProviderUrl } from "@/utils";
8
+ import { ethers } from "ethers";
9
+ import { MetaTransaction, OperationType } from "ethers-multisend";
10
+
11
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
12
+ const transactions: MetaTransaction[] = [];
13
+ const logs: any[] = [];
14
+
15
+ if (transaction.action !== 'withdraw') {
16
+ throw new Error(`Invalid action: ${transaction.action}`)
17
+ }
18
+
19
+ if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
20
+ throw Error('Cannot build data for pending withdraw transaction');
21
+ }
22
+
23
+ if (!transaction.submitEvent) {
24
+ throw Error('Cannot build data for transaction without submitEvent');
25
+ }
26
+
27
+ const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
28
+
29
+ const itoken = itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
30
+
31
+ if (!itoken) {
32
+ throw Error(`Unsupported itoken ${itokenAddress}`);
33
+ }
34
+
35
+ const token = tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
36
+
37
+ if (!token) {
38
+ throw Error(`Unsupported token ${itoken.symbol}`);
39
+ }
40
+
41
+ const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
42
+ const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
43
+ const gatewayAddress = addresses[targetChainId].interopXGateway;
44
+ const interopBridgeContract = getContract<InteropXGateway>(gatewayAddress, abi.interopXGateway, targetWallet);
45
+
46
+ const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(
47
+ ethers.BigNumber.from(amount.toString()),
48
+ to,
49
+ token.address,
50
+ ethers.BigNumber.from(sourceChainId.toString()),
51
+ transaction.submitTransactionHash,
52
+ );
53
+
54
+ transactions.push({
55
+ to: gatewayAddress,
56
+ data: data!,
57
+ value: '0',
58
+ operation: OperationType.Call,
59
+ });
60
+
61
+ logs.push({
62
+ type: 'transfer',
63
+ message: `Transfer ${amount / 10 ** token.decimals} ${token.symbol} to ${to}`,
64
+ })
65
+
66
+ return { transactions, logs }
67
+ }
@@ -0,0 +1,19 @@
1
+ import { Transaction } from "@/db";
2
+ import { encodeMulti } from "ethers-multisend";
3
+ import actions from "./actions";
4
+
5
+ export const buildGnosisAction = async (transaction: Transaction, type?: 'source' | 'target') => {
6
+ type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
7
+
8
+ if (actions.hasOwnProperty(transaction.action)) {
9
+
10
+ const { transactions, logs } = await actions[transaction.action](transaction, type);
11
+
12
+ return {
13
+ data: encodeMulti(transactions).data,
14
+ logs
15
+ };
16
+ }
17
+
18
+ throw new Error(`Unknown action: ${transaction.action}`);
19
+ }
package/src/index.ts CHANGED
@@ -1,21 +1,7 @@
1
- import moduleAlias from 'module-alias';
2
-
3
- moduleAlias.addAliases({
4
- "@/": __dirname + "/",
5
- "@/logger": __dirname + "/logger",
6
- "@/tasks": __dirname + "/tasks",
7
- "@/utils": __dirname + "/utils",
8
- "@/api": __dirname + "/api",
9
- "@/net": __dirname + "/net",
10
- "@/db": __dirname + "/db",
11
- "@/config": __dirname + "/config",
12
- "@/types": __dirname + "/types",
13
- "@/abi": __dirname + "/abi",
14
- "@/constants": __dirname + "/constants",
15
- "@/typechain": __dirname + "/typechain"
16
- })
1
+ import './alias'
2
+ import expandHomeDir from "expand-home-dir";
3
+ import fs from 'fs-extra'
17
4
 
18
- moduleAlias();
19
5
  import dotenv from "dotenv";
20
6
  import chalk from 'chalk';
21
7
  import { ethers } from "ethers";
@@ -25,12 +11,30 @@ dotenv.config();
25
11
  import Logger from "@/logger";
26
12
  const logger = new Logger('Process')
27
13
 
14
+ const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
15
+
28
16
  const printUsage = () => {
17
+ console.log()
18
+ console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
19
+ console.log()
20
+
29
21
  console.log('Usage:')
30
- console.log(' PRIVATE_KEY=abcd1234 interop-x')
31
- console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x')
32
- console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x')
33
- console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x')
22
+ console.log(' interop-x help Show this message')
23
+ console.log(' interop-x version Print out the installed version of Interop X')
24
+
25
+ console.log()
26
+
27
+ console.log(' interop-x down Put the node into maintenance mode')
28
+ console.log(' interop-x up Take the node out of maintenance mode')
29
+
30
+ console.log()
31
+
32
+ console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key')
33
+ console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode')
34
+ console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode')
35
+ 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')
36
+ console.log()
37
+
34
38
  }
35
39
 
36
40
  if (process.argv.at(-1) === 'help') {
@@ -38,14 +42,27 @@ if (process.argv.at(-1) === 'help') {
38
42
  process.exit(0)
39
43
  }
40
44
 
41
- const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
45
+ const basePath = expandHomeDir(`~/.interop-x`);
46
+
47
+ if (process.argv.at(-1) === 'down') {
48
+ fs.outputFileSync(basePath + '/maintenance', Date.now().toString())
49
+ console.log(chalk.red('Maintenance mode enabled'))
50
+ process.exit(0)
51
+ }
52
+
53
+ if (process.argv.at(-1) === 'up') {
54
+ fs.removeSync(basePath + '/maintenance')
55
+ console.log(chalk.green('Maintenance mode disabled'))
56
+ process.exit(0)
57
+ }
58
+
42
59
 
43
60
  if (process.argv.at(-1) === 'version') {
44
61
  console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
45
62
  process.exit(0)
46
63
  }
47
64
 
48
- if(! process.env.PRIVATE_KEY) {
65
+ if (!process.env.PRIVATE_KEY) {
49
66
  console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
50
67
  printUsage()
51
68
  process.exit(1)
@@ -80,10 +97,10 @@ async function main() {
80
97
  if (!peerPool.isLeadNode(payload.peerId)) {
81
98
  const peer = peerPool.getPeer(payload.peerId)
82
99
 
83
- if(! peer) {
100
+ if (!peer) {
84
101
  return;
85
102
  }
86
-
103
+
87
104
  logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
88
105
  return;
89
106
  }
@@ -97,10 +114,12 @@ async function main() {
97
114
  transaction.sourceStatus = payload.data.sourceStatus
98
115
  transaction.sourceTransactionHash = payload.data.sourceTransactionHash
99
116
  transaction.sourceErrors = payload.data.sourceErrors
117
+ transaction.sourceLogs = payload.data.sourceLogs
100
118
 
101
119
  transaction.targetStatus = payload.data.targetStatus
102
120
  transaction.targetTransactionHash = payload.data.targetTransactionHash
103
121
  transaction.targetErrors = payload.data.targetErrors
122
+ transaction.targetLogs = payload.data.targetLogs
104
123
 
105
124
  transaction.status = payload.data.status
106
125
 
@@ -2,12 +2,13 @@ import { BaseDialProtocol } from "./BaseDialProtocol";
2
2
  import wait from "waait";
3
3
  import config from "@/config";
4
4
  import { Transaction } from "@/db";
5
- import { buildDataForTransaction, signGnosisSafeTx } from "@/utils";
5
+ import { signGnosisSafeTx } from "@/utils";
6
6
  import { addresses } from "@/constants";
7
7
  import { ChainId } from "@/types";
8
+ import { buildGnosisAction } from "@/gnosis";
8
9
 
9
10
  export interface ISignatureRequest {
10
- type: 'source' | 'target' ,
11
+ type: 'source' | 'target',
11
12
  transactionHash: string
12
13
  safeTxGas: string
13
14
  safeNonce: string
@@ -46,18 +47,11 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
46
47
  error: 'Event not found'
47
48
  };
48
49
  }
49
-
50
- console.log("signing:", {
51
- to: addresses[transaction.targetChainId].multisend,
52
- data: await buildDataForTransaction(transaction, data.type),
53
- chainId: transaction.targetChainId as ChainId,
54
- safeTxGas: data.safeTxGas,
55
- nonce: data.safeNonce,
56
- });
50
+ const { data: gnosisData } = await buildGnosisAction(transaction, data.type);
57
51
 
58
52
  const signedData = await signGnosisSafeTx({
59
53
  to: addresses[transaction.targetChainId].multisend,
60
- data: await buildDataForTransaction(transaction, data.type),
54
+ data: gnosisData,
61
55
  chainId: transaction.targetChainId as ChainId,
62
56
  safeTxGas: data.safeTxGas,
63
57
  nonce: data.safeNonce,
@@ -1,7 +1,7 @@
1
1
  import { BaseDialProtocol } from "./BaseDialProtocol";
2
2
  import { Transaction } from "@/db";
3
3
 
4
- export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'> | null> {
4
+ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'> | null> {
5
5
  protected timeout = 30000;
6
6
 
7
7
  constructor(libp2p) {
@@ -20,10 +20,12 @@ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick
20
20
  sourceStatus: transaction.sourceStatus,
21
21
  sourceTransactionHash: transaction.sourceTransactionHash,
22
22
  sourceErrors: transaction.sourceErrors,
23
+ sourceLogs: transaction.sourceLogs,
23
24
 
24
25
  targetStatus: transaction.targetStatus,
25
26
  targetTransactionHash: transaction.targetTransactionHash,
26
27
  targetErrors: transaction.targetErrors,
28
+ targetLogs: transaction.targetLogs,
27
29
 
28
30
  status: transaction.status,
29
31
  }
@@ -6,7 +6,7 @@ import { IPeerInfo, peerPool } from "..";
6
6
  import config from "@/config";
7
7
  import { Event } from "@/types";
8
8
  import { Transaction } from "@/db";
9
- import { TransactionStatusDialProtocol } from "./dial/SignatureDialProtocol.1";
9
+ import { TransactionStatusDialProtocol } from "./dial/TransactionStatusDialProtocol";
10
10
 
11
11
  export interface ProtocolOptions {
12
12
  /* Handshake timeout in ms (default: 8000) */
@@ -36,7 +36,7 @@ interface PeerInfoEvent extends BaseMessageEvent {
36
36
  }
37
37
 
38
38
  interface TransactionStatusEvent extends BaseMessageEvent {
39
- data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'>
39
+ data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'>
40
40
  }
41
41
 
42
42
  declare interface Protocol {
@@ -66,25 +66,35 @@ class Protocol extends EventEmitter {
66
66
  Buffer.from(transaction.transactionHash),
67
67
 
68
68
  Buffer.from(transaction.sourceStatus),
69
- Buffer.from(transaction.sourceTransactionHash),
69
+ Buffer.from(transaction.sourceTransactionHash || ''),
70
70
  transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
71
+ transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
71
72
 
72
73
  Buffer.from(transaction.targetStatus),
73
- Buffer.from(transaction.targetTransactionHash),
74
+ Buffer.from(transaction.targetTransactionHash || ''),
74
75
  transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
76
+ transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
75
77
 
76
78
  Buffer.from(transaction.status),
77
79
  ],
78
- decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]: [Buffer, Buffer, Buffer, Buffer[], Buffer, Buffer, Buffer[], Buffer]) => ({
80
+ decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]: [Buffer, Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer]) => ({
79
81
  transactionHash: transactionHash.toString(),
80
82
 
81
83
  sourceStatus: sourceStatus.toString(),
82
- sourceTransactionHash: sourceTransactionHash.toString(),
84
+ sourceTransactionHash: sourceTransactionHash.toString() || null,
83
85
  sourceErrors: sourceErrors.map((e) => e.toString()),
86
+ sourceLogs: sourceLogs.map(e => ({
87
+ type: e[0].toString(),
88
+ message: e[1].toString(),
89
+ })),
84
90
 
85
91
  targetStatus: targetStatus.toString(),
86
- targetTransactionHash: targetTransactionHash.toString(),
92
+ targetTransactionHash: targetTransactionHash.toString() || null,
87
93
  targetErrors: targetErrors.map((e) => e.toString()),
94
+ targetLogs: targetLogs.map(e => ({
95
+ type: e[0].toString(),
96
+ message: e[1].toString(),
97
+ })),
88
98
 
89
99
  status: status.toString(),
90
100
  }),