Skip to main content

Examples

Historical Data

We can fetch historical data by specifying a block number.

Query for liquidityRate by block number
{
reserves(block: {number: 23792785}) { # provide block number here
symbol
liquidityRate
}
}

Data of All Reserves

We can get a list of all the reserves that are able to be used as collateral, along with each reserve's interest rate details.

Query for all reserves
{
reserves(where: {usageAsCollateralEnabled: true}) {
id
name
price {
id
}
liquidityRate
variableBorrowRate
stableBorrowRate
}
}

Data of Specific Reserve

We can fetch data for a specific reserve using reserve's ERC20 token address. E.g. for the Chainlink reserve.

Query for a specific reserve
{
reserve(
id: "0x63a72806098bd3d9520cc43356dd78afe5d386d90xa97684ead0e402dc232d5a977953df7ecbab3cdb" # provide reserve address here
) {
symbol
price {
id
}
aToken {
id
}
}
}

Detailed Data of a Specific Reserve

We can fetch detailed data for a specific reserve by `lendingPoolAddressProvider` address for the market you are querying data for using the query below.

Query for detailed data of a specific reserve by pool address
{
reserves(where: {pool: "0xa97684ead0e402dc232d5a977953df7ecbab3cdb"}) { # provide pool address here
id
symbol
name
decimals
underlyingAsset
usageAsCollateralEnabled
reserveFactor
baseLTVasCollateral
averageStableRate
stableDebtLastUpdateTimestamp
liquidityIndex
reserveLiquidationThreshold
reserveLiquidationBonus
variableBorrowIndex
variableBorrowRate
liquidityRate
totalPrincipalStableDebt
totalScaledVariableDebt
lastUpdateTimestamp
availableLiquidity
stableBorrowRate
totalLiquidity
price {
priceInEth
}
}
}

Historic Interest Rate for a Specific Reserve

We can fetch historic interest rate data for a particular reserve and paginate through the records using the queery below.

Query of historic interest rate for a specific reserve
{
reserve(
id: "0x63a72806098bd3d9520cc43356dd78afe5d386d90xa97684ead0e402dc232d5a977953df7ecbab3cdb" # provide reserve address here
) {
id
paramsHistory(skip: 1000, first: 1000) {
id
variableBorrowRate
utilizationRate
liquidityRate
timestamp
}
}
}

User Reserve Data

We can fetch the details of a particular user reserve. When an address interacts with the Aave Protocol, an user reserve is created with the user ID being the user's address + the reserve's ID (which is the ERC20 token address).

Query of the user reserve data
{
userReserve(
id: "0x00000001b01122945d67cf7c972f1a2063ca40080xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e0xa97684ead0e402dc232d5a977953df7ecbab3cdb" # provide user's address + the reserve's ID
) {
reserve {
id
symbol
}
user {
id
}
}
}

All Reserves of an User

We can fetch all the reserves (i.e. positions) that a specific user has using the query below.

Query of the user's reserves
{
userReserves(where: {user: "0x00067c68c96f8bf2d2258630badf8e4379234179"}) { # provide user's address here
reserve {
id
symbol
underlyingAsset
}
scaledATokenBalance
usageAsCollateralEnabledOnUser
stableBorrowRate
scaledVariableDebt
principalStableDebt
stableBorrowLastUpdateTimestamp
user {
id
}
}
}

Recent Borrows for a Particular Asset

We can fetch recent borrows for a particular asset using the query below.

Query of the recent borrows for a particular asset
{
borrows(
orderBy: timestamp
orderDirection: desc
where: {reserve: "0x5947bb275c521040051d82396192181b413227a30xa97684ead0e402dc232d5a977953df7ecbab3cdb"} # provide reserve address here
) {
id
amount
timestamp
}
}

Recent Flash Loans

We can fetch the 5 most recent Flash Loans using the query below.

Query of the recent flash loans for a particular asset
{
flashLoans(first: 5, orderBy: timestamp, orderDirection: desc) {
id
reserve {
id
name
symbol
}
amount
totalFee
timestamp
}
}

User Transaction History

We can use the query below to get transaction history of a Aave user.

User Transaction History Query
{
userTransactions(
where: {user: "0x00067c68c96f8bf2d2258630badf8e4379234179"} # provide user address here
orderBy: timestamp
orderDirection: desc
) {
id
timestamp
txHash
action
... on RedeemUnderlying {
amount
reserve {
symbol
decimals
}
assetPriceUSD
}
... on Borrow {
amount
borrowRateMode
borrowRate
stableTokenDebt
variableTokenDebt
reserve {
symbol
decimals
}
assetPriceUSD
}
... on UsageAsCollateral {
fromState
toState
reserve {
symbol
}
}
... on Repay {
amount
reserve {
symbol
decimals
}
assetPriceUSD
}
... on LiquidationCall {
collateralAmount
collateralReserve {
symbol
decimals
}
principalAmount
principalReserve {
symbol
decimals
}
collateralAssetPriceUSD
borrowAssetPriceUSD
}
}
}