Cover Image for Beneath Aave V3 Data with Bitquery APIs​

Beneath Aave V3 Data with Bitquery APIs​

DeFi
Aave
Decentralized Finance
ETH

Today we will discuss getting all the data from Aave which is the top lending protocol on Ethereum and is multichain. Aave is a decentralized non-custodial liquidity protocol where users can participate as depositors or borrowers. Depositors provide liquidity to the market to earn a passive income, while borrowers can borrow in an overcollateralized (perpetually) or undercollateralized (one-block liquidity) fashion.

Aave has upgraded to Aave v3 which augments the core concepts of Aave Protocol (aTokens, instant liquidity, stable rate borrowing, credit delegation, etc.) with new features which include Portal(for flow of liquidity in different chains), eMode, Isolation mode and much more.

Anyone can access the basic analysis without a single line of code through Bitquery Explorer. If you want to learn more about Bitquery Protocol's data capabilities, you can read our article about how to track liquidity for any token pair on Uniswap.

Note - We are using Streaming APIs (v2) to get the following data; you can also turn them into WebSocket simply using Graphql Subscription.

You can run the following queries here.

Aave V3 API's

Aave V3 Ethereum Daily User Activities

The main functions a user calls are "Supply", "Borrow", "Withdraw" and "Repay", we can get these events count for each day for unique address count by aggregating the data by event and block time in the query below

query ($network: EthereumNetwork!, $address: String!, $limit: Int, $offset: Int, $from: ISO8601DateTime, $till: ISO8601DateTime) {
  ethereum(network: $network) {
    smartContractEvents(
      options: {desc: "count", limit: $limit, offset: $offset}
      date: {since: $from, till: $till}
      smartContractAddress: {is: $address}
      smartContractEvent: {in: ["Supply", "Borrow", "Withdraw", "Repay"]}
    ) {
      smartContractEvent {
        name
      }
      block {
        timestamp {
          time(format: "%Y-%m-%d")
        }
      }
      count(uniq: callers)
    }
  }
}

Parameters:

{
  "limit": 1000000,
  "offset": 0,
  "network": "ethereum",
  "address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
  "from": "2022-10-15",
  "till": "2023-10-22T23:59:59",
  "dateFormat": "%Y-%m-%d"
}

Count of Different Activities on Aave V3

Borrow Volume of an Asset on Aave V3

To calculate the borrow Volume of an asset(USDC) on a specific chain(ETH), we have to use the transfers database and filter out based on the contract address of USDC and Aave v3, then aggregate the results based on date format in the query below

query ($network: EthereumNetwork!, $token: String!, $dateFormat: String!, $from: ISO8601DateTime, $till: ISO8601DateTime) {
  ethereum(network: $network) {
    transfers(
      currency: {is: $token}
      height: {gt: 0}
      amount: {gt: 0}
      date: {since: $from, till: $till}
      any: {sender: {is: "0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c"}}
    ) {
      date {
        date(format: $dateFormat)
      }
      count: countBigInt
      amount
    }
  }
}

Parameters:

{
  "limit": 10,
  "offset": 0,
  "network": "ethereum",
  "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  "from": "2023-10-15",
  "till": "2023-10-22T23:59:59",
  "dateFormat": "%Y-%m-%d"
}

Borrow Volume of USDC on Ethereum on Aave V3

Supplied Volume of an Asset on Aave V3

We can get the Supplied USDC on Aave V3 using Events data and filtering it using the contract address and "Mint" event method of Aave Ethereum USDC (aEthUSDC) in the query below

query ($network: EthereumNetwork!, $address: String!, $limit: Int, $offset: Int, $from: ISO8601DateTime, $till: ISO8601DateTime) {
  ethereum(network: $network) {
    smartContractEvents(
      options: {limit: $limit, offset: $offset}
      date: {since: $from, till: $till}
      smartContractAddress: {is: $address}
      any: {smartContractEvent: {is: "Mint"}}
    ) {
      arguments {
        argument
        value
      }
      block {
        timestamp {
          time
        }
      }
    }
  }
}

Parameters:

{
  "limit": 1000000000,
  "offset": 0,
  "network": "ethereum",
  "address": "0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c",
  "from": "2023-08-01",
  "till": "2023-10-24T23:59:59",
  "dateFormat": "%Y-%m-%d"
}

USDC deposited on Aave V3 since August 1

Current and Historical Supply APY and Borrow Rate

We can get the Supply APY and Borrow Rate for DAI(or any asset) using the events emitted by the Aave V3 contract first, we have to filter out the data according to the Log Signature and then the DAI contract, which is done in the query below

{
  EVM(dataset: combined, network: eth) {
    Events(
      orderBy: {descending: Block_Number}
      limit: {count: 10}
      where: {Transaction: {To: {is: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2"}},
        Log: {Signature: {Name: {is: "ReserveDataUpdated"}}},
        Arguments: {includes: {Value: {Address: {is: "0x6B175474E89094C44Da98b954EedeAC495271d0F"}}}}}
    ) {
      Log {
        Signature {
          Name
        }
      }
      Block {
        Date
        Time
      }
      Arguments {
        Name
        Value {
          ... on EVM_ABI_Integer_Value_Arg {
            integer
          }
          ... on EVM_ABI_BigInt_Value_Arg {
            bigInteger
          }
          ... on EVM_ABI_Address_Value_Arg {
            address
          }
        }
      }
    }
  }
}

Parameters:

{}

History of Supply Rate, Stable Borrow Rate, and variable borrow rate of DAI

Aave Unique Users

We can get the unique users on the Aave V3 Platform for each day by filtering out the Calls made to contract and aggregating them using dates as done in the query below

query ($network: EthereumNetwork!, $dateFormat: String!, $address: String!, $from: ISO8601DateTime, $till: ISO8601DateTime) {
  ethereum(network: $network) {
    smartContractCalls(
      date: {since: $from, till: $till}
      any: {smartContractAddress: {is: $address}}
    ) {
      count: countBigInt(uniq: callers)
      date {
        date(format: $dateFormat)
      }
    }
  }
}

Parameters:

{
  "limit": 10,
  "offset": 0,
  "network": "ethereum",
  "address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
  "from": "2023-08-01",
  "till": "2023-10-25T23:59:59",
  "dateFormat": "%Y-%m-%d"
}

Unique Users each day from August

FlashLoan Stats on Aave V3

We can get the FlashLoan Total Volume using Bitquery Streaming APIs, in which we have to filter out the Calls dataset using Call Signature and AAve Contract which is done in the query below

{
  EVM(dataset: combined, network: eth) {
    Calls(
      limit: {count: 10000000}
      where: {Call: {To: {is: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2"}, Signature: {Name: {is: "flashLoanSimple"}}}, Block: {Date: {after: "2023-08-01", before: "2023-10-25"}}}
      orderBy: {descending: Block_Number}
    ) {
      Call {
        Signature {
          Name
          Signature
          SignatureHash
        }
      }
      Arguments {
        Name
        Path {
          Index
          Type
          Name
        }
        Index
        Type
        Value {
          ... on EVM_ABI_Address_Value_Arg {
            address
          }
          ... on EVM_ABI_BigInt_Value_Arg {
            bigInteger
          }
        }
      }
      Transaction {
        Hash
      }
    }
  }
}

Parameters:

{}

Total Flashloan of WETH taken from Aave

Miner Rewards and Priority Fee in FlashLoan Transactions on Aave V3

Flashloan Transactions are all about getting the arbitrage or small profits in the Defi ecosystem but there is a major problem to tackle for the Devs using these transactions i.e. the Priority Fee to Get included in the block, We can get the gas stats using Bitquery by filtering the Calls dataset by Aave Contract address and the call signature, then get all the specific stats regarding the Gas fee in the query below

{
  EVM(dataset: combined, network: eth) {
    Calls(
      limit: {count: 10000000}
      where: {Call: {To: {is: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2"}, Signature: {Name: {is: "flashLoanSimple"}}}, Block: {Date: {after: "2023-08-01", before: "2023-10-25"}}}
      orderBy: {descending: Block_Number}
    ) {
      Call {
        Signature {
          Name
        }
      }
      Transaction {
        Hash
      }
      Fee {
        SenderFee
        Savings
        PriorityFeePerGas
        MinerReward
        EffectiveGasPrice
        Burnt
      }
      Receipt {
        GasUsed
      }
    }
  }
}

Parameters:

{}

Total Miner reward vs Priority fees

That's it folks, another protocol another time :]

About Bitquery

Bitquery is your comprehensive toolkit designed with developers in mind, simplifying blockchain data access. Our products offer practical advantages and flexibility.

  • APIs - Explore API: Easily retrieve precise real-time and historical data for over 40 blockchains using GraphQL. Seamlessly integrate blockchain data into your applications, making data-driven decisions effortless.

  • Coinpath® - Try Coinpath: Streamline compliance and crypto investigations by tracing money movements across 40+ blockchains. Gain insights for efficient decision-making.

  • Data in Cloud - Try Demo Bucket: Access indexed blockchain data cost-effectively and at scale for your data pipeline. We currently support Ethereum, BSC, Solana, with more blockchains on the horizon, simplifying your data access.

  • Explorer - Try Explorer: Discover an intuitive platform for exploring data from 40+ blockchains. Visualize data, generate queries, and integrate effortlessly into your applications.

Bitquery empowers developers with straightforward blockchain data tools. If you have questions or need assistance, connect with us on our Telegram channel or via email at sales@bitquery.io. Stay updated on the latest in cryptocurrency by subscribing to our newsletter below.

This blog was written by guest author Nitin.

Subscribe to our newsletter

Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.