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: 14568297}) { # 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: "0x63a72806098bd3d9520cc43356dd78afe5d386d90xb6a86025f0fe1862b372cb0ca18ce3ede02a318f" # 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: "0xb6a86025f0fe1862b372cb0ca18ce3ede02a318f"}) { # 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: "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c70xb6a86025f0fe1862b372cb0ca18ce3ede02a318f" # 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: "0x000000000a38444e0a6e37d3b630d7e855a7cb130xb31f66aa3c1e785363f0875a1b74e27b85fd66c70xb6a86025f0fe1862b372cb0ca18ce3ede02a318f" # 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: "0x00000000004ad9f29c4209b469b2bc9bbab062ad"}) { # provide user's address here
reserve {
id
symbol
underlyingAsset
}
scaledATokenBalance
usageAsCollateralEnabledOnUser
stableBorrowRate
scaledVariableDebt
principalStableDebt
stableBorrowLastUpdateTimestamp
user {
id
}
}
}

Recent Deposits for a Particular Asset

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

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

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: "0x50b7545627a5162f82a992c33b87adc75187b2180xb6a86025f0fe1862b372cb0ca18ce3ede02a318f"} # 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: "0xc4a936b003bc223df757b35ee52f6da66b062935"} # provide user address here
orderBy: timestamp
orderDirection: desc
) {
id
timestamp
txHash
action
... on Deposit {
amount
reserve {
symbol
decimals
}
assetPriceUSD
}
... 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 Swap {
borrowRateModeFrom
borrowRateModeTo
variableBorrowRate
stableBorrowRate
reserve {
symbol
decimals
}
}
... on LiquidationCall {
collateralAmount
collateralReserve {
symbol
decimals
}
principalAmount
principalReserve {
symbol
decimals
}
collateralAssetPriceUSD
borrowAssetPriceUSD
}
}
}