@instadapp/interop-x 0.0.0-dev.fd7fd6f → 0.0.0-dev.fded533
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/package.json +4 -3
- package/dist/src/abi/interopBridgeToken.json +21 -9
- package/dist/src/abi/interopXGateway.json +11 -11
- package/dist/src/api/index.js +3 -3
- package/dist/src/config/index.js +10 -1
- package/dist/src/constants/addresses.js +1 -1
- package/dist/src/constants/itokens.js +1 -1
- package/dist/src/index.js +33 -6
- package/dist/src/net/peer/index.js +2 -1
- package/dist/src/net/pool/index.js +7 -2
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
- package/dist/src/net/protocol/index.js +15 -4
- package/dist/src/tasks/AutoUpdateTask.js +42 -16
- package/dist/src/tasks/BaseTask.js +11 -3
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -1
- package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -9
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +14 -2
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -3
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
- package/dist/src/tasks/index.js +17 -4
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
- package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
- package/dist/src/utils/index.js +20 -10
- package/package.json +4 -3
- package/src/abi/interopBridgeToken.json +21 -9
- package/src/abi/interopXGateway.json +11 -11
- package/src/api/index.ts +2 -2
- package/src/config/index.ts +9 -1
- package/src/constants/addresses.ts +1 -1
- package/src/constants/itokens.ts +1 -1
- package/src/index.ts +46 -8
- package/src/net/peer/index.ts +2 -1
- package/src/net/pool/index.ts +7 -3
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
- package/src/net/protocol/index.ts +16 -4
- package/src/tasks/AutoUpdateTask.ts +48 -19
- package/src/tasks/BaseTask.ts +13 -3
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +0 -2
- package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +10 -10
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +18 -6
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -4
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
- package/src/tasks/index.ts +25 -4
- package/src/typechain/InteropBridgeToken.ts +23 -17
- package/src/typechain/InteropXGateway.ts +13 -13
- package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
- package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
- package/src/utils/index.ts +21 -9
package/src/api/index.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import fastify from "fastify"
|
2
|
-
import cors from 'fastify
|
2
|
+
import cors from '@fastify/cors'
|
3
3
|
import Logger from "@/logger"
|
4
4
|
import { Transaction } from "@/db";
|
5
5
|
|
@@ -27,7 +27,7 @@ export const startApiServer = async () => {
|
|
27
27
|
|
28
28
|
logger.log(`RPC Server listening at http://${HOST}:${PORT}`)
|
29
29
|
} catch (err) {
|
30
|
-
logger.error(err)
|
30
|
+
logger.error(err.message)
|
31
31
|
process.exit(1)
|
32
32
|
}
|
33
33
|
}
|
package/src/config/index.ts
CHANGED
@@ -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 =
|
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: '
|
15
|
+
interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
|
16
16
|
}
|
17
17
|
}
|
package/src/constants/itokens.ts
CHANGED
package/src/index.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import moduleAlias from 'module-alias';
|
2
|
-
|
2
|
+
import expandHomeDir from "expand-home-dir";
|
3
|
+
import fs from 'fs-extra'
|
3
4
|
moduleAlias.addAliases({
|
4
5
|
"@/": __dirname + "/",
|
5
6
|
"@/logger": __dirname + "/logger",
|
@@ -25,12 +26,30 @@ dotenv.config();
|
|
25
26
|
import Logger from "@/logger";
|
26
27
|
const logger = new Logger('Process')
|
27
28
|
|
29
|
+
const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
|
30
|
+
|
28
31
|
const printUsage = () => {
|
32
|
+
console.log()
|
33
|
+
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
34
|
+
console.log()
|
35
|
+
|
29
36
|
console.log('Usage:')
|
30
|
-
console.log('
|
31
|
-
console.log('
|
32
|
-
|
33
|
-
console.log(
|
37
|
+
console.log(' interop-x help Show this message')
|
38
|
+
console.log(' interop-x version Print out the installed version of Interop X')
|
39
|
+
|
40
|
+
console.log()
|
41
|
+
|
42
|
+
console.log(' interop-x down Put the node into maintenance mode')
|
43
|
+
console.log(' interop-x up Take the node out of maintenance mode')
|
44
|
+
|
45
|
+
console.log()
|
46
|
+
|
47
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key')
|
48
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode')
|
49
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode')
|
50
|
+
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')
|
51
|
+
console.log()
|
52
|
+
|
34
53
|
}
|
35
54
|
|
36
55
|
if (process.argv.at(-1) === 'help') {
|
@@ -38,14 +57,27 @@ if (process.argv.at(-1) === 'help') {
|
|
38
57
|
process.exit(0)
|
39
58
|
}
|
40
59
|
|
41
|
-
const
|
60
|
+
const basePath = expandHomeDir(`~/.interop-x`);
|
61
|
+
|
62
|
+
if (process.argv.at(-1) === 'down') {
|
63
|
+
fs.outputFileSync(basePath + '/maintenance', Date.now().toString())
|
64
|
+
console.log(chalk.red('Maintenance mode enabled'))
|
65
|
+
process.exit(0)
|
66
|
+
}
|
67
|
+
|
68
|
+
if (process.argv.at(-1) === 'up') {
|
69
|
+
fs.removeSync(basePath + '/maintenance')
|
70
|
+
console.log(chalk.green('Maintenance mode disabled'))
|
71
|
+
process.exit(0)
|
72
|
+
}
|
73
|
+
|
42
74
|
|
43
75
|
if (process.argv.at(-1) === 'version') {
|
44
76
|
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
45
77
|
process.exit(0)
|
46
78
|
}
|
47
79
|
|
48
|
-
if(!
|
80
|
+
if (!process.env.PRIVATE_KEY) {
|
49
81
|
console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
|
50
82
|
printUsage()
|
51
83
|
process.exit(1)
|
@@ -64,6 +96,7 @@ import { Tasks } from "@/tasks";
|
|
64
96
|
import { startPeer, protocol, peerPool } from "@/net";
|
65
97
|
import { startApiServer } from '@/api';
|
66
98
|
import { Transaction } from './db';
|
99
|
+
import { shortenHash } from './utils';
|
67
100
|
|
68
101
|
async function main() {
|
69
102
|
|
@@ -78,7 +111,12 @@ async function main() {
|
|
78
111
|
protocol.on('TransactionStatus', async (payload) => {
|
79
112
|
if (!peerPool.isLeadNode(payload.peerId)) {
|
80
113
|
const peer = peerPool.getPeer(payload.peerId)
|
81
|
-
|
114
|
+
|
115
|
+
if (!peer) {
|
116
|
+
return;
|
117
|
+
}
|
118
|
+
|
119
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
|
82
120
|
return;
|
83
121
|
}
|
84
122
|
|
package/src/net/peer/index.ts
CHANGED
@@ -17,6 +17,7 @@ import KadDHT from "libp2p-kad-dht";
|
|
17
17
|
import PubsubPeerDiscovery from "libp2p-pubsub-peer-discovery";
|
18
18
|
import { protocol } from "@/net";
|
19
19
|
import config from "@/config";
|
20
|
+
import chalk from "chalk";
|
20
21
|
|
21
22
|
const logger = new Logger("Peer");
|
22
23
|
|
@@ -80,7 +81,7 @@ export const startPeer = async ({ }: IPeerOptions) => {
|
|
80
81
|
},
|
81
82
|
});
|
82
83
|
|
83
|
-
logger.info("Peer ID:", node.peerId.toB58String());
|
84
|
+
logger.info("Peer ID:", chalk.bold(node.peerId.toB58String()));
|
84
85
|
|
85
86
|
await node.start();
|
86
87
|
|
package/src/net/pool/index.ts
CHANGED
@@ -2,6 +2,8 @@ import { Event } from "@/types";
|
|
2
2
|
import config from "@/config";
|
3
3
|
import Logger from "@/logger";
|
4
4
|
import { getAddress } from "ethers/lib/utils";
|
5
|
+
import { shortenHash } from "@/utils";
|
6
|
+
import chalk from "chalk";
|
5
7
|
|
6
8
|
|
7
9
|
const logger = new Logger('PeerPool')
|
@@ -87,7 +89,7 @@ export class PeerPool {
|
|
87
89
|
|
88
90
|
if (newPeer) {
|
89
91
|
config.events.emit(Event.POOL_PEER_ADDED, peer)
|
90
|
-
logger.info(`Peer ${peer.id} with address ${peer.publicAddress} added to pool`)
|
92
|
+
logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} added to pool`)
|
91
93
|
}
|
92
94
|
}
|
93
95
|
}
|
@@ -102,7 +104,7 @@ export class PeerPool {
|
|
102
104
|
if (this.pool.delete(peer.id)) {
|
103
105
|
peer.pooled = false
|
104
106
|
config.events.emit(Event.POOL_PEER_REMOVED, peer)
|
105
|
-
logger.info(`Peer ${peer.id} with address ${peer.publicAddress} removed from pool`)
|
107
|
+
logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} removed from pool`)
|
106
108
|
}
|
107
109
|
}
|
108
110
|
}
|
@@ -123,7 +125,6 @@ export class PeerPool {
|
|
123
125
|
return this.activePeers.map((p) => p.id)
|
124
126
|
}
|
125
127
|
|
126
|
-
|
127
128
|
getPeer(id: string){
|
128
129
|
return this.pool.get(id);
|
129
130
|
}
|
@@ -138,6 +139,9 @@ export class PeerPool {
|
|
138
139
|
return getAddress(peer.publicAddress) === getAddress(config.leadNodeAddress)
|
139
140
|
}
|
140
141
|
|
142
|
+
getLeadPeer() {
|
143
|
+
return this.peers.find((p) => this.isLeadNode(p.id))
|
144
|
+
}
|
141
145
|
|
142
146
|
cleanup() {
|
143
147
|
// let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { BaseDialProtocol } from "./BaseDialProtocol";
|
2
|
+
import { Transaction } from "@/db";
|
3
|
+
|
4
|
+
export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | '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
|
+
|
24
|
+
targetStatus: transaction.targetStatus,
|
25
|
+
targetTransactionHash: transaction.targetTransactionHash,
|
26
|
+
targetErrors: transaction.targetErrors,
|
27
|
+
|
28
|
+
status: transaction.status,
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
@@ -6,6 +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/TransactionStatusDialProtocol";
|
9
10
|
|
10
11
|
export interface ProtocolOptions {
|
11
12
|
/* Handshake timeout in ms (default: 8000) */
|
@@ -65,11 +66,11 @@ class Protocol extends EventEmitter {
|
|
65
66
|
Buffer.from(transaction.transactionHash),
|
66
67
|
|
67
68
|
Buffer.from(transaction.sourceStatus),
|
68
|
-
Buffer.from(transaction.sourceTransactionHash),
|
69
|
+
Buffer.from(transaction.sourceTransactionHash || ''),
|
69
70
|
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
70
71
|
|
71
72
|
Buffer.from(transaction.targetStatus),
|
72
|
-
Buffer.from(transaction.targetTransactionHash),
|
73
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
73
74
|
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
74
75
|
|
75
76
|
Buffer.from(transaction.status),
|
@@ -78,11 +79,11 @@ class Protocol extends EventEmitter {
|
|
78
79
|
transactionHash: transactionHash.toString(),
|
79
80
|
|
80
81
|
sourceStatus: sourceStatus.toString(),
|
81
|
-
sourceTransactionHash: sourceTransactionHash.toString(),
|
82
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
82
83
|
sourceErrors: sourceErrors.map((e) => e.toString()),
|
83
84
|
|
84
85
|
targetStatus: targetStatus.toString(),
|
85
|
-
targetTransactionHash: targetTransactionHash.toString(),
|
86
|
+
targetTransactionHash: targetTransactionHash.toString()|| null,
|
86
87
|
targetErrors: targetErrors.map((e) => e.toString()),
|
87
88
|
|
88
89
|
status: status.toString(),
|
@@ -90,6 +91,7 @@ class Protocol extends EventEmitter {
|
|
90
91
|
},
|
91
92
|
];
|
92
93
|
private signature: SignatureDialProtocol;
|
94
|
+
private transactionStatus: TransactionStatusDialProtocol;
|
93
95
|
|
94
96
|
|
95
97
|
start({ libp2p, topic = null, }) {
|
@@ -109,6 +111,7 @@ class Protocol extends EventEmitter {
|
|
109
111
|
})
|
110
112
|
|
111
113
|
this.signature = new SignatureDialProtocol(this.libp2p);
|
114
|
+
this.transactionStatus = new TransactionStatusDialProtocol(this.libp2p);
|
112
115
|
}
|
113
116
|
|
114
117
|
|
@@ -177,6 +180,15 @@ class Protocol extends EventEmitter {
|
|
177
180
|
return []
|
178
181
|
}
|
179
182
|
}
|
183
|
+
|
184
|
+
async requestTransactionStatus(transactionHash: string, peerId: string) {
|
185
|
+
try {
|
186
|
+
return await this.transactionStatus.send(transactionHash, peerId);
|
187
|
+
} catch (error) {
|
188
|
+
console.log(error);
|
189
|
+
return null
|
190
|
+
}
|
191
|
+
}
|
180
192
|
}
|
181
193
|
|
182
194
|
export const protocol = new Protocol();
|
@@ -1,13 +1,16 @@
|
|
1
1
|
import { BaseTask } from "./BaseTask";
|
2
2
|
import Logger from '@/logger';
|
3
|
-
import
|
4
|
-
import {
|
5
|
-
import { spawn } from 'child_process';
|
3
|
+
import spawnAsync from 'await-spawn';
|
4
|
+
import { spawn } from 'child_process'
|
6
5
|
import config from "@/config";
|
6
|
+
import wait from "waait";
|
7
|
+
import packageJson from "../../package.json";
|
8
|
+
|
7
9
|
const currentVersion = packageJson.version;
|
10
|
+
const tag = config.staging ? 'dev' : 'latest';
|
8
11
|
|
9
12
|
class AutoUpdateTask extends BaseTask {
|
10
|
-
pollIntervalMs: number = 60 * 1000
|
13
|
+
pollIntervalMs: number = 60 * 10 * 1000
|
11
14
|
|
12
15
|
constructor() {
|
13
16
|
super({
|
@@ -19,11 +22,28 @@ class AutoUpdateTask extends BaseTask {
|
|
19
22
|
return config.autoUpdate && !config.isLeadNode();
|
20
23
|
}
|
21
24
|
|
22
|
-
async
|
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
|
+
}
|
23
34
|
|
24
|
-
|
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
|
+
}
|
25
44
|
|
26
|
-
|
45
|
+
async pollHandler() {
|
46
|
+
const version = await this.getLatestVersion()
|
27
47
|
|
28
48
|
if (version === currentVersion) {
|
29
49
|
return;
|
@@ -31,22 +51,31 @@ class AutoUpdateTask extends BaseTask {
|
|
31
51
|
|
32
52
|
this.logger.warn(`New version ${version} available.`)
|
33
53
|
|
54
|
+
this.logger.info('Updating...')
|
34
55
|
|
35
|
-
|
56
|
+
await spawnAsync('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
36
57
|
|
37
|
-
|
38
|
-
this.logger.warn(`Installed version ${version}`)
|
39
|
-
this.logger.warn(`Restarting...`)
|
58
|
+
await wait(5000)
|
40
59
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
stdio: "inherit"
|
46
|
-
});
|
60
|
+
if (version !== await this.getInstalledVersion()) {
|
61
|
+
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`)
|
62
|
+
return;
|
63
|
+
}
|
47
64
|
|
48
|
-
|
49
|
-
|
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()
|
50
79
|
}
|
51
80
|
}
|
52
81
|
|
package/src/tasks/BaseTask.ts
CHANGED
@@ -19,6 +19,7 @@ export class BaseTask extends EventEmitter implements IBaseTask {
|
|
19
19
|
started: boolean = false
|
20
20
|
pollIntervalMs: number = 10 * 1000
|
21
21
|
leadNodeOnly: boolean = false
|
22
|
+
exceptLeadNode: boolean = false
|
22
23
|
|
23
24
|
public constructor({ logger }: { logger?: Logger }) {
|
24
25
|
super()
|
@@ -45,11 +46,20 @@ export class BaseTask extends EventEmitter implements IBaseTask {
|
|
45
46
|
}
|
46
47
|
|
47
48
|
prePollHandler(): boolean {
|
48
|
-
if
|
49
|
-
|
49
|
+
if(config.isMaintenanceMode()){
|
50
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.')
|
51
|
+
return false
|
50
52
|
}
|
51
53
|
|
52
|
-
|
54
|
+
if (this.exceptLeadNode) {
|
55
|
+
return !config.isLeadNode();
|
56
|
+
}
|
57
|
+
|
58
|
+
if (this.leadNodeOnly) {
|
59
|
+
return config.isLeadNode()
|
60
|
+
}
|
61
|
+
|
62
|
+
return true
|
53
63
|
}
|
54
64
|
|
55
65
|
async pollHandler() {
|
@@ -220,8 +220,6 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
220
220
|
}
|
221
221
|
|
222
222
|
async start(): Promise<void> {
|
223
|
-
this.logger.info(`Starting execution watcher on interop chain`);
|
224
|
-
|
225
223
|
this.provider = new ethers.providers.JsonRpcProvider(
|
226
224
|
getRpcProviderUrl(this.chainId)
|
227
225
|
);
|
@@ -8,7 +8,7 @@ import { ChainId } from "@/types";
|
|
8
8
|
import config from "@/config";
|
9
9
|
import { InteropBridgeToken } from "@/typechain";
|
10
10
|
|
11
|
-
class
|
11
|
+
class SyncBurnEvents extends BaseTask {
|
12
12
|
contractAddress: string;
|
13
13
|
provider: ethers.providers.JsonRpcProvider;
|
14
14
|
contract: InteropBridgeToken;
|
@@ -17,7 +17,7 @@ class SyncWithdrawEvents extends BaseTask {
|
|
17
17
|
|
18
18
|
constructor({ chainId, itokenAddress }: { chainId: ChainId, itokenAddress: string }) {
|
19
19
|
super({
|
20
|
-
logger: new Logger("InteropBridgeToken::
|
20
|
+
logger: new Logger("InteropBridgeToken::SyncBurnEvents"),
|
21
21
|
})
|
22
22
|
this.chainId = chainId;
|
23
23
|
this.itokenAddress = itokenAddress;
|
@@ -41,13 +41,13 @@ class SyncWithdrawEvents extends BaseTask {
|
|
41
41
|
continue;
|
42
42
|
}
|
43
43
|
|
44
|
-
const { to, amount,
|
44
|
+
const { to, amount, sourceChainId, targetChainId } = event.args;
|
45
45
|
|
46
46
|
const uniqueIdentifier = {
|
47
47
|
action: 'withdraw',
|
48
48
|
submitTransactionHash: event.transactionHash,
|
49
|
-
sourceChainId:
|
50
|
-
targetChainId:
|
49
|
+
sourceChainId: sourceChainId,
|
50
|
+
targetChainId: targetChainId,
|
51
51
|
}
|
52
52
|
|
53
53
|
if (await Transaction.findOne({ where: uniqueIdentifier })) {
|
@@ -77,14 +77,16 @@ class SyncWithdrawEvents extends BaseTask {
|
|
77
77
|
to,
|
78
78
|
amount: amount.toString(),
|
79
79
|
itoken: this.itokenAddress,
|
80
|
-
|
80
|
+
sourceChainId: sourceChainId,
|
81
|
+
targetChainId: targetChainId,
|
81
82
|
},
|
82
83
|
|
83
84
|
sourceEvent: {
|
84
85
|
to,
|
85
86
|
amount: amount.toString(),
|
86
87
|
itoken: this.itokenAddress,
|
87
|
-
|
88
|
+
sourceChainId: sourceChainId,
|
89
|
+
targetChainId: targetChainId,
|
88
90
|
},
|
89
91
|
status: "pending",
|
90
92
|
})
|
@@ -102,8 +104,6 @@ class SyncWithdrawEvents extends BaseTask {
|
|
102
104
|
}
|
103
105
|
|
104
106
|
async start(): Promise<void> {
|
105
|
-
this.logger.info(`Starting execution watcher on interop chain`);
|
106
|
-
|
107
107
|
this.provider = new ethers.providers.JsonRpcProvider(
|
108
108
|
getRpcProviderUrl(this.chainId)
|
109
109
|
);
|
@@ -118,4 +118,4 @@ class SyncWithdrawEvents extends BaseTask {
|
|
118
118
|
}
|
119
119
|
}
|
120
120
|
|
121
|
-
export default
|
121
|
+
export default SyncBurnEvents;
|
@@ -0,0 +1,99 @@
|
|
1
|
+
import { BaseTask } from "../BaseTask";
|
2
|
+
import Logger from '@/logger';
|
3
|
+
import { ethers } from "ethers";
|
4
|
+
import abi from "@/abi";
|
5
|
+
import { Transaction } from "@/db";
|
6
|
+
import { getContract, getRpcProviderUrl } from "@/utils";
|
7
|
+
import { ChainId } from "@/types";
|
8
|
+
import config from "@/config";
|
9
|
+
import { InteropBridgeToken } from "@/typechain";
|
10
|
+
|
11
|
+
class SyncMintEvents extends BaseTask {
|
12
|
+
contractAddress: string;
|
13
|
+
provider: ethers.providers.JsonRpcProvider;
|
14
|
+
contract: InteropBridgeToken;
|
15
|
+
chainId: ChainId;
|
16
|
+
itokenAddress: string;
|
17
|
+
|
18
|
+
constructor({ chainId, itokenAddress }: { chainId: ChainId, itokenAddress: string }) {
|
19
|
+
super({
|
20
|
+
logger: new Logger("InteropBridgeToken::SyncMintEvents"),
|
21
|
+
})
|
22
|
+
this.chainId = chainId;
|
23
|
+
this.itokenAddress = itokenAddress;
|
24
|
+
}
|
25
|
+
|
26
|
+
async pollHandler() {
|
27
|
+
const currentBlock = await this.provider.getBlockNumber();
|
28
|
+
|
29
|
+
const events = await this.contract.queryFilter(
|
30
|
+
this.contract.filters.Mint(),
|
31
|
+
currentBlock - 500,
|
32
|
+
currentBlock,
|
33
|
+
);
|
34
|
+
|
35
|
+
for (const event of events) {
|
36
|
+
|
37
|
+
try {
|
38
|
+
if (!event.args) {
|
39
|
+
continue;
|
40
|
+
}
|
41
|
+
|
42
|
+
const { sourceChainId, targetChainId, amount, to, submitTransactionHash } = event.args;
|
43
|
+
|
44
|
+
const uniqueIdentifier = {
|
45
|
+
action: 'deposit',
|
46
|
+
submitTransactionHash: submitTransactionHash,
|
47
|
+
sourceChainId: sourceChainId,
|
48
|
+
targetChainId: targetChainId,
|
49
|
+
|
50
|
+
targetEvent: null
|
51
|
+
}
|
52
|
+
|
53
|
+
const transaction = await Transaction.findOne({ where: uniqueIdentifier });
|
54
|
+
|
55
|
+
if(! transaction){
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
|
59
|
+
const tx = await event.getTransaction()
|
60
|
+
|
61
|
+
transaction.targetStatus = 'success'
|
62
|
+
transaction.targetErrors = []
|
63
|
+
transaction.targetTransactionHash = tx.hash
|
64
|
+
transaction.targetEvent = {
|
65
|
+
sourceChainId,
|
66
|
+
targetChainId,
|
67
|
+
amount: amount.toString(),
|
68
|
+
to,
|
69
|
+
submitTransactionHash
|
70
|
+
}
|
71
|
+
transaction.status = 'success'
|
72
|
+
|
73
|
+
await transaction.save()
|
74
|
+
|
75
|
+
this.logger.info(
|
76
|
+
`Mint confirmation received: ${transaction.transactionHash} `
|
77
|
+
);
|
78
|
+
} catch (error) {
|
79
|
+
this.logger.error(error);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
async start(): Promise<void> {
|
85
|
+
this.provider = new ethers.providers.JsonRpcProvider(
|
86
|
+
getRpcProviderUrl(this.chainId)
|
87
|
+
);
|
88
|
+
|
89
|
+
this.contract = getContract<InteropBridgeToken>(
|
90
|
+
this.itokenAddress,
|
91
|
+
abi.interopBridgeToken,
|
92
|
+
new ethers.Wallet(config.privateKey!, this.provider)
|
93
|
+
);
|
94
|
+
|
95
|
+
await super.start()
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
export default SyncMintEvents;
|