Robust way to index historic total supply for all ERC20 tokens

erc-20totalsupply

Is there a robust way to index historic total supply for all ERC20 tokens?

For tokens that update total supply through mint and burn (with proper events), this is easily done by tallying up mints and subtracting burns.

However, not all tokens, by a longshot, behave that way.
I figured a way was to tally up all balances of said token over all addresses (excluding the burn address), but this gets me the 'circulating supply' and not the 'total supply'.

In theory I would be able to get the historic 'total supply' by watching traces/state changes but that's a can of worms I don't want to open.

Any other ways?

Best Answer

Is there a robust way to index historic total supply for all ERC20 tokens?

Short answer: no.

ERC-20 does not specify events for

  • Newly created tokens
  • Supply changes

To add to the complexity rebase tokens do not emit any events when balances and supplies change, as they have dynamic balances and supplies.

Only way is to either

  • Trace all transactions in the chain and check if they modify totalSupply storage variable. However there is no generic solution, because as mentioned above rebase tokens do not have totalSupply variable as it is a dynamic function.
  • Poll the chain. For historical supplies you need to have an archive node and use eth_call JSON-RPC with a historical block identifier.
Related Topic