Sbhn_NP$AXL Holders Divided by Osmosis and Axelar Chains
    Updated 2022-12-03
    --credit : alik110
    with ReceiveTable as (
    select block_timestamp::date as date,
    tx_id,
    receiver,
    amount / pow (10,decimal) as Receive_Volume
    from axelar.core.fact_transfers
    where currency = 'uaxl'
    and transfer_type in ('AXELAR','IBC_TRANSFER_IN')),

    SendTable as (
    select block_timestamp::date as date,
    tx_id,
    sender,
    amount / pow (10,decimal) as Send_Volume
    from axelar.core.fact_transfers
    where currency = 'uaxl'
    and transfer_type in ('AXELAR','IBC_TRANSFER_OUT')),

    maintable as (
    select t1.date,
    receiver as AXL_Holder,
    sum (Send_Volume) as Daily_Send_Volume,
    sum (Receive_Volume) as Daily_Receive_Volume
    from ReceiveTable t1 join SendTable t2 on t1.Date = t2.Date and t1.Receiver = t2.Sender
    group by 1,2),

    FinalTable as (
    select date,
    AXL_Holder,
    ifnull (Daily_Receive_Volume, 0) as Daily_Receive_Volumes,
    ifnull (Daily_Send_Volume, 0) as Daily_Send_Volumes,
    Daily_Receive_Volumes - Daily_Send_Volumes as NET_AXL_Balance,
    sum (NET_AXL_Balance) over (partition by AXL_Holder order by date) as Balance
    from maintable)

    Run a query to Download Data