@instadapp/interop-x 0.0.0-dev.de23e71 → 0.0.0-dev.e33810b
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/constants/addresses.js +3 -3
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +31 -1
- 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 +55 -0
- package/dist/src/gnosis/index.js +4 -4
- package/dist/src/index.js +4 -2
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +6 -2
- package/dist/src/tasks/{InteropBridge/ProcessWithdrawEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +42 -52
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
- package/dist/src/tasks/index.js +13 -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 +37 -8
- package/package.json +13 -12
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +454 -0
- package/src/constants/addresses.ts +3 -3
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +32 -2
- package/src/db/models/transaction.ts +58 -27
- package/src/gnosis/actions/index.ts +0 -2
- package/src/gnosis/actions/withdraw/index.ts +77 -0
- package/src/gnosis/index.ts +5 -5
- package/src/index.ts +3 -1
- package/src/net/protocol/dial/SignatureDialProtocol.ts +6 -2
- package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +66 -99
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
- package/src/tasks/index.ts +15 -37
- 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 +78 -8
- 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,50 +0,0 @@
|
|
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 abi_1 = __importDefault(require("@/abi"));
|
7
|
-
const config_1 = __importDefault(require("@/config"));
|
8
|
-
const constants_1 = require("@/constants");
|
9
|
-
const utils_1 = require("@/utils");
|
10
|
-
const ethers_1 = require("ethers");
|
11
|
-
const ethers_multisend_1 = require("ethers-multisend");
|
12
|
-
async function default_1(transaction, type) {
|
13
|
-
const transactions = [];
|
14
|
-
const logs = [];
|
15
|
-
if (transaction.action !== 'withdraw') {
|
16
|
-
throw new Error(`Invalid action: ${transaction.action}`);
|
17
|
-
}
|
18
|
-
if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
19
|
-
throw Error('Cannot build data for pending withdraw transaction');
|
20
|
-
}
|
21
|
-
if (!transaction.submitEvent) {
|
22
|
-
throw Error('Cannot build data for transaction without submitEvent');
|
23
|
-
}
|
24
|
-
const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
|
25
|
-
const itoken = constants_1.itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
|
26
|
-
if (!itoken) {
|
27
|
-
throw Error(`Unsupported itoken ${itokenAddress}`);
|
28
|
-
}
|
29
|
-
const token = constants_1.tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
|
30
|
-
if (!token) {
|
31
|
-
throw Error(`Unsupported token ${itoken.symbol}`);
|
32
|
-
}
|
33
|
-
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
34
|
-
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
35
|
-
const gatewayAddress = constants_1.addresses[targetChainId].interopXGateway;
|
36
|
-
const interopBridgeContract = (0, utils_1.getContract)(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
|
37
|
-
const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(sourceChainId.toString()), transaction.submitTransactionHash);
|
38
|
-
transactions.push({
|
39
|
-
to: gatewayAddress,
|
40
|
-
data: data,
|
41
|
-
value: '0',
|
42
|
-
operation: ethers_multisend_1.OperationType.Call,
|
43
|
-
});
|
44
|
-
logs.push({
|
45
|
-
type: 'transfer',
|
46
|
-
message: `Transfer ${amount / 10 ** token.decimals} ${token.symbol} to ${to}`,
|
47
|
-
});
|
48
|
-
return { transactions, logs };
|
49
|
-
}
|
50
|
-
exports.default = default_1;
|
@@ -1,71 +0,0 @@
|
|
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;
|
@@ -1,67 +0,0 @@
|
|
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;
|
@@ -1,164 +0,0 @@
|
|
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 gnosis_1 = require("@/gnosis");
|
18
|
-
const generateGnosisTransaction = async (transactionData, safeContract) => {
|
19
|
-
console.log(transactionData);
|
20
|
-
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));
|
21
|
-
while (isExecuted == 1) {
|
22
|
-
transactionData.safeTxGas = ethers_1.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString();
|
23
|
-
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));
|
24
|
-
}
|
25
|
-
return transactionData;
|
26
|
-
};
|
27
|
-
class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
28
|
-
constructor({ chainId }) {
|
29
|
-
super({
|
30
|
-
logger: new logger_1.default("InteropXGateway::ProcessDepositEvents"),
|
31
|
-
});
|
32
|
-
this.leadNodeOnly = true;
|
33
|
-
this.chainId = chainId;
|
34
|
-
}
|
35
|
-
async pollHandler() {
|
36
|
-
var _a;
|
37
|
-
const blockNumber = await this.provider.getBlockNumber();
|
38
|
-
const transaction = await db_1.Transaction.findOne({
|
39
|
-
where: {
|
40
|
-
status: 'pending',
|
41
|
-
sourceStatus: 'success',
|
42
|
-
targetStatus: 'uninitialised',
|
43
|
-
action: 'deposit',
|
44
|
-
sourceCreatedAt: {
|
45
|
-
[sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
46
|
-
},
|
47
|
-
targetDelayUntil: {
|
48
|
-
[sequelize_1.Op.or]: {
|
49
|
-
[sequelize_1.Op.is]: null,
|
50
|
-
[sequelize_1.Op.lt]: new Date(),
|
51
|
-
}
|
52
|
-
},
|
53
|
-
sourceBlockNumber: {
|
54
|
-
[sequelize_1.Op.lt]: blockNumber - 12,
|
55
|
-
},
|
56
|
-
sourceChainId: this.chainId,
|
57
|
-
}
|
58
|
-
});
|
59
|
-
if (!transaction) {
|
60
|
-
return;
|
61
|
-
}
|
62
|
-
console.log(`Processing transaction ${transaction.transactionHash}`);
|
63
|
-
transaction.targetStatus = 'pending';
|
64
|
-
await transaction.save();
|
65
|
-
// refresh event data?
|
66
|
-
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
|
67
|
-
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
68
|
-
const safeAddress = constants_1.addresses[transaction.targetChainId].gnosisSafe;
|
69
|
-
const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
|
70
|
-
const ownersThreshold = await safeContract.getThreshold();
|
71
|
-
await (0, waait_1.default)(10000);
|
72
|
-
let data, logs = [];
|
73
|
-
try {
|
74
|
-
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction));
|
75
|
-
}
|
76
|
-
catch (error) {
|
77
|
-
console.log(error);
|
78
|
-
transaction.targetStatus = 'failed';
|
79
|
-
transaction.targetErrors = [error.message];
|
80
|
-
transaction.status = 'failed';
|
81
|
-
await transaction.save();
|
82
|
-
net_1.protocol.sendTransaction(transaction);
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
let gnosisTx = await generateGnosisTransaction({
|
86
|
-
baseGas: "0",
|
87
|
-
data,
|
88
|
-
gasPrice: "0",
|
89
|
-
gasToken: "0x0000000000000000000000000000000000000000",
|
90
|
-
nonce: '0',
|
91
|
-
operation: "1",
|
92
|
-
refundReceiver: "0x0000000000000000000000000000000000000000",
|
93
|
-
safeAddress: safeAddress,
|
94
|
-
safeTxGas: "79668",
|
95
|
-
to: constants_1.addresses[transaction.targetChainId].multisend,
|
96
|
-
value: "0",
|
97
|
-
}, safeContract);
|
98
|
-
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
99
|
-
const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
|
100
|
-
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
101
|
-
console.log(ownerPeerIds);
|
102
|
-
const signatures = await net_1.protocol.requestSignatures({
|
103
|
-
type: 'source',
|
104
|
-
transactionHash: transaction.transactionHash,
|
105
|
-
safeTxGas: gnosisTx.safeTxGas,
|
106
|
-
safeNonce: gnosisTx.nonce
|
107
|
-
}, ownerPeerIds);
|
108
|
-
const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x');
|
109
|
-
console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
|
110
|
-
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
111
|
-
await transaction.save();
|
112
|
-
transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
|
113
|
-
transaction.targetStatus = 'uninitialised';
|
114
|
-
await transaction.save();
|
115
|
-
const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
116
|
-
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
117
|
-
}
|
118
|
-
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
119
|
-
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));
|
120
|
-
console.log({
|
121
|
-
from: targetWallet.address,
|
122
|
-
gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9).toString(),
|
123
|
-
to: safeAddress,
|
124
|
-
data: txData,
|
125
|
-
});
|
126
|
-
const txSent = await targetWallet.sendTransaction({
|
127
|
-
from: targetWallet.address,
|
128
|
-
gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9),
|
129
|
-
to: safeAddress,
|
130
|
-
data: txData,
|
131
|
-
});
|
132
|
-
const receipt = await txSent.wait();
|
133
|
-
const parsedLogs = [];
|
134
|
-
receipt.logs.forEach((log) => {
|
135
|
-
try {
|
136
|
-
parsedLogs.push(safeContract.interface.parseLog(log));
|
137
|
-
}
|
138
|
-
catch (e) { }
|
139
|
-
});
|
140
|
-
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
141
|
-
console.log('ExecutionSuccess');
|
142
|
-
transaction.targetStatus = 'success';
|
143
|
-
transaction.targetTransactionHash = txSent.hash;
|
144
|
-
transaction.targetLogs = logs;
|
145
|
-
transaction.status = 'success';
|
146
|
-
await transaction.save();
|
147
|
-
}
|
148
|
-
else {
|
149
|
-
console.log('ExecutionFailure');
|
150
|
-
transaction.targetStatus = 'failed';
|
151
|
-
transaction.targetTransactionHash = txSent.hash;
|
152
|
-
transaction.status = 'failed';
|
153
|
-
await transaction.save();
|
154
|
-
}
|
155
|
-
net_1.protocol.sendTransaction(transaction);
|
156
|
-
}
|
157
|
-
async start() {
|
158
|
-
this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
|
159
|
-
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
160
|
-
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
161
|
-
await super.start();
|
162
|
-
}
|
163
|
-
}
|
164
|
-
exports.default = ProcessDepositEvents;
|
@@ -1,74 +0,0 @@
|
|
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 SyncDepositEvents extends BaseTask_1.BaseTask {
|
15
|
-
constructor({ chainId }) {
|
16
|
-
super({
|
17
|
-
logger: new logger_1.default("InteropXGateway::SyncDepositEvents"),
|
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.LogGatewayDeposit(), currentBlock - 2000, currentBlock);
|
24
|
-
let processedEvents = 0;
|
25
|
-
for (const event of events) {
|
26
|
-
try {
|
27
|
-
if (!event.args) {
|
28
|
-
continue;
|
29
|
-
}
|
30
|
-
const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
|
31
|
-
const uniqueIdentifier = {
|
32
|
-
action: 'deposit',
|
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: user, 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
|
-
user,
|
45
|
-
sourceChainId: sourceChainId.toString(),
|
46
|
-
targetChainId: targetChainId.toString(),
|
47
|
-
token: token,
|
48
|
-
amount: amount.toString(),
|
49
|
-
vnonce: vnonce.toString(),
|
50
|
-
}, sourceEvent: {
|
51
|
-
user,
|
52
|
-
sourceChainId: sourceChainId.toString(),
|
53
|
-
targetChainId: targetChainId.toString(),
|
54
|
-
token: token,
|
55
|
-
amount: amount.toString(),
|
56
|
-
vnonce: vnonce.toString(),
|
57
|
-
}, status: "pending" }));
|
58
|
-
this.logger.info(`Deposit queued: ${event.transactionHash} ${event.blockNumber}`);
|
59
|
-
}
|
60
|
-
catch (error) {
|
61
|
-
this.logger.error(error);
|
62
|
-
}
|
63
|
-
}
|
64
|
-
if (processedEvents > 0)
|
65
|
-
this.logger.info(`${processedEvents} events processed`);
|
66
|
-
}
|
67
|
-
async start() {
|
68
|
-
this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
|
69
|
-
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
70
|
-
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
71
|
-
await super.start();
|
72
|
-
}
|
73
|
-
}
|
74
|
-
exports.default = SyncDepositEvents;
|
@@ -1,72 +0,0 @@
|
|
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;
|