GithubHelp home page GithubHelp logo

aave / aave-v3-core Goto Github PK

View Code? Open in Web Editor NEW
812.0 34.0 536.0 18.9 MB

This repository contains the core smart contracts of the Aave V3 protocol.

Home Page: https://aave.com

License: Other

JavaScript 0.08% Dockerfile 0.01% Solidity 38.20% TypeScript 58.24% Shell 0.19% Ruby 2.78% Python 0.46% Makefile 0.04%
ethereum blockchain solidity defi

aave-v3-core's Introduction

Build pass codecov

        .///.                .///.     //.            .//  `/////////////-
       `++:++`              .++:++`    :++`          `++:  `++:......---.`
      `/+: -+/`            `++- :+/`    /+/         `/+/   `++.
      /+/   :+/            /+:   /+/    `/+/        /+/`   `++.
  -::/++::`  /+:       -::/++::` `/+:    `++:      :++`    `++/:::::::::.
  -:+++::-`  `/+:      --++/---`  `++-    .++-    -++.     `++/:::::::::.
   -++.       .++-      -++`       .++.    .++.  .++-      `++.
  .++-         -++.    .++.         -++.    -++``++-       `++.
 `++:           :++`  .++-           :++`    :+//+:        `++:----------`
 -/:             :/-  -/:             :/.     ://:         `/////////////-

Aave Protocol v3

This repository contains the smart contracts source code and markets configuration for Aave Protocol V3. The repository uses Docker Compose and Hardhat as development environment for compilation, testing and deployment tasks.

What is Aave?

Aave is a decentralized non-custodial liquidity markets protocol where users can participate as suppliers or borrowers. Suppliers provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an overcollateralized (perpetually) or undercollateralized (one-block liquidity) fashion.

Documentation

See the link to the technical paper or visit the Aave Developer docs

Audits and Formal Verification

You can find all audit reports under the audits folder

V3.0.1 - December 2022

V3 Round 1 - October 2021

V3 Round 2 - December 2021

Formal Verification - November 2021-January 2022

Connect with the community

You can join the Discord channel or the Governance Forum to ask questions about the protocol or talk about Aave with other peers.

Getting Started

You can install @aave/core-v3 as an NPM package in your Hardhat or Truffle project to import the contracts and interfaces:

npm install @aave/core-v3

Import at Solidity files:

import {IPool} from "@aave/core-v3/contracts/interfaces/IPool.sol";

contract Misc {

  function supply(address pool, address token, address user, uint256 amount) public {
    IPool(pool).supply(token, amount, user, 0);
    {...}
  }
}

The JSON artifacts with the ABI and Bytecode are also included in the bundled NPM package at artifacts/ directory.

Import JSON file via Node JS require:

const PoolV3Artifact = require('@aave/core-v3/artifacts/contracts/protocol/pool/Pool.sol/Pool.json');

// Log the ABI into console
console.log(PoolV3Artifact.abi)

Setup

The repository uses Docker Compose to manage sensitive keys and load the configuration. Prior to any action like test or deploy, you must run docker-compose up to start the contracts-env container, and then connect to the container console via docker-compose exec contracts-env bash.

Follow the next steps to setup the repository:

  • Install docker and docker-compose
  • Create an environment file named .env and fill the next environment variables
# Add Alchemy or Infura provider keys, alchemy takes preference at the config level
ALCHEMY_KEY=""
INFURA_KEY=""


# Optional, if you plan to use Tenderly scripts
TENDERLY_PROJECT=""
TENDERLY_USERNAME=""

Test

You can run the full test suite with the following commands:

# In one terminal
docker-compose up

# Open another tab or terminal
docker-compose exec contracts-env bash

# A new Bash terminal is prompted, connected to the container
npm run test

aave-v3-core's People

Contributors

aaafsfefgdd avatar bojidar00 avatar davidlaprade avatar defispartan avatar dorgeyer123 avatar eboadom avatar foodaka avatar ga-reth avatar github-actions[bot] avatar grothem avatar je55g avatar kartojal avatar kirk-baird avatar lherskind avatar michaelmorami avatar miguelmtzinf avatar omahs avatar princeibs avatar rex4539 avatar sakulstra avatar sendra avatar the-3d avatar zer0dot avatar zhoujia6139 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aave-v3-core's Issues

Gas-optimisation for Sentinel

We can optimize gas-usage related to the price oracle sentinel, by only retrieving from the AddressesProvider when active.
Update in Pool for liquidationCall, borrow and flashloan.

Update for liquidationCall is along the lines of replacing

_addressesProvider.getPriceOracleSentinel()

with

_reserves[debtAsset].configuration.getPriceOracleSentinelActive() 
  ? _addressesProvider.getPriceOracleSentinel()
  : address(0) 

Increase Isolation Mode precision

Right now the debt ceiling in isolation mode only account for the total debt ceiling in dollars. This means that anything below 1USD worth of debt is not accounted in the total debt ceiling. Increase this precision to two decimals so that debt ceiling precision is to the USD cent.

Refactor AaveProtocolDataProvider to make it multi-market

Currently the addressesProvider address is passed to the constructor, so it only works for 1 market.
Pass the addressesProvider as parameter to every function so can be used to extract info for multiple markets in the same network.

Remove cache.refreshDebt

cache.refreshDebt can be removed if the updated state (new total supply and avg stable rate in the case of stable debt) is returned by the mint/burn function. This reduces the code size and saves gas

Add integration tests

Add integration tests so it's easy for integrators know what is the current state of the protocol and also let us detect when we are adding breaking changes.

Add a complete suite of integration tests
or
Add tests cases focused on contract interfaces and events that functions should emit

Implement repayment with the aToken

repay can be extended to allow aToken repayments. Repayment with aTokens can be summarized as a withdraw (aToken burning) + repay, which does not change the final amount of underlying available. Therefore it can be implemented by simply burning the aTokens of the caller.

Upgrade the Pool

Rename functions and other pieces of code with references to LendingPool

fix PoolConfigurator unoptimized compile issue

The getReserveData of the PoolDataProvider fills the stack when returning every value unoptimized. Its use in the PoolConfigurator means that we cannot run coverage. To support this. Add a special function getATokenTotalSupply to the PoolDataProvider, and use that in the PoolConfigurator

Upgrade Liquidation Mechanisms

(See the original issue here)

The goal here is to allow liquidating entire loans if the health factor drops below a certain threshold.

Furthermore, this implements a new liquidation protocol fee.

This may also entail an upgrade of liquidation mechanisms to increase gas-efficiency and reduce the overhead caused by adding the liquidation protocol fee.

Add new supply function

Leave the existing deposit function as deprecated
Add a new supply function with a parameter to indicate if the the supplied asset is used as collateral.

Add a liquidation fee on the liquidation bonus

The idea is to allow the protocol to get a protocol fee on liquidation. The implementation should

  • add a liquidation fee configuration field to ReserveLogic. This parameter can go from 0 to 10000 - 10000 means the protocol gets the whole bonus.

  • calculates on the bonus obtained in liquidationCall() the amount corresponding to liquidationFee

  • Accumulates the amount on accruedToTreasury() if the liquidator chose not to receive atokens, and transfer the atoken to the treasury address if the liquidator chose to receive atokens.

Gas optimized flashloan for single asset

An optimized flashloan that allow a user to perform a flashloan with 1 asset. The asset cannot be added as a borrow and must be returned at the end of the call. Also, there will be no fee whitelist.

Implement the Aave Cross-Chain Liquidity Bridge

Goal

Create a cross-chain asset bridge that uses available Aave market liquidity to allow rapid withdrawals from multiple L2s to L1 Ethereum.

User Flow

See the following example:

  1. User has 1000 USDC on the Aave Arbitrum market and wants to bridge to L1 without waiting for the 7 day challenge period
  2. User interacts with the Arbitrum Aave cross-chain bridge entry contract, this contract...
    • Pulls the 1000 USDC from the bridge user
    • Interacts with the regular Arbitrum 7-day bridge, bridging the 1000 USDC normally
  3. User waits a given time period (probably a matter of minutes)
  4. User interacts with the Aave L1 cross-chain bridge, this contract...
    • Validates the corresponding L2's state using an oracle
    • Mints aTokens (in this case, aUSDC) to the user corresponding to the transferred amount minus a given fee
  5. After the 7 day challenge period is complete, a keeper bot (potentially incentivized with a portion of the fee) executes a transaction to deposit the bridged USDC into Aave.

Requirements

New Contracts

  1. L2 bridge entry point contract
  2. L1 bridge exit point contract

Existing Contracts

  1. Interest rate strategy contracts will need to take into account aToken balances in order to avoid double-counting when new aTokens are minted without underlying deposits.
  2. The L1 bridge exit point contract will need to be allowed to mint aTokens.

Potential Issues, Notes & Solutions

  1. Technically, the L2 bridge entry point contract does not need to validate that there is enough L1 liquidity, since aTokens are minted on L1.
  2. The L2 bridge does however need to somehow not surpass the supply cap of a given asset on L1, how can we fetch that data on L2, or is there an alternative?
  3. If the fixed bridging fee amounts to less than the accumulated interest of the minted aTokens over the duration, protocol depositors are technically losing out, and would have been better off without the bridge transaction.
  4. The fee will need to be largely distributed to the protocol depositors, which could cause potential accounting issues.

Include any other challenges, notes or thoughts about the design in the discussion below!

Inconsistent variable naming `new/next`

There are inconsistencies in the naming of variables for "future" values, especially rates. An example is ReserveLogic where we are using newLiquidityRate, newStableRate and newVariableRate while the ReserveCache struct uses nextLiquidityIndex etc.

Replace all names with new with the next counterpart

Remove global pause functions in Pool

Remove paused() and setPause() functions of Pool contract since there are no longer needed.
This feature was replaced by pause states for each reserve.

High efficiency mode

Implement high efficiency mode

Assets are classified in categories. Users have the ability to enable high efficiency mode, if they do, they can choose a category of assets they will deposit and borrow enjoying high borrowing power.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.