Monitoring a live position on AAVE.

Dojo makes is very easy to change from a backtest simulation to a live monitoring seamlessly.


Specifying the Agents

As described in Runners, monitoring follows much the same patterns as backtesting. In monitoring, dojo is connecting to a live RPC node. Your agent works much the same as in backtesting. There still is a predict function that runs on every new block.

The only difference is that an agent in a monitoring run will never execute any actions on chain.

In this example, we are using ImpersonationAgents to directly track the positions of 3 agents:

run.py
from dojo.agents.impersonation_agent import MonitoringAgent
run.py
class TrackHealthFactorAgent(MonitoringAgent):
  """An agent that displays health factor as its reward."""
 
  def __init__(
      self,
      impersonation_address: str,
      name: Optional[str] = None,
  ):
      """Initialize the agent."""
      super().__init__(
          name=name,
          impersonation_address=impersonation_address,
          unit_token="USDC",
          policy=AAVEv3Policy(),
      )
run.py
agent1 = TrackHealthFactorAgent(
  impersonation_address="0x9c1d67674dE93b71ea16893C95dDA6f4D266a2bC",
  name="Alice",
)

Instantiating a live environment

When we instantiate the environment, we need to set the backend type to live, so we can use monitor_run after. Note that we are not passing in any market agents. We are connecting to the live chain here. The world is our market agent.

run.py
env = AAVEv3Env(
  chain=chain,
  agents=[agent2, agent1, agent3],
  backend_type="live",  # `monitor_run` needs live backend
)

Running monitoring

Then, we can finally call monitor_run. Note that the function signature is nearly identical to backtest_run. This should make it incredibly easy to switch your simulation from backtesting to monitor running.

run.py
monitor_run(
  env,
  dashboard_server_port=dashboard_server_port,
  output_file="live_monitor_aave.db",
  auto_close=auto_close,
  stop_after_n_blocks=num_sim_blocks,
  simulation_title="Monitoring on AAVE",
  simulation_description="Monitoring on AAVE.",
)

Instead of specifying a start_block and end_block like in backtest_run, for monitor_run the start_block is implicitly defined by whenever to kick of the run. We then run for a specified number of n blocks.

The advantage of having defined 3 separate agents as opposed to one agent that exports 3 signals is that we can take full advantage of the dashboards agents tab. Replace this with ScreenshotLive of http://localhost:3000/dashboard?example=live_monitor_aave&menu=Agents