Skip to content

ReVaultron/frontend

Repository files navigation

ReVaultron Frontend

AI-Powered Autonomous Portfolio Management Dashboard on Hedera

React TypeScript Hedera shadcn/ui

🎯 Overview

ReVaultron frontend provides a comprehensive dashboard for managing AI-powered cryptocurrency portfolios on Hedera. Create vaults, configure autonomous agents, monitor real-time volatility, and track automatic rebalancing through an intuitive interface.

Key Features:

  • πŸ” MetaMask wallet integration for Hedera testnet
  • πŸ“Š Real-time portfolio monitoring with live price feeds
  • πŸ€– AI agent activity tracking and status monitoring
  • ⚑ Automated rebalancing notifications
  • πŸ’Ό Multi-token vault management
  • πŸ“ˆ Historical volatility and performance analytics

πŸ—οΈ Architecture

frontend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”‚   β”œβ”€β”€ dashboard/
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.tsx           # Main dashboard view
β”‚   β”‚   β”‚   β”œβ”€β”€ PortfolioOverview.tsx   # Value & allocation summary
β”‚   β”‚   β”‚   β”œβ”€β”€ VolatilityMonitor.tsx   # Real-time volatility display
β”‚   β”‚   β”‚   └── AllocationChart.tsx     # Visual allocation breakdown
β”‚   β”‚   β”œβ”€β”€ vault/
β”‚   β”‚   β”‚   β”œβ”€β”€ VaultCreationWizard.tsx # 4-step vault setup
β”‚   β”‚   β”‚   β”œβ”€β”€ TokenSelector.tsx       # Token selection interface
β”‚   β”‚   β”‚   β”œβ”€β”€ AllocationSlider.tsx    # Allocation percentage controls
β”‚   β”‚   β”‚   └── DepositInterface.tsx    # Deposit/withdrawal UI
β”‚   β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”‚   β”œβ”€β”€ AgentActivityFeed.tsx   # Live HCS message stream
β”‚   β”‚   β”‚   β”œβ”€β”€ AgentAuthorizationCard.tsx
β”‚   β”‚   β”‚   └── RebalancingProgress.tsx # Live rebalancing tracker
β”‚   β”‚   β”œβ”€β”€ wallet/
β”‚   β”‚   β”‚   β”œβ”€β”€ WalletConnect.tsx       # Multi-wallet connection
β”‚   β”‚   β”‚   └── AccountDisplay.tsx      # Account info display
β”‚   β”‚   └── shared/
β”‚   β”‚       β”œβ”€β”€ LoadingSpinner.tsx
β”‚   β”‚       β”œβ”€β”€ ErrorBoundary.tsx
β”‚   β”‚       └── TransactionToast.tsx
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”œβ”€β”€ useHedera.ts               # Hedera client management
β”‚   β”‚   β”œβ”€β”€ useHCS.ts                  # HCS topic subscriptions
β”‚   β”‚   β”œβ”€β”€ useVault.ts                # Vault contract interactions
β”‚   β”‚   β”œβ”€β”€ useAgents.ts               # Agent status tracking
β”‚   β”‚   └── usePortfolio.ts            # Portfolio calculations
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ hedera/
β”‚   β”‚   β”‚   β”œβ”€β”€ client.ts              # Hedera SDK wrapper
β”‚   β”‚   β”‚   β”œβ”€β”€ hcs.ts                 # HCS message handling
β”‚   β”‚   β”‚   β”œβ”€β”€ hts.ts                 # Token transfers
β”‚   β”‚   β”‚   └── contracts.ts           # Smart contract ABIs
β”‚   β”‚   β”œβ”€β”€ wallet/
β”‚   β”‚   β”‚   β”œβ”€β”€ hashpack.ts            # HashPack integration
β”‚   β”‚   β”‚   └── blade.ts               # Blade wallet integration
β”‚   β”‚   └── utils/
β”‚   β”‚       β”œβ”€β”€ formatting.ts          # Number/date formatting
β”‚   β”‚       β”œβ”€β”€ calculations.ts        # Portfolio math
β”‚   β”‚       └── constants.ts           # Contract addresses, etc.
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   β”œβ”€β”€ vault.ts                   # Vault data types
β”‚   β”‚   β”œβ”€β”€ agent.ts                   # Agent message types
β”‚   β”‚   └── portfolio.ts               # Portfolio types
β”‚   β”œβ”€β”€ stores/
β”‚   β”‚   β”œβ”€β”€ walletStore.ts             # Wallet state (Zustand)
β”‚   β”‚   β”œβ”€β”€ vaultStore.ts              # Vault state
β”‚   β”‚   └── agentStore.ts              # Agent activity state
β”‚   β”œβ”€β”€ App.tsx
β”‚   └── main.tsx
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ assets/
β”‚   β”‚   └── agent-icons/               # Agent avatars
β”‚   └── index.html
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ vite.config.ts
└── tailwind.config.js

πŸš€ Quick Start

Prerequisites

Node.js >= 18.0.0
npm >= 9.0.0
MetaMask wallet extension

Installation

# Clone the repository
git clone https://github.com/yourusername/ReVaultron-hedera
cd ReVaultron-hedera/frontend

# Install dependencies
npm install

# Copy environment template
cp .env.example .env.local

Environment Configuration

# .env.local

# Network Configuration
NEXT_PUBLIC_HEDERA_NETWORK=testnet
NEXT_PUBLIC_CHAIN_ID=296                       # Hedera Testnet EVM chain ID

# Contract Addresses (Deployed on Hedera Testnet)
NEXT_PUBLIC_VAULT_FACTORY_ADDRESS=0x...
NEXT_PUBLIC_VOLATILITY_INDEX_ADDRESS=0x...
NEXT_PUBLIC_REBALANCE_EXECUTOR_ADDRESS=0x...

# Agent System (Local development)
NEXT_PUBLIC_AGENT_BASE_URL=http://localhost    # Agent server base URL

# Pyth Network Configuration
NEXT_PUBLIC_PYTH_CONTRACT=0x...
NEXT_PUBLIC_PYTH_PRICE_FEED_HBAR=0x...

Development

# Start development server
npm run dev

# Open browser at http://localhost:3000

Build for Production

# Create optimized production build
npm run build

# Start production server
npm start

πŸ”Œ Core Features

1. Wallet Connection

MetaMask Integration for Hedera Testnet:

// Hedera Testnet Configuration
const HEDERA_TESTNET = {
  chainId: '0x128', // 296 in decimal
  chainName: 'Hedera Testnet',
  rpcUrls: ['https://testnet.hashio.io/api'],
  nativeCurrency: {
    name: 'HBAR',
    symbol: 'HBAR',
    decimals: 18,
  },
  blockExplorerUrls: ['https://hashscan.io/testnet'],
};

Key Features:

  • Automatic network detection and switching
  • Custom network addition to MetaMask
  • Account balance display in HBAR
  • Transaction signing and confirmation

2. Vault Management

Create and manage autonomous vaults:

  • Token selection (HBAR, USDC, ERC20)
  • Allocation percentage controls
  • Volatility threshold configuration
  • Deposit and withdrawal interfaces
  • Real-time balance tracking

3. AI Agent Monitoring

Track autonomous agent activities:

  • Volatility Advisor: AI-powered market analysis
  • Volatility Updater: On-chain volatility updates
  • Allocation Strategist: Portfolio optimization
  • Rebalance Checker: Portfolio drift detection
  • Rebalance Executor: Automatic rebalancing

Real-time status updates via polling (10s intervals) or WebSocket connections.

4. Price Feeds

Pyth Network Integration:

  • Real-time HBAR/USD price feeds
  • Confidence intervals
  • Price history tracking
  • Volatility calculations

🎨 Key Components

Dashboard Widgets

Portfolio Overview

<MetricCard
  title="Total Deposited"
  value="$2,200"
  change={2.5}
  icon={DollarSign}
/>

Volatility Monitor

<VolatilityMonitor
  threshold={30}
  priceFeedId={PYTH_HBAR_USD}
/>

Agent Activity Feed

<AgentActivityFeed />

Vault Components

Deposit/Withdraw Modals

<HBARDepositModal
  open={open}
  onOpenChange={setOpen}
  vaultAddress={vaultAddress}
/>

<HBARWithdrawModal
  open={open}
  onOpenChange={setOpen}
  vaultAddress={vaultAddress}
/>

Token Operations

<ERC20DepositModal
  vaultAddress={vaultAddress}
  tokenAddress={tokenAddress}
/>

πŸ“Š Data Flow

Wallet Connection Flow

User clicks "Connect Wallet"
    ↓
Frontend checks for MetaMask
    ↓
Request network switch to Hedera Testnet
    ↓
User approves connection
    ↓
Frontend receives wallet address
    ↓
Check for existing vault
    ↓
Load dashboard with vault data

Agent Monitoring Flow

Dashboard loads
    ↓
Start polling agent status endpoints (every 10s)
    ↓
Agent executes task
    ↓
Agent stores result in backend
    ↓
Frontend fetches updated status
    ↓
Extract latest result data
    ↓
Generate activity for feed
    ↓
Update UI with new information

Rebalancing Flow

Volatility Updater runs (every 30s)
    ↓
Calls Volatility Advisor for AI recommendation
    ↓
Updates on-chain volatility
    ↓
Rebalance Checker detects drift > 5%
    ↓
Calls Allocation Strategist for target allocation
    ↓
Triggers Rebalance Executor
    ↓
Executes swap on SaucerSwap
    ↓
Frontend displays completion notification

πŸ”§ Configuration

Tailwind Configuration

// tailwind.config.js
export default {
  darkMode: ['class'],
  content: ['./src/**/*.{ts,tsx}'],
  theme: {
    extend: {
      colors: {
        border: 'hsl(var(--border))',
        primary: 'hsl(var(--primary))',
        // ... shadcn/ui color system
      },
    },
  },
  plugins: [require('tailwindcss-animate')],
};

Next.js Configuration

// next.config.js
const nextConfig = {
  reactStrictMode: true,
  webpack: (config) => {
    config.resolve.fallback = {
      ...config.resolve.fallback,
      fs: false,
      net: false,
      tls: false,
    };
    return config;
  },
};

πŸ“¦ Core Dependencies

{
  "dependencies": {
    "next": "^14.1.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "wagmi": "^2.5.0",
    "viem": "^2.7.0",
    "@tanstack/react-query": "^5.22.0",
    "recharts": "^2.12.0",
    "lucide-react": "^0.263.1",
    "date-fns": "^3.3.1",
    "clsx": "^2.1.0",
    "tailwind-merge": "^2.2.1"
  },
  "devDependencies": {
    "@types/react": "^18.2.55",
    "typescript": "^5.3.3",
    "tailwindcss": "^3.4.1",
    "eslint": "^8.56.0",
    "prettier": "^3.2.5"
  }
}

πŸ› Troubleshooting

Common Issues

MetaMask Not Detecting Hedera Network

Solution:

  1. Open MetaMask
  2. Go to Settings β†’ Networks β†’ Add Network
  3. Enter Hedera Testnet details:
    • Network Name: Hedera Testnet
    • RPC URL: https://testnet.hashio.io/api
    • Chain ID: 296
    • Currency Symbol: HBAR

Agent Data Not Updating

Solution:

  1. Verify agent servers are running (npm start in agents directory)
  2. Check agent endpoints return data: curl http://localhost:4001/status
  3. Verify CORS is enabled for your frontend URL
  4. Check browser console for network errors

Transaction Fails with "Insufficient Funds"

Solution:

  1. Ensure wallet has sufficient HBAR for gas fees (~0.1 HBAR minimum)
  2. Check vault has tokens for withdrawal operations
  3. Verify token associations are complete

Price Feed Not Loading

Solution:

  1. Verify Pyth contract address in environment variables
  2. Check price feed ID is correct
  3. Test Pyth endpoint: curl https://hermes.pyth.network/v2/updates/price/latest?ids[]=0x...

🚒 Deployment

Vercel (Recommended)

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel --prod

# Configure environment variables in Vercel dashboard

Build Settings

  • Build Command: npm run build
  • Output Directory: .next
  • Install Command: npm install

πŸ” Security Best Practices

  1. Never store private keys - All transactions use MetaMask signer
  2. Validate all inputs - Amount validation, address checks
  3. Verify contract addresses - Hardcoded in environment variables
  4. Rate limit API calls - Prevent abuse of backend endpoints
  5. Sanitize user inputs - Prevent XSS attacks

πŸ“š Resources

Documentation

Hedera Tools


🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“ License

MIT License - see LICENSE file for details.


Built with ❀️ for the Hedera ecosystem

Releases

No releases published

Packages

 
 
 

Contributors

Languages