title: [ARFC] Aave Swap Upgrade
author: @TokenLogic - @MatthewGraham, @defiJesus & @efecarranza
created: 2023-11-02
Summary
Ths publication proposes that the Aave DAO engages TokenLogic to upgrade the Aave Swap Contract to include Limit Orders and TWAP swap functionality.
Motivation
The intial iteration of the Aave Swap contract includes the functionality to swap one asset for another within a pre-defined variance relative to Chainlink Oracle(s). ie: Chainlink Oracle +/- 50bps slippage including gas cost.
In recent proposals, the DAO has committed to using the Cowswap TWAP functionality to acquire AURA. This highlights a functionality gap on the Aave Swap contract. This publication proposes upgrading the swap contract to include TWAP functionality. The TWAP feature is to use the new Composable COW (Composable Conditional Orders). An example is shown below:
Alice wants to sell 12,000,000 DAI for at least 7500 WETH. She wants to do this using a TWAP, executing a part each day over a period of 30 days.
sellToken
= DAI
buytoken
= WETH
receiver
= address(0)
partSellAmount
= 12000000 / 30 = 400000 DAI
minPartLimit
= 7500 / 30 = 250 WETH
t0
= Nominated start time (unix epoch seconds)
n
= 30 (number of parts)
t
= 86400 (duration of each part, in seconds)
span
= 0 (duration of span, in seconds, or 0 for entire interval)
If Alice also wanted to restrict the duration in which each part traded in each day, she may set span to a non-zero duration. For example, if Alice wanted to execute the TWAP, each day for 30 days, however only wanted to trade for the first 12 hours of each day, she would set span to 43200 (ie. 60 * 60 * 12). Using span allows for use cases such as weekend or week-day only trading.
Whilst integration the TWAP functionality, this publication proposes adding Limit Order functionality. The lift to do so is minimal and it offers additional functionality. Limit Orders enable the DAO to swap one asset for a minimum amount of the received asset. ie: Swap 1 ETH for a minimum 1700 USDC.
To support the developers using the Aave Swap contract, this publication proposes creating a command-line interface (CLI) using Tenderly to verify if the swaps can be executed at prevailing market conditions. This tool serves the dual purpose of ascertaining the feasibility of a swap and help the developer to determine the appropriate slippage percentage to use.
Slippage in the context of COW Swap does not mean that it will be that number, COW Swap matches orders on a best case basis and the actual cost of the full transaction could be lower. The slippage mentioned here is a worst case scenario that takes into account both the counter-party’s price as well as gas costs. Slippage as commonly known could be 0.1% and 0.9% could be gas costs depending on the network utilization at the time of the swap, assuming a 1% slippage. Even allowing for 1% slippage, once executed, the total gas costs + real slippage might end up only being 0.5%.
Specification
TWAP Orders
Using Composable Cow upgrade the Aave Swap contract to perform TWAP swaps.
The details on Composable Cow can be found here.
This upgrade involves adding a Payload template and tests cases.
Limit Orders
Using the new price checker introduced by Milkman, upgrade the Aave Swap contract to perform limit order swap.
This upgrade involves adding a Payload template and tests cases.
Tenderly
Create a CLI tool that uses Tenderly to proactively verify the feasibility of proposed swaps.
This tool offers an approximate assessment of whether a trade with the specified parameters is attainable. It will return true
for a swap that is likely to succeed and false
if not likely to succeed. If not likely, then the user can check with a bigger slippage tolerance.
Could also extend it to suggest a slippage given the size of the order and market conditions.
We want to again reiterate that because of the nature of DAO governance, once the payload is executed, conditions might have changed so we always recommend extending a bit the MAX allowed slippage to account for this.
Funding
To facilitate the development, this publication seeks the following funding:
Funding Amount: $12,672.00 USD, to be paid in GHO.
Delivery Schedule: 5 weeks, which includes an estimated 2wk review period.
As part of our normal process, we intend to submit our work to @bgdlabs for review. We do this to ensure our work is of the highest quality.
The transfer of funds will occur with an AIP submission upon successfully completing the scope.
The Aave DAO is encouraged to vote on one of the following three options:
- YAE
- NAE
- ABSTAIN
Next Steps
- If consensus on ARFC stage is reached, escalate to ARFC snapshot stage.
- If ARFC snapshot stage outcome is YAE, TokenLogic will commence building the contracts.
- Upon delivering the scope, TokenLogic will submit a AIP to create an allowance or transfer for equivalent 12,672.00 USD settled in GHO.
The DAO is expected to uphold outcome of the Snapshot vote.
Copyright
Copyright and related rights waived via CC0.