# Integrating Aave: Yield and Its Tradeoffs

Author: Markus Waas

Published: 2020-08-08T23:15:32.000Z

Updated: 2026-09-13T14:25:30.000Z

Source: [https://soliditydeveloper.com/integrate-aave](<https://soliditydeveloper.com/integrate-aave>)

## Compatibility and review

Before you start

Historical Aave v1/Kovan example. The original wrapper has been withdrawn: it overwrote repeated deposits, used the wrong outbound token operation and omitted safe accounting and interest allocation. Current Aave versions require their own Pool APIs and deployment addresses; lending carries loss and withdrawal-liquidity risks.

[Official reference](<https://aave.com/docs/aave-v3/smart-contracts/pool>)

If you're writing contracts that use, hold or manage user funds, you might want to consider using those funds for potentially generating yield, subject to explicit user expectations and protocol risks. What's the catch?

![free money](<https://cdn0.scrvt.com/b095ee27d37b3d7b6b150adba9ac6ec8/46f0a594ed4fef79/e375e6dddfee/v/4f65e7bb648f/free-money.jpeg>)

Yield is compensation for taking risks, and keeping funds liquid can be an intentional requirement. The decision belongs in the product’s documented custody and risk model. The way these lender/borrower systems work is quite simple conceptually. Once you understand the mechanism and risk involved, you can decide if it's worth it for you or not.

## How those Defi markets work

The lending platforms have significantly risen over the last 1-2 years. The core idea in all of them is the same even though the implementations might differ a lot. We will be using [Aave](<https://aave.com/>) mostly as example, but you may have heard of other platforms as well such as [Maker](<https://makerdao.com/>), [Compound](<https://compound.finance/>), [dYdX](<https://dydx.exchange/>), [BlockFi](<https://blockfi.com/>) or [Curve](<https://www.curve.fi/>).

Aave is an Ethereum-based pooled-liquidity money market protocol for different tokens. This means you can either borrow a token on Aave or lend it. All borrowers are paying a fee to the lenders and that's where the interests come from. The exact rates can vary and the available rate modes depend on the version. The current V3 borrow API specifies variable rate mode.  
  
In return for lending tokens the lenders receive a respective interest-earning version of the token, e.g., [aTokens](<https://docs.aave.com/developers/developing-on-aave/the-protocol/atokens>) in Aave or [cTokens](<https://compound.finance/ctokens>) in Compound. In Aave your aToken balance will automatically increase over time and you can later trade back 1 aToken to 1 original token. That's in contrast to Compound where simply the exchange rate back to the original token changes over time, but your cToken balance won't change. The result will be the same, but the smart contract integration will be slightly different.

**What about the latest trend of yield farming?**

You might heard of [yield farming](<https://www.forbes.com/sites/leeorshimron/2020/06/22/defi-yield-farmers-and-crypto-investors-are-raking-in-100-annualized-yields/#56a4a5b25eb5>) and the Compound's [COMP token](<https://compound.finance/governance/comp>). If you are lending out money or borrowing money you will receive the COMP token for free on top. Similarly Aave has a [new token coming up](<https://medium.com/aave/aavenomics-eeab650cccc2>). They are intended to be used for governance for the protocol, but you could also just sell them. How to integrate those depends on the system. In the original 2020 context, the AAVE governance-token transition was still upcoming; this goes beyond the scope of the article, but if you want to optimize every little bit of income, then you want to make sure you retrieve those as well once it's possible.

**What happens if a borrower runs out of money?**  

You can imagine that at some point the collateral of a borrower might loose too much in value. Liquidation eligibility depends on the configured collateral thresholds and health factor; it can arise before collateral value falls below debt value.

![defi-brillator](<https://cdn0.scrvt.com/b095ee27d37b3d7b6b150adba9ac6ec8/8d35801de369610b/eda5b214e574/v/4faf71486ca6/defi-brillator.jpg>)

That's why those positions will be automatically liquidated. If a liquidation happens too late it could be a potential security problem. To prevent such a scenario, there exist automated liquidator bots. Great, now we know how it works, but how can you actually use it?

## How to integrate Aave

You can visit:

- [https://app.aave.com/](<https://app.aave.com/>) for the mainnet
- [https://testnet.aave.com/](<https://testnet.aave.com/>) for the testnet version.

  

The web app allows you to manually deposit or borrow tokens and is a great way to get your first experience.

![Aave app](<https://cdn0.scrvt.com/b095ee27d37b3d7b6b150adba9ac6ec8/50a3a6aa3fdcddeb/c911c02539fd/v/2329c9ae21d1/Aave-app.png>)

### Integrating it into smart contracts

The original integration used Aave v1: deposit into its lending pool and redeem through the aToken. Those method signatures and Kovan addresses are historical. For a V3 integration, begin with the [Pool supply and withdraw documentation](<https://aave.com/docs/aave-v3/smart-contracts/pool>) and the deployment address for the selected chain and market. Version changes require more than replacing addresses.

```solidity
// Historical Aave v1/Kovan wrapper withdrawn in the 2026 review.
// Repeated deposits overwrote accounting, outbound transferFrom was wrong,
// and withdrawal/interest accounting was incomplete.
// A current integration needs version-specific Pool APIs, tested share
// accounting, token handling and explicit withdrawal-failure behavior.
// Reference: https://aave.com/docs/aave-v3/smart-contracts/pool
```

The conceptual lifecycle is still supply, accrue and withdraw. The wrapper is withdrawn because those steps also need correct per-user accounting, token transfers, liquidity handling and a clear policy for the accrued interest.

### What to do with the interests

Remember that Aave automatically increases the aToken balance. So if we allow a user to only withdraw what they deposited, we just loose all the extra aTokens since they are now stuck in our contract. You have two options how you could handle this:

1. Use all extra interests and do something with them.
2. Or return them fairly to users. One fun way you could achieve this is by minting new tokens that represent ownership of deposited funds in your contracts. For any withdrawal a user burns the tokens again. Then you can see how much of the total supply those tokens are and refund them an equal share of the current aToken balance.  

### Know that redeems can fail

If you read the Aave documentation for the `redeem` function, it states

`redeem() will fail if the aTokens to be redeemed are being used as collateral. Please refer to the transferAllowed() function to understand how to check if a specific redeem/transfer action can be performed.`  

Collateral restrictions and insufficient available liquidity are different reasons a withdrawal can fail. Protocol pauses, asset behavior and other conditions can matter too. Do not promise that a retry will succeed at a particular time; the application needs explicit behavior when funds cannot be withdrawn.

## How to choose a market

Well this really depends and everything comes with a trade-off. For a good overview of lending rates, check out the 30 Day Averages on [https://defirate.com/lend/](<https://defirate.com/lend/>).

![Defirate](<https://cdn0.scrvt.com/b095ee27d37b3d7b6b150adba9ac6ec8/b934616740dbab99/2f9654afb978/v/66467407f938/Defirate.png>)

## A future of possibilities

Those new markets enable completely new business models that weren't thinkable before. We are living in exciting times and new ideas come up literally every week. It's no better time to start your own idea than now!  
  
 I actually have been involved in one new project myself. It hasn't been officially announced yet, so I can't give away too much. But you may want to look at [https://magicbet.io/](<https://magicbet.io/>) (placeholder website should hopefully be working by the time you read this) and keep an eye open for it. Maybe you can already guess what it's all about after reading the post and given its name. ;)
