Uniswap Protocol

Exploring the uniswap protocol for automated liquidity provisioning on Ethereum.

About Uniswap

Uniswap is a fully decentralized protocol for automated liquidity provision on Ethereum.

About This Model

This model, built in HASH, simulates the Uniswap protocol and evaluates arbitrage between two balancer pools and the gains / potential impermanent loss

You can read the HASH blog post about this model at hash.ai/blog/uniswap

The model comprises four types of agents:

  1. Two automated market makers running the uniswap protocol
  2. An arbitrage agent that compares the price between the automated market maker. The agent arbitrages any differences.
  3. A liquidity providing agent that adds liquidity to a pool and later removes it.

Running the model

With the default parameters I suggest stepping through the model to observe the price changes from steps 1-50. All the action happens in the plots tab (select it in the top right). It demonstrates price equalizing due to arbitrageur actions and gains to the liquidity provider. Then experiment with different fee/initial token allocations.

Global Parameters

"ts_deposit_liquidity" <int>: timestep that the liquidity provider deposits liquidity "ts_reclaim_liquidity" <int>: timestep that the liquidity provider burns ls shares and receives tokens from uniswap "amm_fees" <float>: trading fees that the amm takes on each trade "amm_init_a" <float>: initial token reserve a for amm "amm_init_b" <float>: initial token reserve b for amm "amm_two_init_a" <float>: initial token reserve a for amm_two "amm_two_init_b" <float>: initial token reserve b for amm_two


The simulation, and experiments, explores a few different concepts:

  • how different fee regimes can benefit/hurt liquidity providers by capturing more money for the token reserves at the expense of reducing the overall
  • A bit of a "rug pull" when the liquidity provider removes its deposit from the AMM


  • Provide stochastic exchange option (scenario with a uniswap pool and a traditional exchange simulated as a brownian motion process)
  • Add competing arbitrage agents and malicious rug pull scenarios


  • Modify amm to support multiple token pairs.
  • Rename token_a and token_b in amm to a and b for ease of indexing.
  • Add test cases - still very experimental, please flag any bugs to me on the issues page :)