mirror of
https://github.com/FlipsideCrypto/polygon-models.git
synced 2026-02-06 17:11:49 +00:00
add nft transfers from operator and null bug fix (#209)
This commit is contained in:
parent
762f299593
commit
087dbf6fe5
@ -290,8 +290,7 @@ base_sales_buy AS (
|
||||
tx_hash
|
||||
FROM
|
||||
filtered_private_offer_tx
|
||||
)
|
||||
AND tx_type IS NOT NULL
|
||||
) -- AND tx_type IS NOT NULL ; null tx type would mean that there aren't any considerations. The nft is transferred without asking for anything in exchange for it
|
||||
),
|
||||
base_sales_buy_null_values AS (
|
||||
SELECT
|
||||
@ -536,6 +535,18 @@ base_sales_buy_sale_amount_null_values AS (
|
||||
FROM
|
||||
base_sales_buy_sale_amount_filter
|
||||
)
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
event_index,
|
||||
NULL AS currency_address,
|
||||
0 AS sale_amount_raw_,
|
||||
0 AS platform_fee_raw_,
|
||||
0 AS creator_fee_raw_
|
||||
FROM
|
||||
base_sales_buy
|
||||
WHERE
|
||||
tx_type IS NULL
|
||||
),
|
||||
base_sales_buy_sale_amount_combined AS (
|
||||
SELECT
|
||||
@ -960,7 +971,7 @@ base_sales_buy_and_offer AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
token_type,
|
||||
nft_address,
|
||||
nft_address AS nft_address_temp,
|
||||
tokenid AS tokenId,
|
||||
erc1155_value,
|
||||
IFF(
|
||||
@ -995,7 +1006,7 @@ base_sales_buy_and_offer AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
token_type,
|
||||
nft_address,
|
||||
nft_address AS nft_address_temp,
|
||||
tokenid AS tokenId,
|
||||
erc1155_value,
|
||||
IFF(
|
||||
@ -1036,6 +1047,49 @@ tx_data AS (
|
||||
base_sales_buy_and_offer
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) :: DATE - 1
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
nft_transfer_operator AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
contract_address AS nft_address_from_transfers,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS nft_address_temp,
|
||||
--or operator_address
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS offerer,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS recipient,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: STRING AS tokenid,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
)
|
||||
) AS erc1155_value
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
block_timestamp :: DATE >= '2022-06-01'
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
DISTINCT tx_hash
|
||||
FROM
|
||||
base_sales_buy_and_offer
|
||||
)
|
||||
AND topics [0] :: STRING IN (
|
||||
'0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',
|
||||
'0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
@ -1070,7 +1124,11 @@ SELECT
|
||||
ZONE,
|
||||
tx_type,
|
||||
s.token_type,
|
||||
s.nft_address,
|
||||
s.nft_address_temp,
|
||||
CASE
|
||||
WHEN nft_address_from_transfers IS NOT NULL THEN nft_address_from_transfers
|
||||
ELSE s.nft_address_temp
|
||||
END AS nft_address,
|
||||
s.tokenId,
|
||||
s.erc1155_value,
|
||||
s.currency_address,
|
||||
@ -1099,7 +1157,7 @@ SELECT
|
||||
offer,
|
||||
input_data,
|
||||
CONCAT(
|
||||
s.nft_address,
|
||||
nft_address,
|
||||
'-',
|
||||
s.tokenId,
|
||||
'-',
|
||||
@ -1110,7 +1168,12 @@ SELECT
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
base_sales_buy_and_offer s
|
||||
INNER JOIN tx_data t
|
||||
ON t.tx_hash = s.tx_hash qualify(ROW_NUMBER() over(PARTITION BY nft_log_id
|
||||
INNER JOIN tx_data t USING (tx_hash)
|
||||
LEFT JOIN nft_transfer_operator o USING (
|
||||
tx_hash,
|
||||
nft_address_temp,
|
||||
tokenid,
|
||||
recipient
|
||||
) qualify(ROW_NUMBER() over(PARTITION BY nft_log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
|
||||
@ -523,8 +523,7 @@ mao_orderhash AS (
|
||||
tx_hash
|
||||
FROM
|
||||
filtered_private_offer_tx
|
||||
)
|
||||
AND tx_type IS NOT NULL
|
||||
) -- AND tx_type IS NOT NULL ; null tx type would mean that there aren't any considerations. The nft is transferred without asking for anything in exchange for it
|
||||
),
|
||||
base_sales_buy_null_values AS (
|
||||
SELECT
|
||||
@ -767,6 +766,18 @@ mao_orderhash AS (
|
||||
FROM
|
||||
base_sales_buy_sale_amount_filter
|
||||
)
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
event_index,
|
||||
NULL AS currency_address,
|
||||
0 AS sale_amount_raw_,
|
||||
0 AS platform_fee_raw_,
|
||||
0 AS creator_fee_raw_
|
||||
FROM
|
||||
base_sales_buy
|
||||
WHERE
|
||||
tx_type IS NULL
|
||||
),
|
||||
base_sales_buy_sale_amount_combined AS (
|
||||
SELECT
|
||||
@ -1530,7 +1541,7 @@ mao_orderhash AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
token_type,
|
||||
nft_address,
|
||||
nft_address AS nft_address_temp,
|
||||
tokenid AS tokenId,
|
||||
erc1155_value,
|
||||
IFF(
|
||||
@ -1565,7 +1576,7 @@ mao_orderhash AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
token_type,
|
||||
nft_address,
|
||||
nft_address AS nft_address_temp,
|
||||
tokenid AS tokenId,
|
||||
erc1155_value,
|
||||
IFF(
|
||||
@ -1600,7 +1611,7 @@ mao_orderhash AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
token_type,
|
||||
nft_address,
|
||||
nft_address AS nft_address_temp,
|
||||
tokenId,
|
||||
erc1155_value,
|
||||
IFF(
|
||||
@ -1641,6 +1652,49 @@ mao_orderhash AS (
|
||||
base_sales_buy_and_offer
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) :: DATE - 1
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
nft_transfer_operator AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
contract_address AS nft_address_from_transfers,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS nft_address_temp,
|
||||
--or operator_address
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS offerer,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS recipient,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: STRING AS tokenid,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
)
|
||||
) AS erc1155_value
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
block_timestamp :: DATE >= '2022-06-01'
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
DISTINCT tx_hash
|
||||
FROM
|
||||
base_sales_buy_and_offer
|
||||
)
|
||||
AND topics [0] :: STRING IN (
|
||||
'0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',
|
||||
'0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
@ -1676,7 +1730,11 @@ final_seaport AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
s.token_type,
|
||||
s.nft_address,
|
||||
s.nft_address_temp,
|
||||
CASE
|
||||
WHEN nft_address_from_transfers IS NOT NULL THEN nft_address_from_transfers
|
||||
ELSE s.nft_address_temp
|
||||
END AS nft_address,
|
||||
s.tokenId,
|
||||
s.erc1155_value,
|
||||
s.currency_address,
|
||||
@ -1705,7 +1763,7 @@ final_seaport AS (
|
||||
offer,
|
||||
input_data,
|
||||
CONCAT(
|
||||
s.nft_address,
|
||||
nft_address,
|
||||
'-',
|
||||
s.tokenId,
|
||||
'-',
|
||||
@ -1717,8 +1775,13 @@ final_seaport AS (
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
base_sales_buy_and_offer s
|
||||
INNER JOIN tx_data t
|
||||
ON t.tx_hash = s.tx_hash qualify(ROW_NUMBER() over(PARTITION BY nft_log_id
|
||||
INNER JOIN tx_data t USING (tx_hash)
|
||||
LEFT JOIN nft_transfer_operator o USING (
|
||||
tx_hash,
|
||||
nft_address_temp,
|
||||
tokenid,
|
||||
recipient
|
||||
) qualify(ROW_NUMBER() over(PARTITION BY nft_log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
)
|
||||
|
||||
@ -523,8 +523,7 @@ mao_orderhash AS (
|
||||
tx_hash
|
||||
FROM
|
||||
filtered_private_offer_tx
|
||||
)
|
||||
AND tx_type IS NOT NULL
|
||||
) -- AND tx_type IS NOT NULL ; null tx type would mean that there aren't any considerations. The nft is transferred without asking for anything in exchange for it
|
||||
),
|
||||
base_sales_buy_null_values AS (
|
||||
SELECT
|
||||
@ -767,6 +766,18 @@ mao_orderhash AS (
|
||||
FROM
|
||||
base_sales_buy_sale_amount_filter
|
||||
)
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
event_index,
|
||||
NULL AS currency_address,
|
||||
0 AS sale_amount_raw_,
|
||||
0 AS platform_fee_raw_,
|
||||
0 AS creator_fee_raw_
|
||||
FROM
|
||||
base_sales_buy
|
||||
WHERE
|
||||
tx_type IS NULL
|
||||
),
|
||||
base_sales_buy_sale_amount_combined AS (
|
||||
SELECT
|
||||
@ -1530,7 +1541,7 @@ mao_orderhash AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
token_type,
|
||||
nft_address,
|
||||
nft_address AS nft_address_temp,
|
||||
tokenid AS tokenId,
|
||||
erc1155_value,
|
||||
IFF(
|
||||
@ -1565,7 +1576,7 @@ mao_orderhash AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
token_type,
|
||||
nft_address,
|
||||
nft_address AS nft_address_temp,
|
||||
tokenid AS tokenId,
|
||||
erc1155_value,
|
||||
IFF(
|
||||
@ -1600,7 +1611,7 @@ mao_orderhash AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
token_type,
|
||||
nft_address,
|
||||
nft_address AS nft_address_temp,
|
||||
tokenId,
|
||||
erc1155_value,
|
||||
IFF(
|
||||
@ -1641,6 +1652,49 @@ mao_orderhash AS (
|
||||
base_sales_buy_and_offer
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) :: DATE - 1
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
nft_transfer_operator AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
contract_address AS nft_address_from_transfers,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS nft_address_temp,
|
||||
--or operator_address
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS offerer,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS recipient,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: STRING AS tokenid,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
)
|
||||
) AS erc1155_value
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
block_timestamp :: DATE >= '2022-06-01'
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
DISTINCT tx_hash
|
||||
FROM
|
||||
base_sales_buy_and_offer
|
||||
)
|
||||
AND topics [0] :: STRING IN (
|
||||
'0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',
|
||||
'0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
@ -1676,7 +1730,11 @@ final_seaport AS (
|
||||
ZONE,
|
||||
tx_type,
|
||||
s.token_type,
|
||||
s.nft_address,
|
||||
s.nft_address_temp,
|
||||
CASE
|
||||
WHEN nft_address_from_transfers IS NOT NULL THEN nft_address_from_transfers
|
||||
ELSE s.nft_address_temp
|
||||
END AS nft_address,
|
||||
s.tokenId,
|
||||
s.erc1155_value,
|
||||
s.currency_address,
|
||||
@ -1705,7 +1763,7 @@ final_seaport AS (
|
||||
offer,
|
||||
input_data,
|
||||
CONCAT(
|
||||
s.nft_address,
|
||||
nft_address,
|
||||
'-',
|
||||
s.tokenId,
|
||||
'-',
|
||||
@ -1717,8 +1775,13 @@ final_seaport AS (
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
base_sales_buy_and_offer s
|
||||
INNER JOIN tx_data t
|
||||
ON t.tx_hash = s.tx_hash qualify(ROW_NUMBER() over(PARTITION BY nft_log_id
|
||||
INNER JOIN tx_data t USING (tx_hash)
|
||||
LEFT JOIN nft_transfer_operator o USING (
|
||||
tx_hash,
|
||||
nft_address_temp,
|
||||
tokenid,
|
||||
recipient
|
||||
) qualify(ROW_NUMBER() over(PARTITION BY nft_log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user