To run the Tokenomics Engine, execute the following commands:
# Install required packages
pip install -r requirements.txt
# Run the Streamlit application
streamlit run app.pyThe application will open in your default web browser, typically at http://localhost:8501
- Overview
- Architecture
- Core Components
- Data Models
- Simulation Engine
- Visualization Features
- Monte Carlo Simulation
- Caching System
- Error Handling
- Installation and Usage
- Technical Requirements
- Testing
The Unit Zero Labs Tokenomics Engine is a comprehensive simulation and visualization tool designed to model token economics for blockchain projects. It enables users to:
- Visualize token distribution, vesting schedules, and utility allocations over time
- Simulate token price dynamics, market cap evolution, and staking behavior
- Run Monte Carlo simulations to assess risk and potential outcomes across multiple scenarios
- Analyze the impact of different parameter settings on token economics
The tool is built as a Streamlit web application with a Python backend using the cadCAD simulation framework, providing an interactive experience for both token designers and stakeholders.
The application is structured around the following components:
sim-systems/
├── app.py # Main entry point
├── simulate.py # Original simulation code
├── tokenomics_data.py # Original data processing code
├── visualization/ # Visualization components
│ ├── __init__.py
│ ├── charts.py # All plotting functions
│ ├── components.py # Reusable UI components
│ └── styles.py # CSS styles and theming
├── logic/ # Business logic
│ ├── __init__.py
│ ├── data_manager.py # Data loading and transformations
│ ├── state_manager.py # Session state management
│ └── monte_carlo.py # Monte Carlo specific logic
├── utils/ # Utilities
│ ├── __init__.py
│ ├── config.py # Configuration management
│ ├── cache.py # Caching utilities
│ ├── validators.py # Input validation
│ └── error_handler.py # Error handling
└── tests/ # Testing framework
├── __init__.py
└── test_charts.py # Example test file
The application follows a modular design where data parsing, simulation logic, and visualization are separated, making it easier to maintain and extend the codebase.
Serves as the central data structure for storing tokenomics parameters and time-series data:
- Token allocation and vesting schedules
- Utility metrics and allocations
- Financial time-series data (price, market cap, etc.)
- Static parameters for simulation
Handles the loading and processing of tokenomics data:
- Validates input data
- Processes radCAD inputs
- Provides methods for exporting data
- Calculates summary statistics
Implements the simulation logic:
- Sets up initial state based on parsed data
- Defines policy functions for token dynamics
- Defines state update functions
- Provides methods for running simulations
Optimizes Monte Carlo simulations:
- Runs simulations in parallel for better performance
- Provides progress tracking
- Calculates statistical measures from multiple runs
Manages application state:
- Initializes and maintains session state
- Provides a consistent interface for state access
- Handles state updates from UI interactions
Contains all the plotting functions:
- Chart generation for token data
- Visualization of simulation results
- Monte Carlo result visualization
Reusable UI components:
- Headers and layout elements
- Form controls for simulation parameters
- Results display components
CSS styling for the application:
- Consistent theming across components
- Responsive design elements
- Custom styling for Streamlit components
Centralized configuration system:
- Default values for simulation parameters
- UI configuration
- Cache settings
Optimizes performance through caching:
- Memory and persistent caching
- Time-to-live management
- Cache statistics
Consistent error management:
- Error logging
- User-friendly error messages
- Exception wrapping
Input validation utilities:
- Parameter validation
- Data format validation
- Error message formatting
The system uses a variety of static parameters for simulation:
- Initial token supply and distribution
- Launch date and simulation horizon
- Public sale metrics (valuations, percentages)
- Vesting schedules (initial vesting, cliff periods, durations)
- Utility allocations (staking, burning, etc.)
Several time-series datasets are generated and tracked:
- Vesting schedules for different token buckets
- Token price evolution
- Market cap and fully diluted valuation (FDV)
- Staking APR
- Utility allocations over time
The system models tokens in different allocation buckets:
- Public Sale allocations
- Team/Founders
- Advisors
- Strategic Partners
- Community
- CEX Liquidity
- Liquidity Pool
- Airdrops
- Staking Incentives
Key state variables tracked in the simulation:
token_supply: Total token supplycirculating_supply: Tokens in circulation (excludes locked tokens)staked_tokens: Tokens staked by usersliquidity_pool_tokens: Tokens in liquidity poolstoken_price: Current token pricemarket_cap: Market capitalization (circulating supply × price)staking_apr: Annual percentage rate for staking
Policy functions that model system behaviors:
p_vesting_schedule: Determines newly vested tokens based on vesting schedulesp_staking: Models user staking behavior based on staking share parameterp_token_price: Models token price dynamics with market volatility
Functions that update system state:
s_update_supply: Updates circulating supply based on vestings_update_staking: Updates staked tokens based on staking behaviors_update_price: Updates token price based on price dynamicss_update_market_cap: Recalculates market cap based on price and supply
- Distribution of tokens across different buckets over time
- Circulating supply vs. total supply
- Vesting schedules for different stakeholders
- Token price over time
- Market cap and fully diluted valuation (FDV)
- DEX liquidity valuation
- Utility allocations over time
- Monthly utility incentives, burnings, and transfers
- Staking APR
- Comparison of simulated metrics with initial values
- Time-series charts for key metrics from simulation runs
- Statistical analysis of simulation results
The Monte Carlo simulation feature:
- Runs the model multiple times with different random seeds
- Uses parallel processing for improved performance
- Captures the range of possible outcomes for key metrics
- Calculates statistical measures (mean, standard deviation, percentiles)
- Visualizes the distribution of outcomes
Monte Carlo results are visualized through:
- Time-series charts with confidence intervals and percentile bands
- Probability distribution histograms at specific timesteps
- Statistical summary tables
The system provides tools for analyzing Monte Carlo results:
- Confidence intervals for assessing prediction reliability
- Percentile bands for understanding the range of outcomes
- Probability distributions for detailed analysis at specific points in time
- Fast in-memory cache for frequently accessed data
- Automatic cache size management
- Access and update time tracking
- File-based caching for data that persists between sessions
- Automatic cache invalidation
- Support for time-to-live settings
@cacheddecorator for easy function caching@st_cache_datadecorator compatible with Streamlit's caching system- Cache statistics and monitoring
- Centralized error logging
- Context-aware error messages
- Support for detailed error information
- Consistent error presentation in the UI
- Appropriate error levels (info, warning, error)
- Detailed error information for debugging
- Input parameter validation
- Data format and consistency validation
- Helpful error messages for invalid inputs
- Clone the repository
- Install required packages:
pip install -r requirements.txt
Start the Streamlit application:
streamlit run app.py
- Data Loading: Upload a radCAD inputs CSV file with tokenomics parameters
- Data Exploration: Explore the loaded data through various visualizations
- Simulation: Adjust parameters and run simulations to see impacts
- Analysis: Analyze simulation results with various metrics and visualizations
- Python 3.9+
- pandas 2.0.0
- streamlit 1.22.0
- plotly 5.14.1
- numpy 1.24.3
- cadCAD 0.4.28
The application expects a CSV file with the following structure:
- Parameter Name: Name of the tokenomics parameter
- Initial Value: Value of the parameter
- Other optional columns for min/max values, units, comments
The application includes unit tests for key components:
- Chart generation
- Data processing
- Simulation logic
Execute the tests using Python's unittest framework:
python -m unittest discover testsThe test framework focuses on:
- Ensuring visualizations work correctly
- Validating data processing logic
- Testing simulation calculations
This documentation provides a comprehensive overview of the Unit Zero Labs Tokenomics Engine, explaining its architecture, features, and usage. For detailed technical information about specific components, refer to the code documentation in the respective files.