SELECT date_trunc('day', block_timestamp) as date,
sum(CASE
WHEN instruction:programId = 'MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD' THEN inner_instruction:instructions[1]:parsed:info:lamports/1e9
WHEN instruction:programId = 'mRefx8ypXNxE59NhoBqwqb3vTvjgf8MYECp4kgJWiDY' THEN inner_instruction:instructions[2]:parsed:info:lamports/1e9
ELSE 0 END) as amount,
count(tx_id) as n_txn
FROM solana.core.fact_events
WHERE date_trunc('day', block_timestamp) >= '2022-02-01'
AND ((instruction:programId = 'MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD'
AND inner_instruction:instructions[0]:parsed:info:source = '7GgPYjS5Dza89wV6FpZ23kUJRG5vbQ1GM25ezspYFSoE') or (
instruction:programId = 'mRefx8ypXNxE59NhoBqwqb3vTvjgf8MYECp4kgJWiDY'
AND inner_instruction:instructions[1]:parsed:info:source = '7GgPYjS5Dza89wV6FpZ23kUJRG5vbQ1GM25ezspYFSoE'))
AND succeeded = 'TRUE'
GROUP by date