-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tvl so ref supportsDEXes (#589)
- Loading branch information
Showing
5 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
models/projects/ref_finance/fact_ref_finance_dau_txns_volume.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
models/projects/ref_finance/fact_ref_finance_fees_revs_tvl.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
models/staging/ref_finance/core/ez_ref_finance_metrics.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
28 changes: 28 additions & 0 deletions
28
models/staging/ref_finance/core/ez_ref_finance_metrics_by_chain.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |