Price Oracle

Throughout the Aave Protocol, we require reliable, up to date, and secure price feeds. Our proxy price provider contract provides this capability and works by:

  1. First checking for a price from a Chainlink aggregator.

  2. If the price is below or equal to zero, we call our fallback price oracle.

    1. The fallback price oracle is currently maintained by the Aave team.

  3. In the future, Aave governance mechanisms will manage the selection of sources and the fallback price oracle.

The source code of the proxy price provider contract is available on Github.

Web3 code samples exclude the imports and transaction related parts to focus on methods interactions.

If you need development support, join the #developers channel on our Aave community Discord server.

Always get the latest price oracle address by calling getPriceOracle() on the LendingPoolAddressProvider contract.

View Methods

getAssetPrice()

function getAssetPrice(address _asset) public view returns(uint256)

Returns the price of the supported _asset in ETH wei units.

Parameter Name

Type

Description

_asset

address

address of the underlying asset

IPriceOracleGetter.sol
pragma solidity ^0.5.0;

/************
@title IPriceOracleGetter interface
@notice Interface for the Aave price oracle.*/
interface IPriceOracleGetter {
    function getAssetPrice(address _asset) external view returns (uint256);
    function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory);
    function getSourceOfAsset(address _asset) external view returns(address);
    function getFallbackOracle() external view returns(address);
}
YourContract.sol
pragma solidity ^0.5.0;

import "./IPriceOracleGetter.sol";

// ... rest of your contract ...

// Retrieve PriceOracle address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
address priceOracleAddress = provider.getPriceOracle();
IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);

address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 price = priceOracle.getAssetPrice(daiAddress);

getAssetsPrices()

function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory)

Returns any array of prices in ETH wei units.

Parameter Name

Type

Description

_assets

address[ ]

an array of addresses of the underlying assets

IPriceOracleGetter.sol
pragma solidity ^0.5.0;

/************
@title IPriceOracleGetter interface
@notice Interface for the Aave price oracle.*/
interface IPriceOracleGetter {
    function getAssetPrice(address _asset) external view returns (uint256);
    function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory);
    function getSourceOfAsset(address _asset) external view returns(address);
    function getFallbackOracle() external view returns(address);
}
YourContract.sol
pragma solidity ^0.5.0;

import "./IPriceOracleGetter.sol";

// ... rest of your contract ...

// Retrieve PriceOracle address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
address priceOracleAddress = provider.getPriceOracle();
IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);

// Add assets in question to addresses array
address[] memory addresses;
addresses[0] = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI;
addresses[1] = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); // mainnet USDC;
uint256[] memory prices = priceOracle.getAssetsPrices(addresses);

getSourceOfAsset()

function getSourceOfAsset(address _asset) external view returns(uint256)

Returns the address of the price source for _asset.

Parameter Name

Type

Description

_asset

address

address of the underlying asset

IPriceOracleGetter.sol
pragma solidity ^0.5.0;

/************
@title IPriceOracleGetter interface
@notice Interface for the Aave price oracle.*/
interface IPriceOracleGetter {
    function getAssetPrice(address _asset) external view returns (uint256);
    function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory);
    function getSourceOfAsset(address _asset) external view returns(address);
    function getFallbackOracle() external view returns(address);
}
YourContract.sol
import "./IPriceOracleGetter.sol";

// ... rest of your contract ...

// Retrieve PriceOracle address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
address priceOracleAddress = provider.getPriceOracle();
IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);

address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
address source = priceOracle.getSourceOfAsset(daiAddress);

getFallbackOracle()

function getFallbackOracle() external view returns(uint256)

Returns the address of the fallback oracle.

IPriceOracleGetter.sol
pragma solidity ^0.5.0;

/************
@title IPriceOracleGetter interface
@notice Interface for the Aave price oracle.*/
interface IPriceOracleGetter {
    function getAssetPrice(address _asset) external view returns (uint256);
    function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory);
    function getSourceOfAsset(address _asset) external view returns(address);
    function getFallbackOracle() external view returns(address);
}
YourContract.sol
import "./IPriceOracleGetter.sol";

// ... rest of your contract ...

// Retrieve PriceOracle address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
address priceOracleAddress = provider.getPriceOracle();
IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);

address fallback = priceOracle.getFallbackOracle();

IPriceOracleGetter ABI

IPriceOracleGetter.json
[
    {
      "inputs": [
        {
          "internalType": "address[]",
          "name": "_assets",
          "type": "address[]"
        },
        {
          "internalType": "address[]",
          "name": "_sources",
          "type": "address[]"
        },
        {
          "internalType": "address",
          "name": "_fallbackOracle",
          "type": "address"
        }
      ],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "internalType": "address",
          "name": "asset",
          "type": "address"
        },
        {
          "indexed": true,
          "internalType": "address",
          "name": "source",
          "type": "address"
        }
      ],
      "name": "AssetSourceUpdated",
      "type": "event"
    },
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "internalType": "address",
          "name": "fallbackOracle",
          "type": "address"
        }
      ],
      "name": "FallbackOracleUpdated",
      "type": "event"
    },
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "internalType": "address",
          "name": "previousOwner",
          "type": "address"
        },
        {
          "indexed": true,
          "internalType": "address",
          "name": "newOwner",
          "type": "address"
        }
      ],
      "name": "OwnershipTransferred",
      "type": "event"
    },
    {
      "constant": true,
      "inputs": [],
      "name": "isOwner",
      "outputs": [
        {
          "internalType": "bool",
          "name": "",
          "type": "bool"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    },
    {
      "constant": true,
      "inputs": [],
      "name": "owner",
      "outputs": [
        {
          "internalType": "address",
          "name": "",
          "type": "address"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [],
      "name": "renounceOwnership",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "internalType": "address",
          "name": "newOwner",
          "type": "address"
        }
      ],
      "name": "transferOwnership",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "internalType": "address[]",
          "name": "_assets",
          "type": "address[]"
        },
        {
          "internalType": "address[]",
          "name": "_sources",
          "type": "address[]"
        }
      ],
      "name": "setAssetSources",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "internalType": "address",
          "name": "_fallbackOracle",
          "type": "address"
        }
      ],
      "name": "setFallbackOracle",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "constant": true,
      "inputs": [
        {
          "internalType": "address",
          "name": "_asset",
          "type": "address"
        }
      ],
      "name": "getAssetPrice",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    },
    {
      "constant": true,
      "inputs": [
        {
          "internalType": "address[]",
          "name": "_assets",
          "type": "address[]"
        }
      ],
      "name": "getAssetsPrices",
      "outputs": [
        {
          "internalType": "uint256[]",
          "name": "",
          "type": "uint256[]"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    },
    {
      "constant": true,
      "inputs": [
        {
          "internalType": "address",
          "name": "_asset",
          "type": "address"
        }
      ],
      "name": "getSourceOfAsset",
      "outputs": [
        {
          "internalType": "address",
          "name": "",
          "type": "address"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    },
    {
      "constant": true,
      "inputs": [],
      "name": "getFallbackOracle",
      "outputs": [
        {
          "internalType": "address",
          "name": "",
          "type": "address"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    }
  ]

Last updated