hessWeekly Miso
    Updated 2022-09-19
    with polygon_tx as ( select tx_hash
    from polygon.core.fact_event_logs
    where event_name = 'AddedCommitment')
    ,
    polygon_data as ( select trunc(block_timestamp,'week') as date, origin_from_address ,tx_hash, contract_address as token, EVENT_INPUTS:to as project,
    EVENT_INPUTS:value as amount
    from polygon.core.fact_event_logs
    where event_name = 'Transfer' and tx_hash in (select tx_hash from polygon_tx))
    ,
    polygon as ( select date, origin_from_address , tx_hash , project::string as projects, case when token = '0x45c32fa6df82ead1e2ef74d17b76547eddfaff89' then 'FRAX'
    when token = '0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a' then 'SUSHI'
    when token = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174' then 'USDC'
    when token = '0xc2132d05d31c914a87c6611c10748aeb04b58e8f' then 'USDT' end as tokens ,
    case when token = '0x45c32fa6df82ead1e2ef74d17b76547eddfaff89' then amount/pow(10,18)
    when token = '0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a' then amount/pow(10,18)
    when token = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174' then amount/pow(10,6)
    when token = '0xc2132d05d31c914a87c6611c10748aeb04b58e8f' then amount/pow(10,6) end as amounts
    from polygon_data
    UNION
    select trunc(block_timestamp,'week') as date, origin_from_address , tx_hash, origin_to_address::string as projects, 'MATIC' as tokens, AMOUNT as amounts
    from polygon.core.ez_matic_transfers
    where tx_hash in (select tx_hash from polygon_tx))
    ,
    ethereum_tx as ( select tx_hash
    from ethereum.core.fact_event_logs
    where event_name = 'AddedCommitment')
    ,
    ethereum_data as ( select trunc(block_timestamp,'week') as date, origin_from_address ,tx_hash, contract_address as token, EVENT_INPUTS:to as project,
    EVENT_INPUTS:value as amount
    from ethereum.core.fact_event_logs
    where event_name = 'Transfer' and tx_hash in (select tx_hash from ethereum_tx))
    ,
    ethereum as ( select date, origin_from_address , tx_hash , project::string as projects ,SYMBOL as tokens, amount/pow(10,decimals) as amounts
    from ethereum_data a join ethereum.core.fact_hourly_token_prices b on a.token = b.token_address
    UNION
    select trunc(block_timestamp,'week') as date, origin_from_address , tx_hash, origin_to_address::string as projects, 'ETH' as tokens, AMOUNT as amounts
    Run a query to Download Data