-
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.
- Loading branch information
1 parent
7c2b4b3
commit 5e2423f
Showing
7 changed files
with
83 additions
and
48 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,30 @@ | ||
{% fact_solana_dex_swaps(protocol) %} | ||
With price as( | ||
select | ||
date | ||
, price | ||
, token_address | ||
from {{ ref("fact_solana_dex_token_prices") }} | ||
) | ||
|
||
select | ||
block_timestamp | ||
, swapper | ||
, inserted_timestamp | ||
, fact_swaps_id | ||
, swap_from_mint | ||
, swap_from_amount | ||
, swap_to_mint | ||
, swap_to_amount | ||
, coalesce(swap_from_amount * from_price.price, 0) as swap_from_amount_usd | ||
, coalesce(swap_to_amount * to_price.price, 0) as swap_to_amount_usd | ||
from solana_flipside.defi.fact_swaps as swaps | ||
left join price as from_price on from_price.date = date_trunc('day', swaps.block_timestamp) and swap_from_mint = from_price.token_address | ||
left join price as to_price on to_price.date = date_trunc('day', swaps.block_timestamp) and swap_to_mint = to_price.token_address | ||
where succeeded and lower(swap_program) like '%{{protocol}}%' | ||
{% if is_incremental() %} | ||
AND block_timestamp::date >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }}) | ||
{% elif protocol == 'raydium' %} | ||
AND block_timestamp::date >= date('2022-04-22') | ||
{% endif %} | ||
{% endmacro %} |
21 changes: 21 additions & 0 deletions
21
macros/decentralized_exchanges/fact_solana_trading_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,21 @@ | ||
{% macro fact_solana_trading_metrics(protocol) %} | ||
select | ||
date_trunc('day', block_timestamp) as date | ||
, sum(coalesce(swap_from_amount_usd, swap_to_amount_usd, 0)) as trading_volume | ||
, count(distinct swapper) as unique_traders | ||
, count(*) as number_of_swaps | ||
from {{ ref("fact_"~protocol~"_trades") }} | ||
where | ||
(swap_from_amount_usd > 0 and swap_to_amount_usd > 0) | ||
and abs( | ||
ln(coalesce(nullif(swap_from_amount_usd, 0), 1)) / ln(10) | ||
- ln(coalesce(nullif(swap_to_amount_usd, 0), 1)) / ln(10) | ||
) < 1 | ||
{% if is_incremental() %} | ||
AND block_timestamp::date >= (select dateadd('day', -3, max(date)) from {{ this }}) | ||
{% else %} | ||
AND block_timestamp::date >= date('2022-04-22') | ||
{% endif %} | ||
group by 1 | ||
order by 1 desc | ||
{% endmacro %} |
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,13 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="ORCA", | ||
database="orca", | ||
schema="core", | ||
alias="ez_metrics_by_chain", | ||
) | ||
}} | ||
|
||
select date,'solana' as chain, 'orca' as protocol, trading_volume, unique_traders, number_of_swaps | ||
from {{ ref("fact_orca_trading_metrics") }} | ||
where date < to_date(sysdate()) |
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,8 @@ | ||
{{ | ||
config( | ||
materialized="incremental", | ||
unique_key="fact_swaps_id", | ||
snowflake_warehouse="ORCA", | ||
) | ||
}} | ||
{{fact_solana_dex_swaps('orca')}} |
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,9 @@ | ||
{{ | ||
config( | ||
materialized="incremental", | ||
unique_key="date", | ||
snowflake_warehouse="ORCA", | ||
) | ||
}} | ||
|
||
{{fact_solana_trading_metrics('orca')}} |
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
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