Skip to content

Latest commit

 

History

History
206 lines (158 loc) · 6.99 KB

File metadata and controls

206 lines (158 loc) · 6.99 KB

Multi-Regional Tax Jurisdiction Mapping Logic - Issue #207

Summary

This PR implements a comprehensive tax jurisdiction mapping system that transforms Grant-Stream into a "Tax-Native" protocol capable of handling global tax compliance for a distributed workforce of developers while maintaining legal standing with international tax authorities.

🎯 Objectives Achieved

  • GranteeRecord Enhancement: Added jurisdiction_code field to track tax jurisdictions
  • Jurisdiction Registry: Implemented DAO-updatable registry for global tax rates
  • Dynamic Tax Withholding: Tax rates automatically adjust based on jurisdiction
  • Tax Treaty Support: Built-in support for tax treaty benefits
  • Comprehensive Testing: Full test suite covering all scenarios

🏗️ Architecture Overview

Core Components

  1. JurisdictionInfo Structure

    pub struct JurisdictionInfo {
        pub code: String,                    // e.g., "US-CA", "GB-LDN"
        pub name: String,                    // Human-readable name
        pub tax_withholding_rate: u32,       // Rate in basis points (1/100%)
        pub tax_treaty_eligible: bool,       // Treaty benefits available
        pub documentation_required: bool,    // Additional docs needed
        pub updated_at: u64,                 // Last update timestamp
        pub updated_by: Address,             // Who updated this
    }
  2. GranteeRecord Structure

    pub struct GranteeRecord {
        pub address: Address,                // Wallet address
        pub jurisdiction_code: String,       // Tax jurisdiction
        pub tax_id: Option<String>,          // SSN, EIN, etc.
        pub tax_treaty_claimed: bool,        // Treaty benefits claimed
        pub verified: bool,                  // Verification status
        pub verification_documents: Option<[u8; 32]>, // Document hash
        pub created_at: u64,                 // Creation time
        pub updated_at: u64,                 // Last update
    }
  3. TaxWithholdingRecord Structure

    pub struct TaxWithholdingRecord {
        pub grant_id: u64,                   // Associated grant
        pub grantee: Address,                // Grantee address
        pub gross_amount: i128,             // Gross payment
        pub tax_rate: u32,                   // Applied tax rate
        pub tax_withheld: i128,              // Amount withheld
        pub net_amount: i128,               // Net payment
        pub jurisdiction_code: String,        // Jurisdiction used
        pub payment_date: u64,               // Payment timestamp
        pub tax_report_id: Option<u64>,      // Report reference
    }

🔧 Key Functions

DAO Governance Functions

  • register_jurisdiction(): Admin-only jurisdiction registration
  • update_jurisdiction(): Dynamic jurisdiction updates by DAO
  • set_tax_withholding_reserve(): Configure tax reserve address

Grantee Functions

  • register_grantee_jurisdiction(): Self-service jurisdiction registration
  • get_grantee_record(): Retrieve grantee tax information

Tax Processing Functions

  • calculate_tax_withholding(): Real-time tax calculation
  • process_payment_with_tax(): Automated tax withholding

Query Functions

  • get_jurisdiction(): Retrieve jurisdiction details
  • get_all_jurisdictions(): List all registered jurisdictions

🧮 Tax Calculation Logic

The system implements sophisticated tax calculation:

  1. Base Rate Application: Applies jurisdiction-specific base rate
  2. Treaty Benefits: 50% reduction for eligible treaty claims
  3. Validation: Ensures rates stay within configured bounds
  4. Transparency: Full audit trail of all calculations

Example calculation:

  • Gross Amount: $1,000
  • US-CA Base Rate: 30% (3000 basis points)
  • Treaty Benefits: Yes (50% reduction)
  • Effective Rate: 15% (1500 basis points)
  • Tax Withheld: $150
  • Net Payment: $850

🛡️ Safety Features

Input Validation

  • Jurisdiction code length limits (max 10 chars)
  • Tax rate bounds (0-50% maximum)
  • Required field validation

Access Control

  • Admin-only jurisdiction registration/updates
  • Grantee self-service for own records
  • DAO governance for registry changes

Audit Trail

  • Timestamped updates
  • Updater address tracking
  • Complete payment history

📊 Storage Architecture

Data Keys

// Tax Jurisdiction keys
JurisdictionRegistry(String),     // Code → JurisdictionInfo
JurisdictionCodes,                // List of all codes
GranteeJurisdiction(Address),     // Address → GranteeRecord
TaxWithholdingReserve,            // Reserve address

🧪 Test Coverage

Comprehensive test suite includes:

  • ✅ Jurisdiction registration and updates
  • ✅ Grantee jurisdiction registration
  • ✅ Tax withholding calculations
  • ✅ Payment processing with tax
  • ✅ Tax treaty benefits
  • ✅ Input validation and error scenarios
  • ✅ Edge cases and boundary conditions

🌍 Global Compliance

This implementation enables Grant-Stream to:

  1. Handle Multi-Jurisdictional Workforce: Support developers from any country
  2. Maintain Legal Compliance: Automatic tax withholding per local laws
  3. Adapt to Regulatory Changes: DAO can update rates as laws evolve
  4. Provide Tax Transparency: Clear reporting for grantee and foundation
  5. Support Tax Treaties: Reduce withholding for treaty beneficiaries

📈 Economic Impact

For Grantees

  • Predictable net payments regardless of location
  • Automatic tax treaty benefit application
  • Clear tax documentation for filing

For Foundation

  • Compliance with international tax laws
  • Automated tax withholding and reporting
  • Reduced legal and administrative overhead

For Protocol

  • "Tax-Native" positioning enhances adoption
  • DAO-governed tax policy ensures adaptability
  • Transparent operations build trust

🔮 Future Enhancements

Potential future improvements:

  • Tax reporting integration with accounting systems
  • Multi-currency tax withholding
  • Advanced tax treaty calculations
  • Automated tax filing assistance
  • Integration with tax oracle services

📋 Implementation Checklist

  • Data structures defined
  • Core functions implemented
  • Access controls configured
  • Tax calculation logic
  • Payment processing with tax
  • DAO governance functions
  • Comprehensive test suite
  • Error handling and validation
  • Event emissions for transparency
  • Storage optimization

🚀 Deployment Notes

  1. Initialization: Admin must set up initial jurisdictions
  2. Reserve Configuration: Tax withholding reserve address required
  3. Grantee Onboarding: Users register their jurisdiction
  4. Monitoring: DAO oversees jurisdiction registry updates

📚 Documentation

  • Function documentation included in code
  • Test cases serve as usage examples
  • Constants clearly defined for easy modification
  • Error codes comprehensive for debugging

This PR establishes Grant-Stream as a truly global, tax-compliant funding protocol ready for international deployment.