Officer's Blog

Posted on Feb 20, 2023Read on Mirror.xyz

AAVE V3 DeFi Integration: Specifications

We continue our series of instructive articles with some special recommendations for developers using Aave V3 DeFi integration!

We understand and respect your limited time, therefore we created a specific article with nothing superfluous for an easier access!

See the Part I here:

https://officercia.mirror.xyz/DqRTkbCToO3_YpauiR8tJGQKI-kBJfg5ZUwfUkfjDNQ

By the way, here are some vacant slots so if your project needs an audit — feel free to write to us, visit our public reports page here!

Make sure to read the rest of the series:


Following the tips below can significantly improve the security of your project’s integration!

Liquidations:

1. Depending on the user’s health factor, you could liquidate up to 50% of your debt in Aave V2 but up to 100% of your debt in V3:

  • if HF <= 0.95, you can liquidate up to 100%.

  • if HF > 0.95, only up to 50% of the debt.

2. To get the user’s health factor data, use Pool.getUserAccountData(address user)

3. Liquidation interface: Pool.liquidationCall() in case of Ethereum and L2Pool.liquidationCall() in case of Optimism, Polygon, etc. The debtToCover parameter defines the number of tokens (debtAsset) that the liquidator wants to cover. You can pass uint(-1) to liquidate all the available debt.

4. Link to the Dune dashboard with liquidations. Here is a link to the Aave V2 VS Aave V3 dashboard.

5. There is also a subgraph service to define what kind of data they want The Graph to index from the blockchain and how the data will be stored.

6. Aave V3 Error Codes

E-mode:

When the prices of collateral and borrowed assets are correlated, the E-mode feature maximizes capital efficiency.

For example, DAI, USDC, and USDT are all stablecoins pegged to the USD. These stablecoins are all within the same E-mode category. As a result, a user who supplies DAI in E-mode will have higher collateralization power when borrowing assets such as USDC or USDT.

The tips below can help you significantly improve the security of your project’s integration:

1. The category with id=0 is the default category and it indicates that e-mode is disabled!

2. Pool.setUserEMode(uint8 _id) — is used to set the user’s efficiency mode to the category with id=_id. When one of the following occurs, the function is reverted:

  • The user owes one of the tokens that is not listed in the category.

  • Changing e-mode will shift the user’s health factor to the liquidation zone (i.e. HF < 1)

Siloed borrowing:

This feature allows assets with potentially manipulatable oracles (for example, illiquid Uni V3 pairs) to be listed on Aave as a single borrow asset, which means that if a user borrows a siloed asset, they cannot borrow any other asset. This helps mitigate the risk associated with such assets without impacting the overall solvency of the protocol.

The suggestions provided below can significantly improve the security of your project’s integration:

1. AaveProtocolDataProvider.getSiloedBorrowing(address asset) — is used to find out if the asset is in siloed borrowing mode or not.

Supply:

1. Pool.supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) — is used to supply an asset. Also keep in mind that:

  • The a-tokens are minted to the onBehalfOf address.

  • In referralCode you must enter 0, since the referral code feature is currently inactive.

  • At the moment of call, Pool contract must have an approve on amount of tokens from msg.sender.

2. Pool.supplyWithPermit(asset, amount, onBehalfOf, referralCode, deadline, V, R, S) — you have to remember to do supply, having erc-2612 permit signature.

3. To set an asset as collateral, call Pool.setUserUseReserveAsCollateral(asset, true).

4. Pool.withdraw(asset, amount, to) is used to withdraw the user’s underlying asset in such an amount that its health factor does not drop below 1 (maximum — amount). It also returns the number of tokens actually withdrawn (<= amount).

Borrow:

1. You can get the borrow rate for the required asset through AaveProtocolDataProvider.getReserveData(asset). The call will return the tuple, where indexes 7 and 8 will contain variable and stable borrow rates respectively. (scaled to 10²⁷)

2. Pool.borrow() — you must send msg.sender to onBehalfOf if there is no need to make a credit delegation.

3. To repay the loan in amount of the required number of debt tokens, call Pool.repay(asset, amount, rateMode, onBehalfOf), where asset is the underlying asset address, rateMode equals 1 for stable rate and 2 for variable rate. The onBehalfOf address has debt tokens burned, msg.sender pays the debt at its own cost. You must pass onBehalfOf=msg.sender if you pay your own debt (do not ever send a null/zero address!).

4. AaveProtocolDataProvider.getReserveTokensAddresses(asset) outputs a-token, stable-debt-token and variable-debt-token addresses. Debt-token addresses can be useful for credit delegation!

Credit delegation:

Credit delegation enables a depositor to deposit funds in the protocol in order to earn interest and to delegate borrowing power (i.e., their credit) to other users.

The depositor and borrower agree on the loan’s terms, which can be done off-chain through legal agreements or on-chain through smart contracts.

Keep in mind:

1. To approve the user’s loan, call .approveDelegation(address delegatee, uint amount) from the corresponding debt token. Then delegatee can delegate the loan of amount with Pool.borrow().

Isolation mode:

Isolation mode allows Aave Governance to list new assets as isolated assets, which have a specific debt ceiling. Only certain assets can be borrowed in isolation mode — specifically, approved stablecoins.

Assets are approved for borrowing after being voted on by AAVE token holders via the Aave Governance Forum. The debt ceiling for an isolated asset is represented as the maximum amount in USD that can be borrowed with two decimal places against the user’s collateral.

Follow these guidelines to make sure your project’s DeFi integration with Aave V3 is as safe as possible:

1. Although there is no external method available to know if the asset is in isolation mode, you can take the value which Pool.getConfiguration(asset) returns — which is uint256 — and then read bits 212–251 from it, which store the debt ceiling for an isolation mode. Keep in mind that if it is greater than zero, the asset is in isolation mode.

Main links:

Aave V3-specific:


We hope that this article was informative and useful for you! Thank you for reading!

https://blog.pessimistic.io/short-types-in-solidity-rare-tricks-uncovered-46b742c554c9

By the way, here are some vacant slots in the first quarter of 2023 now so if your project needs an audit — feel free to write to us, visit our public reports page here!


Support is very important to me, with it I can do what I love — educating users!

If you want to support my work, you can send me a donation to the address:

https://github.com/OffcierCia/support

Stay safe!

Aave