UniswapV3

You can import the UniswapV3 environment by running:

from dojo.environments import UniV3Env

It is recommended to read the UniswapV3 whitepaper if the concept of an automated market maker or concentrated liquidity is unclear.


Supported Pools

At the moment, we natively have data for the following pools:

If you want to do a simulation on a pool that is not included here, please contact us. We can add other pools fairly quickly.


Observations

An observation refers to the information that the agent receives from the environment at every block. Think of the current price, or the liquidity in the pool.

The methods within UniV3Obs can be found here.


Actions

Actions are the means through which the agent interacts with the environment to achieve goals.

In general, there are 4 actions you can perform on the Uniswap V3 environment:

  • TRADE: trading one token for another token, without changing your invested liquidity
  • QUOTE: either providing or taking liquidity out of the pool
  • COLLECT: collect LP fees from an LP position
  • SET FEE PROTOCOL: set the protocol fee of a pool

Please refer to the code reference for more details.


Example

example.py
import os
import sys
from decimal import Decimal
 
current = os.path.dirname(os.path.realpath(__file__))
parent = os.path.dirname(current)
sys.path.append(parent)
 
 
import numpy as np
from agents import UniV3PoolWealthAgent
from dateutil import parser as dateparser
 
from dojo.environments.uniswapV3 import UniV3Env, UniV3Trade
 
pools = ["USDC/WETH-0.3"]
sim_start = dateparser.parse("2023-04-29 00:00:00 UTC")
sim_end = dateparser.parse("2023-04-30 00:00:00 UTC")
 
agent = UniV3PoolWealthAgent(initial_portfolio={"USDC": Decimal(10_000)})
env = UniV3Env(
  agents=[agent],  # Of course, you'd want an agent here to actually do things
  date_range=(sim_start, sim_end),
  pools=pools,
  market_impact="replay",  # defaults to "replay", simply replaying history
)
 
action = UniV3Trade(
  agent=agent,
  pool=env.obs.pools[0],
  quantities=(Decimal("0.1"), Decimal("0")),
)
 
env.step(actions=[action])