Skip to content

Instantly share code, notes, and snippets.

@Vergan-star
Created September 30, 2020 06:03
Show Gist options
  • Save Vergan-star/e05f4c3107ae8293063cb358628c6353 to your computer and use it in GitHub Desktop.
Save Vergan-star/e05f4c3107ae8293063cb358628c6353 to your computer and use it in GitHub Desktop.
tbtc_suuply
WITH tBTC AS
(
SELECT
date_trunc('day', block_time) as day,
COALESCE(sum(e.value/1e18), 0) as supply
FROM erc20."ERC20_evt_Transfer" e
LEFT JOIN ethereum."transactions" tx ON evt_tx_hash = tx.hash
WHERE "contract_address" = '\x8dAEBADE922dF735c38C80C7eBD708Af50815fAa' -- tBTC contract address
and e."from" = '\x0000000000000000000000000000000000000000'
GROUP BY 1
UNION ALL
SELECT
date_trunc('day', block_time) as day,
COALESCE(sum(-e.value/1e18), 0) as supply
FROM erc20."ERC20_evt_Transfer" e
LEFT JOIN ethereum."transactions" tx ON evt_tx_hash = tx.hash
WHERE "contract_address" = '\x8dAEBADE922dF735c38C80C7eBD708Af50815fAa' -- tBTC contract address
and e."to" = '\x0000000000000000000000000000000000000000'
GROUP BY 1
)
SELECT
sum(supply)
FROM tBTC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment