Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Celo: Transfers #681

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions models/projects/celo/raw/ez_celo_transfers.sql
Original file line number Diff line number Diff line change
@@ -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 %}
66 changes: 66 additions & 0 deletions models/staging/celo/fact_celo_native_token_transfers.sql
Original file line number Diff line number Diff line change
@@ -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

Loading