@instadapp/interop-x 0.0.0-dev.3e0fb42 → 0.0.0-dev.40b2517

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 (100) 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 +130 -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 +115 -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 +15 -6
  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 +158 -0
  32. package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +93 -0
  33. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  34. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
  35. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  36. package/dist/src/tasks/index.js +41 -0
  37. package/dist/src/typechain/Erc20.js +2 -0
  38. package/dist/src/typechain/GnosisSafe.js +2 -0
  39. package/dist/src/typechain/InteropXContract.js +2 -0
  40. package/dist/src/typechain/common.js +2 -0
  41. package/dist/src/typechain/factories/Erc20__factory.js +367 -0
  42. package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
  43. package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
  44. package/dist/src/typechain/factories/index.js +12 -0
  45. package/dist/src/typechain/index.js +33 -0
  46. package/dist/{types.js → src/types.js} +0 -0
  47. package/dist/src/utils/index.js +193 -0
  48. package/package.json +30 -15
  49. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  50. package/src/abi/erc20.json +350 -0
  51. package/src/abi/gnosisSafe.json +747 -0
  52. package/src/abi/index.ts +9 -0
  53. package/src/abi/interopXContract.json +454 -0
  54. package/src/alias.ts +6 -0
  55. package/src/api/index.ts +36 -0
  56. package/src/config/index.ts +18 -2
  57. package/src/constants/addresses.ts +13 -6
  58. package/src/constants/index.ts +1 -0
  59. package/src/constants/tokens.ts +127 -0
  60. package/src/db/index.ts +1 -1
  61. package/src/db/models/index.ts +1 -1
  62. package/src/db/models/transaction.ts +145 -0
  63. package/src/db/sequelize.ts +2 -1
  64. package/src/gnosis/actions/index.ts +5 -0
  65. package/src/gnosis/actions/withdraw/index.ts +155 -0
  66. package/src/gnosis/index.ts +19 -0
  67. package/src/index.ts +118 -7
  68. package/src/net/peer/index.ts +17 -9
  69. package/src/net/pool/index.ts +43 -13
  70. package/src/net/protocol/dial/BaseDialProtocol.ts +1 -1
  71. package/src/net/protocol/dial/SignatureDialProtocol.ts +24 -17
  72. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  73. package/src/net/protocol/index.ts +71 -5
  74. package/src/tasks/AutoUpdateTask.ts +82 -0
  75. package/src/tasks/BaseTask.ts +16 -7
  76. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +226 -0
  77. package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +125 -0
  78. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
  79. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
  80. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  81. package/src/tasks/index.ts +28 -2
  82. package/src/typechain/Erc20.ts +491 -0
  83. package/src/typechain/GnosisSafe.ts +1728 -0
  84. package/src/typechain/InteropXContract.ts +680 -0
  85. package/src/typechain/common.ts +44 -0
  86. package/src/typechain/factories/Erc20__factory.ts +368 -0
  87. package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
  88. package/src/typechain/factories/InteropXContract__factory.ts +642 -0
  89. package/src/typechain/factories/index.ts +6 -0
  90. package/src/typechain/index.ts +10 -0
  91. package/src/types.ts +2 -2
  92. package/src/utils/index.ts +163 -4
  93. package/tsconfig.json +8 -0
  94. package/dist/config/index.js +0 -17
  95. package/dist/constants/addresses.js +0 -13
  96. package/dist/db/models/execution.js +0 -38
  97. package/dist/index.js +0 -34
  98. package/dist/tasks/index.js +0 -19
  99. package/dist/utils/index.js +0 -89
  100. package/src/db/models/execution.ts +0 -57
@@ -1,5 +1,12 @@
1
- import { Event } from "../../types";
2
- import config from "../../config";
1
+ import { Event } from "@/types";
2
+ import config from "@/config";
3
+ import Logger from "@/logger";
4
+ import { getAddress } from "ethers/lib/utils";
5
+ import { shortenHash } from "@/utils";
6
+ import chalk from "chalk";
7
+
8
+
9
+ const logger = new Logger('PeerPool')
3
10
 
4
11
  export interface IPeerInfo {
5
12
  id: string;
@@ -75,10 +82,15 @@ export class PeerPool {
75
82
  * @emits {@link Event.POOL_PEER_ADDED}
76
83
  */
77
84
  add(peer?: IPeerInfo) {
78
- if (peer && peer.id && !this.pool.get(peer.id)) {
85
+ if (peer && peer.id) {
86
+ const newPeer = !this.pool.get(peer.id);
79
87
  this.pool.set(peer.id, peer)
80
88
  peer.pooled = true
81
- config.events.emit(Event.POOL_PEER_ADDED, peer)
89
+
90
+ if (newPeer) {
91
+ config.events.emit(Event.POOL_PEER_ADDED, peer)
92
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} added to pool`)
93
+ }
82
94
  }
83
95
  }
84
96
 
@@ -92,6 +104,7 @@ export class PeerPool {
92
104
  if (this.pool.delete(peer.id)) {
93
105
  peer.pooled = false
94
106
  config.events.emit(Event.POOL_PEER_REMOVED, peer)
107
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} removed from pool`)
95
108
  }
96
109
  }
97
110
  }
@@ -100,7 +113,7 @@ export class PeerPool {
100
113
  this.cleanup()
101
114
 
102
115
  return this.peers.filter((p) => {
103
- if(!p.pooled) return false;
116
+ if (!p.pooled) return false;
104
117
 
105
118
  const now = new Date()
106
119
 
@@ -112,16 +125,33 @@ export class PeerPool {
112
125
  return this.activePeers.map((p) => p.id)
113
126
  }
114
127
 
128
+ getPeer(id: string){
129
+ return this.pool.get(id);
130
+ }
115
131
 
116
- cleanup() {
117
- let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
132
+ isLeadNode(id: string) {
133
+ const peer = this.pool.get(id);
118
134
 
119
- this.peers.forEach((peerInfo) => {
120
- if (peerInfo.updated.getTime() < compDate) {
121
- console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
122
- this.remove(peerInfo)
123
- }
124
- })
135
+ if (!peer) {
136
+ return false;
137
+ }
138
+
139
+ return getAddress(peer.publicAddress) === getAddress(config.leadNodeAddress)
140
+ }
141
+
142
+ getLeadPeer() {
143
+ return this.peers.find((p) => this.isLeadNode(p.id))
144
+ }
145
+
146
+ cleanup() {
147
+ // let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
148
+
149
+ // this.peers.forEach((peerInfo) => {
150
+ // if (peerInfo.updated.getTime() < compDate) {
151
+ // console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
152
+ // this.remove(peerInfo)
153
+ // }
154
+ // })
125
155
  }
126
156
  }
127
157
 
@@ -1,7 +1,7 @@
1
1
  import pipe from 'it-pipe';
2
2
  import Libp2p from 'libp2p';
3
3
  import PeerId from 'peer-id';
4
- import { asyncCallWithTimeout } from '../../../utils';
4
+ import { asyncCallWithTimeout } from '@/utils';
5
5
  import wait from 'waait';
6
6
 
7
7
  export class BaseDialProtocol<TRequest extends any, TResponse extends any> {
@@ -1,14 +1,15 @@
1
- import { signGnosisSafeTx } from "../../../utils";
2
1
  import { BaseDialProtocol } from "./BaseDialProtocol";
3
2
  import wait from "waait";
4
- import { ChainId } from "../../../types";
5
- import config from "config";
6
- import { addresses } from "../../../constants";
7
- import { Execution } from "db";
3
+ import config from "@/config";
4
+ import { Transaction } from "@/db";
5
+ import { signGnosisSafeTx } from "@/utils";
6
+ import { addresses } from "@/constants";
7
+ import { ChainId } from "@/types";
8
+ import { buildGnosisAction } from "@/gnosis";
8
9
 
9
10
  export interface ISignatureRequest {
10
- type: string,
11
- vnonce: string
11
+ type: 'source' | 'target',
12
+ transactionHash: string
12
13
  safeTxGas: string
13
14
  safeNonce: string
14
15
  }
@@ -21,42 +22,48 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
21
22
  protected timeout = 30000;
22
23
 
23
24
  constructor(libp2p) {
24
- super(libp2p, '/signatures')
25
+ super(libp2p, '/interop-x/signatures')
25
26
  }
26
27
 
27
28
  async response(data: ISignatureRequest): Promise<ISignatureResponse> {
29
+ console.log({
30
+ tag: 'SignatureDialProtocol',
31
+ data
32
+ })
28
33
  const signer = config.wallet;
29
34
 
30
- let event: Execution | null;
35
+ let transaction: Transaction | null;
31
36
  let maxTimeout = 20000;
32
37
 
33
38
  do {
34
- event = await Execution.findOne({ where: { vnonce: data.vnonce.toString() } })
39
+ transaction = await Transaction.findOne({ where: { transactionHash: data.transactionHash } })
35
40
 
36
- if (!event) {
41
+ if (!transaction) {
37
42
  await wait(1000);
38
43
  maxTimeout -= 1000;
39
44
  }
40
- } while (!event && maxTimeout > 0)
45
+ } while (!transaction && maxTimeout > 0)
41
46
 
42
- if (!event) {
47
+ if (!transaction) {
43
48
  return {
44
49
  signer: signer.address,
45
50
  data: null,
46
51
  error: 'Event not found'
47
52
  };
48
53
  }
54
+ const { data: gnosisData } = await buildGnosisAction(transaction, data.type);
49
55
 
50
56
  const signedData = await signGnosisSafeTx({
51
- to: addresses[event.chainId as ChainId].multisend,
52
- data: 'TODO',
53
- chainId: event.chainId as ChainId,
57
+ to: addresses[transaction.sourceChainId].multisend,
58
+ data: gnosisData,
59
+ chainId: transaction.sourceChainId as ChainId,
54
60
  safeTxGas: data.safeTxGas,
61
+ nonce: data.safeNonce,
55
62
  }, { signer });
56
63
 
57
64
  return {
58
65
  signer: signer.address,
59
- data: signedData,
66
+ data: signedData
60
67
  }
61
68
  }
62
69
  }
@@ -0,0 +1,33 @@
1
+ import { BaseDialProtocol } from "./BaseDialProtocol";
2
+ import { Transaction } from "@/db";
3
+
4
+ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'> | null> {
5
+ protected timeout = 30000;
6
+
7
+ constructor(libp2p) {
8
+ super(libp2p, '/interop-x/transaction-status')
9
+ }
10
+
11
+ async response(transactionHash: string){
12
+ const transaction = await Transaction.findOne({ where: { transactionHash } })
13
+
14
+ if(! transaction){
15
+ return null
16
+ }
17
+ return {
18
+ transactionHash: transaction.transactionHash,
19
+
20
+ sourceStatus: transaction.sourceStatus,
21
+ sourceTransactionHash: transaction.sourceTransactionHash,
22
+ sourceErrors: transaction.sourceErrors,
23
+ sourceLogs: transaction.sourceLogs,
24
+
25
+ targetStatus: transaction.targetStatus,
26
+ targetTransactionHash: transaction.targetTransactionHash,
27
+ targetErrors: transaction.targetErrors,
28
+ targetLogs: transaction.targetLogs,
29
+
30
+ status: transaction.status,
31
+ }
32
+ }
33
+ }
@@ -3,8 +3,10 @@ import Libp2p from 'libp2p';
3
3
  import { bufferToInt, rlp } from 'ethereumjs-util'
4
4
  import { SignatureDialProtocol, ISignatureRequest, ISignatureResponse } from "./dial/SignatureDialProtocol";
5
5
  import { IPeerInfo, peerPool } from "..";
6
- import config from "config";
7
- import { Event } from "types";
6
+ import config from "@/config";
7
+ import { Event } from "@/types";
8
+ import { Transaction } from "@/db";
9
+ import { TransactionStatusDialProtocol } from "./dial/TransactionStatusDialProtocol";
8
10
 
9
11
  export interface ProtocolOptions {
10
12
  /* Handshake timeout in ms (default: 8000) */
@@ -33,7 +35,12 @@ interface PeerInfoEvent extends BaseMessageEvent {
33
35
  data: Omit<IPeerInfo, 'id' | 'updated' | 'idle' | 'pooled'>
34
36
  }
35
37
 
38
+ interface TransactionStatusEvent extends BaseMessageEvent {
39
+ data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'>
40
+ }
41
+
36
42
  declare interface Protocol {
43
+ on(event: 'TransactionStatus', listener: (payload: TransactionStatusEvent) => void): this;
37
44
  on(event: 'PeerInfo', listener: (payload: PeerInfoEvent) => void): this;
38
45
  on(event: string, listener: (payload: BaseMessageEvent) => void): this;
39
46
  }
@@ -44,7 +51,7 @@ class Protocol extends EventEmitter {
44
51
  private protocolMessages: Message[] = [
45
52
  {
46
53
  name: 'PeerInfo',
47
- code: 0x09,
54
+ code: 0x01,
48
55
  encode: (info: Pick<IPeerInfo, 'publicAddress'>) => [
49
56
  Buffer.from(info.publicAddress),
50
57
  ],
@@ -52,13 +59,54 @@ class Protocol extends EventEmitter {
52
59
  publicAddress: publicAddress.toString(),
53
60
  }),
54
61
  },
62
+ {
63
+ name: 'TransactionStatus',
64
+ code: 0x02,
65
+ encode: (transaction: Transaction) => [
66
+ Buffer.from(transaction.transactionHash),
67
+
68
+ Buffer.from(transaction.sourceStatus),
69
+ Buffer.from(transaction.sourceTransactionHash || ''),
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)]) : [],
72
+
73
+ Buffer.from(transaction.targetStatus),
74
+ Buffer.from(transaction.targetTransactionHash || ''),
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)]) : [],
77
+
78
+ Buffer.from(transaction.status),
79
+ ],
80
+ decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]: [Buffer, Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer]) => ({
81
+ transactionHash: transactionHash.toString(),
82
+
83
+ sourceStatus: sourceStatus.toString(),
84
+ sourceTransactionHash: sourceTransactionHash.toString() || null,
85
+ sourceErrors: sourceErrors.map((e) => e.toString()),
86
+ sourceLogs: sourceLogs.map(e => ({
87
+ type: e[0].toString(),
88
+ message: e[1].toString(),
89
+ })),
90
+
91
+ targetStatus: targetStatus.toString(),
92
+ targetTransactionHash: targetTransactionHash.toString() || null,
93
+ targetErrors: targetErrors.map((e) => e.toString()),
94
+ targetLogs: targetLogs.map(e => ({
95
+ type: e[0].toString(),
96
+ message: e[1].toString(),
97
+ })),
98
+
99
+ status: status.toString(),
100
+ }),
101
+ },
55
102
  ];
56
103
  private signature: SignatureDialProtocol;
104
+ private transactionStatus: TransactionStatusDialProtocol;
57
105
 
58
106
 
59
107
  start({ libp2p, topic = null, }) {
60
108
  this.libp2p = libp2p
61
- this.topic = topic || 'protocol'
109
+ this.topic = topic || 'itnerop-x-protocol'
62
110
 
63
111
  if (this.libp2p.isStarted()) this.init()
64
112
 
@@ -73,6 +121,7 @@ class Protocol extends EventEmitter {
73
121
  })
74
122
 
75
123
  this.signature = new SignatureDialProtocol(this.libp2p);
124
+ this.transactionStatus = new TransactionStatusDialProtocol(this.libp2p);
76
125
  }
77
126
 
78
127
 
@@ -113,7 +162,7 @@ class Protocol extends EventEmitter {
113
162
  }
114
163
 
115
164
 
116
- public sendPeerInfo(data: Omit<IPeerInfo, 'peerId' | 'updated' | 'idle'>) {
165
+ public sendPeerInfo(data: Pick<IPeerInfo, 'publicAddress'>) {
117
166
  const message = this.protocolMessages.find((m) => m.name === 'PeerInfo')!
118
167
 
119
168
  const encoded = rlp.encode([message.code, message.encode(data)]);
@@ -121,6 +170,14 @@ class Protocol extends EventEmitter {
121
170
  this.libp2p.pubsub.publish(this.topic, encoded)
122
171
  }
123
172
 
173
+ public sendTransaction(transaction: Transaction) {
174
+ const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus')!
175
+
176
+ const encoded = rlp.encode([message.code, message.encode(transaction)]);
177
+
178
+ this.libp2p.pubsub.publish(this.topic, encoded)
179
+ }
180
+
124
181
  async requestSignatures(data: ISignatureRequest, peerIds?: string[]) {
125
182
  try {
126
183
  peerIds = peerIds || peerPool.activePeerIds;
@@ -133,6 +190,15 @@ class Protocol extends EventEmitter {
133
190
  return []
134
191
  }
135
192
  }
193
+
194
+ async requestTransactionStatus(transactionHash: string, peerId: string) {
195
+ try {
196
+ return await this.transactionStatus.send(transactionHash, peerId);
197
+ } catch (error) {
198
+ console.log(error);
199
+ return null
200
+ }
201
+ }
136
202
  }
137
203
 
138
204
  export const protocol = new Protocol();
@@ -0,0 +1,82 @@
1
+ import { BaseTask } from "./BaseTask";
2
+ import Logger from '@/logger';
3
+ import spawnAsync from 'await-spawn';
4
+ import { spawn } from 'child_process'
5
+ import config from "@/config";
6
+ import wait from "waait";
7
+ import packageJson from "../../package.json";
8
+
9
+ const currentVersion = packageJson.version;
10
+ const tag = config.staging ? 'dev' : 'latest';
11
+
12
+ class AutoUpdateTask extends BaseTask {
13
+ pollIntervalMs: number = 60 * 10 * 1000
14
+
15
+ constructor() {
16
+ super({
17
+ logger: new Logger("AutoUpdateTask"),
18
+ })
19
+ }
20
+
21
+ prePollHandler(): boolean {
22
+ return config.autoUpdate && !config.isLeadNode();
23
+ }
24
+
25
+ async getInstalledVersion() {
26
+ try {
27
+ const stdout = await spawnAsync('npm', ['-g', 'ls', '--depth=0', '--json'])
28
+ return JSON.parse(stdout.toString()).dependencies[packageJson.name].version
29
+ } catch (error) {
30
+ this.logger.error(error)
31
+ return currentVersion
32
+ }
33
+ }
34
+
35
+ async getLatestVersion() {
36
+ try {
37
+ const stdout = await spawnAsync('npm', ['view', `${packageJson.name}@${tag}`, 'version'])
38
+ return stdout.toString().trim()
39
+ } catch (error) {
40
+ this.logger.error(error)
41
+ return currentVersion
42
+ }
43
+ }
44
+
45
+ async pollHandler() {
46
+ const version = await this.getLatestVersion()
47
+
48
+ if (version === currentVersion) {
49
+ return;
50
+ }
51
+
52
+ this.logger.warn(`New version ${version} available.`)
53
+
54
+ this.logger.info('Updating...')
55
+
56
+ await spawnAsync('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
57
+
58
+ await wait(5000)
59
+
60
+ if (version !== await this.getInstalledVersion()) {
61
+ this.logger.warn(`failed to install ${version}, retrying in 5 minutes`)
62
+ return;
63
+ }
64
+
65
+ this.logger.warn(`Installed version ${version}`)
66
+ this.logger.warn(`Restarting...`)
67
+
68
+
69
+ // TODO: its restarting in the bg, but it should be in the fg
70
+ const subprocess = spawn(process.argv[0], process.argv.slice(1), {
71
+ cwd: process.cwd(),
72
+ stdio: "inherit",
73
+ // shell: process.env.SHELL,
74
+ });
75
+
76
+ subprocess.unref();
77
+
78
+ process.exit()
79
+ }
80
+ }
81
+
82
+ export default AutoUpdateTask;
@@ -1,8 +1,7 @@
1
- import config from "config";
2
- import { ethers } from "ethers";
1
+ import config from "@/config";
3
2
  import EventEmitter from "events";
4
3
  import wait from "waait";
5
- import Logger from "../logger";
4
+ import Logger from "@/logger";
6
5
 
7
6
  export interface IBaseTask {
8
7
  pollCheck(): Promise<void>
@@ -20,6 +19,7 @@ export class BaseTask extends EventEmitter implements IBaseTask {
20
19
  started: boolean = false
21
20
  pollIntervalMs: number = 10 * 1000
22
21
  leadNodeOnly: boolean = false
22
+ exceptLeadNode: boolean = false
23
23
 
24
24
  public constructor({ logger }: { logger?: Logger }) {
25
25
  super()
@@ -38,7 +38,7 @@ export class BaseTask extends EventEmitter implements IBaseTask {
38
38
  await this.pollHandler()
39
39
  }
40
40
  } catch (err) {
41
- this.logger.error(`poll check error: ${err.message}\ntrace: ${err.stack}`)
41
+ this.logger.error(`poll check error:\n${err.message}\ntrace: ${err.stack}`)
42
42
  }
43
43
 
44
44
  await this.postPollHandler()
@@ -46,11 +46,20 @@ export class BaseTask extends EventEmitter implements IBaseTask {
46
46
  }
47
47
 
48
48
  prePollHandler(): boolean {
49
- if (!this.leadNodeOnly) {
50
- return true
49
+ if(config.isMaintenanceMode()){
50
+ this.logger.warn('Maintenance mode is enabled. Skipping task.')
51
+ return false
51
52
  }
52
53
 
53
- return config.isLeadNode()
54
+ if (this.exceptLeadNode) {
55
+ return !config.isLeadNode();
56
+ }
57
+
58
+ if (this.leadNodeOnly) {
59
+ return config.isLeadNode()
60
+ }
61
+
62
+ return true
54
63
  }
55
64
 
56
65
  async pollHandler() {