WITH deposit AS (
SELECT
date_trunc ('month', block_timestamp) AS "date",
SUM (AMOUNT) AS deposited_amount,
SUM (deposited_amount) over (order by "date") as acm_deposit,
COUNT (*) AS deposit_transactions
FROM flipside_prod_db.crosschain.ez_lending
WHERE ACTION = 'Deposit'
AND SYMBOL = 'USDC'
GROUP BY "date"
ORDER BY "date"
),
withdraw AS (
SELECT
date_trunc ('month', block_timestamp) AS "date",
SUM (AMOUNT) AS withdrawn_amount,
SUM (withdrawn_amount) over (order by "date") as acm_withdrawn,
COUNT (*) AS withdraw_transactions
FROM flipside_prod_db.crosschain.ez_lending
WHERE ACTION = 'Withdraw'
AND SYMBOL = 'USDC'
GROUP BY "date"
ORDER BY "date"
)
SELECT
a."date",
a.deposited_amount,
a.deposit_transactions,
a.acm_deposit,
b.withdrawn_amount,
b.withdraw_transactions,
b.acm_withdrawn
FROM deposit a
FULL JOIN withdraw b ON a."date" = b."date"