@instadapp/interop-x 0.0.0-dev.a846f65 → 0.0.0-dev.a9cd1d2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/package.json +14 -12
- package/dist/src/abi/index.js +2 -4
- package/dist/src/abi/interopX.json +1436 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +3 -0
- package/dist/src/config/index.js +10 -1
- package/dist/src/constants/addresses.js +2 -7
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +62 -39
- package/dist/src/db/models/transaction.js +29 -11
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +114 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +34 -22
- 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/AutoUpdateTask.js +11 -8
- package/dist/src/tasks/BaseTask.js +4 -0
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +84 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +6 -2
- package/dist/src/tasks/index.js +7 -19
- package/dist/src/typechain/{InteropBridgeToken.js → InteropX.js} +0 -0
- package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +46 -89
- package/package.json +14 -12
- package/src/abi/index.ts +2 -4
- package/src/abi/interopX.json +1436 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +3 -0
- package/src/config/index.ts +9 -1
- package/src/constants/addresses.ts +3 -8
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +63 -40
- package/src/db/models/transaction.ts +65 -25
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +155 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +47 -26
- 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/AutoUpdateTask.ts +15 -14
- package/src/tasks/BaseTask.ts +5 -0
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +136 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +6 -2
- package/src/tasks/index.ts +12 -23
- package/src/typechain/InteropX.ts +1216 -0
- package/src/typechain/factories/InteropX__factory.ts +1932 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +98 -128
- 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/ProcessDepositEvents.js +0 -149
- 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/ProcessWithdrawEvents.ts +0 -231
- 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,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);
|
@@ -6,16 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const BaseTask_1 = require("./BaseTask");
|
7
7
|
const logger_1 = __importDefault(require("@/logger"));
|
8
8
|
const await_spawn_1 = __importDefault(require("await-spawn"));
|
9
|
+
const child_process_1 = require("child_process");
|
9
10
|
const config_1 = __importDefault(require("@/config"));
|
10
11
|
const waait_1 = __importDefault(require("waait"));
|
11
12
|
const package_json_1 = __importDefault(require("../../package.json"));
|
12
13
|
const currentVersion = package_json_1.default.version;
|
14
|
+
const tag = config_1.default.staging ? 'dev' : 'latest';
|
13
15
|
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
14
16
|
constructor() {
|
15
17
|
super({
|
16
18
|
logger: new logger_1.default("AutoUpdateTask"),
|
17
19
|
});
|
18
|
-
this.pollIntervalMs = 60 *
|
20
|
+
this.pollIntervalMs = 60 * 10 * 1000;
|
19
21
|
}
|
20
22
|
prePollHandler() {
|
21
23
|
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
@@ -32,8 +34,8 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
32
34
|
}
|
33
35
|
async getLatestVersion() {
|
34
36
|
try {
|
35
|
-
const stdout = await (0, await_spawn_1.default)('npm', ['view', package_json_1.default.name
|
36
|
-
return stdout.toString();
|
37
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
|
38
|
+
return stdout.toString().trim();
|
37
39
|
}
|
38
40
|
catch (error) {
|
39
41
|
this.logger.error(error);
|
@@ -47,9 +49,7 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
47
49
|
}
|
48
50
|
this.logger.warn(`New version ${version} available.`);
|
49
51
|
this.logger.info('Updating...');
|
50
|
-
|
51
|
-
spawner.child.on('data', console.log);
|
52
|
-
await spawner;
|
52
|
+
await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
53
53
|
await (0, waait_1.default)(5000);
|
54
54
|
if (version !== await this.getInstalledVersion()) {
|
55
55
|
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
|
@@ -57,10 +57,13 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
57
57
|
}
|
58
58
|
this.logger.warn(`Installed version ${version}`);
|
59
59
|
this.logger.warn(`Restarting...`);
|
60
|
-
|
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), {
|
61
62
|
cwd: process.cwd(),
|
62
|
-
stdio: "inherit"
|
63
|
+
stdio: "inherit",
|
64
|
+
// shell: process.env.SHELL,
|
63
65
|
});
|
66
|
+
subprocess.unref();
|
64
67
|
process.exit();
|
65
68
|
}
|
66
69
|
}
|
@@ -35,6 +35,10 @@ class BaseTask extends events_1.default {
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
prePollHandler() {
|
38
|
+
if (config_1.default.isMaintenanceMode()) {
|
39
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.');
|
40
|
+
return false;
|
41
|
+
}
|
38
42
|
if (this.exceptLeadNode) {
|
39
43
|
return !config_1.default.isLeadNode();
|
40
44
|
}
|
@@ -0,0 +1,84 @@
|
|
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 SyncLogSubmitEvents extends BaseTask_1.BaseTask {
|
15
|
+
constructor({ chainId }) {
|
16
|
+
super({
|
17
|
+
logger: new logger_1.default("InteropX::SyncLogSubmitEvents"),
|
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.LogSubmit(), currentBlock - 2000, currentBlock);
|
24
|
+
let processedEvents = 0;
|
25
|
+
for (const event of events) {
|
26
|
+
try {
|
27
|
+
if (!event.args) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
const { position, actionId, actionIdHashHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
actionId,
|
33
|
+
vnonce: vnonce.toString(),
|
34
|
+
sourceSender: sourceSender.toString(),
|
35
|
+
sourceChainId: sourceChainId.toNumber(),
|
36
|
+
targetChainId: targetChainId.toNumber(),
|
37
|
+
sourceDsaId: sourceDsaId.toString(),
|
38
|
+
targetDsaId: targetDsaId.toString(),
|
39
|
+
};
|
40
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
41
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
42
|
+
if (transaction) {
|
43
|
+
continue;
|
44
|
+
}
|
45
|
+
await db_1.Transaction.create(Object.assign(Object.assign({ transactionHash }, uniqueIdentifier), { submitChainId: this.chainId, submitTransactionHash: event.transactionHash, submitBlockNumber: event.blockNumber, submitCreatedAt: new Date(), submitEvent: {
|
46
|
+
actionId,
|
47
|
+
actionIdHashHash,
|
48
|
+
vnonce: vnonce.toString(),
|
49
|
+
position: {
|
50
|
+
withdraw: position.withdraw.map((v) => ({
|
51
|
+
sourceToken: v.sourceToken,
|
52
|
+
targetToken: v.targetToken,
|
53
|
+
amount: v.amount.toString()
|
54
|
+
})),
|
55
|
+
supply: position.supply.map((v) => ({
|
56
|
+
sourceToken: v.sourceToken,
|
57
|
+
targetToken: v.targetToken,
|
58
|
+
amount: v.amount.toString()
|
59
|
+
})),
|
60
|
+
},
|
61
|
+
sourceChainId: sourceChainId.toNumber(),
|
62
|
+
targetChainId: targetChainId.toNumber(),
|
63
|
+
sourceSender,
|
64
|
+
sourceDsaId: sourceDsaId.toString(),
|
65
|
+
targetDsaId: targetDsaId.toString(),
|
66
|
+
metadata,
|
67
|
+
} }));
|
68
|
+
this.logger.info(`New InteropX tranaction: ${transactionHash} `);
|
69
|
+
}
|
70
|
+
catch (error) {
|
71
|
+
this.logger.error(error);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
if (processedEvents > 0)
|
75
|
+
this.logger.info(`${processedEvents} events processed`);
|
76
|
+
}
|
77
|
+
async start() {
|
78
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopX;
|
79
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
80
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopX, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
81
|
+
await super.start();
|
82
|
+
}
|
83
|
+
}
|
84
|
+
exports.default = SyncLogSubmitEvents;
|
@@ -24,9 +24,11 @@ class SyncTransactionStatusTask extends BaseTask_1.BaseTask {
|
|
24
24
|
}
|
25
25
|
const transaction = await db_1.Transaction.findOne({
|
26
26
|
where: {
|
27
|
-
|
27
|
+
sourceStatus: {
|
28
|
+
[sequelize_1.Op.notIn]: ['success', 'failed'],
|
29
|
+
},
|
28
30
|
sourceCreatedAt: {
|
29
|
-
[sequelize_1.Op.gte]: new Date(Date.now() -
|
31
|
+
[sequelize_1.Op.gte]: new Date(Date.now() - 15 * 60 * 1000),
|
30
32
|
},
|
31
33
|
}
|
32
34
|
});
|
@@ -42,9 +44,11 @@ class SyncTransactionStatusTask extends BaseTask_1.BaseTask {
|
|
42
44
|
transaction.sourceStatus = transactionStatus.sourceStatus;
|
43
45
|
transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash;
|
44
46
|
transaction.sourceErrors = transactionStatus.sourceErrors;
|
47
|
+
transaction.sourceLogs = transactionStatus.sourceLogs;
|
45
48
|
transaction.targetStatus = transactionStatus.targetStatus;
|
46
49
|
transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
|
47
50
|
transaction.targetErrors = transactionStatus.targetErrors;
|
51
|
+
transaction.targetLogs = transactionStatus.targetLogs;
|
48
52
|
transaction.status = transactionStatus.status;
|
49
53
|
await transaction.save();
|
50
54
|
this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
|
package/dist/src/tasks/index.js
CHANGED
@@ -4,36 +4,24 @@ 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 SyncLogSubmitEvents_1 = __importDefault(require("./InteropX/SyncLogSubmitEvents"));
|
13
10
|
class Tasks {
|
14
11
|
constructor() {
|
15
12
|
this.tasks = [
|
16
|
-
new
|
13
|
+
// new SyncTransactionStatusTask(),
|
17
14
|
new AutoUpdateTask_1.default(),
|
18
|
-
|
19
|
-
|
20
|
-
}),
|
21
|
-
new ProcessDepositEvents_1.default({
|
22
|
-
chainId: 43114
|
23
|
-
}),
|
24
|
-
new SyncWithdrawEvents_1.default({
|
25
|
-
chainId: 137,
|
26
|
-
itokenAddress: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
|
27
|
-
}),
|
28
|
-
new ProcessWithdrawEvents_1.default({
|
29
|
-
chainId: 137,
|
30
|
-
})
|
15
|
+
// InteropX
|
16
|
+
new SyncLogSubmitEvents_1.default({ chainId: 137 }),
|
17
|
+
new SyncLogSubmitEvents_1.default({ chainId: 43114 }),
|
31
18
|
];
|
32
19
|
}
|
33
20
|
async start() {
|
34
21
|
for (const task of this.tasks) {
|
35
22
|
try {
|
36
23
|
task.start();
|
24
|
+
await (0, waait_1.default)(1000);
|
37
25
|
}
|
38
26
|
catch (error) {
|
39
27
|
console.error(`Error starting task: ${task.constructor.name}`);
|
File without changes
|