Skip to content

Commit

Permalink
updating stablecoin pricing for non-usd stablecoins
Browse files Browse the repository at this point in the history
  • Loading branch information
SebMelendez01 committed Aug 22, 2024
1 parent ed9f06d commit 41efc0f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
7 changes: 7 additions & 0 deletions macros/coingecko/avg_coingecko_price_7d.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro avg_l7d_coingecko_price(coingecko_id) %}
select
avg(shifted_token_price_usd) as avg_price_7d
from {{ref("fact_coingecko_token_date_adjusted_gold")}}
where coingecko_id = '{{ coingecko_id }}'
and date >= dateadd('day', -7, to_date(sysdate())::date)
{% endmacro %}
21 changes: 14 additions & 7 deletions macros/p2p/p2p_stablecoin_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,22 @@ with
t1.from_address,
t1.to_address,
t1.amount,
coalesce(
pc_dbt_db.prod.FACT_COINGECKO_TOKEN_DATE_ADJUSTED_GOLD.shifted_token_price_usd * transfer_volume, case when pc_dbt_db.prod.FACT_{{ chain }}_STABLECOIN_CONTRACTS.coingecko_id = 'celo-kenyan-shilling' then 0.0077 else 1 end * transfer_volume
transfer_volume * coalesce(
p.shifted_token_price_usd,
case
when c.coingecko_id = 'euro-coin' then ({{ avg_l7d_coingecko_price('euro-coin') }})
when c.coingecko_id = 'celo-euro' then ({{ avg_l7d_coingecko_price('celo-euro') }})
when c.coingecko_id = 'celo-real-creal' then ({{ avg_l7d_coingecko_price('celo-real-creal') }})
when c.coingecko_id = 'celo-kenyan-shilling' then ({{ avg_l7d_coingecko_price('celo-kenyan-shilling') }})
else 1
end
) as amount_usd
from stablecoin_transfers t1
join pc_dbt_db.prod.FACT_{{ chain }}_STABLECOIN_CONTRACTS
on lower(t1.contract_address) = lower(pc_dbt_db.prod.FACT_{{ chain }}_STABLECOIN_CONTRACTS.contract_address)
left join pc_dbt_db.prod.FACT_COINGECKO_TOKEN_DATE_ADJUSTED_GOLD
on lower(pc_dbt_db.prod.FACT_{{ chain }}_STABLECOIN_CONTRACTS.coingecko_id) = lower(pc_dbt_db.prod.FACT_COINGECKO_TOKEN_DATE_ADJUSTED_GOLD.coingecko_id)
and t1.date = pc_dbt_db.prod.FACT_COINGECKO_TOKEN_DATE_ADJUSTED_GOLD.date
join {{ ref("fact_"~chain~"_stablecoin_contracts") }} c
on lower(t1.contract_address) = lower(c.contract_address)
left join {{ ref("fact_coingecko_token_date_adjusted_gold") }} p
on lower(c.coingecko_id) = lower(p.coingecko_id)
and t1.date = p.date
where not t1.to_address in (select contract_address from distinct_contracts)
and not t1.from_address in (select contract_address from distinct_contracts)
{% if is_incremental() %}
Expand Down
8 changes: 5 additions & 3 deletions macros/stablecoins/stablecoin_balances.sql
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ with
, stablecoin_supply * coalesce(
d.shifted_token_price_usd,
case
when lower(c.coingecko_id) = lower('celo-kenyan-shilling') then 0.0077
else 1
when c.coingecko_id = 'euro-coin' then ({{ avg_l7d_coingecko_price('euro-coin') }})
when c.coingecko_id = 'celo-euro' then ({{ avg_l7d_coingecko_price('celo-euro') }})
when c.coingecko_id = 'celo-real-creal' then ({{ avg_l7d_coingecko_price('celo-real-creal') }})
when c.coingecko_id = 'celo-kenyan-shilling' then ({{ avg_l7d_coingecko_price('celo-kenyan-shilling') }})
else 1
end
) as stablecoin_supply
from historical_supply_by_address_balances st
Expand All @@ -167,5 +170,4 @@ select
, date || '-' || address || '-' || contract_address as unique_id
from stablecoin_balances_with_price
where date < to_date(sysdate())

{% endmacro %}
9 changes: 8 additions & 1 deletion macros/stablecoins/stablecoin_metrics_all.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ with
, stablecoin_metrics.symbol
, from_address
, stablecoin_transfer_volume * coalesce(
d.shifted_token_price_usd, case when c.coingecko_id = 'celo-kenyan-shilling' then 0.0077 else 1 end
d.shifted_token_price_usd,
case
when c.coingecko_id = 'euro-coin' then ({{ avg_l7d_coingecko_price('euro-coin') }})
when c.coingecko_id = 'celo-euro' then ({{ avg_l7d_coingecko_price('celo-euro') }})
when c.coingecko_id = 'celo-real-creal' then ({{ avg_l7d_coingecko_price('celo-real-creal') }})
when c.coingecko_id = 'celo-kenyan-shilling' then ({{ avg_l7d_coingecko_price('celo-kenyan-shilling') }})
else 1
end
) as stablecoin_transfer_volume
, stablecoin_daily_txns
from stablecoin_metrics
Expand Down
15 changes: 14 additions & 1 deletion macros/stablecoins/stablecoin_metrics_artemis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,27 @@ with
from artemis_max_transfer_filter
group by 1, 2, 3, 4
),
eurc_7d_avg as (
select
avg(shifted_token_price_usd) as euro_7d_avg
from {{ ref("fact_coingecko_token_date_adjusted_gold") }}
where coingecko_id = 'eurc'
)
results_dollar_denom as (
select
stablecoin_metrics.date
, stablecoin_metrics.contract_address
, stablecoin_metrics.symbol
, from_address
, stablecoin_transfer_volume * coalesce(
d.shifted_token_price_usd, case when c.coingecko_id = 'celo-kenyan-shilling' then 0.0077 else 1 end
d.shifted_token_price_usd,
case
when c.coingecko_id = 'euro-coin' then ({{ avg_l7d_coingecko_price('euro-coin') }})
when c.coingecko_id = 'celo-euro' then ({{ avg_l7d_coingecko_price('celo-euro') }})
when c.coingecko_id = 'celo-real-creal' then ({{ avg_l7d_coingecko_price('celo-real-creal') }})
when c.coingecko_id = 'celo-kenyan-shilling' then ({{ avg_l7d_coingecko_price('celo-kenyan-shilling') }})
else 1
end
) as stablecoin_transfer_volume
, stablecoin_daily_txns
from stablecoin_metrics
Expand Down

0 comments on commit 41efc0f

Please sign in to comment.