• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    TypeScript
  • License
    GNU Affero Genera...
  • Created almost 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The code of Aave protocol subgraphs

Aave Protocol Subgraphs

The Aave Protocol subgraphs index data from the protocol smart contracts, and expose a GraphQL endpoint hosted by The Graph.

Active deployments

Production networks

Test networks

Usage

Subgraphs can be queried directly from the graph explorer, or from another application. The following section gives common queries for Aave protocol data.

Helpful Queries

See TheGraph API docs for a complete guide on querying capabilities.

User Transaction History

V2
{
  userTransactions(
    where: { user: "insert_lowercase_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
    }
  }
}
V3
{
  userTransactions(
    where: { user: "insert_lowercase_address_here" }
    orderBy: timestamp
    orderDirection: desc
  ) {
    id
    timestamp
    txHash
    action
    ... on Supply {
      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 SwapBorrowRate {
      borrowRateModeFrom
      borrowRateModeTo
      variableBorrowRate
      stableBorrowRate
      reserve {
        symbol
        decimals
      }
    }
    ... on LiquidationCall {
      collateralAmount
      collateralReserve {
        symbol
        decimals
      }
      principalAmount
      principalReserve {
        symbol
        decimals
      }
      collateralAssetPriceUSD
      borrowAssetPriceUSD
    }
  }
}
Reserve Data

Reserve Summary

The reserve entity gives data on the assets of the protocol including rates, configuration, and total supply/borrow amounts.

The aave-utilities library includes a formatReserves function which can be used to format all data into a human readable format. The queries to fetch data for passing into this function can be found here.

Why does the raw subgraph data not match app.aave.com?

  • aToken and debtToken balances are continuously increasing. The subgraph provides a snapshot of the balance at the time of indexing (not querying), which means fields affected by interest such as totalLiquidity, availableLiquidity, and totalCurrentVariableDebt will need to be formatted to get real-time values
  • All rates (liquidityRate, variableBorrowRate, stableBorrowRate) are expressed as APR with RAY units (10**27). To convert to the APY percentage as shown on the Aave frontend: supplyAPY = (((1 + ((liquidityRate / 10**27) / 31536000)) ^ 31536000) - 1) \* 100. formatReserves will perform this calculation for you.
User Data

User Summary

The userReserve entity gives the supply and borrow balances for a particular user along with the underlying reserve data.

The aave-utilities library includes a formatUserSummary function which can be used to format all data into a human readable format. The queries to fetch data for passing into this function can be found here.

Why does the raw subgraph data not match my account balances on app.aave.com?

  • aToken and debtToken balances are continuously increasing. The subgraph provides a snapshot of the balance at the time of indexing (not querying), which means fields affected by interest such as currentATokenBalance, currentVariableDebt, and currentStableDebt will need to be formatted to get the real-time values
Querying Tips

Historical Queries

You can query for historical data by specifying a block number:

{
	reserves(block: {number: 14568297}){
  	symbol
  	liquidityRate
	}
}

To query based on a historical timestamp, you will need to convert the timstamp to the most recent block number, you will need to use an external tool such as this.

Pagination

The Graph places a limit on the number of items which can returned by a single query (currently 100). To fetch a larger number of items, the first and skip parameters can be used to create paginated queries.

For example, if you wanted to fetch the first 200 transactions for an Aave market, you can't query 200 items at once, but you can achieve the same thing by concatenating the output of these queries:

{
  userTransactions(orderBy: timestamp, orderDirection: asc, first: 100, skip: 0){
    timestamp
  }
}
{
  userTransactions(orderBy: timestamp, orderDirection: asc, first: 100, skip: 100){
    timestamp
  }
}

Development

# copy env and adjust its content with your personal access token and subgraph name

# you can get an access token from https://thegraph.com/explorer/dashboard
cp .env.test .env

# install project dependencies
npm i

# to regenrate types if schema.graphql has changed
npm run subgraph:codegen

# to run a test build of your subgraph
npm run subgraph:build

# now you're able to deploy to thegraph hosted service with one of the deploy commands:
npm run deploy:hosted:mainnet

Metis V3

API: https://andromeda.thegraph.metis.io/subgraphs/name/aave/protocol-v3-metis
Index node + Playground: https://andromeda-index-node.thegraph.metis.io/graphql/playground

Troubleshooting

If a subgraph encounters an error while indexing, the logs on the explorer may not display the error. You can check for errors on a pending or synced subgraph with the following commands, replacing aave/protocol-v2 with your subgraph name:

Pending:

curl --location --request POST 'https://api.thegraph.com/index-node/graphql' --data-raw '{"query":"{ indexingStatusForPendingVersion(subgraphName: \"aave/protocol-v2\") { subgraph fatalError { message } nonFatalErrors {message } } }"}'

Synced:

curl --location --request POST 'https://api.thegraph.com/index-node/graphql' --data-raw '{"query":"{ indexingStatusForCurrentVersion(subgraphName: \"aave/protocol-v2\") { subgraph fatalError { message } nonFatalErrors {message } } }"}'

More Repositories

1

aave-protocol

Aave Protocol Version 1.0 - Decentralized Lending Pools
HTML
1,384
star
2

aave-v3-core

This repository contains the core smart contracts of the Aave V3 protocol.
TypeScript
866
star
3

protocol-v2

Aave Protocol V2
TypeScript
660
star
4

flashloan-box

A box containing all you need to get started with developing Aave v1 flash loans
Solidity
582
star
5

interface

An open source interface for the decentralized liquidity protocol Aave
TypeScript
407
star
6

gho-core

Solidity
252
star
7

governance-crosschain-bridges

This repo contains the crosschain governance bridges used for the aave markets deployed across different networks
TypeScript
165
star
8

aave-js

TypeScript
142
star
9

aave-v3-periphery

TypeScript
132
star
10

aave-ui

[DEPRECATED] An open source interface for the decentralized liquidity protocol Aave
TypeScript
127
star
11

aave-utilities

TypeScript
119
star
12

aip

Aave Improvement Proposals
JavaScript
103
star
13

code-examples-protocol

Solidity
103
star
14

gho-bug-bounty

81
star
15

aave-stake-v2

V2 implementation of the stkAAVE token
Solidity
57
star
16

aave-v3-deploy

TypeScript
45
star
17

governance-v2

TypeScript
44
star
18

Aave-Vault

ERC4626 vault to hold aToken assets
Solidity
42
star
19

ethlondon-flash

Flashy workshop
JavaScript
34
star
20

aave-sandbox

Sandbox of Aave Markets that replicates a forked production environment. The environment is envisioned for testing liquidations or other integrations.
TypeScript
31
star
21

aptos-aave-v3

Aave's V3 Protocol on Aptos
Move
26
star
22

bug-bounty

25
star
23

aave-token

AAVE token implementation
TypeScript
23
star
24

aave-token-v2

V2 implementation of the AAVE token
TypeScript
21
star
25

safety-module

Safety module implementation for the Aave protocol
TypeScript
20
star
26

aave-ui-caching-server

Thin and simple data caching layer to give better "real time" experience to users of https://github.com/aave/aave-ui
TypeScript
18
star
27

aave-ui-kit

Package containing UI components and helpers used on https://github.com/aave/aave-ui
TypeScript
18
star
28

price-aggregators

Solidity
14
star
29

governance-v2-subgraph

TypeScript
12
star
30

incentives-controller

TypeScript
12
star
31

liquidation-ui

TypeScript
11
star
32

branding-assets

Repository for the Aave protocol branding assets
11
star
33

docs-v3

11
star
34

upgradeable-configurable-rights-pool

Solidity
10
star
35

dlp-docs-abi

Initial documentation of the Decentralized Lending Pool protocol developed by Aave
JavaScript
10
star
36

aave-asset-listing

TypeScript
8
star
37

gho-aip

Solidity
8
star
38

markets-adapters

Adapters smart contracts used on different Aave markets
TypeScript
6
star
39

loanlord-bot

An open source bot that interacts with the ETHLend platform.
JavaScript
5
star
40

aave-api

Misc Aave api
TypeScript
5
star
41

risk-v3

5
star
42

tests-protocol-v2-sigmaprime

Test suite for the Aave Protocol v2 by SigmaPrime during their audit
Solidity
5
star
43

docs-gho

JavaScript
4
star
44

aip-uploader

JavaScript
4
star
45

docs-v2

4
star
46

split-croatia-workshop

https://aave.github.io/split-croatia-workshop/
JavaScript
4
star
47

proto-governance

Aave governance based on LEND token
TypeScript
4
star
48

gho-public

Gho is a collateral backed stablecoin that can be natively integrated into the Aave Protocol
4
star
49

aavenomics

4
star
50

aave-grants-update-and-renewal

TypeScript
4
star
51

arc-timelock

Set of contracts for Timelock Executor of ARC Market
TypeScript
3
star
52

v3-retroactive-funding

V3 Retroactive funding proposal
TypeScript
3
star
53

walletconnect-connector

Fork of @web3-react/walletconnect-connector from deprecated V6 version of uniswap/web3-react, which is still in use on aave/interface
TypeScript
3
star
54

aave-addresses

TypeScript
3
star
55

gho-brand-assets

3
star
56

pinata-action

Github action to upload & pin to pinata
JavaScript
2
star
57

cloudflare-update-action

JavaScript
2
star
58

aave-gitcoin-hackaton-2019

2
star
59

governance-delegation-subgraph

TypeScript
1
star
60

token-wrappers

Foundry-based repository for testing token wrappers for supply/withdrawal from v3 Pools
Solidity
1
star
61

genesis-migration

Misc smart contracts used on the LEND -> AAVE migration
TypeScript
1
star