Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8a16ff9
Main (#81)
franko4don Jun 26, 2025
20b21f0
worked on multiple rpc
stephenson080 Jul 10, 2025
9641cc9
fixed merge conflict
stephenson080 Jul 10, 2025
3084b21
Rpc (#82)
stephenson080 Jul 10, 2025
5408bd8
Merge branch 'staging' of github.com-work:xendfinance/assetchain-brid…
stephenson080 Jul 11, 2025
77e9b55
Merge branch 'main' of github.com-work:xendfinance/assetchain-bridge
stephenson080 Aug 5, 2025
2991bb7
polygon support
stephenson080 Aug 5, 2025
7b64fb3
polygon support (#84)
stephenson080 Aug 6, 2025
ee25c6c
use polygon rpc from env
stephenson080 Aug 8, 2025
0ff9c26
resolve conflict
stephenson080 Aug 8, 2025
05329d0
Merge branch 'main' of github.com-work:xendfinance/assetchain-bridge
stephenson080 Aug 8, 2025
d60bc4c
resolve conflict
stephenson080 Aug 8, 2025
5f3fdb4
finish wnt-restriction on arb (#88)
stephenson080 Aug 20, 2025
7af03ba
changed block number
stephenson080 Aug 22, 2025
e93baf7
resolve merge conflict
stephenson080 Aug 22, 2025
0a84609
fix wnt restriction bug
stephenson080 Aug 24, 2025
e60b16e
trying to reduce time for server response
stephenson080 Aug 26, 2025
4f25feb
fix merge conflict
stephenson080 Aug 26, 2025
80c80ae
fix bug
stephenson080 Aug 26, 2025
a3a54d8
fix bug
stephenson080 Aug 26, 2025
8933f95
fix merge conflict
stephenson080 Aug 26, 2025
2484b1d
fix merge conflict
stephenson080 Aug 26, 2025
3ecfe43
Merge branch 'main' of github.com-work:xendfinance/assetchain-bridge
stephenson080 Aug 31, 2025
56cc9ad
Merge branch 'main' into staging
stephenson080 Aug 31, 2025
ffcd022
Solana integration (#93)
stephenson080 Sep 8, 2025
bbc6727
Merge branch 'staging' of github.com-work:xendfinance/assetchain-brid…
stephenson080 Sep 21, 2025
3b9232d
support multiple solana bridges (#94)
stephenson080 Sep 22, 2025
6efefae
Merge branch 'staging' of github.com-work:xendfinance/assetchain-brid…
stephenson080 Oct 8, 2025
702a171
Redesign backend to for the bridge frontend (#95)
stephenson080 Oct 11, 2025
7aeb3ba
Merge branch 'staging' of github.com-work:xendfinance/assetchain-brid…
stephenson080 Oct 11, 2025
78d9ee6
symbol check for USDT
stephenson080 Oct 11, 2025
b7ddabd
worked on getting balance and block fromapi (#96)
stephenson080 Oct 15, 2025
7b30684
bug Fix (#97)
stephenson080 Oct 17, 2025
9e50923
bug fix
stephenson080 Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions backend-all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
"contracts": "yarn contracts:sync && yarn contracts:typings",
"contracts:sync": "SCRIPT=./src/gotbit-tools/scripts/shell/import-contracts.sh yarn script",
"contracts:typings": "node ./src/gotbit-tools/scripts/typings.js",
"typeorm": "typeorm-ts-node-commonjs",
"migration:generate": "yarn typeorm migration:generate -d src/lib/database/data-source.ts",
"migration:run": "yarn typeorm migration:run -d src/lib/database/data-source.ts",
"migration:revert": "yarn typeorm migration:revert -d src/lib/database/data-source.ts",
"migration:show": "yarn typeorm migration:show -d src/lib/database/data-source.ts",
"schema:sync": "yarn typeorm schema:sync -d src/lib/database/data-source.ts",
"schema:drop": "yarn typeorm schema:drop -d src/lib/database/data-source.ts",
"\n# UTILS SCRIPTS:": "",
"script": "chmod +x $SCRIPT && $SCRIPT",
"dev-win": "yarn build-win && concurrently \"tsc -w\" \"cross-env DEBUG=true node-dev --respawn dist/app.js\"",
Expand Down Expand Up @@ -44,8 +51,12 @@
"author": "kotsmile",
"license": "MIT",
"dependencies": {
"@coral-xyz/anchor": "^0.31.1",
"@solana/spl-token": "^0.4.13",
"@solana/web3.js": "^1.98.4",
"axios": "^0.27.2",
"body-parser": "^1.20.0",
"bs58": "^6.0.0",
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"ethers": "^5.6.6",
Expand All @@ -55,7 +66,11 @@
"helmet": "^5.0.2",
"module-alias": "^2.2.2",
"moment": "^2.29.3",
"morgan": "^1.10.0"
"morgan": "^1.10.0",
"pg": "^8.8.0",
"reflect-metadata": "^0.1.13",
"typeorm": "^0.3.12",
"winston": "^3.17.0"
},
"devDependencies": {
"@types/chai": "^4.3.3",
Expand All @@ -65,6 +80,7 @@
"@types/mocha": "^9.1.1",
"@types/morgan": "^1.9.3",
"@types/node": "^17.0.31",
"@types/pg": "^8.6.6",
"@types/supertest": "^2.0.12",
"c8": "^7.11.3",
"chai": "^4.3.6",
Expand All @@ -74,6 +90,6 @@
"node-dev": "^7.4.3",
"supertest": "^6.2.4",
"ts-jest": "^29.0.0",
"typescript": "^4.6.4"
"typescript": "^5.0.0"
}
}
52 changes: 46 additions & 6 deletions backend-all/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'reflect-metadata'
import express from 'express'
import path from 'path'

Expand All @@ -10,7 +11,9 @@ import 'module-alias/register'
import * as dotenv from 'dotenv'
dotenv.config()

import config from '@/config'
import { config } from '@/config'
import { dbConnection } from '@/lib/database'
import { isPublicRelayer } from './utils/env-var'

const app = express()

Expand All @@ -20,10 +23,47 @@ autoroutes(app, {
dir: path.join(__dirname, 'routes'),
})

if (!process.env.TEST)
app.listen(config.port, () => {
console.log(`Server started on port ${config.port}`)
console.log(`DEBUG=${process.env.DEBUG}`)
})
// Initialize database connection and start server
const startServer = async () => {
try {
// Connect to database

if (isPublicRelayer) {
await dbConnection.connect()

// Run migrations on startup (optional - you might want to run them manually)
await dbConnection.runMigrations()
}

if (!process.env.TEST) {
app.listen(config.port, () => {
console.log(`Server started on port ${config.port}`)
console.log(`DEBUG=${process.env.DEBUG}`)
console.log('Database connected successfully')
})
}
} catch (error) {
console.error('Failed to start server:', error)
process.exit(1)
}
}

// Graceful shutdown
process.on('SIGINT', async () => {
console.log('Shutting down gracefully...')


await dbConnection.disconnect()
process.exit(0)
})

process.on('SIGTERM', async () => {
console.log('Shutting down gracefully...')

await dbConnection.disconnect()
process.exit(0)
})

startServer()

export default app
14 changes: 12 additions & 2 deletions backend-all/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
export default {
console.log(process.env.DATABASE_USERNAME)
export const config = {
morganLogger:
':date[web] :method :url :status :res[content-length] - :response-time ms',
port: process.env.PORT,
}
database: {
host: process.env.DATABASE_HOST || 'localhost',
port: parseInt(process.env.DATABASE_PORT || '5432'),
username: process.env.DATABASE_USERNAME || 'postgres',
password: process.env.DATABASE_PASSWORD || 'password',
database: process.env.DATABASE_NAME || 'assetchain_bridge',
logging: process.env.DB_LOGGING === 'true',
ssl: process.env.DB_SSL === 'true',
},
};
43 changes: 23 additions & 20 deletions backend-all/src/confirmations.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{
"1": 7,
"97": 42,
"56": 42,
"137": 42,
"369": 42,
"5000": 42,
"31337": 42,
"42161": 42,
"5001": 42,
"43113": 42,
"80001": 42,
"421614": 42,
"8453": 42,
"42421": 42,
"80002": 42,
"84532": 42,
"11155111": 42,
"200810": 42,
"200901": 42,
"42420": 42
"1": 10,
"97": 10,
"56": 10,
"137": 10,
"369": 10,
"5000": 10,
"31337": 10,
"42161": 10,
"5001": 10,
"43113": 10,
"80001": 10,
"421614": 10,
"8453": 10,
"42421": 5,
"80002": 10,
"84532": 10,
"11155111": 10,
"200810": 10,
"200901": 10,
"42420": 5,
"solana": 10,
"sol.devnet": 10,
"sol.mainnet": 10
}
88 changes: 88 additions & 0 deletions backend-all/src/lib/database/connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import "reflect-metadata";
import { DataSource } from "typeorm";
import { AppDataSource } from "./data-source";
import EventLogger from "../logger/index.logger";

class DatabaseConnection {
private static instance: DatabaseConnection;
private dataSource: DataSource | null = null;

private constructor() {}

public static getInstance(): DatabaseConnection {
if (!DatabaseConnection.instance) {
DatabaseConnection.instance = new DatabaseConnection();
}
return DatabaseConnection.instance;
}

public async connect() {
try {
if (!this.dataSource) {
this.dataSource = AppDataSource;
await this.dataSource.initialize();
EventLogger.info("Database connection established successfully");
}
return this.dataSource;
} catch (error: any) {
EventLogger.error(`Error connecting to database ${error.message}`);
throw error;
}
}

public async disconnect() {
try {
if (this.dataSource && this.dataSource.isInitialized) {
await this.dataSource.destroy();
this.dataSource = null;
EventLogger.info("Database connection closed");
}
} catch (error:any) {
EventLogger.error("Error disconnecting from database:" + error.message);
throw error;
}
}

public getDataSource() {
return this.dataSource;
}

public async runMigrations() {
try {
if (!this.dataSource) {
await this.connect();
}

if (this.dataSource && this.dataSource.isInitialized) {
await this.dataSource.runMigrations();
EventLogger.info("Migrations completed successfully");
}
} catch (error:any) {
EventLogger.error("Error running migrations:" + error.message);
throw error;
}
}

public async undoLastMigration() {
try {
if (!this.dataSource) {
await this.connect();
}

if (this.dataSource && this.dataSource.isInitialized) {
await this.dataSource.undoLastMigration();
EventLogger.info("Last migration reverted successfully");
}
} catch (error:any) {
EventLogger.error("Error reverting migration:" + error.message);
throw error;
}
}

public isConnected() {
return this.dataSource ? this.dataSource.isInitialized : false;
}
}

export const dbConnection = DatabaseConnection.getInstance();
export default dbConnection;
21 changes: 21 additions & 0 deletions backend-all/src/lib/database/data-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import "reflect-metadata";
import { DataSource } from "typeorm";
import { config } from "../../config";

export const AppDataSource = new DataSource({
type: "postgres",
host: config.database.host,
port: config.database.port,
username: config.database.username,
password: config.database.password,
database: config.database.database,
synchronize: false, // Set to false when using migrations
logging: config.database.logging || false,
entities: [__dirname + "/entities/*.{ts,js}"],
migrations: [__dirname + "/migrations/*.{ts,js}"],
subscribers: [__dirname + "/subscribers/*.{ts,js}"],
migrationsTableName: "migrations",
ssl: config.database.ssl ? { rejectUnauthorized: false } : false,
});

export default AppDataSource;
12 changes: 12 additions & 0 deletions backend-all/src/lib/database/entities/BaseEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from "typeorm";

export abstract class BaseEntity {
@PrimaryGeneratedColumn("uuid")
id: string;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
14 changes: 14 additions & 0 deletions backend-all/src/lib/database/entities/BlockscanInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Entity, Column } from "typeorm";
import { BaseEntity } from "./BaseEntity";

@Entity("blockscan_infos")
export class BlockscanInfo extends BaseEntity {
@Column({ type: "text" })
lastBlockScanned: string; // Using text for very long block numbers

@Column()
chainId: string;

@Column()
contractAddress: string;
}
38 changes: 38 additions & 0 deletions backend-all/src/lib/database/entities/BridgeInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
import { BaseEntity } from "./BaseEntity";
import { Token } from "./Token";
import { Transaction } from "./Transaction";

@Entity("bridge_infos")
export class BridgeInfo extends BaseEntity {
@Column()
bridgeAddress: string;

@Column()
chainId: string;

@Column({ type: "jsonb" })
fees: {
feeFulfill: number;
feeSend: number;
};

@ManyToOne("Token", "bridgeInfos", {
onDelete: "CASCADE",
nullable: false
})
@JoinColumn({ name: "tokenId" })
token: Token;

@Column()
tokenId: string;

@Column({ type: "text" })
limitPerSend: string;

@Column()
tokenDecimal: number;

@OneToMany(() => Transaction, (transaction) => transaction.bridgeInfo)
transactions: Transaction[];
}
24 changes: 24 additions & 0 deletions backend-all/src/lib/database/entities/Token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Entity, Column, OneToMany } from "typeorm";
import { BaseEntity } from "./BaseEntity";
import { BridgeInfo } from "./BridgeInfo";

@Entity("tokens")
export class Token extends BaseEntity {
@Column()
tokenAddress: string;

@Column()
decimal: number;

@Column()
symbol: string;

@Column()
name: string;

@Column()
chainId: string;

@OneToMany("BridgeInfo", "token")
bridgeInfos: BridgeInfo[];
}
Loading
Loading