bachilil nouns voting
    Updated 2022-06-21
    WITH txns AS
    (
    SELECT tx_hash,
    Round(Sum(gas_used * gas_price),2) AS gas_fees
    FROM ethereum.core.fact_transactions
    GROUP BY tx_hash ), votingdtls AS
    (
    SELECT tx_hash,
    origin_from_address AS voter,
    EVENT_INPUTS:proposalid AS proposal,
    EVENT_INPUTS:votes AS votes
    FROM ethereum.core.fact_event_logs
    WHERE contract_address = '0x5d2c31ce16924c2a71d317e5bbfd5ce387854039'
    AND event_name = 'VoteCast' ), gasfees AS
    (
    SELECT a.voter,
    a.proposal,
    a.votes,
    b.gas_fees
    FROM votingdtls a
    JOIN txns b
    ON a.tx_hash = b.tx_hash ), holdingdtls AS
    (
    SELECT user_address,
    amount_usd
    FROM flipside_prod_db.ethereum.erc20_balances
    WHERE amount_usd > 0
    AND amount_usd IS NOT NULL )
    /*select count(distinct voter) as voters, sum(votes) as votes_casted, proposal
    from gasfees group by proposal*/
    SELECT DISTINCT a.voter,
    round(b.amount_usd,2) AS holdings_usd
    FROM votingdtls a
    JOIN holdingdtls b
    ON a.voter = b.user_address
    AND b.amount_usd >= 1
    Run a query to Download Data