KaskoazulGARD extended
    Updated 2022-07-10
    with app_calls_AG as (
    select tx_group_id
    from algorand.application_call_transaction
    where app_id = 684650147
    and block_timestamp >= '2022-06-30' and block_timestamp <= '2022-07-14'
    --and TRY_BASE64_DECODE_STRING(tx_message :txn :apaa [0] :: STRING) IS NOT NULL --= 'NewPosition'--
    ),
    all_amounts_AG as (
    select pt.block_timestamp,
    pt.tx_group_id,
    pt.sender as owner,
    pt.receiver as governor,
    pt.amount,
    try_base64_decode_string(c.tx_message:txn:apaa[0]::string) as arg2,
    try_base64_decode_binary(c.tx_message:lsig:arg[0]::string)::string as arg1
    from algorand.payment_transaction pt
    left join algorand.application_call_transaction c
    on pt.tx_group_id = c.tx_group_id
    where pt.tx_group_id in (select tx_group_id from app_calls_AG)
    and pt.receiver <> 'MTMJ5ADRK3CFG3HGUI7FS4Y55WGCUO5CRUMVNBZ7FW5IIG6T3IU2VJHUMM' --GARD's fee address
    and pt.amount <> 0
    ),

    governors_deposits_agg_AG as (
    select block_timestamp::date as fecha,
    governor,
    sum (amount) as deposit
    from all_amounts_AG
    group by fecha, governor
    order by fecha
    ),

    governors_withdraws_AG as (
    select block_timestamp,
    tx_group_id,
    tx_id,
    Run a query to Download Data