MahrooUntitled Query
    Updated 2022-09-14
    WITH safeCte AS ( SELECT DISTINCT from_address
    FROM ethereum.core.fact_traces
    WHERE 1=1
    AND tx_status = 'SUCCESS'
    AND type = 'DELEGATECALL'
    AND (
    substr(input,1,10) = '0x0ec78d9e'
    AND to_address = '0x8942595a2dc5181df0465af0d7be08c8f23c93af'
    )
    OR (
    substr(input,1,10) = '0xa97ab18a'
    AND to_address = '0xb6029ea3b2c51d09a50b53ca8012feeb05bda35a'
    )
    OR (
    substr(input,1,10) = '0xb63e800d'
    AND to_address IN ('0xae32496491b53841efb51829d6f886387708f99b','0x34cfac646f301356faa8b21e94227e3583fe3f5f','0x6851d6fdfafd08c0295c392436245e5bc78b0185','0xd9db270c1b5e3bd161e8c8503c55ceabee709552','0x3e5c63644e683549055b9be8653de26e0b4cd36e') -- mastercopy v1.1.0, 1.1.1, 1.2.0, 1.3.0, 1.3.0L2
    )
    AND BLOCK_TIMESTAMP::date BETWEEN '2022-02-09' AND '2022-08-17')
    , stablecoin_tx_cte AS (SELECT BLOCK_TIMESTAMP, BLOCK_TIMESTAMP::date date , b.from_address safe
    , CASE WHEN a.to_address = b.from_address THEN 'store'
    WHEN a.from_address = b.from_address THEN 'withdraw'
    END tx_type
    , tx_hash
    , amount
    FROM ethereum.core.ez_token_transfers a
    JOIN create_safe_cte b ON (a.from_address = b.from_address OR a.to_address = b.from_address)
    WHERE 1=1
    AND amount > 0
    AND contract_address IN (
    '0x6b175474e89094c44da98b954eedeac495271d0f', -- DAI
    '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', -- SAI
    '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', -- USDC
    '0xdac17f958d2ee523a2206206994597c13d831ec7' -- USDT
    )
    AND a.from_address != a.to_address -- transfer from Safe to itself doesn't have an influence on the balance
    )
    Run a query to Download Data