Afonso_DiazOvertime
    Updated 2024-11-01
    with

    pricet as (
    select
    block_timestamp::date as day,
    avg(rune_usd) as token_price_usd
    from
    thorchain.price.fact_prices t1
    group by 1
    )

    select
    date_trunc('{{ period }}', day) as date,
    sum(earnings * token_price_usd) as earnings_usd,
    sum(earnings) as earnings_rune,
    sum(bonding_earnings * token_price_usd) as bonding_earnings_usd,
    sum(bonding_earnings) as bonding_earnings_rune,
    sum(liquidity_earnings * token_price_usd) as liquidity_earnings_usd,
    sum(liquidity_earnings) as liquidity_earnings_rune,
    sum(liquidity_fee * token_price_usd) as liquidity_fee_usd,
    sum(liquidity_fee) as liquidity_fee_rune,
    sum(block_rewards * token_price_usd) as block_rewards_usd,
    sum(block_rewards) as block_rewards_rune,
    sum(earnings_rune) over (order by date) as cumulative_earnings_rune,
    sum(earnings_usd) over (order by date) as cumulative_earnings_usd,
    sum(liquidity_earnings_rune) over (order by date) as cumulative_liquidity_earnings_rune,
    sum(liquidity_earnings_usd) over (order by date) as cumulative_liquidity_earnings_usd,
    sum(liquidity_fee_rune) over (order by date) as cumulative_liquidity_fee_rune,
    sum(liquidity_fee_usd) over (order by date) as cumulative_liquidity_fee_usd,
    sum(block_rewards_rune) over (order by date) as cumulative_block_rewards_rune,
    sum(block_rewards_usd) over (order by date) as cumulative_block_rewards_usd
    from
    thorchain.defi.fact_block_rewards rewards
    join
    pricet using (day)
    where
    QueryRunArchived: QueryRun has been archived