Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Magic Eden Ethereum & Polygon fees #5469

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,35 @@ WITH trades AS (
{% endif %}
)

, bundled_whitelisted_trades AS (
SELECT block_number
, tx_hash
, array_agg(seller) AS sellers
FROM whitelisted_trades
GROUP BY 1, 2
)

, fees AS (
SELECT tr.block_number
, tr.tx_hash
, contract_address
, 0xca9337244b5f04cb946391bc8b8a980e988f9a6a AS platform_fee_address
, MAX_BY(tr.to, tr.amount_raw) FILTER (WHERE to != 0xca9337244b5f04cb946391bc8b8a980e988f9a6a) AS royalty_fee_address
, SUM(tr.amount_raw) FILTER (WHERE to = 0xca9337244b5f04cb946391bc8b8a980e988f9a6a) AS platform_fee_amount_raw
, SUM(tr.amount_raw) FILTER (WHERE to != 0xca9337244b5f04cb946391bc8b8a980e988f9a6a) AS royalty_fee_amount_raw
FROM tokens_ethereum.transfers tr
INNER JOIN whitelisted_trades wt ON tr.block_number=wt.block_number
INNER JOIN bundled_whitelisted_trades wt ON tr.block_number=wt.block_number
AND tr.tx_hash=wt.tx_hash
AND tr.amount_raw > 0
AND tr."from" = 0x9a1d00bed7cd04bcda516d721a596eb22aac6834
AND tr."to" != wt.seller
AND NOT contains(wt.sellers, tr."to")
AND tr.block_number >= 19242536
{% if is_incremental() %}
WHERE tr.{{incremental_predicate('block_time')}}
{% else %}
WHERE tr.block_time >= {{magiceden_start_date}}
{% endif %}
GROUP BY 1, 2
GROUP BY 1, 2, 3
)

SELECT 'ethereum' as blockchain
Expand Down Expand Up @@ -172,4 +181,5 @@ SELECT 'ethereum' as blockchain
, t.sub_tx_trade_id
FROM whitelisted_trades t
LEFT JOIN fees f ON t.block_number=f.block_number
AND t.tx_hash=f.tx_hash
AND t.tx_hash=f.tx_hash
AND (f.contract_address=t.currency_contract OR (f.contract_address=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee AND t.currency_contract=0x0000000000000000000000000000000000000000))
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,35 @@ WITH trades AS (
{% endif %}
)

, bundled_whitelisted_trades AS (
SELECT block_number
, tx_hash
, array_agg(seller) AS sellers
FROM whitelisted_trades
GROUP BY 1, 2
)

, fees AS (
SELECT tr.block_number
, tr.tx_hash
, contract_address
, 0xca9337244b5f04cb946391bc8b8a980e988f9a6a AS platform_fee_address
, MAX_BY(tr.to, tr.amount_raw) FILTER (WHERE to != 0xca9337244b5f04cb946391bc8b8a980e988f9a6a) AS royalty_fee_address
, SUM(tr.amount_raw) FILTER (WHERE to = 0xca9337244b5f04cb946391bc8b8a980e988f9a6a) AS platform_fee_amount_raw
, SUM(tr.amount_raw) FILTER (WHERE to != 0xca9337244b5f04cb946391bc8b8a980e988f9a6a) AS royalty_fee_amount_raw
FROM tokens_polygon.transfers tr
INNER JOIN whitelisted_trades wt ON tr.block_number=wt.block_number
INNER JOIN bundled_whitelisted_trades wt ON tr.block_number=wt.block_number
AND tr.tx_hash=wt.tx_hash
AND tr.amount_raw > 0
AND tr."from" = 0x9a1d00bed7cd04bcda516d721a596eb22aac6834
AND tr."to" != wt.seller
AND NOT contains(wt.sellers, tr."to")
AND tr.block_number >= 19242536
{% if is_incremental() %}
WHERE tr.{{incremental_predicate('block_time')}}
{% else %}
WHERE tr.block_time >= {{magiceden_start_date}}
{% endif %}
GROUP BY 1, 2
GROUP BY 1, 2, 3
)

, base_trades AS (
Expand Down Expand Up @@ -174,6 +183,7 @@ WITH trades AS (
FROM whitelisted_trades t
LEFT JOIN fees f ON t.block_number=f.block_number
AND t.tx_hash=f.tx_hash
AND (f.contract_address=t.currency_contract OR (f.contract_address=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee AND t.currency_contract=0x0000000000000000000000000000000000000000))
)

-- this will be removed once tx_from and tx_to are available in the base event tables
Expand Down
2 changes: 1 addition & 1 deletion models/nft/nft_marketplaces_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FROM (VALUES
, ('quix', 'Quix', 'Direct', NULL)
, ('bluesweep', 'bluesweep', 'Aggregator', 'bluesweep_xyz')
, ('pancakeswap', 'PancakeSwap', 'Direct', 'PancakeSwap')
, ('magiceden', 'MagicEden', 'Direct', 'MagicEden')
, ('magiceden', 'Magic Eden', 'Direct', 'MagicEden')
, ('oxalus', 'Oxalus', 'Aggregator', 'Oxalus_io')
, ('tofu', 'tofuNFT', 'Direct', 'tofuNFT')
, ('skillet', 'Skillet', 'Aggregator', 'SkilletNFT')
Expand Down
Loading