with LUNA2_price as (
select
block_timestamp::date as p_date,
median(to_amount/from_amount) as USDPrice
from terra.core.ez_swaps
where from_currency = 'uluna'
and to_currency in ('ibc/CBF67A2BCF6CAE343FDF251E510C8E18C361FC02B23430C121116E0811835DEF',
'ibc/B3504E092456BA618CC28AC671A71FB08C6CA0FD0BE7C8A5B5A3E2DD933CC9E4') --USDC,USDT
and to_amount > 0
and from_amount > 0
and tx_succeeded = TRUE
group by 1
)
select
receiver as "Reciver",
sum(amount*USDPrice/pow(10,6)) as "Reward Volume($)"
FROM terra.core.ez_transfers t JOIN LUNA2_price p on t.block_timestamp::date = p.p_date
WHERE MESSAGE_VALUE['@type'] ='/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward'
AND CURRENCY='uluna'
AND block_timestamp::date <= CURRENT_DATE-1
GROUP BY 1
order by 2 DESC
limit 10