Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init beets daily spells #7430

Merged
merged 31 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
234f929
init beets dex models
viniabussafi Dec 30, 2024
e88f5c7
fix
viniabussafi Dec 30, 2024
5cc0dd9
fix schema
viniabussafi Dec 30, 2024
3715a3e
again
viniabussafi Dec 30, 2024
30f357d
fix typo
viniabussafi Dec 30, 2024
8f9122b
fix copypasta
viniabussafi Dec 30, 2024
aab6ab0
add sonic base trades
viniabussafi Dec 30, 2024
62a03db
adjust macro
viniabussafi Dec 30, 2024
5f8f393
fix schema
viniabussafi Dec 30, 2024
1f0c063
Merge branch 'main' into beetsdexspells
viniabussafi Jan 3, 2025
b4f9d99
Update beets_sonic_base_trades_seed.csv
viniabussafi Jan 3, 2025
acbc7cb
add version column
viniabussafi Jan 3, 2025
3d51323
lighter rerun
viniabussafi Jan 3, 2025
8e3678c
fix comment
viniabussafi Jan 3, 2025
3865874
again
viniabussafi Jan 3, 2025
ebae72e
update dex_info
viniabussafi Jan 3, 2025
771bfc3
init beets daily_spellbook spells
viniabussafi Jan 7, 2025
2e99d51
Merge branch 'main' into beetsdailyspells
viniabussafi Jan 9, 2025
db5b809
Update beets_sonic_base_trades_seed.csv
viniabussafi Jan 9, 2025
aabd3cc
fix source
viniabussafi Jan 9, 2025
c26cc62
update sources and token whitelist for pricing
viniabussafi Jan 9, 2025
ea68dc1
again
viniabussafi Jan 9, 2025
0f52519
again
viniabussafi Jan 9, 2025
c1cb016
again
viniabussafi Jan 9, 2025
d94155f
update macros to allow cros subproject spells
viniabussafi Jan 9, 2025
63f8294
broken ref
viniabussafi Jan 9, 2025
47b9509
fix column
viniabussafi Jan 9, 2025
ea7f5da
Update beets_sonic_base_trades_seed.csv
viniabussafi Jan 13, 2025
b4304bf
Merge branch 'main' into beetsdailyspells
viniabussafi Jan 13, 2025
2bfc990
merge source changes on single file
viniabussafi Jan 13, 2025
b35fc69
again
viniabussafi Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dbt_macros/shared/balancer/balancer_bpt_prices_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ WITH pool_labels AS (
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
DATE_TRUNC ('day', next_change) AS next_change
FROM {{ ref('balancer_v3_erc4626_token_prices') }}
FROM {{ source('balancer_v3' , 'erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
),
Expand Down
2 changes: 1 addition & 1 deletion dbt_macros/shared/balancer/balancer_liquidity_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ WITH pool_labels AS (
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
DATE_TRUNC ('day', next_change) AS next_change
FROM {{ ref('balancer_v3_erc4626_token_prices') }}
FROM {{ source('balancer_v3' , 'erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
),
Expand Down
2 changes: 1 addition & 1 deletion dbt_macros/shared/balancer/balancer_protocol_fee_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ WITH pool_labels AS (
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
DATE_TRUNC ('day', next_change) AS next_change
FROM {{ ref('balancer_v3_erc4626_token_prices') }}
FROM {{ source('balancer_v3' , 'erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ WITH
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
DATE_TRUNC ('day', next_change) AS next_change
FROM {{ ref('balancer_v3_erc4626_token_prices') }}
FROM {{ source('balancer_v3' , 'erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
),
Expand Down
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
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
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
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
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
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
Loading
Loading