Last active
December 26, 2021 02:38
-
-
Save medvedev1088/e40dfb92288a91e20bd09dc92b0c732e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#standardSQL | |
-- MIT License | |
-- Copyright (c) 2018 Evgeny Medvedev, evge.medvedev@gmail.com | |
with double_entry_book as ( | |
-- debits | |
select to_address as address, value as value | |
from `bigquery-public-data.crypto_ethereum.traces` | |
where to_address is not null | |
and status = 1 | |
and (call_type not in ('delegatecall', 'callcode', 'staticcall') or call_type is null) | |
union all | |
-- credits | |
select from_address as address, -value as value | |
from `bigquery-public-data.crypto_ethereum.traces` | |
where from_address is not null | |
and status = 1 | |
and (call_type not in ('delegatecall', 'callcode', 'staticcall') or call_type is null) | |
union all | |
-- transaction fees debits | |
select miner as address, sum(cast(receipt_gas_used as numeric) * cast(gas_price as numeric)) as value | |
from `bigquery-public-data.crypto_ethereum.transactions` as transactions | |
join `bigquery-public-data.crypto_ethereum.blocks` as blocks on blocks.number = transactions.block_number | |
group by blocks.miner | |
union all | |
-- transaction fees credits | |
select from_address as address, -(cast(receipt_gas_used as numeric) * cast(gas_price as numeric)) as value | |
from `bigquery-public-data.crypto_ethereum.transactions` | |
) | |
select address, sum(value) as balance | |
from double_entry_book | |
group by address | |
order by balance desc | |
limit 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment