misaghlbTerradash Part 1: Activity - wallet balance holder
Updated 2022-12-07
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 raw1 as (
SELECT t.*,
split(CURRENCY, ',') as aa
from terra.core.ez_transfers t
where CURRENCY like '%uluna%'
and TX_SUCCEEDED = 'TRUE'
),
raw2 as (
SELECT
f.value as aa2,
*,
REGEXP_SUBSTR(aa2, $$[^\d*][\S+]*$$) AS input_ibc,
CAST(REGEXP_SUBSTR(aa2, $$^\d*$$) AS bigint) AS input_amount,
case when currency = 'uluna' and CAST(amount AS bigint) > 0 then (CAST(amount AS bigint) ) when INPUT_IBC = 'uluna' and INPUT_AMOUNT > 0 then try_to_number(INPUT_AMOUNT) end as main_amount
from raw1, table(flatten(aa)) f
where INPUT_IBC = 'uluna'
),
raw3 as (
SELECT
sender as address,
(main_amount)/1e6 * -1 as flow
FROM raw2
where TX_SUCCEEDED = 'TRUE'
union all
select
receiver as address,
(main_amount)/1e6 as flow
FROM raw2
where TX_SUCCEEDED = 'TRUE'
),
wallets as (
select
address ,
sum(flow) as balance
Run a query to Download Data