@instadapp/interop-x 0.0.0-dev.14afa72 → 0.0.0-dev.1f933be
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/index.js +2 -4
- package/dist/src/abi/interopXContract.json +391 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/constants/addresses.js +3 -3
- package/dist/src/constants/index.js +0 -1
- package/dist/src/db/models/transaction.js +19 -9
- package/dist/src/gnosis/actions/index.js +0 -2
- package/dist/src/gnosis/actions/withdraw/index.js +41 -0
- package/dist/src/gnosis/index.js +1 -1
- package/dist/src/index.js +7 -19
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +4 -0
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +2 -0
- package/dist/src/net/protocol/index.js +11 -1
- package/dist/src/tasks/{InteropBridge/ProcessWithdrawEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +32 -47
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
- package/dist/src/tasks/index.js +10 -30
- package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +14 -3
- package/package.json +2 -2
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +391 -0
- package/src/alias.ts +6 -0
- package/src/constants/addresses.ts +3 -3
- package/src/constants/index.ts +0 -1
- package/src/db/models/transaction.ts +49 -21
- package/src/gnosis/actions/index.ts +0 -2
- package/src/gnosis/actions/withdraw/index.ts +56 -0
- package/src/gnosis/index.ts +2 -2
- package/src/index.ts +6 -18
- package/src/net/protocol/dial/SignatureDialProtocol.ts +4 -0
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +3 -1
- package/src/net/protocol/index.ts +13 -3
- package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +58 -96
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
- package/src/tasks/index.ts +12 -39
- package/src/typechain/InteropXContract.ts +524 -0
- package/src/typechain/factories/InteropXContract__factory.ts +533 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +45 -3
- package/tsconfig.json +7 -2
- package/dist/src/abi/interopBridgeToken.json +0 -298
- package/dist/src/abi/interopXGateway.json +0 -184
- package/dist/src/constants/itokens.js +0 -13
- package/dist/src/gnosis/actions/deposit.js +0 -48
- package/dist/src/gnosis/actions/withdraw.js +0 -50
- package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +0 -71
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +0 -67
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -164
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +0 -72
- package/dist/src/typechain/InteropXGateway.js +0 -2
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -471
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -298
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/gnosis/actions/deposit.ts +0 -63
- package/src/gnosis/actions/withdraw.ts +0 -67
- package/src/tasks/InteropBridge/SyncBurnEvents.ts +0 -119
- package/src/tasks/InteropBridge/SyncMintEvents.ts +0 -99
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -260
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +0 -105
- package/src/typechain/InteropBridgeToken.ts +0 -692
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -478
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -26,6 +26,10 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
|
|
26
26
|
}
|
27
27
|
|
28
28
|
async response(data: ISignatureRequest): Promise<ISignatureResponse> {
|
29
|
+
console.log({
|
30
|
+
tag: 'SignatureDialProtocol',
|
31
|
+
data
|
32
|
+
})
|
29
33
|
const signer = config.wallet;
|
30
34
|
|
31
35
|
let transaction: Transaction | null;
|
@@ -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
|
}
|
@@ -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 {
|
@@ -68,23 +68,33 @@ class Protocol extends EventEmitter {
|
|
68
68
|
Buffer.from(transaction.sourceStatus),
|
69
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
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
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()|| null,
|
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
|
}),
|
@@ -1,67 +1,33 @@
|
|
1
1
|
import { BaseTask } from "../BaseTask";
|
2
2
|
import Logger from '@/logger';
|
3
|
-
import {
|
3
|
+
import { ethers, Wallet } from "ethers";
|
4
4
|
import abi from "@/abi";
|
5
5
|
import { Transaction } from "@/db";
|
6
|
-
import { buildSignatureBytes, getContract, getRpcProviderUrl, Signature } from "@/utils";
|
6
|
+
import { buildSignatureBytes, generateGnosisTransaction, generateInteropTransactionHash, getContract, getRpcProviderUrl, Signature } from "@/utils";
|
7
7
|
import { addresses } from "@/constants";
|
8
|
+
import { Op } from "sequelize";
|
8
9
|
import { ChainId } from "@/types";
|
9
10
|
import config from "@/config";
|
10
|
-
import { GnosisSafe } from "@/typechain";
|
11
|
-
import { Op } from "sequelize";
|
11
|
+
import { GnosisSafe, InteropXContract } from "@/typechain";
|
12
12
|
import wait from "waait";
|
13
|
+
import { buildGnosisAction } from "@/gnosis";
|
13
14
|
import { peerPool, protocol } from "@/net";
|
14
15
|
import { LogDescription } from "ethers/lib/utils";
|
15
|
-
import { buildGnosisAction } from "@/gnosis";
|
16
|
-
|
17
|
-
const generateGnosisTransaction = async (transactionData: any, safeContract: GnosisSafe) => {
|
18
|
-
console.log(transactionData);
|
19
|
-
|
20
|
-
let isExecuted = await safeContract.dataHashes(
|
21
|
-
await safeContract.getTransactionHash(
|
22
|
-
transactionData.to,
|
23
|
-
transactionData.value,
|
24
|
-
transactionData.data,
|
25
|
-
transactionData.operation,
|
26
|
-
transactionData.safeTxGas,
|
27
|
-
transactionData.baseGas,
|
28
|
-
transactionData.gasPrice,
|
29
|
-
transactionData.gasToken,
|
30
|
-
transactionData.refundReceiver,
|
31
|
-
transactionData.nonce
|
32
|
-
)
|
33
|
-
)
|
34
|
-
|
35
|
-
while (isExecuted == 1) {
|
36
|
-
transactionData.safeTxGas = BigNumber.from(String(transactionData.safeTxGas)).add(1).toString()
|
37
|
-
|
38
|
-
isExecuted = await safeContract.dataHashes(
|
39
|
-
await safeContract.getTransactionHash(
|
40
|
-
transactionData.to,
|
41
|
-
transactionData.value,
|
42
|
-
transactionData.data,
|
43
|
-
transactionData.operation,
|
44
|
-
transactionData.safeTxGas,
|
45
|
-
transactionData.baseGas,
|
46
|
-
transactionData.gasPrice,
|
47
|
-
transactionData.gasToken,
|
48
|
-
transactionData.refundReceiver,
|
49
|
-
transactionData.nonce
|
50
|
-
)
|
51
|
-
)
|
52
|
-
}
|
53
|
-
|
54
|
-
return transactionData
|
55
|
-
}
|
56
16
|
|
57
|
-
class
|
17
|
+
class ProccessBridgeRequestEvents extends BaseTask {
|
18
|
+
contractAddress: string;
|
19
|
+
safeContractAddress: string;
|
58
20
|
provider: ethers.providers.JsonRpcProvider;
|
21
|
+
contract: InteropXContract;
|
22
|
+
safeContract: GnosisSafe;
|
59
23
|
chainId: ChainId;
|
60
|
-
|
24
|
+
sourceWallet: Wallet;
|
25
|
+
|
26
|
+
leadNodeOnly: boolean = true;
|
61
27
|
|
62
28
|
constructor({ chainId }: { chainId: ChainId }) {
|
63
29
|
super({
|
64
|
-
logger: new Logger("
|
30
|
+
logger: new Logger("InteropXContract::ProccessBridgeRequestEvents"),
|
65
31
|
})
|
66
32
|
this.chainId = chainId;
|
67
33
|
}
|
@@ -72,19 +38,17 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
72
38
|
const transaction = await Transaction.findOne({
|
73
39
|
where: {
|
74
40
|
status: 'pending',
|
75
|
-
sourceStatus: '
|
76
|
-
|
77
|
-
action: 'withdraw',
|
78
|
-
sourceCreatedAt: {
|
41
|
+
sourceStatus: 'uninitialised',
|
42
|
+
createdAt: {
|
79
43
|
[Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
80
44
|
},
|
81
|
-
|
45
|
+
sourceDelayUntil: {
|
82
46
|
[Op.or]: {
|
83
47
|
[Op.is]: null,
|
84
48
|
[Op.lt]: new Date(),
|
85
49
|
}
|
86
50
|
},
|
87
|
-
|
51
|
+
requestBlockNumber: {
|
88
52
|
[Op.lt]: blockNumber - 12,
|
89
53
|
},
|
90
54
|
sourceChainId: this.chainId,
|
@@ -100,34 +64,21 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
100
64
|
transaction.targetStatus = 'pending';
|
101
65
|
await transaction.save();
|
102
66
|
|
103
|
-
|
104
|
-
|
105
|
-
const targetChainProvider = new ethers.providers.JsonRpcProvider(
|
106
|
-
getRpcProviderUrl(transaction.targetChainId as ChainId)
|
107
|
-
);
|
108
|
-
|
109
|
-
const targetWallet = new ethers.Wallet(config.privateKey!, targetChainProvider);
|
110
|
-
|
111
|
-
const safeAddress = addresses[transaction.targetChainId].gnosisSafe;
|
112
|
-
|
113
|
-
|
114
|
-
const safeContract = getContract<GnosisSafe>(
|
115
|
-
safeAddress,
|
116
|
-
abi.gnosisSafe,
|
117
|
-
targetWallet
|
118
|
-
)
|
119
|
-
|
120
|
-
const ownersThreshold = await safeContract.getThreshold();
|
67
|
+
const ownersThreshold = await this.safeContract.getThreshold();
|
121
68
|
await wait(10000);
|
122
69
|
|
70
|
+
|
123
71
|
let data, logs = [];
|
124
72
|
|
125
73
|
try {
|
126
|
-
({ data, logs } = await buildGnosisAction(transaction));
|
74
|
+
({ data, logs } = await buildGnosisAction(transaction, 'source'));
|
75
|
+
|
127
76
|
} catch (error) {
|
128
77
|
console.log(error);
|
78
|
+
transaction.sourceStatus = 'failed';
|
79
|
+
transaction.sourceErrors = [error.message];
|
129
80
|
transaction.targetStatus = 'failed';
|
130
|
-
|
81
|
+
|
131
82
|
transaction.status = 'failed'
|
132
83
|
await transaction.save();
|
133
84
|
protocol.sendTransaction(transaction)
|
@@ -142,13 +93,13 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
142
93
|
nonce: '0',
|
143
94
|
operation: "1",
|
144
95
|
refundReceiver: "0x0000000000000000000000000000000000000000",
|
145
|
-
safeAddress:
|
96
|
+
safeAddress: this.safeContractAddress,
|
146
97
|
safeTxGas: "79668",
|
147
|
-
to: addresses[transaction.
|
98
|
+
to: addresses[transaction.sourceChainId].multisend,
|
148
99
|
value: "0",
|
149
|
-
}, safeContract);
|
100
|
+
}, this.safeContract);
|
150
101
|
|
151
|
-
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
102
|
+
const owners = await this.safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
152
103
|
|
153
104
|
const ownerPeerIds = peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id)
|
154
105
|
|
@@ -170,18 +121,17 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
170
121
|
|
171
122
|
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
172
123
|
await transaction.save();
|
173
|
-
transaction.
|
174
|
-
transaction.
|
124
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
125
|
+
transaction.sourceStatus = 'uninitialised'
|
175
126
|
|
176
127
|
await transaction.save();
|
177
128
|
const errorMessage = signatures.find(s => !!s.error)?.error;
|
178
129
|
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
179
130
|
}
|
180
131
|
|
181
|
-
|
182
132
|
console.log(`Executing transaction for execution ${transaction.transactionHash}`)
|
183
133
|
|
184
|
-
const { data: txData } = await safeContract.populateTransaction.execTransaction(
|
134
|
+
const { data: txData } = await this.safeContract.populateTransaction.execTransaction(
|
185
135
|
gnosisTx.to,
|
186
136
|
gnosisTx.value,
|
187
137
|
gnosisTx.data,
|
@@ -194,20 +144,15 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
194
144
|
buildSignatureBytes(validSignatures)
|
195
145
|
);
|
196
146
|
|
197
|
-
|
198
|
-
from:
|
199
|
-
gasPrice: BigNumber.from(120 * 10 ** 9)
|
200
|
-
to:
|
147
|
+
const txSent = await this.sourceWallet.sendTransaction({
|
148
|
+
from: this.sourceWallet.address,
|
149
|
+
gasPrice: ethers.BigNumber.from(120 * 10 ** 9),
|
150
|
+
to: this.safeContractAddress,
|
201
151
|
data: txData,
|
202
152
|
})
|
203
153
|
|
204
|
-
|
205
|
-
|
206
|
-
from: targetWallet.address,
|
207
|
-
gasPrice: BigNumber.from(120 * 10 ** 9),
|
208
|
-
to: safeAddress,
|
209
|
-
data: txData,
|
210
|
-
})
|
154
|
+
console.log(txSent);
|
155
|
+
|
211
156
|
|
212
157
|
const receipt = await txSent.wait();
|
213
158
|
|
@@ -215,7 +160,7 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
215
160
|
|
216
161
|
receipt.logs.forEach((log) => {
|
217
162
|
try {
|
218
|
-
parsedLogs.push(safeContract.interface.parseLog(log));
|
163
|
+
parsedLogs.push(this.safeContract.interface.parseLog(log));
|
219
164
|
} catch (e) { }
|
220
165
|
});
|
221
166
|
|
@@ -223,7 +168,7 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
223
168
|
console.log('ExecutionSuccess')
|
224
169
|
transaction.targetStatus = 'success'
|
225
170
|
transaction.targetTransactionHash = txSent.hash
|
226
|
-
transaction.targetLogs = logs
|
171
|
+
transaction.targetLogs = logs;
|
227
172
|
transaction.status = 'success'
|
228
173
|
await transaction.save();
|
229
174
|
} else {
|
@@ -238,12 +183,29 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
238
183
|
}
|
239
184
|
|
240
185
|
async start(): Promise<void> {
|
186
|
+
this.contractAddress = addresses[this.chainId].interopXContract;
|
187
|
+
|
241
188
|
this.provider = new ethers.providers.JsonRpcProvider(
|
242
189
|
getRpcProviderUrl(this.chainId)
|
243
190
|
);
|
244
191
|
|
192
|
+
this.sourceWallet = new ethers.Wallet(config.privateKey!, this.provider);
|
193
|
+
|
194
|
+
this.contract = getContract<InteropXContract>(
|
195
|
+
this.contractAddress,
|
196
|
+
abi.interopXContract,
|
197
|
+
this.sourceWallet
|
198
|
+
);
|
199
|
+
|
200
|
+
this.safeContractAddress = addresses[this.chainId].gnosisSafe;
|
201
|
+
this.safeContract = getContract<GnosisSafe>(
|
202
|
+
this.safeContractAddress,
|
203
|
+
abi.gnosisSafe,
|
204
|
+
this.sourceWallet
|
205
|
+
);
|
206
|
+
|
245
207
|
await super.start()
|
246
208
|
}
|
247
209
|
}
|
248
210
|
|
249
|
-
export default
|
211
|
+
export default ProccessBridgeRequestEvents;
|
@@ -0,0 +1,116 @@
|
|
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 { generateInteropTransactionHash, getContract, getRpcProviderUrl } from "@/utils";
|
7
|
+
import { addresses } from "@/constants";
|
8
|
+
import { ChainId } from "@/types";
|
9
|
+
import config from "@/config";
|
10
|
+
import { InteropXContract } from "@/typechain";
|
11
|
+
|
12
|
+
class SyncBridgeRequestEvents extends BaseTask {
|
13
|
+
contractAddress: string;
|
14
|
+
provider: ethers.providers.JsonRpcProvider;
|
15
|
+
contract: InteropXContract;
|
16
|
+
chainId: ChainId;
|
17
|
+
|
18
|
+
constructor({ chainId }: { chainId: ChainId }) {
|
19
|
+
super({
|
20
|
+
logger: new Logger("InteropXContract::SyncBridgeRequestEvents"),
|
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.LogBridgeRequest(),
|
30
|
+
currentBlock - 2000,
|
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 { bridger, position, sourceChainId, targetChainId, metadata } = event.args;
|
44
|
+
|
45
|
+
const uniqueIdentifier = {
|
46
|
+
action: 'withdraw', //todo
|
47
|
+
bridger,
|
48
|
+
requestTransactionHash: event.transactionHash,
|
49
|
+
sourceChainId: sourceChainId.toNumber(),
|
50
|
+
targetChainId: targetChainId.toNumber(),
|
51
|
+
}
|
52
|
+
|
53
|
+
let transactionHash = generateInteropTransactionHash(uniqueIdentifier);
|
54
|
+
|
55
|
+
const transaction = await Transaction.findOne({ where: { transactionHash } });
|
56
|
+
|
57
|
+
if (transaction) {
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
|
61
|
+
await Transaction.create({
|
62
|
+
transactionHash,
|
63
|
+
...uniqueIdentifier,
|
64
|
+
position,
|
65
|
+
metadata,
|
66
|
+
requestBlockNumber: event.blockNumber,
|
67
|
+
requestEvent: {
|
68
|
+
bridger,
|
69
|
+
position: {
|
70
|
+
withdraw: position.withdraw.map((v) => ({
|
71
|
+
sourceToken: v.sourceToken,
|
72
|
+
targetToken: v.targetToken,
|
73
|
+
amount: v.amount.toString()
|
74
|
+
})),
|
75
|
+
supply: position.supply.map((v) => ({
|
76
|
+
sourceToken: v.sourceToken,
|
77
|
+
targetToken: v.targetToken,
|
78
|
+
amount: v.amount.toString()
|
79
|
+
})),
|
80
|
+
},
|
81
|
+
sourceChainId: sourceChainId.toNumber(),
|
82
|
+
targetChainId: targetChainId.toNumber(),
|
83
|
+
metadata,
|
84
|
+
}
|
85
|
+
})
|
86
|
+
|
87
|
+
this.logger.info(
|
88
|
+
`New bridge request received: ${transactionHash} `
|
89
|
+
);
|
90
|
+
} catch (error) {
|
91
|
+
this.logger.error(error);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
if (processedEvents > 0)
|
96
|
+
this.logger.info(`${processedEvents} events processed`);
|
97
|
+
}
|
98
|
+
|
99
|
+
async start(): Promise<void> {
|
100
|
+
this.contractAddress = addresses[this.chainId].interopXContract;
|
101
|
+
|
102
|
+
this.provider = new ethers.providers.JsonRpcProvider(
|
103
|
+
getRpcProviderUrl(this.chainId)
|
104
|
+
);
|
105
|
+
|
106
|
+
this.contract = getContract<InteropXContract>(
|
107
|
+
this.contractAddress,
|
108
|
+
abi.interopXContract,
|
109
|
+
new ethers.Wallet(config.privateKey!, this.provider)
|
110
|
+
);
|
111
|
+
|
112
|
+
await super.start()
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
export default SyncBridgeRequestEvents;
|
@@ -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,59 +1,32 @@
|
|
1
1
|
import { BaseTask } from "./BaseTask";
|
2
|
-
import InteropXGatewayProcessDepositEvents from "./InteropXGateway/ProcessDepositEvents";
|
3
|
-
import InteropXGatewaySyncDepositEvents from "./InteropXGateway/SyncDepositEvents";
|
4
|
-
import InteropXGatewaySyncWithdrawEvents from "./InteropXGateway/SyncWithdrawtEvents";
|
5
|
-
|
6
|
-
import InteropBridgeProcessWithdrawEvents from "./InteropBridge/ProcessWithdrawEvents";
|
7
|
-
import InteropBridgeSyncBurnEvents from "./InteropBridge/SyncBurnEvents";
|
8
|
-
import InteropBridgeSyncMintEvents from "./InteropBridge/SyncMintEvents";
|
9
|
-
|
10
2
|
import SyncTransactionStatusTask from "./Transactions/SyncTransactionStatusTask";
|
11
3
|
|
12
4
|
import AutoUpdateTask from "./AutoUpdateTask";
|
13
5
|
|
6
|
+
import SyncBridgeRequestEvents from "./InteropXContract/SyncBridgeRequestEvents";
|
7
|
+
import ProccessBridgeRequestEvents from "./InteropXContract/ProcessBridgeRequestEvents";
|
8
|
+
import wait from "waait";
|
9
|
+
|
14
10
|
export class Tasks {
|
15
|
-
|
11
|
+
|
16
12
|
tasks: BaseTask[] = [
|
17
|
-
new SyncTransactionStatusTask(),
|
13
|
+
// new SyncTransactionStatusTask(),
|
18
14
|
new AutoUpdateTask(),
|
19
15
|
|
20
|
-
//
|
21
|
-
|
22
|
-
new InteropXGatewaySyncDepositEvents({
|
23
|
-
chainId: 43114
|
24
|
-
}),
|
25
|
-
|
26
|
-
new InteropXGatewayProcessDepositEvents({
|
27
|
-
chainId: 43114
|
28
|
-
}),
|
29
|
-
|
30
|
-
|
31
|
-
new InteropXGatewaySyncWithdrawEvents({
|
32
|
-
chainId: 43114
|
33
|
-
}),
|
34
|
-
|
35
|
-
|
36
|
-
// InteropBridge
|
37
|
-
|
38
|
-
new InteropBridgeProcessWithdrawEvents({
|
39
|
-
chainId: 137,
|
40
|
-
}),
|
16
|
+
// InteropXContract
|
41
17
|
|
42
|
-
new
|
43
|
-
|
44
|
-
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
45
|
-
}),
|
18
|
+
new SyncBridgeRequestEvents({ chainId: 137 }),
|
19
|
+
new SyncBridgeRequestEvents({ chainId: 43114 }),
|
46
20
|
|
47
|
-
new
|
48
|
-
|
49
|
-
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
50
|
-
})
|
21
|
+
new ProccessBridgeRequestEvents({ chainId: 137 }),
|
22
|
+
new ProccessBridgeRequestEvents({ chainId: 43114 }),
|
51
23
|
];
|
52
24
|
|
53
25
|
async start() {
|
54
26
|
for (const task of this.tasks) {
|
55
27
|
try {
|
56
28
|
task.start();
|
29
|
+
await wait(1000)
|
57
30
|
} catch (error) {
|
58
31
|
console.error(`Error starting task: ${task.constructor.name}`);
|
59
32
|
}
|