theericstoneInterest Paid Out on Compound by Market by Day
    Updated 2021-11-10
    with markets as (
    select
    distinct
    ctoken_address,
    ms.contract_name,
    underlying_contract,
    er.decimals as decimals
    from
    compound.market_stats ms
    join
    ethereum.token_prices_hourly er
    on er.token_address = ms.underlying_contract
    where ms.block_hour > current_timestamp - interval '12 hours'
    and er.hour > current_timestamp - interval '12 hours'
    ),

    token_prices as (
    select block_hour,
    ctoken_address,
    token_price
    from compound.market_stats
    where block_hour > current_date - interval '31 days'
    ),

    accruals as (
    select block_timestamp,
    m.contract_name as market_name,
    ee.contract_address as market_contract_address,
    m.decimals as decs,
    cp.token_price as price,
    (event_inputs:interestAccumulated / pow(10,decs)) * cp.token_price as interest_owed
    from ethereum.events_emitted ee
    join markets m on ee.contract_address = m.ctoken_address
    join token_prices cp on cp.block_hour = date_trunc('hour',ee.block_timestamp) and cp.ctoken_address = ee.contract_address
    and ee.event_name = 'AccrueInterest' and ee.block_timestamp > current_date - interval '31 days'
    )
    Run a query to Download Data