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/with reserve as (select 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0 --wstETH), weth_reserve as (select 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 --wETH), deposits as (selectuser, sum(CAST(amount as DOUBLE))/1e18 as wsteth_deposited, count(amount) as cnt_wsteth_depositedfrom spark_protocol_ethereum.Pool_evt_Supplywhere reserve in (select * from reserve)group by 1), withdrawals as (selectuser, sum(CAST(amount as DOUBLE))/1e18 as wsteth_withdrawn, count(amount) as cnt_wsteth_withdrawnfrom spark_protocol_ethereum.Pool_evt_Withdrawwhere reserve in (select * from reserve)group by 1), wsteth_collaterals as (selectdeposits.user as user, deposits.wsteth_deposited, COALESCE(withdrawals.wsteth_withdrawn, 0) wsteth_withdrawn, (deposits.wsteth_deposited - COALESCE(withdrawals.wsteth_withdrawn, 0)) as wsteth_collateral, deposits.cnt_wsteth_deposited, COALESCE(withdrawals.cnt_wsteth_withdrawn, 0) cnt_wsteth_withdrawnfrom depositsleft join withdrawals on deposits.user = withdrawals.userwhere (deposits.wsteth_deposited - COALESCE(withdrawals.wsteth_withdrawn, 0)) > 0), borrowings as (selectonBehalfOf as user, sum(CAST(amount as DOUBLE))/1e18 as weth_loan, count(amount) as cnt_weth_loanfrom spark_protocol_ethereum.Pool_evt_Borrowwhere reserve in (select * from weth_reserve)and onBehalfOf in (select user from wsteth_collaterals)group by 1), repayings as (selectuser as user, sum(CAST(amount as DOUBLE))/1e18 as weth_loan, count(amount) as cnt_weth_loanfrom spark_protocol_ethereum.Pool_evt_Repaywhere reserve in (select * from weth_reserve)