From ba5cc22bc2af2c1fb26ae99c3eb18e090f9ce149 Mon Sep 17 00:00:00 2001 From: SebMelendez01 <78228475+SebMelendez01@users.noreply.github.com> Date: Sun, 15 Dec 2024 21:16:16 -0500 Subject: [PATCH] Celo: Transfers (#681) --- .../projects/celo/raw/ez_celo_transfers.sql | 47 +++++++++++++ .../celo/fact_celo_native_token_transfers.sql | 66 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 models/projects/celo/raw/ez_celo_transfers.sql create mode 100644 models/staging/celo/fact_celo_native_token_transfers.sql diff --git a/models/projects/celo/raw/ez_celo_transfers.sql b/models/projects/celo/raw/ez_celo_transfers.sql new file mode 100644 index 00000000..92dbd8f4 --- /dev/null +++ b/models/projects/celo/raw/ez_celo_transfers.sql @@ -0,0 +1,47 @@ +{{ + config( + materialized="incremental", + snowflake_warehouse="CELO", + database="celo", + schema="raw", + alias="ez_transfers", + ) +}} + +select + block_timestamp, + block_number, + transaction_hash, + index::string as event_index, + origin_from_address, + origin_to_address, + contract_address, + from_address, + to_address, + amount::number as amount, + amount_adjusted, + amount_usd, + tx_status +from {{ref('fact_celo_native_token_transfers')}} +{% if is_incremental() %} + where block_timestamp >= (select max(block_timestamp) from {{ this }}) +{% endif %} +union all +select + block_timestamp, + block_number, + transaction_hash, + event_index::string as event_index, + origin_from_address, + origin_to_address, + contract_address, + from_address, + to_address, + amount::number as amount, + amount_adjusted, + amount_usd, + tx_status +from {{ref('fact_celo_token_transfers')}} +{% if is_incremental() %} + where block_timestamp >= (select max(block_timestamp) from {{ this }}) +{% endif %} \ No newline at end of file diff --git a/models/staging/celo/fact_celo_native_token_transfers.sql b/models/staging/celo/fact_celo_native_token_transfers.sql new file mode 100644 index 00000000..8c3fc3b8 --- /dev/null +++ b/models/staging/celo/fact_celo_native_token_transfers.sql @@ -0,0 +1,66 @@ +{{ + config( + materialized="incremental", + unique_key=["transaction_hash", "index"], + snowflake_warehouse="CELO_LG" + ) +}} +with +prices as ({{get_coingecko_price_with_latest('celo')}}) +, celo_native_transfers as ( + select + t1.block_timestamp, + t1.block_number, + t1.transaction_hash, + trace_address as index, + t2.from_address as origin_from_address, + t2.to_address as origin_to_address, + 'native-token:42220' as contract_address, + t1.from_address, + t1.to_address, + t1.value as amount, + t1.status as tx_status + from {{ ref("fact_celo_traces") }} t1 + left join {{ ref("fact_celo_transactions") }} t2 using(transaction_hash) + where t1.status = 1 + {% if is_incremental() %} + and block_timestamp >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }}) + {% endif %} + union + select distinct + t1.block_timestamp, + t1.block_number, + t1.transaction_hash, + '-1' as index, + t1.from_address as origin_from_address, + t1.to_address as origin_to_address, + 'native-token:42220' as contract_address, + t1.from_address, + t2.miner as to_address, + t1.gas * t1.gas_price as amount, + 1 as tx_status -- Fees are paid whether or not the transaction is successful + from {{ref("fact_celo_transactions")}} t1 + left join {{ref("fact_celo_blocks")}} t2 using (block_number) + where fee_currency is null + {% if is_incremental() %} + and block_timestamp >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }}) + {% endif %} +) +select + block_timestamp, + block_number, + transaction_hash, + index, + origin_from_address, + origin_to_address, + contract_address, + from_address, + to_address, + amount, + amount / pow(10, 18) as amount_adjusted, + amount_adjusted * price as amount_usd, + tx_status +from celo_native_transfers +left join prices on block_timestamp::date = prices.date +where amount is not null and amount > 0 +