primo_dataNEAR Gas Guzzlers
    Updated 2022-07-24
    --What contracts are users spending the most gas on to use? How has this changed over the past week? Past month?
    --Hint: The gas units in the table are in raw (not decimal adjusted) format. To adjust accordingly, divide by 10^12.
    -- Each NEAR account can only hold one smart contract. However, you can create "subaccounts" with a "master account" for apps with multiple contracts.
    -- Account naming follows the internet domains model. So for example, the account user-A-account can create subaccounts contract1.user-A-account and contract2.user-A-account.
    -- https://near.org/bridge/
    -- https://docs.near.org/concepts/basics/transactions/gas

    select
    date(block_timestamp) dt
    , tx_receiver contract
    , case when tx_receiver like 'sigma%.near' then 'sigma.near' else tx_receiver end contract
    , case when tx_receiver like 'sigma%.near' then 'sigma.near'
    when tx_receiver like '%.factory.bridge.near' then 'factory.bridge.near'
    when tx_receiver like '%.%.%.near' then split_part(tx_receiver ,'.',3) || '.near'
    when tx_receiver like '%.%.near' then split_part(tx_receiver ,'.',2) || '.near'
    when tx_receiver like 'rezerv%.near' then 'rezerv.near'
    else tx_receiver end account
    , count(txn_hash) txn_ct
    , sum(gas_used / pow(10,12)) total_gas_near
    from flipside_prod_db.mdao_near.transactions t
    where date(block_timestamp) >= current_date - 7
    and date(block_timestamp) < current_date - 0
    and tx_receiver like '%near'
    group by 1,2,3
    having count(distinct txn_hash) > 1
    order by 1 desc

    Run a query to Download Data