MLDZMNnfttrader8
    Updated 2023-10-22
    -- forked from nfttrader8 @ https://flipsidecrypto.xyz/edit/queries/aadc8f0c-01bd-4d19-a01e-07a1b0520557

    with pallet as ( select DISTINCT tx_id,
    msg_type
    from sei.core.fact_msg_attributes
    where ATTRIBUTE_VALUE in ('sei152u2u0lqc27428cuf8dx48k8saua74m6nql5kgvsu4rfeqm547rsnhy4y9')
    and ATTRIBUTE_KEY = '_contract_address'
    and msg_type in ('wasm-buy_now','wasm-accept_bid')
    and TX_SUCCEEDED = 'true'
    and block_timestamp::date >= '2023-08-26')
    ,
    seller as ( select block_timestamp, tx_id, msg_index, ATTRIBUTE_VALUE as seller
    from sei.core.fact_msg_attributes
    where tx_id in (select tx_id from pallet)
    and ATTRIBUTE_KEY = 'nft_seller'
    and block_timestamp::date >= '2023-08-26')
    ,
    price as ( select a.block_timestamp, a.tx_id, a.msg_index,seller, case when attribute_value ilike 'native:%' then substr(attribute_value, 13,24)
    else split(attribute_value, 'usei')[0] end as prices, prices/pow(10,6) as price
    from sei.core.fact_msg_attributes a join seller b on a.tx_id = b.tx_id and a.msg_index = b.msg_index
    where ATTRIBUTE_KEY = 'sale_price'
    and a.block_timestamp::date >= '2023-08-26')
    ,
    buyer as ( select a.block_timestamp, 'Pallet' as platform, a.tx_id, a.msg_index,seller, price , ATTRIBUTE_VALUE as buyer
    from sei.core.fact_msg_attributes a join price b on a.tx_id = b.tx_id
    where ATTRIBUTE_KEY in ('fee_payer','sold_to')
    and a.block_timestamp::date >= '2023-08-26'
    )
    ,
    pallet_bid as ( select block_timestamp, tx_id, ATTRIBUTE_VALUE as buyer
    from sei.core.fact_msg_attributes
    where ATTRIBUTE_KEY = 'sold_to'
    and msg_type = 'wasm-accept_bid'
    and block_timestamp::Date >= '2023-08-26'
    and tx_id in (select tx_id from pallet) )
    ,
    Run a query to Download Data