with label as (
SELECT
address,
label_type,
project_name
FROM avalanche.core.dim_labels
)
, main_table as(
SELECT
date_trunc('day', block_timestamp) as date,
pool_name as pool,
platform,
tx_hash,
sender,
tx_to,
origin_to_address,
origin_from_address
FROM avalanche.core.ez_dex_swaps
WHERE
token_in = '0x714f020c54cc9d104b6f4f6998c63ce2a31d1888'
OR token_out = '0x714f020c54cc9d104b6f4f6998c63ce2a31d1888'
)
SELECT
date,
b.label_type,
b.project_name,
count(tx_hash) as swaps
FROM main_table a
LEFT JOIN label b ON a.origin_to_address = b.address OR a.tx_to = b.address
WHERE label_type IS NOT NULL
GROUP BY 1 , 3 , 2