Query editor
-- This query used incompatible data types from Dune SQL alpha and may need to be updated.-- More details can be found on https://dune.com/docs/query/dunesql-changes/--evt_Transfer filtered on pair_address--get all transfers from and to for all addresses of holders--sum over time, you can get their current balance--divide current balance by total supply (sum of all balances = total supply)--if you can figure out how many tokens are held in staking/rewards contracts or--gnosis safes. We have a label.contracts table you might remember from earlier onwithtransfers_in as (SELECTtr.to as holder, contract_address as pair, sum(cast(value as double)/1e18) as recievedFROM erc20_ethereum.evt_Transfer tr--uniswap_v2_ethereum.Pair_evt_TransferWHERE contract_address = {{Pair Address}}AND to != 0x0000000000000000000000000000000000000000GROUP BY 1, 2), transfers_out as (SELECTtr."from" as holder, contract_address as pair, sum(cast(value as double)/1e18) as sentFROM erc20_ethereum.evt_Transfer tr--uniswap_v2_ethereum.Pair_evt_TransferWHERE contract_address = {{Pair Address}}AND "from" != 0x0000000000000000000000000000000000000000GROUP BY 1, 2), net_balance as (SELECTt_in.pair, t_in.holder, t_in.recieved - COALESCE(t_out.sent, 0) as balanceFROM transfers_in t_inLEFT JOIN transfers_out t_out ON t_in.holder = t_out.holder AND t_in.pair = t_out.pairWHERE t_in.recieved - COALESCE(t_out.sent, 0) > 0), total_supply as (SELECTpair, sum(balance) total_balanceFROM net_balanceGROUP BY 1),final as (SELECTnt.pair, holder, case when tr.address is not null then 'contract'else 'eoa/wallet'end as holder_type, balance, balance/ts.total_balance as percent_liq_heldFROM net_balance nt