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

Stablecoin V2: Tron and Ethereum Balances #337

Merged
merged 1 commit into from
Jul 25, 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
67 changes: 65 additions & 2 deletions macros/address_balances/address_balances_by_token.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,61 @@


{% macro address_balances_with_flipside_ez(chain) %}
-- Maker does not use ERC20 DAI tokens in the protocol, instead the amount associated with an addresses is stored in the VAT contract
-- This amount can be transfered to the POT contract(0x197e90f9fad81970ba7976f33cbd77088e5d7cf7) to earn yield on your DAI.
{% if chain in ('ethereum') %}
with
ethereum_maker_vat_dai_debit as (
select
lower('0x197e90f9fad81970ba7976f33cbd77088e5d7cf7') AS address
, lower('0x6B175474E89094C44Da98b954EedeAC495271d0F') AS contract_address
, block_timestamp
, rad::double * 1e18 AS delta
from ethereum_flipside.maker.fact_VAT_move
where dst_address = '0x197e90f9fad81970ba7976f33cbd77088e5d7cf7'
{% if is_incremental() %}
and block_timestamp > (select max(block_timestamp) from {{ this }})
{% endif %}
union all
select
lower('0x197e90f9fad81970ba7976f33cbd77088e5d7cf7') AS address
, lower('0x6B175474E89094C44Da98b954EedeAC495271d0F') AS contract_address
, block_timestamp
, - rad::double * 1e18 AS delta
from ethereum_flipside.maker.fact_VAT_move
where lower(src_address) = lower('0x197e90f9fad81970ba7976f33cbd77088e5d7cf7')
{% if is_incremental() %}
and block_timestamp > (select max(block_timestamp) from {{ this }})
{% endif %}
union all
select
lower('0x197e90f9fad81970ba7976f33cbd77088e5d7cf7') as address
, lower('0x6B175474E89094C44Da98b954EedeAC495271d0F') AS contract_address
, block_timestamp
, rad::double * 1e18 AS delta
from ethereum_flipside.maker.fact_VAT_suck
where lower(v_address) = lower('0x197e90f9fad81970ba7976f33cbd77088e5d7cf7')
{% if is_incremental() %}
and block_timestamp > (select max(block_timestamp) from {{ this }})
{% endif %}
)
, ethereum_maker_vat_dai_balances as (
select address, contract_address, block_timestamp, delta
from ethereum_maker_vat_dai_debit
{% if is_incremental() %}
union all
select
address
, contract_address
, max(block_timestamp) as block_timestamp
, max_by(balance_token, block_timestamp) as delta
from {{this}}
where lower(address) = lower('0x197e90f9fad81970ba7976f33cbd77088e5d7cf7')
and lower(contract_address) = lower('0x6B175474E89094C44Da98b954EedeAC495271d0F')
group by address, contract_address
{% endif %}
)
{% endif %}
select
user_address as address,
case
Expand All @@ -59,7 +114,15 @@
where
to_date(block_timestamp) < to_date(sysdate())
{% if is_incremental() %}
and block_timestamp
>= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
and block_timestamp >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% endif %}
{% if chain in ('ethereum') %}
union all
select
address
, contract_address
, block_timestamp
, sum(delta) over (partition by contract_address, address order by block_timestamp) as balance_token
from ethereum_maker_vat_dai_balances
{% endif %}
{% endmacro %}
4 changes: 3 additions & 1 deletion macros/address_balances/address_credits_allium.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
and block_timestamp
>= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% endif %}

union all
select
to_address as address,
Expand All @@ -37,9 +38,10 @@
{% endif %}
{% if is_incremental() %}
and block_timestamp
>= (select dateadd('day', -7, max(block_timestamp)) from {{ this }})
>= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% endif %}
and to_date(block_timestamp) < to_date(sysdate())
and to_address <> from_address


{% endmacro %}
4 changes: 2 additions & 2 deletions macros/address_balances/address_debits_allium.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
and to_date(block_timestamp) < to_date(sysdate())
{% if is_incremental() %}
and block_timestamp
>= (select dateadd('day', -7, max(block_timestamp)) from {{ this }})
>= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% endif %}
and to_address <> from_address
union all
Expand All @@ -38,7 +38,7 @@
and to_date(block_timestamp) < to_date(sysdate())
{% if is_incremental() %}
and block_timestamp
>= (select dateadd('day', -7, max(block_timestamp)) from {{ this }})
>= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% endif %}
and to_address <> from_address

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ with
ref("ez_arbitrum_stablecoin_metrics_by_address"),
ref("ez_optimism_stablecoin_metrics_by_address"),
ref("ez_avalanche_stablecoin_metrics_by_address"),
ref("ez_ethereum_stablecoin_metrics_by_address"),
ref("ez_polygon_stablecoin_metrics_by_address"),
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{
config(
materialized="incremental",
unique_key=["unique_id"],
unique_key="unique_id",
snowflake_warehouse="BALANCES_LG",
)
}}
Expand Down
2 changes: 1 addition & 1 deletion models/staging/tron/fact_tron_address_debit_by_token.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{
config(
materialized="incremental",
unique_key=["unique_id"],
unique_key="unique_id",
snowflake_warehouse="BALANCES_LG",
)
}}
Expand Down
Loading