-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add solana orca price * Fix syntax * Fix name duplicate * Fix model * Fix synctax * Temp fix * Fix build issue
- Loading branch information
Showing
2 changed files
with
108 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,69 @@ | ||
{{ | ||
config( | ||
schema = 'orca_whirlpool', | ||
alias = 'token_prices', | ||
partition_by = ['block_month'], | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['blockchain', 'contract_address', 'minute'], | ||
pre_hook='{{ enforce_join_distribution("PARTITIONED") }}', | ||
post_hook='{{ expose_spells(\'["solana"]\', | ||
"project", | ||
"orca_whirlpool", | ||
\'["get_nimbus"]\') }}') | ||
}} | ||
|
||
{# { % set project_start_date = '2022-03-10' % } --grabbed min block time from whirlpool_solana.whirlpool_call_swap #} | ||
with | ||
raw_data as ( | ||
SELECT | ||
* | ||
FROM | ||
{{ ref('orca_whirlpool_trades') }} | ||
WHERE 1 = 1 | ||
{% if is_incremental() %} | ||
AND {{ incremental_predicate('block_time') }} | ||
{% else %} | ||
AND block_time >= DATE('2022-03-10') | ||
{% endif %} | ||
), | ||
bought_price as ( | ||
SELECT | ||
token_bought_mint_address as token_mint, | ||
DATE_TRUNC('minute', block_time) AS minute, | ||
SUM(amount_usd) / SUM(token_bought_amount) AS price | ||
FROM raw_data | ||
GROUP BY | ||
1, | ||
2 | ||
), | ||
sold_price as ( | ||
SELECT token_sold_mint_address as token_mint, | ||
DATE_TRUNC('minute', block_time) AS minute, | ||
SUM(amount_usd) / SUM(token_sold_amount) AS price | ||
FROM raw_data | ||
GROUP BY 1, | ||
2 | ||
), | ||
all_trades as ( | ||
SELECT * | ||
FROM bought_price | ||
UNION ALL | ||
SELECT * | ||
FROM sold_price | ||
) | ||
SELECT t1.token_mint as contract_address, | ||
t1.minute as minute, | ||
t2.symbol, | ||
t2.decimals, | ||
'solana' as blockchain, | ||
avg(t1.price) as price, | ||
DATE_TRUNC('month', t1.minute) as block_month | ||
FROM all_trades t1 | ||
JOIN | ||
{{ ref('tokens_solana_fungible') }} t2 ON t1.token_mint = t2.token_mint_address | ||
GROUP BY 1, | ||
2, | ||
3, | ||
4 |
39 changes: 39 additions & 0 deletions
39
models/orca_whirlpool/orca_whirlpool_token_prices_schema.yml
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,39 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: orca_whirlpool_token_prices | ||
meta: | ||
blockchain: solana | ||
contributors: [get_nimbus] | ||
config: | ||
tags: ['solana','dex', 'price'] | ||
description: > | ||
All token price in Orca pool | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- blockchain | ||
- contract_address | ||
- minute | ||
columns: | ||
- &blockchain | ||
name: blockchain | ||
description: "Blockchain which the DEX is deployed" | ||
- &contract_address | ||
name: contract_address | ||
description: "contract_address of token" | ||
- &minute | ||
name: minute | ||
description: "Time of price in minute" | ||
- &block_month | ||
name: block_month | ||
description: "UTC event block month of each DEX trade" | ||
- &symbol | ||
name: symbol | ||
description: "Token symbol" | ||
- &decimals | ||
name: decimals | ||
description: "Token decimals" | ||
- &price | ||
name: price | ||
description: "Token price" |