diff --git a/macros/models/_sector/nft/platforms/seaport_fork_trades.sql b/macros/models/_sector/nft/platforms/seaport_fork_trades.sql new file mode 100644 index 00000000000..aeadc3b4cae --- /dev/null +++ b/macros/models/_sector/nft/platforms/seaport_fork_trades.sql @@ -0,0 +1,726 @@ +{% macro seaport_fork_trades( + blockchain + ,source_transactions + ,Seaport_evt_OrderFulfilled + ,Seaport_call_matchAdvancedOrders + ,Seaport_call_matchOrders + ,fee_wallet_list_cte + ,native_token_address = '0x0000000000000000000000000000000000000000' + ,alternative_token_address = '0x0000000000000000000000000000000000000000' + ,native_token_symbol = 'ETH' + ,start_date = '2023-02-01' + ,seaport_fork_address = '0x00000000006c3852cbef3e08e8df289169ede581' +) %} +--This macro is a copy of seaport_v3_trades with support for a different contract address + +with source_ethereum_transactions as ( + select * + from {{ source_transactions }} + {% if not is_incremental() %} + where block_time >= TIMESTAMP '{{start_date}}' -- seaport first txn + {% endif %} + {% if is_incremental() %} + where block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +) +,ref_tokens_nft as ( + select * + from {{ ref('tokens_nft') }} + where blockchain = '{{ blockchain }}' +) +,ref_tokens_erc20 as ( + select * + from {{ ref('tokens_erc20') }} + where blockchain = '{{ blockchain }}' +) +,ref_nft_aggregators as ( + select * + from {{ ref('nft_aggregators') }} + where blockchain = '{{ blockchain }}' +) +,ref_nft_aggregators_marks as ( + select * + from {{ ref('nft_ethereum_aggregators_markers') }} +) +,source_prices_usd as ( + select * + from {{ source('prices', 'usd') }} + where blockchain = '{{ blockchain }}' + {% if not is_incremental() %} + and minute >= TIMESTAMP '{{start_date}}' -- seaport first txn + {% endif %} + {% if is_incremental() %} + and minute >= date_trunc('day', now() - interval '7' day) + {% endif %} +) +,fee_wallet_list as ( + select wallet_address, wallet_name + from {{ fee_wallet_list_cte }} +) +,iv_offer_consideration as ( + select evt_block_time as block_time + ,evt_block_number as block_number + ,evt_tx_hash as tx_hash + ,evt_index + ,'offer' as sub_type + ,offer_idx as sub_idx + ,case json_extract_scalar(element_at(offer,1),'$.itemType') + when '0' then 'native' + when '1' then 'erc20' + when '2' then 'erc721' + when '3' then 'erc1155' + else 'etc' + end as offer_first_item_type + ,case json_extract_scalar(element_at(consideration,1),'$.itemType') + when '0' then 'native' + when '1' then 'erc20' + when '2' then 'erc721' + when '3' then 'erc1155' + else 'etc' + end as consideration_first_item_type + ,offerer + ,recipient + ,offerer as sender + ,recipient as receiver + ,zone + ,from_hex(json_extract_scalar(offer_item,'$.token')) as token_contract_address + ,cast(json_extract_scalar(offer_item,'$.amount') as uint256) as original_amount + ,case json_extract_scalar(offer_item,'$.itemType') + when '0' then 'native' + when '1' then 'erc20' + when '2' then 'erc721' + when '3' then 'erc1155' + else 'etc' + end as item_type + ,cast(json_extract_scalar(offer_item,'$.identifier') as uint256) as token_id + ,contract_address as platform_contract_address + ,cardinality(offer) as offer_cnt + ,cardinality(consideration) as consideration_cnt + ,order_hash + ,false as is_private -- will be deprecated in base_pairs + from + ( + select consideration + , contract_address + , evt_block_number + , evt_block_time + , evt_index + , evt_tx_hash + , offer + , offerer + , recipient + , zone + , orderHash AS order_hash + , offer_idx + , offer_item + from {{ Seaport_evt_OrderFulfilled }} + cross join unnest(offer) with ordinality as foo(offer_item, offer_idx) + where contract_address = {{ seaport_fork_address }} -- seaport v1.1 + and recipient != 0x0000000000000000000000000000000000000000 + {% if not is_incremental() %} + and evt_block_time >= TIMESTAMP '{{start_date}}' -- seaport first txn + {% endif %} + {% if is_incremental() %} + and evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + ) + union all + select evt_block_time as block_time + ,evt_block_number as block_number + ,evt_tx_hash as tx_hash + ,evt_index + ,'consideration' as sub_type + ,consideration_idx as sub_idx + ,case json_extract_scalar(element_at(offer,1),'$.itemType') + when '0' then 'native' + when '1' then 'erc20' + when '2' then 'erc721' + when '3' then 'erc1155' + else 'etc' + end as offer_first_item_type + ,case json_extract_scalar(element_at(consideration,1),'$.itemType') + when '0' then 'native' + when '1' then 'erc20' + when '2' then 'erc721' + when '3' then 'erc1155' + else 'etc' + end as consideration_first_item_type + ,offerer + ,recipient + ,recipient as sender + ,from_hex(json_extract_scalar(consideration_item,'$.recipient')) as receiver + ,zone + ,from_hex(json_extract_scalar(consideration_item,'$.token')) as token_contract_address + ,cast(json_extract_scalar(consideration_item,'$.amount') as uint256) as original_amount + ,case json_extract_scalar(consideration_item,'$.itemType') + when '0' then 'native' + when '1' then 'erc20' + when '2' then 'erc721' + when '3' then 'erc1155' + else 'etc' -- actually not exists + end as item_type + ,cast(json_extract_scalar(consideration_item,'$.identifier') as uint256) as token_id + ,contract_address as platform_contract_address + ,cardinality(offer) as offer_cnt + ,cardinality(consideration) as consideration_cnt + ,order_hash + ,false as is_private -- will be deprecated in base_pairs + from + ( + select consideration + , contract_address + , evt_block_number + , evt_block_time + , evt_index + , evt_tx_hash + , offer + , offerer + , recipient + , zone + , orderHash AS order_hash + , consideration_item + , consideration_idx + from {{ Seaport_evt_OrderFulfilled }} + cross join unnest(consideration) with ordinality as foo(consideration_item,consideration_idx) + where contract_address = {{ seaport_fork_address }} -- Seaport v1.1 + and recipient != 0x0000000000000000000000000000000000000000 + {% if not is_incremental() %} + and evt_block_time >= TIMESTAMP '{{start_date}}' -- seaport first txn + {% endif %} + {% if is_incremental() %} + and evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + ) +) +,iv_match_output as ( + select block_time + ,block_number + ,tx_hash + ,evt_index + ,sub_type + ,sub_idx + ,case offer_first_item + when '0' then 'native' + when '1' then 'erc20' + when '2' then 'erc721' + when '3' then 'erc1155' + when '4' then 'erc721' + when '5' then 'erc1155' + else 'etc' + end as offer_first_item_type + ,case consider_first_item + when '0' then 'native' + when '1' then 'erc20' + when '2' then 'erc721' + when '3' then 'erc1155' + when '4' then 'erc721' + when '5' then 'erc1155' + else 'etc' + end as consideration_first_item_type + ,offerer + ,receiver as recipient + ,sender + ,receiver + ,zone + ,token_contract_address + ,cast(original_amount as uint256) as original_amount + ,case item_type_code + when '0' then 'native' + when '1' then 'erc20' + when '2' then 'erc721' + when '3' then 'erc1155' + when '4' then 'erc721' + when '5' then 'erc1155' + else 'etc' + end as item_type + ,token_id + ,platform_contract_address + ,1 as offer_cnt + ,1 as consideration_cnt + ,NULL as order_hash + ,false as is_private + from (select call_block_time as block_time + ,call_block_number as block_number + ,call_tx_hash as tx_hash + ,dense_rank() over (partition by call_tx_hash order by call_trace_address) as evt_index + ,'match_adv_ord' as sub_type + ,execution_idx as sub_idx + ,from_hex(json_extract_scalar(json_extract_scalar(advancedOrders[1],'$.parameters'),'$.zone')) as zone + ,from_hex(json_extract_scalar(json_extract_scalar(advancedOrders[1],'$.parameters'),'$.offerer')) as offerer + ,json_extract_scalar(json_extract_scalar(json_extract_scalar(advancedOrders[1],'$.parameters'),'$.offer[0]'),'$.itemType') as offer_first_item + ,json_extract_scalar(json_extract_scalar(json_extract_scalar(advancedOrders[1],'$.parameters'),'$.consideration[0]'),'$.itemType') as consider_first_item + ,from_hex(json_extract_scalar(execution,'$.offerer')) as sender + ,from_hex(json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.token')) as token_contract_address + ,json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.amount') as original_amount + ,json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.itemType') as item_type_code + ,cast(json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.identifier') as uint256) as token_id + ,from_hex(json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.recipient')) as receiver + ,contract_address as platform_contract_address + from (select * + from {{ Seaport_call_matchAdvancedOrders }} + cross join unnest(output_executions) with ordinality as foo(execution,execution_idx) + where call_success + and contract_address = {{ seaport_fork_address }} -- Seaport v1.1 + {% if not is_incremental() %} + and call_block_time >= timestamp '{{start_date}}' -- seaport first txn + {% else %} + and call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + ) + union all + select call_block_time as block_time + ,call_block_number as block_number + ,call_tx_hash as tx_hash + ,dense_rank() over (partition by call_tx_hash order by call_trace_address) as evt_index + ,'match_ord' as sub_type + ,execution_idx as sub_idx + ,from_hex(json_extract_scalar(json_extract_scalar(orders[1],'$.parameters'),'$.zone')) as zone + ,from_hex(json_extract_scalar(json_extract_scalar(orders[1],'$.parameters'),'$.offerer')) as offerer + ,json_extract_scalar(json_extract_scalar(json_extract_scalar(orders[1],'$.parameters'),'$.offer[0]'),'$.itemType') as offer_first_item + ,json_extract_scalar(json_extract_scalar(json_extract_scalar(orders[1],'$.parameters'),'$.consideration[0]'),'$.itemType') as consider_first_item + ,from_hex(json_extract_scalar(execution,'$.offerer')) as sender + ,from_hex(json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.token')) as token_contract_address + ,json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.amount') as original_amount + ,json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.itemType') as item_type_code + ,cast(json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.identifier') as uint256) as token_id + ,from_hex(json_extract_scalar(json_extract_scalar(execution,'$.item'),'$.recipient')) as receiver + ,contract_address as platform_contract_address + from (select * + from {{ Seaport_call_matchOrders }} + cross join unnest(output_executions) with ordinality as foo(execution,execution_idx) + where call_success + and contract_address = {{ seaport_fork_address }} -- Seaport v1.1 + {% if not is_incremental() %} + and call_block_time >= timestamp '{{start_date}}' -- seaport first txn + {% else %} + and call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + ) + ) +) +,iv_base_pairs as ( + select a.block_time + ,a.block_number + ,a.tx_hash + ,a.evt_index + ,a.sub_type + ,a.sub_idx + ,a.offer_first_item_type + ,a.consideration_first_item_type + ,a.offerer + ,a.recipient + ,a.sender + ,a.receiver + ,a.zone + ,a.token_contract_address + ,a.original_amount + ,a.item_type + ,a.token_id + ,a.platform_contract_address + ,a.offer_cnt + ,a.consideration_cnt + ,a.order_hash + ,a.is_private + ,a.is_self_trans + ,a.is_platform_fee + ,a.eth_erc_idx + ,a.nft_cnt + ,a.erc721_cnt + ,a.erc1155_cnt + ,cast(date_trunc('day', a.block_time) as date) as block_date + ,case when offer_first_item_type = 'erc20' then 'offer accepted' + when offer_first_item_type in ('erc721','erc1155') then 'buy' + else 'etc' -- some txns has no nfts + end as order_type + ,case when offer_first_item_type = 'erc20' and sub_type = 'offer' and item_type = 'erc20' then true + when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and item_type in ('native','erc20') then true + else false + end is_price + ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx = 0 then true -- offer accepted has no price at all. it has to be calculated. + when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx = 1 then true + else false + end is_netprice + ,case when is_platform_fee then false + when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx > 0 then true + when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx > 1 then true + else false + end is_creator_fee + ,sum(case when is_platform_fee then null + when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx > 0 then 1 + when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx > 1 then 1 + end) over (partition by tx_hash, evt_index order by eth_erc_idx) as creator_fee_idx + ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721','erc1155') then true + when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721','erc1155') then true + else false + end is_traded_nft + ,case when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and item_type in ('erc721','erc1155') then true + else false + end is_moved_nft + ,fee_wallet_name + from (select a.block_time + ,a.block_number + ,a.tx_hash + ,a.evt_index + ,a.sub_type + ,a.sub_idx + ,a.offer_first_item_type + ,a.consideration_first_item_type + ,a.offerer + ,a.recipient + ,a.sender + ,a.receiver + ,a.zone + ,a.token_contract_address + ,a.original_amount + ,a.item_type + ,a.token_id + ,a.platform_contract_address + ,a.offer_cnt + ,a.consideration_cnt + ,a.order_hash + ,a.is_private + ,f.wallet_name as fee_wallet_name + ,case when sender = receiver then true else false end is_self_trans + ,case when f.wallet_address is not null then true else false end as is_platform_fee + ,case when item_type in ('native','erc20') + then sum(case when item_type in ('native','erc20') then 1 end) over (partition by tx_hash, evt_index, sub_type order by sub_idx) + end as eth_erc_idx + ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721','erc1155') then 1 + when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721','erc1155') then 1 + end) over (partition by tx_hash, evt_index) as nft_cnt + ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721') then 1 + when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721') then 1 + end) over (partition by tx_hash, evt_index) as erc721_cnt + ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc1155') then 1 + when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc1155') then 1 + end) over (partition by tx_hash, evt_index) as erc1155_cnt + from iv_offer_consideration a + left join fee_wallet_list f on f.wallet_address = a.receiver + ) a + where not is_self_trans + -- match orders + union all + select a.block_time + ,a.block_number + ,a.tx_hash + ,a.evt_index + ,a.sub_type + ,a.sub_idx + ,a.offer_first_item_type + ,a.consideration_first_item_type + ,a.offerer + ,a.recipient + ,a.sender + ,a.receiver + ,a.zone + ,a.token_contract_address + ,a.original_amount + ,a.item_type + ,a.token_id + ,a.platform_contract_address + ,a.offer_cnt + ,a.consideration_cnt + ,a.order_hash + ,a.is_private + ,a.is_self_trans + ,a.is_platform_fee + ,a.eth_erc_idx + ,a.nft_cnt + ,a.erc721_cnt + ,a.erc1155_cnt + ,cast(date_trunc('day', a.block_time) as date) as block_date + ,case when offer_first_item_type in ('erc20','native') then 'offer accepted' + when offer_first_item_type in ('erc721','erc1155') then 'buy' + else 'etc' -- some txns has no nfts + end as order_type + ,case when item_type in ('native','erc20') then true + else false + end is_price + ,false as is_netprice -- it has to be calculated. + ,case when is_platform_fee then false -- to os fee wallet has to be excluded + when offer_first_item_type in ('erc721','erc1155') and eth_erc_idx = 1 then false -- buy = first transfer is is profit + when offer_first_item_type in ('erc20','native') and eth_erc_idx = eth_erc_cnt then false -- offer_accepted = last transfer is is profit + when eth_erc_idx > 0 then true -- else is all creator fees + else false + end is_creator_fee + ,sum(case when is_platform_fee then null -- to os fee wallet has to be excluded + when offer_first_item_type in ('erc721','erc1155') and eth_erc_idx = 1 then null -- buy = first transfer is is profit + when offer_first_item_type in ('erc20','native') and eth_erc_idx = eth_erc_cnt then null -- offer_accepted = last transfer is is profit + when eth_erc_idx > 0 then 1 -- else is all creator fees + end) over (partition by tx_hash, evt_index order by eth_erc_idx) as creator_fee_idx + ,case when item_type in ('erc721','erc1155') then true + else false + end is_traded_nft + ,false as is_moved_nft + ,fee_wallet_name + from (select a.block_time + ,a.block_number + ,a.tx_hash + ,a.evt_index + ,a.sub_type + ,a.sub_idx + ,a.offer_first_item_type + ,a.consideration_first_item_type + ,a.offerer + ,a.recipient + ,a.sender + ,a.receiver + ,a.zone + ,a.token_contract_address + ,a.original_amount + ,a.item_type + ,a.token_id + ,a.platform_contract_address + ,a.offer_cnt + ,a.consideration_cnt + ,a.order_hash + ,a.is_private + ,f.wallet_name as fee_wallet_name + ,case when sender = receiver then true else false end is_self_trans + ,case when f.wallet_address is not null then true else false end as is_platform_fee + ,case when item_type in ('native','erc20') + then sum(case when item_type in ('native','erc20') then 1 end) over (partition by tx_hash, evt_index, sub_type order by sub_idx) + end as eth_erc_idx + ,sum(case when item_type in ('erc721','erc1155') then 1 end) over (partition by tx_hash, evt_index) as nft_cnt + ,sum(case when item_type in ('erc721') then 1 end) over (partition by tx_hash, evt_index) as erc721_cnt + ,sum(case when item_type in ('erc1155') then 1 end) over (partition by tx_hash, evt_index) as erc1155_cnt + ,sum(case when item_type in ('native','erc20') then 1 end) over (partition by tx_hash, evt_index) as eth_erc_cnt + from iv_match_output a + left join fee_wallet_list f on f.wallet_address = a.receiver + ) a + where not is_self_trans +) +,iv_volume as ( + select block_date + ,block_time + ,tx_hash + ,evt_index + ,max(token_contract_address) as token_contract_address + ,CAST(sum(case when is_price then original_amount end) AS DOUBLE) as price_amount_raw + ,sum(case when is_platform_fee then original_amount end) as platform_fee_amount_raw + ,max(case when is_platform_fee then receiver end) as platform_fee_receiver + ,sum(case when is_creator_fee then original_amount end) as creator_fee_amount_raw + ,sum(case when is_creator_fee and creator_fee_idx = 1 then original_amount end) as creator_fee_amount_raw_1 + ,sum(case when is_creator_fee and creator_fee_idx = 2 then original_amount end) as creator_fee_amount_raw_2 + ,sum(case when is_creator_fee and creator_fee_idx = 3 then original_amount end) as creator_fee_amount_raw_3 + ,sum(case when is_creator_fee and creator_fee_idx = 4 then original_amount end) as creator_fee_amount_raw_4 + ,sum(case when is_creator_fee and creator_fee_idx = 5 then original_amount end) as creator_fee_amount_raw_5 + ,max(case when is_creator_fee and creator_fee_idx = 1 then receiver end) as creator_fee_receiver_1 + ,max(case when is_creator_fee and creator_fee_idx = 2 then receiver end) as creator_fee_receiver_2 + ,max(case when is_creator_fee and creator_fee_idx = 3 then receiver end) as creator_fee_receiver_3 + ,max(case when is_creator_fee and creator_fee_idx = 4 then receiver end) as creator_fee_receiver_4 + ,max(case when is_creator_fee and creator_fee_idx = 5 then receiver end) as creator_fee_receiver_5 + ,max(a.fee_wallet_name) as fee_wallet_name + + from iv_base_pairs a + where 1=1 + and eth_erc_idx > 0 + group by 1,2,3,4 + having count(distinct token_contract_address) = 1 -- some private sale trade has more that one currencies +) +,iv_nfts as ( + select a.block_date + ,a.block_time + ,a.tx_hash + ,a.evt_index + ,a.block_number + ,a.sender as seller + ,a.receiver as buyer + ,case when nft_cnt > 1 then 'bundle trade' + else 'single item trade' + end as trade_type + ,a.order_type + ,a.token_contract_address as nft_contract_address + ,a.original_amount as nft_token_amount + ,a.token_id as nft_token_id + ,a.item_type as nft_token_standard + ,a.zone + ,a.platform_contract_address + ,b.token_contract_address + ,CAST(round(price_amount_raw / nft_cnt) as uint256) as price_amount_raw -- to truncate the odd number of decimal places + ,cast(platform_fee_amount_raw / nft_cnt as uint256) as platform_fee_amount_raw + ,platform_fee_receiver + ,cast(creator_fee_amount_raw / nft_cnt as uint256) as creator_fee_amount_raw + ,creator_fee_amount_raw_1 / nft_cnt as creator_fee_amount_raw_1 + ,creator_fee_amount_raw_2 / nft_cnt as creator_fee_amount_raw_2 + ,creator_fee_amount_raw_3 / nft_cnt as creator_fee_amount_raw_3 + ,creator_fee_amount_raw_4 / nft_cnt as creator_fee_amount_raw_4 + ,creator_fee_amount_raw_5 / nft_cnt as creator_fee_amount_raw_5 + ,creator_fee_receiver_1 + ,creator_fee_receiver_2 + ,creator_fee_receiver_3 + ,creator_fee_receiver_4 + ,creator_fee_receiver_5 + ,case when nft_cnt > 1 then true + else false + end as estimated_price + ,is_private + ,sub_type + ,sub_idx + ,order_hash + ,b.fee_wallet_name + from iv_base_pairs a + left join iv_volume b on b.block_date = a.block_date -- tx_hash and evt_index is PK, but for performance, block_time is included + and b.tx_hash = a.tx_hash + and b.evt_index = a.evt_index + where 1=1 + and a.is_traded_nft +) +,iv_trades as ( + select a.block_date + ,a.block_time + ,a.tx_hash + ,a.evt_index + ,a.block_number + ,a.seller + ,a.buyer + ,a.trade_type + ,a.order_type + ,a.nft_contract_address + ,a.nft_token_amount + ,a.nft_token_id + ,a.nft_token_standard + ,a.zone + ,a.platform_contract_address + ,a.token_contract_address + ,a.price_amount_raw + ,a.platform_fee_amount_raw + ,a.platform_fee_receiver + ,a.creator_fee_amount_raw + ,a.creator_fee_amount_raw_1 + ,a.creator_fee_amount_raw_2 + ,a.creator_fee_amount_raw_3 + ,a.creator_fee_amount_raw_4 + ,a.creator_fee_amount_raw_5 + ,a.creator_fee_receiver_1 + ,a.creator_fee_receiver_2 + ,a.creator_fee_receiver_3 + ,a.creator_fee_receiver_4 + ,a.creator_fee_receiver_5 + ,a.estimated_price + ,a.is_private + ,a.sub_type + ,a.sub_idx + ,n.name AS nft_token_name + ,t."from" as tx_from + ,t.to as tx_to + ,bytearray_reverse(bytearray_substring(bytearray_reverse(t.data),1,4)) as right_hash + ,case when a.token_contract_address = {{native_token_address}} then '{{native_token_symbol}}' + else e.symbol + end as token_symbol + ,case when a.token_contract_address = {{native_token_address}} then {{alternative_token_address}} + else a.token_contract_address + end as token_alternative_symbol + ,e.decimals as price_token_decimals + ,a.price_amount_raw / power(10, e.decimals) as price_amount + ,a.price_amount_raw / power(10, e.decimals) * p.price as price_amount_usd + ,a.platform_fee_amount_raw / power(10, e.decimals) as platform_fee_amount + ,a.platform_fee_amount_raw / power(10, e.decimals) * p.price as platform_fee_amount_usd + ,a.creator_fee_amount_raw / power(10, e.decimals) as creator_fee_amount + ,a.creator_fee_amount_raw / power(10, e.decimals) * p.price as creator_fee_amount_usd + ,coalesce(agg_m.aggregator_name, agg.name) as aggregator_name + ,agg.contract_address AS aggregator_address + ,a.fee_wallet_name + from iv_nfts a + inner join source_ethereum_transactions t on t.hash = a.tx_hash + left join ref_tokens_nft n on n.contract_address = nft_contract_address + left join ref_tokens_erc20 e on e.contract_address = case when a.token_contract_address = {{native_token_address}} then {{alternative_token_address}} + else a.token_contract_address + end + left join source_prices_usd p on p.contract_address = case when a.token_contract_address = {{native_token_address}} then {{alternative_token_address}} + else a.token_contract_address + end + and p.minute = date_trunc('minute', a.block_time) + left join ref_nft_aggregators agg on agg.contract_address = t.to + left join ref_nft_aggregators_marks agg_m on bytearray_starts_with(bytearray_reverse(t.data), bytearray_reverse(agg_m.hash_marker)) +) + -- Rename column to align other *.trades tables + -- But the columns ordering is according to convenience. + -- initcap the code value if needed +select + -- basic info + '{{blockchain}}' as blockchain + ,'opensea' as project + ,'v3' as version + + -- order info + ,block_date + ,block_time + ,seller + ,buyer + ,trade_type + ,order_type as trade_category -- Buy / Offer Accepted + ,'Trade' as evt_type + + -- nft token info + ,nft_contract_address + ,nft_token_name as collection + ,nft_token_id as token_id + ,nft_token_amount as number_of_items + ,nft_token_standard as token_standard + + -- price info + ,price_amount as amount_original + ,price_amount_raw as amount_raw + ,price_amount_usd as amount_usd + ,token_symbol as currency_symbol + ,token_alternative_symbol as currency_contract + ,token_contract_address as original_currency_contract + ,price_token_decimals as currency_decimals -- in case calculating royalty1~4 + + -- project info (platform or exchange) + ,platform_contract_address as project_contract_address + ,platform_fee_receiver as platform_fee_receive_address + ,platform_fee_amount_raw + ,platform_fee_amount + ,platform_fee_amount_usd + + -- royalty info + ,creator_fee_receiver_1 as royalty_fee_receive_address + ,creator_fee_amount_raw as royalty_fee_amount_raw + ,creator_fee_amount as royalty_fee_amount + ,creator_fee_amount_usd as royalty_fee_amount_usd + ,creator_fee_receiver_1 as royalty_fee_receive_address_1 + ,creator_fee_receiver_2 as royalty_fee_receive_address_2 + ,creator_fee_receiver_3 as royalty_fee_receive_address_3 + ,creator_fee_receiver_4 as royalty_fee_receive_address_4 + ,creator_fee_receiver_5 as royalty_fee_receive_address_5 + ,creator_fee_amount_raw_1 as royalty_fee_amount_raw_1 + ,creator_fee_amount_raw_2 as royalty_fee_amount_raw_2 + ,creator_fee_amount_raw_3 as royalty_fee_amount_raw_3 + ,creator_fee_amount_raw_4 as royalty_fee_amount_raw_4 + ,creator_fee_amount_raw_5 as royalty_fee_amount_raw_5 + + -- aggregator + ,aggregator_name + ,aggregator_address + + -- tx + ,block_number + ,tx_hash + ,evt_index + ,tx_from + ,tx_to + ,right_hash + + -- seaport etc + ,zone as zone_address + ,estimated_price + ,is_private + ,sub_idx + ,sub_type + ,fee_wallet_name + ,token_symbol as royalty_fee_currency_symbol + ,case when price_amount_raw > uint256 '0' then CAST ((platform_fee_amount_raw / price_amount_raw * 100) AS DOUBLE) end platform_fee_percentage + ,case when price_amount_raw > uint256 '0' then CAST((creator_fee_amount_raw/ price_amount_raw * 100) AS DOUBLE) end royalty_fee_percentage + ,'seaport-' || CAST(tx_hash AS varchar) || '-' || cast(evt_index as varchar) || '-' || CAST(nft_contract_address AS varchar) || '-' || cast(nft_token_id as varchar) || '-' || cast(sub_type as varchar) || '-' || cast(sub_idx as varchar) as unique_trade_id + from iv_trades +-- where ( zone in (0xf397619df7bfd4d1657ea9bdd9df7ff888731a11 +-- ,0x9b814233894cd227f561b78cc65891aa55c62ad2 +-- ,0x004c00500000ad104d7dbd00e3ae0a5c00560c00 +-- ,0x110b2b128a9ed1be5ef3232d8e4e41640df5c2cd +-- ,0x000000e7ec00e7b300774b00001314b8610022b8 -- newly added on seaport v1.4 +-- ) +-- or fee_wallet_name = 'opensea' +-- ) +{% endmacro %} diff --git a/models/_sector/nft/trades/old/platforms/_schema.yml b/models/_sector/nft/trades/old/platforms/_schema.yml index da6e607db2c..08c64704bc1 100644 --- a/models/_sector/nft/trades/old/platforms/_schema.yml +++ b/models/_sector/nft/trades/old/platforms/_schema.yml @@ -183,21 +183,6 @@ models: - token_id - sub_type - sub_idx - - check_seed_legacy: - seed_file: ref('nftearth_events_seed') - filter: - blockchain: optimism - project: nftearth - version: v1 - match_columns: - - block_date - - tx_hash - - token_id - - seller - - evt_index - check_columns: - - buyer - - nft_contract_address - name: oneplanet_polygon_events meta: diff --git a/models/_sector/nft/trades/old/platforms/_sources.yml b/models/_sector/nft/trades/old/platforms/_sources.yml index d2b85c1b99e..b86b9ae455d 100644 --- a/models/_sector/nft/trades/old/platforms/_sources.yml +++ b/models/_sector/nft/trades/old/platforms/_sources.yml @@ -26,10 +26,15 @@ sources: - name: nftearth_optimism tables: - name: Seaport_evt_OrderFulfilled + - name: Seaport_call_matchOrders + - name: Seaport_call_matchAdvancedOrders + - name: oneplanet_polygon tables: - name: Seaport_evt_OrderFulfilled + - name: Seaport_call_matchOrders + - name: Seaport_call_matchAdvancedOrders - name: pancakeswap_v2_bnb tables: diff --git a/models/_sector/nft/trades/old/platforms/nftearth_optimism_events.sql b/models/_sector/nft/trades/old/platforms/nftearth_optimism_events.sql index eae2680c9aa..5f2a3c72b8c 100644 --- a/models/_sector/nft/trades/old/platforms/nftearth_optimism_events.sql +++ b/models/_sector/nft/trades/old/platforms/nftearth_optimism_events.sql @@ -1,7 +1,7 @@ {{ config( schema = 'nftearth_optimism', alias = alias('events'), - partition_by = ['block_date'], + tags = ['dunesql'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', @@ -9,382 +9,27 @@ ) }} -{% set c_native_token_address = "0x0000000000000000000000000000000000000000" %} -{% set c_alternative_token_address = "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000" %} -- ETH -{% set c_native_symbol = "ETH" %} -{% set c_seaport_first_date = "2023-01-31" %} -{% set non_buyer_address = "0x2140ea50bc3b6ac3971f9e9ea93a1442665670e4" %} -- nftearth contract address - -with source_optimism_transactions as ( - select * - from {{ source('optimism','transactions') }} - {% if not is_incremental() %} - where block_time >= '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - where block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,ref_nftearth_optimism_base_pairs as ( - select * - from {{ ref('nftearth_optimism_base_pairs') }} - where 1=1 - {% if is_incremental() %} - and block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,ref_tokens_nft as ( - select * - from {{ ref('tokens_nft') }} - where blockchain = 'optimism' -) -,ref_tokens_erc20 as ( - select * - from {{ ref('tokens_erc20') }} - where blockchain = 'optimism' -) -,ref_nft_aggregators as ( - select * - from {{ ref('nft_aggregators') }} - where blockchain = 'optimism' -) -,source_prices_usd as ( - select * - from {{ source('prices', 'usd') }} - where blockchain = 'optimism' - {% if not is_incremental() %} - and minute >= '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - and minute >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,iv_base_pairs_priv as ( - select a.block_date - ,a.block_time - ,a.block_number - ,a.tx_hash - ,a.evt_index - ,a.sub_type - ,a.sub_idx - ,a.offer_first_item_type - ,a.consideration_first_item_type - ,a.sender - ,a.receiver - ,a.zone - ,a.token_contract_address - ,a.original_amount - ,a.item_type - ,a.token_id - ,a.platform_contract_address - ,a.offer_cnt - ,a.consideration_cnt - ,a.is_private - ,a.eth_erc_idx - ,a.nft_cnt - ,a.erc721_cnt - ,a.erc1155_cnt - ,a.order_type - ,a.is_price - ,a.is_netprice - ,a.is_platform_fee - ,a.is_creator_fee - ,a.creator_fee_idx - ,a.is_traded_nft - ,a.is_moved_nft - from ref_nftearth_optimism_base_pairs a - where 1=1 - and not a.is_private - union all - select a.block_date - ,a.block_time - ,a.block_number - ,a.tx_hash - ,a.evt_index - ,a.sub_type - ,a.sub_idx - ,a.offer_first_item_type - ,a.consideration_first_item_type - ,a.sender - ,case when b.tx_hash is not null then b.receiver - else a.receiver - end as receiver - ,a.zone - ,a.token_contract_address - ,a.original_amount - ,a.item_type - ,a.token_id - ,a.platform_contract_address - ,a.offer_cnt - ,a.consideration_cnt - ,a.is_private - ,a.eth_erc_idx - ,a.nft_cnt - ,a.erc721_cnt - ,a.erc1155_cnt - ,a.order_type - ,a.is_price - ,a.is_netprice - ,a.is_platform_fee - ,a.is_creator_fee - ,a.creator_fee_idx - ,a.is_traded_nft - ,a.is_moved_nft - from ref_nftearth_optimism_base_pairs a - left join ref_nftearth_optimism_base_pairs b on b.tx_hash = a.tx_hash - and b.evt_index = a.evt_index - and b.block_date = a.block_date -- for performance - and b.token_contract_address = a.token_contract_address - and b.token_id = a.token_id - and b.original_amount = a.original_amount - and b.is_moved_nft - where 1=1 - and a.is_private - and not a.is_moved_nft - and a.consideration_cnt > 0 -) -,iv_volume as ( - select block_date - ,block_time - ,tx_hash - ,evt_index - ,max(token_contract_address) as token_contract_address - ,sum(case when is_price then original_amount end) as price_amount_raw - ,sum(case when is_platform_fee then original_amount end) as platform_fee_amount_raw - ,max(case when is_platform_fee then receiver end) as platform_fee_receiver - ,sum(case when is_creator_fee then original_amount end) as creator_fee_amount_raw - ,sum(case when is_creator_fee and creator_fee_idx = 1 then original_amount end) as creator_fee_amount_raw_1 - ,sum(case when is_creator_fee and creator_fee_idx = 2 then original_amount end) as creator_fee_amount_raw_2 - ,sum(case when is_creator_fee and creator_fee_idx = 3 then original_amount end) as creator_fee_amount_raw_3 - ,sum(case when is_creator_fee and creator_fee_idx = 4 then original_amount end) as creator_fee_amount_raw_4 - ,max(case when is_creator_fee and creator_fee_idx = 1 then receiver end) as creator_fee_receiver_1 - ,max(case when is_creator_fee and creator_fee_idx = 2 then receiver end) as creator_fee_receiver_2 - ,max(case when is_creator_fee and creator_fee_idx = 3 then receiver end) as creator_fee_receiver_3 - ,max(case when is_creator_fee and creator_fee_idx = 4 then receiver end) as creator_fee_receiver_4 - from iv_base_pairs_priv a - where 1=1 - and eth_erc_idx > 0 - group by 1,2,3,4 -) -,iv_nfts as ( - select a.block_date - ,a.block_time - ,a.tx_hash - ,a.evt_index - ,a.block_number - ,a.sender as seller - ,a.receiver as buyer - ,case when nft_cnt > 1 then 'bundle trade' - else 'single item trade' - end as trade_type - ,a.order_type - ,a.token_contract_address as nft_contract_address - ,a.original_amount as nft_token_amount - ,a.token_id as nft_token_id - ,a.item_type as nft_token_standard - ,a.zone - ,a.platform_contract_address - ,b.token_contract_address - ,round(price_amount_raw / nft_cnt) as price_amount_raw -- to truncate the odd number of decimal places - ,round(platform_fee_amount_raw / nft_cnt) as platform_fee_amount_raw - ,platform_fee_receiver - ,round(creator_fee_amount_raw / nft_cnt) as creator_fee_amount_raw - ,creator_fee_amount_raw_1 / nft_cnt as creator_fee_amount_raw_1 - ,creator_fee_amount_raw_2 / nft_cnt as creator_fee_amount_raw_2 - ,creator_fee_amount_raw_3 / nft_cnt as creator_fee_amount_raw_3 - ,creator_fee_amount_raw_4 / nft_cnt as creator_fee_amount_raw_4 - ,creator_fee_receiver_1 - ,creator_fee_receiver_2 - ,creator_fee_receiver_3 - ,creator_fee_receiver_4 - ,case when nft_cnt > 1 then true - else false - end as estimated_price - ,is_private - ,sub_type - ,sub_idx - from iv_base_pairs_priv a - left join iv_volume b on b.block_date = a.block_date -- tx_hash and evt_index is PK, but for performance, block_time is included - and b.tx_hash = a.tx_hash - and b.evt_index = a.evt_index - where 1=1 - and a.is_traded_nft -) -,iv_trades as ( - select a.* - ,n.name AS nft_token_name - ,t.from as tx_from - ,t.to as tx_to - ,right(t.data,8) as right_hash - ,case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_native_symbol}}' - else e.symbol - end as token_symbol - ,case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_alternative_token_address}}' - else a.token_contract_address - end as token_alternative_symbol - ,e.decimals as price_token_decimals - ,a.price_amount_raw / power(10, e.decimals) as price_amount - ,a.price_amount_raw / power(10, e.decimals) * p.price as price_amount_usd - ,a.platform_fee_amount_raw / power(10, e.decimals) as platform_fee_amount - ,a.platform_fee_amount_raw / power(10, e.decimals) * p.price as platform_fee_amount_usd - ,a.creator_fee_amount_raw / power(10, e.decimals) as creator_fee_amount - ,a.creator_fee_amount_raw / power(10, e.decimals) * p.price as creator_fee_amount_usd - ,agg.name as aggregator_name - ,agg.contract_address AS aggregator_address - ,sub_idx - from iv_nfts a - inner join source_optimism_transactions t on t.hash = a.tx_hash - left join ref_tokens_nft n on n.contract_address = nft_contract_address - left join ref_tokens_erc20 e on e.contract_address = case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_alternative_token_address}}' - else a.token_contract_address - end - left join source_prices_usd p on p.contract_address = case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_alternative_token_address}}' - else a.token_contract_address - end - and p.minute = date_trunc('minute', a.block_time) - left join ref_nft_aggregators agg on agg.contract_address = t.to -) -,erc721_transfer as ( - select - evt_tx_hash - ,evt_block_time - ,evt_block_number - ,tokenId - ,contract_address - ,from - ,to - from {{ source('erc721_optimism','evt_transfer') }} - where - (from = '{{non_buyer_address}}' - or to = '{{non_buyer_address}}') - {% if not is_incremental() %} - and evt_block_time >= '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - and evt_block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,erc1155_transfer as ( - select - evt_tx_hash - ,evt_block_time - ,evt_block_number - ,id as tokenId - ,contract_address - ,from - ,to - from {{ source('erc1155_optimism','evt_transfersingle') }} - where - (from = '{{non_buyer_address}}' - or to = '{{non_buyer_address}}') - {% if not is_incremental() %} - and evt_block_time >= '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - and evt_block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,all_transfers as ( - select * - from erc721_transfer - - union all - - select * - from erc1155_transfer +WITH fee_wallets as ( + select wallet_address, wallet_name from ( + values (0xd55c6b0a208362b18beb178e1785cf91c4ce937a,'nftearth') + ) as foo(wallet_address, wallet_name) +) +, trades as ( + {{ seaport_fork_trades( + blockchain = 'optimism' + ,source_transactions = source('optimism','transactions') + ,Seaport_evt_OrderFulfilled = source('nftearth_optimism','Seaport_evt_OrderFulfilled') + ,Seaport_call_matchAdvancedOrders = source('nftearth_optimism','Seaport_call_matchAdvancedOrders') + ,Seaport_call_matchOrders = source('nftearth_optimism','Seaport_call_matchOrders') + ,fee_wallet_list_cte = 'fee_wallets' + ,native_token_address = '0x0000000000000000000000000000000000000000' + ,alternative_token_address = '0x4200000000000000000000000000000000000006' + ,native_token_symbol = 'ETH' + ,start_date = '2023-01-31' + ,seaport_fork_address = '0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901' + ) + }} ) -,iv_columns as ( - -- Rename column to align other *.trades tables - -- But the columns ordering is according to convenience. - -- initcap the code value if needed - select - -- basic info - 'optimism' as blockchain - ,'nftearth' as project - ,'v1' as version - - -- order info - ,t.block_date - ,t.block_time - ,case when t.seller = '{{non_buyer_address}}' then erc2.from else t.seller end as seller - ,case when t.buyer = '{{non_buyer_address}}' then erc.to else t.buyer end as buyer - ,initcap(t.trade_type) as trade_type - ,initcap(t.order_type) as trade_category -- Buy / Offer Accepted - ,'Trade' as evt_type - - -- nft token info - ,t.nft_contract_address - ,t.nft_token_name as collection - ,t.nft_token_id as token_id - ,cast(t.nft_token_amount as decimal(38, 0)) as number_of_items - ,t.nft_token_standard as token_standard - -- price info - ,t.price_amount as amount_original - ,cast(t.price_amount_raw as decimal(38, 0)) as amount_raw - ,t.price_amount_usd as amount_usd - ,t.token_symbol as currency_symbol - ,t.token_alternative_symbol as currency_contract - ,t.token_contract_address as original_currency_contract - ,t.price_token_decimals as currency_decimals -- in case calculating royalty1~4 - - -- project info (platform or exchange) - ,t.platform_contract_address as project_contract_address - ,t.platform_fee_receiver as platform_fee_receive_address - ,CAST(t.platform_fee_amount_raw as double) as platform_fee_amount_raw - ,t.platform_fee_amount - ,t.platform_fee_amount_usd - ,case when t.price_amount_raw > 0 then CAST ((t.platform_fee_amount_raw / t.price_amount_raw * 100) AS DOUBLE) end platform_fee_percentage - - -- royalty info - ,t.creator_fee_receiver_1 as royalty_fee_receive_address - ,CAST(t.creator_fee_amount_raw as double) as royalty_fee_amount_raw - ,case when t.price_amount_raw > 0 then CAST ((creator_fee_amount_raw / t.price_amount_raw * 100) AS DOUBLE) end royalty_fee_percentage - ,t.token_symbol as royalty_fee_currency_symbol - ,t.creator_fee_amount as royalty_fee_amount - ,t.creator_fee_amount_usd as royalty_fee_amount_usd - ,t.creator_fee_receiver_1 as royalty_fee_receive_address_1 - ,t.creator_fee_receiver_2 as royalty_fee_receive_address_2 - ,t.creator_fee_receiver_3 as royalty_fee_receive_address_3 - ,t.creator_fee_receiver_4 as royalty_fee_receive_address_4 - ,t.creator_fee_amount_raw_1 as royalty_fee_amount_raw_1 - ,t.creator_fee_amount_raw_2 as royalty_fee_amount_raw_2 - ,t.creator_fee_amount_raw_3 as royalty_fee_amount_raw_3 - ,t.creator_fee_amount_raw_4 as royalty_fee_amount_raw_4 - - -- aggregator - ,t.aggregator_name - ,t.aggregator_address - - -- tx - ,t.block_number - ,t.tx_hash - ,t.evt_index - ,t.tx_from - ,t.tx_to - ,t.right_hash - - -- seaport etc - ,t.zone as zone_address - ,t.estimated_price - ,t.is_private - ,t.sub_idx - ,t.sub_type - from iv_trades as t - left join all_transfers as erc - on t.tx_hash = erc.evt_tx_hash - and t.block_number = erc.evt_block_number - and t.nft_token_id = erc.tokenId - and t.nft_contract_address = erc.contract_address - and t.buyer = erc.from - left join all_transfers as erc2 - on t.tx_hash = erc2.evt_tx_hash - and t.block_number = erc2.evt_block_number - and t.nft_token_id = erc2.tokenId - and t.nft_contract_address = erc2.contract_address - and t.seller = erc2.to -) -select - * - ,concat(block_date, tx_hash, evt_index, nft_contract_address, token_id, sub_type, sub_idx) as unique_trade_id -from iv_columns +select * +from trades diff --git a/models/_sector/nft/trades/old/platforms/oneplanet_polygon_events.sql b/models/_sector/nft/trades/old/platforms/oneplanet_polygon_events.sql index ca73357aa63..fb95439f6b6 100644 --- a/models/_sector/nft/trades/old/platforms/oneplanet_polygon_events.sql +++ b/models/_sector/nft/trades/old/platforms/oneplanet_polygon_events.sql @@ -1,294 +1,35 @@ {{ config( schema = 'oneplanet_polygon', alias = alias('events'), + tags = ['dunesql'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', - unique_key = ['tx_hash', 'evt_index', 'token_id'] + unique_key = ['block_date', 'tx_hash', 'evt_index', 'nft_contract_address', 'token_id', 'sub_type', 'sub_idx'] ) }} -{% set c_native_token_address = "0x0000000000000000000000000000000000000000" %} -{% set c_alternative_token_address = "0x0000000000000000000000000000000000001010" %} -- MATIC -{% set c_native_symbol = "MATIC" %} -{% set c_oneplanet_first_date = "2023-09-03" %} - -with source_polygon_transactions as ( - select block_time, block_number, "from", "to", hash, data - from {{ source('polygon','transactions') }} - {% if not is_incremental() %} - where block_time >= date '{{c_oneplanet_first_date}}' - {% endif %} - {% if is_incremental() %} - where block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,ref_oneplanet_polygon_base_pairs as ( - select * - from {{ ref('oneplanet_polygon_base_pairs') }} - where 1=1 - {% if is_incremental() %} - and block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,ref_tokens_nft as ( - select * - from {{ ref('tokens_nft') }} - where blockchain = 'polygon' -) -,ref_tokens_erc20 as ( - select * - from {{ ref('tokens_erc20') }} - where blockchain = 'polygon' -) -,ref_nft_aggregators as ( - select * - from {{ ref('nft_aggregators') }} - where blockchain = 'polygon' -) -,source_prices_usd as ( - select * - from {{ source('prices', 'usd') }} - where blockchain = 'polygon' - {% if not is_incremental() %} - and minute >= date '{{c_oneplanet_first_date}}' - {% endif %} - {% if is_incremental() %} - and minute >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,iv_base_pairs_priv as ( - select a.block_date - ,a.block_time - ,a.block_number - ,a.tx_hash - ,a.evt_index - ,a.sub_type - ,a.sub_idx - ,a.offer_first_item_type - ,a.consideration_first_item_type - ,a.sender - ,a.receiver - ,a.zone - ,a.token_contract_address - ,a.original_amount - ,a.item_type - ,a.token_id - ,a.platform_contract_address - ,a.offer_cnt - ,a.consideration_cnt - ,a.is_private - ,a.eth_erc_idx - ,a.nft_cnt - ,a.erc721_cnt - ,a.erc1155_cnt - ,a.order_type - ,a.is_price - ,a.is_netprice - ,a.is_platform_fee - ,a.is_creator_fee - ,a.creator_fee_idx - ,a.is_traded_nft - ,a.is_moved_nft - from ref_oneplanet_polygon_base_pairs a - where 1=1 - and not a.is_private - union all - select distinct - a.block_date - ,a.block_time - ,a.block_number - ,a.tx_hash - ,a.evt_index - ,a.sub_type - ,coalesce(b.sub_idx, a.sub_idx) as sub_idx - ,a.offer_first_item_type - ,a.consideration_first_item_type - ,a.sender - ,case when b.tx_hash is not null then b.receiver - else a.receiver - end as receiver - ,a.zone - ,a.token_contract_address - ,a.original_amount - ,a.item_type - ,a.token_id - ,a.platform_contract_address - ,a.offer_cnt - ,a.consideration_cnt - ,a.is_private - ,a.eth_erc_idx - ,a.nft_cnt - ,a.erc721_cnt - ,a.erc1155_cnt - ,a.order_type - ,a.is_price - ,a.is_netprice - ,a.is_platform_fee - ,a.is_creator_fee - ,a.creator_fee_idx - ,a.is_traded_nft - ,a.is_moved_nft - from ref_oneplanet_polygon_base_pairs a - left join ref_oneplanet_polygon_base_pairs b on b.tx_hash = a.tx_hash - and b.evt_index = a.evt_index - and b.block_date = a.block_date - and b.token_contract_address = a.token_contract_address - and b.token_id = a.token_id - and b.original_amount = a.original_amount - and b.is_moved_nft - where 1=1 - and a.is_private - and not a.is_moved_nft - and a.consideration_cnt > 0 -) -,iv_volume as ( - select block_date - ,block_time - ,tx_hash - ,evt_index - ,max(token_contract_address) as token_contract_address - ,sum(case when is_price then original_amount end) as price_amount_raw - ,sum(case when is_platform_fee then original_amount end) as platform_fee_amount_raw - ,max(case when is_platform_fee then receiver end) as platform_fee_receiver - ,sum(case when is_creator_fee then original_amount end) as creator_fee_amount_raw - ,sum(case when is_creator_fee and creator_fee_idx = 1 then original_amount end) as creator_fee_amount_raw_1 - ,sum(case when is_creator_fee and creator_fee_idx = 2 then original_amount end) as creator_fee_amount_raw_2 - ,sum(case when is_creator_fee and creator_fee_idx = 3 then original_amount end) as creator_fee_amount_raw_3 - ,sum(case when is_creator_fee and creator_fee_idx = 4 then original_amount end) as creator_fee_amount_raw_4 - ,max(case when is_creator_fee and creator_fee_idx = 1 then receiver end) as creator_fee_receiver_1 - ,max(case when is_creator_fee and creator_fee_idx = 2 then receiver end) as creator_fee_receiver_2 - ,max(case when is_creator_fee and creator_fee_idx = 3 then receiver end) as creator_fee_receiver_3 - ,max(case when is_creator_fee and creator_fee_idx = 4 then receiver end) as creator_fee_receiver_4 - from iv_base_pairs_priv a - where 1=1 - and eth_erc_idx > 0 - group by 1,2,3,4 -) -,iv_nfts as ( - select a.block_date - ,a.block_time - ,a.tx_hash - ,a.evt_index - ,a.block_number - ,a.sender as seller - ,a.receiver as buyer - ,case when nft_cnt > 1 then 'bundle trade' - else 'single item trade' - end as trade_type - ,a.order_type - ,a.token_contract_address as nft_contract_address - ,a.original_amount as nft_token_amount - ,a.token_id as nft_token_id - ,a.item_type as nft_token_standard - ,a.zone - ,a.platform_contract_address - ,b.token_contract_address - ,price_amount_raw - ,platform_fee_amount_raw - ,platform_fee_receiver - ,creator_fee_amount_raw - ,creator_fee_amount_raw_1 - ,creator_fee_amount_raw_2 - ,creator_fee_amount_raw_3 - ,creator_fee_amount_raw_4 - ,creator_fee_receiver_1 - ,creator_fee_receiver_2 - ,creator_fee_receiver_3 - ,creator_fee_receiver_4 - ,case when nft_cnt > 1 then true - else false - end as estimated_price - ,is_private - ,sub_type - ,sub_idx - from iv_base_pairs_priv a - left join iv_volume b on b.block_date = a.block_date - and b.tx_hash = a.tx_hash - and b.evt_index = a.evt_index - where 1=1 - and a.is_traded_nft -) -,iv_trades as ( - select a.* - ,n.name AS nft_token_name - ,t.from as tx_from - ,t.to as tx_to - ,right(t.data,8) as right_hash - ,case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_native_symbol}}' - else e.symbol - end as token_symbol - ,case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_alternative_token_address}}' - else a.token_contract_address - end as token_alternative_symbol - ,e.decimals as price_token_decimals - ,a.price_amount_raw / power(10, e.decimals) as price_amount - ,a.price_amount_raw / power(10, e.decimals) * p.price as price_amount_usd - ,a.platform_fee_amount_raw / power(10, e.decimals) as platform_fee_amount - ,a.platform_fee_amount_raw / power(10, e.decimals) * p.price as platform_fee_amount_usd - ,cast(coalesce(a.platform_fee_amount_raw, 0) / a.price_amount_raw as double) as platform_fee_percentage - ,a.creator_fee_amount_raw as royalty_fee_amount_raw - ,a.creator_fee_amount_raw / power(10, e.decimals) as royalty_fee_amount - ,a.creator_fee_amount_raw / power(10, e.decimals) * p.price as royalty_fee_amount_usd - ,cast(coalesce(a.creator_fee_amount_raw, 0) / a.price_amount_raw as double) as royalty_fee_percentage - ,creator_fee_receiver_1 as royalty_fee_receive_address - ,agg.name as aggregator_name - ,agg.contract_address AS aggregator_address - ,sub_idx - from iv_nfts a - inner join source_polygon_transactions t on t.hash = a.tx_hash - left join ref_tokens_nft n on n.contract_address = nft_contract_address - left join ref_tokens_erc20 e on e.contract_address = case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_alternative_token_address}}' - else a.token_contract_address - end - left join source_prices_usd p on p.contract_address = case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_alternative_token_address}}' - else a.token_contract_address - end - and p.minute = date_trunc('minute', a.block_time) - left join ref_nft_aggregators agg on agg.contract_address = t.to -) -,iv_columns as ( - select - 'polygon' as blockchain - ,'oneplanet' as project - ,'v1' as version - ,block_time - ,nft_token_id as token_id - ,nft_token_name as collection - ,cast(price_amount_usd as double) as amount_usd - ,nft_token_standard as token_standard - ,initcap(trade_type) as trade_type - ,cast(nft_token_amount as decimal(38,0)) as number_of_items - ,initcap(order_type) as trade_category - ,'Trade' as evt_type - ,seller - ,buyer - ,cast(price_amount as double) as amount_original - ,cast(price_amount_raw as decimal(38,0)) as amount_raw - ,token_symbol as currency_symbol - ,token_alternative_symbol as currency_contract - ,nft_contract_address - ,platform_contract_address as project_contract_address - ,aggregator_name - ,aggregator_address - ,block_number - ,tx_hash - ,tx_from - ,tx_to - ,evt_index - ,cast(platform_fee_amount_raw as double) as platform_fee_amount_raw - ,cast(platform_fee_amount as double) as platform_fee_amount - ,cast(platform_fee_amount_usd as double) as platform_fee_amount_usd - ,cast(platform_fee_percentage as double) as platform_fee_percentage - ,cast(royalty_fee_amount_raw as double) as royalty_fee_amount_raw - ,cast(royalty_fee_amount as double) as royalty_fee_amount - ,cast(royalty_fee_amount_usd as double) as royalty_fee_amount_usd - ,cast(royalty_fee_percentage as double) as royalty_fee_percentage - ,royalty_fee_receive_address - ,token_symbol as royalty_fee_currency_symbol - ,'OnePlanet-' || tx_hash || '-' || cast(evt_index as VARCHAR(10)) || '-' || nft_contract_address || '-' || cast(nft_token_id as VARCHAR(10)) || '-' || cast(sub_idx as VARCHAR(10)) as unique_trade_id - from iv_trades +WITH fee_wallets as ( + select wallet_address, wallet_name from ( + values (0xf7eB758c21a6d0f9029Da4655B9F24343c3924dB,'oneplanet') + ) as foo(wallet_address, wallet_name) +) +, trades as ( + {{ seaport_fork_trades( + blockchain = 'polygon' + ,source_transactions = source('polygon','transactions') + ,Seaport_evt_OrderFulfilled = source('oneplanet_polygon','Seaport_evt_OrderFulfilled') + ,Seaport_call_matchAdvancedOrders = source('oneplanet_polygon','Seaport_call_matchAdvancedOrders') + ,Seaport_call_matchOrders = source('oneplanet_polygon','Seaport_call_matchOrders') + ,fee_wallet_list_cte = 'fee_wallets' + ,native_token_address = '0x0000000000000000000000000000000000000000' + ,alternative_token_address = '0x0000000000000000000000000000000000001010' + ,native_token_symbol = 'MATIC' + ,start_date = '2023-09-03' + ,seaport_fork_address = '0xcbbecf690e030d096794f7685a1bf4a58378a575' + ) + }} ) + select * -from iv_columns -; +from trades diff --git a/models/_sector/nft/trades/old/platforms/quix_seaport_optimism_events.sql b/models/_sector/nft/trades/old/platforms/quix_seaport_optimism_events.sql index e38b0845e2a..73b7b852393 100644 --- a/models/_sector/nft/trades/old/platforms/quix_seaport_optimism_events.sql +++ b/models/_sector/nft/trades/old/platforms/quix_seaport_optimism_events.sql @@ -1,7 +1,7 @@ {{ config( schema = 'quix_seaport_optimism', - alias = alias('seaport_events'), - partition_by = ['block_date'], + alias = alias('events'), + tags = ['dunesql'], materialized = 'incremental', file_format = 'delta', incremental_strategy = 'merge', @@ -9,339 +9,27 @@ ) }} -{% set c_native_token_address = "0x0000000000000000000000000000000000000000" %} -{% set c_alternative_token_address = "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000" %} -- ETH -{% set c_native_symbol = "ETH" %} -{% set c_seaport_first_date = "2022-07-29" %} -{% set non_buyer_address = "0xc78a09d6a4badecc7614a339fd264b7290361ef1" %} -- quix contract address - -with source_optimism_transactions as ( - select * - from {{ source('optimism','transactions') }} - {% if not is_incremental() %} - where block_time >= '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - where block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,ref_quix_seaport_optimism_base_pairs as ( - select * - from {{ ref('quix_seaport_optimism_base_pairs') }} - where 1=1 - {% if is_incremental() %} - and block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,ref_tokens_nft as ( - select * - from {{ ref('tokens_nft') }} - where blockchain = 'optimism' -) -,ref_tokens_erc20 as ( - select * - from {{ ref('tokens_erc20') }} - where blockchain = 'optimism' -) -,ref_nft_aggregators as ( - select * - from {{ ref('nft_aggregators') }} - where blockchain = 'optimism' -) -,source_prices_usd as ( - select * - from {{ source('prices', 'usd') }} - where blockchain = 'optimism' - {% if not is_incremental() %} - and minute >= '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - and minute >= date_trunc("day", now() - interval '1 week') - {% endif %} -) -,iv_base_pairs_priv as ( - select a.block_date - ,a.block_time - ,a.block_number - ,a.tx_hash - ,a.evt_index - ,a.sub_type - ,a.sub_idx - ,a.offer_first_item_type - ,a.consideration_first_item_type - ,a.sender - ,a.receiver - ,a.zone - ,a.token_contract_address - ,a.original_amount - ,a.item_type - ,a.token_id - ,a.platform_contract_address - ,a.offer_cnt - ,a.consideration_cnt - ,a.is_private - ,a.eth_erc_idx - ,a.nft_cnt - ,a.erc721_cnt - ,a.erc1155_cnt - ,a.order_type - ,a.is_price - ,a.is_netprice - ,a.is_platform_fee - ,a.is_creator_fee - ,a.creator_fee_idx - ,a.is_traded_nft - ,a.is_moved_nft - from ref_quix_seaport_optimism_base_pairs a - where 1=1 - and not a.is_private - union all - select a.block_date - ,a.block_time - ,a.block_number - ,a.tx_hash - ,a.evt_index - ,a.sub_type - ,a.sub_idx - ,a.offer_first_item_type - ,a.consideration_first_item_type - ,a.sender - ,case when b.tx_hash is not null then b.receiver - else a.receiver - end as receiver - ,a.zone - ,a.token_contract_address - ,a.original_amount - ,a.item_type - ,a.token_id - ,a.platform_contract_address - ,a.offer_cnt - ,a.consideration_cnt - ,a.is_private - ,a.eth_erc_idx - ,a.nft_cnt - ,a.erc721_cnt - ,a.erc1155_cnt - ,a.order_type - ,a.is_price - ,a.is_netprice - ,a.is_platform_fee - ,a.is_creator_fee - ,a.creator_fee_idx - ,a.is_traded_nft - ,a.is_moved_nft - from ref_quix_seaport_optimism_base_pairs a - left join ref_quix_seaport_optimism_base_pairs b on b.tx_hash = a.tx_hash - and b.evt_index = a.evt_index - and b.block_date = a.block_date -- for performance - and b.token_contract_address = a.token_contract_address - and b.token_id = a.token_id - and b.original_amount = a.original_amount - and b.is_moved_nft - where 1=1 - and a.is_private - and not a.is_moved_nft - and a.consideration_cnt > 0 -) -,iv_volume as ( - select block_date - ,block_time - ,tx_hash - ,evt_index - ,max(token_contract_address) as token_contract_address - ,sum(case when is_price then original_amount end) as price_amount_raw - ,sum(case when is_platform_fee then original_amount end) as platform_fee_amount_raw - ,max(case when is_platform_fee then receiver end) as platform_fee_receiver - ,sum(case when is_creator_fee then original_amount end) as creator_fee_amount_raw - ,sum(case when is_creator_fee and creator_fee_idx = 1 then original_amount end) as creator_fee_amount_raw_1 - ,sum(case when is_creator_fee and creator_fee_idx = 2 then original_amount end) as creator_fee_amount_raw_2 - ,sum(case when is_creator_fee and creator_fee_idx = 3 then original_amount end) as creator_fee_amount_raw_3 - ,sum(case when is_creator_fee and creator_fee_idx = 4 then original_amount end) as creator_fee_amount_raw_4 - ,max(case when is_creator_fee and creator_fee_idx = 1 then receiver end) as creator_fee_receiver_1 - ,max(case when is_creator_fee and creator_fee_idx = 2 then receiver end) as creator_fee_receiver_2 - ,max(case when is_creator_fee and creator_fee_idx = 3 then receiver end) as creator_fee_receiver_3 - ,max(case when is_creator_fee and creator_fee_idx = 4 then receiver end) as creator_fee_receiver_4 - from iv_base_pairs_priv a - where 1=1 - and eth_erc_idx > 0 - group by 1,2,3,4 -) -,iv_nfts as ( - select a.block_date - ,a.block_time - ,a.tx_hash - ,a.evt_index - ,a.block_number - ,a.sender as seller - ,a.receiver as buyer - ,case when nft_cnt > 1 then 'bundle trade' - else 'single item trade' - end as trade_type - ,a.order_type - ,a.token_contract_address as nft_contract_address - ,a.original_amount as nft_token_amount - ,a.token_id as nft_token_id - ,a.item_type as nft_token_standard - ,a.zone - ,a.platform_contract_address - ,b.token_contract_address - ,round(price_amount_raw / nft_cnt) as price_amount_raw -- to truncate the odd number of decimal places - ,round(platform_fee_amount_raw / nft_cnt) as platform_fee_amount_raw - ,platform_fee_receiver - ,round(creator_fee_amount_raw / nft_cnt) as creator_fee_amount_raw - ,creator_fee_amount_raw_1 / nft_cnt as creator_fee_amount_raw_1 - ,creator_fee_amount_raw_2 / nft_cnt as creator_fee_amount_raw_2 - ,creator_fee_amount_raw_3 / nft_cnt as creator_fee_amount_raw_3 - ,creator_fee_amount_raw_4 / nft_cnt as creator_fee_amount_raw_4 - ,creator_fee_receiver_1 - ,creator_fee_receiver_2 - ,creator_fee_receiver_3 - ,creator_fee_receiver_4 - ,case when nft_cnt > 1 then true - else false - end as estimated_price - ,is_private - ,sub_type - ,sub_idx - from iv_base_pairs_priv a - left join iv_volume b on b.block_date = a.block_date -- tx_hash and evt_index is PK, but for performance, block_time is included - and b.tx_hash = a.tx_hash - and b.evt_index = a.evt_index - where 1=1 - and a.is_traded_nft -) -,iv_trades as ( - select a.* - ,n.name AS nft_token_name - ,t.from as tx_from - ,t.to as tx_to - ,right(t.data,8) as right_hash - ,case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_native_symbol}}' - else e.symbol - end as token_symbol - ,case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_alternative_token_address}}' - else a.token_contract_address - end as token_alternative_symbol - ,e.decimals as price_token_decimals - ,a.price_amount_raw / power(10, e.decimals) as price_amount - ,a.price_amount_raw / power(10, e.decimals) * p.price as price_amount_usd - ,a.platform_fee_amount_raw / power(10, e.decimals) as platform_fee_amount - ,a.platform_fee_amount_raw / power(10, e.decimals) * p.price as platform_fee_amount_usd - ,a.creator_fee_amount_raw / power(10, e.decimals) as creator_fee_amount - ,a.creator_fee_amount_raw / power(10, e.decimals) * p.price as creator_fee_amount_usd - ,agg.name as aggregator_name - ,agg.contract_address AS aggregator_address - ,sub_idx - from iv_nfts a - inner join source_optimism_transactions t on t.hash = a.tx_hash - left join ref_tokens_nft n on n.contract_address = nft_contract_address - left join ref_tokens_erc20 e on e.contract_address = case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_alternative_token_address}}' - else a.token_contract_address - end - left join source_prices_usd p on p.contract_address = case when a.token_contract_address = '{{c_native_token_address}}' then '{{c_alternative_token_address}}' - else a.token_contract_address - end - and p.minute = date_trunc('minute', a.block_time) - left join ref_nft_aggregators agg on agg.contract_address = t.to -) -,erc721_transfer as ( - select * - from {{ source('erc721_optimism','evt_transfer') }} - where - from = '{{non_buyer_address}}' - {% if not is_incremental() %} - and evt_block_time >= '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - and evt_block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} +WITH fee_wallets as ( + select wallet_address, wallet_name from ( + values (0xeC1557A67d4980C948cD473075293204F4D280fd,'quix') + ) as foo(wallet_address, wallet_name) +) +, trades as ( + {{ seaport_fork_trades( + blockchain = 'optimism' + ,source_transactions = source('optimism','transactions') + ,Seaport_evt_OrderFulfilled = source('quixotic_optimism','Seaport_evt_OrderFulfilled') + ,Seaport_call_matchAdvancedOrders = source('quixotic_optimism','Seaport_call_matchAdvancedOrders') + ,Seaport_call_matchOrders = source('quixotic_optimism','Seaport_call_matchOrders') + ,fee_wallet_list_cte = 'fee_wallets' + ,native_token_address = '0x0000000000000000000000000000000000000000' + ,alternative_token_address = '0x4200000000000000000000000000000000000006' + ,native_token_symbol = 'ETH' + ,start_date = '2022-07-29' + ,seaport_fork_address = '0x998ef16ea4111094eb5ee72fc2c6f4e6e8647666' + ) + }} ) -,iv_columns as ( - -- Rename column to align other *.trades tables - -- But the columns ordering is according to convenience. - -- initcap the code value if needed - select - -- basic info - 'optimism' as blockchain - ,'quix' as project - ,'seaport' as version - - -- order info - ,t.block_date - ,t.block_time - ,t.seller - ,case when t.buyer = '{{non_buyer_address}}' then erc.to else t.buyer end as buyer - ,initcap(t.trade_type) as trade_type - ,initcap(t.order_type) as trade_category -- Buy / Offer Accepted - ,'Trade' as evt_type - - -- nft token info - ,t.nft_contract_address - ,t.nft_token_name as collection - ,t.nft_token_id as token_id - ,cast(t.nft_token_amount as decimal(38, 0)) as number_of_items - ,t.nft_token_standard as token_standard - - -- price info - ,t.price_amount as amount_original - ,cast(t.price_amount_raw as decimal(38, 0)) as amount_raw - ,t.price_amount_usd as amount_usd - ,t.token_symbol as currency_symbol - ,t.token_alternative_symbol as currency_contract - ,t.token_contract_address as original_currency_contract - ,t.price_token_decimals as currency_decimals -- in case calculating royalty1~4 - -- project info (platform or exchange) - ,t.platform_contract_address as project_contract_address - ,t.platform_fee_receiver as platform_fee_receive_address - ,CAST(t.platform_fee_amount_raw as double) as platform_fee_amount_raw - ,t.platform_fee_amount - ,t.platform_fee_amount_usd - ,case when t.price_amount_raw > 0 then CAST ((t.platform_fee_amount_raw / t.price_amount_raw * 100) AS DOUBLE) end platform_fee_percentage - - -- royalty info - ,t.creator_fee_receiver_1 as royalty_fee_receive_address - ,CAST(t.creator_fee_amount_raw as double) as royalty_fee_amount_raw - ,case when t.price_amount_raw > 0 then CAST ((creator_fee_amount_raw / t.price_amount_raw * 100) AS DOUBLE) end royalty_fee_percentage - ,t.token_symbol as royalty_fee_currency_symbol - ,t.creator_fee_amount as royalty_fee_amount - ,t.creator_fee_amount_usd as royalty_fee_amount_usd - ,t.creator_fee_receiver_1 as royalty_fee_receive_address_1 - ,t.creator_fee_receiver_2 as royalty_fee_receive_address_2 - ,t.creator_fee_receiver_3 as royalty_fee_receive_address_3 - ,t.creator_fee_receiver_4 as royalty_fee_receive_address_4 - ,t.creator_fee_amount_raw_1 as royalty_fee_amount_raw_1 - ,t.creator_fee_amount_raw_2 as royalty_fee_amount_raw_2 - ,t.creator_fee_amount_raw_3 as royalty_fee_amount_raw_3 - ,t.creator_fee_amount_raw_4 as royalty_fee_amount_raw_4 - - -- aggregator - ,t.aggregator_name - ,t.aggregator_address - - -- tx - ,t.block_number - ,t.tx_hash - ,t.evt_index - ,t.tx_from - ,t.tx_to - ,t.right_hash - - -- seaport etc - ,t.zone as zone_address - ,t.estimated_price - ,t.is_private - ,t.sub_idx - ,t.sub_type - from iv_trades as t - left join erc721_transfer as erc - on t.tx_hash = erc.evt_tx_hash - and t.block_number = erc.evt_block_number - and t.nft_token_id = erc.tokenId - and t.nft_contract_address = erc.contract_address - and t.buyer = erc.from -) -select - * - ,concat(block_date, tx_hash, evt_index, nft_contract_address, token_id, sub_type, sub_idx) as unique_trade_id -from iv_columns +select * +from trades diff --git a/models/nftearth/optimism/nftearth_optimism_base_pairs.sql b/models/nftearth/optimism/nftearth_optimism_base_pairs.sql deleted file mode 100644 index 0f5e145f0d4..00000000000 --- a/models/nftearth/optimism/nftearth_optimism_base_pairs.sql +++ /dev/null @@ -1,224 +0,0 @@ -{{ config( - alias = alias('base_pairs'), - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['block_date', 'tx_hash', 'evt_index', 'sub_type', 'sub_idx'], - post_hook='{{ expose_spells(\'["optimism"]\', - "project", - "nftearth", - \'["chuxin"]\') }}' - ) -}} - -{% set c_seaport_first_date = "2023-01-31" %} -{% set weth_address = "0x4200000000000000000000000000000000000006" %} - -with iv_offer_consideration_raw as ( - select evt_block_time as block_time - ,evt_block_number as block_number - ,evt_tx_hash as tx_hash - ,evt_index - ,'offer' as sub_type - ,offer_idx + 1 as sub_idx - ,case offer[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as offer_first_item_type - ,case consideration[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as consideration_first_item_type - ,offerer as sender - ,recipient as receiver - ,zone - ,offer_item:token as token_contract_address - ,cast(offer_item:amount as numeric(38)) as original_amount - ,case offer_item:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as item_type - ,offer_item:identifier as token_id - ,contract_address as platform_contract_address - ,size(offer) as offer_cnt - ,size(consideration) as consideration_cnt - ,case when recipient = '0x0000000000000000000000000000000000000000' then true - else false - end as is_private - from - ( - select consideration - , contract_address - , evt_block_number - , evt_block_time - , evt_index - , evt_tx_hash - , offer - , offerer - -- , orderHash - , recipient - , zone - , posexplode(offer) as (offer_idx, offer_item) - from {{ source('nftearth_optimism', 'Seaport_evt_OrderFulfilled') }} - {% if not is_incremental() %} - where evt_block_time >= date '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - where evt_block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} - ) - union all - select evt_block_time as block_time - ,evt_block_number as block_number - ,evt_tx_hash as tx_hash - ,evt_index - ,'consideration' as sub_type - ,consideration_idx + 1 as sub_idx - ,case offer[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as offer_first_item_type - ,case consideration[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as consideration_first_item_type - ,recipient as sender - ,consideration_item:recipient as receiver - ,zone - ,consideration_item:token as token_contract_address - ,cast(consideration_item:amount as numeric(38)) as original_amount - ,case consideration_item:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' -- actually not exists - end as item_type - ,consideration_item:identifier as token_id - ,contract_address as platform_contract_address - ,size(offer) as offer_cnt - ,size(consideration) as consideration_cnt - ,case when recipient = '0x0000000000000000000000000000000000000000' then true - else false - end as is_private - from - ( - select consideration - , contract_address - , evt_block_number - , evt_block_time - , evt_index - , evt_tx_hash - , offer - , recipient - , zone - ,posexplode(consideration) as (consideration_idx, consideration_item) - from {{ source('nftearth_optimism','Seaport_evt_OrderFulfilled') }} - {% if not is_incremental() %} - where evt_block_time >= date '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - where evt_block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} - ) -) -,iv_offer_consideration as ( - select a.* - ,case when item_type in ('native','erc20') then sum(1) over (partition by tx_hash, evt_index, sub_type order by sub_idx) end as eth_erc_idx - ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721','erc1155') then 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721','erc1155') then 1 - end) over (partition by tx_hash, evt_index) as nft_cnt - ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721') then 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721') then 1 - end) over (partition by tx_hash, evt_index) as erc721_cnt - ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc1155') then 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc1155') then 1 - end) over (partition by tx_hash, evt_index) as erc1155_cnt - from iv_offer_consideration_raw a -) -,adjustment as ( - select - tx_hash - ,max(eth_erc_idx) as max_eth_erc_idx - from iv_offer_consideration - group by 1 -) -,iv_base_pairs as ( - select a.* - ,try_cast(date_trunc('day', a.block_time) as date) as block_date - ,case when offer_first_item_type = 'erc20' then 'offer accepted' - when offer_first_item_type in ('erc721','erc1155') then 'buy' - else 'etc' -- some txns has no nfts - end as order_type - ,case when offer_first_item_type = 'erc20' and sub_type = 'offer' and item_type = 'erc20' then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and item_type in ('native','erc20') then true - else false - end is_price - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx = 0 then true -- offer accepted has no price at all. it has to be calculated. - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx = 1 then true - else false - end is_netprice - ,case - when offer_first_item_type = 'erc20' and sub_type = 'consideration' - and token_contract_address != '{{weth_address}}' and eth_erc_idx = 1 then true - when offer_first_item_type = 'erc20' and sub_type = 'consideration' - and aj.max_eth_erc_idx >=3 - and token_contract_address = '{{weth_address}}' and eth_erc_idx > 2 then true - when offer_first_item_type = 'erc20' and sub_type = 'consideration' - and aj.max_eth_erc_idx < 3 - and token_contract_address = '{{weth_address}}' and eth_erc_idx = 2 then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' - and aj.max_eth_erc_idx >=3 and eth_erc_idx > 2 then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' - and aj.max_eth_erc_idx < 3 and eth_erc_idx = 2 then true - else false - end is_platform_fee - ,case - when offer_first_item_type = 'erc20' and sub_type = 'consideration' - and token_contract_address != '{{weth_address}}' and eth_erc_idx > 1 then true - when offer_first_item_type = 'erc20' and sub_type = 'consideration' - and aj.max_eth_erc_idx >=3 - and token_contract_address = '{{weth_address}}' and eth_erc_idx = 2 then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' - and aj.max_eth_erc_idx >=3 and eth_erc_idx = 2 then true - else false - end is_creator_fee - ,case - when offer_first_item_type = 'erc20' and sub_type = 'consideration' - and token_contract_address != '{{weth_address}}' and eth_erc_idx > 1 then eth_erc_idx - 1 - when offer_first_item_type = 'erc20' and sub_type = 'consideration' - and aj.max_eth_erc_idx >=3 - and token_contract_address = '{{weth_address}}' and eth_erc_idx = 2 then eth_erc_idx - 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' - and aj.max_eth_erc_idx >=3 and eth_erc_idx = 2 then eth_erc_idx - 1 - end creator_fee_idx - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721','erc1155') then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721','erc1155') then true - else false - end is_traded_nft - ,case when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and item_type in ('erc721','erc1155') then true - else false - end is_moved_nft - from iv_offer_consideration as a - left join adjustment as aj - on a.tx_hash = aj.tx_hash -) -select * -from iv_base_pairs -; diff --git a/models/nftearth/optimism/nftearth_optimism_schema.yml b/models/nftearth/optimism/nftearth_optimism_schema.yml index b6230e9e787..fdaff2c5936 100644 --- a/models/nftearth/optimism/nftearth_optimism_schema.yml +++ b/models/nftearth/optimism/nftearth_optimism_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: nftearth_optimism_base_pairs + - name: nftearth_optimism_base_pairs_legacy meta: blockchain: optimism project: nftearth diff --git a/models/oneplanet/polygon/oneplanet_polygon_base_pairs.sql b/models/oneplanet/polygon/oneplanet_polygon_base_pairs.sql deleted file mode 100644 index 45ee913ae31..00000000000 --- a/models/oneplanet/polygon/oneplanet_polygon_base_pairs.sql +++ /dev/null @@ -1,193 +0,0 @@ -{{ config( - alias = alias('base_pairs'), - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['block_date', 'tx_hash', 'evt_index', 'sub_type', 'sub_idx'], - post_hook='{{ expose_spells(\'["polygon"]\', - "project", - "oneplanet", - \'["springzh"]\') }}' - ) -}} - -{% set c_oneplanet_first_date = "2023-09-03" %} - -with iv_offer_consideration as ( - select evt_block_time as block_time - ,evt_block_number as block_number - ,evt_tx_hash as tx_hash - ,evt_index - ,'offer' as sub_type - ,offer_idx + 1 as sub_idx - ,case offer[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as offer_first_item_type - ,case consideration[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as consideration_first_item_type - ,offerer as sender - ,recipient as receiver - ,zone - ,offer_item:token as token_contract_address - ,cast(offer_item:amount as numeric(38)) as original_amount - ,case offer_item:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as item_type - ,offer_item:identifier as token_id - ,contract_address as platform_contract_address - ,size(offer) as offer_cnt - ,size(consideration) as consideration_cnt - ,case when recipient = '0x0000000000000000000000000000000000000000' then true - else false - end as is_private - from - ( - select consideration - , contract_address - , evt_block_number - , evt_block_time - , evt_index - , evt_tx_hash - , offer - , offerer - -- , orderHash - , recipient - , zone - , posexplode(offer) as (offer_idx, offer_item) - from {{ source('oneplanet_polygon', 'Seaport_evt_OrderFulfilled') }} - {% if not is_incremental() %} - where evt_block_time >= date '{{c_oneplanet_first_date}}' -- oneplanet first txn - {% endif %} - {% if is_incremental() %} - where evt_block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} - ) - union all - select evt_block_time as block_time - ,evt_block_number as block_number - ,evt_tx_hash as tx_hash - ,evt_index - ,'consideration' as sub_type - ,consideration_idx + 1 as sub_idx - ,case offer[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as offer_first_item_type - ,case consideration[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as consideration_first_item_type - ,recipient as sender - ,consideration_item:recipient as receiver - ,zone - ,consideration_item:token as token_contract_address - ,cast(consideration_item:amount as numeric(38)) as original_amount - ,case consideration_item:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' -- actually not exists - end as item_type - ,consideration_item:identifier as token_id - ,contract_address as platform_contract_address - ,size(offer) as offer_cnt - ,size(consideration) as consideration_cnt - ,case when recipient = '0x0000000000000000000000000000000000000000' then true - else false - end as is_private - from - ( - select consideration - , contract_address - , evt_block_number - , evt_block_time - , evt_index - , evt_tx_hash - , offer - -- , offerer - -- , orderHash - , recipient - , zone - ,posexplode(consideration) as (consideration_idx, consideration_item) - from {{ source('oneplanet_polygon','Seaport_evt_OrderFulfilled') }} - {% if not is_incremental() %} - where evt_block_time >= date '{{c_oneplanet_first_date}}' -- oneplanet first txn - {% endif %} - {% if is_incremental() %} - where evt_block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} - ) -) -,iv_base_pairs as ( - select a.* - ,try_cast(date_trunc('day', a.block_time) as date) as block_date - ,case when offer_first_item_type = 'erc20' then 'offer accepted' - when offer_first_item_type in ('erc721','erc1155') then 'buy' - else 'etc' -- some txns has no nfts - end as order_type - ,case when offer_first_item_type = 'erc20' and sub_type = 'offer' and item_type = 'erc20' then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and item_type in ('native','erc20') then true - else false - end is_price - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx = 0 then true -- offer accepted has no price at all. it has to be calculated. - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx = 1 then true - else false - end is_netprice - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx = 1 then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx = 2 then true - else false - end is_platform_fee - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx > 1 then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx > 2 then true - else false - end is_creator_fee - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx > 1 then eth_erc_idx - 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx > 2 then eth_erc_idx - 2 - end creator_fee_idx - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721','erc1155') then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721','erc1155') then true - else false - end is_traded_nft - ,case when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and item_type in ('erc721','erc1155') then true - else false - end is_moved_nft - from - ( - select a.* - ,case when item_type in ('native','erc20') then sum(case when item_type in ('native','erc20') then 1 end) over (partition by tx_hash, evt_index, sub_type order by sub_idx) end as eth_erc_idx - ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721','erc1155') then 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721','erc1155') then 1 - end) over (partition by tx_hash, evt_index) as nft_cnt - ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721') then 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721') then 1 - end) over (partition by tx_hash, evt_index) as erc721_cnt - ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc1155') then 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc1155') then 1 - end) over (partition by tx_hash, evt_index) as erc1155_cnt - from iv_offer_consideration a - ) a -) -select * -from iv_base_pairs -; \ No newline at end of file diff --git a/models/oneplanet/polygon/oneplanet_polygon_schema.yml b/models/oneplanet/polygon/oneplanet_polygon_schema.yml index 4079302de5a..0de76aeea4f 100644 --- a/models/oneplanet/polygon/oneplanet_polygon_schema.yml +++ b/models/oneplanet/polygon/oneplanet_polygon_schema.yml @@ -1,7 +1,7 @@ version: 2 models: - - name: oneplanet_polygon_base_pairs + - name: oneplanet_polygon_base_pairs_legacy meta: blockchain: polygon project: oneplanet diff --git a/models/quix/optimism/quix_optimism_schema.yml b/models/quix/optimism/quix_optimism_schema.yml index fff9809640a..5f782f7d16e 100644 --- a/models/quix/optimism/quix_optimism_schema.yml +++ b/models/quix/optimism/quix_optimism_schema.yml @@ -145,7 +145,7 @@ models: name: royalty_fee_currency_symbol description: "Symbol of the token in which fees are paid out" - - name: quix_seaport_optimism_base_pairs + - name: quix_seaport_optimism_base_pairs_legacy meta: blockchain: optimism project: quix @@ -551,8 +551,8 @@ models: - token_id - sub_type - sub_idx - - check_seed_legacy: - seed_file: ref('quix_events_seed_legacy') + - check_seed: + seed_file: ref('quix_events_seed') filter: blockchain: optimism project: quix diff --git a/models/quix/optimism/quix_optimism_sources.yml b/models/quix/optimism/quix_optimism_sources.yml index 3d2c05a04b6..f47fcbfdbd3 100644 --- a/models/quix/optimism/quix_optimism_sources.yml +++ b/models/quix/optimism/quix_optimism_sources.yml @@ -23,31 +23,31 @@ sources: - &evt_block_number name: evt_block_number - description: "Block number" + description: "Block number" - &evt_block_time name: evt_block_time - description: "Block time" - + description: "Block time" + - &evt_index name: evt_index - description: "Event index." + description: "Event index." - &evt_tx_hash name: evt_tx_hash - description: "Transaction hash." + description: "Transaction hash." - &price name: price - description: "Price of the NFT token." + description: "Price of the NFT token." - &seller name: seller - description: "Seller wallet address" + description: "Seller wallet address" - &tokenId name: tokenId - description: "Token id." + description: "Token id." - name: ExchangeV2_evt_DutchAuctionFilled loaded_at_field: evt_block_time @@ -136,33 +136,8 @@ sources: warn_after: { count: 24, period: hour } tables: - name: Seaport_evt_OrderFulfilled - loaded_at_field: evt_block_time - description: "Events emitted from Seaport OrderFulfilled." - columns: - - &consideration - name: consideration - description: "The consideration contains an array of items that must be received in order to fulfill the order." - - *contract_address - - *evt_block_number - - *evt_block_time - - *evt_index - - *evt_tx_hash - - &offer - name: offer - description: "The offer contains an array of items that may be transferred from the offerer's account." - - &offerer - name: offerer - description: "The address making the offer." - - &orderHash - name: orderHash - description: "Hash of the order." - - &recipient - name: recipient - description: "The recipient that will receive each item." - - &zone - name: zone - description: "Zone address." - + - name: Seaport_call_matchOrders + - name: Seaport_call_matchAdvancedOrders - name: Exchange_evt_SellOrderFilled loaded_at_field: evt_block_time description: "Events emitted from SellOrderFilled." diff --git a/models/quix/optimism/quix_seaport_optimism_base_pairs.sql b/models/quix/optimism/quix_seaport_optimism_base_pairs.sql deleted file mode 100644 index 58c4dab4092..00000000000 --- a/models/quix/optimism/quix_seaport_optimism_base_pairs.sql +++ /dev/null @@ -1,191 +0,0 @@ -{{ config( - alias = alias('base_pairs'), - partition_by = ['block_date'], - materialized = 'incremental', - file_format = 'delta', - incremental_strategy = 'merge', - unique_key = ['block_date', 'tx_hash', 'evt_index', 'sub_type', 'sub_idx'], - post_hook='{{ expose_spells(\'["optimism"]\', - "project", - "quix", - \'["chuxin"]\') }}' - ) -}} - -{% set c_seaport_first_date = "2022-07-29" %} - -with iv_offer_consideration as ( - select evt_block_time as block_time - ,evt_block_number as block_number - ,evt_tx_hash as tx_hash - ,evt_index - ,'offer' as sub_type - ,offer_idx + 1 as sub_idx - ,case offer[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as offer_first_item_type - ,case consideration[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as consideration_first_item_type - ,offerer as sender - ,recipient as receiver - ,zone - ,offer_item:token as token_contract_address - ,cast(offer_item:amount as numeric(38)) as original_amount - ,case offer_item:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as item_type - ,offer_item:identifier as token_id - ,contract_address as platform_contract_address - ,size(offer) as offer_cnt - ,size(consideration) as consideration_cnt - ,case when recipient = '0x0000000000000000000000000000000000000000' then true - else false - end as is_private - from - ( - select consideration - , contract_address - , evt_block_number - , evt_block_time - , evt_index - , evt_tx_hash - , offer - , offerer - -- , orderHash - , recipient - , zone - , posexplode(offer) as (offer_idx, offer_item) - from {{ source('quixotic_optimism', 'Seaport_evt_OrderFulfilled') }} - {% if not is_incremental() %} - where evt_block_time >= '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - where evt_block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} - ) - union all - select evt_block_time as block_time - ,evt_block_number as block_number - ,evt_tx_hash as tx_hash - ,evt_index - ,'consideration' as sub_type - ,consideration_idx + 1 as sub_idx - ,case offer[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as offer_first_item_type - ,case consideration[0]:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' - end as consideration_first_item_type - ,recipient as sender - ,consideration_item:recipient as receiver - ,zone - ,consideration_item:token as token_contract_address - ,cast(consideration_item:amount as numeric(38)) as original_amount - ,case consideration_item:itemType - when '0' then 'native' - when '1' then 'erc20' - when '2' then 'erc721' - when '3' then 'erc1155' - else 'etc' -- actually not exists - end as item_type - ,consideration_item:identifier as token_id - ,contract_address as platform_contract_address - ,size(offer) as offer_cnt - ,size(consideration) as consideration_cnt - ,case when recipient = '0x0000000000000000000000000000000000000000' then true - else false - end as is_private - from - ( - select consideration - , contract_address - , evt_block_number - , evt_block_time - , evt_index - , evt_tx_hash - , offer - , recipient - , zone - ,posexplode(consideration) as (consideration_idx, consideration_item) - from {{ source('quixotic_optimism', 'Seaport_evt_OrderFulfilled') }} - {% if not is_incremental() %} - where evt_block_time >= '{{c_seaport_first_date}}' -- seaport first txn - {% endif %} - {% if is_incremental() %} - where evt_block_time >= date_trunc("day", now() - interval '1 week') - {% endif %} - ) -) - -,iv_base_pairs as ( - select a.* - ,try_cast(date_trunc('day', a.block_time) as date) as block_date - ,case when offer_first_item_type = 'erc20' then 'offer accepted' - when offer_first_item_type in ('erc721','erc1155') then 'buy' - else 'etc' -- some txns has no nfts - end as order_type - ,case when offer_first_item_type = 'erc20' and sub_type = 'offer' and item_type = 'erc20' then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and item_type in ('native','erc20') then true - else false - end is_price - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx = 0 then true -- offer accepted has no price at all. it has to be calculated. - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx = 1 then true - else false - end is_netprice - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx = 1 then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx = 1 then true - else false - end is_platform_fee - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx > 1 then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx > 2 then true - else false - end is_creator_fee - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and eth_erc_idx > 1 then eth_erc_idx - 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and eth_erc_idx > 2 then eth_erc_idx - 2 - end creator_fee_idx - ,case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721','erc1155') then true - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721','erc1155') then true - else false - end is_traded_nft - ,case when offer_first_item_type in ('erc721','erc1155') and sub_type = 'consideration' and item_type in ('erc721','erc1155') then true - else false - end is_moved_nft - from - ( - select a.* - ,case when item_type in ('native','erc20') then sum(case when item_type in ('native','erc20') then 1 end) over (partition by tx_hash, evt_index, sub_type order by sub_idx) end as eth_erc_idx - ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721','erc1155') then 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721','erc1155') then 1 - end) over (partition by tx_hash, evt_index) as nft_cnt - ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc721') then 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc721') then 1 - end) over (partition by tx_hash, evt_index) as erc721_cnt - ,sum(case when offer_first_item_type = 'erc20' and sub_type = 'consideration' and item_type in ('erc1155') then 1 - when offer_first_item_type in ('erc721','erc1155') and sub_type = 'offer' and item_type in ('erc1155') then 1 - end) over (partition by tx_hash, evt_index) as erc1155_cnt - from iv_offer_consideration a - ) a -) -select * -from iv_base_pairs diff --git a/seeds/nftearth/optimism/nftearth_events_seed.csv b/seeds/nftearth/optimism/nftearth_events_seed.csv deleted file mode 100644 index adc207db650..00000000000 --- a/seeds/nftearth/optimism/nftearth_events_seed.csv +++ /dev/null @@ -1,15 +0,0 @@ -blockchain,project,version,block_date,block_time,seller,buyer,trade_type,trade_category,evt_type,nft_contract_address,collection,token_id,number_of_items,token_standard,amount_original,amount_raw,amount_usd,currency_symbol,currency_contract,original_currency_contract,currency_decimals,project_contract_address,platform_fee_receive_address,platform_fee_amount_raw,platform_fee_amount,platform_fee_amount_usd,platform_fee_percentage,royalty_fee_receive_address,royalty_fee_amount_raw,royalty_fee_percentage,royalty_fee_currency_symbol,royalty_fee_amount,royalty_fee_amount_usd,royalty_fee_receive_address_1,royalty_fee_receive_address_2,royalty_fee_receive_address_3,royalty_fee_receive_address_4,royalty_fee_amount_raw_1,royalty_fee_amount_raw_2,royalty_fee_amount_raw_3,royalty_fee_amount_raw_4,aggregator_name,aggregator_address,block_number,tx_hash,evt_index,tx_from,tx_to,right_hash,zone_address,estimated_price,is_private,sub_idx,sub_type,unique_trade_id -optimism,nftearth,v1,2023-02-02T00:00:00Z,2023-02-02T00:20:35Z,0x8acd4ee46a97be6e483dcfcc99263915abde996a,0x7d3e5dd617eaf4a3d42ea550c41097086605c4af,Single Item Trade,Offer Accepted,Trade,0x99030c3f880a468ed74806fb2785afd2da54a2f4,,4,1,erc721,0.0001,1e+14,0.16414700000000002,WETH,0x4200000000000000000000000000000000000006,0x4200000000000000000000000000000000000006,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,2.5e+12,2.5e-06,0.004103675,2.5,,,,WETH,,,,,,,,,,,,,7.1754724e+07,0x89f370d765eab2ae8e375166af04f186ac9b8db13fed7f9eeb5f5168a1d53388,8,0x8acd4ee46a97be6e483dcfcc99263915abde996a,0x99030c3f880a468ed74806fb2785afd2da54a2f4,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,consideration,2023-02-020x89f370d765eab2ae8e375166af04f186ac9b8db13fed7f9eeb5f5168a1d5338880x99030c3f880a468ed74806fb2785afd2da54a2f44consideration1 -optimism,nftearth,v1,2023-02-07T00:00:00Z,2023-02-07T06:45:40Z,0x8acd4ee46a97be6e483dcfcc99263915abde996a,0x3008087707330e3b85d61b6972934121aed8e6e1,Single Item Trade,Offer Accepted,Trade,0x9b9f542456ad12796ccb8eb6644f29e3314e68e1,OptiChads,1422,1,erc721,0.0231,2.31e+16,37.739855999999996,WETH,0x4200000000000000000000000000000000000006,0x4200000000000000000000000000000000000006,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,5.775e+14,0.0005775,0.9434964,2.5,,,,WETH,,,,,,,,,,,,,7.2690796e+07,0x5617aed9e5e8fd58d76b38acb9b38c2f489046c64fa46174370fdd881aee0f29,6,0x8acd4ee46a97be6e483dcfcc99263915abde996a,0x9b9f542456ad12796ccb8eb6644f29e3314e68e1,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,consideration,2023-02-070x5617aed9e5e8fd58d76b38acb9b38c2f489046c64fa46174370fdd881aee0f2960x9b9f542456ad12796ccb8eb6644f29e3314e68e11422consideration1 -optimism,nftearth,v1,2023-02-19T00:00:00Z,2023-02-19T05:27:33Z,0x28e60fd30536ae13156232f8920af8d7862da5a1,0xf9e1d1e9f22c96752356adfd377231528c7e851e,Single Item Trade,Offer Accepted,Trade,0x00e3aa03e47c32397a94509e50b0558988c0d04e,L2NFTOG,1062,1,erc721,0.015,1.5e+16,25.5207,WETH,0x4200000000000000000000000000000000000006,0x4200000000000000000000000000000000000006,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0xd55c6b0a208362b18beb178e1785cf91c4ce937a,3.75e+14,0.000375,0.6380175,2.5,,,,WETH,,,,,,,,,,,,,7.5266941e+07,0x24679633da0295d880757f7ec741c352a9168b869657c656875cd4ad73afcc1a,6,0x28e60fd30536ae13156232f8920af8d7862da5a1,0x00e3aa03e47c32397a94509e50b0558988c0d04e,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,consideration,2023-02-190x24679633da0295d880757f7ec741c352a9168b869657c656875cd4ad73afcc1a60x00e3aa03e47c32397a94509e50b0558988c0d04e1062consideration1 -optimism,nftearth,v1,2023-02-19T00:00:00Z,2023-02-19T22:33:58Z,0xaa68c24719e4e082a8343442f4b04287a5e55ba9,0x36fdd3dd2f849a2b8932cb0d7d5e0826761bf478,Single Item Trade,Offer Accepted,Trade,0x66deb6cc4d65dc9cb02875dc5e8751d71fa5d50e,L2 State of Mind,881,1,erc721,0.03,3e+16,50.6112,WETH,0x4200000000000000000000000000000000000006,0x4200000000000000000000000000000000000006,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0xd55c6b0a208362b18beb178e1785cf91c4ce937a,7.5e+14,0.00075,1.26528,2.5,,,,WETH,,,,,,,,,,,,,7.5439677e+07,0xdc2f5936d4790c3f778cd059c3eb9d0aa4736933f9ea8528dcd3c8acc138ad9e,6,0xaa68c24719e4e082a8343442f4b04287a5e55ba9,0x66deb6cc4d65dc9cb02875dc5e8751d71fa5d50e,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,consideration,2023-02-190xdc2f5936d4790c3f778cd059c3eb9d0aa4736933f9ea8528dcd3c8acc138ad9e60x66deb6cc4d65dc9cb02875dc5e8751d71fa5d50e881consideration1 -optimism,nftearth,v1,2023-02-18T00:00:00Z,2023-02-18T07:02:04Z,0x81df22ebe26f7e499b5c16c4ec350abb0c312b1c,0xa788e0586409fa4eaf986e24604003adaa3dcc9d,Single Item Trade,Buy,Trade,0xc1853a0f8755c63518f1d22283b5caedd86dfd97,,1200,1,erc721,2.5,2.5e+18,7,OP,0x4200000000000000000000000000000000000042,0x4200000000000000000000000000000000000042,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0xd55c6b0a208362b18beb178e1785cf91c4ce937a,6.25e+16,0.0625,0.175,2.5,,,,OP,,,,,,,,,,,,,7.510953e+07,0x353395578557f5e9b86397941490799d7c23e3e816d25ea69f5ce5c3e49dd248,0,0xa788e0586409fa4eaf986e24604003adaa3dcc9d,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-180x353395578557f5e9b86397941490799d7c23e3e816d25ea69f5ce5c3e49dd24800xc1853a0f8755c63518f1d22283b5caedd86dfd971200offer1 -optimism,nftearth,v1,2023-02-20T00:00:00Z,2023-02-20T01:51:29Z,0x52a7086ae376fefe37aefaecb4b50281949b94da,0x3207446dd7fdefa5dd9f66e89f0f49070afc5731,Single Item Trade,Buy,Trade,0xab236c814a1651d3d699e333495d4bb1a818a2ad,Opti yEEts Gang,593,1,erc721,0.5,5e+17,1.28,OP,0x4200000000000000000000000000000000000042,0x4200000000000000000000000000000000000042,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,1.25e+16,0.0125,0.032,2.5,,,,OP,,,,,,,,,,,,,7.5466295e+07,0xca54b387d0866c3e6d25ecb134cb5e35d9c2dc6db4a61f0faf2bffad8d5794de,0,0x3207446dd7fdefa5dd9f66e89f0f49070afc5731,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-200xca54b387d0866c3e6d25ecb134cb5e35d9c2dc6db4a61f0faf2bffad8d5794de00xab236c814a1651d3d699e333495d4bb1a818a2ad593offer1 -optimism,nftearth,v1,2023-02-08T00:00:00Z,2023-02-08T02:25:59Z,0x8acd4ee46a97be6e483dcfcc99263915abde996a,0xe45c950efb371c331ffef421b5c8787c74830479,Single Item Trade,Buy,Trade,0x9b9f542456ad12796ccb8eb6644f29e3314e68e1,OptiChads,6726,1,erc721,0.03,3e+16,50.4672,ETH,0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000,0x0000000000000000000000000000000000000000,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,7.5e+14,0.00075,1.2616800000000001,2.5,,,,ETH,,,,,,,,,,,,,7.2855735e+07,0xa1fd2f37915babeb69b53f899aa87bca0257382384b880121a82caa4f9def8a8,0,0xe45c950efb371c331ffef421b5c8787c74830479,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-080xa1fd2f37915babeb69b53f899aa87bca0257382384b880121a82caa4f9def8a800x9b9f542456ad12796ccb8eb6644f29e3314e68e16726offer1 -optimism,nftearth,v1,2023-02-08T00:00:00Z,2023-02-08T07:18:39Z,0x8acd4ee46a97be6e483dcfcc99263915abde996a,0x4f49c34759b7e888ce77de9dd34fec63d63495cc,Single Item Trade,Buy,Trade,0x0deaac29d8a3d4ebbaaa3ecd3cc97c9def00f720,OaycNFT,5554,1,erc721,0.02,2e+16,33.5118,ETH,0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000,0x0000000000000000000000000000000000000000,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,5e+14,0.0005,0.837795,2.5,,,,ETH,,,,,,,,,,,,,7.289286e+07,0x091d16fd5645d2e31f91a10cb2f88a584b8c908597cb2726e67dcb2cfc52be4b,0,0x4f49c34759b7e888ce77de9dd34fec63d63495cc,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-080x091d16fd5645d2e31f91a10cb2f88a584b8c908597cb2726e67dcb2cfc52be4b00x0deaac29d8a3d4ebbaaa3ecd3cc97c9def00f7205554offer1 -optimism,nftearth,v1,2023-02-09T00:00:00Z,2023-02-09T02:43:35Z,0x8acd4ee46a97be6e483dcfcc99263915abde996a,0xf005857d42072049567b7089d972ad788b9891ea,Single Item Trade,Buy,Trade,0x00e3aa03e47c32397a94509e50b0558988c0d04e,L2NFTOG,1946,1,erc721,0.019,1.9e+16,31.33404,ETH,0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000,0x0000000000000000000000000000000000000000,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,4.75e+14,0.000475,0.783351,2.5,,,,ETH,,,,,,,,,,,,,7.305278e+07,0xc0f0f804e24482dbf0d59a8b76d0a6f7e6b596d7ce5d60d5f5595462e0da4341,0,0xf005857d42072049567b7089d972ad788b9891ea,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-090xc0f0f804e24482dbf0d59a8b76d0a6f7e6b596d7ce5d60d5f5595462e0da434100x00e3aa03e47c32397a94509e50b0558988c0d04e1946offer1 -optimism,nftearth,v1,2023-02-09T00:00:00Z,2023-02-09T10:08:10Z,0x8acd4ee46a97be6e483dcfcc99263915abde996a,0x577f998446b879f8f12e914e819e21bdc818d07d,Single Item Trade,Buy,Trade,0x00e3aa03e47c32397a94509e50b0558988c0d04e,L2NFTOG,1968,1,erc721,0.02,2e+16,32.726,ETH,0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000,0x0000000000000000000000000000000000000000,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,5e+14,0.0005,0.81815,2.5,,,,ETH,,,,,,,,,,,,,7.3120037e+07,0x099be61641b2ff9371f764606c7f73456861a77c89b95434e702a98c95425970,0,0x577f998446b879f8f12e914e819e21bdc818d07d,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-090x099be61641b2ff9371f764606c7f73456861a77c89b95434e702a98c9542597000x00e3aa03e47c32397a94509e50b0558988c0d04e1968offer1 -optimism,nftearth,v1,2023-02-09T00:00:00Z,2023-02-09T10:08:55Z,0x8acd4ee46a97be6e483dcfcc99263915abde996a,0x577f998446b879f8f12e914e819e21bdc818d07d,Single Item Trade,Buy,Trade,0x00e3aa03e47c32397a94509e50b0558988c0d04e,L2NFTOG,2800,1,erc721,0.02,2e+16,32.726,ETH,0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000,0x0000000000000000000000000000000000000000,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,5e+14,0.0005,0.81815,2.5,,,,ETH,,,,,,,,,,,,,7.3120163e+07,0x0bb18d11eb4d415a33beb5e5fd092ec21f496a34ef385c571617e92e6a44ce68,0,0x577f998446b879f8f12e914e819e21bdc818d07d,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-090x0bb18d11eb4d415a33beb5e5fd092ec21f496a34ef385c571617e92e6a44ce6800x00e3aa03e47c32397a94509e50b0558988c0d04e2800offer1 -optimism,nftearth,v1,2023-02-11T00:00:00Z,2023-02-11T10:09:49Z,0x577f998446b879f8f12e914e819e21bdc818d07d,0xf692450103d37fbed3f50348e9a8518a92bb21ee,Single Item Trade,Buy,Trade,0x00e3aa03e47c32397a94509e50b0558988c0d04e,L2NFTOG,2800,1,erc721,0.036,3.6e+16,54.83304,ETH,0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000,0x0000000000000000000000000000000000000000,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,9e+14,0.0009,1.370826,2.5,,,,ETH,,,,,,,,,,,,,7.36491e+07,0x788ae1feee98ab7be9dd1728a8d1edfdd46d7620d25baf0ef8a1ed2bdf251d6b,0,0xf692450103d37fbed3f50348e9a8518a92bb21ee,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-110x788ae1feee98ab7be9dd1728a8d1edfdd46d7620d25baf0ef8a1ed2bdf251d6b00x00e3aa03e47c32397a94509e50b0558988c0d04e2800offer1 -optimism,nftearth,v1,2023-02-11T00:00:00Z,2023-02-11T14:01:49Z,0x4581b0c0d0d6db8bf970e93d6baa004f0254d6fb,0xd0886275a97757676f051b29d3b636badcb1acb5,Single Item Trade,Buy,Trade,0x9b9f542456ad12796ccb8eb6644f29e3314e68e1,OptiChads,7431,1,erc721,0.11,1.1e+17,167.6532,ETH,0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000,0x0000000000000000000000000000000000000000,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,2.75e+15,0.00275,4.19133,2.5,0x7b91fa01dc8cb3bc55e1781163f5aeaed6747d10,5.5e+15,5,ETH,0.0055,8.38266,0x7b91fa01dc8cb3bc55e1781163f5aeaed6747d10,,,,5.5e+15,,,,,,7.3686816e+07,0x80d18898d16e3679eb12d0694099300b981075467e5bc0fb824ef98e9dd2d4ca,0,0xd0886275a97757676f051b29d3b636badcb1acb5,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-110x80d18898d16e3679eb12d0694099300b981075467e5bc0fb824ef98e9dd2d4ca00x9b9f542456ad12796ccb8eb6644f29e3314e68e17431offer1 -optimism,nftearth,v1,2023-02-12T00:00:00Z,2023-02-12T06:33:47Z,0xacd54246eda0c5638a247c4717a8782c21497eb6,0x078a0b6d78d6fa119655fe6a1b7c02fc9dc7ff73,Single Item Trade,Buy,Trade,0x0deaac29d8a3d4ebbaaa3ecd3cc97c9def00f720,OaycNFT,8969,1,erc721,0.101,1.01e+17,155.03399000000002,ETH,0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000,0x0000000000000000000000000000000000000000,18,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,0x78ed254b9c140c1a2be10d2ad32c65b5f712f54b,2.525e+15,0.002525,3.87584975,2.5,0x81b7e9d8409b857d70ad14073e785c486945caf4,5.05e+15,5,ETH,0.00505,7.7516995,0x81b7e9d8409b857d70ad14073e785c486945caf4,,,,5.05e+15,,,,,,7.3803899e+07,0xcf480eba2cc52cf4bac7b3f6bd1b275fed75722a4ee6355418e25df21e9696c4,0,0x078a0b6d78d6fa119655fe6a1b7c02fc9dc7ff73,0x0f9b80fc3c8b9123d0aef43df58ebdbc034a8901,a8f07167,0x0000000000000000000000000000000000000000,false,false,1,offer,2023-02-120xcf480eba2cc52cf4bac7b3f6bd1b275fed75722a4ee6355418e25df21e9696c400x0deaac29d8a3d4ebbaaa3ecd3cc97c9def00f7208969offer1 diff --git a/seeds/oneplanet/polygon/oneplanet_polygon_trades_seed.csv b/seeds/oneplanet/polygon/oneplanet_polygon_trades_seed.csv deleted file mode 100644 index 9f45edd7ce1..00000000000 --- a/seeds/oneplanet/polygon/oneplanet_polygon_trades_seed.csv +++ /dev/null @@ -1,101 +0,0 @@ -block_time,tx_hash,price_amount_raw -2023-01-04 15:18:59,0x1d1d34afea2d9f67ec0d9a33f19602ab208e59af3042a952eb02af19321a5d14,10000000000000000000 -2023-01-05 19:46:27,0x33b791a02d8ccc4a76f4d62fa54eed0aa811037f7b5e20b48c2bea6df8faa046,270000000000000000000 -2023-01-07 04:13:47,0x8a41654405242144c21dc996361073eb20e76d331500a99987c32ac6f5f3631b,150000000 -2023-01-03 23:04:17,0x8b279b9ae914d2ef9f64bc4431765b622f6d600dc577000a710d40abe209bce1,6500000000000000000 -2023-01-05 13:47:17,0x1a08a3f45fa812e5ca8e423ce3eb8d8c1374e0f9e2b6dee7e416f64820ede270,95000000000000000000 -2023-01-03 03:19:35,0x219dfda000fc8ca842ebd5f483e37183ec11e403d11e4b4f9dee87256457f89f,705000000000000000000 -2023-01-03 00:46:41,0x55570bff3316f55ef87dbfdbc4b87097812eb4dba14e0b89dd30a689698b724f,5000000000000000000 -2023-01-09 14:34:01,0x68539622ed20bac68edc9d4eb5578856b27ec114b71ddb159ee46de85dd43cc9,10000000000000000000 -2023-01-06 23:49:34,0x7d3d4fbd48a2e584d91150c0c8c52fd7570c5df44b1164736aa38b0ab58f8b10,299000000000000000000 -2023-01-08 07:06:59,0xaa3ec864da2cb88bfdde9be1ecbe62ea915080afa004b8f4d40d8a20696b210b,167000000000000000000 -2023-01-03 18:13:08,0xe4f410fe2f8bd43f1eaaf26df6039ed8071fe754039e5bc935b580d5cfd498b1,180000000000000000000 -2023-01-05 23:53:40,0x1cb11df8d5c349bcdef7e083dd541d8cb77871b4dbac0f07669f50acffb8f9cf,3200000000000000000 -2023-01-06 14:00:12,0x6952b6b27425c3f0d79e7d7c2957f92b9e9b6fbee74bd27aafdd474b1cd78359,179000000000000000000 -2023-01-03 02:04:09,0x3f12a0fd4a7d884871f3b121ab0c1475d0c6c5a188acf51c28c7b9e79e93c696,2500000000000000000 -2023-01-08 06:52:43,0x40897b1aa54e8aceb148ea9d319bc43be68bb4315fbae0d6df2354ff6551731e,150000000000000000000 -2023-01-04 15:18:01,0x567da0b0ffa0f88d082431e193d723e55ccb950d300072cd326737ed6a86b5eb,10000000000000000000 -2023-01-06 09:55:19,0x997ae0582d1177ffd709e41b9d6ac80963374236d169bd8c306f7efd6ab7ff6c,6000000000000000000 -2023-01-04 13:01:57,0xbd217079b3919db33e640ae6b36159474699e149f4e98cb71ed66c38e939cab1,10000000000000000000 -2023-01-06 16:50:16,0x17501430ed20e094e97cc1e10a4f38f3db9ae9fb48822577ef91c0d2994570cb,20000000000000000000 -2023-01-07 16:49:32,0x1cf4ca703d309690a312342b36d8706768ea1c458afe87ec90d7b0bff8966a5d,27000000000000000000 -2023-01-09 21:02:28,0x522856b0b8d93879d99d913c4d372de3b96c5d1603a2e80f6c1c90cd3fc1447e,175000000000000000000 -2023-01-05 06:30:01,0x9e76d6839326d4f0d21c5f11e1a183521754645d2506a3b50a5b6bcf548efe5d,450000000000000000000 -2023-01-04 07:35:45,0x4faf1a26ec001a9c6f734f745f40c7c73cad687041622408023ed8322b1563f2,165000000000000000000 -2023-01-02 22:13:27,0x66ba6d9f8bdceeb9bb5f5667f5c6c4160641c4b16fae280b1b720400d398f25a,150000000000000000000 -2023-01-05 00:05:41,0x98e52fcd2e3b3df11bdb546b3c4f26c6f891d030026b9706fd7eec3819e39869,910000000000000000000 -2023-01-03 00:34:23,0xcdc93d56e5f8b9e9df43000f06af695c305e4f7eaa4c6704b5bd474849823589,10000000000000000000 -2023-01-05 13:51:59,0xef005979e849b72bc735d8c1c856c154f355f3359802c96c4558c3253a4cd1d7,97000000000000000000 -2023-01-05 08:28:23,0x0c2dcd80140d8b41de47f34771d6e395f8bfd881bd9b12ece811db0de4595fb6,200000000000000000000 -2023-01-06 17:35:28,0x432a7ed5d3c9fc9b69b1f6e3f742b424ae59d5cc0b061d04b5940c31430b3ebc,44989000000000000000 -2023-01-02 11:28:57,0x96574422b376a2f74492ab809a86f4d000805a363a79c6cc07796b49040c26e6,13000000000000000000 -2023-01-08 18:49:00,0xae8be10b4efa6784776f68c32ab7ddf2a36b4dcdc4e319ba091d42c9860ad1fa,450000000 -2023-01-07 15:45:12,0xce365dbea58e2ad9431e7530ee791d5c1cbc31757ea77904c4ca0647db717530,10000000000000000000 -2023-01-09 14:35:09,0xaff0d038f3b81fb966bf6d2e9c7e716b707572ab5398fec3274d9b805d993493,9500000000000000000 -2023-01-04 15:11:27,0xff4331e795be5e0e532c8cd91e7d93b80b41b054f65562211f84785f11a84c6b,25000000000000000000 -2023-01-02 14:20:31,0x036e24986b64aefc4b7aadc5f59757ff190a7c2e4ff1cc98389f4a02b6a569d1,6000000000000000000 -2023-01-07 11:20:25,0x10f042a263fe7a88d4310a5d2ade6e70257419fdf72667febee4402d6ae2cf61,200000000000000000000 -2023-01-07 12:18:06,0x59433df5692eee8eaff0b13b787392cb2ebcbf4e3b149f0b2a3644e97c645049,2000000000000000000 -2023-01-03 10:43:16,0x82c0aca8e719a5c9d12bc15f5b03bf4a1ae903f22f07a21ea08bbd292a39ea60,167000000000000000000 -2023-01-03 02:05:53,0xd9fa0a0b8ae2156191928ebe1e340fa0a21ed93834e82e690fb282d3176f86d1,2500000000000000000 -2023-01-06 08:04:03,0xef66cb43f806fe629e92a5eaa2d6b06b896be8b30b4164a41312982b2153f0fa,199000000000000000000 -2023-01-06 06:45:49,0xf4cde46ce667f544be5ccbc2045064e8e6fa1a06af79f6ebbba096ae6c73a38e,36000000000000000000 -2023-01-05 16:17:44,0xfdda8f7a26172ed17d4a9d860c7001893f206aab449d180df6a4120d889a9084,50000000000000000000 -2023-01-08 21:34:52,0x1ceb8464e808c71fe99e1c8689c78350450669021aafa4276b4bbf14819acaa1,299000000000000000000 -2023-01-02 15:48:41,0xa292f7112d0b0e95da06bd9a3570bc83a7e988f3866142b45288a8fe71d47653,155000000000000000000 -2023-01-03 02:08:47,0x7410f7d54190787378c42112684bf9608f7373f941909977d797798f663fb3c6,4000000000000000000 -2023-01-05 04:35:15,0xa4973caf4e074a198ef769392d4a778af2857bdb382c4cac00a4075b6c666af0,47500000000000000000 -2023-01-02 13:36:34,0x23b5e3f333e5598290c5211c0d0e8178226da8dd5c05d3498e9ba9fb58e258d9,149000000000000000000 -2023-01-02 15:52:03,0x7c042c16571b755fe87378402e1a13e8950a121e975ac12c839ce9447a3e96cf,178000000000000000000 -2023-01-05 20:07:35,0xb941ea8521736f8e5bb5b169dec263604d21df56c8c6e328c67c4a234fd0976e,37770000000000000000 -2023-01-06 02:30:42,0xc8551217596381240e07350d1dac97ad49e3fb0c71ea785e1f47bb5f70bb767f,600000000000000000000 -2023-01-07 14:32:36,0x2eb21fa47828426dad87f636c5aa0a9bde45584fbcabfa1c06477c29f415ebe9,17000000000000000000000 -2023-01-05 17:07:08,0x365efafbd87606f01589e104955e889ab8675155177258946aac15206697a7e9,190000000000000000000 -2023-01-08 07:06:23,0x8a8ba0bf4ffa0433a156136802bafe0b9ce00d75bb0a204b3604bf31930f614e,170000000000000000000 -2023-01-03 10:44:40,0x4c65ed0b02135bf17814718e0039e5daf9f12600de20ff540a2a34fae42150f7,169000000000000000000 -2023-01-05 08:17:37,0x971e2530a2089c6f68f96b7b610cca786ebe8c10cccabfacec00dabb885e8548,173000000000000000000 -2023-01-05 23:57:06,0xfeefa139f63dd82be1101269264434c1d94fb40f07ab204093fd2fe8358d5ae8,10000000000000000000 -2023-01-03 04:12:03,0x6dac3fcd761e0809ff2d6e9c1d3c5c1cee76c40b534a8508b94d9596409cc94e,700000000000000000000 -2023-01-05 16:13:44,0xe3cdfa62d1bd91ec8625d97492ad0af6e8fe59103aaae009fe6c33374b49fdf8,9690000000000000000 -2023-01-09 05:19:55,0xf11b0762da08c9262f80538b4e20f0f224512ad039915b516ad0dcc65a91e8e0,69000000000000000000 -2023-01-08 08:15:48,0x0a87d1bc94709e95acee0525e296cd6c268db9ee07ad7aff907ae33ddc12ca38,750000000000000000000 -2023-01-09 21:48:16,0x11fe8373dbfa67bb9a06eb79cd5a9028bf4c5a685f03f0544d027b3b3a77c176,180000000000000000000 -2023-01-08 00:20:02,0x3f5e0237fb80ec639a22b39b3d3896dc90c06cbfadf596933eb5fe685e145189,640000000 -2023-01-02 15:50:17,0x58f2ebcc8e74eec5432dd69c2ec2a341544a75436a5e299550084add2fc38352,169000000000000000000 -2023-01-04 21:32:40,0x866da5f8d89f727b7a0b52475a1bf0fdc4cbd4609cc2d31a62d3cafca653f78a,40000000000000000000 -2023-01-03 02:17:29,0x93a496a0268a57840467dc97290e8ebf00501d0c63d51e25feae4c4af9677d5e,2000000000000000000 -2023-01-06 12:07:47,0xab385eb972526692026a8952f4d46f41dbb86c59d575494214f210e337080b04,660000000 -2023-01-02 11:27:11,0xab3eede379aac051c63d08f2d6adcb2b41262405c6ed1c61742fd5491489b165,49000000000000000000 -2023-01-04 23:39:37,0xe0518da8a53c2880af9821ad8c4d834b2da0ae4a868e07698af6d968f00fbd8f,5000000000000000000 -2023-01-01 15:29:34,0xe0b412033941f7ee06c58082e0a9142c244f6f6db616a5c485f40d36da0f6b50,40000000000000000000 -2023-01-08 21:11:52,0x3d0f543cac5595b06efc0d5de3392a48faec277f8b4f37fe695c88a17dfa10df,190000000000000000000 -2023-01-05 16:03:48,0xa25b65252a9f2297f9e0bc75a017cfeb76bc8c3d246e18e2ac66703fe8da8f2a,3800000000000000000 -2023-01-05 16:09:00,0x4942751590ee16266748083214befc91eb6bc52ef7c1ba563a16d810ad0dd36b,5000000000000000000 -2023-01-06 00:31:40,0xafa3fc1efdc2a406aa9d38d496694a535225a6ecdb0319defbd82f00ba44c70c,345000000000000000000 -2023-01-08 16:43:08,0xc1e7968d691e87ee5ba13caaf7036d2609516ac28cf5b31af79a03c06ef287df,5000000000000000000 -2023-01-05 23:03:22,0x32b70658b3584c814fa2dfc5ac1aff989c2a9b5777dbf3cc02b674059d57d276,169000000000000000000 -2023-01-05 13:53:35,0x58fc0894bd82ec511346531ca132e531a8d16e97314f76c93b423b407da8e7bc,110000000000000000000 -2023-01-08 03:07:20,0x32a442429b1e3c91f24ffe4954291ea3bf741e5a5ab1cea530dd163ab8e78ebf,13800000000000000000 -2023-01-05 04:35:57,0x60730ef794aa41581d7c1d826de20348cda4d5ed25c431f61c2a7fef6ac162ba,49000000000000000000 -2023-01-05 18:25:46,0xb82b3412aa2940aa41965b776ea2162f0ba49acb4fe0584decd3333e87a5c189,765000000000000000000 -2023-01-09 04:14:24,0x645f8c934e2e77a9b54c2207e705074b71c85267d8264074457c301b78b8bb25,10500000000000000000000 -2023-01-04 23:28:55,0x7252f1c0ce82bad3485aa666050025d4e93f2dd5a0e6b72721747aed2f55ce24,3000000000000000000 -2023-01-08 05:51:34,0x8a03d603bbbbbbb0a8a3bbfac6c063339c0e80e3ba036c54ab95e95ab29c03f0,4000000000000000000000 -2023-01-05 23:58:34,0x9c9f6640e4fd457ed07845e9450157bff00ad9e22530f59541ea4be4beeac473,10000000000000000000 -2023-01-06 17:26:08,0xbe0eb2c45ac0b37a9feb159de8c74063594bcb42d9af117bf264e70871b5d5f7,30000000000000000000 -2023-01-04 15:17:29,0xd34e320e03c25327db385668a25871c0054c0c5a24b490c9f1c25bb082cef6be,5000000000000000000 -2023-01-07 12:07:23,0x124b8e9c394150897cbdd7fe9205f1cf3c6898665f3ab8c8a741eee97a04d694,3000000000000000000 -2023-01-02 15:49:15,0x1d8cb76f4ce63a9ccc8838fe850c9c67bdd4caa0e281fcbc4793bf894d1447a2,155000000000000000000 -2023-01-06 08:41:55,0xc7b24aa6f11192da9ec4d027a6a83176a5e061dd298eddb83528e63b1611a84f,45000000000000000000 -2023-01-09 15:15:31,0xf86fc195e6272f44eb2f6fbc84e36825d84c6e081b8241ccdba177e4ec7b83ce,179000000000000000000 -2023-01-05 16:08:22,0x2f84161075ed94c7d93c235458f75f2e5f4126195d7b248dec5adbd32e5664f8,4200000000000000000 -2023-01-05 17:42:04,0xef54db6bec0115aaaece5280abd52ec552797884440867b6eee96dd2564d9f8b,37000000000000000000 -2023-01-04 21:45:16,0x1ead30f8110fe9564c86e8bc063bfd3dd3448dda8f6f1015f7972ad28ceb4d12,750000000000000000000 -2023-01-04 15:42:09,0x85b522ba685978aa6b97941ca18065434f82512068b9c398f67e9986233afa1a,125000000000000000000 -2023-01-03 17:45:14,0xc72c697ed711cfe38d499e5cfd84c74bca343379f39b5a634d4e9e2f6b82e4c9,40000000000000000000 -2023-01-02 14:53:11,0xe9e0017bdf34b079b8b151bdd5ef4bc9acc42c0323b510f6f9a702b0e540c8d1,3500000000000000000 -2023-01-01 11:09:09,0x9e0debd14aa4a7777340c2636446f77c8590de65933fa266bc75f11509e78990,240000000000000000000 -2023-01-05 15:27:46,0x22073db4a2284b848d9292dceda6ff7d33e0f9d8a2a35cd8b33cd3c6176c8e31,139000000000000000000 -2023-01-06 16:22:34,0x2488fcfde0cfc21f95b6926606dfb238dc3b19f63905358e2d7871492718112a,18888000000000000000000 -2023-01-04 12:17:59,0x74694e21fd7273f6f5ff8980c5360797b3fe8938ed3e1f254df1b2a0b7868cd5,8000000000000000000 -2023-01-05 03:43:06,0xd94763aa25083ba933055dfa1a66ad09dc35218d5a2519f334ecc2b62dfed876,440000000000000000000 \ No newline at end of file diff --git a/seeds/quix/quix_events_seed.csv b/seeds/quix/quix_events_seed.csv index 73ec85f3d55..d7e43ce56bc 100644 --- a/seeds/quix/quix_events_seed.csv +++ b/seeds/quix/quix_events_seed.csv @@ -11,5 +11,6 @@ optimism,quix,v4,2022-06-02,2022-06-02 13:12,2082,Optimistic Apes,erc721,Single optimism,quix,v4,2022-06-12,2022-06-12 16:07,3778,Bored Town,erc721,Single Item Trade,1,Buy,Trade,0x8c66ac5284fec2676a2c79acc2c27e2a3df143d7,0x9b4ac5feb3fa9c087906cce730dc1bed34f08514,0x8e56343adafa62dac9c9a8ac8c742851b0fb8b03,0x065e8a87b8f11aed6facf9447abe5e8c5d7502b6,0xd437e1eba2b73ca8314056886d42f93eaacb2956bce60643a014158b41642008,2,11421468,0x9b4ac5feb3fa9c087906cce730dc1bed34f08514,0x065e8a87b8f11aed6facf9447abe5e8c5d7502b6,0x6ff5723435b7dfc2371b57fb5cb4c373e5995c78 optimism,quix,v5,2022-07-24,2022-07-24 10:34,1048578,Dope Wars Gear,erc1155,Single Item Trade,1,Buy,Trade,0x4fc885d34a300c93bc19d02eabe3e23ff6368605,0x534d1a3374c966502e25d1d5d1e0ba9b5bd67c37,0x0e55e1913c50e015e0f60386ff56a4bfb00d7110,0x3f9da045b0f77d707ea4061110339c4ea8ecfa70,0x3e7303e51e7e721d1affcd46f41a593b566fe58b380f1c5daf04a128466abd87,1,15599928,0x534d1a3374c966502e25d1d5d1e0ba9b5bd67c37,0x3f9da045b0f77d707ea4061110339c4ea8ecfa70,0x90103bedcfbe1eee44ded89ced88ba8503580b3d optimism,quix,v5,2022-07-26,2022-07-26 14:39,936,Apetimism,erc721,Single Item Trade,1,Buy,Trade,0xd5e625529672803fa47e21d9a79db83e0d651e7c,0xf7dc1b23c904e0ca611ed2e77ecef2fc8e20991e,0x51e5426ede4e2d4c2586371372313b5782387222,0x3f9da045b0f77d707ea4061110339c4ea8ecfa70,0x083ed3fb48b6cd7d8885c82ef6de1365deb04209cf7761e0aa29a9da79d3702c,2,15845871,0xf7dc1b23c904e0ca611ed2e77ecef2fc8e20991e,0x3f9da045b0f77d707ea4061110339c4ea8ecfa70,0x49c45b837e16ee40c7111db22b300124ae3fd83e -optimism,quix,seaport,2022-12-04,2022-12-04T22:53:27Z,2872,Bored Town,erc721,Single Item Trade,1,Offer Accepted,Trade,0x47a2a5a8950dd410410f0af03af0964cae6ffec4,0x1b782def7a5ea494de59977739da7d323aa183de,0x8e56343adafa62dac9c9a8ac8c742851b0fb8b03,0x998ef16ea4111094eb5ee72fc2c6f4e6e8647666,0x5318f8afa3315aed66cdefd6567c8365d30fc3325815ddb1cdfb49017048b7f6,0,4.5445698e+07,0x47a2a5a8950dd410410f0af03af0964cae6ffec4,0x998ef16ea4111094eb5ee72fc2c6f4e6e8647666,0x6ff5723435b7dfc2371b57fb5cb4c373e5995c78 optimism,quix,seaport,2022-12-06,2022-12-06T06:50:54Z,6670,OaycNFT,erc721,Single Item Trade,1,Offer Accepted,Trade,0x2c23f12195077bee4ac4f7d598af30904a5fbf91,0x1797b056c84e56f1b7c8d19715b75f761a81e6c4,0x0deaac29d8a3d4ebbaaa3ecd3cc97c9def00f720,0x998ef16ea4111094eb5ee72fc2c6f4e6e8647666,0xe38f16aef2e57bfd33ff9b54de7529d016eb1bdc950770e84b0ee170401a79da,0,4.5922037e+07,0x2c23f12195077bee4ac4f7d598af30904a5fbf91,0x998ef16ea4111094eb5ee72fc2c6f4e6e8647666,0x9458fac809f8f1448390bd6ff1abb4ef26c1dda8 +optimism,quix,seaport,2022-12-04,2022-12-04T22:53:27Z,2872,Bored Town,erc721,Single Item Trade,1,Offer Accepted,Trade,0x47a2a5a8950dd410410f0af03af0964cae6ffec4,0x1b782def7a5ea494de59977739da7d323aa183de,0x8e56343adafa62dac9c9a8ac8c742851b0fb8b03,0x998ef16ea4111094eb5ee72fc2c6f4e6e8647666,0x5318f8afa3315aed66cdefd6567c8365d30fc3325815ddb1cdfb49017048b7f6,0,4.5445698e+07,0x47a2a5a8950dd410410f0af03af0964cae6ffec4,0x998ef16ea4111094eb5ee72fc2c6f4e6e8647666,0x6ff5723435b7dfc2371b57fb5cb4c373e5995c78 + diff --git a/tests/oneplanet/polygon/oneplanet_polygon_assert_trades.sql b/tests/oneplanet/polygon/oneplanet_polygon_assert_trades.sql deleted file mode 100644 index 6a0db63469f..00000000000 --- a/tests/oneplanet/polygon/oneplanet_polygon_assert_trades.sql +++ /dev/null @@ -1,12 +0,0 @@ --- Manually check against exported data from Dune https://dune.com/queries/2063220 - -WITH unit_tests as ( - SELECT (case when test_data.price_amount_raw = trades.amount_raw then True else False end) as price_test - FROM {{ ref('oneplanet_polygon_events') }} trades - JOIN {{ ref('oneplanet_polygon_trades_seed') }} test_data ON test_data.tx_hash = trades.tx_hash AND test_data.block_time = trades.block_time - WHERE trades.block_time > '2023-01-01' and trades.block_time < '2023-01-10' -) - -select count(case when price_test = false then 1 else null end)/count(*) as pct_mismatch, count(*) as count_rows -from unit_tests -having count(case when price_test = false then 1 else null end) > 0