Skip to content

deegalabs/cronos-shield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

288 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ Cronos Shield

AI-powered security layer for Cronos blockchain

Cronos Shield is a comprehensive security and monetization platform for AI agents operating on the Cronos blockchain. It provides real-time risk analysis, protected vaults, CEX-DEX price validation, and full observability of AI decision-making processes.

πŸ“‹ Table of Contents

🎯 Overview

Cronos Shield addresses the critical need for security and transparency when AI agents interact with blockchain protocols. It provides:

  • Risk Oracle: Real-time risk scoring for smart contracts with cryptographic proof
  • Shielded Vaults: Protected vaults with programmable circuit breakers
  • CEX-DEX Synergy: Price divergence detection between centralized and decentralized exchanges
  • Observability Dashboard: Complete visibility into AI decision-making processes

All services are monetized using the x402 payment protocol, enabling native internet micropayments for AI services.

✨ Features

πŸ” Risk Oracle

  • Real-time risk scoring (0-100 scale)
  • Cryptographic Proof of Risk signatures
  • On-chain verification support
  • Liquidity and contract safety analysis
  • x402 payment-protected API

🏦 Shielded Vaults

  • Protected deposits with risk-based transaction blocking
  • Programmable circuit breakers
  • Integration with Risk Oracle
  • Emergency withdrawal capabilities

πŸ“ˆ CEX-DEX Synergy

  • Real-time price divergence detection
  • Arbitrage opportunity identification
  • Risk-based transaction blocking
  • Integration with Crypto.com Exchange and VVS Finance

πŸ“Š Observability Dashboard

  • Real-time metrics and KPIs
  • Decision log with human-readable translations
  • Blocked transactions tracking
  • Complete audit trail

πŸ—οΈ Architecture

cronos-shield/
β”œβ”€β”€ backend/          # Unified Express.js API
β”œβ”€β”€ frontend/         # React + Vite + Tailwind CSS
β”œβ”€β”€ contracts/        # Solidity smart contracts
β”œβ”€β”€ ai/               # ML/AI models (preview)
β”œβ”€β”€ clients/          # Test clients
└── docs/             # Documentation

Technology Stack

  • Backend: Node.js, TypeScript, Express.js
  • Frontend: React, TypeScript, Vite, Tailwind CSS
  • Blockchain: Solidity, Hardhat, Ethers.js
  • Payment: x402 Protocol, @crypto.com/facilitator-client
  • Network: Cronos EVM (Testnet/Mainnet)

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm/pnpm
  • MetaMask or compatible wallet
  • Cronos Testnet configured in wallet
  • devUSDC.e tokens for x402 payments

1. Clone and Install

cd cronos-shield
pnpm install

2. Backend Setup

cd backend
cp .env.example .env
# Edit .env with your configuration
pnpm install
pnpm dev

3. Frontend Setup

cd frontend
cp .env.example .env
pnpm install
pnpm dev

4. Access

πŸ“ Project Structure

cronos-shield/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/     # Request handlers
β”‚   β”‚   β”œβ”€β”€ services/        # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ risk/        # Risk Oracle service
β”‚   β”‚   β”‚   β”œβ”€β”€ divergence/  # CEX-DEX service
β”‚   β”‚   β”‚   └── observability/ # Logging & metrics
β”‚   β”‚   β”œβ”€β”€ routes/          # API routes
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”œβ”€β”€ x402/        # x402 payment middleware
β”‚   β”‚   β”‚   └── utils/       # Utilities
β”‚   β”‚   └── types/           # TypeScript types
β”‚   └── package.json
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/      # React components
β”‚   β”‚   β”‚   β”œβ”€β”€ dashboard/   # Observability components
β”‚   β”‚   β”‚   β”œβ”€β”€ risk/        # Risk Oracle UI
β”‚   β”‚   β”‚   β”œβ”€β”€ divergence/  # CEX-DEX UI
β”‚   β”‚   β”‚   └── common/      # Shared components
β”‚   β”‚   β”œβ”€β”€ pages/           # Page components
β”‚   β”‚   β”œβ”€β”€ lib/             # Utilities (API, wallet)
β”‚   β”‚   β”œβ”€β”€ hooks/           # React hooks
β”‚   β”‚   └── types/           # TypeScript types
β”‚   └── package.json
β”‚
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ contracts/           # Solidity contracts
β”‚   β”œβ”€β”€ scripts/            # Deployment scripts
β”‚   β”œβ”€β”€ test/               # Contract tests
β”‚   └── hardhat.config.ts
β”‚
└── docs/                   # Additional documentation

πŸ“š API Documentation

For Developers

πŸ‘‰ Complete Developer Documentation

Includes:

  • Quick start guide
  • x402 payment flow
  • Complete API reference
  • SDK integration examples
  • Error handling
  • Best practices

Base URL

Production: https://cronos-shield-backend-production.up.railway.app
Local:      http://localhost:3000/api

Interactive Documentation

Endpoints

Risk Oracle

  • GET /risk/risk-analysis?contract=0x... - Analyze contract risk (x402)
  • POST /risk/pay - Settle x402 payment

CEX-DEX Synergy

  • GET /divergence/divergence?token=CRO - Analyze price divergence (x402)
  • POST /divergence/pay - Settle x402 payment

Observability

  • GET /observability/metrics - Get system metrics
  • GET /observability/logs - Get decision logs
  • POST /observability/logs - Add log entry
  • GET /observability/blocked-transactions - Get blocked transactions

API Documentation

Full API documentation is available at:

πŸ” Smart Contracts

RiskOracle.sol

Stores and verifies risk analysis results on-chain.

Functions:

  • storeResult() - Store risk analysis result
  • verifyProof() - Verify Proof of Risk signature
  • getResult() - Retrieve stored result

ShieldedVault.sol

Protected vault with risk-based transaction blocking.

Functions:

  • deposit() - Deposit native tokens
  • withdraw() - Withdraw tokens
  • executeWithRiskCheck() - Execute transaction with risk validation

πŸ› οΈ Development

Backend Development

cd backend
pnpm dev          # Development server with hot reload
pnpm build        # Build for production
pnpm start        # Run production build

Frontend Development

cd frontend
pnpm dev          # Development server
pnpm build        # Build for production
pnpm preview      # Preview production build

Smart Contract Development

cd contracts
pnpm compile      # Compile contracts
pnpm test         # Run tests
pnpm deploy       # Deploy to network

πŸ“ Environment Variables

Backend (.env)

NODE_ENV=development
PORT=3000
NETWORK=cronos-testnet
RPC_URL=https://evm-t3.cronos.org
CHAIN_ID=338
MERCHANT_ADDRESS=0x...
PRIVATE_KEY=0x...
PRICE_BASE_UNITS=1000000
RISK_ORACLE_CONTRACT_ADDRESS=0x...
DEX_ROUTER_ADDRESS=0x...

# CEX-DEX Integration (Optional - uses mock data if not set)
CRYPTO_COM_API_URL=https://api.crypto.com/v2
CRYPTO_COM_API_KEY=your_api_key_here
CRO_TOKEN_ADDRESS=0x...  # Optional: override token addresses
USDC_TOKEN_ADDRESS=0x...
USDT_TOKEN_ADDRESS=0x...

FRONTEND_URL=http://localhost:5173

Note: For production setup, see Production Guide

Frontend (.env)

VITE_BACKEND_URL=http://localhost:3000
VITE_NETWORK=cronos-testnet
VITE_RPC_URL=https://evm-t3.cronos.org
VITE_CHAIN_ID=338

πŸ§ͺ Testing

Backend Tests

cd backend
pnpm test

Frontend Tests

cd frontend
pnpm test

Smart Contract Tests

cd contracts
pnpm test

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Commit Convention

We follow Conventional Commits:

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation changes
  • style: Code style changes
  • refactor: Code refactoring
  • test: Test changes
  • chore: Build process or auxiliary tool changes

πŸ“„ License

MIT License - see LICENSE file for details

πŸ”— Links

πŸ‘₯ Team

Built for the Cronos x402 Paytech Hackathon


Note: This is a Proof of Concept (POC) implementation. For production use, additional security audits and optimizations are recommended.

About

Cronos Shield is a comprehensive security and monetization platform for AI agents operating on the Cronos blockchain. It provides real-time risk analysis, protected vaults, CEX-DEX price validation, and full observability of AI decision-making processes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors