nft-deal-score/scratch.sql
flipside-kellen 0d06c60c78 updates
2022-02-03 20:35:13 -08:00

41 lines
1.8 KiB
SQL

WITH orders AS (
SELECT tx_id
, block_timestamp AS sale_date
, msg_value:execute_msg:execute_order:order:order:maker_asset:info:nft:token_id AS token_id
, msg_value:execute_msg:execute_order:order:order:maker_asset:info:nft:contract_addr::string AS contract
, msg_value:execute_msg:execute_order:order:order:taker_asset:amount::decimal/pow(10,6) AS price
FROM terra.msgs
WHERE msg_value:contract::string = 'terra1eek0ymmhyzja60830xhzm7k7jkrk99a60q2z2t'
AND tx_status = 'SUCCEEDED'
AND msg_value:execute_msg:execute_order IS NOT NULL
AND contract IN ( '{}' )
), Lorders AS (
SELECT tx_id
, block_timestamp AS sale_date
, msg_value:execute_msg:ledger_proxy:msg:execute_order:order:order:maker_asset:info:nft:token_id AS token_id
, msg_value:execute_msg:ledger_proxy:msg:execute_order:order:order:maker_asset:info:nft:contract_addr::string AS contract
, msg_value:execute_msg:ledger_proxy:msg:execute_order:order:order:taker_asset:amount::decimal/pow(10,6) AS price
FROM terra.msgs
WHERE msg_value:contract::string = 'terra1eek0ymmhyzja60830xhzm7k7jkrk99a60q2z2t'
AND tx_status = 'SUCCEEDED'
AND msg_value:execute_msg:ledger_proxy:msg:execute_order IS NOT NULL
AND contract IN ( '{}' )
), unioned AS (
SELECT * FROM orders
UNION ALL
SELECT * FROM Lorders
)
SELECT CASE
WHEN contract = 'terra1p70x7jkqhf37qa7qm4v23g4u4g8ka4ktxudxa7' THEN 'Levana Dust'
WHEN contract = 'terra1chrdxaef0y2feynkpq63mve0sqeg09acjnp55v' THEN 'Levana Meteors'
WHEN contract = 'terra1k0y373yxqne22pc9g7jvnr4qclpsxtafevtrpg' THEN 'Levana Dragon Eggs'
WHEN contract = 'terra1trn7mhgc9e2wfkm5mhr65p3eu7a2lc526uwny2' THEN 'LunaBulls'
WHEN contract = 'terra103z9cnqm8psy0nyxqtugg6m7xnwvlkqdzm4s4k' THEN 'Galactic Punks'
ELSE 'Other'
END AS collection
, sale_date
, token_id
, tx_id
, price
FROM unioned