AMLBotCEX flow
    Updated 2023-09-20
    with cex_address as
    (
    select address, label from {{blockchain}}.core.dim_labels
    where label_type='cex'
    ),
    cex_outflow as(
    select date_trunc('day', block_timestamp) day,
    label,
    count(distinct tx_hash) as outflow_tx,
    count(distinct from_address) as outflow_unique_users,
    sum(raw_amount/power(10, decimals)) as outflow_volume_usd
    from {{blockchain}}.core.fact_token_transfers transfers
    left join {{blockchain}}.core.dim_contracts contracts
    on transfers.contract_address = contracts.address
    join cex_address
    on transfers.from_address = cex_address.address
    where contract_address = lower('{{token_address}}')
    and block_timestamp::date >= current_date - {{days_back}}
    group by day, label
    order by day, label
    ),
    -- sending the asset to cex
    cex_inflow as(
    select date_trunc('day', block_timestamp) day,
    label,
    count(distinct tx_hash) as inflow_tx,
    count(distinct to_address) as inflow_unique_users,
    sum(raw_amount/power(10, decimals)) as inflow_volume_usd
    from {{blockchain}}.core.fact_token_transfers transfers
    left join {{blockchain}}.core.dim_contracts contracts
    on transfers.contract_address = contracts.address
    join cex_address
    on transfers.to_address = cex_address.address
    where contract_address = lower('{{token_address}}')
    and block_timestamp::date >= current_date - {{days_back}}
    group by day, label
    Run a query to Download Data