aave / aave/protocol-subgraphs

Reserve and UserReserve balances are wrong

Open
#82 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
150
Forks
130
PR merge metrics
No merged PRs in 30d

Description

TLDR

In v3, there are a bunch of wallets in all v3 chains that have wrong balances in the subgraph compared to the on-chain data.

Example

For example, 0xbc1631afcb916bda28af42955fc970bf004596f8 on Polygon has 0 on-chain balance:
image but, querying this user from the subgraph and using aave-utilities formatter, the user has balances.
Same goes for wallets that still have dust balance on chain: 0xee2826453a4fd5afeb7ceffeef3ffa2320081268 on Avalanche : 0.00000018 WETH.e on chain- comparing to 1+ WETH.e using the subgraph.

Root cause - account balance computation updated in v3

It seems like the Burn and Mint events were changed in AAVE v3. In v3, The event value reports the amount that should be minted/burned while taking into account the interest which was accumulated (which impact the amount of mint/burned) since the last update.
In v2, the events reported the amount which was supplied/withdrawn, and the interest could be calculated using other fields in the subgraph like liquidityIndex, liquidityRate, etc.

Scope of Issue
  • Any wallet that executed two actions with a delta such that interest was accrued stores the wrong balance.
    • For example, a wallet that has performed the supply method twice or a combination of withdraw and supply.
  • This bug also affects any field that is affected by interest accumulated by the wallet balances. Namely, this effects Reserve metrics such as totalSupply and totalBorrow per asset.
Impact
  • This is a large-scale bug as it essentially affects all wallets (barring wallets that have only ever supplied).
  • This means that anyone consuming data on wallets/health/risk from the officially supported subgraphs was reading the wrong data.
  • Any teams, traders, or institutions attempting to make data-driven decisions based on subgraph data are affected.

Proposed Fix

In order to keep consistency and backward compatibility to the structure of v2 (and to aave-utilities functions), we need to sum up the Burn.value and Burn.balanceIncrease and use this value for all the calculations. The opposite goes for Mint - we need to subtract Mint.balanceIncrease from Mint.value.

Proposed PR

We have created a PR that fixes the issue, but we couldn't submit it because of repository permissions. If you can provide me access to create PRs, we would be happy to contribute to the repo with the fixed PR.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how Aave v3 Mint and Burn events update Reserve and UserReserve balances. Compare the subgraph results with the Polygon and Avalanche on-chain examples and the aave-utilities formatter. Done means interest-adjusted values produce correct wallet balances and Reserve totalSupply and totalBorrow metrics.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
blockchain, data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.