@instadapp/interop-x 0.0.0-dev.4349539 → 0.0.0-dev.48c6eec
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/api/index.js +3 -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 +27 -11
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +115 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +8 -19
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
- 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/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +61 -52
- 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/Transactions/SyncTransactionStatusTask.js +6 -2
- package/dist/src/tasks/index.js +16 -19
- 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 -89
- 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/api/index.ts +3 -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 +76 -27
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +155 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +7 -18
- package/src/net/protocol/dial/SignatureDialProtocol.ts +11 -13
- package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +3 -1
- package/src/net/protocol/index.ts +17 -7
- package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +89 -94
- 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/Transactions/SyncTransactionStatusTask.ts +6 -2
- package/src/tasks/index.ts +21 -20
- 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 +82 -126
- package/tsconfig.json +7 -2
- package/dist/src/abi/interopBridgeToken.json +0 -286
- package/dist/src/abi/interopXGateway.json +0 -184
- package/dist/src/constants/itokens.js +0 -13
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -146
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -69
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
- package/dist/src/typechain/InteropXGateway.js +0 -2
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -119
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -243
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
- package/src/typechain/InteropBridgeToken.ts +0 -686
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -1,66 +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 {
|
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,
|
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
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
let isExecuted = await safeContract.dataHashes(
|
20
|
-
await safeContract.getTransactionHash(
|
21
|
-
transactionData.to,
|
22
|
-
transactionData.value,
|
23
|
-
transactionData.data,
|
24
|
-
transactionData.operation,
|
25
|
-
transactionData.safeTxGas,
|
26
|
-
transactionData.baseGas,
|
27
|
-
transactionData.gasPrice,
|
28
|
-
transactionData.gasToken,
|
29
|
-
transactionData.refundReceiver,
|
30
|
-
transactionData.nonce
|
31
|
-
)
|
32
|
-
)
|
33
|
-
|
34
|
-
while (isExecuted == 1) {
|
35
|
-
transactionData.safeTxGas = BigNumber.from(String(transactionData.safeTxGas)).add(1).toString()
|
36
|
-
|
37
|
-
isExecuted = await safeContract.dataHashes(
|
38
|
-
await safeContract.getTransactionHash(
|
39
|
-
transactionData.to,
|
40
|
-
transactionData.value,
|
41
|
-
transactionData.data,
|
42
|
-
transactionData.operation,
|
43
|
-
transactionData.safeTxGas,
|
44
|
-
transactionData.baseGas,
|
45
|
-
transactionData.gasPrice,
|
46
|
-
transactionData.gasToken,
|
47
|
-
transactionData.refundReceiver,
|
48
|
-
transactionData.nonce
|
49
|
-
)
|
50
|
-
)
|
51
|
-
}
|
52
|
-
|
53
|
-
return transactionData
|
54
|
-
}
|
55
|
-
|
56
|
-
class ProcessWithdrawEvents extends BaseTask {
|
17
|
+
class ProccessBridgeRequestEvents extends BaseTask {
|
18
|
+
contractAddress: string;
|
19
|
+
safeContractAddress: string;
|
57
20
|
provider: ethers.providers.JsonRpcProvider;
|
21
|
+
contract: InteropXContract;
|
22
|
+
safeContract: GnosisSafe;
|
58
23
|
chainId: ChainId;
|
59
|
-
|
24
|
+
sourceWallet: Wallet;
|
25
|
+
|
26
|
+
leadNodeOnly: boolean = true;
|
60
27
|
|
61
28
|
constructor({ chainId }: { chainId: ChainId }) {
|
62
29
|
super({
|
63
|
-
logger: new Logger("
|
30
|
+
logger: new Logger("InteropXContract::ProccessBridgeRequestEvents"),
|
64
31
|
})
|
65
32
|
this.chainId = chainId;
|
66
33
|
}
|
@@ -71,19 +38,17 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
71
38
|
const transaction = await Transaction.findOne({
|
72
39
|
where: {
|
73
40
|
status: 'pending',
|
74
|
-
sourceStatus: '
|
75
|
-
|
76
|
-
action: 'withdraw',
|
77
|
-
sourceCreatedAt: {
|
41
|
+
sourceStatus: 'uninitialised',
|
42
|
+
createdAt: {
|
78
43
|
[Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
79
44
|
},
|
80
|
-
|
45
|
+
sourceDelayUntil: {
|
81
46
|
[Op.or]: {
|
82
47
|
[Op.is]: null,
|
83
48
|
[Op.lt]: new Date(),
|
84
49
|
}
|
85
50
|
},
|
86
|
-
|
51
|
+
requestBlockNumber: {
|
87
52
|
[Op.lt]: blockNumber - 12,
|
88
53
|
},
|
89
54
|
sourceChainId: this.chainId,
|
@@ -95,52 +60,64 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
95
60
|
}
|
96
61
|
|
97
62
|
console.log(`Processing transaction ${transaction.transactionHash}`);
|
98
|
-
|
63
|
+
|
99
64
|
transaction.targetStatus = 'pending';
|
100
65
|
await transaction.save();
|
101
66
|
|
102
|
-
|
67
|
+
const ownersThreshold = await this.safeContract.getThreshold();
|
68
|
+
await wait(10000);
|
103
69
|
|
104
|
-
const targetChainProvider = new ethers.providers.JsonRpcProvider(
|
105
|
-
getRpcProviderUrl(transaction.targetChainId as ChainId)
|
106
|
-
);
|
107
70
|
|
108
|
-
|
71
|
+
let data, logs = [];
|
109
72
|
|
110
|
-
|
73
|
+
try {
|
74
|
+
({ data, logs } = await buildGnosisAction(transaction, 'source'));
|
111
75
|
|
76
|
+
} catch (error) {
|
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();
|
112
84
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
targetWallet
|
117
|
-
)
|
85
|
+
throw error
|
86
|
+
return;
|
87
|
+
}
|
118
88
|
|
119
|
-
|
120
|
-
|
89
|
+
transaction.sourceStatus = 'failed';
|
90
|
+
transaction.sourceErrors = [error.message];
|
91
|
+
transaction.targetStatus = 'failed';
|
92
|
+
|
93
|
+
transaction.status = 'failed'
|
94
|
+
await transaction.save();
|
95
|
+
protocol.sendTransaction(transaction)
|
96
|
+
return;
|
97
|
+
}
|
121
98
|
|
122
99
|
let gnosisTx = await generateGnosisTransaction({
|
123
100
|
baseGas: "0",
|
124
|
-
data
|
101
|
+
data,
|
125
102
|
gasPrice: "0",
|
126
103
|
gasToken: "0x0000000000000000000000000000000000000000",
|
127
104
|
nonce: '0',
|
128
105
|
operation: "1",
|
129
106
|
refundReceiver: "0x0000000000000000000000000000000000000000",
|
130
|
-
safeAddress:
|
107
|
+
safeAddress: this.safeContractAddress,
|
131
108
|
safeTxGas: "79668",
|
132
|
-
to: addresses[transaction.
|
109
|
+
to: addresses[transaction.sourceChainId].multisend,
|
133
110
|
value: "0",
|
134
|
-
}, safeContract);
|
111
|
+
}, this.safeContract);
|
135
112
|
|
136
|
-
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()));
|
137
114
|
|
138
115
|
const ownerPeerIds = peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id)
|
139
116
|
|
140
117
|
console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
|
141
118
|
|
142
119
|
console.log(ownerPeerIds);
|
143
|
-
|
120
|
+
|
144
121
|
const signatures = await protocol.requestSignatures({
|
145
122
|
type: 'source',
|
146
123
|
transactionHash: transaction.transactionHash,
|
@@ -155,18 +132,17 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
155
132
|
|
156
133
|
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
157
134
|
await transaction.save();
|
158
|
-
transaction.
|
159
|
-
transaction.
|
135
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
136
|
+
transaction.sourceStatus = 'uninitialised'
|
160
137
|
|
161
138
|
await transaction.save();
|
162
139
|
const errorMessage = signatures.find(s => !!s.error)?.error;
|
163
140
|
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
164
141
|
}
|
165
142
|
|
166
|
-
|
167
143
|
console.log(`Executing transaction for execution ${transaction.transactionHash}`)
|
168
144
|
|
169
|
-
const { data: txData } = await safeContract.populateTransaction.execTransaction(
|
145
|
+
const { data: txData } = await this.safeContract.populateTransaction.execTransaction(
|
170
146
|
gnosisTx.to,
|
171
147
|
gnosisTx.value,
|
172
148
|
gnosisTx.data,
|
@@ -179,20 +155,15 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
179
155
|
buildSignatureBytes(validSignatures)
|
180
156
|
);
|
181
157
|
|
182
|
-
|
183
|
-
from:
|
184
|
-
gasPrice: BigNumber.from(120 * 10 ** 9)
|
185
|
-
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,
|
186
162
|
data: txData,
|
187
163
|
})
|
188
164
|
|
165
|
+
console.log(txSent);
|
189
166
|
|
190
|
-
const txSent = await targetWallet.sendTransaction({
|
191
|
-
from: targetWallet.address,
|
192
|
-
gasPrice: BigNumber.from(120 * 10 ** 9),
|
193
|
-
to: safeAddress,
|
194
|
-
data: txData,
|
195
|
-
})
|
196
167
|
|
197
168
|
const receipt = await txSent.wait();
|
198
169
|
|
@@ -200,32 +171,56 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
200
171
|
|
201
172
|
receipt.logs.forEach((log) => {
|
202
173
|
try {
|
203
|
-
parsedLogs.push(safeContract.interface.parseLog(log));
|
174
|
+
parsedLogs.push(this.safeContract.interface.parseLog(log));
|
204
175
|
} catch (e) { }
|
205
176
|
});
|
206
177
|
|
207
178
|
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
208
179
|
console.log('ExecutionSuccess')
|
209
|
-
transaction.
|
210
|
-
|
211
|
-
|
180
|
+
transaction.sourceStatus = 'success'
|
181
|
+
if (txSent.blockNumber)
|
182
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
183
|
+
transaction.sourceTransactionHash = txSent.hash
|
184
|
+
transaction.sourceLogs = logs;
|
212
185
|
await transaction.save();
|
213
186
|
} else {
|
214
187
|
console.log('ExecutionFailure')
|
215
|
-
transaction.
|
216
|
-
|
188
|
+
transaction.sourceStatus = 'failed'
|
189
|
+
if (txSent.blockNumber)
|
190
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
191
|
+
transaction.sourceTransactionHash = txSent.hash
|
192
|
+
transaction.sourceTransactionHash = txSent.hash
|
217
193
|
transaction.status = 'failed'
|
218
194
|
await transaction.save();
|
219
195
|
}
|
196
|
+
|
197
|
+
protocol.sendTransaction(transaction)
|
220
198
|
}
|
221
199
|
|
222
200
|
async start(): Promise<void> {
|
201
|
+
this.contractAddress = addresses[this.chainId].interopXContract;
|
202
|
+
|
223
203
|
this.provider = new ethers.providers.JsonRpcProvider(
|
224
204
|
getRpcProviderUrl(this.chainId)
|
225
205
|
);
|
226
206
|
|
207
|
+
this.sourceWallet = new ethers.Wallet(config.privateKey!, this.provider);
|
208
|
+
|
209
|
+
this.contract = getContract<InteropXContract>(
|
210
|
+
this.contractAddress,
|
211
|
+
abi.interopXContract,
|
212
|
+
this.sourceWallet
|
213
|
+
);
|
214
|
+
|
215
|
+
this.safeContractAddress = addresses[this.chainId].gnosisSafe;
|
216
|
+
this.safeContract = getContract<GnosisSafe>(
|
217
|
+
this.safeContractAddress,
|
218
|
+
abi.gnosisSafe,
|
219
|
+
this.sourceWallet
|
220
|
+
);
|
221
|
+
|
227
222
|
await super.start()
|
228
223
|
}
|
229
224
|
}
|
230
225
|
|
231
|
-
export default
|
226
|
+
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;
|
@@ -25,9 +25,11 @@ class SyncTransactionStatusTask extends BaseTask {
|
|
25
25
|
|
26
26
|
const transaction = await Transaction.findOne({
|
27
27
|
where: {
|
28
|
-
|
28
|
+
sourceStatus: {
|
29
|
+
[Op.notIn] : ['success', 'failed'],
|
30
|
+
},
|
29
31
|
sourceCreatedAt: {
|
30
|
-
[Op.gte]: new Date(Date.now() -
|
32
|
+
[Op.gte]: new Date(Date.now() - 15 * 60 * 1000),
|
31
33
|
},
|
32
34
|
}
|
33
35
|
})
|
@@ -49,10 +51,12 @@ class SyncTransactionStatusTask extends BaseTask {
|
|
49
51
|
transaction.sourceStatus = transactionStatus.sourceStatus
|
50
52
|
transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash
|
51
53
|
transaction.sourceErrors = transactionStatus.sourceErrors
|
54
|
+
transaction.sourceLogs = transactionStatus.sourceLogs
|
52
55
|
|
53
56
|
transaction.targetStatus = transactionStatus.targetStatus
|
54
57
|
transaction.targetTransactionHash = transactionStatus.targetTransactionHash
|
55
58
|
transaction.targetErrors = transactionStatus.targetErrors
|
59
|
+
transaction.targetLogs = transactionStatus.targetLogs
|
56
60
|
|
57
61
|
transaction.status = transactionStatus.status
|
58
62
|
|