dojo.agents

This module contains the agents that can be used in the Dojo environment.

class BaseAgent(abc.ABC, typing.Generic[~Observation]):

The BaseAgent class is the base class for all agents.

The agents can be viewed as part of the environment in that they are only responsible for handling their own state given new data, and do not make any decisions on how to act in the environment. They are effectively a data wrapper around the on-chain brownie accounts. You should override the reward() method to define the reward generating function for your agent.

BaseAgent( initial_portfolio: dict[str, decimal.Decimal], policy: Any, name: Optional[str] = None, write_results: bool = True)

Initialize the agent.

Parameters
  • initial_portfolio: initial asset portfolio to load at reset. e.g. {"ETH": Decimal(10), "USDC": Decimal(1000)}
  • name: optional name for the agent, if not set will use the class name.
def quantity(self, token: str) -> decimal.Decimal:

Get the agent quantity of a token.

Parameters
  • token: The token symbol or address.
def portfolio(self) -> dict[str, decimal.Decimal]:

Get the agent portfolio.

def erc20_portfolio(self) -> dict[str, decimal.Decimal]:

Get the agent portfolio of ERC20 tokens.

def erc721_portfolio(self) -> dict[str, list[int]]:

Get the agent portfolio of ERC721 NFTs.

def wealth(self, date: datetime.datetime) -> decimal.Decimal:

Get the agent wealth in $.

Parameters
  • date: the date to calculate the wealth at.
def erc20_wealth(self, date: datetime.datetime) -> decimal.Decimal:

Get the agent wealth of ERC20 tokens in $.

Parameters
  • date: the date to calculate the wealth at.
@abstractmethod
def reward(self, obs: ~Observation) -> float:

Get the agent reward.

Parameters
  • obs: The observation from the environment.
Returns

A user defined quantity which measures the agent's performance, to be recorded by Dojo.

There are many inbuilt methods and data structures that can be used to calculate the reward: - self.wealth(): agent wealth. - self.portfolio(): agent portfolio. - self.erc20_portfolio(): agent ERC20 portfolio. - self.erc721_portfolio(): agent ERC721 portfolio. - self.erc20_wealth(): agent ERC20 wealth.

The BaseAgent class is the base class for UniswapV3 agents.

Agents in UniswapV3 environments can inherit from BaseAgent instead, but will be missing certain helper methods.

def get_liquidity_ownership_tokens(self) -> list[int]:

Get the list of erc721 IDs representing our liquidity positions.

def total_wealth( self, obs: dojo.observations.UniswapV3Observation, unit_token: str) -> float:

Total wealth of the agent denoted in the unit_token.

Total wealth is everything the agents has ownership of. This means tokens in the agent's wallet as well as liquidity positions.

Parameters
  • obs: Uniswap observation that contains price information of the pools.
  • unit_token: Token in which the total wealth should be measured.