line bg

Aave integration into Dojo

May 25, 2022

Introduction

We are excited to announce the integration of Aave into Dojo, our cutting-edge on-premises simulation and optimization platform for decentralised finance.

Compass Labs partnered with Aave on the Aave-Dojo integration, to empower users and web3 developers to access on-chain protocol data and simulate and optimize on-chain strategies and smart contracts in robust real worlds scenarios.

With dojo, you can interact seamlessly with Aave. We abstract the complexities introduced by Solidity away, and open up a simple Python interface to simulate and optimize an the EVM level.

Our newest release allows our users to perform simulations on AaveV3.

In this article we’ll dive into:

1. Aave Background
2. Dojo-Aave integration — key features
3. Release Details
4. Aave strategy example
5. Next steps
6. Learn more

Aave Background

Aave is a lending protocol. You can supply tokens as collateral and borrow a list of other tokens, secured via your collateral.

The health of your positions in Aave is characterized by the health factor. Should it ever drop below 1.0, Aave sells some of your collateral in exchange for the borrowed token. While this does not sound very exciting at first, it opens up a few opportunies. Firstly, you might get a different price for the borrowed token on Aave than e.g. on Uniswap, thus opening up arbitrage opportunities. Moreover, you can resupply a borrowed token and then borrow against it again, to effectivly create a leveraged position. See here.

Another major feature of Aave are flash loans. These are uncollateralized loans you’re allowed to take, as long as you pay them back in the same transaction.

Dojo-Aave integration — key features

With dojo, we allow you to interact seamlessly with AAVE. We abstract the complexities introduced by Solidity away, and open up a simple Python interface to run agent based simulations at the individual transaction level. Check our key features here:

1. Simulate strategies and monitor flow of funds on AaveV3

Dojo incorporates an agent and scenario based learning software that runs on blockchain forks to enable users to simulating strategies and monitoring funds’ flows directly on-premises.

2. Stress test market scenarios and find economic exploits

Dojo isn’t just for investors; it’s a powerful tool for smart contract developers to stress-testing market scenarios and understanding the economic risk of the protocol.

3. Understand the impact of different market scenarios on investment strategies

With Dojo, you can simulate and analyze strategies & liquidation events before deploying them under different market conditions, ensuring you’re well-prepared for market eventualities.

4. Check agent positions and protocol statistics in real-time

The real-time performance tracking on the Dojo dashboard enables monitoring of agent positions and protocol statistic on Aave to gain valuable insights into market dynamics as they unfold.

Release Details

With the current release we support:

Aave Strategy Example

Here’s how a dojo-policy for AAVE might look like:

def predict(obs: AaveV3Obs) -> List[BaseAction] # Supplying collateral if not self.supplied: self.supplied=True return [AAVEv3Supply( agent=self.agent, token_name="USDC", amount=Decimal("100_000") )] # If health factor is large, borrow more if obs.getUserAccountData(self.agent).healthFactor>2.0: return [AAVEv3BorrowToHealthFactor( agent=self.agent, token_name="WBTC", factor=1.2 )] # If health factor is getting small, repay some if obs.getUserAccountData(self.agent).healthFactor<1.2: return [AAVEv3RepayToHealthFactor( agent=self.agent, token_name="WBTC", factor=2.0 )] return []

In the picture below, you can see a screenshot of our simulation in action (via our custom dashboard). In this particular case, the day USDC depegged, borrowing to such a small health factor turned out too much, and so parts of the agents collateral got liquidated.

Next Steps

  • A simple action to execute a flash loan
  • Multi Environment Support: This will allow you to e.g. trade your flash loaned tokens on UniswapV3
  • Simulations using our local backend (much faster simulations)

Here’s an example of how you’d write a dojo-policy with multiple environments:

class MakeMeRichPolicy(BasePolicy): def trade_indicated(obs: MultiEnvObs) -> Bool: # Here's where your expertise comes in. # In each iteration, we give you the current state of the envs in `obs` # This function would identify trading opportunities # ... def predict(obs: MultiEnvObs) -> List[BaseAction] if trade_indicated(obs): # If trade is indicated, flashloan-borrow-trade-repay!! block_actions = [ AAVEv3FlashLoan( agent=self.agent, token_name="USDC", amount=Decimal("100_000") ), UniV3Trade( agent=self.agent, pool='USDC/WETH-0.05', quantities=(Decimal(100_000), Decimal(0)) ), # ... # More trades of your strategy # ... AAVEv3FlashLoanRepayAll( agent=self.agent, token_name="USDC" ) ] return block return []

Learn more

We are hiring!
webflow icon
All Templates