@instadapp/interop-x 0.0.0-dev.75809ae → 0.0.0-dev.7adf1b5
Sign up to get free protection for your applications and to get access to all the features.
- package/.env.example +2 -1
- package/dist/package.json +73 -0
- package/dist/src/abi/erc20.json +350 -0
- package/dist/src/abi/gnosisSafe.json +747 -0
- package/dist/src/abi/index.js +15 -0
- package/dist/src/abi/interopBridgeToken.json +298 -0
- package/dist/src/abi/interopXGateway.json +184 -0
- package/dist/src/api/index.js +36 -0
- package/dist/src/config/index.js +31 -0
- package/dist/src/constants/addresses.js +20 -0
- package/dist/{constants → src/constants}/index.js +2 -0
- package/dist/src/constants/itokens.js +13 -0
- package/dist/src/constants/tokens.js +107 -0
- package/dist/{db → src/db}/index.js +0 -0
- package/dist/{db → src/db}/models/index.js +1 -1
- package/dist/src/db/models/transaction.js +62 -0
- package/dist/{db → src/db}/sequelize.js +2 -1
- package/dist/src/gnosis/actions/deposit.js +48 -0
- package/dist/src/gnosis/actions/index.js +11 -0
- package/dist/src/gnosis/actions/withdraw.js +50 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +130 -0
- package/dist/{logger → src/logger}/index.js +0 -0
- package/dist/{net → src/net}/index.js +0 -0
- package/dist/{net → src/net}/peer/index.js +13 -8
- package/dist/{net → src/net}/pool/index.js +34 -11
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +1 -1
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +17 -14
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
- package/dist/{net → src/net}/protocol/index.js +44 -4
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +14 -6
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +162 -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 +164 -0
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +74 -0
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
- package/dist/src/tasks/index.js +55 -0
- package/dist/src/typechain/Erc20.js +2 -0
- package/dist/src/typechain/GnosisSafe.js +2 -0
- package/dist/src/typechain/InteropBridgeToken.js +2 -0
- package/dist/src/typechain/InteropXGateway.js +2 -0
- package/dist/src/typechain/common.js +2 -0
- package/dist/src/typechain/factories/Erc20__factory.js +367 -0
- package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +471 -0
- package/dist/src/typechain/factories/InteropXGateway__factory.js +265 -0
- package/dist/src/typechain/factories/index.js +14 -0
- package/dist/src/typechain/index.js +35 -0
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/src/utils/index.js +157 -0
- package/package.json +21 -7
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/abi/erc20.json +350 -0
- package/src/abi/gnosisSafe.json +747 -0
- package/src/abi/index.ts +11 -0
- package/src/abi/interopBridgeToken.json +298 -0
- package/src/abi/interopXGateway.json +184 -0
- package/src/api/index.ts +36 -0
- package/src/config/index.ts +18 -2
- package/src/constants/addresses.ts +9 -2
- package/src/constants/index.ts +2 -0
- package/src/constants/itokens.ts +10 -0
- package/src/constants/tokens.ts +104 -0
- package/src/db/index.ts +1 -1
- package/src/db/models/index.ts +1 -1
- package/src/db/models/transaction.ts +106 -0
- package/src/db/sequelize.ts +2 -1
- package/src/gnosis/actions/deposit.ts +63 -0
- package/src/gnosis/actions/index.ts +7 -0
- package/src/gnosis/actions/withdraw.ts +67 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +128 -6
- package/src/net/peer/index.ts +12 -10
- package/src/net/pool/index.ts +43 -13
- package/src/net/protocol/dial/BaseDialProtocol.ts +1 -1
- package/src/net/protocol/dial/SignatureDialProtocol.ts +20 -17
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
- package/src/net/protocol/index.ts +60 -4
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +16 -7
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +249 -0
- package/src/tasks/InteropBridge/SyncBurnEvents.ts +119 -0
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +260 -0
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +124 -0
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
- package/src/tasks/index.ts +45 -1
- package/src/typechain/Erc20.ts +491 -0
- package/src/typechain/GnosisSafe.ts +1728 -0
- package/src/typechain/InteropBridgeToken.ts +692 -0
- package/src/typechain/InteropXGateway.ts +407 -0
- package/src/typechain/common.ts +44 -0
- package/src/typechain/factories/Erc20__factory.ts +368 -0
- package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
- package/src/typechain/factories/InteropBridgeToken__factory.ts +478 -0
- package/src/typechain/factories/InteropXGateway__factory.ts +272 -0
- package/src/typechain/factories/index.ts +7 -0
- package/src/typechain/index.ts +12 -0
- package/src/types.ts +2 -2
- package/src/utils/index.ts +87 -5
- package/tsconfig.json +3 -0
- package/dist/config/index.js +0 -17
- package/dist/constants/addresses.js +0 -13
- package/dist/db/models/execution.js +0 -38
- package/dist/index.js +0 -34
- package/dist/tasks/index.js +0 -19
- package/dist/utils/index.js +0 -89
- package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TransactionStatusDialProtocol = void 0;
|
4
|
+
const BaseDialProtocol_1 = require("./BaseDialProtocol");
|
5
|
+
const db_1 = require("@/db");
|
6
|
+
class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
7
|
+
constructor(libp2p) {
|
8
|
+
super(libp2p, '/interop-x/transaction-status');
|
9
|
+
this.timeout = 30000;
|
10
|
+
}
|
11
|
+
async response(transactionHash) {
|
12
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
13
|
+
if (!transaction) {
|
14
|
+
return null;
|
15
|
+
}
|
16
|
+
return {
|
17
|
+
transactionHash: transaction.transactionHash,
|
18
|
+
sourceStatus: transaction.sourceStatus,
|
19
|
+
sourceTransactionHash: transaction.sourceTransactionHash,
|
20
|
+
sourceErrors: transaction.sourceErrors,
|
21
|
+
targetStatus: transaction.targetStatus,
|
22
|
+
targetTransactionHash: transaction.targetTransactionHash,
|
23
|
+
targetErrors: transaction.targetErrors,
|
24
|
+
status: transaction.status,
|
25
|
+
};
|
26
|
+
}
|
27
|
+
}
|
28
|
+
exports.TransactionStatusDialProtocol = TransactionStatusDialProtocol;
|
@@ -8,15 +8,16 @@ const stream_1 = require("stream");
|
|
8
8
|
const ethereumjs_util_1 = require("ethereumjs-util");
|
9
9
|
const SignatureDialProtocol_1 = require("./dial/SignatureDialProtocol");
|
10
10
|
const __1 = require("..");
|
11
|
-
const config_1 = __importDefault(require("config"));
|
12
|
-
const types_1 = require("types");
|
11
|
+
const config_1 = __importDefault(require("@/config"));
|
12
|
+
const types_1 = require("@/types");
|
13
|
+
const TransactionStatusDialProtocol_1 = require("./dial/TransactionStatusDialProtocol");
|
13
14
|
class Protocol extends stream_1.EventEmitter {
|
14
15
|
constructor() {
|
15
16
|
super(...arguments);
|
16
17
|
this.protocolMessages = [
|
17
18
|
{
|
18
19
|
name: 'PeerInfo',
|
19
|
-
code:
|
20
|
+
code: 0x01,
|
20
21
|
encode: (info) => [
|
21
22
|
Buffer.from(info.publicAddress),
|
22
23
|
],
|
@@ -24,11 +25,35 @@ class Protocol extends stream_1.EventEmitter {
|
|
24
25
|
publicAddress: publicAddress.toString(),
|
25
26
|
}),
|
26
27
|
},
|
28
|
+
{
|
29
|
+
name: 'TransactionStatus',
|
30
|
+
code: 0x02,
|
31
|
+
encode: (transaction) => [
|
32
|
+
Buffer.from(transaction.transactionHash),
|
33
|
+
Buffer.from(transaction.sourceStatus),
|
34
|
+
Buffer.from(transaction.sourceTransactionHash || ''),
|
35
|
+
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
36
|
+
Buffer.from(transaction.targetStatus),
|
37
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
38
|
+
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
39
|
+
Buffer.from(transaction.status),
|
40
|
+
],
|
41
|
+
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
|
42
|
+
transactionHash: transactionHash.toString(),
|
43
|
+
sourceStatus: sourceStatus.toString(),
|
44
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
45
|
+
sourceErrors: sourceErrors.map((e) => e.toString()),
|
46
|
+
targetStatus: targetStatus.toString(),
|
47
|
+
targetTransactionHash: targetTransactionHash.toString() || null,
|
48
|
+
targetErrors: targetErrors.map((e) => e.toString()),
|
49
|
+
status: status.toString(),
|
50
|
+
}),
|
51
|
+
},
|
27
52
|
];
|
28
53
|
}
|
29
54
|
start({ libp2p, topic = null, }) {
|
30
55
|
this.libp2p = libp2p;
|
31
|
-
this.topic = topic || 'protocol';
|
56
|
+
this.topic = topic || 'itnerop-x-protocol';
|
32
57
|
if (this.libp2p.isStarted())
|
33
58
|
this.init();
|
34
59
|
this.on('PeerInfo', (payload) => {
|
@@ -40,6 +65,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
40
65
|
});
|
41
66
|
});
|
42
67
|
this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
|
68
|
+
this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
|
43
69
|
}
|
44
70
|
init() {
|
45
71
|
this.libp2p.pubsub.subscribe(this.topic);
|
@@ -75,6 +101,11 @@ class Protocol extends stream_1.EventEmitter {
|
|
75
101
|
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(data)]);
|
76
102
|
this.libp2p.pubsub.publish(this.topic, encoded);
|
77
103
|
}
|
104
|
+
sendTransaction(transaction) {
|
105
|
+
const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
|
106
|
+
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
|
107
|
+
this.libp2p.pubsub.publish(this.topic, encoded);
|
108
|
+
}
|
78
109
|
async requestSignatures(data, peerIds) {
|
79
110
|
try {
|
80
111
|
peerIds = peerIds || __1.peerPool.activePeerIds;
|
@@ -88,5 +119,14 @@ class Protocol extends stream_1.EventEmitter {
|
|
88
119
|
return [];
|
89
120
|
}
|
90
121
|
}
|
122
|
+
async requestTransactionStatus(transactionHash, peerId) {
|
123
|
+
try {
|
124
|
+
return await this.transactionStatus.send(transactionHash, peerId);
|
125
|
+
}
|
126
|
+
catch (error) {
|
127
|
+
console.log(error);
|
128
|
+
return null;
|
129
|
+
}
|
130
|
+
}
|
91
131
|
}
|
92
132
|
exports.protocol = new Protocol();
|
@@ -0,0 +1,70 @@
|
|
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 await_spawn_1 = __importDefault(require("await-spawn"));
|
9
|
+
const child_process_1 = require("child_process");
|
10
|
+
const config_1 = __importDefault(require("@/config"));
|
11
|
+
const waait_1 = __importDefault(require("waait"));
|
12
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
13
|
+
const currentVersion = package_json_1.default.version;
|
14
|
+
const tag = config_1.default.staging ? 'dev' : 'latest';
|
15
|
+
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
16
|
+
constructor() {
|
17
|
+
super({
|
18
|
+
logger: new logger_1.default("AutoUpdateTask"),
|
19
|
+
});
|
20
|
+
this.pollIntervalMs = 60 * 10 * 1000;
|
21
|
+
}
|
22
|
+
prePollHandler() {
|
23
|
+
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
24
|
+
}
|
25
|
+
async getInstalledVersion() {
|
26
|
+
try {
|
27
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['-g', 'ls', '--depth=0', '--json']);
|
28
|
+
return JSON.parse(stdout.toString()).dependencies[package_json_1.default.name].version;
|
29
|
+
}
|
30
|
+
catch (error) {
|
31
|
+
this.logger.error(error);
|
32
|
+
return currentVersion;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
async getLatestVersion() {
|
36
|
+
try {
|
37
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
|
38
|
+
return stdout.toString().trim();
|
39
|
+
}
|
40
|
+
catch (error) {
|
41
|
+
this.logger.error(error);
|
42
|
+
return currentVersion;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
async pollHandler() {
|
46
|
+
const version = await this.getLatestVersion();
|
47
|
+
if (version === currentVersion) {
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
this.logger.warn(`New version ${version} available.`);
|
51
|
+
this.logger.info('Updating...');
|
52
|
+
await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
53
|
+
await (0, waait_1.default)(5000);
|
54
|
+
if (version !== await this.getInstalledVersion()) {
|
55
|
+
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
this.logger.warn(`Installed version ${version}`);
|
59
|
+
this.logger.warn(`Restarting...`);
|
60
|
+
// TODO: its restarting in the bg, but it should be in the fg
|
61
|
+
const subprocess = (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
|
62
|
+
cwd: process.cwd(),
|
63
|
+
stdio: "inherit",
|
64
|
+
// shell: process.env.SHELL,
|
65
|
+
});
|
66
|
+
subprocess.unref();
|
67
|
+
process.exit();
|
68
|
+
}
|
69
|
+
}
|
70
|
+
exports.default = AutoUpdateTask;
|
@@ -4,16 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.BaseTask = void 0;
|
7
|
-
const config_1 = __importDefault(require("config"));
|
7
|
+
const config_1 = __importDefault(require("@/config"));
|
8
8
|
const events_1 = __importDefault(require("events"));
|
9
9
|
const waait_1 = __importDefault(require("waait"));
|
10
|
-
const logger_1 = __importDefault(require("
|
10
|
+
const logger_1 = __importDefault(require("@/logger"));
|
11
11
|
class BaseTask extends events_1.default {
|
12
12
|
constructor({ logger }) {
|
13
13
|
super();
|
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() {
|
@@ -28,16 +29,23 @@ class BaseTask extends events_1.default {
|
|
28
29
|
}
|
29
30
|
}
|
30
31
|
catch (err) {
|
31
|
-
this.logger.error(`poll check error
|
32
|
+
this.logger.error(`poll check error:\n${err.message}\ntrace: ${err.stack}`);
|
32
33
|
}
|
33
34
|
await this.postPollHandler();
|
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,162 @@
|
|
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 ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
28
|
+
constructor({ chainId }) {
|
29
|
+
super({
|
30
|
+
logger: new logger_1.default("InteropXGateway::ProcessWithdrawEvents"),
|
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: 'withdraw',
|
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.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
159
|
+
await super.start();
|
160
|
+
}
|
161
|
+
}
|
162
|
+
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;
|