@instadapp/interop-x 0.0.0-dev.4c169eb → 0.0.0-dev.59f2858
Sign up to get free protection for your applications and to get access to all the features.
- package/.env.example +2 -1
- package/dist/api/index.js +33 -0
- package/dist/config/index.js +1 -0
- package/dist/db/models/transaction.js +1 -1
- package/dist/db/sequelize.js +1 -1
- package/dist/index.js +24 -1
- package/dist/tasks/InteropXGateway/SyncDepositEvents.js +3 -16
- package/dist/utils/index.js +1 -1
- package/package.json +5 -15
- package/src/api/index.ts +33 -0
- package/src/config/index.ts +2 -0
- package/src/db/models/transaction.ts +2 -2
- package/src/db/sequelize.ts +1 -1
- package/src/index.ts +29 -2
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -5
- package/src/utils/index.ts +2 -2
package/.env.example
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
PRIVATE_KEY=
|
1
|
+
PRIVATE_KEY=
|
2
|
+
STAGING=
|
@@ -0,0 +1,33 @@
|
|
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 fastify_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(fastify_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
|
+
});
|
24
|
+
});
|
25
|
+
await server.listen(PORT, HOST);
|
26
|
+
logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
|
27
|
+
}
|
28
|
+
catch (err) {
|
29
|
+
logger.error(err);
|
30
|
+
process.exit(1);
|
31
|
+
}
|
32
|
+
};
|
33
|
+
exports.startApiServer = startApiServer;
|
package/dist/config/index.js
CHANGED
@@ -7,6 +7,7 @@ class Config {
|
|
7
7
|
this.events = new types_1.EventBus();
|
8
8
|
this.maxPeers = 10;
|
9
9
|
this.privateKey = process.env.PRIVATE_KEY;
|
10
|
+
this.staging = !!process.env.STAGING && process.env.STAGING === 'true';
|
10
11
|
this.wallet = new ethers_1.Wallet(this.privateKey);
|
11
12
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
|
12
13
|
}
|
@@ -13,7 +13,7 @@ Transaction.init({
|
|
13
13
|
primaryKey: true
|
14
14
|
},
|
15
15
|
transactionHash: sequelize_2.DataTypes.STRING,
|
16
|
-
|
16
|
+
action: sequelize_2.DataTypes.STRING,
|
17
17
|
from: sequelize_2.DataTypes.STRING,
|
18
18
|
to: sequelize_2.DataTypes.STRING,
|
19
19
|
sourceChainId: sequelize_2.DataTypes.NUMBER,
|
package/dist/db/sequelize.js
CHANGED
@@ -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`,
|
package/dist/index.js
CHANGED
@@ -3,13 +3,34 @@ 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
|
-
require("module-alias
|
6
|
+
const module_alias_1 = __importDefault(require("module-alias"));
|
7
|
+
module_alias_1.default.addAliases({
|
8
|
+
"@/": __dirname + "/",
|
9
|
+
"@/logger": __dirname + "/logger",
|
10
|
+
"@/tasks": __dirname + "/tasks",
|
11
|
+
"@/utils": __dirname + "/utils",
|
12
|
+
"@/api": __dirname + "/api",
|
13
|
+
"@/net": __dirname + "/net",
|
14
|
+
"@/db": __dirname + "/db",
|
15
|
+
"@/config": __dirname + "/config",
|
16
|
+
"@/types": __dirname + "/types",
|
17
|
+
"@/abi": __dirname + "/abi",
|
18
|
+
"@/constants": __dirname + "/constants",
|
19
|
+
"@/typechain": __dirname + "/typechain"
|
20
|
+
});
|
21
|
+
(0, module_alias_1.default)();
|
7
22
|
const assert_1 = __importDefault(require("assert"));
|
8
23
|
const dotenv_1 = __importDefault(require("dotenv"));
|
9
24
|
const ethers_1 = require("ethers");
|
10
25
|
dotenv_1.default.config();
|
11
26
|
const logger_1 = __importDefault(require("@/logger"));
|
12
27
|
const logger = new logger_1.default('Process');
|
28
|
+
if (process.argv.at(-1) === 'help') {
|
29
|
+
console.log('Usage:');
|
30
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x');
|
31
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x');
|
32
|
+
process.exit(0);
|
33
|
+
}
|
13
34
|
(0, assert_1.default)(process.env.PRIVATE_KEY, "PRIVATE_KEY is not defined");
|
14
35
|
try {
|
15
36
|
new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
|
@@ -20,10 +41,12 @@ catch (e) {
|
|
20
41
|
}
|
21
42
|
const tasks_1 = require("@/tasks");
|
22
43
|
const net_1 = require("@/net");
|
44
|
+
const api_1 = require("@/api");
|
23
45
|
async function main() {
|
24
46
|
(0, net_1.startPeer)({});
|
25
47
|
const tasks = new tasks_1.Tasks();
|
26
48
|
tasks.start();
|
49
|
+
(0, api_1.startApiServer)();
|
27
50
|
}
|
28
51
|
main()
|
29
52
|
.then(() => {
|
@@ -29,7 +29,7 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
|
|
29
29
|
}
|
30
30
|
const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
|
31
31
|
const uniqueIdentifier = {
|
32
|
-
|
32
|
+
action: 'deposit',
|
33
33
|
sourceTransactionHash: event.transactionHash,
|
34
34
|
sourceChainId: sourceChainId.toNumber(),
|
35
35
|
targetChainId: targetChainId.toNumber(),
|
@@ -38,27 +38,14 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
|
|
38
38
|
continue;
|
39
39
|
}
|
40
40
|
const tx = await event.getTransaction();
|
41
|
-
await db_1.Transaction.create({
|
42
|
-
transactionHash: (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier),
|
43
|
-
type: 'deposit',
|
44
|
-
from: tx.from,
|
45
|
-
to: user,
|
46
|
-
sourceChainId: sourceChainId.toNumber(),
|
47
|
-
sourceTransactionHash: event.transactionHash,
|
48
|
-
sourceBlockNumber: event.blockNumber,
|
49
|
-
sourceStatus: "uninitialised",
|
50
|
-
targetChainId: targetChainId.toNumber(),
|
51
|
-
targetStatus: "uninitialised",
|
52
|
-
submitEvent: {
|
41
|
+
await db_1.Transaction.create(Object.assign(Object.assign({}, uniqueIdentifier), { transactionHash: (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier), from: tx.from, to: user, sourceBlockNumber: event.blockNumber, sourceStatus: "uninitialised", targetStatus: "uninitialised", submitEvent: {
|
53
42
|
user,
|
54
43
|
sourceChainId: sourceChainId.toString(),
|
55
44
|
targetChainId: targetChainId.toString(),
|
56
45
|
token: token,
|
57
46
|
ammout: amount.toString(),
|
58
47
|
vnonce: vnonce.toString(),
|
59
|
-
},
|
60
|
-
status: "pending",
|
61
|
-
});
|
48
|
+
}, status: "pending" }));
|
62
49
|
this.logger.info(`Execution queued: ${event.transactionHash} ${event.blockNumber}`);
|
63
50
|
}
|
64
51
|
catch (error) {
|
package/dist/utils/index.js
CHANGED
@@ -92,7 +92,7 @@ const asyncCallWithTimeout = async (asyncPromise, timeout) => {
|
|
92
92
|
exports.asyncCallWithTimeout = asyncCallWithTimeout;
|
93
93
|
const generateInteropTransactionHash = (data) => {
|
94
94
|
return ethers_1.ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
|
95
|
-
String(data.
|
95
|
+
String(data.action),
|
96
96
|
String(data.sourceTransactionHash),
|
97
97
|
String(data.sourceChainId),
|
98
98
|
String(data.targetChainId),
|
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.59f2858",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -32,6 +32,8 @@
|
|
32
32
|
"ethers": "^5.6.4",
|
33
33
|
"ethers-multisend": "^2.1.1",
|
34
34
|
"expand-home-dir": "^0.0.3",
|
35
|
+
"fastify": "^3.28.0",
|
36
|
+
"fastify-cors": "^6.0.3",
|
35
37
|
"libp2p": "^0.36.2",
|
36
38
|
"libp2p-bootstrap": "^0.14.0",
|
37
39
|
"libp2p-kad-dht": "^0.28.6",
|
@@ -48,7 +50,8 @@
|
|
48
50
|
"waait": "^1.0.5"
|
49
51
|
},
|
50
52
|
"bin": {
|
51
|
-
"interop-
|
53
|
+
"interop-x": "bin/interop-x",
|
54
|
+
"interopx": "bin/interop-x"
|
52
55
|
},
|
53
56
|
"devDependencies": {
|
54
57
|
"@typechain/ethers-v5": "^10.0.0",
|
@@ -62,18 +65,5 @@
|
|
62
65
|
"tsconfig-paths": "^3.12.0",
|
63
66
|
"typechain": "^8.0.0",
|
64
67
|
"typescript": "^4.5.5"
|
65
|
-
},
|
66
|
-
"_moduleAliases": {
|
67
|
-
"@/": "./dist",
|
68
|
-
"@/logger": "./dist/logger",
|
69
|
-
"@/tasks": "./dist/tasks",
|
70
|
-
"@/utils": "./dist/utils",
|
71
|
-
"@/net": "./dist/net",
|
72
|
-
"@/db": "./dist/db",
|
73
|
-
"@/config": "./dist/config",
|
74
|
-
"@/types": "./dist/types",
|
75
|
-
"@/abi": "./dist/abi",
|
76
|
-
"@/constants": "./dist/constants",
|
77
|
-
"@/typechain": "./dist/typechain"
|
78
68
|
}
|
79
69
|
}
|
package/src/api/index.ts
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
import fastify from "fastify"
|
2
|
+
import cors from 'fastify-cors'
|
3
|
+
import Logger from "@/logger"
|
4
|
+
import { Transaction } from "@/db";
|
5
|
+
|
6
|
+
const logger = new Logger("RPC");
|
7
|
+
|
8
|
+
|
9
|
+
const server = fastify({ logger: false })
|
10
|
+
|
11
|
+
server.register(cors, {})
|
12
|
+
|
13
|
+
server.get('/', async () => 'Interop X API')
|
14
|
+
|
15
|
+
export 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 Transaction.findAndCountAll({
|
21
|
+
limit: 20,
|
22
|
+
offset: 0,
|
23
|
+
})
|
24
|
+
})
|
25
|
+
|
26
|
+
await server.listen(PORT, HOST)
|
27
|
+
|
28
|
+
logger.log(`RPC Server listening at http://${HOST}:${PORT}`)
|
29
|
+
} catch (err) {
|
30
|
+
logger.error(err)
|
31
|
+
process.exit(1)
|
32
|
+
}
|
33
|
+
}
|
package/src/config/index.ts
CHANGED
@@ -7,11 +7,13 @@ class Config {
|
|
7
7
|
public readonly leadNodeAddress: string
|
8
8
|
public readonly privateKey: string
|
9
9
|
public readonly wallet: Wallet
|
10
|
+
public readonly staging: boolean
|
10
11
|
|
11
12
|
constructor() {
|
12
13
|
this.events = new EventBus() as EventBusType
|
13
14
|
this.maxPeers = 10
|
14
15
|
this.privateKey = process.env.PRIVATE_KEY as string;
|
16
|
+
this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
|
15
17
|
this.wallet = new Wallet(this.privateKey);
|
16
18
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
|
17
19
|
}
|
@@ -5,7 +5,7 @@ export class Transaction extends Model<InferAttributes<Transaction>, InferCreati
|
|
5
5
|
declare id: CreationOptional<number>;
|
6
6
|
|
7
7
|
declare transactionHash: string;
|
8
|
-
declare
|
8
|
+
declare action: string;
|
9
9
|
declare from: string;
|
10
10
|
declare to: string;
|
11
11
|
|
@@ -47,7 +47,7 @@ Transaction.init({
|
|
47
47
|
|
48
48
|
|
49
49
|
transactionHash: DataTypes.STRING,
|
50
|
-
|
50
|
+
action: DataTypes.STRING,
|
51
51
|
|
52
52
|
from: DataTypes.STRING,
|
53
53
|
to: DataTypes.STRING,
|
package/src/db/sequelize.ts
CHANGED
@@ -4,7 +4,7 @@ import expandHomeDir from "expand-home-dir";
|
|
4
4
|
|
5
5
|
import { Sequelize } from 'sequelize';
|
6
6
|
|
7
|
-
const basePath = expandHomeDir(`~/.interop-x/data/${config.publicAddress}`);
|
7
|
+
const basePath = expandHomeDir(`~/.interop-x/data/${config.publicAddress}/${config.staging ? 'staging' : ''}`);
|
8
8
|
|
9
9
|
export const sequelize = new Sequelize({
|
10
10
|
dialect: 'sqlite',
|
package/src/index.ts
CHANGED
@@ -1,4 +1,21 @@
|
|
1
|
-
import 'module-alias
|
1
|
+
import moduleAlias from 'module-alias';
|
2
|
+
|
3
|
+
moduleAlias.addAliases({
|
4
|
+
"@/": __dirname + "/",
|
5
|
+
"@/logger": __dirname + "/logger",
|
6
|
+
"@/tasks": __dirname + "/tasks",
|
7
|
+
"@/utils": __dirname + "/utils",
|
8
|
+
"@/api": __dirname + "/api",
|
9
|
+
"@/net": __dirname + "/net",
|
10
|
+
"@/db": __dirname + "/db",
|
11
|
+
"@/config": __dirname + "/config",
|
12
|
+
"@/types": __dirname + "/types",
|
13
|
+
"@/abi": __dirname + "/abi",
|
14
|
+
"@/constants": __dirname + "/constants",
|
15
|
+
"@/typechain": __dirname + "/typechain"
|
16
|
+
})
|
17
|
+
|
18
|
+
moduleAlias();
|
2
19
|
import assert from "assert";
|
3
20
|
import dotenv from "dotenv";
|
4
21
|
import { ethers } from "ethers";
|
@@ -7,6 +24,14 @@ dotenv.config();
|
|
7
24
|
import Logger from "@/logger";
|
8
25
|
const logger = new Logger('Process')
|
9
26
|
|
27
|
+
|
28
|
+
if (process.argv.at(-1) === 'help') {
|
29
|
+
console.log('Usage:')
|
30
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x')
|
31
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x')
|
32
|
+
process.exit(0)
|
33
|
+
}
|
34
|
+
|
10
35
|
assert(process.env.PRIVATE_KEY, "PRIVATE_KEY is not defined");
|
11
36
|
|
12
37
|
try {
|
@@ -18,7 +43,7 @@ try {
|
|
18
43
|
|
19
44
|
import { Tasks } from "@/tasks";
|
20
45
|
import { startPeer } from "@/net";
|
21
|
-
|
46
|
+
import { startApiServer } from '@/api';
|
22
47
|
|
23
48
|
async function main() {
|
24
49
|
|
@@ -27,6 +52,8 @@ async function main() {
|
|
27
52
|
const tasks = new Tasks()
|
28
53
|
|
29
54
|
tasks.start();
|
55
|
+
|
56
|
+
startApiServer()
|
30
57
|
}
|
31
58
|
|
32
59
|
main()
|
@@ -43,7 +43,7 @@ class SyncDepositEvents extends BaseTask {
|
|
43
43
|
const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
|
44
44
|
|
45
45
|
const uniqueIdentifier = {
|
46
|
-
|
46
|
+
action: 'deposit',
|
47
47
|
sourceTransactionHash: event.transactionHash,
|
48
48
|
sourceChainId: sourceChainId.toNumber(),
|
49
49
|
targetChainId: targetChainId.toNumber(),
|
@@ -56,17 +56,14 @@ class SyncDepositEvents extends BaseTask {
|
|
56
56
|
const tx = await event.getTransaction()
|
57
57
|
|
58
58
|
await Transaction.create({
|
59
|
+
...uniqueIdentifier,
|
59
60
|
transactionHash: generateInteropTransactionHash(uniqueIdentifier),
|
60
|
-
type: 'deposit',
|
61
61
|
from: tx.from,
|
62
62
|
to: user,
|
63
63
|
|
64
|
-
sourceChainId: sourceChainId.toNumber(),
|
65
|
-
sourceTransactionHash: event.transactionHash,
|
66
64
|
sourceBlockNumber: event.blockNumber,
|
67
65
|
sourceStatus: "uninitialised",
|
68
66
|
|
69
|
-
targetChainId: targetChainId.toNumber(),
|
70
67
|
targetStatus: "uninitialised",
|
71
68
|
|
72
69
|
submitEvent: {
|
package/src/utils/index.ts
CHANGED
@@ -119,9 +119,9 @@ export const asyncCallWithTimeout = async <T>(asyncPromise: Promise<T>, timeout:
|
|
119
119
|
}
|
120
120
|
|
121
121
|
|
122
|
-
export const generateInteropTransactionHash = (data: {
|
122
|
+
export const generateInteropTransactionHash = (data: { action: string, sourceTransactionHash: string, sourceChainId: string | number, targetChainId: string | number }) => {
|
123
123
|
return ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
|
124
|
-
String(data.
|
124
|
+
String(data.action),
|
125
125
|
String(data.sourceTransactionHash),
|
126
126
|
String(data.sourceChainId),
|
127
127
|
String(data.targetChainId),
|