From 543f4a35541548535d98f0bc1ef3f583a3ea95a6 Mon Sep 17 00:00:00 2001 From: SebMelendez01 <78228475+SebMelendez01@users.noreply.github.com> Date: Fri, 28 Feb 2025 17:46:48 -0500 Subject: [PATCH] C911: updating stargate pricing data (#870) --- macros/bridge/stargate_OFTReceived.sql | 94 +++++++++++++++++++------ macros/bridge/stargate_OFTSent.sql | 96 ++++++++++++++++++++------ 2 files changed, 145 insertions(+), 45 deletions(-) diff --git a/macros/bridge/stargate_OFTReceived.sql b/macros/bridge/stargate_OFTReceived.sql index d980b2a3..16421c32 100644 --- a/macros/bridge/stargate_OFTReceived.sql +++ b/macros/bridge/stargate_OFTReceived.sql @@ -1,23 +1,77 @@ {% macro stargate_OFTReceived(chain)%} with -{% if chain in ('berachain', 'mantle') %} - prices as ( - select date, coingecko_id, shifted_token_price_usd as price - from {{ ref("fact_coingecko_token_date_adjusted_gold") }} - where date < dateadd(day, -1, to_date(sysdate())) - union - select - dateadd('day', -1, to_date(sysdate())) as date, - token_id as coingecko_id, - token_current_price as price - from {{ ref("fact_coingecko_token_realtime_data") }} - ) -{% else %} - prices as ( - {{ get_multiple_coingecko_price_with_latest(chain) }} - ) -{% endif %} +usdc_prices as ( + select date as date, 'usdc' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'usd-coin' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'usdc' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'usd-coin' +) +, eth_prices as ( + select date as date, 'eth' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'ethereum' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'eth' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'ethereum' +) +, meth_prices as ( + select date as date, 'meth' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'mantle-staked-ether' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'meth' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'mantle-staked-ether' +) +, usdt_prices as ( + select date as date, 'usdt' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'tether' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'usdt' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'tether' +) +, bsc_usd_prices as ( + select date as date, 'bsc-usd' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'binance-peg-busd' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'bsc-usd' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'binance-peg-busd' +) +, prices as ( + select date, symbol, price + from usdc_prices + union all + select date, symbol, price + from eth_prices + union all + select date, symbol, price + from usdt_prices + union all + select date, symbol, price + from bsc_usd_prices + union all + select date, symbol, price + from meth_prices +) {% if chain == 'mantle' %} , events as ( @@ -128,10 +182,6 @@ select case when lower(token_address) in ('0x3894085ef7ff0f0aedf52e2a2704928d1ec074f1', '0xb75d0b03c06a926e488e2659df1a861f860bd3d1') then 1 end ) as price from events -{% if chain in ('berachain', 'mantle') %} - left join prices on block_timestamp::date = prices.date and lower(events.coingecko_id) = lower(prices.coingecko_id) -{% else %} - left join prices on block_timestamp::date = prices.date and lower(prices.contract_address) = lower(token_address) -{% endif %} +left join prices on block_timestamp::date = prices.date and lower(events.symbol) = lower(prices.symbol) where events.block_timestamp < to_date(sysdate()) {% endmacro %} \ No newline at end of file diff --git a/macros/bridge/stargate_OFTSent.sql b/macros/bridge/stargate_OFTSent.sql index ee1002b9..f92ac95a 100644 --- a/macros/bridge/stargate_OFTSent.sql +++ b/macros/bridge/stargate_OFTSent.sql @@ -1,23 +1,76 @@ {% macro stargate_OFTSent(chain)%} - with -{% if chain in ('berachain', 'mantle') %} - prices as ( - select date, coingecko_id, shifted_token_price_usd as price - from {{ ref("fact_coingecko_token_date_adjusted_gold") }} - where date < dateadd(day, -1, to_date(sysdate())) - union - select - dateadd('day', -1, to_date(sysdate())) as date, - token_id as coingecko_id, - token_current_price as price - from {{ ref("fact_coingecko_token_realtime_data") }} - ) -{% else %} - prices as ( - {{ get_multiple_coingecko_price_with_latest(chain) }} - ) -{% endif %} +usdc_prices as ( + select date as date, 'usdc' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'usd-coin' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'usdc' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'usd-coin' +) +, eth_prices as ( + select date as date, 'eth' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'ethereum' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'eth' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'ethereum' +) +, meth_prices as ( + select date as date, 'meth' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'mantle-staked-ether' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'meth' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'mantle-staked-ether' +) +, usdt_prices as ( + select date as date, 'usdt' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'tether' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'usdt' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'tether' +) +, bsc_usd_prices as ( + select date as date, 'bsc-usd' as symbol, shifted_token_price_usd as price + from pc_dbt_db.prod.fact_coingecko_token_date_adjusted_gold + where + coingecko_id = 'binance-peg-busd' + and date < dateadd(day, -1, to_date(sysdate())) + union + select dateadd('day', -1, to_date(sysdate())) as date, 'bsc-usd' as symbol, token_current_price as price + from pc_dbt_db.prod.fact_coingecko_token_realtime_data + where token_id = 'binance-peg-busd' +) +, prices as ( + select date, symbol, price + from usdc_prices + union all + select date, symbol, price + from eth_prices + union all + select date, symbol, price + from usdt_prices + union all + select date, symbol, price + from bsc_usd_prices + union all + select date, symbol, price + from meth_prices +) {% if chain == 'mantle' %} , events as ( select @@ -127,10 +180,7 @@ select case when lower(events.token_address) in ('0x3894085ef7ff0f0aedf52e2a2704928d1ec074f1', '0xb75d0b03c06a926e488e2659df1a861f860bd3d1') then 1 end ) as price from events -{% if chain in ('berachain', 'mantle') %} - left join prices on block_timestamp::date = prices.date and lower(events.coingecko_id) = lower(prices.coingecko_id) -{% else %} - left join prices on block_timestamp::date = prices.date and lower(prices.contract_address) = lower(token_address) -{% endif %} +left join prices on block_timestamp::date = prices.date and lower(events.symbol) = lower(prices.symbol) where events.block_timestamp < to_date(sysdate()) + {% endmacro %} \ No newline at end of file