@instadapp/interop-x 0.0.0-dev.a775e30 → 0.0.0-dev.a861339
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/api/index.js +3 -0
- package/dist/src/constants/addresses.js +3 -3
- package/dist/src/constants/index.js +0 -1
- package/dist/src/db/models/transaction.js +27 -9
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +41 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +7 -18
- 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} +49 -51
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +80 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
- package/dist/src/tasks/index.js +13 -19
- 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 -84
- 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/api/index.ts +3 -0
- package/src/constants/addresses.ts +3 -3
- package/src/constants/index.ts +0 -1
- package/src/db/models/transaction.ts +66 -21
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +56 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +6 -17
- 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} +75 -95
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +112 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
- package/src/tasks/index.ts +17 -20
- 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 +46 -125
- 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
@@ -10,12 +10,17 @@ const config_1 = __importDefault(require("@/config"));
|
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const utils_1 = require("@/utils");
|
12
12
|
const constants_1 = require("@/constants");
|
13
|
+
const gnosis_1 = require("@/gnosis");
|
13
14
|
class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
14
15
|
constructor(libp2p) {
|
15
16
|
super(libp2p, '/interop-x/signatures');
|
16
17
|
this.timeout = 30000;
|
17
18
|
}
|
18
19
|
async response(data) {
|
20
|
+
console.log({
|
21
|
+
tag: 'SignatureDialProtocol',
|
22
|
+
data
|
23
|
+
});
|
19
24
|
const signer = config_1.default.wallet;
|
20
25
|
let transaction;
|
21
26
|
let maxTimeout = 20000;
|
@@ -33,17 +38,11 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
33
38
|
error: 'Event not found'
|
34
39
|
};
|
35
40
|
}
|
36
|
-
|
37
|
-
to: constants_1.addresses[transaction.targetChainId].multisend,
|
38
|
-
data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
|
39
|
-
chainId: transaction.targetChainId,
|
40
|
-
safeTxGas: data.safeTxGas,
|
41
|
-
nonce: data.safeNonce,
|
42
|
-
});
|
41
|
+
const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
|
43
42
|
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
44
|
-
to: constants_1.addresses[transaction.
|
45
|
-
data:
|
46
|
-
chainId: transaction.
|
43
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
44
|
+
data: gnosisData,
|
45
|
+
chainId: transaction.sourceChainId,
|
47
46
|
safeTxGas: data.safeTxGas,
|
48
47
|
nonce: data.safeNonce,
|
49
48
|
}, { signer });
|
package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js}
RENAMED
@@ -18,9 +18,11 @@ class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol
|
|
18
18
|
sourceStatus: transaction.sourceStatus,
|
19
19
|
sourceTransactionHash: transaction.sourceTransactionHash,
|
20
20
|
sourceErrors: transaction.sourceErrors,
|
21
|
+
sourceLogs: transaction.sourceLogs,
|
21
22
|
targetStatus: transaction.targetStatus,
|
22
23
|
targetTransactionHash: transaction.targetTransactionHash,
|
23
24
|
targetErrors: transaction.targetErrors,
|
25
|
+
targetLogs: transaction.targetLogs,
|
24
26
|
status: transaction.status,
|
25
27
|
};
|
26
28
|
}
|
@@ -10,7 +10,7 @@ const SignatureDialProtocol_1 = require("./dial/SignatureDialProtocol");
|
|
10
10
|
const __1 = require("..");
|
11
11
|
const config_1 = __importDefault(require("@/config"));
|
12
12
|
const types_1 = require("@/types");
|
13
|
-
const
|
13
|
+
const TransactionStatusDialProtocol_1 = require("./dial/TransactionStatusDialProtocol");
|
14
14
|
class Protocol extends stream_1.EventEmitter {
|
15
15
|
constructor() {
|
16
16
|
super(...arguments);
|
@@ -31,21 +31,31 @@ class Protocol extends stream_1.EventEmitter {
|
|
31
31
|
encode: (transaction) => [
|
32
32
|
Buffer.from(transaction.transactionHash),
|
33
33
|
Buffer.from(transaction.sourceStatus),
|
34
|
-
Buffer.from(transaction.sourceTransactionHash),
|
34
|
+
Buffer.from(transaction.sourceTransactionHash || ''),
|
35
35
|
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
36
|
+
transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
36
37
|
Buffer.from(transaction.targetStatus),
|
37
|
-
Buffer.from(transaction.targetTransactionHash),
|
38
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
38
39
|
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
40
|
+
transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
39
41
|
Buffer.from(transaction.status),
|
40
42
|
],
|
41
|
-
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
|
43
|
+
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
|
42
44
|
transactionHash: transactionHash.toString(),
|
43
45
|
sourceStatus: sourceStatus.toString(),
|
44
|
-
sourceTransactionHash: sourceTransactionHash.toString(),
|
46
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
45
47
|
sourceErrors: sourceErrors.map((e) => e.toString()),
|
48
|
+
sourceLogs: sourceLogs.map(e => ({
|
49
|
+
type: e[0].toString(),
|
50
|
+
message: e[1].toString(),
|
51
|
+
})),
|
46
52
|
targetStatus: targetStatus.toString(),
|
47
|
-
targetTransactionHash: targetTransactionHash.toString(),
|
53
|
+
targetTransactionHash: targetTransactionHash.toString() || null,
|
48
54
|
targetErrors: targetErrors.map((e) => e.toString()),
|
55
|
+
targetLogs: targetLogs.map(e => ({
|
56
|
+
type: e[0].toString(),
|
57
|
+
message: e[1].toString(),
|
58
|
+
})),
|
49
59
|
status: status.toString(),
|
50
60
|
}),
|
51
61
|
},
|
@@ -65,7 +75,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
65
75
|
});
|
66
76
|
});
|
67
77
|
this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
|
68
|
-
this.transactionStatus = new
|
78
|
+
this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
|
69
79
|
}
|
70
80
|
init() {
|
71
81
|
this.libp2p.pubsub.subscribe(this.topic);
|
@@ -10,23 +10,15 @@ const abi_1 = __importDefault(require("@/abi"));
|
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const utils_1 = require("@/utils");
|
12
12
|
const constants_1 = require("@/constants");
|
13
|
-
const config_1 = __importDefault(require("@/config"));
|
14
13
|
const sequelize_1 = require("sequelize");
|
14
|
+
const config_1 = __importDefault(require("@/config"));
|
15
15
|
const waait_1 = __importDefault(require("waait"));
|
16
|
+
const gnosis_1 = require("@/gnosis");
|
16
17
|
const net_1 = require("@/net");
|
17
|
-
|
18
|
-
console.log(transactionData);
|
19
|
-
let isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
|
20
|
-
while (isExecuted == 1) {
|
21
|
-
transactionData.safeTxGas = ethers_1.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString();
|
22
|
-
isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
|
23
|
-
}
|
24
|
-
return transactionData;
|
25
|
-
};
|
26
|
-
class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
18
|
+
class ProccessBridgeRequestEvents extends BaseTask_1.BaseTask {
|
27
19
|
constructor({ chainId }) {
|
28
20
|
super({
|
29
|
-
logger: new logger_1.default("
|
21
|
+
logger: new logger_1.default("InteropXContract::ProccessBridgeRequestEvents"),
|
30
22
|
});
|
31
23
|
this.leadNodeOnly = true;
|
32
24
|
this.chainId = chainId;
|
@@ -37,19 +29,17 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
37
29
|
const transaction = await db_1.Transaction.findOne({
|
38
30
|
where: {
|
39
31
|
status: 'pending',
|
40
|
-
sourceStatus: '
|
41
|
-
|
42
|
-
action: 'deposit',
|
43
|
-
sourceCreatedAt: {
|
32
|
+
sourceStatus: 'uninitialised',
|
33
|
+
createdAt: {
|
44
34
|
[sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
45
35
|
},
|
46
|
-
|
36
|
+
sourceDelayUntil: {
|
47
37
|
[sequelize_1.Op.or]: {
|
48
38
|
[sequelize_1.Op.is]: null,
|
49
39
|
[sequelize_1.Op.lt]: new Date(),
|
50
40
|
}
|
51
41
|
},
|
52
|
-
|
42
|
+
requestBlockNumber: {
|
53
43
|
[sequelize_1.Op.lt]: blockNumber - 12,
|
54
44
|
},
|
55
45
|
sourceChainId: this.chainId,
|
@@ -61,27 +51,36 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
61
51
|
console.log(`Processing transaction ${transaction.transactionHash}`);
|
62
52
|
transaction.targetStatus = 'pending';
|
63
53
|
await transaction.save();
|
64
|
-
|
65
|
-
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
|
66
|
-
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
67
|
-
const safeAddress = constants_1.addresses[transaction.targetChainId].gnosisSafe;
|
68
|
-
const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
|
69
|
-
const ownersThreshold = await safeContract.getThreshold();
|
54
|
+
const ownersThreshold = await this.safeContract.getThreshold();
|
70
55
|
await (0, waait_1.default)(10000);
|
71
|
-
let
|
56
|
+
let data, logs = [];
|
57
|
+
try {
|
58
|
+
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, 'source'));
|
59
|
+
}
|
60
|
+
catch (error) {
|
61
|
+
console.log(error);
|
62
|
+
transaction.sourceStatus = 'failed';
|
63
|
+
transaction.sourceErrors = [error.message];
|
64
|
+
transaction.targetStatus = 'failed';
|
65
|
+
transaction.status = 'failed';
|
66
|
+
await transaction.save();
|
67
|
+
net_1.protocol.sendTransaction(transaction);
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
72
71
|
baseGas: "0",
|
73
|
-
data
|
72
|
+
data,
|
74
73
|
gasPrice: "0",
|
75
74
|
gasToken: "0x0000000000000000000000000000000000000000",
|
76
75
|
nonce: '0',
|
77
76
|
operation: "1",
|
78
77
|
refundReceiver: "0x0000000000000000000000000000000000000000",
|
79
|
-
safeAddress:
|
78
|
+
safeAddress: this.safeContractAddress,
|
80
79
|
safeTxGas: "79668",
|
81
|
-
to: constants_1.addresses[transaction.
|
80
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
82
81
|
value: "0",
|
83
|
-
}, safeContract);
|
84
|
-
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
82
|
+
}, this.safeContract);
|
83
|
+
const owners = await this.safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
85
84
|
const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
|
86
85
|
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
87
86
|
console.log(ownerPeerIds);
|
@@ -95,55 +94,54 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
95
94
|
console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
|
96
95
|
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
97
96
|
await transaction.save();
|
98
|
-
transaction.
|
99
|
-
transaction.
|
97
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
98
|
+
transaction.sourceStatus = 'uninitialised';
|
100
99
|
await transaction.save();
|
101
100
|
const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
102
101
|
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
103
102
|
}
|
104
103
|
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
105
|
-
const { data: txData } = await safeContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
|
106
|
-
|
107
|
-
from:
|
108
|
-
gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9)
|
109
|
-
to:
|
110
|
-
data: txData,
|
111
|
-
});
|
112
|
-
const txSent = await targetWallet.sendTransaction({
|
113
|
-
from: targetWallet.address,
|
114
|
-
gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9),
|
115
|
-
to: safeAddress,
|
104
|
+
const { data: txData } = await this.safeContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
|
105
|
+
const txSent = await this.sourceWallet.sendTransaction({
|
106
|
+
from: this.sourceWallet.address,
|
107
|
+
gasPrice: ethers_1.ethers.BigNumber.from(120 * 10 ** 9),
|
108
|
+
to: this.safeContractAddress,
|
116
109
|
data: txData,
|
117
110
|
});
|
111
|
+
console.log(txSent);
|
118
112
|
const receipt = await txSent.wait();
|
119
113
|
const parsedLogs = [];
|
120
114
|
receipt.logs.forEach((log) => {
|
121
115
|
try {
|
122
|
-
parsedLogs.push(safeContract.interface.parseLog(log));
|
116
|
+
parsedLogs.push(this.safeContract.interface.parseLog(log));
|
123
117
|
}
|
124
118
|
catch (e) { }
|
125
119
|
});
|
126
120
|
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
127
121
|
console.log('ExecutionSuccess');
|
128
|
-
transaction.
|
129
|
-
transaction.
|
122
|
+
transaction.sourceStatus = 'success';
|
123
|
+
transaction.sourceTransactionHash = txSent.hash;
|
124
|
+
transaction.sourceLogs = logs;
|
130
125
|
transaction.status = 'success';
|
131
126
|
await transaction.save();
|
132
127
|
}
|
133
128
|
else {
|
134
129
|
console.log('ExecutionFailure');
|
135
|
-
transaction.
|
136
|
-
transaction.
|
130
|
+
transaction.sourceStatus = 'failed';
|
131
|
+
transaction.sourceTransactionHash = txSent.hash;
|
137
132
|
transaction.status = 'failed';
|
138
133
|
await transaction.save();
|
139
134
|
}
|
140
135
|
net_1.protocol.sendTransaction(transaction);
|
141
136
|
}
|
142
137
|
async start() {
|
143
|
-
this.contractAddress = constants_1.addresses[this.chainId].
|
138
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
144
139
|
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
145
|
-
this.
|
140
|
+
this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider);
|
141
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, this.sourceWallet);
|
142
|
+
this.safeContractAddress = constants_1.addresses[this.chainId].gnosisSafe;
|
143
|
+
this.safeContract = (0, utils_1.getContract)(this.safeContractAddress, abi_1.default.gnosisSafe, this.sourceWallet);
|
146
144
|
await super.start();
|
147
145
|
}
|
148
146
|
}
|
149
|
-
exports.default =
|
147
|
+
exports.default = ProccessBridgeRequestEvents;
|
@@ -0,0 +1,78 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const BaseTask_1 = require("../BaseTask");
|
7
|
+
const logger_1 = __importDefault(require("@/logger"));
|
8
|
+
const ethers_1 = require("ethers");
|
9
|
+
const abi_1 = __importDefault(require("@/abi"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const constants_1 = require("@/constants");
|
13
|
+
const config_1 = __importDefault(require("@/config"));
|
14
|
+
class SyncBridgeRequestEvents extends BaseTask_1.BaseTask {
|
15
|
+
constructor({ chainId }) {
|
16
|
+
super({
|
17
|
+
logger: new logger_1.default("InteropXContract::SyncBridgeRequestEvents"),
|
18
|
+
});
|
19
|
+
this.chainId = chainId;
|
20
|
+
}
|
21
|
+
async pollHandler() {
|
22
|
+
const currentBlock = await this.provider.getBlockNumber();
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogBridgeRequest(), currentBlock - 2000, currentBlock);
|
24
|
+
let processedEvents = 0;
|
25
|
+
for (const event of events) {
|
26
|
+
try {
|
27
|
+
if (!event.args) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
const { bridger, position, sourceChainId, targetChainId, metadata } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
action: 'withdraw',
|
33
|
+
bridger,
|
34
|
+
requestTransactionHash: event.transactionHash,
|
35
|
+
sourceChainId: sourceChainId.toNumber(),
|
36
|
+
targetChainId: targetChainId.toNumber(),
|
37
|
+
};
|
38
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
39
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
40
|
+
if (transaction) {
|
41
|
+
continue;
|
42
|
+
}
|
43
|
+
await db_1.Transaction.create(Object.assign(Object.assign({ transactionHash }, uniqueIdentifier), { position,
|
44
|
+
metadata, requestBlockNumber: event.blockNumber, requestEvent: {
|
45
|
+
bridger,
|
46
|
+
position: {
|
47
|
+
withdraw: position.withdraw.map((v) => ({
|
48
|
+
sourceToken: v.sourceToken,
|
49
|
+
targetToken: v.targetToken,
|
50
|
+
amount: v.amount.toString()
|
51
|
+
})),
|
52
|
+
supply: position.supply.map((v) => ({
|
53
|
+
sourceToken: v.sourceToken,
|
54
|
+
targetToken: v.targetToken,
|
55
|
+
amount: v.amount.toString()
|
56
|
+
})),
|
57
|
+
},
|
58
|
+
sourceChainId: sourceChainId.toNumber(),
|
59
|
+
targetChainId: targetChainId.toNumber(),
|
60
|
+
metadata,
|
61
|
+
} }));
|
62
|
+
this.logger.info(`New bridge request received: ${transactionHash} `);
|
63
|
+
}
|
64
|
+
catch (error) {
|
65
|
+
this.logger.error(error);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
if (processedEvents > 0)
|
69
|
+
this.logger.info(`${processedEvents} events processed`);
|
70
|
+
}
|
71
|
+
async start() {
|
72
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
73
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
74
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
75
|
+
await super.start();
|
76
|
+
}
|
77
|
+
}
|
78
|
+
exports.default = SyncBridgeRequestEvents;
|
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const BaseTask_1 = require("../BaseTask");
|
7
|
+
const logger_1 = __importDefault(require("@/logger"));
|
8
|
+
const ethers_1 = require("ethers");
|
9
|
+
const abi_1 = __importDefault(require("@/abi"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const constants_1 = require("@/constants");
|
13
|
+
const config_1 = __importDefault(require("@/config"));
|
14
|
+
class SyncBridgeRequestSentEvents extends BaseTask_1.BaseTask {
|
15
|
+
constructor({ chainId }) {
|
16
|
+
super({
|
17
|
+
logger: new logger_1.default("InteropXContract::SyncBridgeRequestSentEvents"),
|
18
|
+
});
|
19
|
+
this.chainId = chainId;
|
20
|
+
}
|
21
|
+
async pollHandler() {
|
22
|
+
const currentBlock = await this.provider.getBlockNumber();
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogBridgeRequestSent(), currentBlock - 2000, currentBlock);
|
24
|
+
let processedEvents = 0;
|
25
|
+
for (const event of events) {
|
26
|
+
try {
|
27
|
+
if (!event.args) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
const { bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
action: 'withdraw',
|
33
|
+
bridger,
|
34
|
+
requestTransactionHash,
|
35
|
+
sourceChainId: sourceChainId,
|
36
|
+
targetChainId: targetChainId,
|
37
|
+
};
|
38
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
39
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
40
|
+
if (!transaction) {
|
41
|
+
continue;
|
42
|
+
}
|
43
|
+
transaction.sourceStatus = 'success';
|
44
|
+
transaction.requestSentEvent = {
|
45
|
+
bridger,
|
46
|
+
position: {
|
47
|
+
withdraw: position.withdraw.map((v) => ({
|
48
|
+
sourceToken: v.sourceToken,
|
49
|
+
targetToken: v.targetToken,
|
50
|
+
amount: v.amount.toString()
|
51
|
+
})),
|
52
|
+
supply: position.supply.map((v) => ({
|
53
|
+
sourceToken: v.sourceToken,
|
54
|
+
targetToken: v.targetToken,
|
55
|
+
amount: v.amount.toString()
|
56
|
+
})),
|
57
|
+
},
|
58
|
+
sourceChainId: sourceChainId,
|
59
|
+
targetChainId: targetChainId,
|
60
|
+
metadata,
|
61
|
+
requestTransactionHash,
|
62
|
+
};
|
63
|
+
await transaction.save();
|
64
|
+
this.logger.info(`New bridge reques sent received: ${transactionHash} `);
|
65
|
+
}
|
66
|
+
catch (error) {
|
67
|
+
this.logger.error(error);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
if (processedEvents > 0)
|
71
|
+
this.logger.info(`${processedEvents} events processed`);
|
72
|
+
}
|
73
|
+
async start() {
|
74
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
75
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
76
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
77
|
+
await super.start();
|
78
|
+
}
|
79
|
+
}
|
80
|
+
exports.default = SyncBridgeRequestSentEvents;
|
@@ -42,9 +42,11 @@ class SyncTransactionStatusTask extends BaseTask_1.BaseTask {
|
|
42
42
|
transaction.sourceStatus = transactionStatus.sourceStatus;
|
43
43
|
transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash;
|
44
44
|
transaction.sourceErrors = transactionStatus.sourceErrors;
|
45
|
+
transaction.sourceLogs = transactionStatus.sourceLogs;
|
45
46
|
transaction.targetStatus = transactionStatus.targetStatus;
|
46
47
|
transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
|
47
48
|
transaction.targetErrors = transactionStatus.targetErrors;
|
49
|
+
transaction.targetLogs = transactionStatus.targetLogs;
|
48
50
|
transaction.status = transactionStatus.status;
|
49
51
|
await transaction.save();
|
50
52
|
this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
|
package/dist/src/tasks/index.js
CHANGED
@@ -4,36 +4,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.Tasks = void 0;
|
7
|
-
const
|
8
|
-
const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
|
9
|
-
const SyncWithdrawEvents_1 = __importDefault(require("./InteropBridge/SyncWithdrawEvents"));
|
10
|
-
const ProcessWithdrawEvents_1 = __importDefault(require("./InteropBridge/ProcessWithdrawEvents"));
|
7
|
+
const waait_1 = __importDefault(require("waait"));
|
11
8
|
const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
|
12
|
-
const
|
9
|
+
const SyncBridgeRequestEvents_1 = __importDefault(require("./InteropXContract/SyncBridgeRequestEvents"));
|
10
|
+
const ProcessBridgeRequestEvents_1 = __importDefault(require("./InteropXContract/ProcessBridgeRequestEvents"));
|
11
|
+
const SyncBridgeRequestSentEvents_1 = __importDefault(require("./InteropXContract/SyncBridgeRequestSentEvents"));
|
13
12
|
class Tasks {
|
14
13
|
constructor() {
|
15
14
|
this.tasks = [
|
16
|
-
new
|
15
|
+
// new SyncTransactionStatusTask(),
|
17
16
|
new AutoUpdateTask_1.default(),
|
18
|
-
|
19
|
-
|
20
|
-
}),
|
21
|
-
new
|
22
|
-
|
23
|
-
}),
|
24
|
-
new
|
25
|
-
chainId: 137,
|
26
|
-
itokenAddress: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
|
27
|
-
}),
|
28
|
-
new ProcessWithdrawEvents_1.default({
|
29
|
-
chainId: 137,
|
30
|
-
})
|
17
|
+
// InteropXContract
|
18
|
+
new SyncBridgeRequestEvents_1.default({ chainId: 137 }),
|
19
|
+
new SyncBridgeRequestEvents_1.default({ chainId: 43114 }),
|
20
|
+
new ProcessBridgeRequestEvents_1.default({ chainId: 137 }),
|
21
|
+
new ProcessBridgeRequestEvents_1.default({ chainId: 43114 }),
|
22
|
+
new SyncBridgeRequestSentEvents_1.default({ chainId: 137 }),
|
23
|
+
new SyncBridgeRequestSentEvents_1.default({ chainId: 43114 }),
|
31
24
|
];
|
32
25
|
}
|
33
26
|
async start() {
|
34
27
|
for (const task of this.tasks) {
|
35
28
|
try {
|
36
29
|
task.start();
|
30
|
+
await (0, waait_1.default)(1000);
|
37
31
|
}
|
38
32
|
catch (error) {
|
39
33
|
console.error(`Error starting task: ${task.constructor.name}`);
|
File without changes
|