@instadapp/interop-x 0.0.0-dev.d05464a → 0.0.0-dev.d71f27e
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 +3 -3
- package/dist/src/abi/index.js +2 -4
- package/dist/src/abi/interopXContract.json +391 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +4 -1
- package/dist/src/config/index.js +10 -1
- package/dist/src/constants/addresses.js +3 -3
- package/dist/src/constants/index.js +0 -1
- package/dist/src/db/models/transaction.js +27 -9
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +41 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +39 -23
- package/dist/src/net/peer/index.js +2 -1
- package/dist/src/net/pool/index.js +7 -2
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/src/net/protocol/index.js +26 -5
- package/dist/src/tasks/AutoUpdateTask.js +33 -11
- package/dist/src/tasks/BaseTask.js +11 -3
- package/dist/src/tasks/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +54 -52
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +89 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
- package/dist/src/tasks/index.js +13 -17
- package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +27 -87
- package/package.json +3 -3
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +391 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +4 -1
- package/src/config/index.ts +9 -1
- package/src/constants/addresses.ts +3 -3
- package/src/constants/index.ts +0 -1
- package/src/db/models/transaction.ts +66 -21
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +56 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +52 -25
- package/src/net/peer/index.ts +2 -1
- package/src/net/pool/index.ts +7 -3
- package/src/net/protocol/dial/SignatureDialProtocol.ts +11 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +28 -6
- package/src/tasks/AutoUpdateTask.ts +36 -14
- package/src/tasks/BaseTask.ts +13 -3
- package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +78 -95
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +120 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
- package/src/tasks/index.ts +17 -18
- package/src/typechain/InteropXContract.ts +524 -0
- package/src/typechain/factories/InteropXContract__factory.ts +533 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +61 -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 -147
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -70
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
- package/dist/src/typechain/InteropXGateway.js +0 -2
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -121
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -245
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
- 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
@@ -0,0 +1,78 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const BaseTask_1 = require("../BaseTask");
|
7
|
+
const logger_1 = __importDefault(require("@/logger"));
|
8
|
+
const ethers_1 = require("ethers");
|
9
|
+
const abi_1 = __importDefault(require("@/abi"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const constants_1 = require("@/constants");
|
13
|
+
const config_1 = __importDefault(require("@/config"));
|
14
|
+
class SyncBridgeRequestEvents extends BaseTask_1.BaseTask {
|
15
|
+
constructor({ chainId }) {
|
16
|
+
super({
|
17
|
+
logger: new logger_1.default("InteropXContract::SyncBridgeRequestEvents"),
|
18
|
+
});
|
19
|
+
this.chainId = chainId;
|
20
|
+
}
|
21
|
+
async pollHandler() {
|
22
|
+
const currentBlock = await this.provider.getBlockNumber();
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogBridgeRequest(), currentBlock - 2000, currentBlock);
|
24
|
+
let processedEvents = 0;
|
25
|
+
for (const event of events) {
|
26
|
+
try {
|
27
|
+
if (!event.args) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
const { bridger, position, sourceChainId, targetChainId, metadata } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
action: 'withdraw',
|
33
|
+
bridger,
|
34
|
+
requestTransactionHash: event.transactionHash,
|
35
|
+
sourceChainId: sourceChainId.toNumber(),
|
36
|
+
targetChainId: targetChainId.toNumber(),
|
37
|
+
};
|
38
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
39
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
40
|
+
if (transaction) {
|
41
|
+
continue;
|
42
|
+
}
|
43
|
+
await db_1.Transaction.create(Object.assign(Object.assign({ transactionHash }, uniqueIdentifier), { position,
|
44
|
+
metadata, requestBlockNumber: event.blockNumber, requestEvent: {
|
45
|
+
bridger,
|
46
|
+
position: {
|
47
|
+
withdraw: position.withdraw.map((v) => ({
|
48
|
+
sourceToken: v.sourceToken,
|
49
|
+
targetToken: v.targetToken,
|
50
|
+
amount: v.amount.toString()
|
51
|
+
})),
|
52
|
+
supply: position.supply.map((v) => ({
|
53
|
+
sourceToken: v.sourceToken,
|
54
|
+
targetToken: v.targetToken,
|
55
|
+
amount: v.amount.toString()
|
56
|
+
})),
|
57
|
+
},
|
58
|
+
sourceChainId: sourceChainId.toNumber(),
|
59
|
+
targetChainId: targetChainId.toNumber(),
|
60
|
+
metadata,
|
61
|
+
} }));
|
62
|
+
this.logger.info(`New bridge request received: ${transactionHash} `);
|
63
|
+
}
|
64
|
+
catch (error) {
|
65
|
+
this.logger.error(error);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
if (processedEvents > 0)
|
69
|
+
this.logger.info(`${processedEvents} events processed`);
|
70
|
+
}
|
71
|
+
async start() {
|
72
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
73
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
74
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
75
|
+
await super.start();
|
76
|
+
}
|
77
|
+
}
|
78
|
+
exports.default = SyncBridgeRequestEvents;
|
@@ -0,0 +1,89 @@
|
|
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
|
+
class SyncBridgeRequestSentEvents extends BaseTask_1.BaseTask {
|
16
|
+
constructor({ chainId }) {
|
17
|
+
super({
|
18
|
+
logger: new logger_1.default("InteropXContract::SyncBridgeRequestSentEvents"),
|
19
|
+
});
|
20
|
+
this.chainId = chainId;
|
21
|
+
}
|
22
|
+
async pollHandler() {
|
23
|
+
const currentBlock = await this.provider.getBlockNumber();
|
24
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogBridgeRequestSent(), currentBlock - 2000, currentBlock);
|
25
|
+
let processedEvents = 0;
|
26
|
+
for (const event of events) {
|
27
|
+
try {
|
28
|
+
if (!event.args) {
|
29
|
+
continue;
|
30
|
+
}
|
31
|
+
const { bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
|
32
|
+
const uniqueIdentifier = {
|
33
|
+
action: 'withdraw',
|
34
|
+
bridger,
|
35
|
+
requestTransactionHash,
|
36
|
+
sourceChainId: sourceChainId,
|
37
|
+
targetChainId: targetChainId,
|
38
|
+
};
|
39
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
40
|
+
const transaction = await db_1.Transaction.findOne({
|
41
|
+
where: {
|
42
|
+
transactionHash, sourceStatus: {
|
43
|
+
[sequelize_1.Op.ne]: 'success',
|
44
|
+
}
|
45
|
+
}
|
46
|
+
});
|
47
|
+
if (!transaction) {
|
48
|
+
continue;
|
49
|
+
}
|
50
|
+
transaction.sourceStatus = 'success';
|
51
|
+
transaction.sourceBlockNumber = event.blockNumber;
|
52
|
+
transaction.sourceTransactionHash = event.transactionHash;
|
53
|
+
transaction.requestSentEvent = {
|
54
|
+
bridger,
|
55
|
+
position: {
|
56
|
+
withdraw: position.withdraw.map((v) => ({
|
57
|
+
sourceToken: v.sourceToken,
|
58
|
+
targetToken: v.targetToken,
|
59
|
+
amount: v.amount.toString()
|
60
|
+
})),
|
61
|
+
supply: position.supply.map((v) => ({
|
62
|
+
sourceToken: v.sourceToken,
|
63
|
+
targetToken: v.targetToken,
|
64
|
+
amount: v.amount.toString()
|
65
|
+
})),
|
66
|
+
},
|
67
|
+
sourceChainId: sourceChainId,
|
68
|
+
targetChainId: targetChainId,
|
69
|
+
metadata,
|
70
|
+
requestTransactionHash,
|
71
|
+
};
|
72
|
+
await transaction.save();
|
73
|
+
this.logger.info(`New bridge request sent received: ${transactionHash} `);
|
74
|
+
}
|
75
|
+
catch (error) {
|
76
|
+
this.logger.error(error);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
if (processedEvents > 0)
|
80
|
+
this.logger.info(`${processedEvents} events processed`);
|
81
|
+
}
|
82
|
+
async start() {
|
83
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
84
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
85
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
86
|
+
await super.start();
|
87
|
+
}
|
88
|
+
}
|
89
|
+
exports.default = SyncBridgeRequestSentEvents;
|
@@ -0,0 +1,55 @@
|
|
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.sourceLogs = transactionStatus.sourceLogs;
|
46
|
+
transaction.targetStatus = transactionStatus.targetStatus;
|
47
|
+
transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
|
48
|
+
transaction.targetErrors = transactionStatus.targetErrors;
|
49
|
+
transaction.targetLogs = transactionStatus.targetLogs;
|
50
|
+
transaction.status = transactionStatus.status;
|
51
|
+
await transaction.save();
|
52
|
+
this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
exports.default = SyncTransactionStatusTask;
|
package/dist/src/tasks/index.js
CHANGED
@@ -4,34 +4,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.Tasks = void 0;
|
7
|
-
const
|
8
|
-
const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
|
9
|
-
const SyncWithdrawEvents_1 = __importDefault(require("./InteropBridge/SyncWithdrawEvents"));
|
10
|
-
const ProcessWithdrawEvents_1 = __importDefault(require("./InteropBridge/ProcessWithdrawEvents"));
|
7
|
+
const waait_1 = __importDefault(require("waait"));
|
11
8
|
const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
|
9
|
+
const SyncBridgeRequestEvents_1 = __importDefault(require("./InteropXContract/SyncBridgeRequestEvents"));
|
10
|
+
const ProcessBridgeRequestEvents_1 = __importDefault(require("./InteropXContract/ProcessBridgeRequestEvents"));
|
11
|
+
const SyncBridgeRequestSentEvents_1 = __importDefault(require("./InteropXContract/SyncBridgeRequestSentEvents"));
|
12
12
|
class Tasks {
|
13
13
|
constructor() {
|
14
14
|
this.tasks = [
|
15
|
+
// new SyncTransactionStatusTask(),
|
15
16
|
new AutoUpdateTask_1.default(),
|
16
|
-
|
17
|
-
|
18
|
-
}),
|
19
|
-
new
|
20
|
-
|
21
|
-
}),
|
22
|
-
new
|
23
|
-
chainId: 137,
|
24
|
-
itokenAddress: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
|
25
|
-
}),
|
26
|
-
new ProcessWithdrawEvents_1.default({
|
27
|
-
chainId: 137,
|
28
|
-
})
|
17
|
+
// InteropXContract
|
18
|
+
new SyncBridgeRequestEvents_1.default({ chainId: 137 }),
|
19
|
+
new SyncBridgeRequestEvents_1.default({ chainId: 43114 }),
|
20
|
+
new SyncBridgeRequestSentEvents_1.default({ chainId: 137 }),
|
21
|
+
new SyncBridgeRequestSentEvents_1.default({ chainId: 43114 }),
|
22
|
+
new ProcessBridgeRequestEvents_1.default({ chainId: 137 }),
|
23
|
+
new ProcessBridgeRequestEvents_1.default({ chainId: 43114 }),
|
29
24
|
];
|
30
25
|
}
|
31
26
|
async start() {
|
32
27
|
for (const task of this.tasks) {
|
33
28
|
try {
|
34
29
|
task.start();
|
30
|
+
await (0, waait_1.default)(1000);
|
35
31
|
}
|
36
32
|
catch (error) {
|
37
33
|
console.error(`Error starting task: ${task.constructor.name}`);
|
File without changes
|