Skip to content

elohcrypto/Vanguard

Repository files navigation

Vanguard RWA StableCoin - ERC-3643 Compliant Digital Currency

Overview

This project implements a production-ready Vanguard RWA StableCoin (VSC) system with comprehensive compliance management integrated with ERC-3643 standard and OnchainID (ERC-734/ERC-735). The system provides:

  • Real-time compliance validation through oracle networks
  • Dynamic whitelist/blacklist management with 2/3 consensus
  • Zero-knowledge privacy features (5 Circom circuits)
  • Complete token lifecycle management with audit trails
  • Investor type differentiation (4 types: Normal, Retail, Accredited, Institutional)
  • Democratic governance (1 Person = 1 Vote with VGT voting fees)
  • Enhanced escrow system (2-of-3 multisig with dispute resolution)
  • Payment protocol with multi-type refunds
  • 89 interactive demo options for complete system testing

Current Status: ✅ PRODUCTION READY - All 11 core requirements fully implemented

🏗️ Project Structure

Vanguard/
├── contracts/                    # Smart Contract Implementation 
│   ├── onchain_id/              # OnchainID contracts (ERC-734/735)
│   ├── erc3643/                 # ERC-3643 T-REX contracts
│   ├── oracle/                  # Oracle management contracts
│   ├── compliance/              # ComplianceRules engine
│   ├── privacy/                 # ZK verification contracts
│   ├── investor/                # Investor type management
│   ├── governance/              # Governance system (1 Person = 1 Vote)
│   ├── payment/                 # Payment protocol with refunds
│   ├── migrations/              # Contract migration scripts
│   ├── upgradeable/             # Upgradeable contract patterns
│   └── test/                    # Test contracts and helpers
├── circuits/                    # Zero-Knowledge Circuits 
│   ├── whitelist_membership.circom          # Whitelist membership proof
│   ├── blacklist_membership.circom          # Blacklist membership proof
│   ├── jurisdiction_proof.circom            # Jurisdiction compliance proof
│   ├── accreditation_proof.circom           # Accreditation status proof
│   ├── compliance_aggregation.circom        # Aggregated compliance proof
│   └── compliance_aggregation_fixed.circom  # Fixed aggregation circuit
├── demo/                        # Interactive Demo System 
│   ├── core/                    # Core demo functionality
│   ├── modules/                 # Demo modules (89 menu options)
│   ├── logging/                 # Demo logging utilities
│   ├── utils/                   # Demo helper utilities
│   └── index.js                 # Main demo entry point
├── scripts/                     # Deployment & Utility Scripts
│   ├── production/              # Production deployment scripts
│   ├── deploy-*.ts              # Contract deployment scripts
│   ├── test-*.js                # Testing and validation scripts
│   ├── generate-*.js            # ZK proof generation scripts
│   └── setup-*.js               # Setup and configuration scripts
├── test/                        # Comprehensive Test Suite
│   ├── circuits/                # ZK circuit tests
│   ├── compliance/              # Compliance system tests
│   ├── erc3643/                 # ERC-3643 token tests
│   ├── investor/                # Investor type system tests
│   ├── onchain_id/              # OnchainID tests
│   ├── oracle/                  # Oracle system tests
│   ├── privacy/                 # Privacy/ZK tests
│   ├── integration/             # Integration tests
│   ├── production/              # Production readiness tests
│   └── *.test.ts                # Individual test files
├── docs/                        # Comprehensive Documentation
│   ├── SYSTEM_OVERVIEW.md                      # System architecture overview
│   ├── NEW_FAIR_VOTING_SYSTEM.md               # Fair voting implementation
│   ├── INVESTOR_TYPE_SYSTEM.md                 # Investor type documentation
│   ├── PAYMENT_PROTOCOL_DESIGN.md              # Payment protocol docs
│   ├── SYSTEM_WORKFLOW_GUIDE.md                # User workflows and interactions
│   ├── TECHNICAL_DEEP_DIVE.md                  # In-depth technical analysis
│   ├── VANGUARD_RWA_TOKEN_ECOSYSTEM_GUIDE.md   # Complete ecosystem guide
│   ├── VOTING_SYSTEM_DIAGRAM.md                # Voting system visualization
│   ├── WORKFLOW_IMPLEMENTATION_SUMMARY.md      # Implementation workflow summary
│   ├── WORKING_DEMOS.md                        # Verified working demos guide
│   └── ZK_CIRCUIT_BUILD_GUIDE.md               # Zero-knowledge circuit build guide
├── utils/                       # Utility Functions
│   ├── merkle-tree-builder.js   # Merkle tree construction
│   └── proof-formatter.js       # ZK proof formatting
├── typechain-types/             # TypeScript contract types
├── hardhat.config.ts            # Hardhat configuration
├── tsconfig.json                # TypeScript configuration
├── foundry.toml                 # Foundry configuration
└── package.json                 # Project dependencies

✅ Implementation Status

Core System

  1. ✅ OnchainID System (ERC-734/735) - Blockchain identity management
  2. ✅ ERC-3643 System - Compliant security token
  3. ✅ Oracle System - Consensus-based access control
  4. ✅ ComplianceRules Engine - Multi-layer validation
  5. ✅ Privacy System - 5 ZK circuits for privacy-preserving compliance

Investor Management

  1. ✅ Investor Type System - 4 types with differentiated limits
  2. ✅ Transfer Limits - Type-specific transfer and holding limits
  3. ✅ Whitelist Tiers - Required tiers per investor type
  4. ✅ Large Transfer Detection - Compliance officer notifications

Payment Protocol

  1. ✅ VanguardPaymentProtocol - Escrow-based payment system
  2. ✅ PaymentEscrow - Secure fund holding
  3. ✅ RefundManager - Multi-type refunds (Automatic/Manual/Dispute/Emergency)
  4. ✅ Payment State Management - Complete payment lifecycle

Governance & Escrow

  1. ✅ VanguardGovernance - 1 Person = 1 Vote governance
  2. ✅ GovernanceToken (VGT) - ERC-3643 compliant voting fee token
  3. ✅ Enhanced Escrow - 2-of-3 multisig with dispute resolution
  4. ✅ EscrowWalletFactory - One-time-use escrow wallets

Interactive Demo System

  1. ✅ 83 Menu Options - Complete workflow coverage
  2. ✅ End-to-End Testing - All systems integrated
  3. ✅ User-Friendly Interface - Step-by-step guided workflows

📚 Documentation

System Overview & Architecture

Governance & Voting System

Investor & Payment Systems

Workflow & Implementation Guides

🛠️ Quick Start

Prerequisites

  • Node.js 18+
  • Hardhat
  • Circom (for ZK circuits)
  • snarkjs (for ZK proof generation)

Installation

# 1. Clone the repository
git clone <repository-url>
cd ERC-3643

# 2. Install dependencies
npm install

# 3. Compile contracts
npx hardhat compile

# 4. Compile ZK circuits (optional - pre-compiled artifacts included)

npm run setup:zk             # Setup ZK circuits (one-time)


### Available NPM Scripts

**Core Development** (Most Used):
```bash
npm run compile              # Compile smart contracts
npm run test                 # Run all tests
npm run node                 # Start local Hardhat node
npm run clean                # Clean build artifacts
npm run demo:interactive:proof  # Run main interactive demo (89 options)

Testing & Analysis:

npm run test        # Run tests with coverage report

Running the Interactive Demo

# 1. Start Hardhat node in one terminal
npm run node

# 2. Run the interactive demo in another terminal
npm run demo:interactive:proof

The interactive demo provides 89 menu options covering:

  • User onboarding (KYC/AML verification)
  • Token minting and transfers
  • Oracle access control (whitelist/blacklist)
  • Privacy & ZK verification
  • Token burning with quotas
  • Investor type management
  • Enhanced escrow with dispute resolution
  • Payment protocol with refunds
  • Governance (1 Person = 1 Vote)
  • Dynamic governance cost management (NEW!)
  • Complete system integration

Running Tests

# Run all tests
npx hardhat test

# Run specific test file
npx hardhat test test/VanguardGovernance.test.ts

# Run with gas reporting
REPORT_GAS=true npx hardhat test

# Run with coverage
npx hardhat coverage

🎯 Key Features

1. Identity & Compliance

  • OnchainID (ERC-734/735): Blockchain-based identity with key and claim management
  • ERC-3643 T-REX: Compliant security token standard
  • KYC/AML Verification: Trusted claim issuers for identity verification
  • ComplianceRules Engine: Multi-layer validation (jurisdiction, investor type, holding period)

2. Oracle Access Control

  • Dynamic Whitelist: 5-tier whitelist with oracle consensus (2/3 threshold)
  • Real-time Blacklist: 4-severity blacklist with emergency override
  • Oracle Consensus: M-of-N consensus mechanism with reputation scoring
  • Fallback Mechanisms: Graceful degradation on oracle failures

3. Privacy & Zero-Knowledge

  • 5 ZK Circuits: Whitelist, blacklist, jurisdiction, accreditation, compliance aggregation
  • Groth16 Proofs: Privacy-preserving compliance validation
  • Selective Disclosure: Prove compliance without revealing personal data
  • Complete Integration: ZK proofs integrated with existing compliance systems

4. Investor Type Management

  • 4 Investor Types: Normal (0), Retail (1), Accredited (2), Institutional (3)
  • Type-Specific Limits: Transfer limits (8K/50K/500K VSC), Holding limits (50K/500K/5M VSC)
  • Whitelist Tiers: Required tiers per investor type (1/2/3/4)
  • Transfer Cooldowns: Type-specific cooldowns (60/60/30/15 minutes)

5. Governance System

  • 1 Person = 1 Vote: Equal voting power for all verified users
  • VGT Voting Fees: 1,000 VGT proposal creation, 10 VGT per vote
  • Token Burning: Passed proposals burn tokens, failed proposals return them
  • ≥51% Approval: Simple majority threshold for proposal passage
  • KYC/AML Required: Only verified users can participate in governance

6. Enhanced Escrow System

  • 2-of-3 Multisig: Investor MUST sign + (Payer OR Payee)
  • One-Time-Use Wallets: Unique escrow wallet per payment
  • Dispute Resolution: 14-day dispute window with investor mediation
  • Fee Distribution: Auto-distribution (3% investor, 2% owner)
  • Shipment Proof: Proof submission with dispute mechanism

7. Payment Protocol

  • Escrow-Based Payments: VanguardPaymentProtocol with state management
  • Multi-Type Refunds: Automatic/Manual/Dispute/Emergency refunds
  • Payment Escrow: Secure fund holding with fee management
  • Compliance Integration: Full integration with ComplianceRules and IdentityRegistry

8. Token Lifecycle Management

  • Issuer-Only Minting: Exclusive minting authority with economic rationale
  • Quota-Based Burning: Daily/weekly/monthly quotas with consistency checks
  • Supply Management: Complete supply tracking with audit trails
  • Compliance Validation: All operations validated through ComplianceRules

🔒 Security

Smart Contract Security

  • Access Control: Role-based access control for all critical functions
  • Reentrancy Protection: ReentrancyGuard on all state-changing functions
  • Input Validation: Comprehensive validation of all inputs
  • Safe Math: Built-in overflow protection (Solidity 0.8+)

Oracle Security

  • M-of-N Consensus: 2/3 oracle consensus required for list updates
  • Reputation Management: Oracle scoring and reputation tracking
  • Emergency Override: Emergency blacklist for immediate threat response
  • Fallback Mechanisms: Graceful degradation on oracle failures

Privacy & Compliance

  • Zero-Knowledge Proofs: Privacy-preserving compliance validation
  • Selective Disclosure: Prove compliance without revealing personal data
  • Audit Trail: Immutable compliance event logging
  • KYC/AML Verification: Trusted claim issuers for identity verification

Governance Security

  • Sybil Resistance: KYC/AML required for all governance participants
  • Proposer Restriction: Proposers cannot vote on their own proposals
  • Token Locking: Voting fees locked during voting period
  • Equal Voting Power: 1 Person = 1 Vote prevents whale domination

📊 System Architecture

Smart Contract Layers

┌─────────────────────────────────────────────────────────────────┐
│                    VANGUARD RWA STABLECOIN SYSTEM               │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐           │
│  │  OnchainID   │  │ ERC-3643     │  │ Oracle       │           │
│  │  (Identity)  │  │ (Compliance) │  │ (Access)     │           │
│  └──────────────┘  └──────────────┘  └──────────────┘           │
│         │                 │                  │                  │
│         └─────────────────┼──────────────────┘                  │
│                           │                                     │
│  ┌────────────────────────────────────────────────────────┐     │
│  │         ComplianceRules Engine (Multi-Layer)           │     │
│  │  - Jurisdiction validation                             │     │
│  │  - Investor type validation                            │     │
│  │  - Holding period enforcement                          │     │
│  │  - Compliance level validation                         │     │
│  └────────────────────────────────────────────────────────┘     │
│                           │                                     │
│  ┌────────────────────────────────────────────────────────┐     │
│  │      Vanguard RWA StableCoin Token (VSC) - ERC-3643    │     │
│  │  - Compliant transfers with multi-layer validation     │     │
│  │  - Investor type-specific limits                       │     │
│  │  - Issuer-only minting with quotas                     │     │
│  │  - Quota-based burning with audit trails               │     │
│  └────────────────────────────────────────────────────────┘     │
│                                                                 │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐           │
│  │ Governance   │  │ Escrow       │  │ Payment      │           │
│  │ (1P=1V)      │  │ (2-of-3)     │  │ (Refunds)    │           │
│  └──────────────┘  └──────────────┘  └──────────────┘           │
│                                                                 │
│  ┌────────────────────────────────────────────────────────┐     │
│  │      Privacy Layer (5 ZK Circuits - Groth16)           │     │
│  │  - Whitelist/Blacklist membership proofs               │     │
│  │  - Jurisdiction compliance proofs                      │     │
│  │  - Accreditation status proofs                         │     │
│  │  - Compliance aggregation proofs                       │     │
│  └────────────────────────────────────────────────────────┘     │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Contract Categories

Category Contracts Status
OnchainID 5 contracts ✅ COMPLETE
ERC-3643 6 contracts ✅ COMPLETE
Oracle 4 contracts ✅ COMPLETE
Compliance 1 contract ✅ COMPLETE
Privacy 7 contracts ✅ COMPLETE
Investor Type 2 contracts ✅ COMPLETE
Governance 2 contracts ✅ COMPLETE
Escrow 2 contracts ✅ COMPLETE
Payment 3 contracts ✅ COMPLETE
Total 32+ contracts PRODUCTION READY

🚀 Getting Started with the Demo

Step 1: Deploy the System

# Start Hardhat node
npx hardhat node

# In another terminal, run the demo
npm run demo:interactive:proof


**See [Complete Demo Workflow](/docs/COMPLETE_DEMO_WORKFLOW.md) for detailed step-by-step guide.**

## 📈 Performance & Scalability

### **Gas Optimization**
- ✅ Efficient storage patterns (packed structs, minimal storage writes)
- ✅ Batch operations for multiple actions
- ✅ Optimized loops and data structures
- ⏳ **PENDING**: Comprehensive gas benchmarking and optimization

### **Scalability**
- ✅ Modular architecture for easy upgrades
- ✅ Oracle consensus for distributed validation
- ✅ Efficient caching mechanisms
- ✅ Designed for high-throughput transaction processing

### **Monitoring & Observability**
- ✅ Comprehensive event logging for all operations
- ✅ Audit trails for compliance and governance
- ⏳ **PENDING**: Real-time monitoring and alerting setup
- ⏳ **PENDING**: Performance metrics and dashboards

## 🤝 Contributing

### **Development Guidelines**
1. ✅ Maintain comprehensive test coverage
2. ✅ Update documentation with any changes
3. ✅ Follow security best practices
4. ✅ Submit detailed test results
5. ✅ Follow existing code style and patterns

### **Testing Requirements**
- All new features must include unit tests
- Integration tests for cross-contract interactions
- Gas optimization tests for critical functions
- Security testing for access control and validation

### **Documentation Requirements**
- Update relevant documentation files
- Add inline code comments for complex logic
- Create workflow guides for new features
- Update API documentation for contract changes

## 📄 License

MIT License - See LICENSE file for details

## 🆘 Support & Resources

### **Documentation**
- [System Overview](/docs/SYSTEM_OVERVIEW.md) - Start here for system architecture
- [Vanguard RWA StableCoin Ecosystem Guide](/docs/VANGUARD_STABLECOIN_ECOSYSTEM_GUIDE.md) - Complete ecosystem overview
- [Working Demos](/docs/WORKING_DEMOS.md) - Verified working demos guide
- [System Workflow Guide](/docs/SYSTEM_WORKFLOW_GUIDE.md) - User workflows and interactions

### **Getting Help**
1. Check the comprehensive documentation in the `/docs` folder
2. Review the interactive demo (83 menu options)
3. Examine test files for usage examples
4. Submit issues with detailed reproduction steps

---

## 🎯 Project Status

**Current Phase**: ✅ **Phase 5 Complete** - All core features implemented
**Next Milestone**: Phase 6 - Production Deployment (Gas optimization, security audits, mainnet deployment)

### **Implementation Summary**
- ✅ **11 Core Requirements**: All fully implemented
- ✅ **32+ Smart Contracts**: Production-ready
- ✅ **5 ZK Circuits**: Privacy-preserving compliance
- ✅ **83 Demo Options**: Complete system testing
- ✅ **Comprehensive Documentation**: Complete guides and technical deep dives

### **Production Readiness**
- ✅ **Smart Contracts**: Complete and tested
- ✅ **Integration**: All systems working together
- ✅ **Documentation**: Comprehensive and up-to-date
- ⏳ **Security Audits**: Pending professional audits
- ⏳ **Gas Optimization**: Pending benchmarking and optimization
- ⏳ **Mainnet Deployment**: Pending production deployment

**This is production-ready technology ready for security audits and mainnet deployment! 🎉**

About

Vanguard RWA StableCoin - ERC-3643 Compliant Digital Currency

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published