with eth_lend_depo as (
select
lending_pool,
sum(amount_usd) as deposit_usd
from flipside_prod_db.crosschain.ez_lending
where platform = 'sushi' and blockchain = 'ethereum'
and action = 'Deposit' and block_timestamp >= '2022-01-01'
and amount_usd is not null
group by 1
), eth_lend_with as (
select
lending_pool,
sum(amount_usd) as withdraw_usd
from flipside_prod_db.crosschain.ez_lending
where platform = 'sushi' and blockchain = 'ethereum'
and action = 'Withdraw' and block_timestamp >= '2022-01-01'
and amount_usd is not null
group by 1
)
select
a.lending_pool,
(b.withdraw_usd - a.deposit_usd) as user_earning
from eth_lend_depo a
left outer join eth_lend_with b
on a.lending_pool = b.lending_pool
where user_earning is not null
order by 2 desc limit 5