Skip to content

Instantly share code, notes, and snippets.

@banteg
Created March 6, 2019 08:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save banteg/b0d05fdf5a49a6ec6f8994533ddc14c2 to your computer and use it in GitHub Desktop.
Save banteg/b0d05fdf5a49a6ec6f8994533ddc14c2 to your computer and use it in GitHub Desktop.
tally ether locked across all uniswap exchanges
from concurrent.futures import ThreadPoolExecutor
from web3.auto import w3
from cryptocompare import get_price
abi = [{'name': 'NewExchange', 'inputs': [{'type': 'address', 'name': 'token', 'indexed': True}, {'type': 'address', 'name': 'exchange', 'indexed': True}], 'anonymous': False, 'type': 'event'}]
factory = w3.eth.contract('0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95', abi=abi)
new_exchange = factory.events.NewExchange().createFilter(fromBlock=6627917)
exchanges = [x.args.exchange for x in new_exchange.get_all_entries()]
balances = ThreadPoolExecutor(10).map(w3.eth.getBalance, exchanges)
eth_locked = w3.fromWei(sum(balances), 'ether')
price = get_price('ETH', 'USD')['ETH']['USD']
print(f'{eth_locked:,.2f} ETH locked across {len(exchanges)} uniswap exchanges\n${float(eth_locked) * 2 * price:,.0f} total locked')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment