Query editor
WITH attempts AS (SELECT t."from" wallet,t.hash tx_hash,t.block_time,t.block_date day,t.success,t."to" target,IF(varbinary_length(t.data)>=4,varbinary_substring(t.data,1,4),0x00000000) selector,CAST(t.value AS DOUBLE)/1e18 tx_value_eth,COALESCE(g.tx_fee,CAST(t.gas_used AS DOUBLE)*CAST(t.effective_gas_price AS DOUBLE)/1e18) gas_ethFROM robinhood.transactions tLEFT JOIN gas.fees g ON g.blockchain='robinhood'AND g.block_date=CURRENT_DATE AND g.tx_hash=t.hashWHERE t.block_date=CURRENT_DATE),cash_by_tx AS (SELECT a.wallet,a.tx_hash,SUM(IF(LOWER(tr.token_standard)='native' AND tr."to"=a.wallet,COALESCE(tr.amount,0e0),0e0)) native_in,SUM(IF(LOWER(tr.token_standard)='native' AND tr."from"=a.wallet,COALESCE(tr.amount,0e0),0e0)) native_transfer_out,SUM(IF(tr.contract_address=0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73AND tr."to"=a.wallet,COALESCE(tr.amount,0e0),0e0)) weth_in,SUM(IF(tr.contract_address=0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73AND tr."from"=a.wallet,COALESCE(tr.amount,0e0),0e0)) weth_out,SUM(IF(tr.contract_address=0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168AND tr."to"=a.wallet,COALESCE(tr.amount,0e0),0e0)) usdg_in,SUM(IF(tr.contract_address=0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168AND tr."from"=a.wallet,COALESCE(tr.amount,0e0),0e0)) usdg_out,COUNT_IF(LOWER(tr.token_standard)<>'native'AND tr.contract_address NOT IN (0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73,0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168)AND (tr."from"=a.wallet OR tr."to"=a.wallet)) nonquote_legsFROM attempts aLEFT JOIN tokens.transfers tr ON tr.blockchain='robinhood'AND tr.block_date=CURRENT_DATE AND tr.tx_hash=a.tx_hashWHERE a.successGROUP BY 1,2),price AS (SELECT APPROX_PERCENTILE(price,0.5) eth_usdFROM prices.minuteWHERE blockchain='robinhood'AND contract_address=0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73AND timestamp>=CAST(CURRENT_DATE AS TIMESTAMP)),tx_value0 AS (SELECT a.*,p.eth_usd,COALESCE(c.native_in,0e0) native_in,COALESCE(c.native_transfer_out,0e0) native_transfer_out,IF(a.success,GREATEST(COALESCE(c.native_transfer_out,0e0),a.tx_value_eth),0e0)effective_native_out,COALESCE(c.weth_in,0e0) weth_in,COALESCE(c.weth_out,0e0) weth_out,COALESCE(c.usdg_in,0e0) usdg_in,COALESCE(c.usdg_out,0e0) usdg_out,COALESCE(c.nonquote_legs,0) nonquote_legsFROM attempts a CROSS JOIN price pLEFT JOIN cash_by_tx c ON c.wallet=a.wallet AND c.tx_hash=a.tx_hash),tx_value AS (SELECT *,IF(success,native_in-effective_native_out+weth_in-weth_out,0e0) quote_eth,IF(success,usdg_in-usdg_out,0e0) usdg,IF(success,(native_in-effective_native_out+weth_in-weth_out)*eth_usd