with fee_data as (
SELECT
date(ac.BLOCK_TIMESTAMP) as date,
sum(pt.amount) as fee
from algorand.transactions ac, algorand.transactions mi
join algorand.payment_transaction pt on mi.tx_group_id = pt.tx_group_id and pt.receiver = 'MTMJ5ADRK3CFG3HGUI7FS4Y55WGCUO5CRUMVNBZ7FW5IIG6T3IU2VJHUMM'
where ac.BLOCK_TIMESTAMP::date >= '2022-03-31'
and ac.tx_group_id = mi.tx_group_id
and mi.tx_type_name = 'asset transfer'
and mi.asset_id = '684649988' -- GARD
and TRY_BASE64_DECODE_STRING(ac.tx_message:txn:apaa[0]::STRING) = 'NewPosition'
and ac.tx_message:txn:apid::string = '684650147'
GROUP BY date
)
SELECT
date,
sum(fee) over (order by date asc) as "Cumulative fee Amount"
from fee_data