@instadapp/interop-x 0.0.0-dev.de23e71 → 0.0.0-dev.e33810b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +13 -12
- package/dist/src/abi/index.js +2 -4
- package/dist/src/abi/interopXContract.json +454 -0
- package/dist/src/constants/addresses.js +3 -3
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +31 -1
- package/dist/src/db/models/transaction.js +19 -11
- package/dist/src/gnosis/actions/index.js +0 -2
- package/dist/src/gnosis/actions/withdraw/index.js +55 -0
- package/dist/src/gnosis/index.js +4 -4
- package/dist/src/index.js +4 -2
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +6 -2
- package/dist/src/tasks/{InteropBridge/ProcessWithdrawEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +42 -52
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
- package/dist/src/tasks/index.js +13 -30
- package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +37 -8
- package/package.json +13 -12
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +454 -0
- package/src/constants/addresses.ts +3 -3
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +32 -2
- package/src/db/models/transaction.ts +58 -27
- package/src/gnosis/actions/index.ts +0 -2
- package/src/gnosis/actions/withdraw/index.ts +77 -0
- package/src/gnosis/index.ts +5 -5
- package/src/index.ts +3 -1
- package/src/net/protocol/dial/SignatureDialProtocol.ts +6 -2
- package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +66 -99
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
- package/src/tasks/index.ts +15 -37
- package/src/typechain/InteropXContract.ts +680 -0
- package/src/typechain/factories/InteropXContract__factory.ts +642 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +78 -8
- package/dist/src/abi/interopBridgeToken.json +0 -298
- package/dist/src/abi/interopXGateway.json +0 -184
- package/dist/src/constants/itokens.js +0 -13
- package/dist/src/gnosis/actions/deposit.js +0 -48
- package/dist/src/gnosis/actions/withdraw.js +0 -50
- package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +0 -71
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +0 -67
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -164
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +0 -72
- package/dist/src/typechain/InteropXGateway.js +0 -2
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -471
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -298
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/gnosis/actions/deposit.ts +0 -63
- package/src/gnosis/actions/withdraw.ts +0 -67
- package/src/tasks/InteropBridge/SyncBurnEvents.ts +0 -119
- package/src/tasks/InteropBridge/SyncMintEvents.ts +0 -99
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -260
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +0 -105
- package/src/typechain/InteropBridgeToken.ts +0 -692
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -478
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -4,30 +4,42 @@ exports.tokens = void 0;
|
|
4
4
|
exports.tokens = {
|
5
5
|
1: [
|
6
6
|
{
|
7
|
+
aliases: ['eth'],
|
7
8
|
symbol: "ETH",
|
8
9
|
name: "Ethereum",
|
9
10
|
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
10
11
|
decimals: 18,
|
11
12
|
},
|
12
13
|
{
|
14
|
+
aliases: ['weth'],
|
15
|
+
symbol: "WETH",
|
16
|
+
name: "Wrapped Ethereum",
|
17
|
+
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
18
|
+
decimals: 18,
|
19
|
+
},
|
20
|
+
{
|
21
|
+
aliases: ['dai'],
|
13
22
|
symbol: "DAI",
|
14
23
|
name: "DAI Stable",
|
15
24
|
address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
16
25
|
decimals: 18,
|
17
26
|
},
|
18
27
|
{
|
28
|
+
aliases: ['usdc'],
|
19
29
|
symbol: "USDC",
|
20
30
|
name: "USD Coin",
|
21
31
|
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
22
32
|
decimals: 6,
|
23
33
|
},
|
24
34
|
{
|
35
|
+
aliases: ['usdt'],
|
25
36
|
symbol: "USDT",
|
26
37
|
name: "Tether USD Coin",
|
27
38
|
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
28
39
|
decimals: 6,
|
29
40
|
},
|
30
41
|
{
|
42
|
+
aliases: ['wbtc'],
|
31
43
|
symbol: "WBTC",
|
32
44
|
name: "Wrapped BTC",
|
33
45
|
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
@@ -36,36 +48,42 @@ exports.tokens = {
|
|
36
48
|
],
|
37
49
|
137: [
|
38
50
|
{
|
51
|
+
aliases: ['eth', 'weth'],
|
39
52
|
symbol: "ETH",
|
40
53
|
name: "Ethereum",
|
41
54
|
address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
42
55
|
decimals: 18,
|
43
56
|
},
|
44
57
|
{
|
58
|
+
aliases: ['dai'],
|
45
59
|
symbol: "DAI",
|
46
60
|
name: "DAI Stable",
|
47
61
|
address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
|
48
62
|
decimals: 18,
|
49
63
|
},
|
50
64
|
{
|
65
|
+
aliases: ['usdc'],
|
51
66
|
symbol: "USDC",
|
52
67
|
name: "USD Coin",
|
53
68
|
address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
54
69
|
decimals: 6,
|
55
70
|
},
|
56
71
|
{
|
72
|
+
aliases: ['usdt'],
|
57
73
|
symbol: "USDT",
|
58
74
|
name: "Tether USD Coin",
|
59
75
|
address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
|
60
76
|
decimals: 6,
|
61
77
|
},
|
62
78
|
{
|
79
|
+
aliases: ['wbtc'],
|
63
80
|
symbol: "WBTC",
|
64
81
|
name: "Wrapped BTC",
|
65
82
|
address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
66
83
|
decimals: 8,
|
67
84
|
},
|
68
85
|
{
|
86
|
+
aliases: ['avax'],
|
69
87
|
symbol: "AVAX",
|
70
88
|
name: "Avalanche Token",
|
71
89
|
address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
|
@@ -74,30 +92,42 @@ exports.tokens = {
|
|
74
92
|
],
|
75
93
|
43114: [
|
76
94
|
{
|
95
|
+
aliases: ['eth', 'weth'],
|
77
96
|
symbol: "ETH",
|
78
97
|
name: "Ethereum",
|
79
98
|
address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
|
80
99
|
decimals: 18,
|
81
100
|
},
|
82
101
|
{
|
102
|
+
aliases: ['dai'],
|
83
103
|
symbol: "DAI",
|
84
104
|
name: "DAI Stable",
|
85
105
|
address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
|
86
106
|
decimals: 18,
|
87
107
|
},
|
88
108
|
{
|
109
|
+
aliases: ['usdc'],
|
89
110
|
symbol: "USDC",
|
90
111
|
name: "USD Coin",
|
91
112
|
address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
|
92
113
|
decimals: 6,
|
93
114
|
},
|
94
115
|
{
|
95
|
-
|
116
|
+
aliases: ['usdt'],
|
117
|
+
symbol: "USDt",
|
96
118
|
name: "Tether USD Coin",
|
119
|
+
address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
|
120
|
+
decimals: 6,
|
121
|
+
},
|
122
|
+
{
|
123
|
+
aliases: ['usdt'],
|
124
|
+
symbol: "USDT.e",
|
125
|
+
name: "Tether USD",
|
97
126
|
address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
|
98
127
|
decimals: 6,
|
99
128
|
},
|
100
129
|
{
|
130
|
+
aliases: ["wbtc"],
|
101
131
|
symbol: "WBTC",
|
102
132
|
name: "Wrapped BTC",
|
103
133
|
address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
|
@@ -12,16 +12,18 @@ Transaction.init({
|
|
12
12
|
autoIncrement: true,
|
13
13
|
primaryKey: true
|
14
14
|
},
|
15
|
-
|
16
|
-
|
15
|
+
requestTransactionHash: sequelize_2.DataTypes.NUMBER,
|
16
|
+
requestBlockNumber: sequelize_2.DataTypes.NUMBER,
|
17
17
|
transactionHash: sequelize_2.DataTypes.STRING,
|
18
|
-
|
19
|
-
|
20
|
-
to: sequelize_2.DataTypes.STRING,
|
18
|
+
actionId: sequelize_2.DataTypes.STRING,
|
19
|
+
bridger: sequelize_2.DataTypes.STRING,
|
21
20
|
sourceChainId: sequelize_2.DataTypes.NUMBER,
|
22
21
|
sourceTransactionHash: sequelize_2.DataTypes.STRING,
|
23
22
|
sourceBlockNumber: sequelize_2.DataTypes.NUMBER,
|
24
|
-
sourceStatus:
|
23
|
+
sourceStatus: {
|
24
|
+
type: sequelize_2.DataTypes.STRING,
|
25
|
+
defaultValue: 'uninitialised'
|
26
|
+
},
|
25
27
|
sourceErrors: {
|
26
28
|
type: sequelize_2.DataTypes.JSON,
|
27
29
|
// defaultValue: [],
|
@@ -38,7 +40,10 @@ Transaction.init({
|
|
38
40
|
targetChainId: sequelize_2.DataTypes.NUMBER,
|
39
41
|
targetTransactionHash: sequelize_2.DataTypes.STRING,
|
40
42
|
targetBlockNumber: sequelize_2.DataTypes.NUMBER,
|
41
|
-
targetStatus:
|
43
|
+
targetStatus: {
|
44
|
+
type: sequelize_2.DataTypes.STRING,
|
45
|
+
defaultValue: 'uninitialised'
|
46
|
+
},
|
42
47
|
targetErrors: {
|
43
48
|
type: sequelize_2.DataTypes.JSON,
|
44
49
|
// defaultValue: [],
|
@@ -49,10 +54,13 @@ Transaction.init({
|
|
49
54
|
},
|
50
55
|
targetCreatedAt: sequelize_2.DataTypes.DATE,
|
51
56
|
targetDelayUntil: sequelize_2.DataTypes.DATE,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
requestEvent: {
|
58
|
+
type: sequelize_2.DataTypes.JSON,
|
59
|
+
allowNull: false
|
60
|
+
},
|
61
|
+
requestSentEvent: sequelize_2.DataTypes.JSON,
|
62
|
+
committedEvent: sequelize_2.DataTypes.JSON,
|
63
|
+
completedEvent: sequelize_2.DataTypes.JSON,
|
56
64
|
status: {
|
57
65
|
type: sequelize_2.DataTypes.STRING,
|
58
66
|
defaultValue: 'pending'
|
@@ -3,9 +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
|
-
const deposit_1 = __importDefault(require("./deposit"));
|
7
6
|
const withdraw_1 = __importDefault(require("./withdraw"));
|
8
7
|
exports.default = {
|
9
|
-
deposit: deposit_1.default,
|
10
8
|
withdraw: withdraw_1.default,
|
11
9
|
};
|
@@ -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 abi_1 = __importDefault(require("@/abi"));
|
7
|
+
const config_1 = __importDefault(require("@/config"));
|
8
|
+
const constants_1 = require("@/constants");
|
9
|
+
const utils_1 = require("@/utils");
|
10
|
+
const ethers_1 = require("ethers");
|
11
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
12
|
+
async function default_1(transaction, type) {
|
13
|
+
const transactions = [];
|
14
|
+
const logs = [];
|
15
|
+
if (transaction.actionId !== 'withdraw') {
|
16
|
+
throw new Error(`Invalid action: ${transaction.actionId}`);
|
17
|
+
}
|
18
|
+
if (type !== 'source') {
|
19
|
+
throw new Error(`[WIP] Type not supported: ${type}`);
|
20
|
+
}
|
21
|
+
if (transaction.sourceStatus === 'pending') {
|
22
|
+
throw Error('Source transaction already processesing');
|
23
|
+
}
|
24
|
+
if (transaction.sourceStatus === 'pending') {
|
25
|
+
throw Error('Source transaction already processed');
|
26
|
+
}
|
27
|
+
if (!transaction.requestEvent) {
|
28
|
+
throw Error('Something went wrong, source transaction has no request event');
|
29
|
+
}
|
30
|
+
const { actionId, bridger, position, sourceChainId, targetChainId, metadata } = transaction.requestEvent;
|
31
|
+
const sourceChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
32
|
+
const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
|
33
|
+
const contractAddress = constants_1.addresses[sourceChainId].interopXContract;
|
34
|
+
const contract = (0, utils_1.getContract)(contractAddress, abi_1.default.interopXContract, sourceWallet);
|
35
|
+
const sourceToken = constants_1.tokens[sourceChainId].find(t => t.address.toLowerCase() === position.withdraw[0].sourceToken.toLowerCase());
|
36
|
+
if (!sourceToken) {
|
37
|
+
throw Error('Source token not found');
|
38
|
+
}
|
39
|
+
const targetToken = constants_1.tokens[targetChainId].find(t => t.address.toLowerCase() === position.withdraw[0].targetToken.toLowerCase());
|
40
|
+
if (!targetToken) {
|
41
|
+
throw Error('Target token not found');
|
42
|
+
}
|
43
|
+
if (!sourceToken.aliases.some(alias => targetToken.aliases.includes(alias))) {
|
44
|
+
throw Error('Source and target token must be the same');
|
45
|
+
}
|
46
|
+
const { data } = await contract.populateTransaction.withdrawRequested(actionId, bridger, position.withdraw[0].sourceToken, position.withdraw[0].targetToken, position.withdraw[0].amount, targetChainId, transaction.requestTransactionHash, metadata);
|
47
|
+
transactions.push({
|
48
|
+
to: contractAddress,
|
49
|
+
data: data,
|
50
|
+
value: '0',
|
51
|
+
operation: ethers_multisend_1.OperationType.Call,
|
52
|
+
});
|
53
|
+
return { transactions, logs };
|
54
|
+
}
|
55
|
+
exports.default = default_1;
|
package/dist/src/gnosis/index.js
CHANGED
@@ -7,14 +7,14 @@ exports.buildGnosisAction = void 0;
|
|
7
7
|
const ethers_multisend_1 = require("ethers-multisend");
|
8
8
|
const actions_1 = __importDefault(require("./actions"));
|
9
9
|
const buildGnosisAction = async (transaction, type) => {
|
10
|
-
type = type || transaction.sourceStatus === '
|
11
|
-
if (actions_1.default.hasOwnProperty(transaction.
|
12
|
-
const { transactions, logs } = await actions_1.default[transaction.
|
10
|
+
// type = type || (transaction.sourceStatus === 'success' ? 'target' : 'source')
|
11
|
+
if (actions_1.default.hasOwnProperty(transaction.actionId)) {
|
12
|
+
const { transactions, logs } = await actions_1.default[transaction.actionId](transaction, type);
|
13
13
|
return {
|
14
14
|
data: (0, ethers_multisend_1.encodeMulti)(transactions).data,
|
15
15
|
logs
|
16
16
|
};
|
17
17
|
}
|
18
|
-
throw new Error(`Unknown action: ${transaction.
|
18
|
+
throw new Error(`Unknown action: ${transaction.actionId}`);
|
19
19
|
};
|
20
20
|
exports.buildGnosisAction = buildGnosisAction;
|
package/dist/src/index.js
CHANGED
@@ -13,7 +13,7 @@ const package_json_1 = __importDefault(require("../package.json"));
|
|
13
13
|
dotenv_1.default.config();
|
14
14
|
const logger_1 = __importDefault(require("@/logger"));
|
15
15
|
const logger = new logger_1.default('Process');
|
16
|
-
const GIT_SHORT_HASH = '
|
16
|
+
const GIT_SHORT_HASH = 'e33810b';
|
17
17
|
const printUsage = () => {
|
18
18
|
console.log();
|
19
19
|
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
@@ -72,7 +72,9 @@ const utils_1 = require("./utils");
|
|
72
72
|
async function main() {
|
73
73
|
(0, net_1.startPeer)({});
|
74
74
|
const tasks = new tasks_1.Tasks();
|
75
|
-
|
75
|
+
setTimeout(() => {
|
76
|
+
tasks.start();
|
77
|
+
}, 10000);
|
76
78
|
(0, api_1.startApiServer)();
|
77
79
|
net_1.protocol.on('TransactionStatus', async (payload) => {
|
78
80
|
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
@@ -17,6 +17,10 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
17
17
|
this.timeout = 30000;
|
18
18
|
}
|
19
19
|
async response(data) {
|
20
|
+
console.log({
|
21
|
+
tag: 'SignatureDialProtocol',
|
22
|
+
data
|
23
|
+
});
|
20
24
|
const signer = config_1.default.wallet;
|
21
25
|
let transaction;
|
22
26
|
let maxTimeout = 20000;
|
@@ -36,9 +40,9 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
36
40
|
}
|
37
41
|
const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
|
38
42
|
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
39
|
-
to: constants_1.addresses[transaction.
|
43
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
40
44
|
data: gnosisData,
|
41
|
-
chainId: transaction.
|
45
|
+
chainId: transaction.sourceChainId,
|
42
46
|
safeTxGas: data.safeTxGas,
|
43
47
|
nonce: data.safeNonce,
|
44
48
|
}, { signer });
|
@@ -10,24 +10,15 @@ const abi_1 = __importDefault(require("@/abi"));
|
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const utils_1 = require("@/utils");
|
12
12
|
const constants_1 = require("@/constants");
|
13
|
-
const config_1 = __importDefault(require("@/config"));
|
14
13
|
const sequelize_1 = require("sequelize");
|
14
|
+
const config_1 = __importDefault(require("@/config"));
|
15
15
|
const waait_1 = __importDefault(require("waait"));
|
16
|
-
const net_1 = require("@/net");
|
17
16
|
const gnosis_1 = require("@/gnosis");
|
18
|
-
const
|
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));
|
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 {
|
17
|
+
const net_1 = require("@/net");
|
18
|
+
class ProccessBridgeRequestEvents extends BaseTask_1.BaseTask {
|
28
19
|
constructor({ chainId }) {
|
29
20
|
super({
|
30
|
-
logger: new logger_1.default("
|
21
|
+
logger: new logger_1.default("InteropXContract::ProccessBridgeRequestEvents"),
|
31
22
|
});
|
32
23
|
this.leadNodeOnly = true;
|
33
24
|
this.chainId = chainId;
|
@@ -38,19 +29,17 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
|
38
29
|
const transaction = await db_1.Transaction.findOne({
|
39
30
|
where: {
|
40
31
|
status: 'pending',
|
41
|
-
sourceStatus: '
|
42
|
-
|
43
|
-
action: 'withdraw',
|
44
|
-
sourceCreatedAt: {
|
32
|
+
sourceStatus: 'uninitialised',
|
33
|
+
createdAt: {
|
45
34
|
[sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
|
46
35
|
},
|
47
|
-
|
36
|
+
sourceDelayUntil: {
|
48
37
|
[sequelize_1.Op.or]: {
|
49
38
|
[sequelize_1.Op.is]: null,
|
50
39
|
[sequelize_1.Op.lt]: new Date(),
|
51
40
|
}
|
52
41
|
},
|
53
|
-
|
42
|
+
requestBlockNumber: {
|
54
43
|
[sequelize_1.Op.lt]: blockNumber - 12,
|
55
44
|
},
|
56
45
|
sourceChainId: this.chainId,
|
@@ -62,27 +51,23 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
|
62
51
|
console.log(`Processing transaction ${transaction.transactionHash}`);
|
63
52
|
transaction.targetStatus = 'pending';
|
64
53
|
await transaction.save();
|
65
|
-
|
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();
|
54
|
+
const ownersThreshold = await this.safeContract.getThreshold();
|
71
55
|
await (0, waait_1.default)(10000);
|
72
56
|
let data, logs = [];
|
73
57
|
try {
|
74
|
-
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction));
|
58
|
+
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, 'source'));
|
75
59
|
}
|
76
60
|
catch (error) {
|
77
61
|
console.log(error);
|
62
|
+
transaction.sourceStatus = 'failed';
|
63
|
+
transaction.sourceErrors = [error.message];
|
78
64
|
transaction.targetStatus = 'failed';
|
79
|
-
transaction.targetErrors = [error.message];
|
80
65
|
transaction.status = 'failed';
|
81
66
|
await transaction.save();
|
82
67
|
net_1.protocol.sendTransaction(transaction);
|
83
68
|
return;
|
84
69
|
}
|
85
|
-
let gnosisTx = await generateGnosisTransaction({
|
70
|
+
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
86
71
|
baseGas: "0",
|
87
72
|
data,
|
88
73
|
gasPrice: "0",
|
@@ -90,12 +75,12 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
|
90
75
|
nonce: '0',
|
91
76
|
operation: "1",
|
92
77
|
refundReceiver: "0x0000000000000000000000000000000000000000",
|
93
|
-
safeAddress:
|
78
|
+
safeAddress: this.safeContractAddress,
|
94
79
|
safeTxGas: "79668",
|
95
|
-
to: constants_1.addresses[transaction.
|
80
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
96
81
|
value: "0",
|
97
|
-
}, safeContract);
|
98
|
-
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
82
|
+
}, this.safeContract);
|
83
|
+
const owners = await this.safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
99
84
|
const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
|
100
85
|
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
101
86
|
console.log(ownerPeerIds);
|
@@ -109,54 +94,59 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
|
109
94
|
console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
|
110
95
|
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
111
96
|
await transaction.save();
|
112
|
-
transaction.
|
113
|
-
transaction.
|
97
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
98
|
+
transaction.sourceStatus = 'uninitialised';
|
114
99
|
await transaction.save();
|
115
100
|
const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
116
101
|
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
117
102
|
}
|
118
103
|
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
|
-
|
121
|
-
from:
|
122
|
-
gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9)
|
123
|
-
to:
|
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,
|
104
|
+
const { data: txData } = await this.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));
|
105
|
+
const txSent = await this.sourceWallet.sendTransaction({
|
106
|
+
from: this.sourceWallet.address,
|
107
|
+
gasPrice: ethers_1.ethers.BigNumber.from(120 * 10 ** 9),
|
108
|
+
to: this.safeContractAddress,
|
130
109
|
data: txData,
|
131
110
|
});
|
111
|
+
console.log(txSent);
|
132
112
|
const receipt = await txSent.wait();
|
133
113
|
const parsedLogs = [];
|
134
114
|
receipt.logs.forEach((log) => {
|
135
115
|
try {
|
136
|
-
parsedLogs.push(safeContract.interface.parseLog(log));
|
116
|
+
parsedLogs.push(this.safeContract.interface.parseLog(log));
|
137
117
|
}
|
138
118
|
catch (e) { }
|
139
119
|
});
|
140
120
|
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
141
121
|
console.log('ExecutionSuccess');
|
142
|
-
transaction.
|
143
|
-
|
144
|
-
|
122
|
+
transaction.sourceStatus = 'success';
|
123
|
+
if (txSent.blockNumber)
|
124
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
125
|
+
transaction.sourceTransactionHash = txSent.hash;
|
126
|
+
transaction.sourceLogs = logs;
|
145
127
|
transaction.status = 'success';
|
146
128
|
await transaction.save();
|
147
129
|
}
|
148
130
|
else {
|
149
131
|
console.log('ExecutionFailure');
|
150
|
-
transaction.
|
151
|
-
|
132
|
+
transaction.sourceStatus = 'failed';
|
133
|
+
if (txSent.blockNumber)
|
134
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
135
|
+
transaction.sourceTransactionHash = txSent.hash;
|
136
|
+
transaction.sourceTransactionHash = txSent.hash;
|
152
137
|
transaction.status = 'failed';
|
153
138
|
await transaction.save();
|
154
139
|
}
|
155
140
|
net_1.protocol.sendTransaction(transaction);
|
156
141
|
}
|
157
142
|
async start() {
|
143
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
158
144
|
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
145
|
+
this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider);
|
146
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, this.sourceWallet);
|
147
|
+
this.safeContractAddress = constants_1.addresses[this.chainId].gnosisSafe;
|
148
|
+
this.safeContract = (0, utils_1.getContract)(this.safeContractAddress, abi_1.default.gnosisSafe, this.sourceWallet);
|
159
149
|
await super.start();
|
160
150
|
}
|
161
151
|
}
|
162
|
-
exports.default =
|
152
|
+
exports.default = ProccessBridgeRequestEvents;
|
@@ -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 { actionId, bridger, position, sourceChainId, targetChainId, metadata } = event.args;
|
31
|
+
const uniqueIdentifier = {
|
32
|
+
actionId,
|
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), { requestBlockNumber: event.blockNumber, requestEvent: {
|
44
|
+
actionId,
|
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,90 @@
|
|
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 { actionId, bridger, position, sourceChainId, targetChainId, requestTransactionHash, metadata } = event.args;
|
32
|
+
const uniqueIdentifier = {
|
33
|
+
actionId,
|
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
|
+
actionId,
|
55
|
+
bridger,
|
56
|
+
position: {
|
57
|
+
withdraw: position.withdraw.map((v) => ({
|
58
|
+
sourceToken: v.sourceToken,
|
59
|
+
targetToken: v.targetToken,
|
60
|
+
amount: v.amount.toString()
|
61
|
+
})),
|
62
|
+
supply: position.supply.map((v) => ({
|
63
|
+
sourceToken: v.sourceToken,
|
64
|
+
targetToken: v.targetToken,
|
65
|
+
amount: v.amount.toString()
|
66
|
+
})),
|
67
|
+
},
|
68
|
+
sourceChainId: sourceChainId,
|
69
|
+
targetChainId: targetChainId,
|
70
|
+
metadata,
|
71
|
+
requestTransactionHash,
|
72
|
+
};
|
73
|
+
await transaction.save();
|
74
|
+
this.logger.info(`New bridge request sent received: ${transactionHash} `);
|
75
|
+
}
|
76
|
+
catch (error) {
|
77
|
+
this.logger.error(error);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
if (processedEvents > 0)
|
81
|
+
this.logger.info(`${processedEvents} events processed`);
|
82
|
+
}
|
83
|
+
async start() {
|
84
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopXContract;
|
85
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
86
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXContract, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
87
|
+
await super.start();
|
88
|
+
}
|
89
|
+
}
|
90
|
+
exports.default = SyncBridgeRequestSentEvents;
|