with act1 as (
with tab1 as (
select SENDER
from osmosis.mars.ez_redbank_actions
where TX_SUCCEEDED='TRUE'
and ACTION='borrow'
and CURRENCY='uosmo'),
tab2 as (
select DELEGATOR_ADDRESS
,AMOUNT
,DECIMAL
,VALIDATOR_ADDRESS
from osmosis.core.fact_staking
where TX_SUCCEEDED='TRUE')
select VALIDATOR_ADDRESS
,count(distinct DELEGATOR_ADDRESS) as mars_borrowers
,sum(amount/pow(10,decimal)) as stake_amount
from tab1
left join tab2
on tab1.sender=tab2.DELEGATOR_ADDRESS
group by 1
order by 3 desc
limit 22 ),
act2 as (
select ADDRESS
,LABEL
from osmosis.core.fact_validators)
select act1.*,LABEL
from act1
left join act2
on act1.VALIDATOR_ADDRESS=act2.ADDRESS
where label is not null