@instadapp/interop-x 0.0.0-dev.6ea4ee5 → 0.0.0-dev.733ff78
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/interop-x +1 -1
- package/dist/package.json +73 -0
- package/dist/{abi → src/abi}/erc20.json +0 -0
- package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
- package/dist/{abi → src/abi}/index.js +0 -0
- package/dist/{abi → src/abi}/interopBridgeToken.json +21 -9
- package/dist/{abi → src/abi}/interopXGateway.json +11 -11
- package/dist/src/api/index.js +36 -0
- package/dist/{config → src/config}/index.js +11 -1
- package/dist/{constants → src/constants}/addresses.js +1 -9
- package/dist/{constants → src/constants}/index.js +1 -0
- package/dist/src/constants/itokens.js +13 -0
- package/dist/{constants → src/constants}/tokens.js +0 -0
- package/dist/{db → src/db}/index.js +0 -0
- package/dist/{db → src/db}/models/index.js +0 -0
- package/dist/{db → src/db}/models/transaction.js +11 -1
- package/dist/{db → src/db}/sequelize.js +1 -1
- package/dist/src/gnosis/actions/deposit.js +48 -0
- package/dist/src/gnosis/actions/index.js +11 -0
- package/dist/src/gnosis/actions/withdraw.js +50 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +133 -0
- package/dist/{logger → src/logger}/index.js +0 -0
- package/dist/{net → src/net}/index.js +0 -0
- package/dist/{net → src/net}/peer/index.js +8 -3
- package/dist/{net → src/net}/pool/index.js +32 -9
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +17 -12
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/{net → src/net}/protocol/index.js +51 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +162 -0
- package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +71 -0
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +67 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +164 -0
- package/dist/{tasks → src/tasks}/InteropXGateway/SyncDepositEvents.js +18 -23
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +72 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
- package/dist/src/tasks/index.js +55 -0
- package/dist/{typechain → src/typechain}/Erc20.js +0 -0
- package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
- package/dist/{typechain → src/typechain}/InteropBridgeToken.js +0 -0
- package/dist/{typechain → src/typechain}/InteropXGateway.js +0 -0
- package/dist/{typechain → src/typechain}/common.js +0 -0
- package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/InteropBridgeToken__factory.js +23 -11
- package/dist/{typechain → src/typechain}/factories/InteropXGateway__factory.js +14 -14
- package/dist/{typechain → src/typechain}/factories/index.js +0 -0
- package/dist/{typechain → src/typechain}/index.js +0 -0
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/{utils → src/utils}/index.js +62 -6
- package/package.json +12 -5
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/abi/interopBridgeToken.json +21 -9
- package/src/abi/interopXGateway.json +11 -11
- package/src/api/index.ts +36 -0
- package/src/config/index.ts +11 -1
- package/src/constants/addresses.ts +1 -9
- package/src/constants/index.ts +1 -0
- package/src/constants/itokens.ts +10 -0
- package/src/db/models/transaction.ts +18 -4
- package/src/db/sequelize.ts +1 -1
- package/src/gnosis/actions/deposit.ts +63 -0
- package/src/gnosis/actions/index.ts +7 -0
- package/src/gnosis/actions/withdraw.ts +67 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +99 -8
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +19 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +67 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +14 -4
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +249 -0
- package/src/tasks/InteropBridge/SyncBurnEvents.ts +119 -0
- package/src/tasks/InteropBridge/SyncMintEvents.ts +99 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +260 -0
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +25 -15
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +105 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
- package/src/tasks/index.ts +43 -2
- 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 +76 -7
- package/dist/index.js +0 -63
- package/dist/tasks/index.js +0 -27
package/bin/interop-x
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
require('../dist/index')
|
2
|
+
require('../dist/src/index')
|
@@ -0,0 +1,73 @@
|
|
1
|
+
{
|
2
|
+
"name": "@instadapp/interop-x",
|
3
|
+
"version": "0.0.0-dev.733ff78",
|
4
|
+
"license": "MIT",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"engines": {
|
7
|
+
"node": ">=16",
|
8
|
+
"yarn": "^1.22.0"
|
9
|
+
},
|
10
|
+
"scripts": {
|
11
|
+
"start": "yarn build && node bin/interop-x",
|
12
|
+
"build": "yarn generate-abi-types && export GIT_REF=$(git rev-parse --short HEAD) && rimraf ./dist && tsc -p tsconfig.json && replace-in-file '@GIT_SHORT_HASH@' $GIT_REF ./dist/**/*.js",
|
13
|
+
"dev": "yarn generate-abi-types && NODE_ENV=development nodemon",
|
14
|
+
"generate-abi-types": "typechain --target=ethers-v5 'src/abi/*.json' --out-dir 'src/typechain'",
|
15
|
+
"prepublishOnly": "yarn build",
|
16
|
+
"postinstall": "patch-package"
|
17
|
+
},
|
18
|
+
"nodemonConfig": {
|
19
|
+
"watch": [
|
20
|
+
"src"
|
21
|
+
],
|
22
|
+
"ext": "ts",
|
23
|
+
"exec": "./node_modules/.bin/ts-node --files -r tsconfig-paths/register ./src/index.ts"
|
24
|
+
},
|
25
|
+
"dependencies": {
|
26
|
+
"@achingbrain/libp2p-gossipsub": "^0.12.2",
|
27
|
+
"@fastify/cors": "^7.0.0",
|
28
|
+
"await-spawn": "^4.0.2",
|
29
|
+
"axios": "^0.27.1",
|
30
|
+
"axios-retry": "^3.2.4",
|
31
|
+
"chalk": "4.1.2",
|
32
|
+
"dotenv": "^16.0.0",
|
33
|
+
"ethereumjs-util": "^7.1.4",
|
34
|
+
"ethers": "^5.6.4",
|
35
|
+
"ethers-multisend": "^2.1.1",
|
36
|
+
"expand-home-dir": "^0.0.3",
|
37
|
+
"fastify": "^3.28.0",
|
38
|
+
"fs-extra": "^10.1.0",
|
39
|
+
"libp2p": "^0.36.2",
|
40
|
+
"libp2p-bootstrap": "^0.14.0",
|
41
|
+
"libp2p-kad-dht": "^0.28.6",
|
42
|
+
"libp2p-mdns": "^0.18.0",
|
43
|
+
"libp2p-mplex": "^0.10.7",
|
44
|
+
"libp2p-noise": "^4.0.0",
|
45
|
+
"libp2p-pubsub-peer-discovery": "^4.0.0",
|
46
|
+
"libp2p-tcp": "^0.17.2",
|
47
|
+
"libp2p-websockets": "^0.16.2",
|
48
|
+
"luxon": "^2.3.2",
|
49
|
+
"module-alias": "^2.2.2",
|
50
|
+
"patch-package": "^6.4.7",
|
51
|
+
"postinstall-postinstall": "^2.1.0",
|
52
|
+
"sequelize": "6.18.0",
|
53
|
+
"sqlite3": "^5.0.5",
|
54
|
+
"waait": "^1.0.5"
|
55
|
+
},
|
56
|
+
"bin": {
|
57
|
+
"interop-x": "bin/interop-x",
|
58
|
+
"interopx": "bin/interop-x"
|
59
|
+
},
|
60
|
+
"devDependencies": {
|
61
|
+
"@typechain/ethers-v5": "^10.0.0",
|
62
|
+
"@types/bn.js": "^5.1.0",
|
63
|
+
"@types/fs-extra": "^9.0.13",
|
64
|
+
"@types/node": "^17.0.17",
|
65
|
+
"nodemon": "^2.0.15",
|
66
|
+
"replace-in-file": "^6.3.2",
|
67
|
+
"rimraf": "^3.0.2",
|
68
|
+
"ts-node": "^10.5.0",
|
69
|
+
"tsconfig-paths": "^3.12.0",
|
70
|
+
"typechain": "^8.0.0",
|
71
|
+
"typescript": "^4.5.5"
|
72
|
+
}
|
73
|
+
}
|
File without changes
|
File without changes
|
File without changes
|
@@ -46,11 +46,17 @@
|
|
46
46
|
"name": "amount",
|
47
47
|
"type": "uint256"
|
48
48
|
},
|
49
|
+
{
|
50
|
+
"indexed": false,
|
51
|
+
"internalType": "uint32",
|
52
|
+
"name": "sourceChainId",
|
53
|
+
"type": "uint32"
|
54
|
+
},
|
49
55
|
{
|
50
56
|
"indexed": true,
|
51
|
-
"internalType": "
|
52
|
-
"name": "
|
53
|
-
"type": "
|
57
|
+
"internalType": "uint32",
|
58
|
+
"name": "targetChainId",
|
59
|
+
"type": "uint32"
|
54
60
|
}
|
55
61
|
],
|
56
62
|
"name": "Burn",
|
@@ -73,14 +79,20 @@
|
|
73
79
|
},
|
74
80
|
{
|
75
81
|
"indexed": true,
|
76
|
-
"internalType": "
|
77
|
-
"name": "
|
78
|
-
"type": "
|
82
|
+
"internalType": "uint32",
|
83
|
+
"name": "sourceChainId",
|
84
|
+
"type": "uint32"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"indexed": false,
|
88
|
+
"internalType": "uint32",
|
89
|
+
"name": "targetChainId",
|
90
|
+
"type": "uint32"
|
79
91
|
},
|
80
92
|
{
|
81
93
|
"indexed": true,
|
82
94
|
"internalType": "bytes32",
|
83
|
-
"name": "
|
95
|
+
"name": "submitTransactionHash",
|
84
96
|
"type": "bytes32"
|
85
97
|
}
|
86
98
|
],
|
@@ -164,7 +176,7 @@
|
|
164
176
|
"inputs": [
|
165
177
|
{ "internalType": "address", "name": "to", "type": "address" },
|
166
178
|
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
|
167
|
-
{ "internalType": "
|
179
|
+
{ "internalType": "uint32", "name": "chainId", "type": "uint32" }
|
168
180
|
],
|
169
181
|
"name": "burn",
|
170
182
|
"outputs": [],
|
@@ -206,7 +218,7 @@
|
|
206
218
|
"inputs": [
|
207
219
|
{ "internalType": "address", "name": "to", "type": "address" },
|
208
220
|
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
|
209
|
-
{ "internalType": "
|
221
|
+
{ "internalType": "uint32", "name": "chainId", "type": "uint32" },
|
210
222
|
{
|
211
223
|
"internalType": "bytes32",
|
212
224
|
"name": "transactionHash",
|
@@ -35,15 +35,15 @@
|
|
35
35
|
},
|
36
36
|
{
|
37
37
|
"indexed": false,
|
38
|
-
"internalType": "
|
38
|
+
"internalType": "uint32",
|
39
39
|
"name": "sourceChainId",
|
40
|
-
"type": "
|
40
|
+
"type": "uint32"
|
41
41
|
},
|
42
42
|
{
|
43
43
|
"indexed": true,
|
44
|
-
"internalType": "
|
44
|
+
"internalType": "uint32",
|
45
45
|
"name": "targetChainId",
|
46
|
-
"type": "
|
46
|
+
"type": "uint32"
|
47
47
|
}
|
48
48
|
],
|
49
49
|
"name": "LogGatewayDeposit",
|
@@ -72,15 +72,15 @@
|
|
72
72
|
},
|
73
73
|
{
|
74
74
|
"indexed": true,
|
75
|
-
"internalType": "
|
75
|
+
"internalType": "uint32",
|
76
76
|
"name": "sourceChainId",
|
77
|
-
"type": "
|
77
|
+
"type": "uint32"
|
78
78
|
},
|
79
79
|
{
|
80
80
|
"indexed": false,
|
81
|
-
"internalType": "
|
81
|
+
"internalType": "uint32",
|
82
82
|
"name": "targetChainId",
|
83
|
-
"type": "
|
83
|
+
"type": "uint32"
|
84
84
|
},
|
85
85
|
{
|
86
86
|
"indexed": true,
|
@@ -122,7 +122,7 @@
|
|
122
122
|
"inputs": [
|
123
123
|
{ "internalType": "address", "name": "token_", "type": "address" },
|
124
124
|
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
125
|
-
{ "internalType": "
|
125
|
+
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" }
|
126
126
|
],
|
127
127
|
"name": "deposit",
|
128
128
|
"outputs": [],
|
@@ -134,7 +134,7 @@
|
|
134
134
|
{ "internalType": "address", "name": "to_", "type": "address" },
|
135
135
|
{ "internalType": "address", "name": "token_", "type": "address" },
|
136
136
|
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
137
|
-
{ "internalType": "
|
137
|
+
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" }
|
138
138
|
],
|
139
139
|
"name": "depositFor",
|
140
140
|
"outputs": [],
|
@@ -160,7 +160,7 @@
|
|
160
160
|
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
161
161
|
{ "internalType": "address", "name": "user_", "type": "address" },
|
162
162
|
{ "internalType": "address", "name": "token_", "type": "address" },
|
163
|
-
{ "internalType": "
|
163
|
+
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" },
|
164
164
|
{
|
165
165
|
"internalType": "bytes32",
|
166
166
|
"name": "transactionHash_",
|
@@ -0,0 +1,36 @@
|
|
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
|
+
exports.startApiServer = void 0;
|
7
|
+
const fastify_1 = __importDefault(require("fastify"));
|
8
|
+
const cors_1 = __importDefault(require("@fastify/cors"));
|
9
|
+
const logger_1 = __importDefault(require("@/logger"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const logger = new logger_1.default("RPC");
|
12
|
+
const server = (0, fastify_1.default)({ logger: false });
|
13
|
+
server.register(cors_1.default, {});
|
14
|
+
server.get('/', async () => 'Interop X API');
|
15
|
+
const startApiServer = async () => {
|
16
|
+
const HOST = process.env.API_HOST || '0.0.0.0';
|
17
|
+
const PORT = process.env.API_PORT || '8080';
|
18
|
+
try {
|
19
|
+
server.get('/transactions', async (req) => {
|
20
|
+
return await db_1.Transaction.findAndCountAll({
|
21
|
+
limit: 20,
|
22
|
+
offset: 0,
|
23
|
+
order: [
|
24
|
+
['createdAt', 'DESC']
|
25
|
+
]
|
26
|
+
});
|
27
|
+
});
|
28
|
+
await server.listen(PORT, HOST);
|
29
|
+
logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
|
30
|
+
}
|
31
|
+
catch (err) {
|
32
|
+
logger.error(err.message);
|
33
|
+
process.exit(1);
|
34
|
+
}
|
35
|
+
};
|
36
|
+
exports.startApiServer = startApiServer;
|
@@ -1,15 +1,22 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
const ethers_1 = require("ethers");
|
4
7
|
const types_1 = require("@/types");
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
9
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
5
10
|
class Config {
|
6
11
|
constructor() {
|
7
12
|
this.events = new types_1.EventBus();
|
8
|
-
this.maxPeers =
|
13
|
+
this.maxPeers = 20;
|
9
14
|
this.privateKey = process.env.PRIVATE_KEY;
|
10
15
|
this.staging = !!process.env.STAGING && process.env.STAGING === 'true';
|
16
|
+
this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
11
17
|
this.wallet = new ethers_1.Wallet(this.privateKey);
|
12
18
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
|
19
|
+
this.baseConfigPath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
13
20
|
}
|
14
21
|
get publicAddress() {
|
15
22
|
return this.wallet.address;
|
@@ -17,5 +24,8 @@ class Config {
|
|
17
24
|
isLeadNode() {
|
18
25
|
return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
|
19
26
|
}
|
27
|
+
isMaintenanceMode() {
|
28
|
+
return fs_extra_1.default.existsSync(this.baseConfigPath + '/maintenance');
|
29
|
+
}
|
20
30
|
}
|
21
31
|
exports.default = new Config();
|
@@ -6,23 +6,15 @@ exports.addresses = {
|
|
6
6
|
gnosisSafe: '0x811Bff6eF88dAAA0aD6438386B534A81cE3F160F',
|
7
7
|
multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
|
8
8
|
interopXGateway: '',
|
9
|
-
interopBridgeTokens: [],
|
10
9
|
},
|
11
10
|
137: {
|
12
11
|
gnosisSafe: '0x5635d2910e51da33d9DC0422c893CF4F28B69A25',
|
13
12
|
multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
|
14
13
|
interopXGateway: '',
|
15
|
-
interopBridgeTokens: [
|
16
|
-
{
|
17
|
-
address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
|
18
|
-
symbol: 'USDC',
|
19
|
-
}
|
20
|
-
],
|
21
14
|
},
|
22
15
|
43114: {
|
23
16
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
24
17
|
multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
|
25
|
-
interopXGateway: '
|
26
|
-
interopBridgeTokens: [],
|
18
|
+
interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
|
27
19
|
}
|
28
20
|
};
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./addresses"), exports);
|
18
18
|
__exportStar(require("./tokens"), exports);
|
19
|
+
__exportStar(require("./itokens"), exports);
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.itokens = void 0;
|
4
|
+
exports.itokens = {
|
5
|
+
1: [],
|
6
|
+
137: [
|
7
|
+
{
|
8
|
+
address: '0x62C0045f3277E7067cAcad3c8038eEaBB1Bd92D1',
|
9
|
+
symbol: 'USDC',
|
10
|
+
}
|
11
|
+
],
|
12
|
+
43114: []
|
13
|
+
};
|
File without changes
|
File without changes
|
File without changes
|
@@ -12,8 +12,10 @@ Transaction.init({
|
|
12
12
|
autoIncrement: true,
|
13
13
|
primaryKey: true
|
14
14
|
},
|
15
|
+
submitTransactionHash: sequelize_2.DataTypes.NUMBER,
|
16
|
+
submitBlockNumber: sequelize_2.DataTypes.NUMBER,
|
15
17
|
transactionHash: sequelize_2.DataTypes.STRING,
|
16
|
-
|
18
|
+
action: sequelize_2.DataTypes.STRING,
|
17
19
|
from: sequelize_2.DataTypes.STRING,
|
18
20
|
to: sequelize_2.DataTypes.STRING,
|
19
21
|
sourceChainId: sequelize_2.DataTypes.NUMBER,
|
@@ -24,6 +26,10 @@ Transaction.init({
|
|
24
26
|
type: sequelize_2.DataTypes.JSON,
|
25
27
|
// defaultValue: [],
|
26
28
|
},
|
29
|
+
sourceLogs: {
|
30
|
+
type: sequelize_2.DataTypes.JSON,
|
31
|
+
// defaultValue: [],
|
32
|
+
},
|
27
33
|
sourceCreatedAt: {
|
28
34
|
type: sequelize_2.DataTypes.DATE,
|
29
35
|
defaultValue: Date.now()
|
@@ -37,6 +43,10 @@ Transaction.init({
|
|
37
43
|
type: sequelize_2.DataTypes.JSON,
|
38
44
|
// defaultValue: [],
|
39
45
|
},
|
46
|
+
targetLogs: {
|
47
|
+
type: sequelize_2.DataTypes.JSON,
|
48
|
+
// defaultValue: [],
|
49
|
+
},
|
40
50
|
targetCreatedAt: sequelize_2.DataTypes.DATE,
|
41
51
|
targetDelayUntil: sequelize_2.DataTypes.DATE,
|
42
52
|
submitEvent: sequelize_2.DataTypes.JSON,
|
@@ -8,7 +8,7 @@ exports.sequelize = void 0;
|
|
8
8
|
const config_1 = __importDefault(require("@/config"));
|
9
9
|
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
10
10
|
const sequelize_1 = require("sequelize");
|
11
|
-
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x/data/${config_1.default.publicAddress}`);
|
11
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x/data/${config_1.default.publicAddress}/${config_1.default.staging ? 'staging' : ''}`);
|
12
12
|
exports.sequelize = new sequelize_1.Sequelize({
|
13
13
|
dialect: 'sqlite',
|
14
14
|
storage: `${basePath}/localDB.sqlite`,
|
@@ -0,0 +1,48 @@
|
|
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.sourceStatus === 'pending') {
|
16
|
+
throw Error('Cannot build data for pending deposit transaction');
|
17
|
+
}
|
18
|
+
if (!transaction.submitEvent) {
|
19
|
+
throw Error('Cannot build data for transaction without submitEvent');
|
20
|
+
}
|
21
|
+
const token = constants_1.tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
|
22
|
+
if (!token) {
|
23
|
+
throw Error(`Unsupported token ${transaction.submitEvent.token}`);
|
24
|
+
}
|
25
|
+
const itoken = constants_1.itokens[transaction.targetChainId].find(t => t.symbol.toLowerCase() === token.symbol.toLowerCase());
|
26
|
+
if (!itoken) {
|
27
|
+
throw Error(`Unsupported itoken ${token.symbol}`);
|
28
|
+
}
|
29
|
+
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
|
30
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
31
|
+
const interopBridgeContract = (0, utils_1.getContract)(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
|
32
|
+
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);
|
33
|
+
transactions.push({
|
34
|
+
to: itoken.address,
|
35
|
+
data: data,
|
36
|
+
value: '0',
|
37
|
+
operation: ethers_multisend_1.OperationType.Call,
|
38
|
+
});
|
39
|
+
logs.push({
|
40
|
+
type: 'mint',
|
41
|
+
message: `Minted ${transaction.submitEvent.amount / 10 ** token.decimals} ${token.symbol} to ${transaction.submitEvent.user}`,
|
42
|
+
});
|
43
|
+
return {
|
44
|
+
transactions,
|
45
|
+
logs,
|
46
|
+
};
|
47
|
+
}
|
48
|
+
exports.default = default_1;
|
@@ -0,0 +1,11 @@
|
|
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 deposit_1 = __importDefault(require("./deposit"));
|
7
|
+
const withdraw_1 = __importDefault(require("./withdraw"));
|
8
|
+
exports.default = {
|
9
|
+
deposit: deposit_1.default,
|
10
|
+
withdraw: withdraw_1.default,
|
11
|
+
};
|
@@ -0,0 +1,50 @@
|
|
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.action !== 'withdraw') {
|
16
|
+
throw new Error(`Invalid action: ${transaction.action}`);
|
17
|
+
}
|
18
|
+
if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
19
|
+
throw Error('Cannot build data for pending withdraw transaction');
|
20
|
+
}
|
21
|
+
if (!transaction.submitEvent) {
|
22
|
+
throw Error('Cannot build data for transaction without submitEvent');
|
23
|
+
}
|
24
|
+
const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
|
25
|
+
const itoken = constants_1.itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
|
26
|
+
if (!itoken) {
|
27
|
+
throw Error(`Unsupported itoken ${itokenAddress}`);
|
28
|
+
}
|
29
|
+
const token = constants_1.tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
|
30
|
+
if (!token) {
|
31
|
+
throw Error(`Unsupported token ${itoken.symbol}`);
|
32
|
+
}
|
33
|
+
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
34
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
35
|
+
const gatewayAddress = constants_1.addresses[targetChainId].interopXGateway;
|
36
|
+
const interopBridgeContract = (0, utils_1.getContract)(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
|
37
|
+
const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(sourceChainId.toString()), transaction.submitTransactionHash);
|
38
|
+
transactions.push({
|
39
|
+
to: gatewayAddress,
|
40
|
+
data: data,
|
41
|
+
value: '0',
|
42
|
+
operation: ethers_multisend_1.OperationType.Call,
|
43
|
+
});
|
44
|
+
logs.push({
|
45
|
+
type: 'transfer',
|
46
|
+
message: `Transfer ${amount / 10 ** token.decimals} ${token.symbol} to ${to}`,
|
47
|
+
});
|
48
|
+
return { transactions, logs };
|
49
|
+
}
|
50
|
+
exports.default = default_1;
|
@@ -0,0 +1,20 @@
|
|
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
|
+
exports.buildGnosisAction = void 0;
|
7
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
8
|
+
const actions_1 = __importDefault(require("./actions"));
|
9
|
+
const buildGnosisAction = async (transaction, type) => {
|
10
|
+
type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
|
11
|
+
if (actions_1.default.hasOwnProperty(transaction.action)) {
|
12
|
+
const { transactions, logs } = await actions_1.default[transaction.action](transaction, type);
|
13
|
+
return {
|
14
|
+
data: (0, ethers_multisend_1.encodeMulti)(transactions).data,
|
15
|
+
logs
|
16
|
+
};
|
17
|
+
}
|
18
|
+
throw new Error(`Unknown action: ${transaction.action}`);
|
19
|
+
};
|
20
|
+
exports.buildGnosisAction = buildGnosisAction;
|
@@ -0,0 +1,133 @@
|
|
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 module_alias_1 = __importDefault(require("module-alias"));
|
7
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
9
|
+
module_alias_1.default.addAliases({
|
10
|
+
"@/": __dirname + "/",
|
11
|
+
"@/logger": __dirname + "/logger",
|
12
|
+
"@/tasks": __dirname + "/tasks",
|
13
|
+
"@/gnosis": __dirname + "/gnosis",
|
14
|
+
"@/utils": __dirname + "/utils",
|
15
|
+
"@/api": __dirname + "/api",
|
16
|
+
"@/net": __dirname + "/net",
|
17
|
+
"@/db": __dirname + "/db",
|
18
|
+
"@/config": __dirname + "/config",
|
19
|
+
"@/types": __dirname + "/types",
|
20
|
+
"@/abi": __dirname + "/abi",
|
21
|
+
"@/constants": __dirname + "/constants",
|
22
|
+
"@/typechain": __dirname + "/typechain"
|
23
|
+
});
|
24
|
+
(0, module_alias_1.default)();
|
25
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
26
|
+
const chalk_1 = __importDefault(require("chalk"));
|
27
|
+
const ethers_1 = require("ethers");
|
28
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
29
|
+
dotenv_1.default.config();
|
30
|
+
const logger_1 = __importDefault(require("@/logger"));
|
31
|
+
const logger = new logger_1.default('Process');
|
32
|
+
const GIT_SHORT_HASH = '733ff78';
|
33
|
+
const printUsage = () => {
|
34
|
+
console.log();
|
35
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
36
|
+
console.log();
|
37
|
+
console.log('Usage:');
|
38
|
+
console.log(' interop-x help Show this message');
|
39
|
+
console.log(' interop-x version Print out the installed version of Interop X');
|
40
|
+
console.log();
|
41
|
+
console.log(' interop-x down Put the node into maintenance mode');
|
42
|
+
console.log(' interop-x up Take the node out of maintenance mode');
|
43
|
+
console.log();
|
44
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key');
|
45
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode');
|
46
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode');
|
47
|
+
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x Start the node with custom API host and port');
|
48
|
+
console.log();
|
49
|
+
};
|
50
|
+
if (process.argv.at(-1) === 'help') {
|
51
|
+
printUsage();
|
52
|
+
process.exit(0);
|
53
|
+
}
|
54
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
55
|
+
if (process.argv.at(-1) === 'down') {
|
56
|
+
fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
|
57
|
+
console.log(chalk_1.default.red('Maintenance mode enabled'));
|
58
|
+
process.exit(0);
|
59
|
+
}
|
60
|
+
if (process.argv.at(-1) === 'up') {
|
61
|
+
fs_extra_1.default.removeSync(basePath + '/maintenance');
|
62
|
+
console.log(chalk_1.default.green('Maintenance mode disabled'));
|
63
|
+
process.exit(0);
|
64
|
+
}
|
65
|
+
if (process.argv.at(-1) === 'version') {
|
66
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
67
|
+
process.exit(0);
|
68
|
+
}
|
69
|
+
if (!process.env.PRIVATE_KEY) {
|
70
|
+
console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
|
71
|
+
printUsage();
|
72
|
+
process.exit(1);
|
73
|
+
}
|
74
|
+
try {
|
75
|
+
new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
|
76
|
+
}
|
77
|
+
catch (e) {
|
78
|
+
console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
|
79
|
+
printUsage();
|
80
|
+
process.exit(1);
|
81
|
+
}
|
82
|
+
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
83
|
+
const tasks_1 = require("@/tasks");
|
84
|
+
const net_1 = require("@/net");
|
85
|
+
const api_1 = require("@/api");
|
86
|
+
const db_1 = require("./db");
|
87
|
+
const utils_1 = require("./utils");
|
88
|
+
async function main() {
|
89
|
+
(0, net_1.startPeer)({});
|
90
|
+
const tasks = new tasks_1.Tasks();
|
91
|
+
tasks.start();
|
92
|
+
(0, api_1.startApiServer)();
|
93
|
+
net_1.protocol.on('TransactionStatus', async (payload) => {
|
94
|
+
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
95
|
+
const peer = net_1.peerPool.getPeer(payload.peerId);
|
96
|
+
if (!peer) {
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
|
103
|
+
if (!transaction) {
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
transaction.sourceStatus = payload.data.sourceStatus;
|
107
|
+
transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
|
108
|
+
transaction.sourceErrors = payload.data.sourceErrors;
|
109
|
+
transaction.sourceLogs = payload.data.sourceLogs;
|
110
|
+
transaction.targetStatus = payload.data.targetStatus;
|
111
|
+
transaction.targetTransactionHash = payload.data.targetTransactionHash;
|
112
|
+
transaction.targetErrors = payload.data.targetErrors;
|
113
|
+
transaction.targetLogs = payload.data.targetLogs;
|
114
|
+
transaction.status = payload.data.status;
|
115
|
+
await transaction.save();
|
116
|
+
});
|
117
|
+
}
|
118
|
+
main()
|
119
|
+
.then(() => {
|
120
|
+
}).catch(err => {
|
121
|
+
console.error(err);
|
122
|
+
});
|
123
|
+
process.on('SIGINT', () => {
|
124
|
+
logger.debug('received SIGINT signal. exiting.');
|
125
|
+
process.exit(0);
|
126
|
+
});
|
127
|
+
process.on('SIGTERM', () => {
|
128
|
+
logger.debug('received SIGTERM signal. exiting.');
|
129
|
+
process.exit(0);
|
130
|
+
});
|
131
|
+
process.on('unhandledRejection', (reason, p) => {
|
132
|
+
logger.error('unhandled rejection: promise:', p, 'reason:', reason);
|
133
|
+
});
|
File without changes
|
File without changes
|