High-performance C++ implementation of Curve's TwoCrypto AMM pool for simulation and parameter grid search.
Verify C++ pool math matches Vyper reference. Generate test data, run C++ variants (double/float), compare against Vyper.
# Check math parity
uv run python/benchmark_math/main.py
# Generate benchmark data
uv run python/benchmark_pool/generate_data.py --pools 3 --trades 20 --seed 42
# Run C++ variants and Vyper, compare results
uv run python/benchmark_pool/run_full_benchmark.py --n-cpp 8 --n-py 1
Run parameter sweeps over historical candle data to evaluate pool configurations. Optionally replay historical CoWSwap trades.
Get data first:
- Candles: https://github.com/heswithme/FX-1-Minute-Data (put in
python/arb_sim/trade_data/) - CoWSwap trades (optional): https://github.com/heswithme/cowswap-trades-fetch
Run grid search:
# 1. Generate pool parameter grid
uv run python/arb_sim/generate_pools_generic.py
# 2. Run simulation
uv run python/arb_sim/arb_sim.py --real double --dustswapfreq 600 --apy-period-days 1 --apy-period-cap 30 -n 10
# 3. Plot results
uv run python/arb_sim/plot_heatmap.py --metrics apy,tw_capped_apy,tw_capped_apy_net,vp,tw_avg_pool_fee,n_rebalances,trades,total_notional_coin0,tw_apy_geom_mean,avg_rel_bps,tw_slippage,tw_liq_density --ncol 5With CoWSwap replay (add --cow):
uv run python/arb_sim/arb_sim.py --real double --dustswapfreq 600 --apy-period-days 1 --apy-period-cap 30 -n 10 --cowOne-liner:
uv run python/arb_sim/generate_pools_generic.py && uv run python/arb_sim/arb_sim.py --real double --dustswapfreq 600 --apy-period-days 1 --apy-period-cap 30 -n 10 && uv run python/arb_sim/plot_heatmap.py --metrics apy,tw_capped_apy,tw_capped_apy_net,vp,tw_avg_pool_fee,n_rebalances,trades,total_notional_coin0,tw_apy_geom_mean,avg_rel_bps,tw_slippage,tw_liq_density --ncol 5| Flag | Description |
|---|---|
--real double/float/longdouble |
Numeric precision |
-n N |
Thread count |
--n-candles N |
Limit candles processed |
--dustswapfreq S |
Idle tick frequency (seconds) |
--apy-period-days D |
Rolling APY window |
--apy-period-cap P |
Cap per-window APY percent |
--cow |
Enable CoWSwap trade replay |
--save-actions |
Record all trades for replay |
--detailed-log |
Per-candle state output |
- C++17 compiler, CMake, Boost (json)
- Python 3.10+, uv
- For Vyper validation: titanoboa
git submodule update --init --recursivecmake -B cpp_modular/build cpp_modular -DCMAKE_BUILD_TYPE=Release
cmake --build cpp_modular/build -jcpp_modular/ # C++ pool implementation and harness
python/
arb_sim/ # Grid search simulator
trade_data/ # Candle data (btcusd/, ethusd/, etc.)
run_data/ # Output: pool_config.json, arb_run_*.json
benchmark_pool/ # Parity validation tools
vyper_pool/ # Vyper runner via titanoboa
contracts/twocrypto-ng/ # Vyper reference (submodule)
Results written to:
python/arb_sim/run_data/- grid search resultspython/benchmark_pool/data/results/- parity benchmark results
Both directories are gitignored.