Skip to content

Commit

Permalink
Merge pull request #35 from sotatek-dev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Sotatek-TanHoang authored Sep 9, 2024
2 parents 6200579 + b9cbee6 commit 5339a89
Show file tree
Hide file tree
Showing 54 changed files with 1,126 additions and 721 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/auto-deploy-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: 16.15.0
node-version: 18.15.0
- run: |
echo "${{ vars.MINA_BRIDGE_BE_DEV }}" >> .env
docker-compose -p mina-bridge-dev-env up -d
yarn
yarn prebuild
yarn build
yarn migration:run
npx pm2 reload ecosystem.config.js
docker build . -t mina-bridge:1.0.0
docker compose -f docker-compose.dev.yaml up -d
10 changes: 3 additions & 7 deletions .github/workflows/auto-deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ run-name: ${{ github.actor }} is deploying test branch [test] 🌏 🚀 🛰️
on:
push:
branches:
- "test"
- "testing"
jobs:
DeployTest:
runs-on: [self-hosted, mina-bridge-test]
Expand All @@ -14,9 +14,5 @@ jobs:
node-version: 16.15.0
- run: |
echo "${{ vars.MINA_BRIDGE_BE_TEST }}" >> .env
docker-compose -p mina-bridge-test-env up -d
yarn
yarn prebuild
yarn build
yarn migration:run
npx pm2 reload ecosystem.config.js
docker build . -t mina-bridge:1.0.0
docker compose -f docker-compose.dev.yaml up -d
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ postgresData

#Docker mounted volumes
/dumpData/*
.scannerwork/*
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM 590183806579.dkr.ecr.eu-north-1.amazonaws.com/node18-alpine:latest as build
FROM node:18-alpine As build
WORKDIR /app

COPY package*.json yarn.lock ./
RUN yarn
COPY . .
RUN yarn build

FROM 590183806579.dkr.ecr.eu-north-1.amazonaws.com/node18-alpine:latest
FROM node:18-alpine
WORKDIR /app
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
Expand All @@ -17,4 +17,4 @@ COPY --from=build /app/tsconfig.build.json ./tsconfig.build.json
# RUN apk --no-cache add curl
EXPOSE 3000

#CMD ["sh", "-c", "yarn start"]
#CMD ["sh", "-c", "yarn start"]
105 changes: 105 additions & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
services:
api:
image: mina-bridge:1.0.0
command: >
sh -c "npm run migration:run-dist && npm run start:prod;"
tty: true
restart: always
ports:
- ${PORT}:${PORT}
depends_on:
- postgres
networks:
- myNetwork
user: node
crawl-bridge-evm:
image: mina-bridge:1.0.0
command: >
sh -c "npm run console crawl-eth-bridge-contract"
tty: true
restart: always

depends_on:
- postgres
networks:
- myNetwork
user: node
sender-evm:
image: mina-bridge:1.0.0
command: >
sh -c "npm run console sender-eth-bridge-unlock"
tty: true
restart: always

depends_on:
- postgres
networks:
- myNetwork
user: node
crawl-bridge-mina:
image: mina-bridge:1.0.0
command: >
sh -c "npm run console crawl-mina-bridge-contract"
tty: true
restart: always

depends_on:
- postgres
networks:
- myNetwork
user: node
crawl-token-mina:
image: mina-bridge:1.0.0
command: >
sh -c "npm run console crawl-mina-token-contract"
tty: true
restart: always

depends_on:
- postgres
networks:
- myNetwork
user: node
sender-mina:
image: mina-bridge:1.0.0
command: >
sh -c "npm run console sender-mina-bridge-unlock"
tty: true
restart: always
depends_on:
- postgres
networks:
- myNetwork
user: node
get-price-token:
image: mina-bridge:1.0.0
command: >
sh -c "npm run console get-price-token"
tty: true
restart: always
depends_on:
- postgres
networks:
- myNetwork
user: node
postgres:
container_name: mina-bridge-${NODE_ENV}-postgres
image: postgres:15.3-alpine3.18
ports:
- ${DB_PORT}:${DB_PORT}
volumes:
- postgresData:/var/lib/postgresql/data
command: -p ${DB_PORT}
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mina-bridge
networks:
myNetwork:


volumes:
postgresData:
networks:
myNetwork:
name: minaBridgeNetwork${NODE_ENV}
18 changes: 8 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"migration:create": "ts-node -r tsconfig-paths/register src/database/migration-runner.ts",
"migration:run": "npm run typeorm -- -d src/database/data-source.ts migration:run",
"migration:run-dist": "npm run typeorm -- -d dist/database/data-source.js migration:run",
"migration:run:js": "node ./node_modules/typeorm/cli.js -d dist/database/data-source.js migration:run",
"migration:revert": "npm run typeorm -- -d src/database/data-source.ts migration:revert",
"seed:run": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-extension/bin/cli.cjs seed:run -d src/database/data-source.ts",
"seed:run": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-extension/bin/cli.cjs seed:run -d dist/database/data-source.js",
"console:dev": "ts-node -r tsconfig-paths/register src/console.ts",
"console": "node dist/console.js"
},
Expand Down Expand Up @@ -70,7 +71,7 @@
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/node": "^20.16.5",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Injectable } from '@nestjs/common';
export class AppService {
getApiVersion() {
return {
version: 'API V1.0.0',
version: 'v1.0.0',
};
}
}
34 changes: 34 additions & 0 deletions src/config/common.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ConfigService } from '@nestjs/config';

import { ENetworkName } from '@constants/blockchain.constant';
import { EEnvKey } from '@constants/env.constant';

import { RpcFactory } from '@shared/modules/web3/web3.module';
import { ETHBridgeContract } from '@shared/modules/web3/web3.service';

async function createRpcService(configService: ConfigService) {
return await RpcFactory(configService);
}

async function createRpcEthService(configService: ConfigService) {
return await RpcFactory(configService, ENetworkName.ETH);
}
function getEthBridgeAddress(configService: ConfigService) {
return configService.get<string>(EEnvKey.ETH_BRIDGE_CONTRACT_ADDRESS);
}

function getEthBridgeStartBlock(configService: ConfigService) {
return +configService.get<number>(EEnvKey.ETH_BRIDGE_START_BLOCK);
}

async function initializeEthContract(configService: ConfigService) {
const [rpcEthService, address, _startBlock] = await Promise.all([
createRpcEthService(configService),
getEthBridgeAddress(configService),
getEthBridgeStartBlock(configService),
]);

// Instantiate the ETHBridgeContract with the resolved dependencies
return new ETHBridgeContract(rpcEthService, address, _startBlock);
}
export { createRpcService, createRpcEthService, getEthBridgeAddress, getEthBridgeStartBlock, initializeEthContract };
8 changes: 5 additions & 3 deletions src/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { isNumber } from 'class-validator';
import * as Joi from 'joi';

import { EEnvKey } from '@constants/env.constant';
import { EEnvironments, EEnvKey } from '@constants/env.constant';

import redisConfig from './redis.config';

Expand All @@ -13,7 +13,9 @@ import redisConfig from './redis.config';
ConfigModule.forRoot({
isGlobal: true,
validationSchema: Joi.object({
[EEnvKey.NODE_ENV]: Joi.string().valid('local', 'dev', 'test', 'uat', 'production').default('dev'),
[EEnvKey.NODE_ENV]: Joi.string()
.valid(...Object.values(EEnvironments))
.default(EEnvironments.DEV),
[EEnvKey.PORT]: Joi.number().default(3000),
[EEnvKey.TZ]: Joi.string().default('UTC'),
[EEnvKey.GLOBAL_PREFIX]: Joi.string(),
Expand Down Expand Up @@ -55,7 +57,7 @@ import redisConfig from './redis.config';
value[EEnvKey.ETH_BRIDGE_START_BLOCK] = isNumber(value[EEnvKey.ETH_BRIDGE_START_BLOCK])
? value[EEnvKey.ETH_BRIDGE_START_BLOCK]
: Number.MAX_SAFE_INTEGER;
value[EEnvKey.MINA_BRIDGE_START_BLOCK] = value[EEnvKey.MINA_BRIDGE_START_BLOCK];
value[EEnvKey.MINA_BRIDGE_START_BLOCK] = Number(value[EEnvKey.MINA_BRIDGE_START_BLOCK]).valueOf();
value[EEnvKey.MINA_BRIDGE_RPC_OPTIONS] = value[EEnvKey.MINA_BRIDGE_RPC_OPTIONS].split(',');
value[EEnvKey.ETH_BRIDGE_RPC_OPTIONS] = value[EEnvKey.ETH_BRIDGE_RPC_OPTIONS].split(',');
value[EEnvKey.SIGNER_PRIVATE_KEY] = value[EEnvKey.SIGNER_PRIVATE_KEY].split(',');
Expand Down
16 changes: 16 additions & 0 deletions src/constants/api.constant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
export const COMMOM_CONFIG_TIP = 0.5;
export const COMMON__CONFIG_DAILY_QUOTA = 500;

export enum EDirection {
ASC = 'ASC',
DESC = 'DESC',
}

export enum ERole {
MINA_ADMIN = 'Mina Admin',
EVM_ADMIN = 'EVM Admin',
}

export enum EAsset {
ETH = 'ETH',
MINA = 'MINA',
WETH = 'WETH',
}

export const JWT_TOKEN_EXPIRE_DURATION = '1d';
8 changes: 7 additions & 1 deletion src/constants/blockchain.constant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const DEFAULT_DECIMAL_PLACES = 6;

export const DEFAULT_ADDRESS_PREFIX = '0x';
export const DECIMAL_BASE = 10;
export enum ENetworkName {
ETH = 'eth',
MINA = 'mina',
Expand All @@ -22,3 +23,8 @@ export enum ETokenPairStatus {
ENABLE = 'enable',
DISABLE = 'disable',
}

export enum EMinaChainEnviroment {
TESTNET = 'testnet',
MAINNET = 'mainnet',
}
8 changes: 8 additions & 0 deletions src/constants/env.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ export enum EEnvKey {
COINMARKET_URL = 'COINMARKET_URL',
BASE_MINA_BRIDGE_FEE = 'BASE_MINA_BRIDGE_FEE',
}

export enum EEnvironments {
LOCAL = 'local',
DEV = 'dev',
TEST = 'test',
UAT = 'uat',
PRODUCTION = 'production',
}
5 changes: 1 addition & 4 deletions src/constants/service.constant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export const RPC_SERVICE_INJECT = 'RPC_SERVICE';
export const RPC_ETH_SERVICE_INJECT = 'RPC_ETH_SERVICE';
export const ETH_BRIDGE_ADDRESS_INJECT = 'ETH_BRIDGE_ADDRESS_INJECT';
export const ETH_BRIDGE_START_BLOCK_INJECT = 'ETH_BRIDGE_START_BLOCK_INJECT';
export const ASYNC_CONNECTION = 'ASYNC_CONNECTION';
9 changes: 5 additions & 4 deletions src/core/base-repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Repository, SelectQueryBuilder } from 'typeorm';

import { EDirection } from '@constants/api.constant';
import { ETableName } from '@constants/entity.constant';

import { IPagination } from '@shared/interfaces/pagination.interface';
Expand Down Expand Up @@ -30,8 +31,8 @@ export abstract class BaseRepository<E> extends Repository<E> {
queryBuilder.skip((data.page - 1) * data.limit);
}
if (data.sortBy) {
if (!selections || (selections && selections.includes(`${this.alias}.${data.sortBy}`))) {
queryBuilder.orderBy(`${this.alias}.${data.sortBy}`, data.direction || 'ASC');
if (!selections || selections?.includes(`${this.alias}.${data.sortBy}`)) {
queryBuilder.orderBy(`${this.alias}.${data.sortBy}`, data.direction || EDirection.ASC);
}
}
return queryBuilder;
Expand All @@ -55,8 +56,8 @@ export abstract class BaseRepository<E> extends Repository<E> {
}

if (data.sortBy) {
if (!selections || (selections && selections.includes(`${this.alias}.${data.sortBy}`))) {
queryBuilder.orderBy(`${this.alias}.${data.sortBy}`, data.direction || 'ASC');
if (!selections || selections?.includes(`${this.alias}.${data.sortBy}`)) {
queryBuilder.orderBy(`${this.alias}.${data.sortBy}`, data.direction || EDirection.ASC);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/database/migrations/1702277564741-event_logs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MigrationInterface, QueryRunner, Table } from 'typeorm';

import { EEventName, EEventStatus, ENetworkName } from '@constants/blockchain.constant';
import { EEventName, EEventStatus } from '@constants/blockchain.constant';

export class EventLogs1702277564741 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
Expand Down
Loading

0 comments on commit 5339a89

Please sign in to comment.