Query editor
--Notes----------------------------------------------------------- Realized Pnl: Taking into account cost of all tokens purchased (considers tokens never sold)-- current code does not account for any tokens transfered to a wallet and sold. Only if a token was bought and sold with a wallet.-- Currently does not track for tokens sent to wallet and sold or tokens bought by wallet and transfered out.-- Thought: you could just look at token transfers and find price at time of transfer to assume costs. Then find transfers out and assume price at time of sale? meh--Swaps. Many scenarios 1) User(tx_from) calls a contract(tx_to & taker) that then calls the swap - liquidity goes in and out of contract('Taker'. 2) User(tx_from) calls swap contract but uses another contract/EOA for liquidity (taker)--Formulas----------------------------------------------------------- Realized Profit = USD Sold Amount - USD Bought Amount-- = Sum(Amount_usd_from_sells) - Sum(Amount_usd_from_buys)-- Unrealized Profit = (Current USD Price * # tokens Held) - Total USD Bought-spent-- = Current_price * (token_amount_bought - token_amount_sold) - ((token_amount_bought - token_amount_sold)* sum(token_amount_bought) /sum(usd_amount) )-- Avg Buy Cost Basis = # tokens purchased / USD cost-- Estimated Total Profit = Realized + Unrealized-- Use Etherscan API to pull decimal/meta data for token list.-- Get list of known contract addresses to excludeWith addresses_to_exclude as (select distinct address from (select distinct address as address from labels.contracts where blockchain = 'ethereum'union allselect distinct address as address from ethereum.creation_tracesunion allselect distinct address as address from ethereum.tracesunion allselect distinct address as address from labels.mev_ethereumunion allselect"from" as address --addresses that call a mevbotfrom ethereum.transactions ainner join (select address as address from addresses_ethereum.mev) b on a.to = b.addresswhere block_time > timestamp '2021-01-01'union allselect distinct address as address from labels.sandwich_attackers where blockchain = 'ethereum')),Dex_buys as (selecttoken_bought_address,tx_from as trader,sum(token_bought_amount_raw) as amount_raw,sum(token_bought_amount) as amount_adjusted,--sum(amount_usd) / sum(token_bought_amount) as avg_buy_price,sum(amount_usd) as amount_usd,count(*) as buysfrom dex.trades ainner join query_2924632 b on a.token_bought_address = b.address --only review tokens created within past 6 monthswhere 1=1AND blockchain = 'ethereum'and amount_usd is not nulland a.block_time >= now() - interval '6' month