dojo.environments
Environments package contains environment classes and logic.
The BaseEnvironment
class defines the template for all environments.
Initialize the environment.
Parameters
- date_range: date range of the environment simulation.
- agents: list of agents to use in the environment.
- backend_type: type of backend to use, one of: ['forked', 'local', 'live'].
- port: port to connect to the local chain. Defaults to find a free port.
token_data: optional dict containing token 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 backend_type not implemented or recognized
Sets up the contract on the forked network.
Parameters
- env_name (str): Name of the environment, e.g. UniswapV3, AaveV3.
- contract_name (str): Name of the contract.
Sets up the contract on the local network.
Parameters
- env_name (str): Name of the environment, e.g. UniswapV3, AaveV3.
- contract_name (str): Name of the contract.
args (list, optional): Arguments to be passed to the constructor of the contract. Defaults to [].
method (str, optional): method to use for contract deployment:
- "standard": use the contract constructor
- "alternate": use the contract creation code. Defaults to "standard".
Register contracts on the forked network.
Returns
a list of contracts to approve for ERC20 transfers.
Deploy and register contracts on the local network.
Returns
a list of contracts to approve for ERC20 transfers.
Reset the environment and agents before returning the observation object.
This method needs to be called before any simulation in order to setup the on- chain infrastructure.
Iterate over the simulation period one block at a time.
This also sets the date and block attributes of the environment.
Parameters
- batch_size: parameter for
ethereumetl.export_blocks_and_transactions
see https://ethereum-etl.readthedocs.io/en/latest/commands/. If set to 0, will NOT get the date information for each block. :yield: block number.
Raises
- Exception: batched no longer supported
Predict the market actions of the current block.
Parameters
- agents_actions: The actions from the policies of the other agents.
Execute a sequence of actions in the environment in list order.
Parameters
- actions: in order sequence of actions to execute.
Returns
next observation.
Returns
array of rewards for each agent.
Returns
array of done flags for each agent.
Returns
dict of info for each agent.
The UniswapV3Env environment models the UniswapV3 system dynamics.
It is responsible for updating both the protocol and agent states through time.
Instantiate a UniswapV3Env object.
Parameters
- date_range: date range of the environment simulation.
- agents: list of agents to use in the environment.
- pools: list of pool names to use in the environment.
- 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.
- dataloader: optional dataloader instance to use for loading events data. You'll need to provide this if you want to run a simulation with pools that are not listed in the docs https://compasslabs.github.io/docs/tutorial/environments/UniswapV3#supported-pools.
- 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.
The AAVEv3Env environment models the AAVEv3Env system dynamics.
It is responsible for updating both the protocol and agent states through time.
Instantiate a AAVEv3Env object.
Parameters
- date_range: date range of the environment simulation.
- agents: list of agents 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 backend_type is unsupported.
- ValueError: If the market impact model is unsupported.
- NotImplementedError: If the environment is compiled.
The GmxV2Env models the gmx v2 system dynamics.
Instantiate a GmxV2Env object.
Args: chain: blockchain to use in the environment agents: list of agents to use in the environment. date_range: date 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.