F
FTH Protocol
Institutional Staking
Launch App
Architecture

FTH Protocol Architecture

A system-level overview of the protocol’s layers: UI, API gateway, services, contracts, and the Substrate runtime.

Source: docs/architecture/overview.md
Section
System Overview

FTH Protocol is an institutional-grade stablecoin staking platform built on a custom Substrate-based Layer-1 blockchain. It enables users to stake FTH stablecoins and earn yield from Real World Asset (RWA) investments while maintaining GENIUS Act compliance.

Section
High-Level Architecture
┌─────────────────────────────────────────────────────────────────┐
│                         Frontend Layer                           │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐         │
│  │  Next.js UI  │  │   Wallet     │  │  Analytics   │         │
│  │  Dashboard   │  │  Integration │  │  Dashboard   │         │
│  └──────────────┘  └──────────────┘  └──────────────┘         │
└─────────────────────────────────────────────────────────────────┘
                              │
                    HTTPS/WebSocket
                              │
┌─────────────────────────────────────────────────────────────────┐
│                      API Gateway Layer                           │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐         │
│  │   REST API   │  │  WebSocket   │  │ Rate Limiter │         │
│  │  (Actix-web) │  │   Server     │  │  & Security  │         │
│  └──────────────┘  └──────────────┘  └──────────────┘         │
└─────────────────────────────────────────────────────────────────┘
                              │
┌─────────────────────────────────────────────────────────────────┐
│                      Business Logic Layer                        │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐         │
│  │   Staking    │  │RWA Management│  │  Compliance  │         │
│  │   Service    │  │   Service    │  │   Engine     │         │
│  └──────────────┘  └──────────────┘  └──────────────┘         │
└─────────────────────────────────────────────────────────────────┘
                              │
┌─────────────────────────────────────────────────────────────────┐
│                    Smart Contract Layer                          │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐         │
│  │FTH Stablecoin│  │  stFTH Token │  │  RWA Vault   │         │
│  │   (ink!)     │  │   (ink!)     │  │   (ink!)     │         │
│  └──────────────┘  └──────────────┘  └──────────────┘         │
└─────────────────────────────────────────────────────────────────┘
                              │
┌─────────────────────────────────────────────────────────────────┐
│              Substrate Layer-1 Blockchain                        │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐         │
│  │    Custom    │  │   Consensus  │  │   P2P        │         │
│  │    Runtime   │  │ GRANDPA+BABE │  │   Network    │         │
│  │  (Pallets)   │  │              │  │              │         │
│  └──────────────┘  └──────────────┘  └──────────────┘         │
└─────────────────────────────────────────────────────────────────┘
Section
Layer Breakdown

1. Frontend Layer (Next.js 14)

Purpose: User interface for interacting with the platform

Components:

  • Staking Dashboard: Main interface for staking/unstaking
  • Wallet Integration: Connect via Polkadot.js, MetaMask
  • Analytics: Real-time charts and statistics
  • RWA Portfolio: View current RWA investments
  • Transaction History: Browse past transactions

Technology Stack:

  • Next.js 14 (App Router)
  • TypeScript
  • TailwindCSS
  • Recharts for data visualization
  • Polkadot.js API for blockchain interaction
  • Zustand for state management

Key Features:

  • Server-side rendering (SSR)
  • Real-time WebSocket updates
  • Responsive design
  • Dark mode support
  • Wallet connection abstraction

2. API Gateway Layer (Rust/Actix-web)

Purpose: RESTful API and WebSocket server for client communication

Components:

  • REST API Server: HTTP endpoints for queries and transactions
  • WebSocket Server: Real-time event streaming
  • Rate Limiter: DDoS protection and abuse prevention
  • Authentication: JWT-based auth (optional for premium features)

Endpoints:

GET  /api/v1/health
POST /api/v1/staking
POST /api/v1/staking/unstake
GET  /api/v1/staking/my-stakes
GET  /api/v1/staking/stats
GET  /api/v1/rwa/investments
GET  /api/v1/analytics/tvl

Technology Stack:

  • Actix-web 4 (async web framework)
  • SQLx (database queries)
  • Redis (caching)
  • Serde (serialization)

3. Business Logic Layer (Rust Services)

Purpose: Core application logic and orchestration

Services:

Staking Service

  • Validates stake amounts
  • Calculates receipt tokens
  • Manages unstaking cooldowns
  • Tracks user positions

RWA Management Service

  • Monitors RWA investments
  • Calculates yield accruals
  • Triggers yield distributions
  • Updates APY rates

Compliance Engine

  • KYC/AML verification
  • Whitelist/blacklist management
  • Transaction monitoring
  • Regulatory reporting

Technology Stack:

  • Rust async/await
  • Tokio runtime
  • PostgreSQL for persistence
  • Redis for caching

4. Smart Contract Layer (ink!)

Purpose: On-chain logic for token operations and governance

Contracts:

FTH Stablecoin Contract

pub struct FthStablecoin {
    total_supply: Balance,
    balances: Mapping<AccountId, Balance>,
    // ERC-20 functionality
    // Compliance features (pause, whitelist, blacklist)
}

Functions:

  • transfer() - Transfer FTH tokens
  • mint() - Mint new tokens (governance only)
  • burn() - Burn tokens
  • pause() - Emergency pause
  • whitelist() - Compliance management

stFTH Receipt Token Contract

pub struct StFthToken {
    receipt_balances: Mapping<AccountId, Balance>,
    exchange_rate: u32,  // Rebases over time
    // Rebase mechanism for yield distribution
}

Functions:

  • mint_receipt() - Issue stFTH when staking
  • burn_receipt() - Burn stFTH when unstaking
  • rebase() - Update exchange rate
  • get_value() - Calculate current FTH value

RWA Vault Contract

pub struct RwaVault {
    investments: Vec<Investment>,
    total_yield: Balance,
    // Manages RWA portfolio
}

Functions:

  • add_investment() - Record new RWA
  • distribute_yield() - Trigger yield distribution
  • get_apy() - Calculate current APY

Technology Stack:

  • ink! 5.0 (Substrate smart contracts)
  • cargo-contract (build tool)

5. Substrate Blockchain Layer

Purpose: Custom Layer-1 blockchain infrastructure

Custom Pallets:

Staking Pallet

#[pallet]
pub mod pallet_staking {
    // Manages on-chain staking logic
    pub fn stake(amount: Balance) -> DispatchResult
    pub fn initiate_unstaking() -> DispatchResult
    pub fn unstake() -> DispatchResult
}

Storage:

  • Stakes<AccountId, StakeInfo>
  • TotalStaked
  • ExchangeRate

RWA Pallet

#[pallet]
pub mod pallet_rwa {
    // Manages RWA investments on-chain
    pub fn create_investment(...) -> DispatchResult
    pub fn distribute_yield() -> DispatchResult
}

Storage:

  • Investments<InvestmentId, Investment>
  • CurrentAPY
  • TotalYieldGenerated

Consensus:

  • GRANDPA: Finality gadget
  • BABE: Block production
  • 6-second block time
  • Byzantine fault tolerance

Technology Stack:

  • Substrate 10.x
  • FRAME (Framework for Runtime Aggregation of Modularized Entities)
  • Rust
Section
Data Flow

Staking Flow

1. User clicks "Stake 1000 FTH"
      ↓
2. Frontend → API: POST /api/v1/staking
      ↓
3. API → Staking Service: validate_stake(1000)
      ↓
4. Service → Blockchain: pallet_staking::stake(1000)
      ↓
5. Blockchain: Execute stake extrinsic
   - Lock 1000 FTH
   - Calculate receipt tokens
   - Mint stFTH
   - Update exchange rate
      ↓
6. Blockchain → API: Event emitted
      ↓
7. API → Frontend: WebSocket notification
      ↓
8. Frontend: Update UI with new stake

Yield Distribution Flow

1. Cron job triggers (daily)
      ↓
2. RWA Service: calculate_accrued_yield()
   - Query all active RWA investments
   - Calculate yield since last distribution
      ↓
3. Service → Blockchain: pallet_rwa::distribute_yield()
      ↓
4. Blockchain: Execute yield distribution
   - Calculate new exchange rate
   - Update staking pallet
   - Rebase stFTH tokens
      ↓
5. Blockchain → WebSocket: YieldDistributed event
      ↓
6. All connected clients receive update
      ↓
7. Frontend: Display new APY and balances
Section
Database Schema

PostgreSQL Tables

-- Users
CREATE TABLE users (
    id UUID PRIMARY KEY,
    address VARCHAR(64) UNIQUE NOT NULL,
    created_at TIMESTAMP DEFAULT NOW()
);

-- Stakes
CREATE TABLE stakes (
    id UUID PRIMARY KEY,
    user_id UUID REFERENCES users(id),
    amount NUMERIC(38, 18) NOT NULL,
    receipt_tokens NUMERIC(38, 18) NOT NULL,
    staked_at TIMESTAMP NOT NULL,
    unstaking_at TIMESTAMP,
    status VARCHAR(20) NOT NULL,  -- 'active', 'unstaking', 'completed'
    created_at TIMESTAMP DEFAULT NOW()
);

-- RWA Investments
CREATE TABLE rwa_investments (
    id SERIAL PRIMARY KEY,
    investment_type VARCHAR(50) NOT NULL,
    principal NUMERIC(38, 18) NOT NULL,
    current_value NUMERIC(38, 18) NOT NULL,
    yield_rate_bps INTEGER NOT NULL,
    invested_at TIMESTAMP NOT NULL,
    matures_at TIMESTAMP NOT NULL,
    is_active BOOLEAN DEFAULT true
);

-- Transactions
CREATE TABLE transactions (
    id UUID PRIMARY KEY,
    user_id UUID REFERENCES users(id),
    tx_hash VARCHAR(66) UNIQUE NOT NULL,
    tx_type VARCHAR(20) NOT NULL,  -- 'stake', 'unstake', 'claim'
    amount NUMERIC(38, 18) NOT NULL,
    status VARCHAR(20) NOT NULL,   -- 'pending', 'confirmed', 'failed'
    created_at TIMESTAMP DEFAULT NOW()
);

-- Yield History
CREATE TABLE yield_distributions (
    id SERIAL PRIMARY KEY,
    amount NUMERIC(38, 18) NOT NULL,
    exchange_rate INTEGER NOT NULL,
    apy_bps INTEGER NOT NULL,
    distributed_at TIMESTAMP NOT NULL
);
Section
Security Architecture

Multi-Layer Security

  1. Smart Contract Layer

    • Audited ink! contracts
    • Reentrancy guards
    • Access control (owner, minter roles)
    • Pausable functionality
  2. Blockchain Layer

    • Byzantine fault tolerant consensus
    • Finality gadget (GRANDPA)
    • Network security via P2P encryption
  3. API Layer

    • Rate limiting (60 req/min)
    • JWT authentication
    • CORS policies
    • Input validation
  4. Infrastructure Layer

    • DDoS protection
    • SSL/TLS encryption
    • Firewall rules
    • Intrusion detection

Compliance Features

  • KYC Integration: Optional user verification
  • Transaction Monitoring: Suspicious activity detection
  • Audit Logging: Immutable transaction history
  • Reporting: Automated regulatory reports
Section
Scalability

Horizontal Scaling

  • API Servers: Load-balanced instances
  • Database: Read replicas
  • Blockchain Nodes: Multiple validator nodes

Performance Optimizations

  • Caching: Redis for frequently accessed data
  • Database Indexing: Optimized queries
  • WebSocket Pooling: Efficient real-time updates
  • CDN: Static asset delivery

Capacity

  • TPS: 1,000+ transactions per second
  • Stakers: Support for 100,000+ concurrent stakers
  • Storage: Scalable blockchain storage
  • API: 10,000+ requests per second
Section
Monitoring & Observability

Metrics Collection

  • Prometheus: Metrics aggregation
  • Grafana: Visualization dashboards
  • Jaeger: Distributed tracing

Key Metrics

  • Total Value Locked (TVL)
  • Active stakers
  • APY rate
  • Transaction volume
  • System health indicators
  • RWA portfolio performance

Alerting

  • High error rates
  • Low liquidity
  • Abnormal transaction patterns
  • System resource limits
Section
Deployment Architecture

Development Environment

docker-compose up

Production Environment

Kubernetes Cluster:
- API Pods (3 replicas)
- Blockchain Nodes (5 validators)
- Database (Primary + 2 Replicas)
- Redis Cluster (3 nodes)
- Monitoring Stack
Section
Technology Choices
LayerTechnologyReason
BlockchainSubstrateProduction-ready, modular, upgradeable
Smart Contractsink!Native Substrate, efficient, safe
BackendRust/Actix-webPerformance, safety, async support
FrontendNext.js 14SEO, SSR, React ecosystem
DatabasePostgreSQLACID, mature, reliable
CacheRedisFast, versatile, persistence
MonitoringPrometheus/GrafanaIndustry standard, powerful
Section
Future Enhancements
  1. Layer 2 Scaling: Add optimistic rollup for higher TPS
  2. Cross-Chain Bridges: Enable multi-chain staking
  3. Mobile Apps: Native iOS/Android applications
  4. Advanced RWA: Integration with DeFi protocols
  5. DAO Governance: Decentralized decision-making

Version: 1.0.0
Last Updated: January 2026
Architecture Team: Future Tech Holdings