maybeyonasrocifi_vault_balance
Updated 2022-11-14Copy Reference Fork
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
with
net_movs as (
select
date_trunc('month',block_timestamp) as month,
sum(
case
when event_inputs:from::string = lower('0x10c9f64289cc5114e8854cc216ad75a0d19d60b5')
then -(event_inputs:value/pow(10,6)) -- withdraw
else event_inputs:value/pow(10,6) -- deposit
end
) as net_amt
from polygon.core.fact_event_logs
where contract_address = lower('0x2791bca1f2de4661ed88a30c99a7a9449aa84174') -- USDC contract
and topics[0] = lower('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef') -- Transfer event
and (
event_inputs:from::string = lower('0x10c9f64289cc5114e8854cc216ad75a0d19d60b5')
or
event_inputs:to::string = lower('0x10c9f64289cc5114e8854cc216ad75a0d19d60b5')
)
-- and (
-- event_inputs:from::string in (
-- lower('0x883F10Dc3960493f38F69b8696dC331D22fdEd76'), -- rUSDC1
-- lower('0x8bf2B880B48EA3d1b13677f327c5058480b4e1d0'), -- rUSDC2
-- lower('0x978F89dE413594378a68CB9C14a83CeC0cEC721b') -- rUSDC3
-- ) or
-- event_inputs:to::string in (
-- lower('0x883F10Dc3960493f38F69b8696dC331D22fdEd76'), -- rUSDC1
-- lower('0x8bf2B880B48EA3d1b13677f327c5058480b4e1d0'), -- rUSDC2
-- lower('0x978F89dE413594378a68CB9C14a83CeC0cEC721b') -- rUSDC3
-- )
-- )
group by 1
)
select *,
sum(net_amt) over(order by month rows between unbounded preceding and current row) as bal
Run a query to Download Data