dojo.environments

Environments package contains environment classes and logic.

@final
class UniswapV3Env(dojo.environments.base_environments.BaseEnvironment[dojo.actions.base_action.BaseAction[dojo.observations.uniswapV3.UniswapV3Observation], dojo.observations.uniswapV3.UniswapV3Observation]):

The UniswapV3Env environment models the UniswapV3 system dynamics.

It is responsible for updating both the protocol and agent states through time.

UniswapV3Env( chain: dojo.common.Chain, agents: list[dojo.agents.BaseAgent[dojo.observations.UniswapV3Observation]], pools: list[str], block_range: tuple[int, int], backend_type: Literal['forked', 'local', 'live'] = 'forked', port: Optional[int] = None, token_data: Optional[dict[str, dict[datetime.datetime, decimal.Decimal]]] = None)

Instantiate a UniswapV3Env object.

Parameters
  • chain: blockchain to use in the environment
  • agents: list of agents to use in the environment.
  • block_range: block range of the environment simulation.
  • pools: list of pool names to use in the environment.
  • backend_type: type of backend to use, one of: ['forked', 'local', 'live']. Defaults to 'forked'.
    • 'forked': forks a live network to initialize the environment state at the given date range. This mode requires more communication with an archive node and is more unpredictable when funding agents with tokens, but it is faster to intialize state, especially at later start dates.
    • 'local': deploys contracts locally to initialize the environment state at the given date range. This mode requires less communication with an archive node and is guaranteed stable when funding agents with tokens, but it can be slower to initialize state, especially at later start dates.
  • port: port to connect to the local chain. Defaults to find a free port.
  • token_data: optional dict containing token price data to pass to each agent, needed if you want to call the agent wealth methods. The dictionary has format:

    {
        "token_symbol": {
            datetime0: price0,
            datetime1: price1,
            ...
        },
        ...
    }
    
Raises
  • ValueError: if the market impact param is not one given by the UniswapV3MarketModelType enum.
  • ValueError: if the list of pools is empty.
  • Exception: if the simulation is being run without a license and not on a free example see (example_backtest.py)
@final
class AAVEv3Env(dojo.environments.base_environments.BaseEnvironment[dojo.actions.base_action.BaseAction[dojo.observations.aaveV3.AAVEv3Observation], dojo.observations.aaveV3.AAVEv3Observation]):

The AAVEv3Env environment models the AAVEv3Env system dynamics.

It is responsible for updating both the protocol and agent states through time.

AAVEv3Env( chain: dojo.common.Chain, agents: list[dojo.agents.BaseAgent[dojo.observations.AAVEv3Observation]], block_range: Optional[tuple[int, int]] = None, backend_type: Literal['forked', 'local', 'live'] = 'forked', port: Optional[int] = None, token_data: Optional[dict[str, dict[datetime.datetime, decimal.Decimal]]] = None)

Instantiate a AAVEv3Env object.

Parameters
  • chain: chain to use for the environment.
  • agents: list of agents to use in the environment.
  • block_range: Required for backtesting. Block range of the environment simulation.
  • backend_type: type of backend to use, one of: ['forked', 'local', 'live']. Defaults to 'forked'.
    • 'forked': forks a live network to initialize the environment state at the given date range. This mode requires more communication with an archive node and is more unpredictable when funding agents with tokens, but it is faster to intialize state, especially at later start dates.
    • 'local': deploys contracts locally to initialize the environment state at the given date range. This mode requires less communication with an archive node and is guaranteed stable when funding agents with tokens, but it can be slower to initialize state, especially at later start dates.
  • port: port to connect to the local chain. Defaults to find a free port.
  • token_data: optional dict containing token price data to pass to each agent, needed if you want to call the agent wealth methods. The dictionary has format:

    {
        "token_symbol": {
            datetime0: price0,
            datetime1: price1,
            ...
        },
        ...
    }
    
@final
class GmxV2Env(dojo.environments.base_environments.BaseEnvironment[dojo.actions.base_action.BaseAction[dojo.observations.gmxV2.GmxV2Observation], dojo.observations.gmxV2.GmxV2Observation]):

The GmxV2Env models the gmx v2 system dynamics.

GmxV2Env( chain: dojo.common.Chain, agents: list[dojo.agents.BaseAgent[dojo.observations.GmxV2Observation]], block_range: tuple[int, int], market_venues: list[dojo.models.gmxV2.market.MarketVenue], market_impact: Literal['replay', 'no_market'] = 'no_market', backend_type: Literal['forked', 'local', 'live'] = 'forked', port: Optional[int] = None, token_data: Optional[dict[str, dict[datetime.datetime, decimal.Decimal]]] = None, execution_delay: int = 10)

Instantiate a GmxV2Env object.

Parameters
  • chain: blockchain to use in the environment
  • agents: list of agents to use in the environment.
  • block_range: block range of the environment simulation.
  • market_venues: list of market venues to trade on.
  • market_impact: market impact model to use, one of: ['replay', 'no_market']. Defaults to 'replay'.
  • backend_type: type of backend to use, one of: ['forked', 'local', 'live']. Defaults to 'forked'.
    • 'forked': forks a live network to initialize the environment state at the given date range. This mode requires more communication with an archive node and is more unpredictable when funding agents with tokens, but it is faster to intialize state, especially at later start dates.
    • 'local': deploys contracts locally to initialize the environment state at the given date range. This mode requires less communication with an archive node and is guaranteed stable when funding agents with tokens, but it can be slower to initialize state, especially at later start dates.
  • port: port to connect to the local chain. Defaults to find a free port.
  • token_data: optional dict containing token price data to pass to each agent.
  • execution_delay: delay in blocks to wait before executing actions. Defaults to 10.
Raises
  • ValueError: If no HistoricReplayAgent is provided.