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:
First checking for a price from a Chainlink aggregator.
If the price is below or equal to zero, we call our fallback price oracle.​
The fallback price oracle is currently maintained by the Aave team.
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.
Checking for a price from our Uniswap price aggregator.
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.
function getAssetPrice(address _asset) public view returns(uint256)
Returns the price of the supported _asset
in ETH wei units.
Parameter Name | Type | Description |
| address | address of the underlying asset​ |
IPriceOracleGetter.solpragma 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.solpragma solidity ^0.5.0;​import "./IPriceOracleGetter.sol";​// ... rest of your contract ...​// Retrieve PriceOracle addressLendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instancesaddress priceOracleAddress = provider.getPriceOracle();IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);​address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAIuint256 price = priceOracle.getAssetPrice(daiAddress);​
​IPriceOracle ABI​
import IPriceOracleABI from "./IPriceOracleGetter.json"​// From https://docs.aave.com/developers/developing-on-aave/deployed-contract-instancesimport 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-instancesconst lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)​// Get the latest PriceOracle addressconst priceOracleAddress = await lpAddressProviderContract.methods.getPriceOracle().call().catch((e) => {throw Error(`Error getting priceOracle address: ${e.message}`)})​const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet DAI​// Get the asset priceconst 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}`)})
​
function getAssetsPrices(address[] calldata _assets) external view returns(uint256[] memory)
Returns any array of prices in ETH wei units.
Parameter Name | Type | Description |
| address[ ] | an array of addresses of the underlying assets​ |
IPriceOracleGetter.solpragma 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.solpragma solidity ^0.5.0;​import "./IPriceOracleGetter.sol";​// ... rest of your contract ...​// Retrieve PriceOracle addressLendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instancesaddress priceOracleAddress = provider.getPriceOracle();IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);​// Add assets in question to addresses arrayaddress[] memory addresses;addresses[0] = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI;addresses[1] = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); // mainnet USDC;uint256[] memory prices = priceOracle.getAssetsPrices(addresses);​
​IPriceOracle ABI​
import IPriceOracleABI from "./IPriceOracleGetter.json"​// From https://docs.aave.com/developers/developing-on-aave/deployed-contract-instancesimport 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-instancesconst lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)​// Get the latest PriceOracle addressconst priceOracleAddress = await lpAddressProviderContract.methods.getPriceOracle().call().catch((e) => {throw Error(`Error getting priceOracle address: ${e.message}`)})​const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet DAIconst usdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' // mainnet USDC​// Get the asset pricesconst 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}`)})
function getSourceOfAsset(address _asset) external view returns(uint256)
Returns the address of the price source for _asset
.
Parameter Name | Type | Description |
| address | address of the underlying asset​ |
IPriceOracleGetter.solpragma 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.solimport "./IPriceOracleGetter.sol";​// ... rest of your contract ...​// Retrieve PriceOracle addressLendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instancesaddress priceOracleAddress = provider.getPriceOracle();IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);​address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAIaddress source = priceOracle.getSourceOfAsset(daiAddress);
​IPriceOracle ABI​
import IPriceOracleABI from "./IPriceOracleGetter.json"​// From https://docs.aave.com/developers/developing-on-aave/deployed-contract-instancesimport 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-instancesconst lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)​// Get the latest PriceOracle addressconst priceOracleAddress = await lpAddressProviderContract.methods.getPriceOracle().call().catch((e) => {throw Error(`Error getting priceOracle address: ${e.message}`)})​const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet DAI​// Get source for assetconst 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}`)})
function getFallbackOracle() external view returns(uint256)
Returns the address of the fallback oracle.
IPriceOracleGetter.solpragma 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.solimport "./IPriceOracleGetter.sol";​// ... rest of your contract ...​// Retrieve PriceOracle addressLendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instancesaddress priceOracleAddress = provider.getPriceOracle();IPriceOracleGetter priceOracle = IPriceOracleGetter(priceOracleAddress);​address fallback = priceOracle.getFallbackOracle();​
​
​IPriceOracle ABI​
import IPriceOracleABI from "./IPriceOracleGetter.json"​// From https://docs.aave.com/developers/developing-on-aave/deployed-contract-instancesimport 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-instancesconst lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)​// Get the latest PriceOracle addressconst priceOracleAddress = await lpAddressProviderContract.methods.getPriceOracle().call().catch((e) => {throw Error(`Error getting priceOracle address: ${e.message}`)})​// Get fallback oracle addressconst 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.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"}]
​