forked from duneanalytics/spellbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init beets daily spells (duneanalytics#7430)
* init beets dex models * fix * fix schema * again * fix typo * fix copypasta * add sonic base trades * adjust macro * fix schema * Update beets_sonic_base_trades_seed.csv * add version column * lighter rerun * fix comment * again * update dex_info * init beets daily_spellbook spells * Update beets_sonic_base_trades_seed.csv * fix source * update sources and token whitelist for pricing * again * again * again * update macros to allow cros subproject spells * broken ref * fix column * Update beets_sonic_base_trades_seed.csv * merge source changes on single file * again
- Loading branch information
1 parent
3ff237d
commit a2c8d3a
Showing
19 changed files
with
896 additions
and
7 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
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
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
38 changes: 38 additions & 0 deletions
38
dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_prices.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,38 @@ | ||
{{ | ||
config( | ||
schema = 'beets', | ||
alias = 'bpt_prices', | ||
materialized = 'table', | ||
file_format = 'delta' | ||
) | ||
}} | ||
|
||
|
||
WITH v2 AS( | ||
{{ | ||
balancer_v2_compatible_bpt_prices_macro( | ||
blockchain = 'sonic', | ||
version = '2', | ||
project_decoded_as = 'beethoven_x_v2', | ||
base_spells_namespace = 'beets', | ||
pool_labels_spell = ref('labels_beets_pools_sonic') | ||
) | ||
}}), | ||
|
||
v3 AS( | ||
{{ | ||
balancer_v3_compatible_bpt_prices_macro( | ||
blockchain = 'sonic', | ||
version = '3', | ||
project_decoded_as = 'beethoven_x_v3', | ||
base_spells_namespace = 'beets', | ||
pool_labels_spell = ref('labels_beets_pools_sonic') | ||
) | ||
}} | ||
) | ||
|
||
SELECT * FROM v2 | ||
|
||
UNION | ||
|
||
SELECT * FROM v3 |
34 changes: 34 additions & 0 deletions
34
dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply.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,34 @@ | ||
{{ config( | ||
schema = 'beets', | ||
alias = 'bpt_supply', | ||
materialized = 'table', | ||
file_format = 'delta' | ||
) | ||
}} | ||
|
||
WITH v2 AS( | ||
{{ | ||
balancer_v2_compatible_bpt_supply_macro( | ||
blockchain = 'sonic', | ||
version = '2', | ||
project_decoded_as = 'beethoven_x_v2', | ||
base_spells_namespace = 'beets', | ||
pool_labels_spell = ref('labels_beets_pools_sonic') | ||
) | ||
}}), | ||
|
||
v3 AS({{ | ||
balancer_v3_compatible_bpt_supply_macro( | ||
blockchain = 'sonic', | ||
version = '3', | ||
project_decoded_as = 'beethoven_x_v3', | ||
base_spells_namespace = 'beets', | ||
pool_labels_spell = ref('labels_beets_pools_sonic') | ||
) | ||
}}) | ||
|
||
SELECT * FROM v2 | ||
|
||
UNION | ||
|
||
SELECT * FROM v3 |
39 changes: 39 additions & 0 deletions
39
dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes.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,39 @@ | ||
{{ | ||
config( | ||
schema = 'beets_sonic', | ||
alias = 'bpt_supply_changes', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['block_date', 'evt_tx_hash', 'evt_index', 'label'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] | ||
) | ||
}} | ||
|
||
WITH v2 AS( | ||
{{ | ||
balancer_v2_compatible_bpt_supply_changes_macro( | ||
blockchain = 'sonic', | ||
version = '2', | ||
project_decoded_as = 'beethoven_x_v2', | ||
base_spells_namespace = 'beets', | ||
pool_labels_spell = ref('labels_beets_pools_sonic') | ||
) | ||
}}), | ||
|
||
v3 AS( | ||
{{ | ||
balancer_v3_compatible_bpt_supply_changes_macro( | ||
blockchain = 'sonic', | ||
version = '3', | ||
project_decoded_as = 'beethoven_x_v3', | ||
base_spells_namespace = 'beets', | ||
pool_labels_spell = ref('labels_beets_pools_sonic') | ||
) | ||
}}) | ||
|
||
SELECT * FROM v2 | ||
|
||
UNION | ||
|
||
SELECT * FROM v3 |
34 changes: 34 additions & 0 deletions
34
dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes_daily.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,34 @@ | ||
{{ | ||
config( | ||
schema = 'beets_sonic', | ||
alias = 'bpt_supply_changes_daily', | ||
materialized = 'table', | ||
file_format = 'delta' | ||
) | ||
}} | ||
|
||
WITH v2 AS( | ||
{{ | ||
balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( | ||
blockchain = 'sonic', | ||
version = '2', | ||
project_decoded_as = 'beethoven_x_v2', | ||
base_spells_namespace = 'beets' | ||
) | ||
}}), | ||
|
||
v3 AS( | ||
{{ | ||
balancer_v3_compatible_bpt_supply_changes_daily_agg_macro( | ||
blockchain = 'sonic', | ||
version = '3', | ||
project_decoded_as = 'beethoven_x_v3', | ||
base_spells_namespace = 'beets' | ||
) | ||
}}) | ||
|
||
SELECT * FROM v2 | ||
|
||
UNION | ||
|
||
SELECT * FROM v3 |
38 changes: 38 additions & 0 deletions
38
dbt_subprojects/daily_spellbook/models/beets/sonic/beets_liquidity.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,38 @@ | ||
{% set blockchain = 'sonic' %} | ||
|
||
{{ | ||
config( | ||
schema = 'beets', | ||
alias = 'liquidity', | ||
materialized = 'table', | ||
file_format = 'delta' | ||
) | ||
}} | ||
|
||
WITH v2 AS( | ||
{{ | ||
balancer_v2_compatible_liquidity_macro( | ||
blockchain = blockchain, | ||
version = '2', | ||
project_decoded_as = 'beethoven_x_v2', | ||
base_spells_namespace = 'beets', | ||
pool_labels_spell = ref('labels_beets_pools_sonic') | ||
) | ||
}}), | ||
|
||
v3 AS( | ||
{{ | ||
balancer_v3_compatible_liquidity_macro( | ||
blockchain = blockchain, | ||
version = '3', | ||
project_decoded_as = 'beethoven_x_v3', | ||
base_spells_namespace = 'beets', | ||
pool_labels_spell = ref('labels_beets_pools_sonic') | ||
) | ||
}}) | ||
|
||
SELECT * FROM v2 | ||
|
||
UNION | ||
|
||
SELECT * FROM v3 |
82 changes: 82 additions & 0 deletions
82
dbt_subprojects/daily_spellbook/models/beets/sonic/beets_pools_metrics_daily.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,82 @@ | ||
{{ config( | ||
schema = 'beets', | ||
alias = 'pools_metrics_daily', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['block_date', 'blockchain', 'project', 'version', 'project_contract_address'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')], | ||
post_hook='{{ expose_spells(blockchains = \'["sonic"]\', | ||
spell_type = "project", | ||
spell_name = "beets", | ||
contributors = \'["viniabussafi"]\') }}' | ||
) | ||
}} | ||
|
||
|
||
WITH | ||
trades AS( | ||
SELECT | ||
block_date, | ||
version, | ||
blockchain, | ||
project_contract_address, | ||
sum(amount_usd) AS swap_amount_usd | ||
FROM {{ source('beets', 'trades') }} | ||
{% if is_incremental() %} | ||
WHERE {{incremental_predicate('block_date')}} | ||
{% endif %} | ||
GROUP BY 1, 2, 3, 4 | ||
), | ||
|
||
liquidity AS( | ||
SELECT | ||
day AS block_date, | ||
blockchain, | ||
version, | ||
pool_address AS project_contract_address, | ||
pool_type, | ||
pool_symbol, | ||
sum(pool_liquidity_usd) AS tvl_usd, | ||
sum(pool_liquidity_eth) AS tvl_eth | ||
FROM {{ ref('beets_liquidity') }} | ||
{% if is_incremental() %} | ||
WHERE {{incremental_predicate('day')}} | ||
{% endif %} | ||
GROUP BY 1, 2, 3, 4, 5, 6 | ||
), | ||
|
||
fees AS( | ||
SELECT | ||
day, | ||
version, | ||
blockchain, | ||
pool_address, | ||
sum(protocol_fee_collected_usd) AS fee_amount_usd | ||
FROM {{ ref('beets_protocol_fee') }} | ||
{% if is_incremental() %} | ||
WHERE {{incremental_predicate('day')}} | ||
{% endif %} | ||
GROUP BY 1, 2, 3, 4 | ||
) | ||
|
||
SELECT | ||
l.blockchain, | ||
'beets' AS project, | ||
l.version, | ||
l.block_date, | ||
l.project_contract_address, | ||
l.pool_symbol, | ||
l.pool_type, | ||
t.swap_amount_usd, | ||
l.tvl_usd, | ||
l.tvl_eth, | ||
f.fee_amount_usd | ||
FROM liquidity l | ||
LEFT JOIN trades t ON l.block_date = t.block_date | ||
AND l.project_contract_address = t.project_contract_address | ||
AND l.blockchain = t.blockchain | ||
LEFT JOIN fees f ON l.block_date = f.day | ||
AND l.project_contract_address = f.pool_address | ||
AND l.blockchain = f.blockchain | ||
ORDER BY 1 DESC, 7 DESC |
Oops, something went wrong.