UniswapV3

You can import the UniswapV3 environment by running:

run.py
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:

ChainsBackend TypesPoolsStart Date
Ethereum Mainnet - ethereumforked, localDAI-FRAX-0.05 2021-04-24 01:40:00 UTC
DAI-USDC-0.01 2021-11-13 02:50:00 UTC
DAI-USDC-0.05 2021-05-04 20:00:00 UTC
DAI-WETH-0.3 2021-05-04 20:20:00 UTC
DUSK-USDT-0.3 2021-05-06 10:30:00 UTC
FRAX-USDC-0.05 2021-04-24 01:40:00 UTC
LDO-WETH-0.3 2021-04-24 01:40:00 UTC
LDO-WETH-1 2021-04-24 01:40:00 UTC
MATIC-WETH-0.3 2021-05-05 20:40:00 UTC
PEPE-USDC-1 2021-04-24 01:40:00 UTC
PEPE-WETH-1 2021-04-24 01:40:00 UTC
PRO-WETH-0.012021-08-15 20:20:00 UTC
SHIB-WETH-0.3 2021-04-24 01:40:00 UTC
SHIB-WETH-1 2021-04-24 01:40:00 UTC
SKL-WETH-0.012021-11-17 14:00:00 UTC
UNI-WETH-0.3 2021-05-04 20:00:00 UTC
USDC-USDT-0.01 2021-11-13 17:50:00 UTC
USDC-USDT-0.05 2021-05-04 20:20:00 UTC
USDC-WETH-0.05 2021-05-05 21:50:00 UTC
USDC-WETH-0.3 2021-05-04 23:10:00 UTC
WBTC-USDC-0.3 2021-05-05 19:20:00 UTC
WBTC-WETH-0.01 2021-05-04 20:00:00 UTC
WBTC-WETH-0.05 2021-05-05 20:30:00 UTC
WBTC-WETH-0.3 2021-05-04 20:10:00 UTC
WETH-USDT-0.3 2021-05-05 16:40:00 UTC
Arbitrum L2 - arbitrumforked, localARB-USDC-0.05 2023-03-20 19:40:12 UTC
ARB-WETH-0.05 2023-03-17 01:50:00 UTC
ARB-WETH-0.3 2023-03-17 01:50:00 UTC
CRYPTO-WETH-1.0 2022-09-10 06:00:15 UTC
GMX-WETH-0.3 2021-09-15 02:57:00 UTC
GMX-WETH-1.0 2021-08-31 12:07:19 UTC
PENDLE-WETH-0.3 2023-03-08 09:20:00 UTC
USDC-ARB-0.05 2023-03-20 19:40:12 UTC
USDC-WETH-0.05 2023-06-08 21:28:30 UTC
USDC-WETH-0.3 2021-06-17 17:19:10 UTC
USDT-DAI-0.01 2023-02-27 20:16:00 UTC
USDT-WETH-0.05 2021-09-07 01:05:00 UTC
WBTC-WETH-0.05 2021-09-12 11:51:00 UTC
WBTC-WETH-0.3 2021-06-23 22:03:00 UTC

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("2021-06-21 00:00:00 UTC")
sim_end = dateparser.parse("2021-06-21 00:10: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,
  backend_type="forked",
  market_impact="replay",  # defaults to "replay", simply replaying history
)
env.reset()
 
action = UniV3Trade(
  agent=agent,
  pool=env.obs.pools[0],
  quantities=(Decimal("0.1"), Decimal("0")),
)
 
env.step(actions=[action])