Skip to content

Commit

Permalink
Stablecoin V2: Celo Stablecoin Supply (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebMelendez01 authored Aug 20, 2024
1 parent 8278be4 commit 9a1e530
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
60 changes: 44 additions & 16 deletions macros/stablecoins/agg_chain_stablecoin_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,53 @@
from fact_{{ chain }}_stablecoin_contracts
)
and transfer_type = 'nep141'

{% elif chain in ("celo") %}
select
block_timestamp,
trunc(block_timestamp, 'day') as date,
block_number,
event_index as index,
transaction_hash as tx_hash,
from_address,
to_address,
from_address = '0x0000000000000000000000000000000000000000'
or lower(from_address) in (
select distinct (lower(premint_address))
from {{ ref("fact_"~chain~"_stablecoin_premint_addresses") }}
)
as is_mint,
to_address = '0x0000000000000000000000000000000000000000'
or lower(to_address) in (
select distinct (lower(premint_address))
from {{ ref("fact_"~chain~"_stablecoin_premint_addresses") }}
)
as is_burn,
amount,
case
when is_mint then amount when is_burn then -1 * amount else 0
end as inflow,
case
when not is_mint and not is_burn then amount else 0
end as transfer_volume,
t1.contract_address,
contracts.symbol
from {{ref("fact_" ~ chain ~ "_token_transfers")}} t1
join {{ref("fact_" ~chain~ "_stablecoin_contracts")}} contracts
on lower(t1.contract_address) = lower(contracts.contract_address)
where lower(t1.contract_address) in (
select lower(contract_address)
from {{ref("fact_" ~chain~ "_stablecoin_contracts")}}
)
-- DO NOT include mint / burn events here - they will be duped
and tx_status = 1
{% else %}
select
block_timestamp,
trunc(block_timestamp, 'day') as date,
block_number,
event_index as index,
{% if chain in ("celo") %}
transaction_hash as tx_hash,
{% else %}
tx_hash,
{% endif %}
tx_hash,
-- Notably, we do NOT use the Mint / Burn events here because the
-- basic IERC20 interface does not require them to be implemented
coalesce(
Expand All @@ -222,7 +258,7 @@
{% if chain in ("ethereum") %}
or lower(from_address) in (
select distinct (lower(premint_address))
from {{ ref("fact_ethereum_stablecoin_premint_addresses") }}
from {{ ref("fact_"~chain~"_stablecoin_premint_addresses") }}
)
{% endif %}
as is_mint,
Expand All @@ -231,7 +267,7 @@
{% if chain in ("ethereum") %}
or lower(to_address) in (
select distinct (lower(premint_address))
from {{ ref("fact_ethereum_stablecoin_premint_addresses") }}
from {{ ref("fact_"~chain~"_stablecoin_premint_addresses") }}
)
{% endif %}
as is_burn,
Expand Down Expand Up @@ -264,11 +300,7 @@
end as transfer_volume,
t1.contract_address,
fact_{{ chain }}_stablecoin_contracts.symbol
{% if chain in ("celo")%}
from {{ref("fact_" ~ chain ~ "_decoded_events")}} t1
{% else %}
from {{ chain }}_flipside.core.ez_decoded_event_logs t1
{% endif %}
from {{ chain }}_flipside.core.ez_decoded_event_logs t1
join
fact_{{ chain }}_stablecoin_contracts
on lower(t1.contract_address)
Expand All @@ -280,11 +312,7 @@
)
-- DO NOT include mint / burn events here - they will be duped
and event_name in ('Transfer', 'Issue', 'Redeem')
{% if chain in ("celo") %}
and tx_status = 1
{% else %}
and tx_status = 'SUCCESS'
{% endif %}
{% endif %}
{% if is_incremental() %}
and block_timestamp >= (
Expand Down
2 changes: 1 addition & 1 deletion macros/stablecoins/stablecoin_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
when lower(address) in (select lower(premint_address) from {{ref("fact_"~chain~"_stablecoin_bridge_addresses")}}) then 0
else stablecoin_supply
end as stablecoin_supply
{% elif chain in ('solana') %}
{% elif chain in ('solana', 'celo') %}
, case
when
lower(address) in (select lower(premint_address) from {{ref("fact_"~chain~"_stablecoin_premint_addresses")}}) then 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{ config(materialized="table") }}
-- Premint addresses for ethereum are representative of USDT that has been bridged to other L2s
select contract_address, premint_address
from
(
values
-- Un-released Supply
(
'0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e',
'0x5754284f345afc66a98fbb0a0afe71e0f007b949'
)
) as results(contract_address, premint_address)

0 comments on commit 9a1e530

Please sign in to comment.