Skip to content

Commit

Permalink
updated fact celo token transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
SebMelendez01 committed Dec 12, 2024
1 parent dd34d06 commit 4712530
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
18 changes: 18 additions & 0 deletions macros/coingecko/get_coingecko_price_with_latest.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,21 @@
from {{ ref("fact_coingecko_token_realtime_data") }}
where token_id = '{{ coingecko_id }}'
{% endmacro %}



{% macro get_multiple_coingecko_price_with_latest(chain) %}
select date as date, contract_address, decimals, symbol, shifted_token_price_usd as price
from {{ ref("fact_coingecko_token_date_adjusted_gold") }}
inner join {{ ref('dim_coingecko_token_map')}}
on coingecko_id = coingecko_token_id
where
chain = '{{ chain }}'
and date < dateadd(day, -1, to_date(sysdate()))
union
select dateadd('day', -1, to_date(sysdate())) as date, contract_address, decimals, symbol, token_current_price as price
from {{ ref("fact_coingecko_token_realtime_data") }}
inner join {{ ref('dim_coingecko_token_map')}}
on token_id = coingecko_token_id
where chain = '{{ chain }}'
{% endmacro %}
13 changes: 13 additions & 0 deletions models/projects/celo/raw/ez_celo_transactions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{
config(
materialized="view",
snowflake_warehouse="CELO",
database="celo",
schema="raw",
alias="ez_transactions",
)
}}

select
*
from {{ref("fact_celo_transactions")}}
22 changes: 21 additions & 1 deletion models/staging/celo/fact_celo_token_transfers.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
{{ config(materialized="incremental", unique_key=["transaction_hash", "event_index"]) }}
with
prices as ({{get_multiple_coingecko_price_with_latest('celo')}})
, celo_token_transfers as ({{ token_transfer_events("celo") }})
select
block_timestamp,
block_number,
transaction_hash,
event_index,
origin_from_address,
origin_to_address,
celo_token_transfers.contract_address,
from_address,
to_address,
amount,
amount / pow(10, decimals) as amount_adjusted,
amount_adjusted * price as amount_usd,
tx_status
from celo_token_transfers
left join prices
on block_timestamp::date = prices.date
and lower(celo_token_transfers.contract_address) = lower(prices.contract_address)

{{ token_transfer_events("celo") }}
21 changes: 21 additions & 0 deletions models/staging/coingecko/dim_coingecko_token_map.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{config(materialized="view")}}
with
max_extraction as (
select max(extraction_date) as max_date
from {{ source("PROD_LANDING", "raw_coingecko_token_metadata") }}
)
select
parse_json(source_json) as json,
json:id::string AS coingecko_token_id,
json:symbol::string AS symbol,
--TODO: Right now chains are coingecko chains, we need to map them to our chains
f.key::string AS chain,
f.value:contract_address::string AS contract_address,
f.value:decimal_place::number AS decimals
from {{ source("PROD_LANDING", "raw_coingecko_token_metadata") }},
lateral flatten(input => parse_json(source_json):detail_platforms) f
where extraction_date = (select max_date from max_extraction) and (
chain <> '' and chain is not null
and contract_address <> '' and chain is not null
and decimals is not null
)

0 comments on commit 4712530

Please sign in to comment.