Yield Aware AMMs #102

Andre Cronje
Jul 15 · 3 min read

Let’s start with a basic example;

You have BAT, you have the following options;

  1. Supply BAT to Compound, earn interest + COMP
  2. Supply BAT to Aave, earn interest
  3. Sell 50% of your BAT for ETH, supply BAT+ETH to uniswap, earn fees ~ impermanent loss
  4. Sell 50% of your BAT for ETH, supply BAT+ETH to balancer, earn fees + BAL ~ impermanent loss

Adding one more layer of complexity;

Supply BAT to Compound, get cBAT, supply cBAT+ETH to balancer, earn fees + BAL ~ impermanent loss, and on the surface, you think you are earning COMP+cBAT interest.

The balancer pool is actually earning the COMP (you aren’t), and the balancer pool is earning the cBAT (which will be arbitraged away, so technically you are earning trading fees, but not cBAT interest. So even though the strategy seems smart, the net result is similar to BAT+ETH to balancer.

So we have identified the following problems;

  1. The pool (and not the LP) earns incentivized tokens. COMP, BAL, etc.
  2. The pool (and not the LP) earns interest on tokens.
  3. You had to sell 50% of your BAT exposure to fund a pool. (This one is critical to our solution, but will be discussed in a post on its own).

The above problem statement, makes it clear that current AMM (Automated Market Maker) pools can’t support our requirement, and we need a new yield aware AMM.

Supporting Aave tokens (aTokens) is easy enough, they support a function called redirectInterestStream, which allows you to configure an address to which the interest goes. This however does mean your interest is non compounding.

Image for post
Image for post

Compound tokens (cTokens) however grow in value based on their supply index, and such, are a bit more tricky to manage themselves. The AMM needs to be aware of the cTokens underlying value, instead of the cToken value, so all swaps, and quote checks need to measure the underlying, and not the raw token.

The cToken solution also works for the aToken solution and fixes the compounding issue.

So this change to the AMM allows it to trade BAT/ETH while actually holding cBAT or aBAT.

The solution for COMP is fairly straight forward, we measure COMP balance changes on every internal balance (cBAT) change and assign an index.

Image for post
Image for post

However, we want to support any token that might be added in the future, and also allow for distributions that don’t occur on balance changes. So we modify the above to be generic for any token requested, and we add an address lookup for core supported tokens.

The above is building block number 1, the yield aware AMM. It’s able to allow LP’s to earn interest from the highest yield paying lender, while earning incentivized tokens (such as COMP).

Next post will detail how we managed to get rid of selling 50% of your token, and how you can keep your exposure 100% in a single asset.


yearn.finance defi made simple

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store