Skip to content

heswithme/curve-sim-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TwoCrypto C++ Modular

High-performance C++ implementation of Curve's TwoCrypto AMM pool for simulation and parameter grid search.

Two Main Use Cases

1. C++ Pool Parity Validation

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

2. Arbitrage Grid Search

Run parameter sweeps over historical candle data to evaluate pool configurations. Optionally replay historical CoWSwap trades.

Get data first:

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 5

With 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 --cow

One-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

Key CLI Flags

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

Requirements

  • C++17 compiler, CMake, Boost (json)
  • Python 3.10+, uv
  • For Vyper validation: titanoboa
git submodule update --init --recursive

Build

cmake -B cpp_modular/build cpp_modular -DCMAKE_BUILD_TYPE=Release
cmake --build cpp_modular/build -j

Repository Structure

cpp_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)

Outputs

Results written to:

  • python/arb_sim/run_data/ - grid search results
  • python/benchmark_pool/data/results/ - parity benchmark results

Both directories are gitignored.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages