Query editor
-- todo: sum over blocktime&user incase an idiot deposit/withdraw multiple time in same blockwith govv2_evt as (select*fromethereum.logswhereblock_number >= 21683156and contract_address = 0x636dEb767Cd7D0f15ca4aB8eA9a9b26E98B426AC -- liquity governance),deposit as (selectblock_time,varbinary_substring(topic1,13) as "user",varbinary_to_uint256(varbinary_substring(data,33,32)) as amount,varbinary_to_uint256(varbinary_substring(data,33,32))*to_unixtime(block_time) as pw, --partial weight1. as f, -- factor to multiply pw1 as directionfromgovv2_evtwheretopic0 = 0x5cd37895bb9287e542a426d6abbc93d7daca0979bd43264d320d4fd224a5fc5e -- DepositLQTY),withdraw as (selectblock_time,varbinary_substring(topic1,13) as "user",varbinary_to_uint256(varbinary_substring(data,33,32)) as amount,-1 as directionfromgovv2_evtwheretopic0 = 0x2870fe177552976b0dbc3166ded2169d5d73275fc565df30894320fd3608f339 -- WithdrawLQTY),b as ( -- balanceselectblock_time,"user",sum(cast(amount as int256) * direction) over(partition by "user" order by block_time asc rows between unbounded preceding and current row) as cumsumfrom (select block_time, "user", amount, direction from deposit union select block_time, "user", amount, direction from withdraw)),wratio as(selectwithdraw.block_time as block_time,withdraw."user" as "user",withdraw.amount as amount,cumsum/cast((cumsum + withdraw.amount) as double) as rfrom withdrawleft join bon withdraw.block_time = b.block_time and withdraw."user" = b."user"),deposit2 as (selectblock_time,"user" as "user",amount as amount,pw as pw, --partial weightf * (select reduce_agg(r,1,(a, b) -> a * b, (a, b) -> a * b) from wratio where wratio."user" = deposit."user" and wratio.block_time > deposit.block_time) as ffromdeposit