90 rows today at 11:15 PM
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
with
map(
'Ethereum', map(
unhex('2260fac5e5542a773aa44fbcfedf7c193bc2c599'), ('0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', 'WBTC', 8, 'Derivative', 'Ethereum'),
unhex('0316EB71485b0Ab14103307bf65a021042c6d380'), ('0x0316EB71485b0Ab14103307bf65a021042c6d380', 'HBTC', 18, 'Derivative', 'Ethereum'),
unhex('eb4c2781e4eba804ce9a9803c67d0893436bb27d'), ('0xeb4c2781e4eba804ce9a9803c67d0893436bb27d', 'renBTC', 8, 'Derivative', 'Ethereum'),
unhex('fe18be6b3bd88a2d2a7f928d00292e7a9963cfc6'), ('0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6', 'sBTC', 18, 'Derivative', 'Ethereum'),
unhex('18084fba666a33d37592fa2633fd49a74dd93a88'), ('0x18084fba666a33d37592fa2633fd49a74dd93a88', 'tBTC', 18, 'Derivative', 'Ethereum'),
unhex('3212b29E33587A00FB1C83346f5dBFA69A458923'), ('0x3212b29E33587A00FB1C83346f5dBFA69A458923', 'imBTC', 8, 'Derivative', 'Ethereum'),
unhex('0327112423f3a68efdf1fcf402f6c5cb9f7c33fd'), ('0x0327112423f3a68efdf1fcf402f6c5cb9f7c33fd', 'BTC++', 18, 'Derivative', 'Ethereum'),
unhex('C96dE26018A54D51c097160568752c4E3BD6C364'), ('0xC96dE26018A54D51c097160568752c4E3BD6C364', 'FBTC', 8, 'Derivative', 'Ethereum'),
unhex('9BE89D2a4cd102D8Fecc6BF9dA793be995C22541'), ('0x9BE89D2a4cd102D8Fecc6BF9dA793be995C22541', 'BBTC (Binance)', 8, 'Derivative', 'Ethereum'),
unhex('F5e11df1ebCf78b6b6D26E04FF19cD786a1e81dC'), ('0xF5e11df1ebCf78b6b6D26E04FF19cD786a1e81dC', 'BBTC (BounceBit)', 18, 'Derivative', 'Ethereum'),
unhex('7A56E1C57C7475CCf742a1832B028F0456652F97'), ('0x7A56E1C57C7475CCf742a1832B028F0456652F97', 'SolvBTC', 18, 'Derivative', 'Ethereum'),
unhex('cbb7c0000ab88b473b1f5afd9ef808440eed33bf'), ('0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf', 'cbBTC', 8, 'Derivative', 'Ethereum'),
unhex('8236a87084f8B84306f72007F36F2618A5634494'), ('0x8236a87084f8B84306f72007F36F2618A5634494', 'LBTC', 8, 'Staked', 'Ethereum'),
unhex('bdf245957992bfbc62b07e344128a1eec7b7ee3f'), ('0xbdf245957992bfbc62b07e344128a1eec7b7ee3f', 'mBTC', 8, 'Staked', 'Ethereum'),
unhex('004E9C3EF86bc1ca1f0bB5C7662861Ee93350568'), ('0x004E9C3EF86bc1ca1f0bB5C7662861Ee93350568', 'uniBTC', 8, 'Staked', 'Ethereum'),
unhex('f6718b2701D4a6498eF77D7c152b2137Ab28b8A3'), ('0xf6718b2701D4a6498eF77D7c152b2137Ab28b8A3', 'stBTC', 18, 'Staked', 'Ethereum'),
unhex('F469fBD2abcd6B9de8E169d128226C0Fc90a012e'), ('0xF469fBD2abcd6B9de8E169d128226C0Fc90a012e', 'pumpBTC', 8, 'Staked', 'Ethereum'),
unhex('8DB2350D78aBc13f5673A411D4700BCF87864dDE'), ('0x8DB2350D78aBc13f5673A411D4700BCF87864dDE', 'swBTC', 8, 'Restaked', 'Ethereum'),
unhex('d9D920AA40f578ab794426F5C90F6C731D159DEf'), ('0xd9D920AA40f578ab794426F5C90F6C731D159DEf', 'SolvBTC.BBN', 18, 'Restaked', 'Ethereum')
),
'Arbitrum', map(
unhex('2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f'), ('0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f', 'WBTC', 8, 'Derivative', 'Arbitrum'),
unhex('6c84a8f1c29108F47a79964b5Fe888D4f4D0dE40'), ('0x6c84a8f1c29108F47a79964b5Fe888D4f4D0dE40', 'tBTC', 18, 'Derivative', 'Arbitrum'),
unhex('3647c54c4c2c65bc7a2d63c0da2809b399dbbdc0'), ('0x3647c54c4c2c65bc7a2d63c0da2809b399dbbdc0', 'SolvBTC', 18, 'Derivative', 'Arbitrum'),
unhex('f6718b2701D4a6498eF77D7c152b2137Ab28b8A3'), ('0xf6718b2701D4a6498eF77D7c152b2137Ab28b8A3', 'stBTC', 18, 'Staked', 'Arbitrum'),
unhex('346c574C56e1A4aAa8dc88Cda8F7EB12b39947aB'), ('0x346c574C56e1A4aAa8dc88Cda8F7EB12b39947aB', 'SolvBTC.BBN', 18, 'Restaked', 'Arbitrum'),
unhex('aFAfd68AFe3fe65d376eEC9Eab1802616cFacCb8'), ('0xaFAfd68AFe3fe65d376eEC9Eab1802616cFacCb8', 'SolvBTC.ENA', 18, 'Restaked', 'Arbitrum')
),
'BNB', map(
unhex('7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c'), ('0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', 'BTCB', 18, 'Derivative', 'BNB'),
unhex('4aae823a6a0b376De6A78e74eCC5b079d38cBCf7'), ('0x4aae823a6a0b376De6A78e74eCC5b079d38cBCf7', 'SolvBTC', 18, 'Derivative', 'BNB'),
unhex('f9C4FF105803A77eCB5DAE300871Ad76c2794fa4'), ('0xf9C4FF105803A77eCB5DAE300871Ad76c2794fa4', 'pumpBTC', 8, 'Staked', 'BNB'),
unhex('f6718b2701D4a6498eF77D7c152b2137Ab28b8A3'), ('0xf6718b2701D4a6498eF77D7c152b2137Ab28b8A3', 'stBTC', 18, 'Staked', 'BNB'),
unhex('1346b618dc92810ec74163e4c27004c921d446a5'), ('0x1346b618dc92810ec74163e4c27004c921d446a5', 'SolvBTC.BBN', 18, 'Restaked', 'BNB'),
unhex('53E63a31fD1077f949204b94F431bCaB98F72BCE'), ('0x53E63a31fD1077f949204b94F431bCaB98F72BCE', 'SolvBTC.ENA', 18, 'Restaked', 'BNB')
),
'Base', map(
unhex('cbb7c0000ab88b473b1f5afd9ef808440eed33bf'), ('0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf', 'cbBTC', 8, 'Derivative', 'Base')
)
) as wrapped_btcs,
flows as (
select
date_trunc('day', timestamp) as date,
e.address as contract,
wrapped_btcs['Ethereum'][e.address].2 as symbol,
wrapped_btcs['Ethereum'][e.address].3 as decimals,
wrapped_btcs['Ethereum'][e.address].5 as chain,
sum(case
when input_0_value_address = '0x0000000000000000000000000000000000000000'
then cast(input_2_value_uint256 as double) / power(10, wrapped_btcs['Ethereum'][e.address].3) -- Mint
when input_1_value_address = '0x0000000000000000000000000000000000000000'
then -1 * cast(input_2_value_uint256 as double) / power(10, wrapped_btcs['Ethereum'][e.address].3) -- Burn
else 0
end) as net_flow
from evm_events_ethereum_mainnet_v1 e
where e.signature = 'Transfer(address,address,uint256)'
and e.address in mapKeys(wrapped_btcs['Ethereum'])
group by date, contract
union all
select
date_trunc('day', timestamp) as date,
e.address as contract,
wrapped_btcs['Arbitrum'][e.address].2 as symbol,
wrapped_btcs['Arbitrum'][e.address].3 as decimals,
wrapped_btcs['Arbitrum'][e.address].5 as chain,
sum(case
when input_0_value_address = '0x0000000000000000000000000000000000000000'
then cast(input_2_value_uint256 as double) / power(10, wrapped_btcs['Arbitrum'][e.address].3) -- Mint
when input_1_value_address = '0x0000000000000000000000000000000000000000'
then -1 * cast(input_2_value_uint256 as double) / power(10, wrapped_btcs['Arbitrum'][e.address].3) -- Burn
else 0
end) as net_flow
from evm_events_arbitrum_mainnet_v1 e
where e.signature = 'Transfer(address,address,uint256)'
and e.address in mapKeys(wrapped_btcs['Arbitrum'])
group by date, contract
union all
select
date_trunc('day', timestamp) as date,
e.address as contract,
wrapped_btcs['BNB'][e.address].2 as symbol,
wrapped_btcs['BNB'][e.address].3 as decimals,
wrapped_btcs['BNB'][e.address].5 as chain,
sum(case
when input_0_value_address = '0x0000000000000000000000000000000000000000'
then cast(input_2_value_uint256 as double) / power(10, wrapped_btcs['BNB'][e.address].3) -- Mint
when input_1_value_address = '0x0000000000000000000000000000000000000000'
then -1 * cast(input_2_value_uint256 as double) / power(10, wrapped_btcs['BNB'][e.address].3) -- Burn
else 0
end) as net_flow
from evm_events_bsc_mainnet_v1 e
where e.signature = 'Transfer(address,address,uint256)'
and e.address in mapKeys(wrapped_btcs['BNB'])
group by date, contract
union all
select
date_trunc('day', timestamp) as date,
e.address as contract,
wrapped_btcs['Base'][e.address].2 as symbol,
wrapped_btcs['Base'][e.address].3 as decimals,
wrapped_btcs['Base'][e.address].5 as chain,
sum(case
when input_0_value_address = '0x0000000000000000000000000000000000000000'
then cast(input_2_value_uint256 as double) / power(10, wrapped_btcs['Base'][e.address].3) -- Mint
when input_1_value_address = '0x0000000000000000000000000000000000000000'
then -1 * cast(input_2_value_uint256 as double) / power(10, wrapped_btcs['Base'][e.address].3) -- Burn
else 0
end) as net_flow
from evm_events_base_mainnet_v1 e
where e.signature = 'Transfer(address,address,uint256)'
and e.address in mapKeys(wrapped_btcs['Base'])
group by date, contract
),
-- Aggregate daily net flows and calculate cumulative flow
daily_and_cumulative_flows as (
select
date,
symbol,
chain,
sum(net_flow) as daily_net_flow,
sum(sum(net_flow)) over(partition by symbol, chain order by date asc) as cumulative_net_flow
from flows
group by date, symbol, chain
),
-- Filter for the last 30 days
flows_last_30_days as (
select *
from daily_and_cumulative_flows
where date >= now() - interval 90 day
),
-- Calculate the total cumulative flow for each symbol over the last 30 days
symbol_totals as (
select
symbol,
max(cumulative_net_flow) as max_cumulative_net_flow
from flows_last_30_days
group by symbol
),
-- Calculate the grand total cumulative flow across all tokens
total_cumulative_flow as (
select sum(max_cumulative_net_flow) as grand_total_flow
from symbol_totals
),
-- Join to label tokens that are below the 1% threshold as "Other"
labeled_symbols as (
select
s.symbol,
s.max_cumulative_net_flow,
case
when s.max_cumulative_net_flow / t.grand_total_flow < 0.01 then 'Other'
else s.symbol
end as symbol_category
from symbol_totals s
join total_cumulative_flow t on true
),
-- Join back to the flows_last_30_days data to apply the "Other" labeling
categorized_flows as (
select
f.date,
l.symbol_category,
f.cumulative_net_flow
from flows_last_30_days f
join labeled_symbols l on f.symbol = l.symbol
),
-- Pivot data into separate columns for each symbol and "Other"
pivoted_data as (
select
date as chart_x,
maxIf(cumulative_net_flow, symbol_category = 'cbBTC') as chart_y_cbBTC,
maxIf(cumulative_net_flow, symbol_category = 'LBTC') as chart_y_LBTC,
maxIf(cumulative_net_flow, symbol_category = 'SolvBTC.BBN') as chart_y_SolvBTC_BBN,
maxIf(cumulative_net_flow, symbol_category = 'SolvBTC') as chart_y_SolvBTC,
maxIf(cumulative_net_flow, symbol_category = 'tBTC') as chart_y_tBTC,
maxIf(cumulative_net_flow, symbol_category = 'pumpBTC') as chart_y_pumpBTC,
maxIf(cumulative_net_flow, symbol_category = 'BBTC (Binance)') as chart_y_BBTC_Binance,
maxIf(cumulative_net_flow, symbol_category = 'Other') as chart_y_Other
from categorized_flows
group by date
order by date
)
-- Final select with all tokens and "Other" as separate columns
select * from pivoted_data;