@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.
- package/dist/package.json +2 -2
- package/dist/src/abi/interopBridgeToken.json +21 -9
- package/dist/src/abi/interopXGateway.json +11 -11
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +3 -0
- 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/db/models/transaction.js +8 -0
- package/dist/src/gnosis/actions/deposit.js +48 -0
- package/dist/src/gnosis/actions/index.js +11 -0
- package/dist/src/gnosis/actions/withdraw.js +50 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +31 -21
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
- package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +2 -0
- package/dist/src/net/protocol/index.js +17 -7
- package/dist/src/tasks/AutoUpdateTask.js +11 -8
- package/dist/src/tasks/BaseTask.js +4 -0
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +17 -1
- package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -8
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +16 -1
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -2
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
- package/dist/src/tasks/index.js +16 -5
- 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 +1 -82
- package/package.json +2 -2
- package/src/abi/interopBridgeToken.json +21 -9
- package/src/abi/interopXGateway.json +11 -11
- package/src/alias.ts +6 -0
- package/src/api/index.ts +3 -0
- package/src/config/index.ts +9 -1
- package/src/constants/addresses.ts +1 -1
- package/src/constants/itokens.ts +1 -1
- package/src/db/models/transaction.ts +10 -0
- package/src/gnosis/actions/deposit.ts +63 -0
- package/src/gnosis/actions/index.ts +7 -0
- package/src/gnosis/actions/withdraw.ts +67 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +44 -25
- package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
- package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +3 -1
- package/src/net/protocol/index.ts +17 -7
- package/src/tasks/AutoUpdateTask.ts +15 -14
- package/src/tasks/BaseTask.ts +5 -0
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +24 -6
- package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -13
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +22 -5
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -2
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
- package/src/tasks/index.ts +24 -5
- 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 +1 -122
- package/tsconfig.json +7 -2
@@ -1,15 +1,16 @@
|
|
1
1
|
import { BaseTask } from "./BaseTask";
|
2
2
|
import Logger from '@/logger';
|
3
|
-
import
|
4
|
-
import spawn from '
|
3
|
+
import spawnAsync from 'await-spawn';
|
4
|
+
import { spawn } from 'child_process'
|
5
5
|
import config from "@/config";
|
6
6
|
import wait from "waait";
|
7
7
|
import packageJson from "../../package.json";
|
8
8
|
|
9
9
|
const currentVersion = packageJson.version;
|
10
|
+
const tag = config.staging ? 'dev' : 'latest';
|
10
11
|
|
11
12
|
class AutoUpdateTask extends BaseTask {
|
12
|
-
pollIntervalMs: number = 60 *
|
13
|
+
pollIntervalMs: number = 60 * 10 * 1000
|
13
14
|
|
14
15
|
constructor() {
|
15
16
|
super({
|
@@ -23,22 +24,20 @@ class AutoUpdateTask extends BaseTask {
|
|
23
24
|
|
24
25
|
async getInstalledVersion() {
|
25
26
|
try {
|
26
|
-
const stdout = await
|
27
|
+
const stdout = await spawnAsync('npm', ['-g', 'ls', '--depth=0', '--json'])
|
27
28
|
return JSON.parse(stdout.toString()).dependencies[packageJson.name].version
|
28
29
|
} catch (error) {
|
29
30
|
this.logger.error(error)
|
30
|
-
|
31
31
|
return currentVersion
|
32
32
|
}
|
33
33
|
}
|
34
34
|
|
35
35
|
async getLatestVersion() {
|
36
36
|
try {
|
37
|
-
const stdout = await
|
38
|
-
return stdout.toString()
|
37
|
+
const stdout = await spawnAsync('npm', ['view', `${packageJson.name}@${tag}`, 'version'])
|
38
|
+
return stdout.toString().trim()
|
39
39
|
} catch (error) {
|
40
40
|
this.logger.error(error)
|
41
|
-
|
42
41
|
return currentVersion
|
43
42
|
}
|
44
43
|
}
|
@@ -52,12 +51,9 @@ class AutoUpdateTask extends BaseTask {
|
|
52
51
|
|
53
52
|
this.logger.warn(`New version ${version} available.`)
|
54
53
|
|
55
|
-
|
56
54
|
this.logger.info('Updating...')
|
57
55
|
|
58
|
-
|
59
|
-
spawner.child.on(console.log)
|
60
|
-
await spawner
|
56
|
+
await spawnAsync('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
61
57
|
|
62
58
|
await wait(5000)
|
63
59
|
|
@@ -69,11 +65,16 @@ class AutoUpdateTask extends BaseTask {
|
|
69
65
|
this.logger.warn(`Installed version ${version}`)
|
70
66
|
this.logger.warn(`Restarting...`)
|
71
67
|
|
72
|
-
|
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), {
|
73
71
|
cwd: process.cwd(),
|
74
|
-
stdio: "inherit"
|
72
|
+
stdio: "inherit",
|
73
|
+
// shell: process.env.SHELL,
|
75
74
|
});
|
76
75
|
|
76
|
+
subprocess.unref();
|
77
|
+
|
77
78
|
process.exit()
|
78
79
|
}
|
79
80
|
}
|
package/src/tasks/BaseTask.ts
CHANGED
@@ -46,6 +46,11 @@ export class BaseTask extends EventEmitter implements IBaseTask {
|
|
46
46
|
}
|
47
47
|
|
48
48
|
prePollHandler(): boolean {
|
49
|
+
if(config.isMaintenanceMode()){
|
50
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.')
|
51
|
+
return false
|
52
|
+
}
|
53
|
+
|
49
54
|
if (this.exceptLeadNode) {
|
50
55
|
return !config.isLeadNode();
|
51
56
|
}
|
@@ -3,19 +3,20 @@ import Logger from '@/logger';
|
|
3
3
|
import { BigNumber, ethers } from "ethers";
|
4
4
|
import abi from "@/abi";
|
5
5
|
import { Transaction } from "@/db";
|
6
|
-
import {
|
6
|
+
import { buildSignatureBytes, getContract, getRpcProviderUrl, Signature } from "@/utils";
|
7
7
|
import { addresses } from "@/constants";
|
8
8
|
import { ChainId } from "@/types";
|
9
9
|
import config from "@/config";
|
10
|
-
import { GnosisSafe
|
10
|
+
import { GnosisSafe } from "@/typechain";
|
11
11
|
import { Op } from "sequelize";
|
12
12
|
import wait from "waait";
|
13
13
|
import { peerPool, protocol } from "@/net";
|
14
14
|
import { LogDescription } from "ethers/lib/utils";
|
15
|
+
import { buildGnosisAction } from "@/gnosis";
|
15
16
|
|
16
17
|
const generateGnosisTransaction = async (transactionData: any, safeContract: GnosisSafe) => {
|
17
18
|
console.log(transactionData);
|
18
|
-
|
19
|
+
|
19
20
|
let isExecuted = await safeContract.dataHashes(
|
20
21
|
await safeContract.getTransactionHash(
|
21
22
|
transactionData.to,
|
@@ -95,7 +96,7 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
95
96
|
}
|
96
97
|
|
97
98
|
console.log(`Processing transaction ${transaction.transactionHash}`);
|
98
|
-
|
99
|
+
|
99
100
|
transaction.targetStatus = 'pending';
|
100
101
|
await transaction.save();
|
101
102
|
|
@@ -119,9 +120,23 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
119
120
|
const ownersThreshold = await safeContract.getThreshold();
|
120
121
|
await wait(10000);
|
121
122
|
|
123
|
+
let data, logs = [];
|
124
|
+
|
125
|
+
try {
|
126
|
+
({ data, logs } = await buildGnosisAction(transaction));
|
127
|
+
} catch (error) {
|
128
|
+
console.log(error);
|
129
|
+
transaction.targetStatus = 'failed';
|
130
|
+
transaction.targetErrors = [error.message];
|
131
|
+
transaction.status = 'failed'
|
132
|
+
await transaction.save();
|
133
|
+
protocol.sendTransaction(transaction)
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
|
122
137
|
let gnosisTx = await generateGnosisTransaction({
|
123
138
|
baseGas: "0",
|
124
|
-
data
|
139
|
+
data,
|
125
140
|
gasPrice: "0",
|
126
141
|
gasToken: "0x0000000000000000000000000000000000000000",
|
127
142
|
nonce: '0',
|
@@ -140,7 +155,7 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
140
155
|
console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
|
141
156
|
|
142
157
|
console.log(ownerPeerIds);
|
143
|
-
|
158
|
+
|
144
159
|
const signatures = await protocol.requestSignatures({
|
145
160
|
type: 'source',
|
146
161
|
transactionHash: transaction.transactionHash,
|
@@ -208,6 +223,7 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
208
223
|
console.log('ExecutionSuccess')
|
209
224
|
transaction.targetStatus = 'success'
|
210
225
|
transaction.targetTransactionHash = txSent.hash
|
226
|
+
transaction.targetLogs = logs
|
211
227
|
transaction.status = 'success'
|
212
228
|
await transaction.save();
|
213
229
|
} else {
|
@@ -217,6 +233,8 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
217
233
|
transaction.status = 'failed'
|
218
234
|
await transaction.save();
|
219
235
|
}
|
236
|
+
|
237
|
+
protocol.sendTransaction(transaction)
|
220
238
|
}
|
221
239
|
|
222
240
|
async start(): Promise<void> {
|
@@ -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 })) {
|
@@ -62,7 +62,6 @@ class SyncWithdrawEvents extends BaseTask {
|
|
62
62
|
from: tx.from,
|
63
63
|
to,
|
64
64
|
|
65
|
-
|
66
65
|
submitTransactionHash: event.transactionHash,
|
67
66
|
submitBlockNumber: event.blockNumber,
|
68
67
|
|
@@ -70,21 +69,22 @@ class SyncWithdrawEvents extends BaseTask {
|
|
70
69
|
sourceTransactionHash: event.transactionHash,
|
71
70
|
sourceBlockNumber: event.blockNumber,
|
72
71
|
sourceStatus: "success",
|
73
|
-
|
74
72
|
targetStatus: "uninitialised",
|
75
73
|
|
76
74
|
submitEvent: {
|
77
|
-
to,
|
75
|
+
to,
|
78
76
|
amount: amount.toString(),
|
79
77
|
itoken: this.itokenAddress,
|
80
|
-
|
78
|
+
sourceChainId: sourceChainId,
|
79
|
+
targetChainId: targetChainId,
|
81
80
|
},
|
82
81
|
|
83
82
|
sourceEvent: {
|
84
|
-
to,
|
85
|
-
amount: amount.toString(),
|
83
|
+
to,
|
84
|
+
amount: amount.toString(),
|
86
85
|
itoken: this.itokenAddress,
|
87
|
-
|
86
|
+
sourceChainId: sourceChainId,
|
87
|
+
targetChainId: targetChainId,
|
88
88
|
},
|
89
89
|
status: "pending",
|
90
90
|
})
|
@@ -116,4 +116,4 @@ class SyncWithdrawEvents extends BaseTask {
|
|
116
116
|
}
|
117
117
|
}
|
118
118
|
|
119
|
-
export default
|
119
|
+
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;
|
@@ -3,7 +3,7 @@ import Logger from '@/logger';
|
|
3
3
|
import { BigNumber, ethers } from "ethers";
|
4
4
|
import abi from "@/abi";
|
5
5
|
import { Transaction } from "@/db";
|
6
|
-
import {
|
6
|
+
import { buildSignatureBytes, getContract, getRpcProviderUrl, Signature } from "@/utils";
|
7
7
|
import { addresses } from "@/constants";
|
8
8
|
import { ChainId } from "@/types";
|
9
9
|
import config from "@/config";
|
@@ -12,10 +12,11 @@ import { Op } from "sequelize";
|
|
12
12
|
import wait from "waait";
|
13
13
|
import { peerPool, protocol } from "@/net";
|
14
14
|
import { LogDescription } from "ethers/lib/utils";
|
15
|
+
import { buildGnosisAction } from "@/gnosis";
|
15
16
|
|
16
17
|
const generateGnosisTransaction = async (transactionData: any, safeContract: GnosisSafe) => {
|
17
18
|
console.log(transactionData);
|
18
|
-
|
19
|
+
|
19
20
|
let isExecuted = await safeContract.dataHashes(
|
20
21
|
await safeContract.getTransactionHash(
|
21
22
|
transactionData.to,
|
@@ -97,7 +98,7 @@ class ProcessDepositEvents extends BaseTask {
|
|
97
98
|
}
|
98
99
|
|
99
100
|
console.log(`Processing transaction ${transaction.transactionHash}`);
|
100
|
-
|
101
|
+
|
101
102
|
transaction.targetStatus = 'pending';
|
102
103
|
await transaction.save();
|
103
104
|
|
@@ -121,9 +122,24 @@ class ProcessDepositEvents extends BaseTask {
|
|
121
122
|
const ownersThreshold = await safeContract.getThreshold();
|
122
123
|
await wait(10000);
|
123
124
|
|
125
|
+
let data, logs = [];
|
126
|
+
|
127
|
+
try {
|
128
|
+
({ data, logs } = await buildGnosisAction(transaction));
|
129
|
+
|
130
|
+
} catch (error) {
|
131
|
+
console.log(error);
|
132
|
+
transaction.targetStatus = 'failed';
|
133
|
+
transaction.targetErrors = [error.message];
|
134
|
+
transaction.status = 'failed'
|
135
|
+
await transaction.save();
|
136
|
+
protocol.sendTransaction(transaction)
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
|
124
140
|
let gnosisTx = await generateGnosisTransaction({
|
125
141
|
baseGas: "0",
|
126
|
-
data
|
142
|
+
data,
|
127
143
|
gasPrice: "0",
|
128
144
|
gasToken: "0x0000000000000000000000000000000000000000",
|
129
145
|
nonce: '0',
|
@@ -142,7 +158,7 @@ class ProcessDepositEvents extends BaseTask {
|
|
142
158
|
console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
|
143
159
|
|
144
160
|
console.log(ownerPeerIds);
|
145
|
-
|
161
|
+
|
146
162
|
const signatures = await protocol.requestSignatures({
|
147
163
|
type: 'source',
|
148
164
|
transactionHash: transaction.transactionHash,
|
@@ -210,6 +226,7 @@ class ProcessDepositEvents extends BaseTask {
|
|
210
226
|
console.log('ExecutionSuccess')
|
211
227
|
transaction.targetStatus = 'success'
|
212
228
|
transaction.targetTransactionHash = txSent.hash
|
229
|
+
transaction.targetLogs = logs;
|
213
230
|
transaction.status = 'success'
|
214
231
|
await transaction.save();
|
215
232
|
} else {
|
@@ -45,8 +45,8 @@ class SyncDepositEvents extends BaseTask {
|
|
45
45
|
const uniqueIdentifier = {
|
46
46
|
action: 'deposit',
|
47
47
|
submitTransactionHash: event.transactionHash,
|
48
|
-
sourceChainId: sourceChainId
|
49
|
-
targetChainId: targetChainId
|
48
|
+
sourceChainId: sourceChainId,
|
49
|
+
targetChainId: targetChainId,
|
50
50
|
}
|
51
51
|
|
52
52
|
if (await Transaction.findOne({ where: uniqueIdentifier })) {
|
@@ -0,0 +1,105 @@
|
|
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 { addresses } from "@/constants";
|
8
|
+
import { ChainId } from "@/types";
|
9
|
+
import config from "@/config";
|
10
|
+
import { InteropXGateway } from "@/typechain";
|
11
|
+
|
12
|
+
class SyncWithdrawEvents extends BaseTask {
|
13
|
+
contractAddress: string;
|
14
|
+
provider: ethers.providers.JsonRpcProvider;
|
15
|
+
contract: InteropXGateway;
|
16
|
+
chainId: ChainId;
|
17
|
+
|
18
|
+
constructor({ chainId }: { chainId: ChainId }) {
|
19
|
+
super({
|
20
|
+
logger: new Logger("InteropXGateway::SyncWithdrawEvents"),
|
21
|
+
})
|
22
|
+
this.chainId = chainId;
|
23
|
+
}
|
24
|
+
|
25
|
+
async pollHandler() {
|
26
|
+
const currentBlock = await this.provider.getBlockNumber();
|
27
|
+
|
28
|
+
const events = await this.contract.queryFilter(
|
29
|
+
this.contract.filters.LogGatewayWithdraw(),
|
30
|
+
currentBlock - 500,
|
31
|
+
currentBlock,
|
32
|
+
);
|
33
|
+
|
34
|
+
let processedEvents = 0;
|
35
|
+
|
36
|
+
for (const event of events) {
|
37
|
+
|
38
|
+
try {
|
39
|
+
if (!event.args) {
|
40
|
+
continue;
|
41
|
+
}
|
42
|
+
|
43
|
+
const { user, token, amount, sourceChainId, targetChainId, transactionHash } = event.args;
|
44
|
+
|
45
|
+
const uniqueIdentifier = {
|
46
|
+
action: 'withdraw',
|
47
|
+
submitTransactionHash: transactionHash,
|
48
|
+
sourceChainId: sourceChainId,
|
49
|
+
targetChainId: targetChainId,
|
50
|
+
|
51
|
+
targetEvent: null
|
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
|
+
user,
|
66
|
+
token,
|
67
|
+
amount: amount.toString(),
|
68
|
+
sourceChainId,
|
69
|
+
targetChainId,
|
70
|
+
transactionHash,
|
71
|
+
}
|
72
|
+
transaction.status = 'success'
|
73
|
+
|
74
|
+
await transaction.save()
|
75
|
+
|
76
|
+
this.logger.info(
|
77
|
+
`Witdraw confirmation received: ${transaction.transactionHash} `
|
78
|
+
);
|
79
|
+
} catch (error) {
|
80
|
+
this.logger.error(error);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
if (processedEvents > 0)
|
85
|
+
this.logger.info(`${processedEvents} events processed`);
|
86
|
+
}
|
87
|
+
|
88
|
+
async start(): Promise<void> {
|
89
|
+
this.contractAddress = addresses[this.chainId].interopXGateway;
|
90
|
+
|
91
|
+
this.provider = new ethers.providers.JsonRpcProvider(
|
92
|
+
getRpcProviderUrl(this.chainId)
|
93
|
+
);
|
94
|
+
|
95
|
+
this.contract = getContract<InteropXGateway>(
|
96
|
+
this.contractAddress,
|
97
|
+
abi.interopXGateway,
|
98
|
+
new ethers.Wallet(config.privateKey!, this.provider)
|
99
|
+
);
|
100
|
+
|
101
|
+
await super.start()
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
export default SyncWithdrawEvents;
|
@@ -49,10 +49,12 @@ class SyncTransactionStatusTask extends BaseTask {
|
|
49
49
|
transaction.sourceStatus = transactionStatus.sourceStatus
|
50
50
|
transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash
|
51
51
|
transaction.sourceErrors = transactionStatus.sourceErrors
|
52
|
+
transaction.sourceLogs = transactionStatus.sourceLogs
|
52
53
|
|
53
54
|
transaction.targetStatus = transactionStatus.targetStatus
|
54
55
|
transaction.targetTransactionHash = transactionStatus.targetTransactionHash
|
55
56
|
transaction.targetErrors = transactionStatus.targetErrors
|
57
|
+
transaction.targetLogs = transactionStatus.targetLogs
|
56
58
|
|
57
59
|
transaction.status = transactionStatus.status
|
58
60
|
|
package/src/tasks/index.ts
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
import { BaseTask } from "./BaseTask";
|
2
2
|
import InteropXGatewayProcessDepositEvents from "./InteropXGateway/ProcessDepositEvents";
|
3
3
|
import InteropXGatewaySyncDepositEvents from "./InteropXGateway/SyncDepositEvents";
|
4
|
+
import InteropXGatewaySyncWithdrawEvents from "./InteropXGateway/SyncWithdrawtEvents";
|
4
5
|
|
5
|
-
import InteropBridgeSyncWithdrawEvents from "./InteropBridge/SyncWithdrawEvents";
|
6
6
|
import InteropBridgeProcessWithdrawEvents from "./InteropBridge/ProcessWithdrawEvents";
|
7
|
-
import
|
7
|
+
import InteropBridgeSyncBurnEvents from "./InteropBridge/SyncBurnEvents";
|
8
|
+
import InteropBridgeSyncMintEvents from "./InteropBridge/SyncMintEvents";
|
9
|
+
|
8
10
|
import SyncTransactionStatusTask from "./Transactions/SyncTransactionStatusTask";
|
9
11
|
|
12
|
+
import AutoUpdateTask from "./AutoUpdateTask";
|
13
|
+
|
10
14
|
export class Tasks {
|
11
15
|
|
12
16
|
tasks: BaseTask[] = [
|
13
17
|
new SyncTransactionStatusTask(),
|
14
18
|
new AutoUpdateTask(),
|
15
19
|
|
20
|
+
// InteropXGateway
|
21
|
+
|
16
22
|
new InteropXGatewaySyncDepositEvents({
|
17
23
|
chainId: 43114
|
18
24
|
}),
|
@@ -21,13 +27,26 @@ export class Tasks {
|
|
21
27
|
chainId: 43114
|
22
28
|
}),
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
30
|
+
|
31
|
+
new InteropXGatewaySyncWithdrawEvents({
|
32
|
+
chainId: 43114
|
27
33
|
}),
|
28
34
|
|
35
|
+
|
36
|
+
// InteropBridge
|
37
|
+
|
29
38
|
new InteropBridgeProcessWithdrawEvents({
|
30
39
|
chainId: 137,
|
40
|
+
}),
|
41
|
+
|
42
|
+
new InteropBridgeSyncMintEvents({
|
43
|
+
chainId: 137,
|
44
|
+
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
45
|
+
}),
|
46
|
+
|
47
|
+
new InteropBridgeSyncBurnEvents({
|
48
|
+
chainId: 137,
|
49
|
+
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
31
50
|
})
|
32
51
|
];
|
33
52
|
|