with t as (
select
tx_id,
block_timestamp,
nvl(signers[1], signers[0]) as user,
iff(pre.value:owner = 'FK1VcVh5PqEUm8U3aEz69DRSNSCjD6cMjzGx3KKbiE8', 'Fee', 'Subscribe') as type,
(post.value:uiTokenAmount:amount - pre.value:uiTokenAmount:amount)/1e6 as amount_acs
from solana.core.fact_transactions
join lateral flatten (input => pre_token_balances) pre
join lateral flatten (input => post_token_balances) post
where log_messages::string ilike '%6HW8dXjtiTGkD4jzXs7igdFmZExPpmwUrRN5195xGup%'
and log_messages::string ilike '%Program log: Instruction: Stake%'
and succeeded = 1
and pre.value:owner != user
and pre.value:owner = post.value:owner
)
select * from t
where block_timestamp::date >= '2023-07-01' and block_timestamp::date < '2023-08-01'
order by block_timestamp
limit 15000
offset 195000;