From 234f929d929d56a78f4c1177b7f39b84188b8082 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 30 Dec 2024 10:49:43 +0000 Subject: [PATCH 01/28] init beets dex models --- .../dex/models/_projects/beets/_schema.yml | 201 ++++++++++++++++++ .../beets/beethoven_x_v2_sonic_pools_fees.sql | 43 ++++ .../beets/beethoven_x_v3_sonic_pools_fees.sql | 30 +++ .../_projects/beets/beets_pools_fees.sql | 35 +++ .../models/_projects/beets/beets_trades.sql | 38 ++++ dbt_subprojects/dex/models/trades/_schema.yml | 4 +- .../dex/models/trades/dex_base_trades.sql | 1 + .../dex/models/trades/dex_trades.sql | 1 + .../dex/models/trades/sonic/_schema.yml | 23 ++ .../trades/sonic/dex_fantom_base_trades.sql | 48 +++++ .../platforms/beets_sonic_base_trades.sql | 42 ++++ .../trades/beets_sonic_base_trades_seed.csv | 2 + 12 files changed, 466 insertions(+), 2 deletions(-) create mode 100644 dbt_subprojects/dex/models/_projects/beets/_schema.yml create mode 100644 dbt_subprojects/dex/models/_projects/beets/beethoven_x_v2_sonic_pools_fees.sql create mode 100644 dbt_subprojects/dex/models/_projects/beets/beethoven_x_v3_sonic_pools_fees.sql create mode 100644 dbt_subprojects/dex/models/_projects/beets/beets_pools_fees.sql create mode 100644 dbt_subprojects/dex/models/_projects/beets/beets_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/sonic/_schema.yml create mode 100644 dbt_subprojects/dex/models/trades/sonic/dex_fantom_base_trades.sql create mode 100644 dbt_subprojects/dex/models/trades/sonic/platforms/beets_sonic_base_trades.sql create mode 100644 dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv diff --git a/dbt_subprojects/dex/models/_projects/beets/_schema.yml b/dbt_subprojects/dex/models/_projects/beets/_schema.yml new file mode 100644 index 00000000000..65ff76451ae --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/beets/_schema.yml @@ -0,0 +1,201 @@ +version: 2 + +models: + - name: beets_sonic_pools_fees + meta: + blockchain: sonic + project: beets + contributors: jacektrocinski, thetroyharris, tomfutago, viniabussafi + config: + tags: ['sonic', 'beets', 'pools_fees'] + description: > + Beets swap fees stored at the pool level. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_number + - tx_hash + - index + columns: + - &blockchain + name: blockchain + description: "Blockchain which the DEX is deployed" + - &contract_address + name: contract_address + description: 'sonic address for the liquidity pool used in transaction' + data_tests: + - not_null + - &tx_hash + name: tx_hash + description: "Unique transaction hash value tied to each transaction on the DEX" + - &index + name: index + description: '' + data_tests: + - not_null + - &tx_index + name: tx_index + description: '' + data_tests: + - not_null + - &block_time + name: block_time + description: "UTC event block time of each DEX trade" + - &block_number + name: block_number + description: 'Block number' + data_tests: + - not_null + - &swap_fee_percentage + name: swap_fee_percentage + description: 'Swap fees for the pool, values are returned with 18 decimals (1e18 meaning 100%)' + data_tests: + - not_null + + - name: beethoven_x_v2_sonic_pools_fees + meta: + blockchain: sonic + project: beets + contributors: viniabussafi + config: + tags: ['sonic', 'beets', 'pools_fees'] + description: > + Beets v2 swap fees stored at the pool level. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_number + - tx_hash + - index + columns: + - *blockchain + - *version + - *contract_address + - *tx_hash + - *index + - *tx_index + - *block_time + - *block_number + - *swap_fee_percentage + + - name: beethoven_x_v3_sonic_pools_fees + meta: + blockchain: sonic + project: beets + contributors: viniabussafi + config: + tags: ['sonic', 'beets', 'pools_fees'] + description: > + Beets v3 swap fees stored at the pool level. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_number + - tx_hash + - index + columns: + - *blockchain + - *version + - *contract_address + - *tx_hash + - *index + - *tx_index + - *block_time + - *block_number + - *swap_fee_percentage + + - name: beets_trades + meta: + blockchain: sonic + sector: dex + contributors: viniabussafi + config: + tags: ['beets', 'sonic', 'amm', 'trades', 'dex'] + description: > + DEX trades on beets on sonic + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - project + - version + - tx_hash + - evt_index + columns: + - *blockchain + - &project + name: project + description: "Project name (balancer)" + - *version + - &block_month + name: block_month + description: "Block month in UTC" + - &block_date + name: block_date + description: "Block date in UTC" + - *block_time + - *block_number + - &token_bought_symbol + name: token_bought_symbol + description: "Token symbol for token bought in the trade" + - &token_sold_symbol + name: token_sold_symbol + description: "Token symbol for token sold in the trade" + - &token_pair + name: token_pair + description: "Token symbol pair for each token involved in the trade" + - &token_bought_amount + name: token_bought_amount + description: "Value of the token bought at time of execution in the original currency" + - &token_sold_amount + name: token_sold_amount + description: "Value of the token sold at time of execution in the original currency" + - &token_bought_amount_raw + name: token_bought_amount_raw + description: "Raw value of the token bought at time of execution in the original currency" + - &token_sold_amount_raw + name: token_sold_amount_raw + description: "Raw value of the token sold at time of execution in the original currency" + - &amount_usd + name: amount_usd + description: "USD value of the trade at time of execution" + - &token_bought_address + name: token_bought_address + description: "Contract address of the token bought" + - &token_sold_address + name: token_sold_address + description: "Contract address of the token sold" + - &taker + name: taker + description: "Address of trader who purchased a token" + - &maker + name: maker + description: "Address of trader who sold a token" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &swap_fee + name: swap_fee + description: 'Swap fee' + - &project_contract_address + name: project_contract_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &tx_hash + name: tx_hash + description: "Tx. Hash" + - &tx_from + name: tx_from + description: "transaction.from" + - &tx_to + name: tx_to + description: "transaction.to" + - &evt_index + name: evt_index + description: 'Event index' \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v2_sonic_pools_fees.sql b/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v2_sonic_pools_fees.sql new file mode 100644 index 00000000000..712f22d57c0 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v2_sonic_pools_fees.sql @@ -0,0 +1,43 @@ +{{ + config( + schema = 'beethoven_x_v2_sonic', + alias = 'pools_fees', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['block_number', 'tx_hash', 'index'], + post_hook='{{ expose_spells(\'["sonic"]\', + "project", + "beethoven_x", + \'["viniabussafi"]\') }}' + )  +}} + +{% set event_signature = '0xa9ba3ffe0b6c366b81232caab38605a0699ad5398d6cce76f91ee809e322dafc' %} +{% set project_start_date = '2024-12-01' %} + + WITH registered_pools AS ( + SELECT + DISTINCT poolAddress AS pool_address + FROM + {{ source ('beethoven_x_v2_sonic', 'Vault_evt_PoolRegistered') }} + ) + SELECT + 'sonic' AS blockchain, + logs.contract_address, + logs.tx_hash, + logs.tx_index, + logs.index, + logs.block_time, + logs.block_number, + CAST(bytearray_to_uint256(bytearray_ltrim(logs.data)) AS DOUBLE) AS swap_fee_percentage + FROM + {{ source ('sonic', 'logs') }} + INNER JOIN registered_pools ON registered_pools.pool_address = logs.contract_address + WHERE logs.topic0 = {{ event_signature }} + {% if not is_incremental() %} + AND logs.block_time >= TIMESTAMP '{{ project_start_date }}' + {% endif %} + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% endif %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v3_sonic_pools_fees.sql b/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v3_sonic_pools_fees.sql new file mode 100644 index 00000000000..84a2b9b0204 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v3_sonic_pools_fees.sql @@ -0,0 +1,30 @@ +{{ + config( + schema = 'beethoven_x_v3_sonic', + alias = 'pools_fees', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['block_number', 'tx_hash', 'index'], + post_hook='{{ expose_spells(\'["sonic"]\', + "project", + "beethoven_x", + \'["viniabussafi"]\') }}' + )  +}} + + SELECT + 'sonic' AS blockchain, + '3' AS version, + pool AS contract_address, + evt_tx_hash AS tx_hash, + evt_index AS tx_index, + evt_index AS index, + evt_block_time AS block_time, + evt_block_number AS block_number, + swapFeePercentage AS swap_fee_percentage + FROM {{ source ('beethoven_x_v3_sonic', 'Vault_evt_SwapFeePercentageChanged') }} + WHERE 1 = 1 + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/beets/beets_pools_fees.sql b/dbt_subprojects/dex/models/_projects/beets/beets_pools_fees.sql new file mode 100644 index 00000000000..6654724a449 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/beets/beets_pools_fees.sql @@ -0,0 +1,35 @@ +{{ config( + schema = 'beets', + alias = 'pools_fees', + post_hook='{{ expose_spells(blockchains = \'["sonic"]\', + spell_type = "project", + spell_name = "beets", + contributors = \'[]"viniabussafi"]\') }}' + ) +}} + +{% set balancer_models = [ + ref('beethoven_x_v2_sonic_pools_fees'), + ref('beethoven_x_v3_sonic_pools_fees') +] %} + + +SELECT * +FROM ( + {% for model in balancer_models %} + SELECT + blockchain + , version + , contract_address + , tx_hash + , index + , tx_index + , block_time + , block_number + , swap_fee_percentage + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/beets/beets_trades.sql b/dbt_subprojects/dex/models/_projects/beets/beets_trades.sql new file mode 100644 index 00000000000..34a7f8fc577 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/beets/beets_trades.sql @@ -0,0 +1,38 @@ +{{ config( + schema = 'beets', + alias = 'trades', + materialized = 'view', + post_hook='{{ expose_spells(blockchains = \'["sonic"]\', + spell_type = "project", + spell_name = "beets", + contributors = \'["viniabussafi"]\') }}' + ) +}} + + +SELECT blockchain + , project + , version + , block_month + , block_date + , block_time + , block_number + , token_bought_symbol + , token_sold_symbol + , token_pair + , token_bought_amount + , token_sold_amount + , token_bought_amount_raw + , token_sold_amount_raw + , amount_usd + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , tx_from + , tx_to + , evt_index +FROM {{ ref('dex_trades') }} +WHERE project = 'beets' \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/_schema.yml b/dbt_subprojects/dex/models/trades/_schema.yml index cb10cfb6b1d..e9422e10aa7 100644 --- a/dbt_subprojects/dex/models/trades/_schema.yml +++ b/dbt_subprojects/dex/models/trades/_schema.yml @@ -4,7 +4,7 @@ models: - name: dex_trades meta: docs_slug: /curated/trading/DEX/dex-trades - blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, kaia, optimism, polygon, scroll, zksync, linea, blast, sei, ronin + blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, kaia, optimism, polygon, scroll, zksync, linea, blast, sei, ronin, sonic sector: dex short_description: The `dex.trades` table captures detailed data on trades executed via decentralized exchanges (DEXs). This table contains a detailed breakdown of trade execution containing one or many trades per transaction. contributors: 0xRob, hosuke, jeff-dude, tomfutago, viniabussafi @@ -102,7 +102,7 @@ models: - name: dex_base_trades meta: - blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, kaia,optimism, polygon, scroll, zksync, linea, blast, sei, ronin + blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, kaia,optimism, polygon, scroll, zksync, linea, blast, sei, ronin, sonic sector: dex contributors: 0xRob, hosuke, jeff-dude, tomfutago, viniabussafi config: diff --git a/dbt_subprojects/dex/models/trades/dex_base_trades.sql b/dbt_subprojects/dex/models/trades/dex_base_trades.sql index 6a5a68bb734..6464ffb67e9 100644 --- a/dbt_subprojects/dex/models/trades/dex_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_base_trades.sql @@ -29,6 +29,7 @@ , ref('dex_ronin_base_trades') , ref('dex_scroll_base_trades') , ref('dex_sei_base_trades') + , ref('dex_sonic_base_trades') , ref('dex_worldchain_base_trades') , ref('dex_zkevm_base_trades') , ref('dex_zksync_base_trades') diff --git a/dbt_subprojects/dex/models/trades/dex_trades.sql b/dbt_subprojects/dex/models/trades/dex_trades.sql index 203df9a845d..037dd961adf 100644 --- a/dbt_subprojects/dex/models/trades/dex_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_trades.sql @@ -26,6 +26,7 @@ , "ronin" , "scroll" , "sei" + , "sonic" , "zkevm" , "zksync" , "zora" diff --git a/dbt_subprojects/dex/models/trades/sonic/_schema.yml b/dbt_subprojects/dex/models/trades/sonic/_schema.yml new file mode 100644 index 00000000000..6b96924ec34 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/sonic/_schema.yml @@ -0,0 +1,23 @@ +version: 2 + +models: + - name: dex_sonic_base_trades + data_tests: + - check_dex_info_relationship + + - name: beets_sonic_base_trades + meta: + blockchain: sonic + sector: dex + project: beets + contributors: viniabussafi + config: + tags: ['sonic', 'dex', 'trades', 'beets'] + description: "beets sonic base trades" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('beets_sonic_base_trades_seed') \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/sonic/dex_fantom_base_trades.sql b/dbt_subprojects/dex/models/trades/sonic/dex_fantom_base_trades.sql new file mode 100644 index 00000000000..bf2a270bfa8 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/sonic/dex_fantom_base_trades.sql @@ -0,0 +1,48 @@ +{{ config( + schema = 'dex_sonic' + , alias = 'base_trades' + , materialized = 'view' + ) +}} + +{% set base_models = [ + ref('beets_sonic_base_trades') +] %} + +WITH base_union AS ( + SELECT * + FROM ( + {% for base_model in base_models %} + SELECT + blockchain + , project + , version + , block_month + , block_date + , block_time + , block_number + , token_bought_amount_raw + , token_sold_amount_raw + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , evt_index + FROM + {{ base_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) +) + +{{ + add_tx_columns( + model_cte = 'base_union' + , blockchain = 'sonic' + , columns = ['from', 'to', 'index'] + ) +}} diff --git a/dbt_subprojects/dex/models/trades/sonic/platforms/beets_sonic_base_trades.sql b/dbt_subprojects/dex/models/trades/sonic/platforms/beets_sonic_base_trades.sql new file mode 100644 index 00000000000..f2312ce592e --- /dev/null +++ b/dbt_subprojects/dex/models/trades/sonic/platforms/beets_sonic_base_trades.sql @@ -0,0 +1,42 @@ +{{ + config( + schema = 'beets_sonic', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + + +WITH v2_trades AS( + {{ + balancer_compatible_v2_trades( + blockchain = 'sonic', + project = 'beets', + version = '2', + project_decoded_as = 'beethoven_x_v2', + Vault_evt_Swap = 'Vault_evt_Swap', + pools_fees = 'pools_fees' + ) +}}), + +v3_trades AS( + {{ + balancer_compatible_v3_trades( + blockchain = 'sonic', + project = 'beets', + version = '3', + project_decoded_as = 'beethoven_x_v3', + Vault_evt_Swap = 'Vault_evt_Swap', + pools_fees = 'pools_fees' + ) +}}) + +SELECT * FROM v2_trades + +UNION + +SELECT * FROM v3_trades \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv new file mode 100644 index 00000000000..5ff45556a7d --- /dev/null +++ b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv @@ -0,0 +1,2 @@ +blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw +sonic,beets,2,2024-12-30,0x23badfa0d6191092542143171ce3cf1c6017040bef45ceca224af7eddafcfd20,2,0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38,0x29219dd400f2bf60e5a23d13be72b486d4038894,1947622,150253674127296655,118887 From e88f5c7ce687ecbe92afa11ef5d3a8998fee70d9 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 30 Dec 2024 10:50:45 +0000 Subject: [PATCH 02/28] fix --- .../dex/seeds/trades/beets_sonic_base_trades_seed.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv index 5ff45556a7d..7504d9db708 100644 --- a/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv +++ b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv @@ -1,2 +1,2 @@ blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw -sonic,beets,2,2024-12-30,0x23badfa0d6191092542143171ce3cf1c6017040bef45ceca224af7eddafcfd20,2,0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38,0x29219dd400f2bf60e5a23d13be72b486d4038894,1947622,150253674127296655,118887 +sonic,beets,2,2024-12-30,0x23badfa0d6191092542143171ce3cf1c6017040bef45ceca224af7eddafcfd20,2,0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38,0x29219dd400f2bf60e5a23d13be72b486d4038894,1947622,150253674127296655,118887 \ No newline at end of file From 5cc0dd985c592b37f9ee83244d566a87b588d504 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 30 Dec 2024 10:52:25 +0000 Subject: [PATCH 03/28] fix schema --- .../dex/models/_projects/beets/_schema.yml | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/beets/_schema.yml b/dbt_subprojects/dex/models/_projects/beets/_schema.yml index 65ff76451ae..38c70130356 100644 --- a/dbt_subprojects/dex/models/_projects/beets/_schema.yml +++ b/dbt_subprojects/dex/models/_projects/beets/_schema.yml @@ -19,31 +19,38 @@ models: columns: - &blockchain name: blockchain - description: "Blockchain which the DEX is deployed" + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" - &contract_address name: contract_address - description: 'sonic address for the liquidity pool used in transaction' + description: 'zkevm address for the liquidity pool used in transaction' data_tests: - not_null - &tx_hash name: tx_hash - description: "Unique transaction hash value tied to each transaction on the DEX" + description: 'Transaction hash' + data_tests: + - not_null - &index name: index - description: '' + description: 'Event Index' data_tests: - not_null - &tx_index name: tx_index - description: '' + description: 'Transaction Index' data_tests: - not_null - &block_time name: block_time - description: "UTC event block time of each DEX trade" + description: 'Block time in UTC' + data_tests: + - not_null - &block_number name: block_number - description: 'Block number' + description: 'Event Block Number' data_tests: - not_null - &swap_fee_percentage From 3715a3ef36a234e97d942216d93ceab3ddc2c384 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 30 Dec 2024 10:55:35 +0000 Subject: [PATCH 04/28] again --- dbt_subprojects/dex/models/_projects/beets/_schema.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/beets/_schema.yml b/dbt_subprojects/dex/models/_projects/beets/_schema.yml index 38c70130356..05ed4685f8c 100644 --- a/dbt_subprojects/dex/models/_projects/beets/_schema.yml +++ b/dbt_subprojects/dex/models/_projects/beets/_schema.yml @@ -194,9 +194,7 @@ models: - &pool_type name: pool_type description: "Pool attributes, determined by the pool's factory" - - &tx_hash - name: tx_hash - description: "Tx. Hash" + - *tx_hash - &tx_from name: tx_from description: "transaction.from" From 30f357d65073d53d7927ca6b8732c6461593827b Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 30 Dec 2024 11:01:28 +0000 Subject: [PATCH 05/28] fix typo --- dbt_subprojects/dex/models/_projects/beets/beets_pools_fees.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/_projects/beets/beets_pools_fees.sql b/dbt_subprojects/dex/models/_projects/beets/beets_pools_fees.sql index 6654724a449..51342f44e8d 100644 --- a/dbt_subprojects/dex/models/_projects/beets/beets_pools_fees.sql +++ b/dbt_subprojects/dex/models/_projects/beets/beets_pools_fees.sql @@ -4,7 +4,7 @@ post_hook='{{ expose_spells(blockchains = \'["sonic"]\', spell_type = "project", spell_name = "beets", - contributors = \'[]"viniabussafi"]\') }}' + contributors = \'["viniabussafi"]\') }}' ) }} From 8f9122bea441a0d2213624105dc6904901c79671 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 30 Dec 2024 11:03:40 +0000 Subject: [PATCH 06/28] fix copypasta --- .../trades/sonic/dex_fantom_base_trades.sql | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 dbt_subprojects/dex/models/trades/sonic/dex_fantom_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/sonic/dex_fantom_base_trades.sql b/dbt_subprojects/dex/models/trades/sonic/dex_fantom_base_trades.sql deleted file mode 100644 index bf2a270bfa8..00000000000 --- a/dbt_subprojects/dex/models/trades/sonic/dex_fantom_base_trades.sql +++ /dev/null @@ -1,48 +0,0 @@ -{{ config( - schema = 'dex_sonic' - , alias = 'base_trades' - , materialized = 'view' - ) -}} - -{% set base_models = [ - ref('beets_sonic_base_trades') -] %} - -WITH base_union AS ( - SELECT * - FROM ( - {% for base_model in base_models %} - SELECT - blockchain - , project - , version - , block_month - , block_date - , block_time - , block_number - , token_bought_amount_raw - , token_sold_amount_raw - , token_bought_address - , token_sold_address - , taker - , maker - , project_contract_address - , tx_hash - , evt_index - FROM - {{ base_model }} - {% if not loop.last %} - UNION ALL - {% endif %} - {% endfor %} - ) -) - -{{ - add_tx_columns( - model_cte = 'base_union' - , blockchain = 'sonic' - , columns = ['from', 'to', 'index'] - ) -}} From aab6ab0f9df82b4260334992d35b5555ee20b54d Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 30 Dec 2024 11:03:55 +0000 Subject: [PATCH 07/28] add sonic base trades --- .../trades/sonic/dex_sonic_base_trades.sql | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 dbt_subprojects/dex/models/trades/sonic/dex_sonic_base_trades.sql diff --git a/dbt_subprojects/dex/models/trades/sonic/dex_sonic_base_trades.sql b/dbt_subprojects/dex/models/trades/sonic/dex_sonic_base_trades.sql new file mode 100644 index 00000000000..bf2a270bfa8 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/sonic/dex_sonic_base_trades.sql @@ -0,0 +1,48 @@ +{{ config( + schema = 'dex_sonic' + , alias = 'base_trades' + , materialized = 'view' + ) +}} + +{% set base_models = [ + ref('beets_sonic_base_trades') +] %} + +WITH base_union AS ( + SELECT * + FROM ( + {% for base_model in base_models %} + SELECT + blockchain + , project + , version + , block_month + , block_date + , block_time + , block_number + , token_bought_amount_raw + , token_sold_amount_raw + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , evt_index + FROM + {{ base_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) +) + +{{ + add_tx_columns( + model_cte = 'base_union' + , blockchain = 'sonic' + , columns = ['from', 'to', 'index'] + ) +}} From 62a03db6f76585038af67739330ba48f958d8d04 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 30 Dec 2024 11:11:06 +0000 Subject: [PATCH 08/28] adjust macro --- .../models/trades/sonic/platforms/beets_sonic_base_trades.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/sonic/platforms/beets_sonic_base_trades.sql b/dbt_subprojects/dex/models/trades/sonic/platforms/beets_sonic_base_trades.sql index f2312ce592e..75a321f1b4f 100644 --- a/dbt_subprojects/dex/models/trades/sonic/platforms/beets_sonic_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/sonic/platforms/beets_sonic_base_trades.sql @@ -30,8 +30,7 @@ v3_trades AS( project = 'beets', version = '3', project_decoded_as = 'beethoven_x_v3', - Vault_evt_Swap = 'Vault_evt_Swap', - pools_fees = 'pools_fees' + Vault_evt_Swap = 'Vault_evt_Swap' ) }}) From 5f8f393369baec89dffc2e43a9f168be6aad162b Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 30 Dec 2024 11:12:45 +0000 Subject: [PATCH 09/28] fix schema --- dbt_subprojects/dex/models/_projects/beets/_schema.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/beets/_schema.yml b/dbt_subprojects/dex/models/_projects/beets/_schema.yml index 05ed4685f8c..9f25b45cb2e 100644 --- a/dbt_subprojects/dex/models/_projects/beets/_schema.yml +++ b/dbt_subprojects/dex/models/_projects/beets/_schema.yml @@ -1,11 +1,11 @@ version: 2 models: - - name: beets_sonic_pools_fees + - name: beets_pools_fees meta: blockchain: sonic project: beets - contributors: jacektrocinski, thetroyharris, tomfutago, viniabussafi + contributors: viniabussafi config: tags: ['sonic', 'beets', 'pools_fees'] description: > From b4f9d99b94ad6727abdfbdb1df93215e26817c20 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Fri, 3 Jan 2025 18:23:19 +0000 Subject: [PATCH 10/28] Update beets_sonic_base_trades_seed.csv --- .../dex/seeds/trades/beets_sonic_base_trades_seed.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv index 7504d9db708..e3505827c0f 100644 --- a/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv +++ b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv @@ -1,2 +1,2 @@ blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw -sonic,beets,2,2024-12-30,0x23badfa0d6191092542143171ce3cf1c6017040bef45ceca224af7eddafcfd20,2,0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38,0x29219dd400f2bf60e5a23d13be72b486d4038894,1947622,150253674127296655,118887 \ No newline at end of file +sonic,beets,2,2025-01-01,0x7655e24c6b5c265e7baffa17ba5dce67857b09e20f34aa7aa8a82092de185ba6,0,0x29219dd400f2bf60e5a23d13be72b486d4038894,0xd3dce716f3ef535c5ff8d041c1a41c3bd89b97ae,2149520,1000000,1001216 From acbc7cbca5fc67c6537d482a09ed40e4f1c92545 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Fri, 3 Jan 2025 18:29:04 +0000 Subject: [PATCH 11/28] add version column --- .../models/_projects/beets/beethoven_x_v2_sonic_pools_fees.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v2_sonic_pools_fees.sql b/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v2_sonic_pools_fees.sql index 712f22d57c0..14c737e2293 100644 --- a/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v2_sonic_pools_fees.sql +++ b/dbt_subprojects/dex/models/_projects/beets/beethoven_x_v2_sonic_pools_fees.sql @@ -24,6 +24,7 @@ ) SELECT 'sonic' AS blockchain, + '2' AS version, logs.contract_address, logs.tx_hash, logs.tx_index, From 3d513234cc2aa45b9cb04b0da13a1ef1c83738df Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Fri, 3 Jan 2025 19:03:19 +0000 Subject: [PATCH 12/28] lighter rerun --- dbt_subprojects/dex/models/trades/dex_base_trades.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/dex_base_trades.sql b/dbt_subprojects/dex/models/trades/dex_base_trades.sql index 6464ffb67e9..54d971dfa2a 100644 --- a/dbt_subprojects/dex/models/trades/dex_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_base_trades.sql @@ -11,7 +11,8 @@ }} {% set models = [ - ref('dex_arbitrum_base_trades') + ref('dex_sonic_base_trades') + /*ref('dex_arbitrum_base_trades') , ref('dex_avalanche_c_base_trades') , ref('dex_base_base_trades') , ref('dex_blast_base_trades') @@ -33,7 +34,7 @@ , ref('dex_worldchain_base_trades') , ref('dex_zkevm_base_trades') , ref('dex_zksync_base_trades') - , ref('dex_zora_base_trades') + , ref('dex_zora_base_trades')*/ ] %} with base_union as ( From 8e3678cbe8d5b7854714d60da0d38b6226301fbd Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Fri, 3 Jan 2025 19:06:17 +0000 Subject: [PATCH 13/28] fix comment --- .../dex/models/trades/dex_base_trades.sql | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/dex_base_trades.sql b/dbt_subprojects/dex/models/trades/dex_base_trades.sql index 54d971dfa2a..cf1a93a53bb 100644 --- a/dbt_subprojects/dex/models/trades/dex_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_base_trades.sql @@ -12,29 +12,29 @@ {% set models = [ ref('dex_sonic_base_trades') - /*ref('dex_arbitrum_base_trades') - , ref('dex_avalanche_c_base_trades') - , ref('dex_base_base_trades') - , ref('dex_blast_base_trades') - , ref('dex_bnb_base_trades') - , ref('dex_celo_base_trades') - , ref('dex_ethereum_base_trades') - , ref('dex_fantom_base_trades') - , ref('dex_gnosis_base_trades') - , ref('dex_linea_base_trades') - , ref('dex_kaia_base_trades') - , ref('dex_mantle_base_trades') - , ref('dex_nova_base_trades') - , ref('dex_optimism_base_trades') - , ref('dex_polygon_base_trades') - , ref('dex_ronin_base_trades') - , ref('dex_scroll_base_trades') - , ref('dex_sei_base_trades') - , ref('dex_sonic_base_trades') - , ref('dex_worldchain_base_trades') - , ref('dex_zkevm_base_trades') - , ref('dex_zksync_base_trades') - , ref('dex_zora_base_trades')*/ + -- ref('dex_arbitrum_base_trades') + -- , ref('dex_avalanche_c_base_trades') + -- , ref('dex_base_base_trades') + -- , ref('dex_blast_base_trades') + -- , ref('dex_bnb_base_trades') + -- , ref('dex_celo_base_trades') + -- , ref('dex_ethereum_base_trades') + -- , ref('dex_fantom_base_trades') + -- , ref('dex_gnosis_base_trades') + -- , ref('dex_linea_base_trades') + -- , ref('dex_kaia_base_trades') + -- , ref('dex_mantle_base_trades') + -- , ref('dex_nova_base_trades') + -- , ref('dex_optimism_base_trades') + -- , ref('dex_polygon_base_trades') + -- , ref('dex_ronin_base_trades') + -- , ref('dex_scroll_base_trades') + -- , ref('dex_sei_base_trades') + -- , ref('dex_sonic_base_trades') + -- , ref('dex_worldchain_base_trades') + -- , ref('dex_zkevm_base_trades') + -- , ref('dex_zksync_base_trades') + -- , ref('dex_zora_base_trades') ] %} with base_union as ( From 386587450b9adc407f1463ca8f5c5a5a6b9c07cd Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Fri, 3 Jan 2025 19:07:26 +0000 Subject: [PATCH 14/28] again --- .../dex/models/trades/dex_base_trades.sql | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/dbt_subprojects/dex/models/trades/dex_base_trades.sql b/dbt_subprojects/dex/models/trades/dex_base_trades.sql index cf1a93a53bb..4d8263303ac 100644 --- a/dbt_subprojects/dex/models/trades/dex_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_base_trades.sql @@ -12,29 +12,6 @@ {% set models = [ ref('dex_sonic_base_trades') - -- ref('dex_arbitrum_base_trades') - -- , ref('dex_avalanche_c_base_trades') - -- , ref('dex_base_base_trades') - -- , ref('dex_blast_base_trades') - -- , ref('dex_bnb_base_trades') - -- , ref('dex_celo_base_trades') - -- , ref('dex_ethereum_base_trades') - -- , ref('dex_fantom_base_trades') - -- , ref('dex_gnosis_base_trades') - -- , ref('dex_linea_base_trades') - -- , ref('dex_kaia_base_trades') - -- , ref('dex_mantle_base_trades') - -- , ref('dex_nova_base_trades') - -- , ref('dex_optimism_base_trades') - -- , ref('dex_polygon_base_trades') - -- , ref('dex_ronin_base_trades') - -- , ref('dex_scroll_base_trades') - -- , ref('dex_sei_base_trades') - -- , ref('dex_sonic_base_trades') - -- , ref('dex_worldchain_base_trades') - -- , ref('dex_zkevm_base_trades') - -- , ref('dex_zksync_base_trades') - -- , ref('dex_zora_base_trades') ] %} with base_union as ( From ebae72eefd138e65acf88e1e234fa63457af39aa Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Fri, 3 Jan 2025 19:34:12 +0000 Subject: [PATCH 15/28] update dex_info --- dbt_subprojects/dex/models/dex_info.sql | 1 + .../dex/seeds/trades/beets_sonic_base_trades_seed.csv | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/dex_info.sql b/dbt_subprojects/dex/models/dex_info.sql index 8f68ddf7469..82d26c9adb8 100644 --- a/dbt_subprojects/dex/models/dex_info.sql +++ b/dbt_subprojects/dex/models/dex_info.sql @@ -196,4 +196,5 @@ FROM (VALUES , ('levinswap', 'Levinswap', 'Direct', 'levinswap') , ('gravity_finance', 'GravityFinance', 'Direct', 'Gravity_Finance') , ('fluid', 'Fluid DEX', 'Direct', '0xfluid') + , ('beets', 'Beets DEX', 'Direct', 'beets_fi') ) AS temp_table (project, name, marketplace_type, x_username) diff --git a/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv index e3505827c0f..14592ce5b94 100644 --- a/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv +++ b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv @@ -1,2 +1,2 @@ blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw -sonic,beets,2,2025-01-01,0x7655e24c6b5c265e7baffa17ba5dce67857b09e20f34aa7aa8a82092de185ba6,0,0x29219dd400f2bf60e5a23d13be72b486d4038894,0xd3dce716f3ef535c5ff8d041c1a41c3bd89b97ae,2149520,1000000,1001216 +sonic,beets,2,2025-01-01,0x7655e24c6b5c265e7baffa17ba5dce67857b09e20f34aa7aa8a82092de185ba6,0,0x29219dd400f2bf60e5a23d13be72b486d4038894,0xd3dce716f3ef535c5ff8d041c1a41c3bd89b97ae,2149520,1000000,1001216 \ No newline at end of file From 771bfc3445f7be3b67c100b7f3650d449bf9cfb0 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Tue, 7 Jan 2025 12:23:59 +0000 Subject: [PATCH 16/28] init beets daily_spellbook spells --- .../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 ++ sources/_subprojects_outputs/dex/_sources.yml | 4 + .../hourly_spellbook/_sources.yml | 4 + 14 files changed, 893 insertions(+) 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_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..2e96c1c4eb7 --- /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_', '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.weights) 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..41112787321 --- /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_beethoven_x_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/dex/_sources.yml b/sources/_subprojects_outputs/dex/_sources.yml index 1d1d25769a6..00c1802a46a 100644 --- a/sources/_subprojects_outputs/dex/_sources.yml +++ b/sources/_subprojects_outputs/dex/_sources.yml @@ -89,3 +89,7 @@ sources: - name: beethoven_x tables: - name: trades + + - name: beets + tables: + - name: trades diff --git a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml index ecf970cd3af..fc5b24d0196 100644 --- a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml @@ -83,3 +83,7 @@ sources: - name: evms tables: - name: transaction_metrics + + - name: beets + tables: + - name: pools_metrics_daily \ No newline at end of file From db5b809345e296cb175cd65ecdbdaaa137c28e22 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:22:40 +0000 Subject: [PATCH 17/28] Update beets_sonic_base_trades_seed.csv From aabd3cce2e122395335def4a1bd2362f18b9b8f7 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Thu, 9 Jan 2025 17:29:50 +0000 Subject: [PATCH 18/28] fix source --- .../models/beets/sonic/beets_pools_tokens_weights.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 2e96c1c4eb7..2354487a381 100644 --- 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 @@ -14,7 +14,7 @@ WITH registered AS ( SELECT poolID AS pool_id, evt_block_time - FROM {{ source('beethoven_x_v2_', 'Vault_evt_PoolRegistered') }} + FROM {{ source('beethoven_x_v2_sonic', 'Vault_evt_PoolRegistered') }} {% if is_incremental() %} WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) {% endif %} From c26cc6293253caa97b3d572997a40b002a3d0ee8 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Thu, 9 Jan 2025 17:37:35 +0000 Subject: [PATCH 19/28] update sources and token whitelist for pricing --- .../_project/balancer/support/balancer_token_whitelist.sql | 3 +++ sources/_subprojects_outputs/hourly_spellbook/_sources.yml | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/hourly_spellbook/models/_project/balancer/support/balancer_token_whitelist.sql b/dbt_subprojects/hourly_spellbook/models/_project/balancer/support/balancer_token_whitelist.sql index a063cb927cd..2eed6e6548c 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/balancer/support/balancer_token_whitelist.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/support/balancer_token_whitelist.sql @@ -46,6 +46,9 @@ WITH whitelist_token as ( (0xc2132d05d31c914a87c6611c10748aeb04b58e8f, 'USDT', 'polygon'), (0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270, 'WMATIC', 'polygon'), (0x7ceb23fd6bc0add59e62ac25578270cff1b9f619, 'WETH', 'polygon'), + (0xe5da20f15420ad15de0fa650600afc998bbe3955, 'stS', 'sonic'), + (0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38, 'wS', 'sonic'), + (0x2d0e0814e62d80056181f5cd932274405966e4f0, 'BEETS', 'sonic'), (0x37eaa0ef3549a5bb7d431be78a3d99bd360d19e5, 'USDC', 'zkevm'), (0x744c5860ba161b5316f7e80d9ec415e2727e5bd5, 'DAI', 'zkevm'), (0x4f9a0e7fd2bf6067db6994cf12e4495df938e6e9, 'WETH', 'zkevm') diff --git a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml index fc5b24d0196..5dd90a193a5 100644 --- a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml @@ -86,4 +86,9 @@ sources: - name: beets tables: - - name: pools_metrics_daily \ No newline at end of file + - name: pools_metrics_daily + + - name: balancer_v3 + tables: + - name: erc4626_token_mapping + - name: erc4626_token_prices \ No newline at end of file From ea68dc11f42416262e19a74af144191b77b0ea7d Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Thu, 9 Jan 2025 17:42:48 +0000 Subject: [PATCH 20/28] again --- sources/_subprojects_outputs/hourly_spellbook/_sources.yml | 7 +------ sources/_subprojects_outputs/spellbook/_sources.yml | 1 + 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml index 5dd90a193a5..fc5b24d0196 100644 --- a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml @@ -86,9 +86,4 @@ sources: - name: beets tables: - - name: pools_metrics_daily - - - name: balancer_v3 - tables: - - name: erc4626_token_mapping - - name: erc4626_token_prices \ No newline at end of file + - name: pools_metrics_daily \ No newline at end of file diff --git a/sources/_subprojects_outputs/spellbook/_sources.yml b/sources/_subprojects_outputs/spellbook/_sources.yml index 9aa040b2036..ae2af0c84fc 100644 --- a/sources/_subprojects_outputs/spellbook/_sources.yml +++ b/sources/_subprojects_outputs/spellbook/_sources.yml @@ -119,6 +119,7 @@ sources: - name: balancer_v3 tables: - name: erc4626_token_prices + - name: erc4626_token_mapping - name: addresses_ethereum tables: From 0f52519a8b94961fee06c3025e4514cdfff4a20e Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Thu, 9 Jan 2025 17:45:53 +0000 Subject: [PATCH 21/28] again --- sources/_subprojects_outputs/daily_spellbook/_sources.yml | 6 +++++- sources/_subprojects_outputs/hourly_spellbook/_sources.yml | 7 ++++++- sources/_subprojects_outputs/spellbook/_sources.yml | 4 ---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sources/_subprojects_outputs/daily_spellbook/_sources.yml b/sources/_subprojects_outputs/daily_spellbook/_sources.yml index e086d2254ef..a8247bc02eb 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: balancer_v3 + tables: + - name: erc4626_token_prices + - name: erc4626_token_mapping \ 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 fc5b24d0196..8ba8b834e58 100644 --- a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml @@ -86,4 +86,9 @@ sources: - name: beets tables: - - name: pools_metrics_daily \ No newline at end of file + - name: pools_metrics_daily + + - name: balancer_v3 + tables: + - name: erc4626_token_prices + - name: erc4626_token_mapping \ No newline at end of file diff --git a/sources/_subprojects_outputs/spellbook/_sources.yml b/sources/_subprojects_outputs/spellbook/_sources.yml index ae2af0c84fc..65c11b935de 100644 --- a/sources/_subprojects_outputs/spellbook/_sources.yml +++ b/sources/_subprojects_outputs/spellbook/_sources.yml @@ -116,10 +116,6 @@ sources: - name: balancer_v3_gnosis tables: - name: bpt_prices - - name: balancer_v3 - tables: - - name: erc4626_token_prices - - name: erc4626_token_mapping - name: addresses_ethereum tables: From c1cb0160a16763f0c186af3be8e99b402cd8ec66 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Thu, 9 Jan 2025 17:48:26 +0000 Subject: [PATCH 22/28] again --- sources/_subprojects_outputs/hourly_spellbook/_sources.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml index 8ba8b834e58..232f2f29c37 100644 --- a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml @@ -87,8 +87,3 @@ sources: - name: beets tables: - name: pools_metrics_daily - - - name: balancer_v3 - tables: - - name: erc4626_token_prices - - name: erc4626_token_mapping \ No newline at end of file From d94155fa2e16e12e6042219ec900c8155530ab45 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Thu, 9 Jan 2025 17:57:55 +0000 Subject: [PATCH 23/28] update macros to allow cros subproject spells --- dbt_macros/shared/balancer/balancer_bpt_prices_macro.sql | 2 +- dbt_macros/shared/balancer/balancer_liquidity_macro.sql | 2 +- dbt_macros/shared/balancer/balancer_protocol_fee_macro.sql | 2 +- .../balancer_token_balance_changes_daily_agg_macro.sql | 2 +- .../_project/balancer/support/balancer_token_whitelist.sql | 3 --- 5 files changed, 4 insertions(+), 7 deletions(-) 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/hourly_spellbook/models/_project/balancer/support/balancer_token_whitelist.sql b/dbt_subprojects/hourly_spellbook/models/_project/balancer/support/balancer_token_whitelist.sql index 2eed6e6548c..a063cb927cd 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/balancer/support/balancer_token_whitelist.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/support/balancer_token_whitelist.sql @@ -46,9 +46,6 @@ WITH whitelist_token as ( (0xc2132d05d31c914a87c6611c10748aeb04b58e8f, 'USDT', 'polygon'), (0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270, 'WMATIC', 'polygon'), (0x7ceb23fd6bc0add59e62ac25578270cff1b9f619, 'WETH', 'polygon'), - (0xe5da20f15420ad15de0fa650600afc998bbe3955, 'stS', 'sonic'), - (0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38, 'wS', 'sonic'), - (0x2d0e0814e62d80056181f5cd932274405966e4f0, 'BEETS', 'sonic'), (0x37eaa0ef3549a5bb7d431be78a3d99bd360d19e5, 'USDC', 'zkevm'), (0x744c5860ba161b5316f7e80d9ec415e2727e5bd5, 'DAI', 'zkevm'), (0x4f9a0e7fd2bf6067db6994cf12e4495df938e6e9, 'WETH', 'zkevm') From 63f829403b93e8ed1472af6219830d5aae91f3de Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Thu, 9 Jan 2025 18:00:27 +0000 Subject: [PATCH 24/28] broken ref --- .../models/beets/sonic/beets_token_balance_changes.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 41112787321..8a488b178d7 100644 --- 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 @@ -13,7 +13,7 @@ WITH v2 AS( version = '2', project_decoded_as = 'beethoven_x_v2', base_spells_namespace = 'beets', - pool_labels_spell = ref('labels_beethoven_x_pools_sonic') + pool_labels_spell = ref('labels_beets_pools_sonic') ) }}), From 47b9509722610be832e1887a258f7243c98b8a08 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Thu, 9 Jan 2025 18:08:38 +0000 Subject: [PATCH 25/28] fix column --- .../models/beets/sonic/beets_pools_tokens_weights.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 2354487a381..2473176fca0 100644 --- 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 @@ -27,7 +27,7 @@ weighted_pool_factory AS ( 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.weights) WITH ORDINALITY t2(normalized_weight, 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) From ea7f5da17303786e1601a831fd8852d7bce71959 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:45:31 +0000 Subject: [PATCH 26/28] Update beets_sonic_base_trades_seed.csv From 2bfc990cfb93254b5bc40fc0c358191c6d7f512a Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 13 Jan 2025 20:48:56 +0000 Subject: [PATCH 27/28] merge source changes on single file --- .../_subprojects_outputs/daily_spellbook/_sources.yml | 10 +++++++++- sources/_subprojects_outputs/dex/_sources.yml | 6 +----- .../_subprojects_outputs/hourly_spellbook/_sources.yml | 6 +----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sources/_subprojects_outputs/daily_spellbook/_sources.yml b/sources/_subprojects_outputs/daily_spellbook/_sources.yml index a8247bc02eb..e01b4583c8a 100644 --- a/sources/_subprojects_outputs/daily_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/daily_spellbook/_sources.yml @@ -45,4 +45,12 @@ sources: - name: balancer_v3 tables: - name: erc4626_token_prices - - name: erc4626_token_mapping \ No newline at end of file + - name: erc4626_token_mapping + + - name: beets + tables: + - name: pools_metrics_daily + + - name: beets + tables: + - 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 00c1802a46a..bb73d57800e 100644 --- a/sources/_subprojects_outputs/dex/_sources.yml +++ b/sources/_subprojects_outputs/dex/_sources.yml @@ -88,8 +88,4 @@ sources: - name: trades - name: beethoven_x tables: - - name: trades - - - name: beets - 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 232f2f29c37..a5a273cd1b3 100644 --- a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml @@ -82,8 +82,4 @@ sources: - name: evms tables: - - name: transaction_metrics - - - name: beets - tables: - - name: pools_metrics_daily + - name: transaction_metrics \ No newline at end of file From b35fc6908bb04723d22e928610ec62c157a845c4 Mon Sep 17 00:00:00 2001 From: viniabussafi Date: Mon, 13 Jan 2025 20:52:41 +0000 Subject: [PATCH 28/28] again --- .../dex/seeds/trades/beets_sonic_base_trades_seed.csv | 2 +- sources/_subprojects_outputs/daily_spellbook/_sources.yml | 8 -------- sources/_subprojects_outputs/spellbook/_sources.yml | 2 -- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv index 28147c43507..9e9bd5ce4bb 100644 --- a/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv +++ b/dbt_subprojects/dex/seeds/trades/beets_sonic_base_trades_seed.csv @@ -1,2 +1,2 @@ blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw -sonic,beets,2,2025-01-07,0x373d087835d32dee82a306eb8ad67031f57e6f54b6fb0926fce72511b650822f,4,0x29219dd400f2bf60e5a23d13be72b486d4038894,0xd3dce716f3ef535c5ff8d041c1a41c3bd89b97ae,2850908,230927950,230996815 +sonic,beets,2,2025-01-07,0x373d087835d32dee82a306eb8ad67031f57e6f54b6fb0926fce72511b650822f,4,0x29219dd400f2bf60e5a23d13be72b486d4038894,0xd3dce716f3ef535c5ff8d041c1a41c3bd89b97ae,2850908,230927950,230996815 \ 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 e01b4583c8a..be8ca799747 100644 --- a/sources/_subprojects_outputs/daily_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/daily_spellbook/_sources.yml @@ -42,15 +42,7 @@ sources: tables: - name: blobs_submissions - - name: balancer_v3 - tables: - - name: erc4626_token_prices - - name: erc4626_token_mapping - - name: beets tables: - name: pools_metrics_daily - - - name: beets - tables: - name: trades \ No newline at end of file diff --git a/sources/_subprojects_outputs/spellbook/_sources.yml b/sources/_subprojects_outputs/spellbook/_sources.yml index a26ef3743b9..b3eaf34dbd0 100644 --- a/sources/_subprojects_outputs/spellbook/_sources.yml +++ b/sources/_subprojects_outputs/spellbook/_sources.yml @@ -116,13 +116,11 @@ sources: - name: balancer_v3_gnosis tables: - name: bpt_prices - - name: balancer_v3 tables: - name: erc4626_token_prices - name: erc4626_token_mapping - - name: addresses_ethereum tables: - name: optimism_batchinbox_combinations