Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix balances for v3 #83

Merged

Conversation

ronlv10
Copy link
Contributor

@ronlv10 ronlv10 commented Aug 30, 2022

TLDR

In v3, there are a bunch of wallets 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.

Copy link
Contributor

@defispartan defispartan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that changes match the reported event errors in aave/aave-v3-core#682

@defispartan defispartan changed the base branch from main to staging September 27, 2022 00:42
@defispartan defispartan merged commit 5ac8df2 into aave:staging Sep 27, 2022
defispartan added a commit that referenced this pull request Sep 29, 2022
* bump: lockfile

* fix: remove v3 schema at v2's initializer (#78)

* feat: add helpful fields for transaction queries (#76)

* feat: add fields to V2 and V3 UserTransaction schema

* feat: set new fields in v2 and v3 mappings

* fix: schema types

* fix: remove non-existent fields from v2 initializers

* fix: mapppings for new fields

* feat: add precision constant

* feat: add assetPriceUSD to v2 subgraph entities

* feat: switch v3 assetPriceUSD to BigDecimal

* feat: handle v2 USD oracles for assetPriceUSD (avalanche market)

* fix: avax v2 assetPriceUSD

* Fix balances for v3 (#83)

* Fix balances for v3

* rename var

* Fix stable debt

* feat: add configuration for all new testnet deployments

* delete: yarn lockfile, using npm instead

* feat: update deployment scripts

* bump: lockfile

* feat: clean up .env.test

* fix: deployment script typos

* feat: update arc and centrifuge schema

* feat: update README

Co-authored-by: reanox <hireanox@gmail.com>
Co-authored-by: Ron Lev <ronlv10@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants