Skip to content

LightLLM/R_Oracle

Repository files navigation

R-Oracle: Resilient Multi-Source Oracle Chain

CI License Rust Node

A resilient multi-source oracle chain built on Polkadot, providing reliable price data through multiple data sources with automatic failover mechanisms.

🎯 What is R-Oracle?

R-Oracle is a Substrate-based parachain that implements a resilient oracle system with:

  • Multi-Source Data: Fetches data from multiple oracle providers (Binance, Coinbase, Kraken)
  • Automatic Failover: Seamlessly switches between sources on failure
  • RPC Resilience: Dual RPC endpoints with health checks
  • On-Chain Storage: Stores oracle values and history on-chain
  • Modern Frontend: Next.js dashboard for monitoring and interaction

πŸ›‘οΈ Why is it Resilient?

R-Oracle implements multiple layers of resilience:

  1. Oracle Source Failover: Primary (Binance) β†’ Fallback 1 (Coinbase) β†’ Fallback 2 (Kraken)
  2. RPC Failover: Primary (Polkadot Cloud) β†’ Fallback (OnFinality)
  3. Data Validation: Runtime-level validation ensures data integrity
  4. Transaction Retry: Automatic retry logic for transient failures

See docs/RESILIENCE.md for detailed information.

πŸ—οΈ Architecture

Frontend (Next.js) β†’ RPC Layer (with Failover) β†’ Parachain (Substrate) β†’ Oracle APIs (with Failover)

See docs/ARCHITECTURE.md for detailed architecture.

πŸ“‹ Prerequisites

  • Rust: Latest stable version (install via rustup.rs)
  • Node.js: v18 or higher
  • Docker: For containerized deployment (optional)
  • Polkadot.js Extension: For wallet integration

πŸš€ Quick Start

1. Build the Chain

# Clone the repository
git clone <repository-url>
cd R_Oracle

# Build the node
cargo build --release

# Or use the build script
chmod +x scripts/build.sh
./scripts/build.sh

2. Run the Chain Locally

# Run in development mode
./target/release/r-oracle-node --dev

# Or with custom chain spec
./target/release/r-oracle-node --chain=dev --alice

The node will start and you can interact with it via:

  • RPC: ws://127.0.0.1:9944
  • HTTP RPC: http://127.0.0.1:9933

3. Run the Frontend

cd frontend

# Install dependencies
npm install

# Run development server
npm run dev

The frontend will be available at http://localhost:3000

4. Connect Wallet

  1. Install Polkadot.js Extension
  2. Create or import an account
  3. Connect to the R-Oracle chain in the frontend

πŸ“¦ Deployment

Polkadot Cloud Deployment

1. Build Chain Specification

chmod +x scripts/build-chain-spec.sh
./scripts/build-chain-spec.sh

This generates:

  • chain-specs/r-oracle-dev.json - Human-readable chain spec
  • chain-specs/r-oracle-dev-raw.json - Raw chain spec for deployment

2. Build Docker Image

docker build -t r-oracle-node:latest .

3. Deploy to Polkadot Cloud

  1. Create a new project in Polkadot Cloud
  2. Upload the Docker image
  3. Configure chain spec (use raw chain spec)
  4. Set environment variables:
    • CHAIN=chain-specs/r-oracle-dev-raw.json
    • RPC_PORT=9933
    • WS_PORT=9944
    • P2P_PORT=30333

4. Update Frontend RPC

Update frontend/src/lib/api.ts with your deployed RPC endpoint:

const PRIMARY_RPC = 'wss://your-deployed-endpoint.com';

Local Docker Deployment

# Build and run
docker build -t r-oracle-node .
docker run -p 9933:9933 -p 9944:9944 -p 30333:30333 r-oracle-node --dev

πŸ”§ Configuration

Chain Configuration

Edit node/src/chain_spec.rs to customize:

  • Parachain ID
  • Initial validators
  • Genesis accounts
  • Token properties

Frontend Configuration

Environment variables (.env.local):

NEXT_PUBLIC_PRIMARY_RPC=wss://your-primary-rpc.com
NEXT_PUBLIC_FALLBACK_RPC=wss://your-fallback-rpc.com

πŸ“š Documentation

πŸ§ͺ Testing

Pallet Tests

# Run all pallet tests
cargo test -p pallet-roracle

# Run with output
cargo test -p pallet-roracle -- --nocapture

# Run specific test
cargo test -p pallet-roracle test_submit_oracle_value_success

Frontend Tests

cd frontend

# Run all tests
npm test

# Run in watch mode
npm run test:watch

# Run with coverage
npm run test:coverage

See TESTING.md for detailed testing documentation.

🎯 Judging Criteria Alignment

Technical Implementation

  • βœ… Substrate/Polkadot SDK: Built on Substrate with custom pallet
  • βœ… Parachain Development: Full parachain implementation
  • βœ… Custom Pallet: pallet-roracle with storage, extrinsics, and events
  • βœ… Runtime Integration: Properly integrated into runtime

Innovation

  • βœ… Resilience: Multi-layer failover mechanisms
  • βœ… Oracle System: Multi-source oracle with automatic failover
  • βœ… RPC Resilience: Dual RPC endpoints with health checks

User Experience

  • βœ… Frontend: Modern Next.js dashboard
  • βœ… Visualization: Charts and timeline for failover events
  • βœ… Error Handling: Clear error messages and recovery

Documentation

  • βœ… README: Comprehensive setup and usage instructions
  • βœ… Architecture Docs: Detailed system documentation
  • βœ… Deployment Guide: Polkadot Cloud deployment instructions

Code Quality

  • βœ… Structure: Well-organized codebase
  • βœ… Comments: Code documentation
  • βœ… Best Practices: Follows Substrate/Polkadot conventions

🀝 Contributing

Contributions are welcome! Please:

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

πŸ“„ License

This project is licensed under the Unlicense - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

For issues and questions:

  • Open an issue on GitHub
  • Check the documentation in /docs
  • Review the code comments

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

πŸ“„ License

This project is licensed under the Unlicense - see the LICENSE file for details.

πŸ™ Acknowledgments


Built for the Polkadot Hackathon πŸš€

About

This is Polkadot repository for the hackathon

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •