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:

Aave Market
Uniswap Market
Aave Market
  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.

Uniswap Market
  1. Checking for a price from our Uniswap price aggregator.

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

The source code of the Uniswap price aggregator 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

Solidity
JavaScript
Solidity
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 = LendingPool(provider.getPriceOracle());
IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 price = priceOracle.getAssetPrice(daiAddress);
JavaScript

IPriceOracle ABI

import IPriceOracleABI from "./IPriceOracleGetter.json"
// From https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
// ... The rest of your code ...
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest PriceOracle address
const priceOracleAddress = await lpAddressProviderContract.methods
.getPriceOracle()
.call()
.catch((e) => {
throw Error(`Error getting priceOracle address: ${e.message}`)
})
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet DAI
// Get the asset price
const priceOracleContract = new web3.eth.Contract(IPriceOracleABI, priceOracleAddress)
const price = await priceOracleContract.methods
.getAssetPrice(daiAddress)
.call()
.catch((e) => {
throw Error(`Error getting priceOracle price: ${e.message}`)
})

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

Solidity
JavaScript
Solidity
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 = LendingPool(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);
JavaScript

IPriceOracle ABI

import IPriceOracleABI from "./IPriceOracleGetter.json"
// From https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
// ... The rest of your code ...
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest PriceOracle address
const priceOracleAddress = await lpAddressProviderContract.methods
.getPriceOracle()
.call()
.catch((e) => {
throw Error(`Error getting priceOracle address: ${e.message}`)
})
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet DAI
const usdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' // mainnet USDC
// Get the asset prices
const priceOracleContract = new web3.eth.Contract(IPriceOracleABI, priceOracleAddress)
const prices = await priceOracleContract.methods
.getAssetsPrices([daiAddress, usdcAddress])
.call()
.catch((e) => {
throw Error(`Error getting priceOracle prices: ${e.message}`)
})

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

Solidity
JavaScript
Solidity
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 = LendingPool(provider.getPriceOracle());
IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
address source = priceOracle.getSourceOfAsset(daiAddress);
JavaScript

IPriceOracle ABI

import IPriceOracleABI from "./IPriceOracleGetter.json"
// From https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
// ... The rest of your code ...
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest PriceOracle address
const priceOracleAddress = await lpAddressProviderContract.methods
.getPriceOracle()
.call()
.catch((e) => {
throw Error(`Error getting priceOracle address: ${e.message}`)
})
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet DAI
// Get source for asset
const priceOracleContract = new web3.eth.Contract(IPriceOracleABI, priceOracleAddress)
const source = await priceOracleContract.methods
.getSourceOfAsset(daiAddress)
.call()
.catch((e) => {
throw Error(`Error getting priceOracle source for asset: ${e.message}`)
})

getFallbackOracle()

function getFallbackOracle() external view returns(uint256)

Returns the address of the fallback oracle.

Solidity
JavaScript
Solidity
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 = LendingPool(provider.getPriceOracle());
IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);
address fallback = priceOracle.getFallbackOracle();

JavaScript

IPriceOracle ABI

import IPriceOracleABI from "./IPriceOracleGetter.json"
// From https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
// ... The rest of your code ...
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
// Get the latest PriceOracle address
const priceOracleAddress = await lpAddressProviderContract.methods
.getPriceOracle()
.call()
.catch((e) => {
throw Error(`Error getting priceOracle address: ${e.message}`)
})
// Get fallback oracle address
const priceOracleContract = new web3.eth.Contract(IPriceOracleABI, priceOracleAddress)
const fallbackOracle = await priceOracleContract.methods
.getFallbackOracle()
.call()
.catch((e) => {
throw Error(`Error getting priceOracle fallback: ${e.message}`)
})

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"
}
]