superflyDaily Arbitrum Top 5 Destinations by Wallet count
    Updated 2023-01-13
    with table_1 as (select address
    from ethereum.core.dim_labels
    where label like '%arbitrum%'
    and label_type = 'layer2'),

    arbitrum as (select block_timestamp as bridge_date,
    origin_from_address as bridge_wallet
    from ethereum.core.ez_token_transfers a
    inner join ethereum.core.dim_labels b on b.address = a.from_address
    where to_address in (select address from table_1)
    and block_timestamp >= '{{Starting_Date}}'
    union
    select block_timestamp as bridge_date,
    origin_from_address as bridge_wallet
    from ethereum.core.ez_eth_transfers
    where eth_to_address in (select address from table_1)
    and block_timestamp >= '{{Starting_Date}}'),

    final1 as (select min(a.block_timestamp) as first,
    bridge_wallet,
    origin_to_address,
    tx_hash
    from arbitrum.core.fact_event_logs a
    join arbitrum b on a.origin_from_address = b.bridge_wallet
    where a.block_timestamp > bridge_date
    group by 2,3,4),

    final2 as (select date_trunc('{{Periodical}}', first) as {{Periodical}},
    split (address_name, ':')[0] as destination_names,
    initcap(destination_names) as destination_name,
    count(distinct(bridge_wallet)) as wallet_count,
    row_number () over (partition by {{Periodical}} order by wallet_count desc) as count
    from final1 a
    join arbitrum.core.dim_labels c on a.origin_to_address = c.address
    where label_subtype != 'token_contract'
    group by 1,2)
    Run a query to Download Data