Skip to content

Commit

Permalink
C911: updating stargate pricing data (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebMelendez01 authored Feb 28, 2025
1 parent 6b88892 commit 543f4a3
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 45 deletions.
94 changes: 72 additions & 22 deletions macros/bridge/stargate_OFTReceived.sql
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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 %}
96 changes: 73 additions & 23 deletions macros/bridge/stargate_OFTSent.sql
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 %}

0 comments on commit 543f4a3

Please sign in to comment.