Skip to content

Commit

Permalink
adding tvl so ref supportsDEXes (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwes authored Nov 5, 2024
1 parent de513f1 commit d23f17f
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
15 changes: 15 additions & 0 deletions models/projects/ref_finance/__ref_finance_source__.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sources:
- name: NEAR_FLIPSIDE
schema: DEFI
database: NEAR_FLIPSIDE
tables:
- name: ez_dex_swaps

- name: DEFILLAMA
schema: PROD
database: PC_DBT_DB
tables:
- name: fact_defillama_protocol_fees
- name: fact_defillama_protocol_revenue
- name: fact_defillama_protocols
- name: fact_defillama_protocol_tvls
18 changes: 18 additions & 0 deletions models/projects/ref_finance/fact_ref_finance_dau_txns_volume.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{
config(
materialized = 'table',
snowflake_warehouse = 'REF_FINANCE',
unique_key = ['date']
)
}}

select
date(block_timestamp) as date,
count(distinct(concat(tx_hash, swap_index))) as daily_swaps,
count(distinct(trader)) as unique_traders,
SUM(CASE
WHEN amount_out_usd >= amount_in_usd * 10 THEN amount_in_usd
ELSE amount_out_usd
END) AS volume
from {{ source('NEAR_FLIPSIDE', 'ez_dex_swaps') }}
group by 1
22 changes: 22 additions & 0 deletions models/projects/ref_finance/fact_ref_finance_fees_revs_tvl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{
config(
materialized = 'table',
snowflake_warehouse = 'REF_FINANCE',
unique_key = ['date']
)
}}

select
t.date,
p.name,
p.symbol,
f.fees,
r.revenue,
t.tvl
from
{{ source('DEFILLAMA', 'fact_defillama_protocol_tvls') }} t
left join {{ source('DEFILLAMA', 'fact_defillama_protocol_revenue') }} r on t.date = r.date and t.defillama_protocol_id = r.defillama_protocol_id
left join {{ source('DEFILLAMA', 'fact_defillama_protocol_fees') }} f on f.date = t.date and f.defillama_protocol_id = t.defillama_protocol_id
join {{ source('DEFILLAMA', 'fact_defillama_protocols') }} p on t.defillama_protocol_id = p.id
and name = 'Ref Finance'

48 changes: 48 additions & 0 deletions models/staging/ref_finance/core/ez_ref_finance_metrics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{
config(
materialized = 'table',
snowflake_warehouse = 'REF_FINANCE',
unique_key = ['date'],
alias = 'ez_metrics',
schema = 'core',
database = 'REF_FINANCE'
)
}}

with fees_revs_tvl as (
select
date,
fees,
revenue,
tvl
from {{ ref('fact_ref_finance_fees_revs_tvl') }}
)
, dau_txns_volume as(
select
date,
daily_swaps,
unique_traders,
volume
from {{ ref('fact_ref_finance_dau_txns_volume') }}
), price as (
{{ get_coingecko_metrics('ref-finance') }}
)

select
f.date as date,
f.fees as trading_fees,
f.revenue,
f.tvl,
d.daily_swaps,
d.unique_traders,
d.volume as trading_volume,
p.price,
p.market_cap,
p.fdmc,
p.token_turnover_circulating,
p.token_turnover_fdv,
p.token_volume
from fees_revs_tvl f
left join price p on f.date = p.date
left join dau_txns_volume d on d.date = f.date
where d.date < to_date(sysdate())
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{
config(
materialized = 'view',
snowflake_warehouse = 'REF_FINANCE',
unique_key = ['date'],
alias = 'ez_metrics_by_chain',
schema = 'core',
database = 'REF_FINANCE'
)
}}

select
date,
'near' as chain,
trading_fees,
revenue,
tvl,
daily_swaps,
unique_traders,
trading_volume,
price,
market_cap,
fdmc,
token_turnover_circulating,
token_turnover_fdv,
token_volume
from {{ref('ez_ref_finance_metrics')}}
where date < to_date(sysdate())

0 comments on commit d23f17f

Please sign in to comment.