Skip to content

Commit

Permalink
updating curve models
Browse files Browse the repository at this point in the history
  • Loading branch information
SebMelendez01 committed Jun 19, 2024
1 parent 9f44594 commit 5b0f10e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
28 changes: 13 additions & 15 deletions macros/decentralized_exchanges/fact_curve_dex_swaps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
where
event_name in ('TokenExchange', 'TokenExchangeUnderlying')
{% if is_incremental() %}
and t1.block_timestamp >= (select max(block_timestamp) from {{ this }})
and t1.block_timestamp >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% endif %}
),
average_token_price_per_day as (
Expand Down Expand Up @@ -117,20 +117,16 @@

t1.token_out,
t2.symbol as token_out_symbol,
coalesce(t1.amount_out, 0) as amount_out,
t1.amount_out, 0 as amount_out,
t2.decimals as token_out_decimals,
coalesce(t2.price, t3.price) as token_out_price,
coalesce(
(amount_out / pow(10, token_out_decimals)) * token_out_price, 0
) as amount_out_usd,
t2.price as token_out_price,
amount_out / pow(10, token_out_decimals) * token_out_price as amount_out_usd,
t1.token_in,
t3.symbol as token_in_symbol,
coalesce(t1.amount_in, 0) as amount_in,
t1.amount_in as amount_in,
t3.decimals as token_in_decimals,
coalesce(t3.price, 0) as token_in_price,
coalesce(
(amount_in / pow(10, token_in_decimals)) * token_in_price, 0
) as amount_in_usd,
t3.price as token_in_price,
amount_in / pow(10, token_in_decimals) * token_in_price as amount_in_usd,
amount_out_usd * t1.swap_fee as trading_fee,
trading_fee * admin_fee as revenue
from pool_events t1
Expand All @@ -144,7 +140,7 @@
and lower(t1.token_in) = lower(t3.token_address)
),
events as (
select
select
block_timestamp,
tx_hash,
event_index,
Expand All @@ -155,7 +151,7 @@
token_out_symbol,
token_in,
token_in_symbol,
least(amount_in_usd, amount_out_usd) as trading_volume,
coalesce(least(amount_in_usd, amount_out_usd), 0) as trading_volume,
trading_fee as trading_fees,
revenue as trading_revenue,
ROW_NUMBER() OVER (PARTITION by tx_hash, pool ORDER BY event_index) AS row_number
Expand All @@ -177,8 +173,7 @@
and substr(t1.input, 0, 10) in ('0x3df02124', '0xa6417ed6')
left join {{ _chain }}_flipside.core.fact_transactions t3 on t1.tx_hash = t3.tx_hash
{% if is_incremental() %}
where t1.block_timestamp
>= (select max(block_timestamp) from {{ this }})
where t1.block_timestamp >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% endif %}
)

Expand Down Expand Up @@ -208,4 +203,7 @@
and events.pool = traces.to_address
and events.row_number = traces.row_number
where events.block_timestamp is not null
{% if is_incremental() %}
and events.block_timestamp >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% endif %}
{% endmacro %}
39 changes: 20 additions & 19 deletions models/staging/curve/dim_curve_pools.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,26 @@ with

select
chain,
app,
max(app) as app,
'DeFi' as category,
pool_type,
registration_address,
max(pool_type) as pool_type,
max(registration_address) as registration_address,
pool_address,
token,
amplification_coefficient,
name,
symbol,
swap_fee,
admin_fee,
mid_fee,
out_fee,
coin_0,
coin_1,
coin_2,
coin_3,
underlying_coin_0,
underlying_coin_1,
underlying_coin_2,
underlying_coin_3
max(token) as token,
max(amplification_coefficient) as amplification_coefficient,
max(name) as name,
max(symbol) as symbol,
max(swap_fee) as swap_fee,
max(admin_fee) as admin_fee,
max(mid_fee) as mid_fee,
max(out_fee) as out_fee,
max(coin_0) as coin_0,
max(coin_1) as coin_1,
max(coin_2) as coin_2,
max(coin_3) as coin_3,
max(underlying_coin_0) as underlying_coin_0,
max(underlying_coin_1) as underlying_coin_1,
max(underlying_coin_2) as underlying_coin_2,
max(underlying_coin_3) as underlying_coin_3
from latest_entry
group by pool_address, chain
2 changes: 1 addition & 1 deletion models/staging/curve/fact_curve_avalanche_dex_swaps.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{
config(
materialized="incremental", unique_key=["tx_hash", "event_index"], snowflake_warehouse="CURVE_SM"
materialized="table", unique_key=["tx_hash", "event_index"], snowflake_warehouse="CURVE_SM"
)
}}
{{ fact_curve_dex_swaps("avalanche") }}
2 changes: 1 addition & 1 deletion models/staging/curve/fact_curve_ethereum_dex_swaps.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{
config(
materialized="incremental", unique_key=["tx_hash", "event_index"], snowflake_warehouse="CURVE_SM"
materialized="table", unique_key=["tx_hash", "event_index"], snowflake_warehouse="CURVE_SM"
)
}}
{{ fact_curve_dex_swaps("ethereum") }}
2 changes: 1 addition & 1 deletion models/staging/curve/fact_curve_optimism_dex_swaps.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{
config(
materialized="incremental", unique_key=["tx_hash", "event_index"], snowflake_warehouse="CURVE_SM"
materialized="table", unique_key=["tx_hash", "event_index"], snowflake_warehouse="CURVE_SM"
)
}}
{{ fact_curve_dex_swaps("optimism") }}
2 changes: 1 addition & 1 deletion models/staging/curve/fact_curve_polygon_dex_swaps.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{
config(
materialized="incremental", unique_key=["tx_hash", "event_index"], snowflake_warehouse="CURVE_SM"
materialized="table", unique_key=["tx_hash", "event_index"], snowflake_warehouse="CURVE_SM"
)
}}
{{ fact_curve_dex_swaps("polygon") }}

0 comments on commit 5b0f10e

Please sign in to comment.