@instadapp/interop-x 0.0.0-dev.6ea4ee5 → 0.0.0-dev.733ff78
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/bin/interop-x +1 -1
- package/dist/package.json +73 -0
- package/dist/{abi → src/abi}/erc20.json +0 -0
- package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
- package/dist/{abi → src/abi}/index.js +0 -0
- package/dist/{abi → src/abi}/interopBridgeToken.json +21 -9
- package/dist/{abi → src/abi}/interopXGateway.json +11 -11
- package/dist/src/api/index.js +36 -0
- package/dist/{config → src/config}/index.js +11 -1
- package/dist/{constants → src/constants}/addresses.js +1 -9
- package/dist/{constants → src/constants}/index.js +1 -0
- package/dist/src/constants/itokens.js +13 -0
- package/dist/{constants → src/constants}/tokens.js +0 -0
- package/dist/{db → src/db}/index.js +0 -0
- package/dist/{db → src/db}/models/index.js +0 -0
- package/dist/{db → src/db}/models/transaction.js +11 -1
- package/dist/{db → src/db}/sequelize.js +1 -1
- 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 +133 -0
- package/dist/{logger → src/logger}/index.js +0 -0
- package/dist/{net → src/net}/index.js +0 -0
- package/dist/{net → src/net}/peer/index.js +8 -3
- package/dist/{net → src/net}/pool/index.js +32 -9
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +17 -12
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/{net → src/net}/protocol/index.js +51 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +162 -0
- package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +71 -0
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +164 -0
- package/dist/{tasks → src/tasks}/InteropXGateway/SyncDepositEvents.js +18 -23
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
- package/dist/src/tasks/index.js +55 -0
- package/dist/{typechain → src/typechain}/Erc20.js +0 -0
- package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
- package/dist/{typechain → src/typechain}/InteropBridgeToken.js +0 -0
- package/dist/{typechain → src/typechain}/InteropXGateway.js +0 -0
- package/dist/{typechain → src/typechain}/common.js +0 -0
- package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/InteropBridgeToken__factory.js +23 -11
- package/dist/{typechain → src/typechain}/factories/InteropXGateway__factory.js +14 -14
- package/dist/{typechain → src/typechain}/factories/index.js +0 -0
- package/dist/{typechain → src/typechain}/index.js +0 -0
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/{utils → src/utils}/index.js +62 -6
- package/package.json +12 -5
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/abi/interopBridgeToken.json +21 -9
- package/src/abi/interopXGateway.json +11 -11
- package/src/api/index.ts +36 -0
- package/src/config/index.ts +11 -1
- package/src/constants/addresses.ts +1 -9
- package/src/constants/index.ts +1 -0
- package/src/constants/itokens.ts +10 -0
- package/src/db/models/transaction.ts +18 -4
- package/src/db/sequelize.ts +1 -1
- 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 +99 -8
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +19 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +67 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +14 -4
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +249 -0
- package/src/tasks/InteropBridge/SyncBurnEvents.ts +119 -0
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +260 -0
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +25 -15
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
- package/src/tasks/index.ts +43 -2
- 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 +76 -7
- package/dist/index.js +0 -63
- package/dist/tasks/index.js +0 -27
@@ -0,0 +1,260 @@
|
|
1
|
+
import { BaseTask } from "../BaseTask";
|
2
|
+
import Logger from '@/logger';
|
3
|
+
import { BigNumber, ethers } from "ethers";
|
4
|
+
import abi from "@/abi";
|
5
|
+
import { Transaction } from "@/db";
|
6
|
+
import { buildSignatureBytes, getContract, getRpcProviderUrl, Signature } from "@/utils";
|
7
|
+
import { addresses } from "@/constants";
|
8
|
+
import { ChainId } from "@/types";
|
9
|
+
import config from "@/config";
|
10
|
+
import { GnosisSafe, InteropXGateway } from "@/typechain";
|
11
|
+
import { Op } from "sequelize";
|
12
|
+
import wait from "waait";
|
13
|
+
import { peerPool, protocol } from "@/net";
|
14
|
+
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
|
+
|
57
|
+
class ProcessDepositEvents extends BaseTask {
|
58
|
+
contractAddress: string;
|
59
|
+
provider: ethers.providers.JsonRpcProvider;
|
60
|
+
contract: InteropXGateway;
|
61
|
+
chainId: ChainId;
|
62
|
+
leadNodeOnly = true
|
63
|
+
|
64
|
+
constructor({ chainId }: { chainId: ChainId }) {
|
65
|
+
super({
|
66
|
+
logger: new Logger("InteropXGateway::ProcessDepositEvents"),
|
67
|
+
})
|
68
|
+
this.chainId = chainId;
|
69
|
+
}
|
70
|
+
|
71
|
+
async pollHandler() {
|
72
|
+
const blockNumber = await this.provider.getBlockNumber()
|
73
|
+
|
74
|
+
const transaction = await Transaction.findOne({
|
75
|
+
where: {
|
76
|
+
status: 'pending',
|
77
|
+
sourceStatus: 'success',
|
78
|
+
targetStatus: 'uninitialised',
|
79
|
+
action: 'deposit',
|
80
|
+
sourceCreatedAt: {
|
81
|
+
[Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
82
|
+
},
|
83
|
+
targetDelayUntil: {
|
84
|
+
[Op.or]: {
|
85
|
+
[Op.is]: null,
|
86
|
+
[Op.lt]: new Date(),
|
87
|
+
}
|
88
|
+
},
|
89
|
+
sourceBlockNumber: {
|
90
|
+
[Op.lt]: blockNumber - 12,
|
91
|
+
},
|
92
|
+
sourceChainId: this.chainId,
|
93
|
+
}
|
94
|
+
})
|
95
|
+
|
96
|
+
if (!transaction) {
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
|
100
|
+
console.log(`Processing transaction ${transaction.transactionHash}`);
|
101
|
+
|
102
|
+
transaction.targetStatus = 'pending';
|
103
|
+
await transaction.save();
|
104
|
+
|
105
|
+
// refresh event data?
|
106
|
+
|
107
|
+
const targetChainProvider = new ethers.providers.JsonRpcProvider(
|
108
|
+
getRpcProviderUrl(transaction.targetChainId as ChainId)
|
109
|
+
);
|
110
|
+
|
111
|
+
const targetWallet = new ethers.Wallet(config.privateKey!, targetChainProvider);
|
112
|
+
|
113
|
+
const safeAddress = addresses[transaction.targetChainId].gnosisSafe;
|
114
|
+
|
115
|
+
|
116
|
+
const safeContract = getContract<GnosisSafe>(
|
117
|
+
safeAddress,
|
118
|
+
abi.gnosisSafe,
|
119
|
+
targetWallet
|
120
|
+
)
|
121
|
+
|
122
|
+
const ownersThreshold = await safeContract.getThreshold();
|
123
|
+
await wait(10000);
|
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
|
+
|
140
|
+
let gnosisTx = await generateGnosisTransaction({
|
141
|
+
baseGas: "0",
|
142
|
+
data,
|
143
|
+
gasPrice: "0",
|
144
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
145
|
+
nonce: '0',
|
146
|
+
operation: "1",
|
147
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
148
|
+
safeAddress: safeAddress,
|
149
|
+
safeTxGas: "79668",
|
150
|
+
to: addresses[transaction.targetChainId].multisend,
|
151
|
+
value: "0",
|
152
|
+
}, safeContract);
|
153
|
+
|
154
|
+
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
155
|
+
|
156
|
+
const ownerPeerIds = peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id)
|
157
|
+
|
158
|
+
console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
|
159
|
+
|
160
|
+
console.log(ownerPeerIds);
|
161
|
+
|
162
|
+
const signatures = await protocol.requestSignatures({
|
163
|
+
type: 'source',
|
164
|
+
transactionHash: transaction.transactionHash,
|
165
|
+
safeTxGas: gnosisTx.safeTxGas,
|
166
|
+
safeNonce: gnosisTx.nonce
|
167
|
+
}, ownerPeerIds)
|
168
|
+
|
169
|
+
|
170
|
+
const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x') as Signature[];
|
171
|
+
|
172
|
+
console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
|
173
|
+
|
174
|
+
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
175
|
+
await transaction.save();
|
176
|
+
transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
|
177
|
+
transaction.targetStatus = 'uninitialised'
|
178
|
+
|
179
|
+
await transaction.save();
|
180
|
+
const errorMessage = signatures.find(s => !!s.error)?.error;
|
181
|
+
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
182
|
+
}
|
183
|
+
|
184
|
+
|
185
|
+
console.log(`Executing transaction for execution ${transaction.transactionHash}`)
|
186
|
+
|
187
|
+
const { data: txData } = await safeContract.populateTransaction.execTransaction(
|
188
|
+
gnosisTx.to,
|
189
|
+
gnosisTx.value,
|
190
|
+
gnosisTx.data,
|
191
|
+
gnosisTx.operation,
|
192
|
+
gnosisTx.safeTxGas,
|
193
|
+
gnosisTx.baseGas,
|
194
|
+
gnosisTx.gasPrice,
|
195
|
+
gnosisTx.gasToken,
|
196
|
+
gnosisTx.refundReceiver,
|
197
|
+
buildSignatureBytes(validSignatures)
|
198
|
+
);
|
199
|
+
|
200
|
+
console.log({
|
201
|
+
from: targetWallet.address,
|
202
|
+
gasPrice: BigNumber.from(120 * 10 ** 9).toString(),
|
203
|
+
to: safeAddress,
|
204
|
+
data: txData,
|
205
|
+
})
|
206
|
+
|
207
|
+
|
208
|
+
const txSent = await targetWallet.sendTransaction({
|
209
|
+
from: targetWallet.address,
|
210
|
+
gasPrice: BigNumber.from(120 * 10 ** 9),
|
211
|
+
to: safeAddress,
|
212
|
+
data: txData,
|
213
|
+
})
|
214
|
+
|
215
|
+
const receipt = await txSent.wait();
|
216
|
+
|
217
|
+
const parsedLogs: LogDescription[] = [];
|
218
|
+
|
219
|
+
receipt.logs.forEach((log) => {
|
220
|
+
try {
|
221
|
+
parsedLogs.push(safeContract.interface.parseLog(log));
|
222
|
+
} catch (e) { }
|
223
|
+
});
|
224
|
+
|
225
|
+
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
226
|
+
console.log('ExecutionSuccess')
|
227
|
+
transaction.targetStatus = 'success'
|
228
|
+
transaction.targetTransactionHash = txSent.hash
|
229
|
+
transaction.targetLogs = logs;
|
230
|
+
transaction.status = 'success'
|
231
|
+
await transaction.save();
|
232
|
+
} else {
|
233
|
+
console.log('ExecutionFailure')
|
234
|
+
transaction.targetStatus = 'failed'
|
235
|
+
transaction.targetTransactionHash = txSent.hash
|
236
|
+
transaction.status = 'failed'
|
237
|
+
await transaction.save();
|
238
|
+
}
|
239
|
+
|
240
|
+
protocol.sendTransaction(transaction)
|
241
|
+
}
|
242
|
+
|
243
|
+
async start(): Promise<void> {
|
244
|
+
this.contractAddress = addresses[this.chainId].interopXGateway;
|
245
|
+
|
246
|
+
this.provider = new ethers.providers.JsonRpcProvider(
|
247
|
+
getRpcProviderUrl(this.chainId)
|
248
|
+
);
|
249
|
+
|
250
|
+
this.contract = getContract<InteropXGateway>(
|
251
|
+
this.contractAddress,
|
252
|
+
abi.interopXGateway,
|
253
|
+
new ethers.Wallet(config.privateKey!, this.provider)
|
254
|
+
);
|
255
|
+
|
256
|
+
await super.start()
|
257
|
+
}
|
258
|
+
}
|
259
|
+
|
260
|
+
export default ProcessDepositEvents;
|
@@ -3,7 +3,7 @@ import Logger from '@/logger';
|
|
3
3
|
import { ethers } from "ethers";
|
4
4
|
import abi from "@/abi";
|
5
5
|
import { Transaction } from "@/db";
|
6
|
-
import { generateInteropTransactionHash, getRpcProviderUrl } from "@/utils";
|
6
|
+
import { generateInteropTransactionHash, getContract, getRpcProviderUrl } from "@/utils";
|
7
7
|
import { addresses } from "@/constants";
|
8
8
|
import { ChainId } from "@/types";
|
9
9
|
import config from "@/config";
|
@@ -43,10 +43,10 @@ class SyncDepositEvents extends BaseTask {
|
|
43
43
|
const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
|
44
44
|
|
45
45
|
const uniqueIdentifier = {
|
46
|
-
|
47
|
-
|
48
|
-
sourceChainId: sourceChainId
|
49
|
-
targetChainId: targetChainId
|
46
|
+
action: 'deposit',
|
47
|
+
submitTransactionHash: event.transactionHash,
|
48
|
+
sourceChainId: sourceChainId,
|
49
|
+
targetChainId: targetChainId,
|
50
50
|
}
|
51
51
|
|
52
52
|
if (await Transaction.findOne({ where: uniqueIdentifier })) {
|
@@ -56,17 +56,20 @@ class SyncDepositEvents extends BaseTask {
|
|
56
56
|
const tx = await event.getTransaction()
|
57
57
|
|
58
58
|
await Transaction.create({
|
59
|
+
...uniqueIdentifier,
|
59
60
|
transactionHash: generateInteropTransactionHash(uniqueIdentifier),
|
60
|
-
type: 'deposit',
|
61
61
|
from: tx.from,
|
62
62
|
to: user,
|
63
63
|
|
64
|
-
|
64
|
+
|
65
|
+
submitTransactionHash: event.transactionHash,
|
66
|
+
submitBlockNumber: event.blockNumber,
|
67
|
+
|
68
|
+
// submit & source are the same
|
65
69
|
sourceTransactionHash: event.transactionHash,
|
66
70
|
sourceBlockNumber: event.blockNumber,
|
67
|
-
sourceStatus: "
|
71
|
+
sourceStatus: "success",
|
68
72
|
|
69
|
-
targetChainId: targetChainId.toNumber(),
|
70
73
|
targetStatus: "uninitialised",
|
71
74
|
|
72
75
|
submitEvent: {
|
@@ -74,14 +77,23 @@ class SyncDepositEvents extends BaseTask {
|
|
74
77
|
sourceChainId: sourceChainId.toString(),
|
75
78
|
targetChainId: targetChainId.toString(),
|
76
79
|
token: token,
|
77
|
-
|
80
|
+
amount: amount.toString(),
|
81
|
+
vnonce: vnonce.toString(),
|
82
|
+
},
|
83
|
+
|
84
|
+
sourceEvent: {
|
85
|
+
user,
|
86
|
+
sourceChainId: sourceChainId.toString(),
|
87
|
+
targetChainId: targetChainId.toString(),
|
88
|
+
token: token,
|
89
|
+
amount: amount.toString(),
|
78
90
|
vnonce: vnonce.toString(),
|
79
91
|
},
|
80
92
|
status: "pending",
|
81
93
|
})
|
82
94
|
|
83
95
|
this.logger.info(
|
84
|
-
`
|
96
|
+
`Deposit queued: ${event.transactionHash} ${event.blockNumber}`
|
85
97
|
);
|
86
98
|
} catch (error) {
|
87
99
|
this.logger.error(error);
|
@@ -93,19 +105,17 @@ class SyncDepositEvents extends BaseTask {
|
|
93
105
|
}
|
94
106
|
|
95
107
|
async start(): Promise<void> {
|
96
|
-
this.logger.info(`Starting execution watcher on interop chain`);
|
97
|
-
|
98
108
|
this.contractAddress = addresses[this.chainId].interopXGateway;
|
99
109
|
|
100
110
|
this.provider = new ethers.providers.JsonRpcProvider(
|
101
111
|
getRpcProviderUrl(this.chainId)
|
102
112
|
);
|
103
113
|
|
104
|
-
this.contract =
|
114
|
+
this.contract = getContract<InteropXGateway>(
|
105
115
|
this.contractAddress,
|
106
116
|
abi.interopXGateway,
|
107
117
|
new ethers.Wallet(config.privateKey!, this.provider)
|
108
|
-
)
|
118
|
+
);
|
109
119
|
|
110
120
|
await super.start()
|
111
121
|
}
|
@@ -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;
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { BaseTask } from "../BaseTask";
|
2
|
+
import Logger from '@/logger';
|
3
|
+
import config from "@/config";
|
4
|
+
import { peerPool, protocol } from "@/net";
|
5
|
+
import { Transaction } from "@/db";
|
6
|
+
import { Op } from "sequelize";
|
7
|
+
|
8
|
+
class SyncTransactionStatusTask extends BaseTask {
|
9
|
+
pollIntervalMs: number = 60 * 1000
|
10
|
+
exceptLeadNode: boolean = true;
|
11
|
+
|
12
|
+
constructor() {
|
13
|
+
super({
|
14
|
+
logger: new Logger("SyncTransactionStatusTask"),
|
15
|
+
})
|
16
|
+
}
|
17
|
+
|
18
|
+
async pollHandler() {
|
19
|
+
// if transaction is pending for more than 1 hour, check lead node for status
|
20
|
+
const leadNode = peerPool.getLeadPeer();
|
21
|
+
|
22
|
+
if (!leadNode) {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
|
26
|
+
const transaction = await Transaction.findOne({
|
27
|
+
where: {
|
28
|
+
status: 'pending',
|
29
|
+
sourceCreatedAt: {
|
30
|
+
[Op.gte]: new Date(Date.now() - 60 * 60 * 1000),
|
31
|
+
},
|
32
|
+
}
|
33
|
+
})
|
34
|
+
|
35
|
+
if (!transaction) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
|
39
|
+
this.logger.info(`Requesting transaction status for ${transaction.transactionHash}`)
|
40
|
+
|
41
|
+
const transactionStatus = await protocol.requestTransactionStatus(transaction.transactionHash, leadNode.id);
|
42
|
+
|
43
|
+
if (!transactionStatus) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
|
47
|
+
this.logger.info(`Received transaction status for ${transaction.transactionHash}`)
|
48
|
+
|
49
|
+
transaction.sourceStatus = transactionStatus.sourceStatus
|
50
|
+
transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash
|
51
|
+
transaction.sourceErrors = transactionStatus.sourceErrors
|
52
|
+
transaction.sourceLogs = transactionStatus.sourceLogs
|
53
|
+
|
54
|
+
transaction.targetStatus = transactionStatus.targetStatus
|
55
|
+
transaction.targetTransactionHash = transactionStatus.targetTransactionHash
|
56
|
+
transaction.targetErrors = transactionStatus.targetErrors
|
57
|
+
transaction.targetLogs = transactionStatus.targetLogs
|
58
|
+
|
59
|
+
transaction.status = transactionStatus.status
|
60
|
+
|
61
|
+
await transaction.save()
|
62
|
+
|
63
|
+
this.logger.info(`Updated transaction status for ${transaction.transactionHash}`)
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
export default SyncTransactionStatusTask;
|
package/src/tasks/index.ts
CHANGED
@@ -1,11 +1,52 @@
|
|
1
1
|
import { BaseTask } from "./BaseTask";
|
2
|
-
import
|
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
|
+
import SyncTransactionStatusTask from "./Transactions/SyncTransactionStatusTask";
|
11
|
+
|
12
|
+
import AutoUpdateTask from "./AutoUpdateTask";
|
3
13
|
|
4
14
|
export class Tasks {
|
5
15
|
|
6
16
|
tasks: BaseTask[] = [
|
7
|
-
new
|
17
|
+
new SyncTransactionStatusTask(),
|
18
|
+
new AutoUpdateTask(),
|
19
|
+
|
20
|
+
// InteropXGateway
|
21
|
+
|
22
|
+
new InteropXGatewaySyncDepositEvents({
|
23
|
+
chainId: 43114
|
24
|
+
}),
|
25
|
+
|
26
|
+
new InteropXGatewayProcessDepositEvents({
|
8
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
|
+
}),
|
41
|
+
|
42
|
+
new InteropBridgeSyncMintEvents({
|
43
|
+
chainId: 137,
|
44
|
+
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
45
|
+
}),
|
46
|
+
|
47
|
+
new InteropBridgeSyncBurnEvents({
|
48
|
+
chainId: 137,
|
49
|
+
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
9
50
|
})
|
10
51
|
];
|
11
52
|
|
@@ -31,11 +31,11 @@ export interface InteropBridgeTokenInterface extends utils.Interface {
|
|
31
31
|
"allowance(address,address)": FunctionFragment;
|
32
32
|
"approve(address,uint256)": FunctionFragment;
|
33
33
|
"balanceOf(address)": FunctionFragment;
|
34
|
-
"burn(address,uint256,
|
34
|
+
"burn(address,uint256,uint32)": FunctionFragment;
|
35
35
|
"decimals()": FunctionFragment;
|
36
36
|
"decreaseAllowance(address,uint256)": FunctionFragment;
|
37
37
|
"increaseAllowance(address,uint256)": FunctionFragment;
|
38
|
-
"mint(address,uint256,
|
38
|
+
"mint(address,uint256,uint32,bytes32)": FunctionFragment;
|
39
39
|
"name()": FunctionFragment;
|
40
40
|
"owner()": FunctionFragment;
|
41
41
|
"renounceOwnership()": FunctionFragment;
|
@@ -153,8 +153,8 @@ export interface InteropBridgeTokenInterface extends utils.Interface {
|
|
153
153
|
|
154
154
|
events: {
|
155
155
|
"Approval(address,address,uint256)": EventFragment;
|
156
|
-
"Burn(address,uint256,
|
157
|
-
"Mint(address,uint256,
|
156
|
+
"Burn(address,uint256,uint32,uint32)": EventFragment;
|
157
|
+
"Mint(address,uint256,uint32,uint32,bytes32)": EventFragment;
|
158
158
|
"OwnershipTransferred(address,address)": EventFragment;
|
159
159
|
"Transfer(address,address,uint256)": EventFragment;
|
160
160
|
};
|
@@ -181,10 +181,11 @@ export type ApprovalEventFilter = TypedEventFilter<ApprovalEvent>;
|
|
181
181
|
export interface BurnEventObject {
|
182
182
|
to: string;
|
183
183
|
amount: BigNumber;
|
184
|
-
|
184
|
+
sourceChainId: number;
|
185
|
+
targetChainId: number;
|
185
186
|
}
|
186
187
|
export type BurnEvent = TypedEvent<
|
187
|
-
[string, BigNumber,
|
188
|
+
[string, BigNumber, number, number],
|
188
189
|
BurnEventObject
|
189
190
|
>;
|
190
191
|
|
@@ -193,11 +194,12 @@ export type BurnEventFilter = TypedEventFilter<BurnEvent>;
|
|
193
194
|
export interface MintEventObject {
|
194
195
|
to: string;
|
195
196
|
amount: BigNumber;
|
196
|
-
|
197
|
-
|
197
|
+
sourceChainId: number;
|
198
|
+
targetChainId: number;
|
199
|
+
submitTransactionHash: string;
|
198
200
|
}
|
199
201
|
export type MintEvent = TypedEvent<
|
200
|
-
[string, BigNumber,
|
202
|
+
[string, BigNumber, number, number, string],
|
201
203
|
MintEventObject
|
202
204
|
>;
|
203
205
|
|
@@ -486,28 +488,32 @@ export interface InteropBridgeToken extends BaseContract {
|
|
486
488
|
value?: null
|
487
489
|
): ApprovalEventFilter;
|
488
490
|
|
489
|
-
"Burn(address,uint256,
|
491
|
+
"Burn(address,uint256,uint32,uint32)"(
|
490
492
|
to?: string | null,
|
491
493
|
amount?: null,
|
492
|
-
|
494
|
+
sourceChainId?: null,
|
495
|
+
targetChainId?: BigNumberish | null
|
493
496
|
): BurnEventFilter;
|
494
497
|
Burn(
|
495
498
|
to?: string | null,
|
496
499
|
amount?: null,
|
497
|
-
|
500
|
+
sourceChainId?: null,
|
501
|
+
targetChainId?: BigNumberish | null
|
498
502
|
): BurnEventFilter;
|
499
503
|
|
500
|
-
"Mint(address,uint256,
|
504
|
+
"Mint(address,uint256,uint32,uint32,bytes32)"(
|
501
505
|
to?: string | null,
|
502
506
|
amount?: null,
|
503
|
-
|
504
|
-
|
507
|
+
sourceChainId?: BigNumberish | null,
|
508
|
+
targetChainId?: null,
|
509
|
+
submitTransactionHash?: BytesLike | null
|
505
510
|
): MintEventFilter;
|
506
511
|
Mint(
|
507
512
|
to?: string | null,
|
508
513
|
amount?: null,
|
509
|
-
|
510
|
-
|
514
|
+
sourceChainId?: BigNumberish | null,
|
515
|
+
targetChainId?: null,
|
516
|
+
submitTransactionHash?: BytesLike | null
|
511
517
|
): MintEventFilter;
|
512
518
|
|
513
519
|
"OwnershipTransferred(address,address)"(
|