From 244d9c68553e4920c9d1bd15a3f63187fd526c1c Mon Sep 17 00:00:00 2001 From: Alex Weseley Date: Thu, 24 Oct 2024 13:52:06 -0400 Subject: [PATCH] fix edge hour issue --- .../ez_jupiter_perps_price_performance.sql | 2 +- .../jupiter/fact_jupiter_perps_txs.sql | 62 ++++++------------- 2 files changed, 20 insertions(+), 44 deletions(-) diff --git a/models/projects/jupiter/raw/ez_jupiter_perps_price_performance.sql b/models/projects/jupiter/raw/ez_jupiter_perps_price_performance.sql index c357c3bd..159c0df9 100644 --- a/models/projects/jupiter/raw/ez_jupiter_perps_price_performance.sql +++ b/models/projects/jupiter/raw/ez_jupiter_perps_price_performance.sql @@ -16,7 +16,7 @@ with agg as ( m.symbol, CASE when date_part('DOW', convert_timezone('UTC', 'America/New_York', block_timestamp)) IN (0, 6) then 'FALSE' - when convert_timezone('UTC', 'America/New_York', block_timestamp)::time between '09:00:00' and '17:00:00' then 'TRUE' + when convert_timezone('UTC', 'America/New_York', block_timestamp)::time between '09:00:00' and '16:59:59' then 'TRUE' else 'FALSE' END AS nyc_operating_hours FROM {{ ref('fact_jupiter_perps_txs') }} agg diff --git a/models/staging/jupiter/fact_jupiter_perps_txs.sql b/models/staging/jupiter/fact_jupiter_perps_txs.sql index a58be50d..b9e73898 100644 --- a/models/staging/jupiter/fact_jupiter_perps_txs.sql +++ b/models/staging/jupiter/fact_jupiter_perps_txs.sql @@ -24,34 +24,13 @@ with hex_cte as ( and f.value:data is not null and succeeded = 1 ) -, position_events AS ( - SELECT - block_timestamp, - tx_id, - hex_data, - -- First check if transferToken is present (optional parameter) - CASE - WHEN SUBSTRING(hex_data, 618, 1) = '1' THEN 16 - ELSE 0 - END as transfer_token_offset, - -- Check if priceSlippage is present (optional parameter) - CASE - WHEN SUBSTRING(hex_data, - 651 + -- Base offset to priceSlippage flag - CASE WHEN SUBSTRING(hex_data, 601, 1) = '1' THEN 16 ELSE 0 END, -- Add transfer_token offset if present - 1) = '1' THEN 16 - ELSE 0 - END as price_slippage_offset - FROM hex_cte - WHERE SUBSTRING(hex_data, 17, 16) = '409c2b4a6d83107f' -- DecreasePosition event identifier -) , agg as ( SELECT block_timestamp, tx_id, 'inc' as type, PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,582+1,16))/1e6 as size_usd, -- position size fee - PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,680+1,16))/1e6 as fee_usd, --open fee + PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,680+1,16))/1e6 as fees_usd, --open fee PC_DBT_DB.PROD.HEX_TO_BASE58(SUBSTRING(hex_data,454+1,64)) as owner, -- owner/trader address PC_DBT_DB.PROD.HEX_TO_BASE58(SUBSTRING(hex_data,243,64)) as mint, PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,630+1,16))/1e6 as price, @@ -65,31 +44,28 @@ with hex_cte as ( block_timestamp, tx_id, 'dec' as type, - PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data, 585, 16))/1e6 as size_usd, - -- Fee calculation with dynamic offset - PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL( - SUBSTRING( - hex_data, - 667 + -- Base offset to fee - transfer_token_offset + -- Add offset if transferToken present - price_slippage_offset, -- Add offset if priceSlippage present - 16 - ) - )/1e6 as fee_usd, - PC_DBT_DB.PROD.HEX_TO_BASE58(SUBSTRING(hex_data, 457, 64)) as owner, + PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data, 584+1,16))/1e6 as size_usd, --open fee + case when substring(hex_data,1+651,1) = 1 + then PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,1+668,16)) / 1e6 + else PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,1+652,16)) / 1e6 + end as fee_usd, --close fee, has an optional param priceSlippage before it so we need this case when. + PC_DBT_DB.PROD.HEX_TO_BASE58(SUBSTRING(hex_data,456+1,64)) as owner, -- owner/trader address PC_DBT_DB.PROD.HEX_TO_BASE58(SUBSTRING(hex_data,243,64)) as mint, -- Price calculation with dynamic offset PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL( SUBSTRING( hex_data, - 619 + -- Base offset to price - transfer_token_offset, -- Add offset if transferToken present - 16 + 619 -- Base offset to price + + (CASE WHEN SUBSTRING(hex_data, 618, 1) = '1' + THEN 16 + ELSE 0 + END) -- Add offset if transferToken present + , 16 ) - )/1e6 as price, + )/1e6 as price, hex_data - FROM position_events - + FROM hex_cte + WHERE substring(hex_data,1+16,16) = '409c2b4a6d83107f' -- DecreasePosition UNION ALL @@ -102,12 +78,12 @@ with hex_cte as ( PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,1+564,16)) / 1e6 as fee_usd, --close fee PC_DBT_DB.PROD.HEX_TO_BASE58(SUBSTRING(hex_data,1+388,64)) as owner, -- owner/trader address PC_DBT_DB.PROD.HEX_TO_BASE58(SUBSTRING(hex_data,291,64)) as mint, - case when block_timestamp > date('2023-10-16 07:33:16.000') + case when block_timestamp >= date('2023-10-16 07:33:16.000') THEN PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,549,16))/1e6 ELSE PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL(SUBSTRING(hex_data,531,16))/1e6 END as price, - hex_data + hex_data FROM hex_cte WHERE substring(hex_data,1+16,16) IN ('68452084d423bf2f', '806547a880485654') --LiquidatePosition, LiquidateFullPosition ) @@ -117,7 +93,7 @@ SELECT 'solana' as chain, 'jupiter' as app, size_usd, - fee_usd, + fees_usd as fee_usd, owner, mint, price,