@instadapp/interop-x 0.0.0-dev.733ff78 → 0.0.0-dev.76d0265
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 +13 -12
- package/dist/src/abi/index.js +2 -4
- package/dist/src/abi/interopXContract.json +454 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/constants/addresses.js +7 -7
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +62 -39
- package/dist/src/db/models/transaction.js +19 -11
- package/dist/src/gnosis/actions/index.js +0 -2
- package/dist/src/gnosis/actions/withdraw/index.js +115 -0
- package/dist/src/gnosis/index.js +4 -4
- package/dist/src/index.js +5 -19
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +6 -2
- package/dist/src/tasks/{InteropBridge/ProcessWithdrawEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +50 -53
- package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +93 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
- package/dist/src/tasks/index.js +16 -30
- package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +44 -8
- package/package.json +13 -12
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +454 -0
- package/src/alias.ts +6 -0
- package/src/constants/addresses.ts +8 -8
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +63 -40
- package/src/db/models/transaction.ts +66 -27
- package/src/gnosis/actions/index.ts +0 -2
- package/src/gnosis/actions/withdraw/index.ts +155 -0
- package/src/gnosis/index.ts +5 -5
- package/src/index.ts +4 -18
- package/src/net/protocol/dial/SignatureDialProtocol.ts +6 -2
- package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +78 -100
- package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +125 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
- package/src/tasks/index.ts +18 -36
- package/src/typechain/InteropXContract.ts +680 -0
- package/src/typechain/factories/InteropXContract__factory.ts +642 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +85 -8
- 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
@@ -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, LiquidityError, 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,32 @@ 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
|
+
|
78
|
+
if(error instanceof LiquidityError){
|
79
|
+
await transaction.save();
|
80
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
81
|
+
transaction.sourceStatus = 'uninitialised'
|
82
|
+
|
83
|
+
await transaction.save();
|
84
|
+
|
85
|
+
throw error
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
|
89
|
+
transaction.sourceStatus = 'failed';
|
90
|
+
transaction.sourceErrors = [error.message];
|
129
91
|
transaction.targetStatus = 'failed';
|
130
|
-
|
92
|
+
|
131
93
|
transaction.status = 'failed'
|
132
94
|
await transaction.save();
|
133
95
|
protocol.sendTransaction(transaction)
|
@@ -142,13 +104,13 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
142
104
|
nonce: '0',
|
143
105
|
operation: "1",
|
144
106
|
refundReceiver: "0x0000000000000000000000000000000000000000",
|
145
|
-
safeAddress:
|
107
|
+
safeAddress: this.safeContractAddress,
|
146
108
|
safeTxGas: "79668",
|
147
|
-
to: addresses[transaction.
|
109
|
+
to: addresses[transaction.sourceChainId].multisend,
|
148
110
|
value: "0",
|
149
|
-
}, safeContract);
|
111
|
+
}, this.safeContract);
|
150
112
|
|
151
|
-
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
113
|
+
const owners = await this.safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
152
114
|
|
153
115
|
const ownerPeerIds = peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id)
|
154
116
|
|
@@ -170,18 +132,17 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
170
132
|
|
171
133
|
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
172
134
|
await transaction.save();
|
173
|
-
transaction.
|
174
|
-
transaction.
|
135
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
136
|
+
transaction.sourceStatus = 'uninitialised'
|
175
137
|
|
176
138
|
await transaction.save();
|
177
139
|
const errorMessage = signatures.find(s => !!s.error)?.error;
|
178
140
|
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
179
141
|
}
|
180
142
|
|
181
|
-
|
182
143
|
console.log(`Executing transaction for execution ${transaction.transactionHash}`)
|
183
144
|
|
184
|
-
const { data: txData } = await safeContract.populateTransaction.execTransaction(
|
145
|
+
const { data: txData } = await this.safeContract.populateTransaction.execTransaction(
|
185
146
|
gnosisTx.to,
|
186
147
|
gnosisTx.value,
|
187
148
|
gnosisTx.data,
|
@@ -194,20 +155,15 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
194
155
|
buildSignatureBytes(validSignatures)
|
195
156
|
);
|
196
157
|
|
197
|
-
|
198
|
-
from:
|
199
|
-
gasPrice: BigNumber.from(120 * 10 ** 9)
|
200
|
-
to:
|
158
|
+
const txSent = await this.sourceWallet.sendTransaction({
|
159
|
+
from: this.sourceWallet.address,
|
160
|
+
gasPrice: ethers.BigNumber.from(120 * 10 ** 9),
|
161
|
+
to: this.safeContractAddress,
|
201
162
|
data: txData,
|
202
163
|
})
|
203
164
|
|
165
|
+
console.log(txSent);
|
204
166
|
|
205
|
-
const txSent = await targetWallet.sendTransaction({
|
206
|
-
from: targetWallet.address,
|
207
|
-
gasPrice: BigNumber.from(120 * 10 ** 9),
|
208
|
-
to: safeAddress,
|
209
|
-
data: txData,
|
210
|
-
})
|
211
167
|
|
212
168
|
const receipt = await txSent.wait();
|
213
169
|
|
@@ -215,21 +171,26 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
215
171
|
|
216
172
|
receipt.logs.forEach((log) => {
|
217
173
|
try {
|
218
|
-
parsedLogs.push(safeContract.interface.parseLog(log));
|
174
|
+
parsedLogs.push(this.safeContract.interface.parseLog(log));
|
219
175
|
} catch (e) { }
|
220
176
|
});
|
221
177
|
|
222
178
|
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
223
179
|
console.log('ExecutionSuccess')
|
224
|
-
transaction.
|
225
|
-
|
226
|
-
|
180
|
+
transaction.sourceStatus = 'success'
|
181
|
+
if (txSent.blockNumber)
|
182
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
183
|
+
transaction.sourceTransactionHash = txSent.hash
|
184
|
+
transaction.sourceLogs = logs;
|
227
185
|
transaction.status = 'success'
|
228
186
|
await transaction.save();
|
229
187
|
} else {
|
230
188
|
console.log('ExecutionFailure')
|
231
|
-
transaction.
|
232
|
-
|
189
|
+
transaction.sourceStatus = 'failed'
|
190
|
+
if (txSent.blockNumber)
|
191
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
192
|
+
transaction.sourceTransactionHash = txSent.hash
|
193
|
+
transaction.sourceTransactionHash = txSent.hash
|
233
194
|
transaction.status = 'failed'
|
234
195
|
await transaction.save();
|
235
196
|
}
|
@@ -238,12 +199,29 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
238
199
|
}
|
239
200
|
|
240
201
|
async start(): Promise<void> {
|
202
|
+
this.contractAddress = addresses[this.chainId].interopXContract;
|
203
|
+
|
241
204
|
this.provider = new ethers.providers.JsonRpcProvider(
|
242
205
|
getRpcProviderUrl(this.chainId)
|
243
206
|
);
|
244
207
|
|
208
|
+
this.sourceWallet = new ethers.Wallet(config.privateKey!, this.provider);
|
209
|
+
|
210
|
+
this.contract = getContract<InteropXContract>(
|
211
|
+
this.contractAddress,
|
212
|
+
abi.interopXContract,
|
213
|
+
this.sourceWallet
|
214
|
+
);
|
215
|
+
|
216
|
+
this.safeContractAddress = addresses[this.chainId].gnosisSafe;
|
217
|
+
this.safeContract = getContract<GnosisSafe>(
|
218
|
+
this.safeContractAddress,
|
219
|
+
abi.gnosisSafe,
|
220
|
+
this.sourceWallet
|
221
|
+
);
|
222
|
+
|
245
223
|
await super.start()
|
246
224
|
}
|
247
225
|
}
|
248
226
|
|
249
|
-
export default
|
227
|
+
export default ProccessBridgeRequestEvents;
|
@@ -0,0 +1,125 @@
|
|
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
|
+
import { Op } from "sequelize";
|
12
|
+
|
13
|
+
class SyncBridgeCommittedEvents extends BaseTask {
|
14
|
+
contractAddress: string;
|
15
|
+
provider: ethers.providers.JsonRpcProvider;
|
16
|
+
contract: InteropXContract;
|
17
|
+
chainId: ChainId;
|
18
|
+
|
19
|
+
constructor({ chainId }: { chainId: ChainId }) {
|
20
|
+
super({
|
21
|
+
logger: new Logger("InteropXContract::SyncBridgeCommittedEvents"),
|
22
|
+
})
|
23
|
+
this.chainId = chainId;
|
24
|
+
}
|
25
|
+
|
26
|
+
async pollHandler() {
|
27
|
+
const currentBlock = await this.provider.getBlockNumber();
|
28
|
+
|
29
|
+
const events = await this.contract.queryFilter(
|
30
|
+
this.contract.filters.LogBridgeCommitted(),
|
31
|
+
currentBlock - 2000,
|
32
|
+
currentBlock,
|
33
|
+
);
|
34
|
+
|
35
|
+
let processedEvents = 0;
|
36
|
+
|
37
|
+
for (const event of events) {
|
38
|
+
|
39
|
+
try {
|
40
|
+
if (!event.args) {
|
41
|
+
continue;
|
42
|
+
}
|
43
|
+
|
44
|
+
const { actionId, bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
|
45
|
+
|
46
|
+
const uniqueIdentifier = {
|
47
|
+
actionId,
|
48
|
+
bridger,
|
49
|
+
requestTransactionHash,
|
50
|
+
sourceChainId: sourceChainId,
|
51
|
+
targetChainId: targetChainId,
|
52
|
+
}
|
53
|
+
|
54
|
+
let transactionHash = generateInteropTransactionHash(uniqueIdentifier);
|
55
|
+
|
56
|
+
const transaction = await Transaction.findOne({
|
57
|
+
where: {
|
58
|
+
transactionHash,
|
59
|
+
sourceStatus: 'success',
|
60
|
+
committedEvent: {
|
61
|
+
[Op.eq]: null,
|
62
|
+
}
|
63
|
+
}
|
64
|
+
});
|
65
|
+
|
66
|
+
if (!transaction) {
|
67
|
+
continue;
|
68
|
+
}
|
69
|
+
transaction.targetStatus = 'success'
|
70
|
+
transaction.targetBlockNumber = event.blockNumber;
|
71
|
+
transaction.targetTransactionHash = event.transactionHash
|
72
|
+
transaction.committedEvent = {
|
73
|
+
actionId,
|
74
|
+
bridger,
|
75
|
+
position: {
|
76
|
+
withdraw: position.withdraw.map((v) => ({
|
77
|
+
sourceToken: v.sourceToken,
|
78
|
+
targetToken: v.targetToken,
|
79
|
+
amount: v.amount.toString()
|
80
|
+
})),
|
81
|
+
supply: position.supply.map((v) => ({
|
82
|
+
sourceToken: v.sourceToken,
|
83
|
+
targetToken: v.targetToken,
|
84
|
+
amount: v.amount.toString()
|
85
|
+
})),
|
86
|
+
},
|
87
|
+
sourceChainId: sourceChainId,
|
88
|
+
targetChainId: targetChainId,
|
89
|
+
metadata,
|
90
|
+
requestTransactionHash,
|
91
|
+
}
|
92
|
+
|
93
|
+
transaction.status = 'success';
|
94
|
+
await transaction.save()
|
95
|
+
|
96
|
+
this.logger.info(
|
97
|
+
`New bridge committed received: ${transactionHash} `
|
98
|
+
);
|
99
|
+
} catch (error) {
|
100
|
+
this.logger.error(error);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
if (processedEvents > 0)
|
105
|
+
this.logger.info(`${processedEvents} events processed`);
|
106
|
+
}
|
107
|
+
|
108
|
+
async start(): Promise<void> {
|
109
|
+
this.contractAddress = addresses[this.chainId].interopXContract;
|
110
|
+
|
111
|
+
this.provider = new ethers.providers.JsonRpcProvider(
|
112
|
+
getRpcProviderUrl(this.chainId)
|
113
|
+
);
|
114
|
+
|
115
|
+
this.contract = getContract<InteropXContract>(
|
116
|
+
this.contractAddress,
|
117
|
+
abi.interopXContract,
|
118
|
+
new ethers.Wallet(config.privateKey!, this.provider)
|
119
|
+
);
|
120
|
+
|
121
|
+
await super.start()
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
export default SyncBridgeCommittedEvents;
|
@@ -0,0 +1,115 @@
|
|
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 { actionId, bridger, position, sourceChainId, targetChainId, metadata } = event.args;
|
44
|
+
|
45
|
+
const uniqueIdentifier = {
|
46
|
+
actionId,
|
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
|
+
continue;
|
59
|
+
}
|
60
|
+
|
61
|
+
await Transaction.create({
|
62
|
+
transactionHash,
|
63
|
+
...uniqueIdentifier,
|
64
|
+
requestBlockNumber: event.blockNumber,
|
65
|
+
requestEvent: {
|
66
|
+
actionId,
|
67
|
+
bridger,
|
68
|
+
position: {
|
69
|
+
withdraw: position.withdraw.map((v) => ({
|
70
|
+
sourceToken: v.sourceToken,
|
71
|
+
targetToken: v.targetToken,
|
72
|
+
amount: v.amount.toString()
|
73
|
+
})),
|
74
|
+
supply: position.supply.map((v) => ({
|
75
|
+
sourceToken: v.sourceToken,
|
76
|
+
targetToken: v.targetToken,
|
77
|
+
amount: v.amount.toString()
|
78
|
+
})),
|
79
|
+
},
|
80
|
+
sourceChainId: sourceChainId.toNumber(),
|
81
|
+
targetChainId: targetChainId.toNumber(),
|
82
|
+
metadata,
|
83
|
+
}
|
84
|
+
})
|
85
|
+
|
86
|
+
this.logger.info(
|
87
|
+
`New bridge request received: ${transactionHash} `
|
88
|
+
);
|
89
|
+
} catch (error) {
|
90
|
+
this.logger.error(error);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
if (processedEvents > 0)
|
95
|
+
this.logger.info(`${processedEvents} events processed`);
|
96
|
+
}
|
97
|
+
|
98
|
+
async start(): Promise<void> {
|
99
|
+
this.contractAddress = addresses[this.chainId].interopXContract;
|
100
|
+
|
101
|
+
this.provider = new ethers.providers.JsonRpcProvider(
|
102
|
+
getRpcProviderUrl(this.chainId)
|
103
|
+
);
|
104
|
+
|
105
|
+
this.contract = getContract<InteropXContract>(
|
106
|
+
this.contractAddress,
|
107
|
+
abi.interopXContract,
|
108
|
+
new ethers.Wallet(config.privateKey!, this.provider)
|
109
|
+
);
|
110
|
+
|
111
|
+
await super.start()
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
export default SyncBridgeRequestEvents;
|
@@ -0,0 +1,121 @@
|
|
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
|
+
import { Op } from "sequelize";
|
12
|
+
|
13
|
+
class SyncBridgeRequestSentEvents extends BaseTask {
|
14
|
+
contractAddress: string;
|
15
|
+
provider: ethers.providers.JsonRpcProvider;
|
16
|
+
contract: InteropXContract;
|
17
|
+
chainId: ChainId;
|
18
|
+
|
19
|
+
constructor({ chainId }: { chainId: ChainId }) {
|
20
|
+
super({
|
21
|
+
logger: new Logger("InteropXContract::SyncBridgeRequestSentEvents"),
|
22
|
+
})
|
23
|
+
this.chainId = chainId;
|
24
|
+
}
|
25
|
+
|
26
|
+
async pollHandler() {
|
27
|
+
const currentBlock = await this.provider.getBlockNumber();
|
28
|
+
|
29
|
+
const events = await this.contract.queryFilter(
|
30
|
+
this.contract.filters.LogBridgeRequestSent(),
|
31
|
+
currentBlock - 2000,
|
32
|
+
currentBlock,
|
33
|
+
);
|
34
|
+
|
35
|
+
let processedEvents = 0;
|
36
|
+
|
37
|
+
for (const event of events) {
|
38
|
+
|
39
|
+
try {
|
40
|
+
if (!event.args) {
|
41
|
+
continue;
|
42
|
+
}
|
43
|
+
|
44
|
+
const { actionId, bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
|
45
|
+
|
46
|
+
const uniqueIdentifier = {
|
47
|
+
actionId,
|
48
|
+
bridger,
|
49
|
+
requestTransactionHash,
|
50
|
+
sourceChainId: sourceChainId,
|
51
|
+
targetChainId: targetChainId,
|
52
|
+
}
|
53
|
+
|
54
|
+
let transactionHash = generateInteropTransactionHash(uniqueIdentifier);
|
55
|
+
|
56
|
+
const transaction = await Transaction.findOne({
|
57
|
+
where: {
|
58
|
+
transactionHash, requestSentEvent: {
|
59
|
+
[Op.eq]: null,
|
60
|
+
}
|
61
|
+
}
|
62
|
+
});
|
63
|
+
|
64
|
+
if (!transaction) {
|
65
|
+
continue;
|
66
|
+
}
|
67
|
+
transaction.sourceStatus = 'success'
|
68
|
+
transaction.sourceBlockNumber = event.blockNumber;
|
69
|
+
transaction.sourceTransactionHash = event.transactionHash
|
70
|
+
transaction.requestSentEvent = {
|
71
|
+
actionId,
|
72
|
+
bridger,
|
73
|
+
position: {
|
74
|
+
withdraw: position.withdraw.map((v) => ({
|
75
|
+
sourceToken: v.sourceToken,
|
76
|
+
targetToken: v.targetToken,
|
77
|
+
amount: v.amount.toString()
|
78
|
+
})),
|
79
|
+
supply: position.supply.map((v) => ({
|
80
|
+
sourceToken: v.sourceToken,
|
81
|
+
targetToken: v.targetToken,
|
82
|
+
amount: v.amount.toString()
|
83
|
+
})),
|
84
|
+
},
|
85
|
+
sourceChainId: sourceChainId,
|
86
|
+
targetChainId: targetChainId,
|
87
|
+
metadata,
|
88
|
+
requestTransactionHash,
|
89
|
+
}
|
90
|
+
await transaction.save()
|
91
|
+
|
92
|
+
this.logger.info(
|
93
|
+
`New bridge request sent received: ${transactionHash} `
|
94
|
+
);
|
95
|
+
} catch (error) {
|
96
|
+
this.logger.error(error);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
if (processedEvents > 0)
|
101
|
+
this.logger.info(`${processedEvents} events processed`);
|
102
|
+
}
|
103
|
+
|
104
|
+
async start(): Promise<void> {
|
105
|
+
this.contractAddress = addresses[this.chainId].interopXContract;
|
106
|
+
|
107
|
+
this.provider = new ethers.providers.JsonRpcProvider(
|
108
|
+
getRpcProviderUrl(this.chainId)
|
109
|
+
);
|
110
|
+
|
111
|
+
this.contract = getContract<InteropXContract>(
|
112
|
+
this.contractAddress,
|
113
|
+
abi.interopXContract,
|
114
|
+
new ethers.Wallet(config.privateKey!, this.provider)
|
115
|
+
);
|
116
|
+
|
117
|
+
await super.start()
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
export default SyncBridgeRequestSentEvents;
|