Skip to content

kevinfaveri/Monrail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

77 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Monrail ๐Ÿš„

The Fastest & Simplest USDC Bridge - Bridge USDC between Solana and Base with a beautiful neon-themed UI. Powered by Circle's CCTP for trustless, secure transfers.

๐ŸŒŸ Features

Bridging

  • Trustless USDC Bridge: Powered by Circle Bridge Kit (CCTP)
  • Two-Way Bridge: Solana โ†” Base
  • Beautiful UI Flow:
    1. Connect both Solana and Base wallets
    2. Select source and destination chains
    3. Enter USDC amount to bridge
    4. If no USDC โ†’ Embedded Jupiter widget to swap
    5. Bridge with signature on source chain
    6. Animated plane loading screen
    7. Claim with signature on destination chain
    8. Success! View transaction on explorer

Points & Leaderboard

  • Earn Points: Get points for every bridge transaction
  • Volume-Based: More USDC bridged = more points
  • Transaction Bonus: 10 points per transaction
  • Multipliers:
    • 1.5x for volumes > $1,000
    • 2x for volumes > $10,000
  • Leaderboard: Compete with other users
  • Track Progress: See your total volume and transaction count

Backend Tracking

  • Automatic Fee Tracking: Monitors fee addresses on both chains
  • Transaction Recording: Captures all bridge transactions
  • Points Calculation: Automatic points updates
  • Transaction History: Full history per wallet

๐Ÿ—๏ธ Architecture

packitupgg/
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ backend/              # Hono + Prisma API
โ”‚   โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ api/          # REST API routes
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ services/     # Balance & Points services
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ jobs/         # Fee listener jobs
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ config/       # Chain configurations
โ”‚   โ”‚   โ””โ”€โ”€ prisma/
โ”‚   โ”‚       โ””โ”€โ”€ schema.prisma # Database schema
โ”‚   โ””โ”€โ”€ frontend/             # React + Vite + Circle Bridge Kit
โ”‚       โ”œโ”€โ”€ src/
โ”‚       โ”‚   โ”œโ”€โ”€ components/   # BridgeUI, Providers, UI components
โ”‚       โ”‚   โ”œโ”€โ”€ lib/          # API client, wagmi config
โ”‚       โ”‚   โ””โ”€โ”€ pages/        # Application pages
โ”‚       โ””โ”€โ”€ package.json
โ”œโ”€โ”€ docker-compose.yml        # PostgreSQL database
โ””โ”€โ”€ .env.example

๐Ÿ“ฆ Tech Stack

Backend

  • Runtime: Bun
  • Framework: Hono (fast HTTP server)
  • Database: PostgreSQL + Prisma ORM
  • Blockchain:
    • Solana: @solana/web3.js + @solana/spl-token
    • Base: viem (Ethereum client)
  • Bridge: Circle Bridge Kit
  • Jobs: Custom fee listeners for both chains

Frontend

  • Framework: React 19
  • Build Tool: Vite
  • Styling: Tailwind CSS + shadcn/ui
  • Animations: Framer Motion
  • Wallets:
    • Solana: @solana/wallet-adapter (Phantom, Solflare)
    • Base: wagmi + viem (MetaMask, WalletConnect)
  • Bridge: @circle-fin/bridge-kit
  • Swaps: Jupiter widget embedded

๐Ÿš€ Getting Started

Prerequisites

  • Bun >= 1.0.0 (install)
  • Docker & Docker Compose (for PostgreSQL)
  • WalletConnect Project ID (get one)
  • Fee Addresses: Create Solana and Base wallets for receiving fees

Installation

  1. Clone and install:
cd packitupgg
bun install
  1. Start PostgreSQL:
docker compose up -d
  1. Configure environment:
# Root .env (backend)
cp .env.example .env
# Edit .env:
# - Set DATABASE_URL (if different from default)
# - Set SOLANA_FEE_ADDRESS (your Solana wallet for fees)
# - Set BASE_FEE_ADDRESS (your Base wallet for fees)
# - Optionally set custom RPC URLs

# Frontend .env
cp packages/frontend/.env.example packages/frontend/.env
# Edit packages/frontend/.env:
# - Set VITE_WALLETCONNECT_PROJECT_ID
  1. Setup database:
cd packages/backend
bun run db:push
# Creates all tables: Transaction, Points, FeeAddress
  1. Start backend:
cd packages/backend
bun run dev
# Runs on http://localhost:3001
# Automatically starts fee listeners
  1. Start frontend:
cd packages/frontend
bun run dev
# Runs on http://localhost:5173
  1. Open browser: http://localhost:5173

๐ŸŽฎ Usage

Bridging Flow

  1. Connect Wallets

    • Connect Solana wallet (Phantom or Solflare)
    • Connect Base wallet (MetaMask or WalletConnect)
    • Both required for bridging
  2. Select Chains

    • Choose source chain (Base or Solana)
    • Choose destination chain (Solana or Base)
    • Swap button to reverse direction
  3. Enter Amount

    • See your current USDC balance
    • Enter amount to bridge
    • If insufficient balance โ†’ Jupiter widget appears
  4. Get USDC (if needed)

    • Embedded Jupiter widget
    • Swap any token to USDC
    • Click "I have USDC now" when done
  5. Bridge

    • Review amount and destination
    • Click "Bridge"
    • Sign with source wallet
    • Watch the plane animation โœˆ๏ธ
  6. Claim

    • Notification when USDC arrives
    • Sign with destination wallet
    • USDC deposited to your wallet
  7. Success

    • View transaction on explorer
    • See your points earned
    • Bridge again or view leaderboard

Earning Points

Points are calculated using this formula:

Base: 1 point per $1 USDC
Bonus: 10 points per transaction
Multiplier: 1.5x if volume > $1,000
Multiplier: 2x if volume > $10,000

Example:

  • Bridge $500 โ†’ 500 + 10 = 510 points
  • Bridge $1,500 โ†’ (1500 + 10) ร— 1.5 = 2,265 points
  • Bridge $15,000 โ†’ (15000 + 10) ร— 2 = 30,020 points

๐Ÿ”Œ API Reference

Backend Endpoints

GET /balance/:chain/:address

Get USDC balance for a wallet.

Example:

curl http://localhost:3001/balance/solana/YourSolanaAddress
curl http://localhost:3001/balance/base/0xYourBaseAddress

Response:

{
  "chain": "solana",
  "address": "...",
  "balance": "123.45",
  "decimals": 6,
  "token": "USDC"
}

GET /points/:address

Get points for a wallet.

Response:

{
  "walletAddress": "...",
  "totalPoints": 5420,
  "totalVolume": "5000.00",
  "totalTxCount": 12,
  "solanaVolume": "3000.00",
  "solanaTxCount": 7,
  "baseVolume": "2000.00",
  "baseTxCount": 5
}

GET /leaderboard?limit=100

Get top users by points.

Response:

{
  "leaderboard": [
    {
      "rank": 1,
      "walletAddress": "...",
      "totalPoints": 50000,
      "totalVolume": "45000.00",
      "totalTxCount": 100
    }
  ]
}

GET /bridge/status/:txHash

Get bridge transaction status.

Response:

{
  "id": "...",
  "status": "completed",
  "sourceChain": "base",
  "destinationChain": "solana",
  "amount": "100.00",
  "fee": "0.10",
  "sourceTxHash": "0x...",
  "claimTxHash": "...",
  "initiatedAt": "...",
  "completedAt": "..."
}

GET /transactions/:address?limit=50

Get transaction history for a wallet.

๐Ÿ› ๏ธ Development

Database Schema

Transaction Table

Tracks all bridge transactions:

  • Source/destination chains
  • Wallet addresses
  • Amounts and fees
  • Transaction hashes
  • Status tracking
  • Timestamps for each stage

Points Table

Tracks user points:

  • Wallet address
  • Total points
  • Total volume
  • Transaction counts
  • Per-chain breakdown

FeeAddress Table

Configuration for fee addresses:

  • Chain identifier
  • Fee address
  • Last processed block
  • Active status

Fee Listeners

Two background jobs monitor fee addresses:

Solana Listener (packages/backend/src/jobs/fee-listener.ts):

  • Polls Solana RPC every 5 seconds
  • Watches for USDC transfers to fee address
  • Extracts transaction details
  • Creates database records
  • Updates user points

Base Listener:

  • Polls Base RPC every 10 seconds
  • Watches for USDC Transfer events
  • Extracts transaction details
  • Creates database records
  • Updates user points

Points Calculation

Points service (packages/backend/src/services/points.ts):

  • calculatePoints(volume, txCount): Formula implementation
  • updateUserPoints(wallet, chain, amount): Update after transaction
  • getUserPoints(wallet): Get points for display
  • getLeaderboard(limit): Get top users

Adding a New Chain

  1. Update packages/backend/src/config/chains.ts:
mynewchain: {
  name: 'My New Chain',
  rpcUrl: process.env.MYNEWCHAIN_RPC_URL,
  usdcAddress: '0x...',
  decimals: 6,
  feeAddress: process.env.MYNEWCHAIN_FEE_ADDRESS,
}
  1. Add balance adapter in packages/backend/src/services/balance.ts

  2. Add fee listener in packages/backend/src/jobs/fee-listener.ts

  3. Update frontend chain selector in BridgeUI.tsx

  4. Ensure Circle CCTP supports the chain

๐Ÿšข Production Deployment

Environment Variables

Required:

  • DATABASE_URL: PostgreSQL connection string
  • SOLANA_FEE_ADDRESS: Solana wallet for fees
  • BASE_FEE_ADDRESS: Base wallet for fees

Optional:

  • SOLANA_RPC_URL: Custom Solana RPC (default: public)
  • BASE_RPC_URL: Custom Base RPC (default: public)
  • ENABLE_FEE_LISTENERS: Set to false to disable (default: true)
  • CORS_ORIGINS: Comma-separated allowed origins

Building

# Build backend
cd packages/backend
bun run build

# Build frontend
cd packages/frontend
bun run build

Docker Deployment

# Production compose file (create docker-compose.prod.yml)
docker-compose -f docker-compose.prod.yml up -d

๐Ÿ”’ Security

Trust Model

  • Fully Trustless: Circle Bridge Kit handles all bridging
  • No Custody: Backend never holds user funds
  • Client-Side Signing: All transactions signed in user wallets
  • Fee Transparency: Fee addresses are public and verifiable

Best Practices

  • Never commit .env files
  • Use separate fee wallets (don't use main wallets)
  • Monitor fee addresses regularly
  • Set up alerts for unusual activity
  • Use hardware wallets for fee address control
  • Regularly rotate database credentials

Fee Address Security

The fee addresses are used to:

  1. Track transactions (by monitoring incoming fees)
  2. Calculate points for users
  3. Record transaction volume

Important: These addresses receive small fees. Ensure:

  • Private keys are securely stored
  • Access is restricted
  • Regular monitoring is in place

๐Ÿ› Troubleshooting

"Both wallets must be connected"

  • Connect both Solana AND Base wallets
  • Required for bridging in both directions

"Insufficient balance"

  • Use the Jupiter widget to swap to USDC
  • Check you're on the correct chain

"Transaction failed"

  • Check wallet for pending transactions
  • Ensure sufficient gas (SOL or ETH)
  • Verify USDC approval (for Base transactions)

"Fee listeners not working"

  • Check .env file has correct fee addresses
  • Verify database connection
  • Check backend logs for errors
  • Ensure RPC URLs are accessible

"Points not updating"

  • Fee listeners must be running
  • Check that fees were sent to correct addresses
  • Verify transaction appears in /transactions/:address
  • Check backend logs for fee listener errors

๐Ÿ“œ License

MIT

๐Ÿ™ Acknowledgments

  • Circle for Bridge Kit and CCTP
  • Jupiter for excellent DEX aggregation
  • Solana & Base for the ecosystems
  • shadcn/ui for beautiful components
  • Framer Motion for smooth animations

Built with โค๏ธ for cross-chain DeFi

Pack it up, ship it out, earn points! โœจ๐Ÿš€

About

<15 second cross chain bridge full stack app (bridge to Monad)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published