@instadapp/interop-x 0.0.0-dev.d2e8d37 → 0.0.0-dev.de23e71
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 +2 -2
- package/dist/src/abi/interopBridgeToken.json +21 -9
- package/dist/src/abi/interopXGateway.json +11 -11
- 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 +1 -1
- package/dist/src/constants/itokens.js +1 -1
- package/dist/src/db/models/transaction.js +8 -0
- 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 +31 -21
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
- 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/InteropBridge/ProcessWithdrawEvents.js +17 -1
- package/dist/src/tasks/InteropBridge/{SyncWithdrawEvents.js → SyncBurnEvents.js} +10 -8
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +16 -1
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -2
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
- package/dist/src/tasks/index.js +16 -5
- 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 +1 -82
- package/package.json +2 -2
- package/src/abi/interopBridgeToken.json +21 -9
- package/src/abi/interopXGateway.json +11 -11
- 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 +1 -1
- package/src/constants/itokens.ts +1 -1
- package/src/db/models/transaction.ts +10 -0
- 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 +44 -25
- package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
- 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/InteropBridge/ProcessWithdrawEvents.ts +24 -6
- package/src/tasks/InteropBridge/{SyncWithdrawEvents.ts → SyncBurnEvents.ts} +13 -13
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +22 -5
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -2
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
- package/src/tasks/index.ts +24 -5
- 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 +1 -122
- package/tsconfig.json +7 -2
@@ -14,6 +14,7 @@ const config_1 = __importDefault(require("@/config"));
|
|
14
14
|
const sequelize_1 = require("sequelize");
|
15
15
|
const waait_1 = __importDefault(require("waait"));
|
16
16
|
const net_1 = require("@/net");
|
17
|
+
const gnosis_1 = require("@/gnosis");
|
17
18
|
const generateGnosisTransaction = async (transactionData, safeContract) => {
|
18
19
|
console.log(transactionData);
|
19
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));
|
@@ -68,9 +69,22 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
|
68
69
|
const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
|
69
70
|
const ownersThreshold = await safeContract.getThreshold();
|
70
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
|
+
}
|
71
85
|
let gnosisTx = await generateGnosisTransaction({
|
72
86
|
baseGas: "0",
|
73
|
-
data
|
87
|
+
data,
|
74
88
|
gasPrice: "0",
|
75
89
|
gasToken: "0x0000000000000000000000000000000000000000",
|
76
90
|
nonce: '0',
|
@@ -127,6 +141,7 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
|
127
141
|
console.log('ExecutionSuccess');
|
128
142
|
transaction.targetStatus = 'success';
|
129
143
|
transaction.targetTransactionHash = txSent.hash;
|
144
|
+
transaction.targetLogs = logs;
|
130
145
|
transaction.status = 'success';
|
131
146
|
await transaction.save();
|
132
147
|
}
|
@@ -137,6 +152,7 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
|
137
152
|
transaction.status = 'failed';
|
138
153
|
await transaction.save();
|
139
154
|
}
|
155
|
+
net_1.protocol.sendTransaction(transaction);
|
140
156
|
}
|
141
157
|
async start() {
|
142
158
|
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
@@ -10,10 +10,10 @@ const abi_1 = __importDefault(require("@/abi"));
|
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const utils_1 = require("@/utils");
|
12
12
|
const config_1 = __importDefault(require("@/config"));
|
13
|
-
class
|
13
|
+
class SyncBurnEvents extends BaseTask_1.BaseTask {
|
14
14
|
constructor({ chainId, itokenAddress }) {
|
15
15
|
super({
|
16
|
-
logger: new logger_1.default("InteropBridgeToken::
|
16
|
+
logger: new logger_1.default("InteropBridgeToken::SyncBurnEvents"),
|
17
17
|
});
|
18
18
|
this.chainId = chainId;
|
19
19
|
this.itokenAddress = itokenAddress;
|
@@ -27,12 +27,12 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
|
|
27
27
|
if (!event.args) {
|
28
28
|
continue;
|
29
29
|
}
|
30
|
-
const { to, amount,
|
30
|
+
const { to, amount, sourceChainId, targetChainId } = event.args;
|
31
31
|
const uniqueIdentifier = {
|
32
32
|
action: 'withdraw',
|
33
33
|
submitTransactionHash: event.transactionHash,
|
34
|
-
sourceChainId:
|
35
|
-
targetChainId:
|
34
|
+
sourceChainId: sourceChainId,
|
35
|
+
targetChainId: targetChainId,
|
36
36
|
};
|
37
37
|
if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
|
38
38
|
continue;
|
@@ -44,12 +44,14 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
|
|
44
44
|
to,
|
45
45
|
amount: amount.toString(),
|
46
46
|
itoken: this.itokenAddress,
|
47
|
-
|
47
|
+
sourceChainId: sourceChainId,
|
48
|
+
targetChainId: targetChainId,
|
48
49
|
}, sourceEvent: {
|
49
50
|
to,
|
50
51
|
amount: amount.toString(),
|
51
52
|
itoken: this.itokenAddress,
|
52
|
-
|
53
|
+
sourceChainId: sourceChainId,
|
54
|
+
targetChainId: targetChainId,
|
53
55
|
}, status: "pending" }));
|
54
56
|
this.logger.info(`Withdraw queued: ${event.transactionHash} ${event.blockNumber}`);
|
55
57
|
}
|
@@ -66,4 +68,4 @@ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
|
|
66
68
|
await super.start();
|
67
69
|
}
|
68
70
|
}
|
69
|
-
exports.default =
|
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;
|
@@ -14,6 +14,7 @@ const config_1 = __importDefault(require("@/config"));
|
|
14
14
|
const sequelize_1 = require("sequelize");
|
15
15
|
const waait_1 = __importDefault(require("waait"));
|
16
16
|
const net_1 = require("@/net");
|
17
|
+
const gnosis_1 = require("@/gnosis");
|
17
18
|
const generateGnosisTransaction = async (transactionData, safeContract) => {
|
18
19
|
console.log(transactionData);
|
19
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));
|
@@ -68,9 +69,22 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
68
69
|
const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
|
69
70
|
const ownersThreshold = await safeContract.getThreshold();
|
70
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
|
+
}
|
71
85
|
let gnosisTx = await generateGnosisTransaction({
|
72
86
|
baseGas: "0",
|
73
|
-
data
|
87
|
+
data,
|
74
88
|
gasPrice: "0",
|
75
89
|
gasToken: "0x0000000000000000000000000000000000000000",
|
76
90
|
nonce: '0',
|
@@ -127,6 +141,7 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
127
141
|
console.log('ExecutionSuccess');
|
128
142
|
transaction.targetStatus = 'success';
|
129
143
|
transaction.targetTransactionHash = txSent.hash;
|
144
|
+
transaction.targetLogs = logs;
|
130
145
|
transaction.status = 'success';
|
131
146
|
await transaction.save();
|
132
147
|
}
|
@@ -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;
|
@@ -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;
|
@@ -42,9 +42,11 @@ class SyncTransactionStatusTask extends BaseTask_1.BaseTask {
|
|
42
42
|
transaction.sourceStatus = transactionStatus.sourceStatus;
|
43
43
|
transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash;
|
44
44
|
transaction.sourceErrors = transactionStatus.sourceErrors;
|
45
|
+
transaction.sourceLogs = transactionStatus.sourceLogs;
|
45
46
|
transaction.targetStatus = transactionStatus.targetStatus;
|
46
47
|
transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
|
47
48
|
transaction.targetErrors = transactionStatus.targetErrors;
|
49
|
+
transaction.targetLogs = transactionStatus.targetLogs;
|
48
50
|
transaction.status = transactionStatus.status;
|
49
51
|
await transaction.save();
|
50
52
|
this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
|
package/dist/src/tasks/index.js
CHANGED
@@ -6,27 +6,38 @@ 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
|
9
|
+
const SyncWithdrawtEvents_1 = __importDefault(require("./InteropXGateway/SyncWithdrawtEvents"));
|
10
10
|
const ProcessWithdrawEvents_1 = __importDefault(require("./InteropBridge/ProcessWithdrawEvents"));
|
11
|
-
const
|
11
|
+
const SyncBurnEvents_1 = __importDefault(require("./InteropBridge/SyncBurnEvents"));
|
12
|
+
const SyncMintEvents_1 = __importDefault(require("./InteropBridge/SyncMintEvents"));
|
12
13
|
const SyncTransactionStatusTask_1 = __importDefault(require("./Transactions/SyncTransactionStatusTask"));
|
14
|
+
const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
|
13
15
|
class Tasks {
|
14
16
|
constructor() {
|
15
17
|
this.tasks = [
|
16
18
|
new SyncTransactionStatusTask_1.default(),
|
17
19
|
new AutoUpdateTask_1.default(),
|
20
|
+
// InteropXGateway
|
18
21
|
new SyncDepositEvents_1.default({
|
19
22
|
chainId: 43114
|
20
23
|
}),
|
21
24
|
new ProcessDepositEvents_1.default({
|
22
25
|
chainId: 43114
|
23
26
|
}),
|
24
|
-
new
|
25
|
-
chainId:
|
26
|
-
itokenAddress: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
|
27
|
+
new SyncWithdrawtEvents_1.default({
|
28
|
+
chainId: 43114
|
27
29
|
}),
|
30
|
+
// InteropBridge
|
28
31
|
new ProcessWithdrawEvents_1.default({
|
29
32
|
chainId: 137,
|
33
|
+
}),
|
34
|
+
new SyncMintEvents_1.default({
|
35
|
+
chainId: 137,
|
36
|
+
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
37
|
+
}),
|
38
|
+
new SyncBurnEvents_1.default({
|
39
|
+
chainId: 137,
|
40
|
+
itokenAddress: '0x62c0045f3277e7067cacad3c8038eeabb1bd92d1',
|
30
41
|
})
|
31
42
|
];
|
32
43
|
}
|
@@ -57,11 +57,17 @@ const _abi = [
|
|
57
57
|
name: "amount",
|
58
58
|
type: "uint256",
|
59
59
|
},
|
60
|
+
{
|
61
|
+
indexed: false,
|
62
|
+
internalType: "uint32",
|
63
|
+
name: "sourceChainId",
|
64
|
+
type: "uint32",
|
65
|
+
},
|
60
66
|
{
|
61
67
|
indexed: true,
|
62
|
-
internalType: "
|
63
|
-
name: "
|
64
|
-
type: "
|
68
|
+
internalType: "uint32",
|
69
|
+
name: "targetChainId",
|
70
|
+
type: "uint32",
|
65
71
|
},
|
66
72
|
],
|
67
73
|
name: "Burn",
|
@@ -84,14 +90,20 @@ const _abi = [
|
|
84
90
|
},
|
85
91
|
{
|
86
92
|
indexed: true,
|
87
|
-
internalType: "
|
88
|
-
name: "
|
89
|
-
type: "
|
93
|
+
internalType: "uint32",
|
94
|
+
name: "sourceChainId",
|
95
|
+
type: "uint32",
|
96
|
+
},
|
97
|
+
{
|
98
|
+
indexed: false,
|
99
|
+
internalType: "uint32",
|
100
|
+
name: "targetChainId",
|
101
|
+
type: "uint32",
|
90
102
|
},
|
91
103
|
{
|
92
104
|
indexed: true,
|
93
105
|
internalType: "bytes32",
|
94
|
-
name: "
|
106
|
+
name: "submitTransactionHash",
|
95
107
|
type: "bytes32",
|
96
108
|
},
|
97
109
|
],
|
@@ -222,9 +234,9 @@ const _abi = [
|
|
222
234
|
type: "uint256",
|
223
235
|
},
|
224
236
|
{
|
225
|
-
internalType: "
|
237
|
+
internalType: "uint32",
|
226
238
|
name: "chainId",
|
227
|
-
type: "
|
239
|
+
type: "uint32",
|
228
240
|
},
|
229
241
|
],
|
230
242
|
name: "burn",
|
@@ -306,9 +318,9 @@ const _abi = [
|
|
306
318
|
type: "uint256",
|
307
319
|
},
|
308
320
|
{
|
309
|
-
internalType: "
|
321
|
+
internalType: "uint32",
|
310
322
|
name: "chainId",
|
311
|
-
type: "
|
323
|
+
type: "uint32",
|
312
324
|
},
|
313
325
|
{
|
314
326
|
internalType: "bytes32",
|
@@ -46,15 +46,15 @@ const _abi = [
|
|
46
46
|
},
|
47
47
|
{
|
48
48
|
indexed: false,
|
49
|
-
internalType: "
|
49
|
+
internalType: "uint32",
|
50
50
|
name: "sourceChainId",
|
51
|
-
type: "
|
51
|
+
type: "uint32",
|
52
52
|
},
|
53
53
|
{
|
54
54
|
indexed: true,
|
55
|
-
internalType: "
|
55
|
+
internalType: "uint32",
|
56
56
|
name: "targetChainId",
|
57
|
-
type: "
|
57
|
+
type: "uint32",
|
58
58
|
},
|
59
59
|
],
|
60
60
|
name: "LogGatewayDeposit",
|
@@ -83,15 +83,15 @@ const _abi = [
|
|
83
83
|
},
|
84
84
|
{
|
85
85
|
indexed: true,
|
86
|
-
internalType: "
|
86
|
+
internalType: "uint32",
|
87
87
|
name: "sourceChainId",
|
88
|
-
type: "
|
88
|
+
type: "uint32",
|
89
89
|
},
|
90
90
|
{
|
91
91
|
indexed: false,
|
92
|
-
internalType: "
|
92
|
+
internalType: "uint32",
|
93
93
|
name: "targetChainId",
|
94
|
-
type: "
|
94
|
+
type: "uint32",
|
95
95
|
},
|
96
96
|
{
|
97
97
|
indexed: true,
|
@@ -148,9 +148,9 @@ const _abi = [
|
|
148
148
|
type: "uint256",
|
149
149
|
},
|
150
150
|
{
|
151
|
-
internalType: "
|
151
|
+
internalType: "uint32",
|
152
152
|
name: "chainId_",
|
153
|
-
type: "
|
153
|
+
type: "uint32",
|
154
154
|
},
|
155
155
|
],
|
156
156
|
name: "deposit",
|
@@ -176,9 +176,9 @@ const _abi = [
|
|
176
176
|
type: "uint256",
|
177
177
|
},
|
178
178
|
{
|
179
|
-
internalType: "
|
179
|
+
internalType: "uint32",
|
180
180
|
name: "chainId_",
|
181
|
-
type: "
|
181
|
+
type: "uint32",
|
182
182
|
},
|
183
183
|
],
|
184
184
|
name: "depositFor",
|
@@ -224,9 +224,9 @@ const _abi = [
|
|
224
224
|
type: "address",
|
225
225
|
},
|
226
226
|
{
|
227
|
-
internalType: "
|
227
|
+
internalType: "uint32",
|
228
228
|
name: "chainId_",
|
229
|
-
type: "
|
229
|
+
type: "uint32",
|
230
230
|
},
|
231
231
|
{
|
232
232
|
internalType: "bytes32",
|
package/dist/src/utils/index.js
CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.getContract = exports.
|
6
|
+
exports.getContract = exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.shortenHash = exports.http = void 0;
|
7
7
|
/**
|
8
8
|
* @module util
|
9
9
|
*/
|
@@ -11,9 +11,6 @@ const axios_1 = __importDefault(require("axios"));
|
|
11
11
|
const axios_retry_1 = __importDefault(require("axios-retry"));
|
12
12
|
const constants_1 = require("@/constants");
|
13
13
|
const ethers_1 = require("ethers");
|
14
|
-
const ethers_multisend_1 = require("ethers-multisend");
|
15
|
-
const config_1 = __importDefault(require("@/config"));
|
16
|
-
const abi_1 = __importDefault(require("@/abi"));
|
17
14
|
exports.http = axios_1.default.create();
|
18
15
|
(0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
|
19
16
|
function shortenHash(hash, length = 4) {
|
@@ -112,84 +109,6 @@ const generateInteropTransactionHash = (data) => {
|
|
112
109
|
]);
|
113
110
|
};
|
114
111
|
exports.generateInteropTransactionHash = generateInteropTransactionHash;
|
115
|
-
const buildDataForTransaction = async (transaction, type) => {
|
116
|
-
type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
|
117
|
-
switch (transaction.action) {
|
118
|
-
case "deposit":
|
119
|
-
return await (0, exports.buildDepositDataForTransaction)(transaction, type);
|
120
|
-
case "withdraw":
|
121
|
-
return await (0, exports.buildWithdrawDataForTransaction)(transaction, type);
|
122
|
-
default:
|
123
|
-
throw new Error(`Unknown action: ${transaction.action}`);
|
124
|
-
}
|
125
|
-
};
|
126
|
-
exports.buildDataForTransaction = buildDataForTransaction;
|
127
|
-
const buildDepositDataForTransaction = async (transaction, type) => {
|
128
|
-
const transactions = [];
|
129
|
-
if (transaction.action !== 'deposit') {
|
130
|
-
throw new Error(`Invalid action: ${transaction.action}`);
|
131
|
-
}
|
132
|
-
if (transaction.action === 'deposit' && transaction.sourceStatus === 'pending') {
|
133
|
-
throw Error('Cannot build data for pending deposit transaction');
|
134
|
-
}
|
135
|
-
if (!transaction.submitEvent) {
|
136
|
-
throw Error('Cannot build data for transaction without submitEvent');
|
137
|
-
}
|
138
|
-
const token = constants_1.tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
|
139
|
-
if (!token) {
|
140
|
-
throw Error('Cannot build data for transaction without token');
|
141
|
-
}
|
142
|
-
const itoken = constants_1.itokens[transaction.targetChainId].find(itoken => itoken.symbol.toLowerCase() === token.symbol.toLowerCase());
|
143
|
-
if (!itoken) {
|
144
|
-
throw Error('Cannot build data for transaction without itoken');
|
145
|
-
}
|
146
|
-
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
|
147
|
-
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
148
|
-
const interopBridgeContract = getContract(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
|
149
|
-
const { data } = await interopBridgeContract.populateTransaction.mint(transaction.submitEvent.user, ethers_1.ethers.BigNumber.from(transaction.submitEvent.amount.toString()), ethers_1.ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()), transaction.submitTransactionHash);
|
150
|
-
transactions.push({
|
151
|
-
to: itoken.address,
|
152
|
-
data: data,
|
153
|
-
value: '0',
|
154
|
-
operation: ethers_multisend_1.OperationType.Call,
|
155
|
-
});
|
156
|
-
return (0, ethers_multisend_1.encodeMulti)(transactions).data;
|
157
|
-
};
|
158
|
-
exports.buildDepositDataForTransaction = buildDepositDataForTransaction;
|
159
|
-
const buildWithdrawDataForTransaction = async (transaction, type) => {
|
160
|
-
const transactions = [];
|
161
|
-
if (transaction.action !== 'withdraw') {
|
162
|
-
throw new Error(`Invalid action: ${transaction.action}`);
|
163
|
-
}
|
164
|
-
if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
165
|
-
throw Error('Cannot build data for pending withdraw transaction');
|
166
|
-
}
|
167
|
-
if (!transaction.submitEvent) {
|
168
|
-
throw Error('Cannot build data for transaction without submitEvent');
|
169
|
-
}
|
170
|
-
const { to, amount, chainId, itoken: itokenAddress } = transaction.submitEvent;
|
171
|
-
const itoken = constants_1.itokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
|
172
|
-
if (!itoken) {
|
173
|
-
throw Error('Cannot build data for transaction without itoken');
|
174
|
-
}
|
175
|
-
const token = constants_1.tokens[chainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
|
176
|
-
if (!token) {
|
177
|
-
throw Error('Cannot build data for transaction without token');
|
178
|
-
}
|
179
|
-
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
|
180
|
-
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
181
|
-
const gatewayAddress = constants_1.addresses[chainId].interopXGateway;
|
182
|
-
const interopBridgeContract = getContract(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
|
183
|
-
const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(transaction.sourceChainId.toString()), transaction.submitTransactionHash);
|
184
|
-
transactions.push({
|
185
|
-
to: gatewayAddress,
|
186
|
-
data: data,
|
187
|
-
value: '0',
|
188
|
-
operation: ethers_multisend_1.OperationType.Call,
|
189
|
-
});
|
190
|
-
return (0, ethers_multisend_1.encodeMulti)(transactions).data;
|
191
|
-
};
|
192
|
-
exports.buildWithdrawDataForTransaction = buildWithdrawDataForTransaction;
|
193
112
|
function getContract(address, contractInterface, signerOrProvider) {
|
194
113
|
if (!ethers_1.ethers.utils.getAddress(address) || address === ethers_1.ethers.constants.AddressZero) {
|
195
114
|
throw Error(`Invalid 'address' parameter '${address}'.`);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instadapp/interop-x",
|
3
|
-
"version": "0.0.0-dev.
|
3
|
+
"version": "0.0.0-dev.de23e71",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -28,7 +28,6 @@
|
|
28
28
|
"await-spawn": "^4.0.2",
|
29
29
|
"axios": "^0.27.1",
|
30
30
|
"axios-retry": "^3.2.4",
|
31
|
-
"bignumber.js": "^9.0.2",
|
32
31
|
"chalk": "4.1.2",
|
33
32
|
"dotenv": "^16.0.0",
|
34
33
|
"ethereumjs-util": "^7.1.4",
|
@@ -36,6 +35,7 @@
|
|
36
35
|
"ethers-multisend": "^2.1.1",
|
37
36
|
"expand-home-dir": "^0.0.3",
|
38
37
|
"fastify": "^3.28.0",
|
38
|
+
"fs-extra": "^10.1.0",
|
39
39
|
"libp2p": "^0.36.2",
|
40
40
|
"libp2p-bootstrap": "^0.14.0",
|
41
41
|
"libp2p-kad-dht": "^0.28.6",
|