@instadapp/interop-x 0.0.0-dev.8a0297a → 0.0.0-dev.8a917f1
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 +7 -6
- package/dist/src/abi/interopBridgeToken.json +21 -9
- package/dist/src/abi/interopXGateway.json +11 -11
- package/dist/src/api/index.js +3 -3
- package/dist/src/config/index.js +11 -1
- package/dist/src/constants/addresses.js +1 -1
- package/dist/src/constants/itokens.js +1 -1
- package/dist/src/index.js +69 -7
- package/dist/src/net/peer/index.js +2 -1
- package/dist/src/net/pool/index.js +25 -9
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +11 -4
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
- package/dist/src/net/protocol/index.js +41 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/src/tasks/BaseTask.js +11 -3
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +146 -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 +32 -21
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +5 -6
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
- package/dist/src/tasks/index.js +25 -0
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
- package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
- package/dist/src/utils/index.js +71 -11
- package/package.json +7 -6
- package/src/abi/interopBridgeToken.json +21 -9
- package/src/abi/interopXGateway.json +11 -11
- package/src/api/index.ts +2 -2
- package/src/config/index.ts +11 -1
- package/src/constants/addresses.ts +1 -1
- package/src/constants/itokens.ts +1 -1
- package/src/index.ts +90 -9
- package/src/net/peer/index.ts +2 -1
- package/src/net/pool/index.ts +33 -13
- package/src/net/protocol/dial/SignatureDialProtocol.ts +12 -4
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
- package/src/net/protocol/index.ts +57 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +13 -3
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +231 -0
- package/src/tasks/InteropBridge/SyncBurnEvents.ts +121 -0
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +37 -25
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +5 -7
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
- package/src/tasks/index.ts +37 -0
- 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 +93 -12
@@ -14,6 +14,7 @@ class BaseTask extends events_1.default {
|
|
14
14
|
this.started = false;
|
15
15
|
this.pollIntervalMs = 10 * 1000;
|
16
16
|
this.leadNodeOnly = false;
|
17
|
+
this.exceptLeadNode = false;
|
17
18
|
this.logger = logger !== null && logger !== void 0 ? logger : new logger_1.default('BaseTask');
|
18
19
|
}
|
19
20
|
async pollCheck() {
|
@@ -34,10 +35,17 @@ class BaseTask extends events_1.default {
|
|
34
35
|
}
|
35
36
|
}
|
36
37
|
prePollHandler() {
|
37
|
-
if (
|
38
|
-
|
38
|
+
if (config_1.default.isMaintenanceMode()) {
|
39
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.');
|
40
|
+
return false;
|
39
41
|
}
|
40
|
-
|
42
|
+
if (this.exceptLeadNode) {
|
43
|
+
return !config_1.default.isLeadNode();
|
44
|
+
}
|
45
|
+
if (this.leadNodeOnly) {
|
46
|
+
return config_1.default.isLeadNode();
|
47
|
+
}
|
48
|
+
return true;
|
41
49
|
}
|
42
50
|
async pollHandler() {
|
43
51
|
this.logger.warn('pollHandler not implemented');
|
@@ -0,0 +1,146 @@
|
|
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
|
+
const sequelize_1 = require("sequelize");
|
15
|
+
const waait_1 = __importDefault(require("waait"));
|
16
|
+
const net_1 = require("@/net");
|
17
|
+
const generateGnosisTransaction = async (transactionData, safeContract) => {
|
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 ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
27
|
+
constructor({ chainId }) {
|
28
|
+
super({
|
29
|
+
logger: new logger_1.default("InteropXGateway::ProcessWithdrawEvents"),
|
30
|
+
});
|
31
|
+
this.leadNodeOnly = true;
|
32
|
+
this.chainId = chainId;
|
33
|
+
}
|
34
|
+
async pollHandler() {
|
35
|
+
var _a;
|
36
|
+
const blockNumber = await this.provider.getBlockNumber();
|
37
|
+
const transaction = await db_1.Transaction.findOne({
|
38
|
+
where: {
|
39
|
+
status: 'pending',
|
40
|
+
sourceStatus: 'success',
|
41
|
+
targetStatus: 'uninitialised',
|
42
|
+
action: 'withdraw',
|
43
|
+
sourceCreatedAt: {
|
44
|
+
[sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
45
|
+
},
|
46
|
+
targetDelayUntil: {
|
47
|
+
[sequelize_1.Op.or]: {
|
48
|
+
[sequelize_1.Op.is]: null,
|
49
|
+
[sequelize_1.Op.lt]: new Date(),
|
50
|
+
}
|
51
|
+
},
|
52
|
+
sourceBlockNumber: {
|
53
|
+
[sequelize_1.Op.lt]: blockNumber - 12,
|
54
|
+
},
|
55
|
+
sourceChainId: this.chainId,
|
56
|
+
}
|
57
|
+
});
|
58
|
+
if (!transaction) {
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
console.log(`Processing transaction ${transaction.transactionHash}`);
|
62
|
+
transaction.targetStatus = 'pending';
|
63
|
+
await transaction.save();
|
64
|
+
// refresh event data?
|
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();
|
70
|
+
await (0, waait_1.default)(10000);
|
71
|
+
let gnosisTx = await generateGnosisTransaction({
|
72
|
+
baseGas: "0",
|
73
|
+
data: await (0, utils_1.buildDataForTransaction)(transaction),
|
74
|
+
gasPrice: "0",
|
75
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
76
|
+
nonce: '0',
|
77
|
+
operation: "1",
|
78
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
79
|
+
safeAddress: safeAddress,
|
80
|
+
safeTxGas: "79668",
|
81
|
+
to: constants_1.addresses[transaction.targetChainId].multisend,
|
82
|
+
value: "0",
|
83
|
+
}, safeContract);
|
84
|
+
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
85
|
+
const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
|
86
|
+
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
87
|
+
console.log(ownerPeerIds);
|
88
|
+
const signatures = await net_1.protocol.requestSignatures({
|
89
|
+
type: 'source',
|
90
|
+
transactionHash: transaction.transactionHash,
|
91
|
+
safeTxGas: gnosisTx.safeTxGas,
|
92
|
+
safeNonce: gnosisTx.nonce
|
93
|
+
}, ownerPeerIds);
|
94
|
+
const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x');
|
95
|
+
console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
|
96
|
+
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
97
|
+
await transaction.save();
|
98
|
+
transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
|
99
|
+
transaction.targetStatus = 'uninitialised';
|
100
|
+
await transaction.save();
|
101
|
+
const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
102
|
+
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
103
|
+
}
|
104
|
+
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
|
+
console.log({
|
107
|
+
from: targetWallet.address,
|
108
|
+
gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9).toString(),
|
109
|
+
to: safeAddress,
|
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,
|
116
|
+
data: txData,
|
117
|
+
});
|
118
|
+
const receipt = await txSent.wait();
|
119
|
+
const parsedLogs = [];
|
120
|
+
receipt.logs.forEach((log) => {
|
121
|
+
try {
|
122
|
+
parsedLogs.push(safeContract.interface.parseLog(log));
|
123
|
+
}
|
124
|
+
catch (e) { }
|
125
|
+
});
|
126
|
+
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
127
|
+
console.log('ExecutionSuccess');
|
128
|
+
transaction.targetStatus = 'success';
|
129
|
+
transaction.targetTransactionHash = txSent.hash;
|
130
|
+
transaction.status = 'success';
|
131
|
+
await transaction.save();
|
132
|
+
}
|
133
|
+
else {
|
134
|
+
console.log('ExecutionFailure');
|
135
|
+
transaction.targetStatus = 'failed';
|
136
|
+
transaction.targetTransactionHash = txSent.hash;
|
137
|
+
transaction.status = 'failed';
|
138
|
+
await transaction.save();
|
139
|
+
}
|
140
|
+
}
|
141
|
+
async start() {
|
142
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
143
|
+
await super.start();
|
144
|
+
}
|
145
|
+
}
|
146
|
+
exports.default = ProcessWithdrawEvents;
|
@@ -0,0 +1,71 @@
|
|
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 config_1 = __importDefault(require("@/config"));
|
13
|
+
class SyncBurnEvents extends BaseTask_1.BaseTask {
|
14
|
+
constructor({ chainId, itokenAddress }) {
|
15
|
+
super({
|
16
|
+
logger: new logger_1.default("InteropBridgeToken::SyncBurnEvents"),
|
17
|
+
});
|
18
|
+
this.chainId = chainId;
|
19
|
+
this.itokenAddress = itokenAddress;
|
20
|
+
}
|
21
|
+
async pollHandler() {
|
22
|
+
const currentBlock = await this.provider.getBlockNumber();
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.Burn(), currentBlock - 2000, currentBlock);
|
24
|
+
let processedEvents = 0;
|
25
|
+
for (const event of events) {
|
26
|
+
try {
|
27
|
+
if (!event.args) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
const { to, amount, sourceChainId, targetChainId } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
action: 'withdraw',
|
33
|
+
submitTransactionHash: event.transactionHash,
|
34
|
+
sourceChainId: sourceChainId,
|
35
|
+
targetChainId: targetChainId,
|
36
|
+
};
|
37
|
+
if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
|
38
|
+
continue;
|
39
|
+
}
|
40
|
+
const tx = await event.getTransaction();
|
41
|
+
await db_1.Transaction.create(Object.assign(Object.assign({}, uniqueIdentifier), { transactionHash: (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier), from: tx.from, to, submitTransactionHash: event.transactionHash, submitBlockNumber: event.blockNumber,
|
42
|
+
// submit & source are the same
|
43
|
+
sourceTransactionHash: event.transactionHash, sourceBlockNumber: event.blockNumber, sourceStatus: "success", targetStatus: "uninitialised", submitEvent: {
|
44
|
+
to,
|
45
|
+
amount: amount.toString(),
|
46
|
+
itoken: this.itokenAddress,
|
47
|
+
sourceChainId: sourceChainId,
|
48
|
+
targetChainId: targetChainId,
|
49
|
+
}, sourceEvent: {
|
50
|
+
to,
|
51
|
+
amount: amount.toString(),
|
52
|
+
itoken: this.itokenAddress,
|
53
|
+
sourceChainId: sourceChainId,
|
54
|
+
targetChainId: targetChainId,
|
55
|
+
}, status: "pending" }));
|
56
|
+
this.logger.info(`Withdraw queued: ${event.transactionHash} ${event.blockNumber}`);
|
57
|
+
}
|
58
|
+
catch (error) {
|
59
|
+
this.logger.error(error);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
if (processedEvents > 0)
|
63
|
+
this.logger.info(`${processedEvents} events processed`);
|
64
|
+
}
|
65
|
+
async start() {
|
66
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
67
|
+
this.contract = (0, utils_1.getContract)(this.itokenAddress, abi_1.default.interopBridgeToken, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
68
|
+
await super.start();
|
69
|
+
}
|
70
|
+
}
|
71
|
+
exports.default = SyncBurnEvents;
|
@@ -0,0 +1,67 @@
|
|
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 config_1 = __importDefault(require("@/config"));
|
13
|
+
class SyncMintEvents extends BaseTask_1.BaseTask {
|
14
|
+
constructor({ chainId, itokenAddress }) {
|
15
|
+
super({
|
16
|
+
logger: new logger_1.default("InteropBridgeToken::SyncMintEvents"),
|
17
|
+
});
|
18
|
+
this.chainId = chainId;
|
19
|
+
this.itokenAddress = itokenAddress;
|
20
|
+
}
|
21
|
+
async pollHandler() {
|
22
|
+
const currentBlock = await this.provider.getBlockNumber();
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.Mint(), currentBlock - 500, currentBlock);
|
24
|
+
for (const event of events) {
|
25
|
+
try {
|
26
|
+
if (!event.args) {
|
27
|
+
continue;
|
28
|
+
}
|
29
|
+
const { sourceChainId, targetChainId, amount, to, submitTransactionHash } = event.args;
|
30
|
+
const uniqueIdentifier = {
|
31
|
+
action: 'deposit',
|
32
|
+
submitTransactionHash: submitTransactionHash,
|
33
|
+
sourceChainId: sourceChainId,
|
34
|
+
targetChainId: targetChainId,
|
35
|
+
targetEvent: null
|
36
|
+
};
|
37
|
+
const transaction = await db_1.Transaction.findOne({ where: uniqueIdentifier });
|
38
|
+
if (!transaction) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
const tx = await event.getTransaction();
|
42
|
+
transaction.targetStatus = 'success';
|
43
|
+
transaction.targetErrors = [];
|
44
|
+
transaction.targetTransactionHash = tx.hash;
|
45
|
+
transaction.targetEvent = {
|
46
|
+
sourceChainId,
|
47
|
+
targetChainId,
|
48
|
+
amount: amount.toString(),
|
49
|
+
to,
|
50
|
+
submitTransactionHash
|
51
|
+
};
|
52
|
+
transaction.status = 'success';
|
53
|
+
await transaction.save();
|
54
|
+
this.logger.info(`Mint confirmation received: ${transaction.transactionHash} `);
|
55
|
+
}
|
56
|
+
catch (error) {
|
57
|
+
this.logger.error(error);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
async start() {
|
62
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
63
|
+
this.contract = (0, utils_1.getContract)(this.itokenAddress, abi_1.default.interopBridgeToken, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
64
|
+
await super.start();
|
65
|
+
}
|
66
|
+
}
|
67
|
+
exports.default = SyncMintEvents;
|
@@ -43,6 +43,12 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
43
43
|
sourceCreatedAt: {
|
44
44
|
[sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
45
45
|
},
|
46
|
+
targetDelayUntil: {
|
47
|
+
[sequelize_1.Op.or]: {
|
48
|
+
[sequelize_1.Op.is]: null,
|
49
|
+
[sequelize_1.Op.lt]: new Date(),
|
50
|
+
}
|
51
|
+
},
|
46
52
|
sourceBlockNumber: {
|
47
53
|
[sequelize_1.Op.lt]: blockNumber - 12,
|
48
54
|
},
|
@@ -52,6 +58,7 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
52
58
|
if (!transaction) {
|
53
59
|
return;
|
54
60
|
}
|
61
|
+
console.log(`Processing transaction ${transaction.transactionHash}`);
|
55
62
|
transaction.targetStatus = 'pending';
|
56
63
|
await transaction.save();
|
57
64
|
// refresh event data?
|
@@ -61,9 +68,22 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
61
68
|
const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
|
62
69
|
const ownersThreshold = await safeContract.getThreshold();
|
63
70
|
await (0, waait_1.default)(10000);
|
71
|
+
let data;
|
72
|
+
try {
|
73
|
+
data = await (0, utils_1.buildDataForTransaction)(transaction);
|
74
|
+
}
|
75
|
+
catch (error) {
|
76
|
+
console.log(error);
|
77
|
+
transaction.targetStatus = 'failed';
|
78
|
+
transaction.targetErrors = [error.message];
|
79
|
+
transaction.status = 'failed';
|
80
|
+
await transaction.save();
|
81
|
+
net_1.protocol.sendTransaction(transaction);
|
82
|
+
return;
|
83
|
+
}
|
64
84
|
let gnosisTx = await generateGnosisTransaction({
|
65
85
|
baseGas: "0",
|
66
|
-
data
|
86
|
+
data,
|
67
87
|
gasPrice: "0",
|
68
88
|
gasToken: "0x0000000000000000000000000000000000000000",
|
69
89
|
nonce: '0',
|
@@ -77,6 +97,7 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
77
97
|
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
78
98
|
const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
|
79
99
|
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
100
|
+
console.log(ownerPeerIds);
|
80
101
|
const signatures = await net_1.protocol.requestSignatures({
|
81
102
|
type: 'source',
|
82
103
|
transactionHash: transaction.transactionHash,
|
@@ -88,40 +109,22 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
88
109
|
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
89
110
|
await transaction.save();
|
90
111
|
transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
|
91
|
-
transaction.targetStatus = '
|
112
|
+
transaction.targetStatus = 'uninitialised';
|
92
113
|
await transaction.save();
|
93
114
|
const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
94
115
|
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
95
116
|
}
|
96
|
-
const execTransactionParams = [
|
97
|
-
gnosisTx.to,
|
98
|
-
gnosisTx.value,
|
99
|
-
gnosisTx.data,
|
100
|
-
gnosisTx.operation,
|
101
|
-
gnosisTx.safeTxGas,
|
102
|
-
gnosisTx.baseGas,
|
103
|
-
gnosisTx.gasPrice,
|
104
|
-
gnosisTx.gasToken,
|
105
|
-
gnosisTx.refundReceiver,
|
106
|
-
(0, utils_1.buildSignatureBytes)(validSignatures),
|
107
|
-
];
|
108
117
|
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
109
|
-
console.log({
|
110
|
-
execTransactionParams
|
111
|
-
});
|
112
118
|
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));
|
113
119
|
console.log({
|
114
120
|
from: targetWallet.address,
|
115
121
|
gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9).toString(),
|
116
|
-
gasLimit: ethers_1.BigNumber.from(6000000).toString(),
|
117
122
|
to: safeAddress,
|
118
123
|
data: txData,
|
119
124
|
});
|
120
|
-
return;
|
121
125
|
const txSent = await targetWallet.sendTransaction({
|
122
126
|
from: targetWallet.address,
|
123
127
|
gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9),
|
124
|
-
gasLimit: ethers_1.BigNumber.from(6000000),
|
125
128
|
to: safeAddress,
|
126
129
|
data: txData,
|
127
130
|
});
|
@@ -135,13 +138,21 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
135
138
|
});
|
136
139
|
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
137
140
|
console.log('ExecutionSuccess');
|
141
|
+
transaction.targetStatus = 'success';
|
142
|
+
transaction.targetTransactionHash = txSent.hash;
|
143
|
+
transaction.status = 'success';
|
144
|
+
await transaction.save();
|
138
145
|
}
|
139
146
|
else {
|
140
147
|
console.log('ExecutionFailure');
|
148
|
+
transaction.targetStatus = 'failed';
|
149
|
+
transaction.targetTransactionHash = txSent.hash;
|
150
|
+
transaction.status = 'failed';
|
151
|
+
await transaction.save();
|
141
152
|
}
|
153
|
+
net_1.protocol.sendTransaction(transaction);
|
142
154
|
}
|
143
155
|
async start() {
|
144
|
-
this.logger.info(`Starting execution watcher on interop chain`);
|
145
156
|
this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
|
146
157
|
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
147
158
|
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
@@ -31,8 +31,8 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
|
|
31
31
|
const uniqueIdentifier = {
|
32
32
|
action: 'deposit',
|
33
33
|
submitTransactionHash: event.transactionHash,
|
34
|
-
sourceChainId: sourceChainId
|
35
|
-
targetChainId: targetChainId
|
34
|
+
sourceChainId: sourceChainId,
|
35
|
+
targetChainId: targetChainId,
|
36
36
|
};
|
37
37
|
if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
|
38
38
|
continue;
|
@@ -45,17 +45,17 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
|
|
45
45
|
sourceChainId: sourceChainId.toString(),
|
46
46
|
targetChainId: targetChainId.toString(),
|
47
47
|
token: token,
|
48
|
-
|
48
|
+
amount: amount.toString(),
|
49
49
|
vnonce: vnonce.toString(),
|
50
50
|
}, sourceEvent: {
|
51
51
|
user,
|
52
52
|
sourceChainId: sourceChainId.toString(),
|
53
53
|
targetChainId: targetChainId.toString(),
|
54
54
|
token: token,
|
55
|
-
|
55
|
+
amount: amount.toString(),
|
56
56
|
vnonce: vnonce.toString(),
|
57
57
|
}, status: "pending" }));
|
58
|
-
this.logger.info(`
|
58
|
+
this.logger.info(`Deposit queued: ${event.transactionHash} ${event.blockNumber}`);
|
59
59
|
}
|
60
60
|
catch (error) {
|
61
61
|
this.logger.error(error);
|
@@ -65,7 +65,6 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
|
|
65
65
|
this.logger.info(`${processedEvents} events processed`);
|
66
66
|
}
|
67
67
|
async start() {
|
68
|
-
this.logger.info(`Starting execution watcher on interop chain`);
|
69
68
|
this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
|
70
69
|
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
71
70
|
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
@@ -0,0 +1,72 @@
|
|
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 SyncWithdrawEvents extends BaseTask_1.BaseTask {
|
15
|
+
constructor({ chainId }) {
|
16
|
+
super({
|
17
|
+
logger: new logger_1.default("InteropXGateway::SyncWithdrawEvents"),
|
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.LogGatewayWithdraw(), currentBlock - 500, currentBlock);
|
24
|
+
let processedEvents = 0;
|
25
|
+
for (const event of events) {
|
26
|
+
try {
|
27
|
+
if (!event.args) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
const { user, token, amount, sourceChainId, targetChainId, transactionHash } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
action: 'withdraw',
|
33
|
+
submitTransactionHash: transactionHash,
|
34
|
+
sourceChainId: sourceChainId,
|
35
|
+
targetChainId: targetChainId,
|
36
|
+
targetEvent: null
|
37
|
+
};
|
38
|
+
const transaction = await db_1.Transaction.findOne({ where: uniqueIdentifier });
|
39
|
+
if (!transaction) {
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
const tx = await event.getTransaction();
|
43
|
+
transaction.targetStatus = 'success';
|
44
|
+
transaction.targetErrors = [];
|
45
|
+
transaction.targetTransactionHash = tx.hash;
|
46
|
+
transaction.targetEvent = {
|
47
|
+
user,
|
48
|
+
token,
|
49
|
+
amount: amount.toString(),
|
50
|
+
sourceChainId,
|
51
|
+
targetChainId,
|
52
|
+
transactionHash,
|
53
|
+
};
|
54
|
+
transaction.status = 'success';
|
55
|
+
await transaction.save();
|
56
|
+
this.logger.info(`Witdraw confirmation received: ${transaction.transactionHash} `);
|
57
|
+
}
|
58
|
+
catch (error) {
|
59
|
+
this.logger.error(error);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
if (processedEvents > 0)
|
63
|
+
this.logger.info(`${processedEvents} events processed`);
|
64
|
+
}
|
65
|
+
async start() {
|
66
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
|
67
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
68
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
69
|
+
await super.start();
|
70
|
+
}
|
71
|
+
}
|
72
|
+
exports.default = SyncWithdrawEvents;
|
@@ -0,0 +1,53 @@
|
|
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 net_1 = require("@/net");
|
9
|
+
const db_1 = require("@/db");
|
10
|
+
const sequelize_1 = require("sequelize");
|
11
|
+
class SyncTransactionStatusTask extends BaseTask_1.BaseTask {
|
12
|
+
constructor() {
|
13
|
+
super({
|
14
|
+
logger: new logger_1.default("SyncTransactionStatusTask"),
|
15
|
+
});
|
16
|
+
this.pollIntervalMs = 60 * 1000;
|
17
|
+
this.exceptLeadNode = true;
|
18
|
+
}
|
19
|
+
async pollHandler() {
|
20
|
+
// if transaction is pending for more than 1 hour, check lead node for status
|
21
|
+
const leadNode = net_1.peerPool.getLeadPeer();
|
22
|
+
if (!leadNode) {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
const transaction = await db_1.Transaction.findOne({
|
26
|
+
where: {
|
27
|
+
status: 'pending',
|
28
|
+
sourceCreatedAt: {
|
29
|
+
[sequelize_1.Op.gte]: new Date(Date.now() - 60 * 60 * 1000),
|
30
|
+
},
|
31
|
+
}
|
32
|
+
});
|
33
|
+
if (!transaction) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
this.logger.info(`Requesting transaction status for ${transaction.transactionHash}`);
|
37
|
+
const transactionStatus = await net_1.protocol.requestTransactionStatus(transaction.transactionHash, leadNode.id);
|
38
|
+
if (!transactionStatus) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
this.logger.info(`Received transaction status for ${transaction.transactionHash}`);
|
42
|
+
transaction.sourceStatus = transactionStatus.sourceStatus;
|
43
|
+
transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash;
|
44
|
+
transaction.sourceErrors = transactionStatus.sourceErrors;
|
45
|
+
transaction.targetStatus = transactionStatus.targetStatus;
|
46
|
+
transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
|
47
|
+
transaction.targetErrors = transactionStatus.targetErrors;
|
48
|
+
transaction.status = transactionStatus.status;
|
49
|
+
await transaction.save();
|
50
|
+
this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
exports.default = SyncTransactionStatusTask;
|
package/dist/src/tasks/index.js
CHANGED
@@ -6,14 +6,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Tasks = void 0;
|
7
7
|
const ProcessDepositEvents_1 = __importDefault(require("./InteropXGateway/ProcessDepositEvents"));
|
8
8
|
const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
|
9
|
+
const SyncWithdrawtEvents_1 = __importDefault(require("./InteropXGateway/SyncWithdrawtEvents"));
|
10
|
+
const SyncBurnEvents_1 = __importDefault(require("./InteropBridge/SyncBurnEvents"));
|
11
|
+
const SyncBurnEvents_2 = __importDefault(require("./InteropBridge/SyncBurnEvents"));
|
12
|
+
const SyncMintEvents_1 = __importDefault(require("./InteropBridge/SyncMintEvents"));
|
13
|
+
const SyncTransactionStatusTask_1 = __importDefault(require("./Transactions/SyncTransactionStatusTask"));
|
14
|
+
const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
|
9
15
|
class Tasks {
|
10
16
|
constructor() {
|
11
17
|
this.tasks = [
|
18
|
+
new SyncTransactionStatusTask_1.default(),
|
19
|
+
new AutoUpdateTask_1.default(),
|
20
|
+
// InteropXGateway
|
12
21
|
new SyncDepositEvents_1.default({
|
13
22
|
chainId: 43114
|
14
23
|
}),
|
15
24
|
new ProcessDepositEvents_1.default({
|
16
25
|
chainId: 43114
|
26
|
+
}),
|
27
|
+
new SyncWithdrawtEvents_1.default({
|
28
|
+
chainId: 43114
|
29
|
+
}),
|
30
|
+
// InteropBridge
|
31
|
+
new SyncBurnEvents_1.default({
|
32
|
+
chainId: 137,
|
33
|
+
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
34
|
+
}),
|
35
|
+
new SyncMintEvents_1.default({
|
36
|
+
chainId: 137,
|
37
|
+
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
38
|
+
}),
|
39
|
+
new SyncBurnEvents_2.default({
|
40
|
+
chainId: 137,
|
41
|
+
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
17
42
|
})
|
18
43
|
];
|
19
44
|
}
|