This project simulates a token-based economy where autonomous agents interact with a bonding curve mechanism. The simulation explores how different bonding curve parameters affect market stability, token supply, and price dynamics. An optimization component automatically tunes bonding curve parameters to minimize price volatility while maintaining healthy market activity.
The simulation provides insights into: - Market dynamics under different bonding curve configurations - Agent behavior patterns and wealth distribution - Price stability and volatility characteristics - Optimal parameter selection for stable markets
Multi-segment: Hybrid approach combining linear and exponential phases
🤖 Autonomous Agents: Intelligent trading agents with:
Wealth preservation and risk management
âš¡ Parameter Optimization: Advanced optimization using random search to:
Support multiple evaluation metrics
📊 Comprehensive Analytics: Detailed tracking of:
.
├── src/ # Source code directory
│ ├── agent.py # Agent class and trading logic
│ ├── bonding_curves.py # Bonding curve price calculations
│ ├── config.py # Simulation parameters and constants
│ ├── main.py # Main execution and visualization
│ ├── optimization.py # Parameter optimization logic
│ ├── simulation.py # Simulation state management
│ └── tests/ # Test suite
│ ├── test_agent.py
│ ├── test_bonding_curves.py
│ ├── test_optimization.py
│ └── test_simulation.py
├── .venv/ # Virtual environment (created automatically)
├── .gitignore # Git ignore patterns
├── pytest.ini # Pytest configuration
├── README.md # Project documentation
└── LICENSE # MIT-0 License
Clone the repository:
bash
git clone https://github.com/waifuai/sim-bonding-curve.git
cd sim-bonding-curve
Create virtual environment:
bash
python -m uv venv .venv
source .venv/Scripts/activate # On Windows
# or
source .venv/bin/activate # On macOS/Linux
Install dependencies:
bash
python -m uv pip install -e .[test]
pip install numpy matplotlib pytest
Run a basic simulation:
bash
python -m src.main
Run with custom parameters (edit src/config.py first):
bash
python -m src.main
Run tests:
bash
python -m pytest src/tests/
Key parameters in src/config.py:
# Simulation Scale
NUM_AGENTS = 100 # Number of trading agents
SIMULATION_STEPS = 500 # Duration of simulation
# Initial Conditions
INITIAL_TOKEN_SUPPLY = 100.0 # Starting token supply
INITIAL_AGENT_CAPITAL = 100.0 # Starting capital per agent
INITIAL_TOKEN_PRICE = 1.0 # Starting token price
# Market Parameters
TRADING_FEE = 0.001 # Transaction fee (0.1%)
BONDING_CURVE_TYPE = 'sigmoid' # Default curve type
# Agent Behavior
AGENT_TRADE_FREQUENCY = 0.1 # Probability of trading each step
AGENT_TRADE_SIZE_RANGE = [0.01, 0.1] # Min/max trade size as fraction of holdings
AGENT_MEMORY_SIZE = 10 # Price history window
AGENT_TREND_THRESHOLD = 0.01 # Minimum trend for action
AGENT_TREND_DELAY = 2 # Steps between trades
price = m × supply + bParameters: m (slope), b (intercept)
Exponential: price = a × exp(k × supply)
Parameters: a (scale), k (growth rate)
Sigmoid: price = k_max / (1 + exp(-k × (supply - s0)))
Parameters: k (steepness), s0 (center), k_max (maximum)
Multi-segment: Combines linear and exponential phases
breakpoint, m, a, kAgents use sophisticated trading strategies based on:
AGENT_MEMORY_SIZE pricesAGENT_TREND_THRESHOLDAGENT_TRADE_FREQUENCYAGENT_TREND_DELAY between tradesThe optimization system finds optimal bonding curve parameters by:
# Example for sigmoid curve optimization
optimization_ranges = {
'k': (0.02, 0.05), # Steepness parameter
's0': (80, 120), # Center point
'k_max': (5, 10) # Maximum price
}
The simulation generates comprehensive outputs:
Example output includes: - Supply dynamics showing market growth patterns - Price evolution with volatility analysis - Agent wealth distribution and Gini coefficient - Performance comparison across parameter sets
# Run all tests
python -m pytest src/tests/
# Run with coverage
python -m pytest --cov=src src/tests/
# Run specific test file
python -m pytest src/tests/test_bonding_curves.py
flake8 or black for code formattingAgent: Represents a trading agent with memory and decision logicSimulationState: Manages global simulation state and metricscalculate_bonding_curve_price(): Compute token price for given supplysimulation_step(): Execute one simulation time stepoptimize_bonding_curve(): Find optimal bonding curve parametersevaluate_parameters(): Assess parameter set performanceImport Errors: Ensure you're running from the project root
bash
python -m src.main # Correct
python src/main.py # May cause import issues
Slow Performance: Reduce NUM_AGENTS or SIMULATION_STEPS
Memory Issues: Decrease AGENT_MEMORY_SIZE or simulation scale
Convergence Problems: Adjust optimization ranges in optimization.py
num_runs in evaluation for quicker feedbackThis project is licensed under the MIT-0 License - see the LICENSE file for details.
If you use this simulation in your research, please cite:
@software{bonding_curve_sim,
title={Token Economy Simulation with Bonding Curves},
author={Your Name},
year={2024},
url={https://github.com/waifuai/sim-bonding-curve}
}
Browse the source repository