From a2c8d3a83b3a7736849731913810e9a363570778 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Mon, 13 Jan 2025 21:04:35 +0000 Subject: [PATCH] Init beets daily spells (#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 --- .../balancer/balancer_bpt_prices_macro.sql | 2 +- .../balancer/balancer_liquidity_macro.sql | 2 +- .../balancer/balancer_protocol_fee_macro.sql | 2 +- ..._token_balance_changes_daily_agg_macro.sql | 2 +- .../models/beets/sonic/beets_bpt_prices.sql | 38 ++ .../models/beets/sonic/beets_bpt_supply.sql | 34 ++ .../beets/sonic/beets_bpt_supply_changes.sql | 39 ++ .../sonic/beets_bpt_supply_changes_daily.sql | 34 ++ .../models/beets/sonic/beets_liquidity.sql | 38 ++ .../beets/sonic/beets_pools_metrics_daily.sql | 82 ++++ .../sonic/beets_pools_tokens_weights.sql | 107 +++++ .../models/beets/sonic/beets_protocol_fee.sql | 38 ++ .../models/beets/sonic/beets_schema.yml | 369 ++++++++++++++++++ .../sonic/beets_token_balance_changes.sql | 36 ++ .../beets_token_balance_changes_daily.sql | 34 ++ .../beets/sonic/beets_transfers_bpt.sql | 36 ++ .../daily_spellbook/_sources.yml | 6 +- sources/_subprojects_outputs/dex/_sources.yml | 2 +- .../hourly_spellbook/_sources.yml | 2 +- 19 files changed, 896 insertions(+), 7 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_prices.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_liquidity.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_pools_metrics_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_pools_tokens_weights.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_protocol_fee.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_token_balance_changes.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_token_balance_changes_daily.sql create mode 100644 dbt_subprojects/daily_spellbook/models/beets/sonic/beets_transfers_bpt.sql diff --git a/dbt_macros/shared/balancer/balancer_bpt_prices_macro.sql b/dbt_macros/shared/balancer/balancer_bpt_prices_macro.sql index 92fae3fa1b5..9a0ad174f84 100644 --- a/dbt_macros/shared/balancer/balancer_bpt_prices_macro.sql +++ b/dbt_macros/shared/balancer/balancer_bpt_prices_macro.sql @@ -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 ), diff --git a/dbt_macros/shared/balancer/balancer_liquidity_macro.sql b/dbt_macros/shared/balancer/balancer_liquidity_macro.sql index 0f893a0f561..0e565086bd5 100644 --- a/dbt_macros/shared/balancer/balancer_liquidity_macro.sql +++ b/dbt_macros/shared/balancer/balancer_liquidity_macro.sql @@ -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 ), diff --git a/dbt_macros/shared/balancer/balancer_protocol_fee_macro.sql b/dbt_macros/shared/balancer/balancer_protocol_fee_macro.sql index eb5f72e13fb..4783a06189a 100644 --- a/dbt_macros/shared/balancer/balancer_protocol_fee_macro.sql +++ b/dbt_macros/shared/balancer/balancer_protocol_fee_macro.sql @@ -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 ), diff --git a/dbt_macros/shared/balancer/balancer_token_balance_changes_daily_agg_macro.sql b/dbt_macros/shared/balancer/balancer_token_balance_changes_daily_agg_macro.sql index 2d177e5d182..d811d198202 100644 --- a/dbt_macros/shared/balancer/balancer_token_balance_changes_daily_agg_macro.sql +++ b/dbt_macros/shared/balancer/balancer_token_balance_changes_daily_agg_macro.sql @@ -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 ), diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_prices.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_prices.sql new file mode 100644 index 00000000000..85cdf31bdf2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_prices.sql @@ -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 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply.sql new file mode 100644 index 00000000000..f21d783be1e --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply.sql @@ -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 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes.sql new file mode 100644 index 00000000000..bb72023ec7f --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes.sql @@ -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 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes_daily.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes_daily.sql new file mode 100644 index 00000000000..36b2e0328fd --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_bpt_supply_changes_daily.sql @@ -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 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_liquidity.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_liquidity.sql new file mode 100644 index 00000000000..bc76b82bc8a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_liquidity.sql @@ -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 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_pools_metrics_daily.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_pools_metrics_daily.sql new file mode 100644 index 00000000000..476e8cc33fd --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_pools_metrics_daily.sql @@ -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 diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_pools_tokens_weights.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_pools_tokens_weights.sql new file mode 100644 index 00000000000..2473176fca0 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_pools_tokens_weights.sql @@ -0,0 +1,107 @@ +{{ + config( + schema='beets', + alias = 'pools_tokens_weights', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +WITH v2 AS( +WITH registered AS ( + SELECT + poolID AS pool_id, + evt_block_time + FROM {{ source('beethoven_x_v2_sonic', 'Vault_evt_PoolRegistered') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('beethoven_x_v2_sonic', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), + +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory +) + +SELECT + 'sonic' AS blockchain, + '2' AS version, + r.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +LEFT JOIN registered r ON BYTEARRAY_SUBSTRING(r.pool_id,1,20) = w.pool_id +WHERE w.pool_id IS NOT NULL), + +v3 AS( +WITH token_data AS ( + SELECT + pool, + ARRAY_AGG(FROM_HEX(json_extract_scalar(token, '$.token')) ORDER BY token_index) AS tokens + FROM ( + SELECT + pool, + tokenConfig, + SEQUENCE(1, CARDINALITY(tokenConfig)) AS token_index_array + FROM {{ source('beethoven_x_v3_sonic', 'Vault_evt_PoolRegistered') }} + ) AS pool_data + CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index) + GROUP BY 1 + ), + +weighted_pool_factory AS ( + SELECT + call_create.output_pool AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('beethoven_x_v3_sonic', 'WeightedPoolFactory_call_create') }} AS call_create + JOIN token_data td ON td.pool = call_create.output_pool + CROSS JOIN UNNEST(td.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), + +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory +) + +SELECT + 'sonic' AS blockchain, + '3' AS version, + w.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +WHERE w.pool_id IS NOT NULL +) + +SELECT * FROM v2 +UNION +SELECT * FROM v3 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_protocol_fee.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_protocol_fee.sql new file mode 100644 index 00000000000..e9267173dfe --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_protocol_fee.sql @@ -0,0 +1,38 @@ +{{ + config( + schema = 'beets', + alias = 'protocol_fee', + materialized = 'table', + file_format = 'delta' + ) +}} + +WITH v2 AS( +{{ + balancer_v2_compatible_protocol_fee_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_protocol_fee_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 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_schema.yml b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_schema.yml new file mode 100644 index 00000000000..60d7c5f5375 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_schema.yml @@ -0,0 +1,369 @@ +version: 2 + +models: + - name: beets_pools_tokens_weights + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'beethoven_x', 'pools', 'tokens', 'weights'] + description: > + Token weights in Beethoven X pools. + columns: + - &blockchain + name: blockchain + description: "Blockchain which the DEX is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + - name: beets_liquidity + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'balancer', 'pools', 'liquidity'] + description: > + Beethoven X pools liquidity by token in sonic. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - name: day + description: 'UTC event block time truncated to the day mark' + - *pool_id + - name: pool_address + - name: pool_symbol + description: 'Symbol of the pool, consisting of the symbol of its tokens and their respective weights' + - name: version + description: "Version of Balancer where the liquidity pool is deployed" + - name: blockchain + description: 'Blockchain in which pool was deployed' + - name: pool_type + - *token_address + - name: token_symbol + description: 'Symbol of the token' + - name: token_balance_raw + description: 'Raw balance of the token in the pool' + - name: token_balance + description: 'Scaled balance of the token in the pool' + - name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' + + - name: beets_protocol_fee + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'revenue', 'fees'] + description: > + Daily Protocol Fee collected and Revenue by pool on Beethoven X, an automated portfolio manager and trading platform built on Balancer. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - name: day + - name: pool_id + - name: pool_address + - name: pool_symbol + - name: blockchain + - name: version + - name: pool_type + - name: token_address + - name: token_symbol + - name: token_amount_raw + description: "Raw amount of revenues of the token in the pool" + - name: token_amount + description: "Amount of revenues of the token in the pool" + - name: protocol_fee_collected_usd + description: "Fee collected in the pool in USD" + - &treasury_share + name: treasury_share + description: "Share of total fee that is directed to Balancer DAO's treasury, as per BIPs 19, 161 and 371" + - &treasury_revenue_usd + name: treasury_revenue_usd + description: "USD value of fee directed to Balancer DAO's treasury" + + - name: beets_bpt_supply + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply for Beethoven X pools built on Balancer. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - name: day + - name: pool_type + - name: blockchain + - name: version + - name: token_address + - name: supply + + - name: beets_bpt_prices + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Beethoven X, an automated portfolio manager and trading platform built on Balancer. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - name: blockchain + - name: version + - name: day + - name: decimals + - name: contract_address + - name: pool_type + - name: bpt_price + + - name: beets_transfers_bpt + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Beethoven X, an automated portfolio manager and trading platform built on Balancer. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - name: blockchain + - name: contract_address + - name: block_date + - name: block_month + - name: evt_tx_hash + - name: evt_index + - name: evt_block_time + - name: evt_block_number + - name: from + - name: to + - name: value + + - name: beets_token_balance_changes + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Beethoven X Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - name: block_date + description: "UTC event block date of each DEX trade" + - name: evt_block_time + description: 'Block time of transfer event' + - name: evt_block_number + description: 'Block number of transfer event' + - name: blockchain + description: "Blockchain" + - name: evt_tx_hash + description: 'Transaction hash of transfer event' + - name: evt_index + description: 'Event index' + - name: pool_id + description: "Unique encoded identifier that refers to each pool" + - name: pool_address + description: "Pool address" + - name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - name: pool_type + description: "Pool attributes, determined by the pool's factory" + - name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - name: token_address + description: "Contract address of the token" + - name: token_symbol + description: "Token symbol" + - name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: beets_token_balance_changes_daily + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Beethoven X Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - name: block_date + - name: pool_id + - name: pool_address + - name: pool_symbol + - name: version + - name: blockchain + - name: pool_type + - name: token_address + - name: token_symbol + - &daily_delta + name: daily_delta + description: "Daily total impact on token balance" + - &daily_delta_usd + name: daily_delta_usd + description: "Daily total impact on token balance, in USD" + - &daily_delta_eth + name: daily_delta_eth + description: "Daily total impact on token balance, in eth" + + - name: beets_bpt_supply_changes + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events on Beethoven X. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - name: block_date + - name: evt_block_time + - name: evt_block_number + - name: blockchain + - name: evt_tx_hash + - name: evt_index + - name: pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - name: version + - &label + name: label + description: "Nature of the transaction (Join/Exit via swap or Mint/Burn via transfer)" + - *token_address + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction on token supply at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction on token supply at the time of execution in the original currency" + + - name: beets_bpt_supply_changes_daily + meta: + blockchain: sonic + project: beethoven_x + contributors: viniabussafi + config: + tags: ['sonic', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events on Beethoven X, grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - name: block_date + - name: blockchain + - name: pool_type + - name: pool_symbol + - name: version + - name: token_address + - name: daily_delta + description: "Daily total impact on BPT supply" + + - name: beets_pools_metrics_daily + meta: + blockchain: sonic + contributors: viniabussafi, metacrypto + config: + tags: ['sonic', 'jelly_swap', 'pool', 'stats', 'volume', 'tvl', 'fee'] + description: > + This spell aggregates data from the trades, liquidity and protocol fees spells, by day and pool, while also displaying some basic information about the pool + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - project + - version + - project_contract_address + columns: + - *blockchain + - name: project + - name: version + - name: block_date + - &project_contract_address + name: project_contract_address + description: "Pool address" + - *pool_symbol + - name: pool_type + - &swap_amount_usd + name: swap_amount_usd + description: "Daily swap volume on a pool, in USD" + - &tvl_usd + name: tvl_usd + description: "Total Value Locked on a pool, in USD" + - &tvl_eth + name: tvl_eth + description: "Total Value Locked on a pool, in eth" + - &fee_amount_usd + name: fee_amount_usd + description: "Daily fees collected on a pool, in USD" \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_token_balance_changes.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_token_balance_changes.sql new file mode 100644 index 00000000000..8a488b178d7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_token_balance_changes.sql @@ -0,0 +1,36 @@ +{{ config( + schema = 'beets', + alias = 'token_balance_changes', + materialized = 'table', + file_format = 'delta' + ) +}} + +WITH v2 AS( +{{ + balancer_v2_compatible_token_balance_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_token_balance_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 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_token_balance_changes_daily.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_token_balance_changes_daily.sql new file mode 100644 index 00000000000..b5bae1d7789 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_token_balance_changes_daily.sql @@ -0,0 +1,34 @@ +{{ + config( + schema = 'beets', + alias = 'token_balance_changes_daily', + materialized = 'table', + file_format = 'delta' + ) +}} + +WITH v2 AS( +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = 'sonic', + version = '2', + project_decoded_as = 'beethoven_x_v2', + base_spells_namespace = 'beets' + ) +}}), + +v3 AS( +{{ + balancer_v3_compatible_token_balance_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 \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_transfers_bpt.sql b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_transfers_bpt.sql new file mode 100644 index 00000000000..4456198f7ec --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/beets/sonic/beets_transfers_bpt.sql @@ -0,0 +1,36 @@ +{{ + config( + schema = 'beets', + alias = 'transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +WITH v2 AS( +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = 'sonic', + version = '2', + project_decoded_as = 'beethoven_x_v2' + ) +}}), + +v3 AS ( +{{ + balancer_v3_compatible_transfers_bpt_macro( + blockchain = 'sonic', + version = '3', + project_decoded_as = 'beethoven_x_v3' + ) +}}) + +SELECT * FROM v2 + +UNION + +SELECT * FROM v3 \ No newline at end of file diff --git a/sources/_subprojects_outputs/daily_spellbook/_sources.yml b/sources/_subprojects_outputs/daily_spellbook/_sources.yml index e086d2254ef..be8ca799747 100644 --- a/sources/_subprojects_outputs/daily_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/daily_spellbook/_sources.yml @@ -41,4 +41,8 @@ sources: - name: ethereum tables: - name: blobs_submissions - \ No newline at end of file + + - name: beets + tables: + - name: pools_metrics_daily + - name: trades \ No newline at end of file diff --git a/sources/_subprojects_outputs/dex/_sources.yml b/sources/_subprojects_outputs/dex/_sources.yml index 1d1d25769a6..bb73d57800e 100644 --- a/sources/_subprojects_outputs/dex/_sources.yml +++ b/sources/_subprojects_outputs/dex/_sources.yml @@ -88,4 +88,4 @@ sources: - name: trades - name: beethoven_x tables: - - name: trades + - name: trades \ No newline at end of file diff --git a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml index ecf970cd3af..a5a273cd1b3 100644 --- a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml @@ -82,4 +82,4 @@ sources: - name: evms tables: - - name: transaction_metrics + - name: transaction_metrics \ No newline at end of file