Query editor
WITH curve_data AS (SELECT0xdbdb4d16eda451d0503b854cf79d55697f90c8df as prot_token,0x9001a452d39A8710D27ED5c2E10431C13F5Fba74 as lp_token,0xD3B5D9a561c293Fb42b446FE7e237DaA9BF9AA84 as t_address,0x90b6C61B102eA260131aB48377E143D6EB3A9d4B as lp_owner),protbalance AS (SELECTSUM(protbalance) AS protbalanceFROM (SELECT(cast(value AS DECIMAL)/1e18) as protbalanceFROM erc20_ethereum.evt_TransferWHERE contract_address = (select prot_token from curve_data) -- ALCX token addressAND to in (select lp_token from curve_data) -- LP token addressUNION ALLSELECT-(cast(value AS DECIMAL)/1e18) as protbalanceFROM erc20_ethereum.evt_TransferWHERE contract_address = (select prot_token from curve_data) -- ALCX token addressAND "from" in (select lp_token from curve_data) -- LP token address)),t_balance AS (SELECTSUM(t_balance) AS t_balanceFROM (SELECT(CAST(SUM(CASE WHEN "from" = (select lp_token from curve_data) THEN -CAST(value AS INT256) ELSE CAST(value AS INT256) END) AS DECIMAL) / 1e18) as t_balanceFROM erc20_ethereum.evt_TransferWHERE contract_address = (select t_address from curve_data) -- t token addressAND ("to" = (select lp_token from curve_data) OR "from" = (select lp_token from curve_data)) -- LP token address)),mint_burn_events AS (SELECTCASEWHEN "from" = 0x0000000000000000000000000000000000000000 THEN CAST(value AS DECIMAL)ELSE -CAST(value AS DECIMAL)END AS valueFROM erc20_ethereum.evt_TransferWHERE contract_address = (select lp_token from curve_data) -- LP token addressAND ("from" = 0x0000000000000000000000000000000000000000 OR "to" = 0x0000000000000000000000000000000000000000)),total_supply AS (SELECT SUM(value) * 1e-18 AS total_supplyFROM mint_burn_events),t_mint_burn_events AS (SELECTCASEWHEN "from" = 0x0000000000000000000000000000000000000000 THEN CAST(value AS DECIMAL)ELSE -CAST(value AS DECIMAL)END AS valueFROM erc20_ethereum.evt_TransferWHERE contract_address = (select t_address from curve_data)AND ("from" = 0x0000000000000000000000000000000000000000 OR "to" = 0x0000000000000000000000000000000000000000)),t_total_supply AS (