dojo.agents package

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

class dojo.agents.BaseAgent(initial_portfolio: Dict[str, Decimal], name: str | None = None)

Bases: ABC

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.

DEFAULT_ETH = Decimal('10')
add_asset(asset: str) None

Need to keep track of which assets the agent has.

add_nft(token: str, token_id: int)

Need to keep track of which NFTs the agent has.

approve(grantee: str, token: str) TxReceipt

Approve a grantee to spend ERC20 tokens on the agent’s behalf.

Parameters:
  • grantee – the grantee contract name.

  • token – the token symbol.

cache(token_data: dict) None

Cache token price data.

create_web3_account() None

Create an on-chain account associated with this agent.

done() bool

Get the agent done.

erc20_portfolio() Dict[str, Decimal]

Get the agent portfolio of ERC20 tokens.

erc20_wealth(date: datetime) float

Get the agent wealth of ERC20 tokens in $.

erc721_portfolio() Dict[str, list]

Get the agent portfolio of ERC721 NFTs.

fund_erc20(token: str, source: str, quantity: Decimal | int) None

Transfer quantity ERC20 tokens from the source address to the agent.

fund_erc721(token: str, token_id: int, source: str) None

Transfer token_id NFT from the source address to the agent.

fund_eth(quantity: Decimal) None

Transfer quantity ETH to the agent.

info() dict

Get the agent info.

portfolio() Dict[str, Decimal]

Get the agent portfolio.

quantity(token: str) Decimal

Get the agent quantity of a token.

Token:

The token symbol or address.

abstract reward(obs: BaseObs) float

Get the agent reward.

Parameters:

obs – The observation from the environment.

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.

set_backend(backend: BaseBackend)

Set the agent backend.

set_id(id: int) None

Set the agent ID.

setup()

Setup the agent on-chain account and initialize the token portfolio.

Raises:

NotImplementedError – if backend type is not recognized.

wealth(date: datetime) float

Get the agent wealth in $.

class dojo.agents.DummyAgent

Bases: BaseAgent

A placeholder agent that does nothing.

reward(obs: BaseObs) float

No reward for the dummy agent.

class dojo.agents.MarketAgent

Bases: BaseAgent

This agent executes the actions given by the market impact model.

DEFAULT_ETH = Decimal('500000000')
reward(obs: BaseObs) float

No reward for replay agent.

Parameters:

obs – The observation from the environment.

set_obs(obs: BaseObs) None

Set the observation for the agent.

Parameters:

obs – The observation from the environment.

setup()

TODO.

Submodules

Base agent class for all agents.

class dojo.agents.base_agent.BaseAgent(initial_portfolio: Dict[str, Decimal], name: str | None = None)

Bases: ABC

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.

DEFAULT_ETH = Decimal('10')
add_asset(asset: str) None

Need to keep track of which assets the agent has.

add_nft(token: str, token_id: int)

Need to keep track of which NFTs the agent has.

approve(grantee: str, token: str) TxReceipt

Approve a grantee to spend ERC20 tokens on the agent’s behalf.

Parameters:
  • grantee – the grantee contract name.

  • token – the token symbol.

cache(token_data: dict) None

Cache token price data.

create_web3_account() None

Create an on-chain account associated with this agent.

done() bool

Get the agent done.

erc20_portfolio() Dict[str, Decimal]

Get the agent portfolio of ERC20 tokens.

erc20_wealth(date: datetime) float

Get the agent wealth of ERC20 tokens in $.

erc721_portfolio() Dict[str, list]

Get the agent portfolio of ERC721 NFTs.

fund_erc20(token: str, source: str, quantity: Decimal | int) None

Transfer quantity ERC20 tokens from the source address to the agent.

fund_erc721(token: str, token_id: int, source: str) None

Transfer token_id NFT from the source address to the agent.

fund_eth(quantity: Decimal) None

Transfer quantity ETH to the agent.

id: int
info() dict

Get the agent info.

portfolio() Dict[str, Decimal]

Get the agent portfolio.

quantity(token: str) Decimal

Get the agent quantity of a token.

Token:

The token symbol or address.

abstract reward(obs: BaseObs) float

Get the agent reward.

Parameters:

obs – The observation from the environment.

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.

set_backend(backend: BaseBackend)

Set the agent backend.

set_id(id: int) None

Set the agent ID.

setup()

Setup the agent on-chain account and initialize the token portfolio.

Raises:

NotImplementedError – if backend type is not recognized.

wealth(date: datetime) float

Get the agent wealth in $.

A placeholder agent that does nothing.

class dojo.agents.dummy_agent.DummyAgent

Bases: BaseAgent

A placeholder agent that does nothing.

reward(obs: BaseObs) float

No reward for the dummy agent.

Market agent to represent the state of the market.

class dojo.agents.market_agent.MarketAgent

Bases: BaseAgent

This agent executes the actions given by the market impact model.

DEFAULT_ETH = Decimal('500000000')
id: int
reward(obs: BaseObs) float

No reward for replay agent.

Parameters:

obs – The observation from the environment.

set_obs(obs: BaseObs) None

Set the observation for the agent.

Parameters:

obs – The observation from the environment.

setup()

TODO.