dojo.environments package

Environments package contains environment classes and logic.

class dojo.environments.AAVEv3Env(agents: List[BaseAgent], date_range: Tuple[datetime, datetime], backend_type: Literal['forked', 'local', 'live'] = 'forked', port: int | None = None, token_data: dict | None = None, market_impact: Literal['default'] = 'default')

Bases: BaseEnvironment

The AAVEv3Env environment models the AAVEv3Env system dynamics.

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

initialize_state()

Initialize.

setup_contracts_forked() List[str]

Setup contracts for a forked env.

setup_contracts_local()

Setup local version of the contracts.

class dojo.environments.BaseEnvironment(date_range: Tuple[datetime, datetime], agents: List[BaseAgent], backend_type: Literal['forked', 'local', 'live'] = 'forked', port: int | None = None, token_data: dict | None = None)

Bases: ABC

The BaseEnvironment class defines the template for all environments.

deploy_contract(contract_path: str, contract_name: str, constructor_args: list, compiler_version: str = 'latest') None

Deploy and register a contract on the local network.

Parameters:
  • contract_path – path to the contract .sol file.

  • contract_name – lookup name of the contract to deploy.

  • constructor_args – list of contract constructor arguments.

  • compiler_version – solc compiler version to use.

disconnect() None

Disconnect and close the connection to the local dojo network.

abstract initialize_state()

Initialize the state of the environment.

iter_block(batch_size: int = 0) Generator[int, None, None]

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

market_actions(agents_actions: List[BaseAction]) List[BaseAction]

Predict the market actions of the current block.

Parameters:

agents_actions – The actions from the policies of the other agents.

reset() BaseObs

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.

abstract setup_contracts_forked() List[str]

Register contracts on the forked network.

Returns:

a list of contracts to approve for ERC20 transfers.

abstract setup_contracts_local() List[str]

Deploy and register contracts on the local network.

Returns:

a list of contracts to approve for ERC20 transfers.

step(actions: List[BaseAction]) Tuple[BaseObs, ndarray, ndarray, dict]

Execute a sequence of actions in the environment in list order.

Parameters:

actions – in order sequence of actions to execute.

Return next_obs:

next observation.

Return rewards:

array of rewards for each agent.

Return dones:

array of done flags for each agent.

Return infos:

dict of info for each agent.

class dojo.environments.UniV3Env(agents: List[BaseAgent], date_range: Tuple[datetime, datetime], pools: List[str], market_impact: Literal['replay', 'no_market'] = 'replay', backend_type: Literal['forked', 'local', 'live'] = 'forked', dataloader: BaseLoader | Literal['auto'] | None = 'auto', port: int | None = None, token_data: dict | None = None)

Bases: BaseEnvironment

The UniV3Env environment models the UniswapV3 system dynamics.

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

MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342
MAX_TICK = 887272
MIN_SQRT_RATIO = 4295128739
MIN_TICK = -887272
POOL_SIZE = 2
initialize_state()

Initialize the state of the environment.

setup_contracts_forked() List[str]

Register contracts on the forked network.

Returns:

a list of contracts to approve for ERC20 transfers.

setup_contracts_local() List[str]

Deploy and register contracts on the local network.

Returns:

a list of contracts to approve for ERC20 transfers.

Submodules

Simulation environement for AAVEv3.

class dojo.environments.aaveV3.AAVEv3Env(agents: List[BaseAgent], date_range: Tuple[datetime, datetime], backend_type: Literal['forked', 'local', 'live'] = 'forked', port: int | None = None, token_data: dict | None = None, market_impact: Literal['default'] = 'default')

Bases: BaseEnvironment

The AAVEv3Env environment models the AAVEv3Env system dynamics.

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

initialize_state()

Initialize.

setup_contracts_forked() List[str]

Setup contracts for a forked env.

setup_contracts_local()

Setup local version of the contracts.

class dojo.environments.aaveV3.AaveV3MarketModelType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

This enum defines the types of market impact models available.

Attr NO_MARKET:

The no market impact model does nothing. :attr REPLAY: The replay

market impact model replays history.

DEFAULT = 'default'

Base Environments defines the template for all environments.

class dojo.environments.base_environments.BaseEnvironment(date_range: Tuple[datetime, datetime], agents: List[BaseAgent], backend_type: Literal['forked', 'local', 'live'] = 'forked', port: int | None = None, token_data: dict | None = None)

Bases: ABC

The BaseEnvironment class defines the template for all environments.

deploy_contract(contract_path: str, contract_name: str, constructor_args: list, compiler_version: str = 'latest') None

Deploy and register a contract on the local network.

Parameters:
  • contract_path – path to the contract .sol file.

  • contract_name – lookup name of the contract to deploy.

  • constructor_args – list of contract constructor arguments.

  • compiler_version – solc compiler version to use.

disconnect() None

Disconnect and close the connection to the local dojo network.

abstract initialize_state()

Initialize the state of the environment.

iter_block(batch_size: int = 0) Generator[int, None, None]

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

market_actions(agents_actions: List[BaseAction]) List[BaseAction]

Predict the market actions of the current block.

Parameters:

agents_actions – The actions from the policies of the other agents.

reset() BaseObs

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.

abstract setup_contracts_forked() List[str]

Register contracts on the forked network.

Returns:

a list of contracts to approve for ERC20 transfers.

abstract setup_contracts_local() List[str]

Deploy and register contracts on the local network.

Returns:

a list of contracts to approve for ERC20 transfers.

step(actions: List[BaseAction]) Tuple[BaseObs, ndarray, ndarray, dict]

Execute a sequence of actions in the environment in list order.

Parameters:

actions – in order sequence of actions to execute.

Return next_obs:

next observation.

Return rewards:

array of rewards for each agent.

Return dones:

array of done flags for each agent.

Return infos:

dict of info for each agent.

Simulation environement for AAVEv3.

class dojo.environments.multi_env.MultiEnv(date_range: Tuple[datetime, datetime], agents: List[BaseAgent], backend_type: Literal['forked', 'local', 'live'] = 'forked', port: int | None = None, token_data: dict | None = None)

Bases: BaseEnvironment

The AAVEv3Env environment models the AAVEv3Env system dynamics.

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

initialize_state()

Initialize.

reset() BaseObs

Reset.

setup_contracts_forked() List[str]

Setup contracts on forked backend.

setup_contracts_local()

Setup contracts on local backend.

Uniswap V3 environment.

class dojo.environments.uniswapV3.UniV3Env(agents: List[BaseAgent], date_range: Tuple[datetime, datetime], pools: List[str], market_impact: Literal['replay', 'no_market'] = 'replay', backend_type: Literal['forked', 'local', 'live'] = 'forked', dataloader: BaseLoader | Literal['auto'] | None = 'auto', port: int | None = None, token_data: dict | None = None)

Bases: BaseEnvironment

The UniV3Env environment models the UniswapV3 system dynamics.

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

MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342
MAX_TICK = 887272
MIN_SQRT_RATIO = 4295128739
MIN_TICK = -887272
POOL_SIZE = 2
initialize_state()

Initialize the state of the environment.

market_model: BaseMarketModel
setup_contracts_forked() List[str]

Register contracts on the forked network.

Returns:

a list of contracts to approve for ERC20 transfers.

setup_contracts_local() List[str]

Deploy and register contracts on the local network.

Returns:

a list of contracts to approve for ERC20 transfers.

class dojo.environments.uniswapV3.UniV3MarketModelType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

This enum defines the types of market impact models available.

Attr NO_MARKET:

The no market impact model does nothing. :attr REPLAY: The replay

market impact model replays history.

NO_MARKET = 'no_market'
REPLAY = 'replay'