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) None

Need to keep track of which NFTs the agent has.

approve(grantee: str, token: str) PendingTx

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[str, dict[datetime, Decimal]]) 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) Decimal

Get the agent wealth of ERC20 tokens in $.

erc721_portfolio() dict[str, list[int]]

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
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: Observation) 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) None

Set the agent backend.

set_id(id: int) None

Set the agent ID.

setup() None

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

Raises:

NotImplementedError – if backend type is not recognized.

setup_live() None

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

wealth(date: datetime) Decimal

Get the agent wealth in $.

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

Bases: BaseAgent

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.

get_liquidity_ownership_tokens() list[int]

Get the list of erc721 IDs representing our liquidity positions.

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')
account: Account
add_asset(asset: str) None

Need to keep track of which assets the agent has.

add_nft(token: str, token_id: int) None

Need to keep track of which NFTs the agent has.

approve(grantee: str, token: str) PendingTx

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[str, dict[datetime, Decimal]]) 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) Decimal

Get the agent wealth of ERC20 tokens in $.

erc721_portfolio() dict[str, list[int]]

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
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: Observation) 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) None

Set the agent backend.

set_id(id: int) None

Set the agent ID.

setup() None

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

Raises:

NotImplementedError – if backend type is not recognized.

setup_live() None

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

wealth(date: datetime) Decimal

Get the agent wealth in $.

Market agent to represent the state of the market.