diff --git a/macros/models/_project/balancer/balancer_bpt_prices_macro.sql b/macros/models/_project/balancer/balancer_bpt_prices_macro.sql index 4b207acbd42..197c0216018 100644 --- a/macros/models/_project/balancer/balancer_bpt_prices_macro.sql +++ b/macros/models/_project/balancer/balancer_bpt_prices_macro.sql @@ -1,6 +1,6 @@ {% macro - balancer_bpt_prices_macro( - blockchain, version + balancer_v2_compatible_bpt_prices_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_spell ) %} @@ -9,7 +9,7 @@ WITH pool_labels AS ( address AS pool_id, name AS pool_symbol, pool_type - FROM {{ source('labels', 'balancer_v2_pools') }} + FROM {{ pool_labels_spell }} WHERE blockchain = '{{blockchain}}' ), @@ -48,7 +48,7 @@ WITH pool_labels AS ( poolId AS pool_id, tokenIn AS token, CAST(amountIn as int256) AS delta - FROM {{ source('balancer_v2_' ~ blockchain, 'Vault_evt_Swap') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} UNION ALL @@ -57,7 +57,7 @@ WITH pool_labels AS ( poolId AS pool_id, tokenOut AS token, -CAST(amountOut AS int256) AS delta - FROM {{ source('balancer_v2_' ~ blockchain, 'Vault_evt_Swap') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} ) swaps GROUP BY 1, 2, 3 ), @@ -69,7 +69,7 @@ WITH pool_labels AS ( t.tokens, d.deltas, p.protocolFeeAmounts - FROM {{ source('balancer_v2_' ~ blockchain, 'Vault_evt_PoolBalanceChanged') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolBalanceChanged') }} CROSS JOIN UNNEST (tokens) WITH ORDINALITY as t(tokens,i) CROSS JOIN UNNEST (deltas) WITH ORDINALITY as d(deltas,i) CROSS JOIN UNNEST (protocolFeeAmounts) WITH ORDINALITY as p(protocolFeeAmounts,i) @@ -94,7 +94,7 @@ WITH pool_labels AS ( poolId AS pool_id, token, cashDelta + managedDelta AS delta - FROM {{ source('balancer_v2_' ~ blockchain, 'Vault_evt_PoolBalanceManaged') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolBalanceManaged') }} ), daily_delta_balance AS ( @@ -177,7 +177,7 @@ WITH pool_labels AS ( ROW_NUMBER() OVER (partition by b.day, b.pool_id ORDER BY SUM(b.protocol_liquidity_usd) ASC) AS pricing_count, --to avoid double count in pools with multiple pricing assets SUM(b.protocol_liquidity_usd) / COALESCE(SUM(w.normalized_weight), 1) AS protocol_liquidity FROM cumulative_usd_balance b - LEFT JOIN {{ ref('balancer_pools_tokens_weights') }} w ON b.pool_id = w.pool_id + LEFT JOIN {{ ref(base_spells_namespace + '_pools_tokens_weights') }} w ON b.pool_id = w.pool_id AND b.token = w.token_address AND b.protocol_liquidity_usd > 0 LEFT JOIN {{ ref('balancer_token_whitelist') }} q ON b.token = q.address @@ -208,7 +208,7 @@ WITH pool_labels AS ( FROM cumulative_usd_balance c FULL OUTER JOIN weighted_pool_liquidity_estimates_2 b ON c.day = b.day AND c.pool_id = b.pool_id - LEFT JOIN {{ ref('balancer_pools_tokens_weights') }} w ON b.pool_id = w.pool_id + LEFT JOIN {{ ref(base_spells_namespace + '_pools_tokens_weights') }} w ON b.pool_id = w.pool_id AND w.blockchain = '{{blockchain}}' AND w.version = '{{version}}' AND w.token_address = c.token @@ -220,8 +220,8 @@ WITH pool_labels AS ( bpt_trades AS ( SELECT * - FROM {{ source('balancer_v2_' ~ blockchain, 'Vault_evt_Swap') }} v - INNER JOIN pool_labels l ON bytearray_substring(v.poolId, 1, 20) = l.pool_id AND l.pool_type = 'linear' + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} v + LEFT JOIN pool_labels l ON bytearray_substring(v.poolId, 1, 20) = l.pool_id WHERE v.tokenIn = bytearray_substring(v.poolId, 1, 20) OR v.tokenOut = bytearray_substring(v.poolId, 1, 20) ), @@ -340,7 +340,7 @@ WITH pool_labels AS ( ELSE l.liquidity / s.supply END AS bpt_price FROM tvl l - LEFT JOIN {{ ref('balancer_bpt_supply') }} s ON l.pool_address = s.token_address + LEFT JOIN {{ ref(base_spells_namespace + '_bpt_supply') }} s ON l.pool_address = s.token_address AND l.blockchain = s.blockchain AND l.version = s.version AND l.day = s.day diff --git a/macros/models/_project/balancer/balancer_bpt_supply_macro.sql b/macros/models/_project/balancer/balancer_bpt_supply_macro.sql index 9ccb707cd73..9d128983005 100644 --- a/macros/models/_project/balancer/balancer_bpt_supply_macro.sql +++ b/macros/models/_project/balancer/balancer_bpt_supply_macro.sql @@ -1,6 +1,6 @@ {% macro - balancer_bpt_supply_macro( - blockchain, version + balancer_v2_compatible_bpt_supply_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_spell ) %} @@ -11,7 +11,7 @@ WITH pool_labels AS ( name, pool_type, ROW_NUMBER() OVER (PARTITION BY address ORDER BY MAX(updated_at) DESC) AS num - FROM {{ source('labels', 'balancer_v2_pools') }} + FROM {{ pool_labels_spell }} WHERE blockchain = '{{blockchain}}' GROUP BY 1, 2, 3) WHERE num = 1 @@ -24,7 +24,7 @@ WITH pool_labels AS ( contract_address AS token, COALESCE(SUM(CASE WHEN t."from" = 0x0000000000000000000000000000000000000000 THEN value / POWER(10, 18) ELSE 0 END), 0) AS mints, COALESCE(SUM(CASE WHEN t.to = 0x0000000000000000000000000000000000000000 THEN value / POWER(10, 18) ELSE 0 END), 0) AS burns - FROM {{ ref('balancer_transfers_bpt') }} t + FROM {{ ref(base_spells_namespace + '_transfers_bpt') }} t WHERE blockchain = '{{blockchain}}' AND version = '{{version}}' GROUP BY 1, 2 @@ -47,7 +47,7 @@ WITH pool_labels AS ( t.token, d.delta, ROW_NUMBER() OVER (PARTITION BY poolId ORDER BY evt_block_time ASC) AS rn - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_PoolBalanceChanged') }} pb + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolBalanceChanged') }} pb CROSS JOIN UNNEST (pb.deltas) WITH ORDINALITY d(delta, i) CROSS JOIN UNNEST (pb.tokens) WITH ORDINALITY t(token, i) WHERE d.i = t.i @@ -85,7 +85,7 @@ WITH pool_labels AS ( THEN 0 ELSE SUM(amountOut / POWER(10, 18)) END AS ajoins - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_Swap') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} LEFT JOIN pool_labels ON BYTEARRAY_SUBSTRING(poolId, 1, 20) = address WHERE tokenOut = BYTEARRAY_SUBSTRING(poolId, 1, 20) GROUP BY 1, 2, 3 @@ -100,7 +100,7 @@ WITH pool_labels AS ( THEN 0 ELSE SUM(amountIn / POWER(10, 18)) END AS aexits - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_Swap') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} LEFT JOIN pool_labels ON BYTEARRAY_SUBSTRING(poolId, 1, 20) = address WHERE tokenIn = BYTEARRAY_SUBSTRING(poolId, 1, 20) GROUP BY 1, 2, 3 diff --git a/macros/models/_project/balancer/balancer_liquidity_macro.sql b/macros/models/_project/balancer/balancer_liquidity_macro.sql index 5eb9a247eba..dffab61aa96 100644 --- a/macros/models/_project/balancer/balancer_liquidity_macro.sql +++ b/macros/models/_project/balancer/balancer_liquidity_macro.sql @@ -1,6 +1,6 @@ {% macro - balancer_liquidity_macro( - blockchain, version + balancer_v2_compatible_liquidity_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_spell ) %} @@ -9,7 +9,7 @@ WITH pool_labels AS ( address AS pool_id, name AS pool_symbol, pool_type - FROM {{ source('labels', 'balancer_v2_pools') }} + FROM {{ pool_labels_spell }} WHERE blockchain = '{{blockchain}}' ), @@ -60,7 +60,7 @@ WITH pool_labels AS ( contract_address AS token, decimals, bpt_price - FROM {{ ref('balancer_bpt_prices') }} + FROM {{ ref(base_spells_namespace + '_bpt_prices') }} WHERE blockchain = '{{blockchain}}' AND version = '{{version}}' ), @@ -96,7 +96,7 @@ WITH pool_labels AS ( poolId AS pool_id, tokenIn AS token, CAST(amountIn as int256) AS delta - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_Swap') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} UNION ALL @@ -105,7 +105,7 @@ WITH pool_labels AS ( poolId AS pool_id, tokenOut AS token, -CAST(amountOut AS int256) AS delta - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_Swap') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} ) swaps GROUP BY 1, 2, 3 ), @@ -117,7 +117,7 @@ WITH pool_labels AS ( t.tokens, d.deltas, p.protocolFeeAmounts - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_PoolBalanceChanged') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolBalanceChanged') }} CROSS JOIN UNNEST (tokens) WITH ORDINALITY as t(tokens,i) CROSS JOIN UNNEST (deltas) WITH ORDINALITY as d(deltas,i) CROSS JOIN UNNEST (protocolFeeAmounts) WITH ORDINALITY as p(protocolFeeAmounts,i) @@ -142,7 +142,7 @@ WITH pool_labels AS ( poolId AS pool_id, token, cashDelta + managedDelta AS delta - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_PoolBalanceManaged') }} + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolBalanceManaged') }} ), daily_delta_balance AS ( @@ -235,7 +235,7 @@ WITH pool_labels AS ( SUM(b.protocol_liquidity_usd) / COALESCE(SUM(w.normalized_weight), 1) AS protocol_liquidity, SUM(b.pool_liquidity_usd) / COALESCE(SUM(w.normalized_weight), 1) AS pool_liquidity FROM cumulative_usd_balance b - LEFT JOIN {{ ref('balancer_pools_tokens_weights') }} w ON b.pool_id = w.pool_id + LEFT JOIN {{ ref(base_spells_namespace + '_pools_tokens_weights') }} w ON b.pool_id = w.pool_id AND b.token = w.token_address AND b.pool_liquidity_usd > 0 LEFT JOIN {{ ref('balancer_token_whitelist') }} q ON b.token = q.address @@ -276,7 +276,7 @@ WITH pool_labels AS ( FROM cumulative_usd_balance c FULL OUTER JOIN weighted_pool_liquidity_estimates_2 b ON c.day = b.day AND c.pool_id = b.pool_id - LEFT JOIN {{ ref('balancer_pools_tokens_weights') }} w ON b.pool_id = w.pool_id + LEFT JOIN {{ ref(base_spells_namespace + '_pools_tokens_weights') }} w ON b.pool_id = w.pool_id AND w.blockchain = '{{blockchain}}' AND w.version = '{{version}}' AND w.token_address = c.token diff --git a/macros/models/_project/balancer/balancer_pool_token_supply_changes_daily_agg_macro.sql b/macros/models/_project/balancer/balancer_pool_token_supply_changes_daily_agg_macro.sql index d94bbccf741..510ebbe007e 100644 --- a/macros/models/_project/balancer/balancer_pool_token_supply_changes_daily_agg_macro.sql +++ b/macros/models/_project/balancer/balancer_pool_token_supply_changes_daily_agg_macro.sql @@ -1,6 +1,6 @@ {% macro - bpt_supply_changes_daily_agg_macro( - blockchain, version + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( + blockchain, version, project_decoded_as, base_spells_namespace ) %} WITH @@ -13,7 +13,7 @@ WITH token_address, LEAD(block_date, 1, NOW()) OVER (PARTITION BY token_address ORDER BY block_date) AS day_of_next_change, SUM(delta_amount) AS daily_amount - FROM {{ ref('balancer_bpt_supply_changes') }} + FROM {{ ref(base_spells_namespace + '_bpt_supply_changes') }} WHERE blockchain = '{{blockchain}}' GROUP BY 1, 2, 3, 4, 5 ), @@ -34,4 +34,5 @@ WITH FROM calendar c LEFT JOIN daily_balance b ON b.block_date = c.day WHERE b.token_address IS NOT NULL + AND b.pool_type IS NOT NULL {% endmacro %} \ No newline at end of file diff --git a/macros/models/_project/balancer/balancer_pool_token_supply_changes_macro.sql b/macros/models/_project/balancer/balancer_pool_token_supply_changes_macro.sql index a9a70e5369d..71d9b78053e 100644 --- a/macros/models/_project/balancer/balancer_pool_token_supply_changes_macro.sql +++ b/macros/models/_project/balancer/balancer_pool_token_supply_changes_macro.sql @@ -1,6 +1,6 @@ {% macro - bpt_supply_changes_macro( - blockchain, version + balancer_v2_compatible_bpt_supply_changes_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_spell ) %} WITH pool_labels AS ( @@ -8,11 +8,11 @@ WITH pool_labels AS ( address, name, pool_type - FROM {{ source('labels', 'balancer_v2_pools') }} + FROM {{ pool_labels_spell }} WHERE blockchain = '{{blockchain}}' ), - -- Extract mints and burns from transfers + -- Extract mints and burns from transfers transfers AS ( SELECT t.evt_block_time, @@ -35,7 +35,7 @@ WITH pool_labels AS ( THEN - value ELSE 0 END AS amount - FROM {{ ref('balancer_transfers_bpt') }} t + FROM {{ ref(base_spells_namespace + '_transfers_bpt') }} t LEFT JOIN pool_labels l ON t.contract_address = l.address WHERE t.blockchain = '{{blockchain}}' AND t.version = '{{version}}' @@ -59,7 +59,7 @@ WITH pool_labels AS ( THEN 0 ELSE s.amountOut END AS amount - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_Swap') }} s + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} s LEFT JOIN pool_labels l ON BYTEARRAY_SUBSTRING(s.poolId, 1, 20) = l.address WHERE tokenOut = BYTEARRAY_SUBSTRING(s.poolId, 1, 20) {% if is_incremental() %} @@ -82,7 +82,7 @@ WITH pool_labels AS ( THEN 0 ELSE - s.amountIn END AS amount - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_Swap') }} s + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} s LEFT JOIN pool_labels l ON BYTEARRAY_SUBSTRING(s.poolId, 1, 20) = l.address WHERE tokenIn = BYTEARRAY_SUBSTRING(s.poolId, 1, 20) {% if is_incremental() %} diff --git a/macros/models/_project/balancer/balancer_protocol_fee_macro.sql b/macros/models/_project/balancer/balancer_protocol_fee_macro.sql index a5dafd0cd11..d5569e3cbb4 100644 --- a/macros/models/_project/balancer/balancer_protocol_fee_macro.sql +++ b/macros/models/_project/balancer/balancer_protocol_fee_macro.sql @@ -1,6 +1,6 @@ {% macro - balancer_protocol_fee_macro( - blockchain, version + balancer_v2_compatible_protocol_fee_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_spell ) %} @@ -11,7 +11,7 @@ WITH pool_labels AS ( name, pool_type, ROW_NUMBER() OVER (PARTITION BY address ORDER BY MAX(updated_at) DESC) AS num - FROM {{ source('labels', 'balancer_v2_pools') }} + FROM {{ pool_labels_spell }} WHERE blockchain = '{{blockchain}}' GROUP BY 1, 2, 3) WHERE num = 1 @@ -65,8 +65,8 @@ WITH pool_labels AS ( s.token_address AS token, 18 AS decimals, SUM(protocol_liquidity_usd / supply) AS price - FROM {{ ref('balancer_liquidity') }} l - LEFT JOIN {{ ref('balancer_bpt_supply') }} s ON s.token_address = l.pool_address + FROM {{ ref(base_spells_namespace + '_liquidity') }} l + LEFT JOIN {{ ref(base_spells_namespace + '_bpt_supply') }} s ON s.token_address = l.pool_address AND l.blockchain = s.blockchain AND s.day = l.day AND s.supply > 0 WHERE l.blockchain = '{{blockchain}}' AND l.version = '{{version}}' @@ -89,7 +89,7 @@ WITH pool_labels AS ( poolId AS pool_id, token AS token_address, SUM(protocol_fees) AS protocol_fee_amount_raw - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_PoolBalanceChanged') }} b + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolBalanceChanged') }} b CROSS JOIN unnest("protocolFeeAmounts", "tokens") AS t(protocol_fees, token) GROUP BY 1, 2, 3 @@ -100,11 +100,15 @@ WITH pool_labels AS ( poolId AS pool_id, b.poolAddress AS token_address, sum(value) AS protocol_fee_amount_raw - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_PoolRegistered') }} b + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolRegistered') }} b INNER JOIN {{ source('erc20_' + blockchain, 'evt_transfer') }} t ON t.contract_address = b.poolAddress AND t."from" = 0x0000000000000000000000000000000000000000 - AND t.to = 0xce88686553686DA562CE7Cea497CE749DA109f9F --ProtocolFeesCollector address, which is the same across all chains + AND t."to" = + CASE + WHEN '{{blockchain}}' = 'fantom' THEN 0xc6920d3a369e7c8bd1a22dbe385e11d1f7af948f + ELSE 0xce88686553686DA562CE7Cea497CE749DA109f9F + END --ProtocolFeesCollector address, which is the same across all chains except for fantom GROUP BY 1, 2, 3 ), diff --git a/macros/models/_project/balancer/balancer_token_balance_changes_daily_agg_macro.sql b/macros/models/_project/balancer/balancer_token_balance_changes_daily_agg_macro.sql index 27af2752d29..ad9cd783869 100644 --- a/macros/models/_project/balancer/balancer_token_balance_changes_daily_agg_macro.sql +++ b/macros/models/_project/balancer/balancer_token_balance_changes_daily_agg_macro.sql @@ -1,6 +1,6 @@ {% macro - balancer_token_balance_changes_daily_agg_macro( - blockchain, version + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain, version, project_decoded_as, base_spells_namespace ) %} WITH @@ -57,7 +57,7 @@ WITH contract_address AS token, decimals, bpt_price - FROM {{ ref('balancer_bpt_prices') }} + FROM {{ ref(base_spells_namespace + '_bpt_prices') }} WHERE blockchain = '{{blockchain}}' {% if is_incremental() %} AND {{ incremental_predicate('day') }} @@ -96,7 +96,7 @@ WITH token_symbol, LEAD(block_date, 1, NOW()) OVER (PARTITION BY token_address, pool_id ORDER BY block_date) AS day_of_next_change, SUM(delta_amount) AS daily_amount - FROM {{ ref('balancer_token_balance_changes') }} + FROM {{ ref(base_spells_namespace + '_token_balance_changes') }} WHERE blockchain = '{{blockchain}}' GROUP BY 1, 2, 3, 4, 5, 6 ), @@ -140,7 +140,7 @@ WITH ROW_NUMBER() OVER (PARTITION BY b.block_date, b.pool_id ORDER BY SUM(b.daily_amount_usd) ASC) AS pricing_count, --to avoid double count in pools with multiple pricing assets SUM(b.daily_amount_usd) / COALESCE(SUM(w.normalized_weight), 1) AS weighted_daily_amount_usd FROM daily_usd_balance b - LEFT JOIN {{ ref('balancer_pools_tokens_weights') }} w ON b.pool_id = w.pool_id + LEFT JOIN {{ ref(base_spells_namespace + '_pools_tokens_weights') }} w ON b.pool_id = w.pool_id AND b.token_address = w.token_address AND b.daily_amount_usd > 0 LEFT JOIN {{ ref('balancer_token_whitelist') }} q ON b.token_address = q.address @@ -166,7 +166,7 @@ WITH BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) AS pool_address, c.pool_symbol, '2' AS version, - 'ethereum' AS blockchain, + '{{blockchain}}' AS blockchain, c.pool_type, c.token_address, c.token_symbol, @@ -176,8 +176,8 @@ WITH FROM daily_usd_balance c FULL OUTER JOIN weighted_pool_amount_estimates_2 b ON c.block_date = b.block_date AND c.pool_id = b.pool_id - LEFT JOIN {{ ref('balancer_pools_tokens_weights') }} w ON b.pool_id = w.pool_id - AND w.blockchain = 'ethereum' + LEFT JOIN {{ ref(base_spells_namespace + '_pools_tokens_weights') }} w ON b.pool_id = w.pool_id + AND w.blockchain = '{{blockchain}}' AND w.version = '2' AND w.token_address = c.token_address LEFT JOIN eth_prices e ON e.day = c.block_date diff --git a/macros/models/_project/balancer/balancer_token_balance_changes_macro.sql b/macros/models/_project/balancer/balancer_token_balance_changes_macro.sql index 26feb0e2a10..4e606ed955b 100644 --- a/macros/models/_project/balancer/balancer_token_balance_changes_macro.sql +++ b/macros/models/_project/balancer/balancer_token_balance_changes_macro.sql @@ -1,6 +1,6 @@ {% macro - balancer_token_balance_changes_macro( - blockchain, version + balancer_v2_compatible_token_balance_changes_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_spell ) %} WITH pool_labels AS ( @@ -8,7 +8,7 @@ WITH pool_labels AS ( address AS pool_id, name AS pool_symbol, pool_type - FROM {{ source('labels', 'balancer_v2_pools') }} + FROM {{ pool_labels_spell }} WHERE blockchain = '{{blockchain}}' ), @@ -31,7 +31,7 @@ WITH pool_labels AS ( poolId AS pool_id, tokenIn AS token, CAST(amountIn as int256) AS delta - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_Swap') }} + FROM {{ source(project_decoded_as ~ '_' ~ blockchain, 'Vault_evt_Swap') }} {% if is_incremental() %} WHERE {{ incremental_predicate('evt_block_time') }} {% endif %} @@ -46,7 +46,7 @@ WITH pool_labels AS ( poolId AS pool_id, tokenOut AS token, -CAST(amountOut AS int256) AS delta - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_Swap') }} + FROM {{ source(project_decoded_as ~ '_' ~ blockchain, 'Vault_evt_Swap') }} {% if is_incremental() %} WHERE {{ incremental_predicate('evt_block_time') }} {% endif %} @@ -64,7 +64,7 @@ WITH pool_labels AS ( t.tokens, d.deltas, p.protocolFeeAmounts - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_PoolBalanceChanged') }} + FROM {{ source(project_decoded_as ~ '_' ~ blockchain, 'Vault_evt_PoolBalanceChanged') }} CROSS JOIN UNNEST (tokens) WITH ORDINALITY as t(tokens,i) CROSS JOIN UNNEST (deltas) WITH ORDINALITY as d(deltas,i) CROSS JOIN UNNEST (protocolFeeAmounts) WITH ORDINALITY as p(protocolFeeAmounts,i) @@ -96,7 +96,7 @@ WITH pool_labels AS ( poolId AS pool_id, token, cashDelta + managedDelta AS delta - FROM {{ source('balancer_v2_' + blockchain, 'Vault_evt_PoolBalanceManaged') }} + FROM {{ source(project_decoded_as ~ '_' ~ blockchain, 'Vault_evt_PoolBalanceManaged') }} {% if is_incremental() %} WHERE {{ incremental_predicate('evt_block_time') }} {% endif %} diff --git a/macros/models/_project/balancer/balancer_transfers_bpt_macro.sql b/macros/models/_project/balancer/balancer_transfers_bpt_macro.sql index fe05b2f9ea6..e7137266c70 100644 --- a/macros/models/_project/balancer/balancer_transfers_bpt_macro.sql +++ b/macros/models/_project/balancer/balancer_transfers_bpt_macro.sql @@ -1,6 +1,6 @@ {% macro - balancer_transfers_bpt_macro( - blockchain, version + balancer_v2_compatible_transfers_bpt_macro( + blockchain, version, project_decoded_as ) %} @@ -8,7 +8,7 @@ SELECT DISTINCT poolAddress AS pool_address FROM - {{ source('balancer_v2_' + blockchain, 'Vault_evt_PoolRegistered') }} + {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolRegistered') }} ) SELECT DISTINCT * FROM ( diff --git a/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes.sql b/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes.sql index ca58f713377..421b08d2de6 100644 --- a/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes.sql +++ b/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes.sql @@ -9,8 +9,11 @@ }} {{ - balancer_token_balance_changes_macro( + balancer_v2_compatible_token_balance_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes_daily.sql b/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes_daily.sql index c35d7b60259..2c5d83eca2a 100644 --- a/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes_daily.sql +++ b/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - balancer_token_balance_changes_daily_agg_macro( + balancer_v2_compatible_token_balance_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes.sql b/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes.sql index ab55e6e99f1..73716eb8e16 100644 --- a/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes.sql +++ b/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes.sql @@ -9,8 +9,11 @@ }} {{ - balancer_token_balance_changes_macro( + balancer_v2_compatible_token_balance_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes_daily.sql b/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes_daily.sql index 35ed123547e..6d3df850e57 100644 --- a/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes_daily.sql +++ b/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - balancer_token_balance_changes_daily_agg_macro( + balancer_v2_compatible_token_balance_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes.sql b/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes.sql index 1f35750f21d..3a5af67bc42 100644 --- a/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes.sql +++ b/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes.sql @@ -9,8 +9,11 @@ }} {{ - balancer_token_balance_changes_macro( + balancer_v2_compatible_token_balance_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes_daily.sql b/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes_daily.sql index fe24b712bee..03331f8846b 100644 --- a/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes_daily.sql +++ b/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - balancer_token_balance_changes_daily_agg_macro( + balancer_v2_compatible_token_balance_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes.sql b/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes.sql index 12b1a61ad46..5150d559de9 100644 --- a/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes.sql +++ b/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes.sql @@ -9,8 +9,11 @@ }} {{ - balancer_token_balance_changes_macro( + balancer_v2_compatible_token_balance_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes_daily.sql b/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes_daily.sql index 44aeb0ee7b8..ac035f2c59f 100644 --- a/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes_daily.sql +++ b/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - balancer_token_balance_changes_daily_agg_macro( + balancer_v2_compatible_token_balance_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes.sql b/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes.sql index e3e0177541d..63325ce0c1b 100644 --- a/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes.sql +++ b/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes.sql @@ -9,8 +9,11 @@ }} {{ - balancer_token_balance_changes_macro( + balancer_v2_compatible_token_balance_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes_daily.sql b/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes_daily.sql index 434e9b096fb..f8b030b1df3 100644 --- a/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes_daily.sql +++ b/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - balancer_token_balance_changes_daily_agg_macro( + balancer_v2_compatible_token_balance_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes.sql b/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes.sql index 39fd96a795d..d03cf281196 100644 --- a/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes.sql +++ b/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes.sql @@ -9,8 +9,11 @@ }} {{ - balancer_token_balance_changes_macro( + balancer_v2_compatible_token_balance_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes_daily.sql b/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes_daily.sql index ac9db7d6bd7..eab7f0b5282 100644 --- a/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes_daily.sql +++ b/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - balancer_token_balance_changes_daily_agg_macro( + balancer_v2_compatible_token_balance_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes.sql b/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes.sql index efbac69046b..14db781551f 100644 --- a/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes.sql +++ b/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes.sql @@ -9,8 +9,11 @@ }} {{ - balancer_token_balance_changes_macro( + balancer_v2_compatible_token_balance_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes_daily.sql b/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes_daily.sql index fa318aaec80..184c9a75f5a 100644 --- a/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes_daily.sql +++ b/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - balancer_token_balance_changes_daily_agg_macro( + balancer_v2_compatible_token_balance_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes.sql b/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes.sql index 80eff1513b7..0952527ec09 100644 --- a/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes.sql +++ b/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes.sql @@ -9,8 +9,11 @@ }} {{ - balancer_token_balance_changes_macro( + balancer_v2_compatible_token_balance_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes_daily.sql b/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes_daily.sql index 9bd7cabbb72..e51dbef7265 100644 --- a/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes_daily.sql +++ b/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - balancer_token_balance_changes_daily_agg_macro( + balancer_v2_compatible_token_balance_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_prices.sql b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_prices.sql index b97e0576b82..2f52a7d2cea 100644 --- a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_prices.sql +++ b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_prices.sql @@ -11,8 +11,11 @@ {{ - balancer_bpt_prices_macro( + balancer_v2_compatible_bpt_prices_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply.sql b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply.sql index 47781622c4e..e9d9799b37d 100644 --- a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply.sql +++ b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply.sql @@ -9,8 +9,11 @@ }} {{ - balancer_bpt_supply_macro( + balancer_v2_compatible_bpt_supply_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply_changes.sql b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply_changes.sql index b30224001c3..d36269d0be5 100644 --- a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply_changes.sql +++ b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply_changes.sql @@ -13,8 +13,11 @@ }} {{ - bpt_supply_changes_macro( + balancer_v2_compatible_bpt_supply_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply_changes_daily.sql b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply_changes_daily.sql index df606a75ceb..43df78d10f9 100644 --- a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply_changes_daily.sql +++ b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply_changes_daily.sql @@ -1,8 +1,8 @@ -{% set blockchain = 'ethereum' %} +{% set blockchain = 'arbitrum' %} {{ config( - schema = 'balancer_v2_ethereum', + schema = 'balancer_v2_arbitrum', alias = 'bpt_supply_changes_daily', materialized = 'table', file_format = 'delta' @@ -10,8 +10,10 @@ }} {{ - bpt_supply_changes_daily_agg_macro( + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_transfers_bpt.sql b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_transfers_bpt.sql index caa17acc4c5..62c27a3c900 100644 --- a/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_transfers_bpt.sql +++ b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_transfers_bpt.sql @@ -14,8 +14,9 @@ }} {{ - balancer_transfers_bpt_macro( + balancer_v2_compatible_transfers_bpt_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_prices.sql b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_prices.sql index 6b9c2d21b1d..7aa571ebaca 100644 --- a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_prices.sql +++ b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_prices.sql @@ -11,8 +11,11 @@ {{ - balancer_bpt_prices_macro( + balancer_v2_compatible_bpt_prices_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply.sql b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply.sql index 7aea9b3daa2..e54bfc0da26 100644 --- a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply.sql +++ b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply.sql @@ -11,8 +11,11 @@ }} {{ - balancer_bpt_supply_macro( + balancer_v2_compatible_bpt_supply_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply_changes.sql b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply_changes.sql index db1052cb8d8..dd75dacf9a3 100644 --- a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply_changes.sql +++ b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply_changes.sql @@ -13,8 +13,11 @@ }} {{ - bpt_supply_changes_macro( + balancer_v2_compatible_bpt_supply_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply_changes_daily.sql b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply_changes_daily.sql index 5ce53b4aa92..89bc419a859 100644 --- a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply_changes_daily.sql +++ b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - bpt_supply_changes_daily_agg_macro( + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_transfers_bpt.sql b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_transfers_bpt.sql index 1353ac03ebd..b904f58720b 100644 --- a/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_transfers_bpt.sql +++ b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_transfers_bpt.sql @@ -14,8 +14,9 @@ }} {{ - balancer_transfers_bpt_macro( + balancer_v2_compatible_transfers_bpt_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/base/balancer_v2_base_bpt_prices.sql b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_prices.sql index aa2a480b646..cfa575c00ff 100644 --- a/models/_project/balancer/bpt/base/balancer_v2_base_bpt_prices.sql +++ b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_prices.sql @@ -11,8 +11,11 @@ {{ - balancer_bpt_prices_macro( + balancer_v2_compatible_bpt_prices_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply.sql b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply.sql index 37c4a8960a6..c1890613101 100644 --- a/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply.sql +++ b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply.sql @@ -11,8 +11,11 @@ }} {{ - balancer_bpt_supply_macro( + balancer_v2_compatible_bpt_supply_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply_changes.sql b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply_changes.sql index 1d273f4e49e..db226367a56 100644 --- a/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply_changes.sql +++ b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply_changes.sql @@ -13,8 +13,11 @@ }} {{ - bpt_supply_changes_macro( + balancer_v2_compatible_bpt_supply_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply_changes_daily.sql b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply_changes_daily.sql index b90fdf94033..335e377b2ce 100644 --- a/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply_changes_daily.sql +++ b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - bpt_supply_changes_daily_agg_macro( + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/base/balancer_v2_base_transfers_bpt.sql b/models/_project/balancer/bpt/base/balancer_v2_base_transfers_bpt.sql index a6117ef8a43..742719b0fe6 100644 --- a/models/_project/balancer/bpt/base/balancer_v2_base_transfers_bpt.sql +++ b/models/_project/balancer/bpt/base/balancer_v2_base_transfers_bpt.sql @@ -14,8 +14,9 @@ }} {{ - balancer_transfers_bpt_macro( + balancer_v2_compatible_transfers_bpt_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_prices.sql b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_prices.sql index 3002cd197b6..1648061d288 100644 --- a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_prices.sql +++ b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_prices.sql @@ -11,8 +11,11 @@ {{ - balancer_bpt_prices_macro( + balancer_v2_compatible_bpt_prices_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply.sql b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply.sql index 6cdcdf3df90..84a1f35b109 100644 --- a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply.sql +++ b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply.sql @@ -11,8 +11,11 @@ }} {{ - balancer_bpt_supply_macro( + balancer_v2_compatible_bpt_supply_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply_changes.sql b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply_changes.sql index 1fa7db6b904..b936dfee98b 100644 --- a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply_changes.sql +++ b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply_changes.sql @@ -13,8 +13,11 @@ }} {{ - bpt_supply_changes_macro( + balancer_v2_compatible_bpt_supply_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply_changes_daily.sql b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply_changes_daily.sql index 74d3be91fdf..0bb15c8a787 100644 --- a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply_changes_daily.sql +++ b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply_changes_daily.sql @@ -1,8 +1,8 @@ -{% set blockchain = 'arbitrum' %} +{% set blockchain = 'ethereum' %} {{ config( - schema = 'balancer_v2_arbitrum', + schema = 'balancer_v2_ethereum', alias = 'bpt_supply_changes_daily', materialized = 'table', file_format = 'delta' @@ -10,8 +10,10 @@ }} {{ - bpt_supply_changes_daily_agg_macro( + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_transfers_bpt.sql b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_transfers_bpt.sql index 6da288b91d2..a07a16ff74d 100644 --- a/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_transfers_bpt.sql +++ b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_transfers_bpt.sql @@ -14,8 +14,9 @@ }} {{ - balancer_transfers_bpt_macro( + balancer_v2_compatible_transfers_bpt_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_prices.sql b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_prices.sql index 945bf1cfb88..cc1362a3c6b 100644 --- a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_prices.sql +++ b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_prices.sql @@ -11,8 +11,11 @@ {{ - balancer_bpt_prices_macro( + balancer_v2_compatible_bpt_prices_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply.sql b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply.sql index 95c286ad863..83728740fc2 100644 --- a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply.sql +++ b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply.sql @@ -10,8 +10,11 @@ }} {{ - balancer_bpt_supply_macro( + balancer_v2_compatible_bpt_supply_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply_changes.sql b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply_changes.sql index fd1539a9495..9a0000dac7f 100644 --- a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply_changes.sql +++ b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply_changes.sql @@ -13,8 +13,11 @@ }} {{ - bpt_supply_changes_macro( + balancer_v2_compatible_bpt_supply_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply_changes_daily.sql b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply_changes_daily.sql index 516f2e2dc0c..56a2a1cfb37 100644 --- a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply_changes_daily.sql +++ b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - bpt_supply_changes_daily_agg_macro( + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_transfers_bpt.sql b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_transfers_bpt.sql index 5322e7c894e..750bbff1ad3 100644 --- a/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_transfers_bpt.sql +++ b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_transfers_bpt.sql @@ -14,8 +14,9 @@ }} {{ - balancer_transfers_bpt_macro( + balancer_v2_compatible_transfers_bpt_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_prices.sql b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_prices.sql index 9efb7531986..c00466c71ff 100644 --- a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_prices.sql +++ b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_prices.sql @@ -11,8 +11,11 @@ {{ - balancer_bpt_prices_macro( + balancer_v2_compatible_bpt_prices_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply.sql b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply.sql index c9ae2916910..4d563e8667f 100644 --- a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply.sql +++ b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply.sql @@ -10,8 +10,11 @@ }} {{ - balancer_bpt_supply_macro( + balancer_v2_compatible_bpt_supply_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply_changes.sql b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply_changes.sql index 225b00465db..a7ea7a08470 100644 --- a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply_changes.sql +++ b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply_changes.sql @@ -13,8 +13,11 @@ }} {{ - bpt_supply_changes_macro( + balancer_v2_compatible_bpt_supply_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply_changes_daily.sql b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply_changes_daily.sql index f816df8d206..1b77fec96c0 100644 --- a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply_changes_daily.sql +++ b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - bpt_supply_changes_daily_agg_macro( + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_transfers_bpt.sql b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_transfers_bpt.sql index 094ed052ce6..206a5a6f374 100644 --- a/models/_project/balancer/bpt/optimism/balancer_v2_optimism_transfers_bpt.sql +++ b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_transfers_bpt.sql @@ -14,8 +14,9 @@ }} {{ - balancer_transfers_bpt_macro( + balancer_v2_compatible_transfers_bpt_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_prices.sql b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_prices.sql index 672e57b1946..ca1ee92c3b9 100644 --- a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_prices.sql +++ b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_prices.sql @@ -11,8 +11,11 @@ {{ - balancer_bpt_prices_macro( + balancer_v2_compatible_bpt_prices_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply.sql b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply.sql index 25a1aa12fb1..e12ba88ab1a 100644 --- a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply.sql +++ b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply.sql @@ -10,8 +10,11 @@ }} {{ - balancer_bpt_supply_macro( + balancer_v2_compatible_bpt_supply_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply_changes.sql b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply_changes.sql index 7ff8034b96b..278b8d0cf9b 100644 --- a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply_changes.sql +++ b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply_changes.sql @@ -13,8 +13,11 @@ }} {{ - bpt_supply_changes_macro( + balancer_v2_compatible_bpt_supply_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply_changes_daily.sql b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply_changes_daily.sql index 57615beb139..08f251d8e83 100644 --- a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply_changes_daily.sql +++ b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - bpt_supply_changes_daily_agg_macro( + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_transfers_bpt.sql b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_transfers_bpt.sql index 88969aed4c7..e6edae2f23a 100644 --- a/models/_project/balancer/bpt/polygon/balancer_v2_polygon_transfers_bpt.sql +++ b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_transfers_bpt.sql @@ -14,8 +14,9 @@ }} {{ - balancer_transfers_bpt_macro( + balancer_v2_compatible_transfers_bpt_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_prices.sql b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_prices.sql index 79c962604bc..40f793b1d2a 100644 --- a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_prices.sql +++ b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_prices.sql @@ -11,8 +11,11 @@ {{ - balancer_bpt_prices_macro( + balancer_v2_compatible_bpt_prices_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply.sql b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply.sql index 0b1d2932696..64cc32dc59f 100644 --- a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply.sql +++ b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply.sql @@ -10,8 +10,11 @@ }} {{ - balancer_bpt_supply_macro( + balancer_v2_compatible_bpt_supply_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply_changes.sql b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply_changes.sql index f11227e4013..af349f8a637 100644 --- a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply_changes.sql +++ b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply_changes.sql @@ -13,8 +13,11 @@ }} {{ - bpt_supply_changes_macro( + balancer_v2_compatible_bpt_supply_changes_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply_changes_daily.sql b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply_changes_daily.sql index 4e548f4bcf7..5337f4641fc 100644 --- a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply_changes_daily.sql +++ b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply_changes_daily.sql @@ -10,8 +10,10 @@ }} {{ - bpt_supply_changes_daily_agg_macro( + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' ) }} \ No newline at end of file diff --git a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_transfers_bpt.sql b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_transfers_bpt.sql index 852f3f69c46..419ee9fcb4e 100644 --- a/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_transfers_bpt.sql +++ b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_transfers_bpt.sql @@ -14,8 +14,9 @@ }} {{ - balancer_transfers_bpt_macro( + balancer_v2_compatible_transfers_bpt_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2' ) }} \ No newline at end of file diff --git a/models/_project/balancer/liquidity/arbitrum/balancer_v2_arbitrum_liquidity.sql b/models/_project/balancer/liquidity/arbitrum/balancer_v2_arbitrum_liquidity.sql index c32f49c73ac..be5479eb97d 100644 --- a/models/_project/balancer/liquidity/arbitrum/balancer_v2_arbitrum_liquidity.sql +++ b/models/_project/balancer/liquidity/arbitrum/balancer_v2_arbitrum_liquidity.sql @@ -11,8 +11,11 @@ }} {{ - balancer_liquidity_macro( + balancer_v2_compatible_liquidity_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/liquidity/avalanche_c/balancer_v2_avalanche_c_liquidity.sql b/models/_project/balancer/liquidity/avalanche_c/balancer_v2_avalanche_c_liquidity.sql index 30e2856d411..1a214679e9d 100644 --- a/models/_project/balancer/liquidity/avalanche_c/balancer_v2_avalanche_c_liquidity.sql +++ b/models/_project/balancer/liquidity/avalanche_c/balancer_v2_avalanche_c_liquidity.sql @@ -11,8 +11,11 @@ }} {{ - balancer_liquidity_macro( + balancer_v2_compatible_liquidity_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/liquidity/base/balancer_v2_base_liquidity.sql b/models/_project/balancer/liquidity/base/balancer_v2_base_liquidity.sql index 20f257ad753..16d3280253f 100644 --- a/models/_project/balancer/liquidity/base/balancer_v2_base_liquidity.sql +++ b/models/_project/balancer/liquidity/base/balancer_v2_base_liquidity.sql @@ -11,8 +11,11 @@ }} {{ - balancer_liquidity_macro( + balancer_v2_compatible_liquidity_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/liquidity/ethereum/balancer_v2_ethereum_liquidity.sql b/models/_project/balancer/liquidity/ethereum/balancer_v2_ethereum_liquidity.sql index 54efdce06c3..7f660cfce7e 100644 --- a/models/_project/balancer/liquidity/ethereum/balancer_v2_ethereum_liquidity.sql +++ b/models/_project/balancer/liquidity/ethereum/balancer_v2_ethereum_liquidity.sql @@ -12,8 +12,11 @@ {{ - balancer_liquidity_macro( + balancer_v2_compatible_liquidity_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/liquidity/gnosis/balancer_v2_gnosis_liquidity.sql b/models/_project/balancer/liquidity/gnosis/balancer_v2_gnosis_liquidity.sql index fc5885a24e0..e2c916bdf1b 100644 --- a/models/_project/balancer/liquidity/gnosis/balancer_v2_gnosis_liquidity.sql +++ b/models/_project/balancer/liquidity/gnosis/balancer_v2_gnosis_liquidity.sql @@ -11,8 +11,11 @@ }} {{ - balancer_liquidity_macro( + balancer_v2_compatible_liquidity_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/liquidity/optimism/balancer_v2_optimism_liquidity.sql b/models/_project/balancer/liquidity/optimism/balancer_v2_optimism_liquidity.sql index b34e0e3557a..dc1e410f9dc 100644 --- a/models/_project/balancer/liquidity/optimism/balancer_v2_optimism_liquidity.sql +++ b/models/_project/balancer/liquidity/optimism/balancer_v2_optimism_liquidity.sql @@ -11,8 +11,11 @@ }} {{ - balancer_liquidity_macro( + balancer_v2_compatible_liquidity_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/liquidity/polygon/balancer_v2_polygon_liquidity.sql b/models/_project/balancer/liquidity/polygon/balancer_v2_polygon_liquidity.sql index 3f0c521ade6..66c97fc627e 100644 --- a/models/_project/balancer/liquidity/polygon/balancer_v2_polygon_liquidity.sql +++ b/models/_project/balancer/liquidity/polygon/balancer_v2_polygon_liquidity.sql @@ -11,8 +11,11 @@ }} {{ - balancer_liquidity_macro( + balancer_v2_compatible_liquidity_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/liquidity/zkevm/balancer_v2_zkevm_liquidity.sql b/models/_project/balancer/liquidity/zkevm/balancer_v2_zkevm_liquidity.sql index 737b858ca3c..6a43d5c0736 100644 --- a/models/_project/balancer/liquidity/zkevm/balancer_v2_zkevm_liquidity.sql +++ b/models/_project/balancer/liquidity/zkevm/balancer_v2_zkevm_liquidity.sql @@ -11,8 +11,11 @@ }} {{ - balancer_liquidity_macro( + balancer_v2_compatible_liquidity_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/protocol_fee/arbitrum/balancer_v2_arbitrum_protocol_fee.sql b/models/_project/balancer/protocol_fee/arbitrum/balancer_v2_arbitrum_protocol_fee.sql index ffb1312dc93..10fa5d5eaf5 100644 --- a/models/_project/balancer/protocol_fee/arbitrum/balancer_v2_arbitrum_protocol_fee.sql +++ b/models/_project/balancer/protocol_fee/arbitrum/balancer_v2_arbitrum_protocol_fee.sql @@ -10,8 +10,11 @@ }} {{ - balancer_protocol_fee_macro( + balancer_v2_compatible_protocol_fee_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/protocol_fee/avalanche_c/balancer_v2_avalanche_c_protocol_fee.sql b/models/_project/balancer/protocol_fee/avalanche_c/balancer_v2_avalanche_c_protocol_fee.sql index 7e8a2bcd83c..c041090fa1e 100644 --- a/models/_project/balancer/protocol_fee/avalanche_c/balancer_v2_avalanche_c_protocol_fee.sql +++ b/models/_project/balancer/protocol_fee/avalanche_c/balancer_v2_avalanche_c_protocol_fee.sql @@ -10,8 +10,11 @@ }} {{ - balancer_protocol_fee_macro( + balancer_v2_compatible_protocol_fee_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/_project/balancer/protocol_fee/base/balancer_v2_base_protocol_fee.sql b/models/_project/balancer/protocol_fee/base/balancer_v2_base_protocol_fee.sql index 6e60543611c..c63fef06752 100644 --- a/models/_project/balancer/protocol_fee/base/balancer_v2_base_protocol_fee.sql +++ b/models/_project/balancer/protocol_fee/base/balancer_v2_base_protocol_fee.sql @@ -10,8 +10,11 @@ }} {{ - balancer_protocol_fee_macro( + balancer_v2_compatible_protocol_fee_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/protocol_fee/ethereum/balancer_v2_ethereum_protocol_fee.sql b/models/_project/balancer/protocol_fee/ethereum/balancer_v2_ethereum_protocol_fee.sql index ab3efa1a563..645c6862d33 100644 --- a/models/_project/balancer/protocol_fee/ethereum/balancer_v2_ethereum_protocol_fee.sql +++ b/models/_project/balancer/protocol_fee/ethereum/balancer_v2_ethereum_protocol_fee.sql @@ -10,8 +10,11 @@ }} {{ - balancer_protocol_fee_macro( + balancer_v2_compatible_protocol_fee_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/protocol_fee/gnosis/balancer_v2_gnosis_protocol_fee.sql b/models/_project/balancer/protocol_fee/gnosis/balancer_v2_gnosis_protocol_fee.sql index 1bfed151b87..a5c7aa73639 100644 --- a/models/_project/balancer/protocol_fee/gnosis/balancer_v2_gnosis_protocol_fee.sql +++ b/models/_project/balancer/protocol_fee/gnosis/balancer_v2_gnosis_protocol_fee.sql @@ -10,8 +10,11 @@ }} {{ - balancer_protocol_fee_macro( + balancer_v2_compatible_protocol_fee_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/protocol_fee/optimism/balancer_v2_optimism_protocol_fee.sql b/models/_project/balancer/protocol_fee/optimism/balancer_v2_optimism_protocol_fee.sql index 97967c7a252..a15e98c2fd7 100644 --- a/models/_project/balancer/protocol_fee/optimism/balancer_v2_optimism_protocol_fee.sql +++ b/models/_project/balancer/protocol_fee/optimism/balancer_v2_optimism_protocol_fee.sql @@ -10,8 +10,11 @@ }} {{ - balancer_protocol_fee_macro( + balancer_v2_compatible_protocol_fee_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/protocol_fee/polygon/balancer_v2_polygon_protocol_fee.sql b/models/_project/balancer/protocol_fee/polygon/balancer_v2_polygon_protocol_fee.sql index 543db9802d7..2b4e7824e1f 100644 --- a/models/_project/balancer/protocol_fee/polygon/balancer_v2_polygon_protocol_fee.sql +++ b/models/_project/balancer/protocol_fee/polygon/balancer_v2_polygon_protocol_fee.sql @@ -10,8 +10,11 @@ }} {{ - balancer_protocol_fee_macro( + balancer_v2_compatible_protocol_fee_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} diff --git a/models/_project/balancer/protocol_fee/zkevm/balancer_v2_zkevm_protocol_fee.sql b/models/_project/balancer/protocol_fee/zkevm/balancer_v2_zkevm_protocol_fee.sql index 59b2a38a41f..80101f6bae1 100644 --- a/models/_project/balancer/protocol_fee/zkevm/balancer_v2_zkevm_protocol_fee.sql +++ b/models/_project/balancer/protocol_fee/zkevm/balancer_v2_zkevm_protocol_fee.sql @@ -10,8 +10,11 @@ }} {{ - balancer_protocol_fee_macro( + balancer_v2_compatible_protocol_fee_macro( blockchain = blockchain, - version = '2' + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_spell = source('labels', 'balancer_v2_pools') ) }} \ No newline at end of file diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_bpt_prices.sql b/models/beethoven_x/fantom/beethoven_x_fantom_bpt_prices.sql index 26ad476e648..0ef7a185349 100644 --- a/models/beethoven_x/fantom/beethoven_x_fantom_bpt_prices.sql +++ b/models/beethoven_x/fantom/beethoven_x_fantom_bpt_prices.sql @@ -8,378 +8,12 @@ }} -WITH pool_labels AS ( - SELECT - address AS pool_id, - name AS pool_symbol, - pool_type - FROM {{ ref('labels_beethoven_x_pools_fantom') }} - WHERE blockchain = 'fantom' - ), - --- liquidity formulation, with a few simplifications, compared to liquidity spell - - prices AS ( - SELECT - date_trunc('day', minute) AS day, - contract_address AS token, - decimals, - AVG(price) AS price - FROM {{ source('prices', 'usd') }} - WHERE blockchain = 'fantom' - GROUP BY 1, 2, 3 - ), - - swaps_changes AS ( - SELECT - day, - pool_id, - token, - SUM(COALESCE(delta, INT256 '0')) AS delta - FROM - ( - SELECT - date_trunc('day', evt_block_time) AS day, - poolId AS pool_id, - tokenIn AS token, - CAST(amountIn as int256) AS delta - FROM {{ source('beethoven_x_fantom','Vault_evt_Swap') }} - - UNION ALL - - SELECT - date_trunc('day', evt_block_time) AS day, - poolId AS pool_id, - tokenOut AS token, - -CAST(amountOut AS int256) AS delta - FROM {{ source('beethoven_x_fantom','Vault_evt_Swap') }} - ) swaps - GROUP BY 1, 2, 3 - ), - - zipped_balance_changes AS ( - SELECT - date_trunc('day', evt_block_time) AS day, - poolId AS pool_id, - t.tokens, - d.deltas, - p.protocolFeeAmounts - FROM {{ source('beethoven_x_fantom','Vault_evt_PoolBalanceChanged') }} - CROSS JOIN UNNEST (tokens) WITH ORDINALITY as t(tokens,i) - CROSS JOIN UNNEST (deltas) WITH ORDINALITY as d(deltas,i) - CROSS JOIN UNNEST (protocolFeeAmounts) WITH ORDINALITY as p(protocolFeeAmounts,i) - WHERE t.i = d.i - AND d.i = p.i - ORDER BY 1, 2, 3 - ), - - balances_changes AS ( - SELECT - day, - pool_id, - tokens AS token, - deltas - CAST(protocolFeeAmounts as int256) AS delta - FROM zipped_balance_changes - ORDER BY 1, 2, 3 - ), - - managed_changes AS ( - SELECT - date_trunc('day', evt_block_time) AS day, - poolId AS pool_id, - token, - cashDelta + managedDelta AS delta - FROM {{ source('beethoven_x_fantom','Vault_evt_PoolBalanceManaged') }} - ), - - daily_delta_balance AS ( - SELECT - day, - pool_id, - token, - SUM(COALESCE(amount, INT256 '0')) AS amount - FROM - ( - SELECT - day, - pool_id, - token, - SUM(COALESCE(delta, INT256 '0')) AS amount - FROM balances_changes - GROUP BY 1, 2, 3 - - UNION ALL - - SELECT - day, - pool_id, - token, - delta AS amount - FROM - swaps_changes - - UNION ALL - - SELECT - day, - pool_id, - token, - CAST(delta AS int256) AS amount - FROM managed_changes - ) balance - GROUP BY 1, 2, 3 - ), - - cumulative_balance AS ( - SELECT - DAY, - pool_id, - token, - LEAD(DAY, 1, NOW()) OVER (PARTITION BY token, pool_id ORDER BY DAY) AS day_of_next_change, - SUM(amount) OVER (PARTITION BY pool_id, token ORDER BY DAY ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_amount - FROM daily_delta_balance - ), - - calendar AS ( - SELECT date_sequence AS day - FROM unnest(sequence(date('2021-04-21'), date(now()), interval '1' day)) as t(date_sequence) - ), - - cumulative_usd_balance AS ( - SELECT - c.day, - 'fantom' as blockchain, - b.pool_id, - b.token, - cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals)) * COALESCE(p1.price, 0) AS protocol_liquidity_usd - FROM calendar c - LEFT JOIN cumulative_balance b ON b.day <= c.day - AND c.day < b.day_of_next_change - LEFT JOIN {{ source('tokens', 'erc20') }} t ON t.contract_address = b.token - AND blockchain = 'fantom' - LEFT JOIN prices p1 ON p1.day = b.day - AND p1.token = b.token - WHERE b.token != BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) - ), - - weighted_pool_liquidity_estimates AS ( - SELECT - b.day, - b.pool_id, - q.name, - pool_type, - ROW_NUMBER() OVER (partition by b.day, b.pool_id ORDER BY SUM(b.protocol_liquidity_usd) ASC) AS pricing_count, --to avoid double count in pools with multiple pricing assets - SUM(b.protocol_liquidity_usd) / COALESCE(SUM(w.normalized_weight), 1) AS protocol_liquidity - FROM cumulative_usd_balance b - LEFT JOIN {{ ref('beethoven_x_fantom_pools_tokens_weights') }} w ON b.pool_id = w.pool_id - AND b.token = w.token_address - AND b.protocol_liquidity_usd > 0 - LEFT JOIN {{ ref('balancer_token_whitelist') }} q ON b.token = q.address - AND b.blockchain = q.chain - LEFT JOIN pool_labels p ON p.pool_id = BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) - WHERE q.name IS NOT NULL - AND p.pool_type IN ('weighted') -- filters for weighted pools with pricing assets - AND w.blockchain = 'fantom' - GROUP BY 1, 2, 3, 4 - ), - - weighted_pool_liquidity_estimates_2 AS( - SELECT e.day, - e.pool_id, - SUM(e.protocol_liquidity) / MAX(e.pricing_count) AS protocol_liquidity - FROM weighted_pool_liquidity_estimates e - GROUP BY 1,2 - ), - - tvl AS( - SELECT - c.day, - BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) AS pool_address, - 'fantom' AS blockchain, - SUM(COALESCE(b.protocol_liquidity * w.normalized_weight, c.protocol_liquidity_usd)) AS liquidity - FROM cumulative_usd_balance c - FULL OUTER JOIN weighted_pool_liquidity_estimates_2 b ON c.day = b.day - AND c.pool_id = b.pool_id - LEFT JOIN {{ ref('beethoven_x_fantom_pools_tokens_weights') }} w ON b.pool_id = w.pool_id - AND w.blockchain = 'fantom' - AND w.token_address = c.token - LEFT JOIN pool_labels p ON p.pool_id = BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) - GROUP BY 1, 2, 3 - ), - --- trade based formulation, for Linear Pools (former BPT prices spell) - - bpt_trades AS ( - SELECT * - FROM {{ source('beethoven_x_fantom','Vault_evt_Swap') }} v - LEFT JOIN pool_labels l ON bytearray_substring(v.poolId, 1, 20) = l.pool_id - WHERE v.tokenIn = bytearray_substring(v.poolId, 1, 20) OR v.tokenOut = bytearray_substring(v.poolId, 1, 20) - AND l.pool_type = 'linear' - ), - - all_trades_info AS ( - SELECT - a.evt_tx_hash AS tx_hash, - a.evt_block_time AS block_time, - a.evt_block_number AS block_number, - a.poolId AS pool_id, - bytearray_substring(a.poolId, 1, 20) AS bpt_address, - a.tokenIn AS token_in, - CAST(a.amountIn AS DOUBLE) AS amount_in, - a.tokenOut AS token_out, - CAST(a.amountOut AS DOUBLE) AS amount_out, - p1.price AS token_in_p, - COALESCE(p1.symbol, t1.symbol) AS token_in_sym, - COALESCE(p1.decimals, t1.decimals) AS token_in_decimals, - p2.price AS token_out_p, - COALESCE(p2.symbol, t2.symbol) AS token_out_sym, - COALESCE(p2.decimals, t2.decimals) AS token_out_decimals - FROM bpt_trades a - LEFT JOIN {{ source ('prices', 'usd') }} p1 ON p1.contract_address = a.tokenIn AND p1.blockchain = 'fantom' - AND p1.minute = date_trunc('minute', a.evt_block_time) - LEFT JOIN {{ source ('prices', 'usd') }} p2 ON p2.contract_address = a.tokenOut AND p2.blockchain = 'fantom' - AND p2.minute = date_trunc('minute', a.evt_block_time) - LEFT JOIN {{ source('tokens', 'erc20') }} t1 ON t1.contract_address = a.tokenIn AND t1.blockchain = 'fantom' - LEFT JOIN {{ source('tokens', 'erc20') }} t2 ON t2.contract_address = a.tokenOut AND t2.blockchain = 'fantom' - ORDER BY a.evt_block_number DESC, a.evt_index DESC - ), - - all_trades_calc_2 AS ( - SELECT *, - amount_in / POWER(10, COALESCE(token_in_decimals, 18)) AS amount_in_norm, - amount_out / POWER(10, COALESCE(token_out_decimals, 18)) AS amount_out_norm, - (amount_in / POWER(10, COALESCE(token_in_decimals, 18))) / (amount_out / POWER(10, COALESCE(token_out_decimals, 18))) AS in_out_norm_rate, - (amount_out / POWER(10, COALESCE(token_out_decimals, 18))) / (amount_in / POWER(10, COALESCE(token_in_decimals, 18))) AS out_in_norm_rate, - CASE - WHEN token_in_p IS NULL AND token_out_p IS NULL THEN NULL - ELSE COALESCE( - token_in_p, - (amount_out / POWER(10, COALESCE(token_out_decimals, 18))) / (amount_in / POWER(10, COALESCE(token_in_decimals, 18))) * token_out_p - ) - END AS token_in_price, - CASE - WHEN token_in_p IS NULL AND token_out_p IS NULL THEN NULL - ELSE COALESCE( - token_out_p, - (amount_in / POWER(10, COALESCE(token_in_decimals, 18))) / (amount_out / POWER(10, COALESCE(token_out_decimals, 18))) * token_in_p - ) - END AS token_out_price - FROM all_trades_info - ), - - unique_tx_token_price AS ( - SELECT - distinct - tx_hash, - token, - AVG(token_price) OVER(PARTITION BY tx_hash, token) AS avg_price - FROM ( - SELECT tx_hash, token_in AS token, token_in_price AS token_price - FROM all_trades_calc_2 - UNION ALL - SELECT tx_hash, token_out AS token, token_out_price AS token_price - FROM all_trades_calc_2 - ) - - ORDER BY 1,2 - ), - - backfill_pricing_1 AS ( - SELECT - c2.block_time, - c2.tx_hash, - c2.bpt_address, - c2.token_in, - c2.in_out_norm_rate, - COALESCE(c2.token_in_price, u1.avg_price) AS token_in_price, - c2.token_out, - c2.out_in_norm_rate, - COALESCE(c2.token_out_price, u2.avg_price) AS token_out_price - FROM all_trades_calc_2 c2 - LEFT JOIN unique_tx_token_price u1 ON u1.tx_hash = c2.tx_hash AND u1.token = c2.token_in - LEFT JOIN unique_tx_token_price u2 ON u2.tx_hash = c2.tx_hash AND u2.token = c2.token_out - ), - - backfill_pricing_2 AS ( - SELECT - block_time, - tx_hash, - bpt_address AS contract_address, - token_in, - COALESCE(token_in_price, (out_in_norm_rate * token_out_price)) AS token_in_price, - token_out, - COALESCE(token_out_price, (in_out_norm_rate * token_in_price)) AS token_out_price, - in_out_norm_rate, - out_in_norm_rate - FROM backfill_pricing_1 - ), - - trade_price_formulation AS ( - SELECT - date_trunc('day', block_time) AS day, - contract_address, - approx_percentile(price, 0.5) FILTER (WHERE is_finite(price)) AS median_price - FROM ( - SELECT block_time, contract_address, token_in_price AS price - FROM backfill_pricing_2 b2 WHERE b2.contract_address = b2.token_in - UNION - SELECT block_time, contract_address, token_out_price AS price - FROM backfill_pricing_2 b2 WHERE b2.contract_address = b2.token_out - ) - GROUP BY 1, 2 - ), - - trade_price_formulation_2 AS( - SELECT - day, - contract_address, - CASE - WHEN median_price IS NOT NULL THEN median_price - WHEN LEAD(median_price) OVER(PARTITION BY contract_address ORDER BY day DESC) IS NOT NULL - THEN LEAD(median_price) OVER(PARTITION BY contract_address ORDER BY day DESC) - WHEN LAG(median_price) OVER(PARTITION BY contract_address ORDER BY day DESC) IS NOT NULL - THEN LAG(median_price) OVER(PARTITION BY contract_address ORDER BY day DESC) - ELSE approx_percentile(median_price, 0.5) OVER( - PARTITION BY contract_address ORDER BY day - ROWS BETWEEN 10 PRECEDING AND 10 FOLLOWING - ) - END AS median_price - FROM trade_price_formulation - ), - - price_formulation AS( - SELECT - day, - contract_address, - median_price - FROM ( - SELECT - day, - contract_address, - median_price, - AVG(median_price) OVER (PARTITION BY contract_address) AS avg_median_price - FROM trade_price_formulation - ) subquery - WHERE median_price < avg_median_price * 2 --removes outliers - GROUP BY 1, 2, 3 +{{ + balancer_v2_compatible_bpt_prices_macro( + blockchain = 'fantom', + version = '2', + project_decoded_as = 'beethoven_x', + base_spells_namespace = 'beethoven_x_fantom', + pool_labels_spell = ref('labels_beethoven_x_pools_fantom') ) - - SELECT - l.day, - l.blockchain, - 18 AS decimals, - l.pool_address AS contract_address, - pl.pool_type, - CASE WHEN pl.pool_type = 'linear' AND median_price IS NOT NULL - THEN p.median_price - WHEN l.liquidity = 0 AND median_price IS NOT NULL - THEN p.median_price - ELSE l.liquidity / s.supply - END AS bpt_price - FROM tvl l - LEFT JOIN {{ ref('beethoven_x_fantom_bpt_supply') }} s ON l.pool_address = s.token_address - AND l.blockchain = s.blockchain - AND l.day = s.day - LEFT JOIN price_formulation p ON p.day = l.day AND p.contract_address = l.pool_address - LEFT JOIN pool_labels pl ON pl.pool_id = l.pool_address - WHERE supply > 1 \ No newline at end of file +}} \ No newline at end of file diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply.sql b/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply.sql index d9c665f3261..515a2738c5f 100644 --- a/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply.sql +++ b/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply.sql @@ -6,133 +6,12 @@ ) }} -WITH pool_labels AS ( - SELECT * FROM ( - SELECT - address, - name, - pool_type, - ROW_NUMBER() OVER (PARTITION BY address ORDER BY MAX(updated_at) DESC) AS num - FROM {{ ref('labels_beethoven_x_pools_fantom') }} - WHERE blockchain = 'fantom' - GROUP BY 1, 2, 3) - WHERE num = 1 - ), - - -- Extract mints and burns from transfers - transfers AS ( - SELECT - block_date AS day, - contract_address AS token, - COALESCE(SUM(CASE WHEN t."from" = 0x0000000000000000000000000000000000000000 THEN value / POWER(10, 18) ELSE 0 END), 0) AS mints, - COALESCE(SUM(CASE WHEN t.to = 0x0000000000000000000000000000000000000000 THEN value / POWER(10, 18) ELSE 0 END), 0) AS burns - FROM {{ ref('beethoven_x_fantom_transfers_bpt') }} t - WHERE blockchain = 'fantom' - GROUP BY 1, 2 - ), - - -- Calculate token balances over time - balances AS ( - SELECT - day, - token, - LEAD(DAY, 1, NOW()) OVER (PARTITION BY token ORDER BY DAY) AS day_of_next_change, - SUM(COALESCE(mints, 0) - COALESCE(burns, 0)) OVER (PARTITION BY token ORDER BY DAY ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS supply - FROM transfers - ), - - -- Extract preminted BPTs data - premints_1 AS ( - SELECT - poolId AS pool_id, - t.token, - d.delta, - ROW_NUMBER() OVER (PARTITION BY poolId ORDER BY evt_block_time ASC) AS rn - FROM {{ source('beethoven_x_fantom', 'Vault_evt_PoolBalanceChanged') }} pb - CROSS JOIN UNNEST (pb.deltas) WITH ORDINALITY d(delta, i) - CROSS JOIN UNNEST (pb.tokens) WITH ORDINALITY t(token, i) - WHERE d.i = t.i - AND BYTEARRAY_SUBSTRING(poolId, 1, 20) = t.token - ORDER BY 1 DESC - ), - - -- Select the first row for each pool, which counts as the preminted tokens - premints_2 AS ( - SELECT - * - FROM premints_1 - WHERE rn = 1 - ), - - -- Calculate preminted BPTs based on pool type - premints AS ( - SELECT - p.address AS bpt, - CASE WHEN pool_type IN ('linear') THEN CAST('5192296858534827628530496329220095' AS INT256) / POWER(10, 18) - WHEN pool_type IN ('stable') THEN CAST(m.delta AS INT256) / POWER(10, 18) - ELSE 0 - END AS preminted_bpts - FROM pool_labels p - LEFT JOIN premints_2 m ON p.address = BYTEARRAY_SUBSTRING(m.pool_id, 1, 20) - ), - - -- Calculating Joins(mint) and Exits(burn) via Swap - joins AS ( - SELECT - DATE_TRUNC('day', evt_block_time) AS block_date, - tokenOut, - pool_type, - CASE WHEN pool_type IN ('weighted') - THEN 0 - ELSE SUM(amountOut / POWER(10, 18)) - END AS ajoins - FROM {{ source('beethoven_x_fantom', 'Vault_evt_Swap') }} - LEFT JOIN pool_labels ON BYTEARRAY_SUBSTRING(poolId, 1, 20) = address - WHERE tokenOut = BYTEARRAY_SUBSTRING(poolId, 1, 20) - GROUP BY 1, 2, 3 - ), - - exits AS ( - SELECT - DATE_TRUNC('day', evt_block_time) AS block_date, - tokenIn, - pool_type, - CASE WHEN pool_type IN ('weighted') - THEN 0 - ELSE SUM(amountIn / POWER(10, 18)) - END AS aexits - FROM {{ source('beethoven_x_fantom', 'Vault_evt_Swap') }} - LEFT JOIN pool_labels ON BYTEARRAY_SUBSTRING(poolId, 1, 20) = address - WHERE tokenIn = BYTEARRAY_SUBSTRING(poolId, 1, 20) - GROUP BY 1, 2, 3 - ), - - joins_and_exits AS ( - SELECT - j.block_date, - j.tokenOut AS bpt, - SUM(COALESCE(ajoins, 0) - COALESCE(aexits, 0)) OVER (PARTITION BY j.tokenOut ORDER BY j.block_date ASC) AS adelta - FROM joins j - FULL OUTER JOIN exits e ON j.block_date = e.block_date AND e.tokenIn = j.tokenOut - ), - - calendar AS ( - SELECT - date_sequence AS day - FROM unnest(sequence(date('2021-04-21'), date(now()), interval '1' day)) as t(date_sequence) +{{ + balancer_v2_compatible_bpt_supply_macro( + blockchain = 'fantom', + version = '2', + project_decoded_as = 'beethoven_x', + base_spells_namespace = 'beethoven_x_fantom', + pool_labels_spell = ref('labels_beethoven_x_pools_fantom') ) - - SELECT - c.day, - l.pool_type, - 'fantom' as blockchain, - b.token AS token_address, - COALESCE(SUM(b.supply - COALESCE(preminted_bpts, 0) + COALESCE(adelta, 0)),0) AS supply - FROM calendar c - LEFT JOIN balances b ON b.day <= c.day AND c.day < b.day_of_next_change - LEFT JOIN joins_and_exits j ON c.day = j.block_date AND b.token = j.bpt - LEFT JOIN premints p ON b.token = p.bpt - LEFT JOIN pool_labels l ON b.token = l.address - WHERE l.pool_type IN ('weighted', 'LBP', 'investment', 'stable', 'linear', 'ECLP', 'managed', 'FX') - GROUP BY 1, 2, 3, 4 - HAVING SUM(b.supply - COALESCE(preminted_bpts, 0) + COALESCE(adelta, 0)) >= 0 --simple filter to remove outliers +}} \ No newline at end of file diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply_changes.sql b/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply_changes.sql new file mode 100644 index 00000000000..0df2a9446ef --- /dev/null +++ b/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply_changes.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'beethoven_x_fantom', + 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')] + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_changes_macro( + blockchain = 'fantom', + version = '2', + project_decoded_as = 'beethoven_x', + base_spells_namespace = 'beethoven_x_fantom', + pool_labels_spell = ref('labels_beethoven_x_pools_fantom') + ) +}} \ No newline at end of file diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply_changes_daily.sql b/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply_changes_daily.sql new file mode 100644 index 00000000000..1155ae7afdd --- /dev/null +++ b/models/beethoven_x/fantom/beethoven_x_fantom_bpt_supply_changes_daily.sql @@ -0,0 +1,17 @@ +{{ + config( + schema = 'beethoven_x_fantom', + alias = 'bpt_supply_changes_daily', + materialized = 'table', + file_format = 'delta' + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_changes_daily_agg_macro( + blockchain = 'fantom', + version = '2', + project_decoded_as = 'beethoven_x', + base_spells_namespace = 'beethoven_x_fantom' + ) +}} \ No newline at end of file diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_liquidity.sql b/models/beethoven_x/fantom/beethoven_x_fantom_liquidity.sql index 3190dd21fa3..c31ac7bbb3d 100644 --- a/models/beethoven_x/fantom/beethoven_x_fantom_liquidity.sql +++ b/models/beethoven_x/fantom/beethoven_x_fantom_liquidity.sql @@ -11,6 +11,7 @@ ) }} + WITH pool_labels AS ( SELECT address AS pool_id, @@ -209,13 +210,17 @@ WITH pool_labels AS ( c.pool_id, BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) AS pool_address, p.pool_symbol, + '2' AS version, 'fantom' AS blockchain, + p.pool_type, c.token AS token_address, c.token_symbol, c.token_balance_raw, c.token_balance, COALESCE(b.protocol_liquidity * w.normalized_weight, c.protocol_liquidity_usd) AS protocol_liquidity_usd, - COALESCE(b.protocol_liquidity * w.normalized_weight, c.protocol_liquidity_usd)/e.eth_price AS protocol_liquidity_eth + COALESCE(b.protocol_liquidity * w.normalized_weight, c.protocol_liquidity_usd)/e.eth_price AS protocol_liquidity_eth, + COALESCE(b.protocol_liquidity * w.normalized_weight, c.protocol_liquidity_usd) AS pool_liquidity_usd, + COALESCE(b.protocol_liquidity * w.normalized_weight, c.protocol_liquidity_usd)/e.eth_price AS pool_liquidity_eth FROM cumulative_usd_balance c FULL OUTER JOIN weighted_pool_liquidity_estimates_2 b ON c.day = b.day AND c.pool_id = b.pool_id @@ -223,4 +228,4 @@ WITH pool_labels AS ( AND w.blockchain = 'fantom' AND w.token_address = c.token LEFT JOIN eth_prices e ON e.day = c.day - LEFT JOIN pool_labels p ON p.pool_id = BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) + LEFT JOIN pool_labels p ON p.pool_id = BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) \ No newline at end of file diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_protocol_fee.sql b/models/beethoven_x/fantom/beethoven_x_fantom_protocol_fee.sql index a41f2474d8b..fc6b1a20fa4 100644 --- a/models/beethoven_x/fantom/beethoven_x_fantom_protocol_fee.sql +++ b/models/beethoven_x/fantom/beethoven_x_fantom_protocol_fee.sql @@ -7,148 +7,13 @@ ) }} -WITH pool_labels AS ( - SELECT * FROM ( - SELECT - address, - name, - pool_type, - ROW_NUMBER() OVER (PARTITION BY address ORDER BY MAX(updated_at) DESC) AS num - FROM {{ ref('labels_beethoven_x_pools_fantom') }} - GROUP BY 1, 2, 3) - WHERE num = 1 - ), +{{ + balancer_v2_compatible_protocol_fee_macro( + blockchain = 'fantom', + version = '2', + project_decoded_as = 'beethoven_x', + base_spells_namespace = 'beethoven_x_fantom', + pool_labels_spell = ref('labels_beethoven_x_pools_fantom') - prices AS ( - SELECT - date_trunc('day', minute) AS day, - contract_address AS token, - decimals, - AVG(price) AS price - FROM {{ source('prices', 'usd') }} - WHERE blockchain = 'fantom' - GROUP BY 1, 2, 3 - - ), - - dex_prices_1 AS ( - SELECT - date_trunc('day', hour) AS DAY, - contract_address AS token, - approx_percentile(median_price, 0.5) AS price, - sum(sample_size) AS sample_size - FROM {{ source('dex', 'prices') }} - GROUP BY 1, 2 - HAVING sum(sample_size) > 3 - ), - - dex_prices_2 AS( - SELECT - day, - token, - price, - lag(price) OVER(PARTITION BY token ORDER BY day) AS previous_price - FROM dex_prices_1 - ), - - dex_prices AS ( - SELECT - day, - token, - price, - LEAD(DAY, 1, NOW()) OVER (PARTITION BY token ORDER BY DAY) AS day_of_next_change - FROM dex_prices_2 - WHERE (price < previous_price * 1e4 AND price > previous_price / 1e4) - ), - - bpt_prices_1 AS ( --special calculation for this spell, in order to achieve completeness without relying on prices.usd - SELECT - l.day, - s.token_address AS token, - 18 AS decimals, - SUM(protocol_liquidity_usd / supply) AS price - FROM {{ ref('beethoven_x_fantom_liquidity') }} l - LEFT JOIN {{ ref('beethoven_x_fantom_bpt_supply') }} s ON s.token_address = l.pool_address - AND l.blockchain = s.blockchain AND s.day = l.day AND s.supply > 0 - WHERE l.blockchain = 'fantom' - GROUP BY 1, 2, 3 - ), - - bpt_prices AS ( - SELECT - day, - token, - decimals, - price, - LEAD(DAY, 1, NOW()) OVER (PARTITION BY token ORDER BY DAY) AS day_of_next_change - FROM bpt_prices_1 - ), - - daily_protocol_fee_collected AS ( - SELECT - date_trunc('day', evt_block_time) AS day, - poolId AS pool_id, - token AS token_address, - SUM(protocol_fees) AS protocol_fee_amount_raw - FROM {{ source('beethoven_x_fantom', 'Vault_evt_PoolBalanceChanged') }} b - CROSS JOIN unnest("protocolFeeAmounts", "tokens") AS t(protocol_fees, token) - GROUP BY 1, 2, 3 - - UNION ALL - - SELECT - date_trunc('day', t.evt_block_time) AS day, - poolId AS pool_id, - b.poolAddress AS token_address, - sum(value) AS protocol_fee_amount_raw - FROM {{ source('beethoven_x_fantom', 'Vault_evt_PoolRegistered') }} b - INNER JOIN {{ source('erc20_fantom', 'evt_transfer') }} t - ON t.contract_address = b.poolAddress - AND t."from" = 0x0000000000000000000000000000000000000000 - AND t.to = 0xc6920d3a369e7c8bd1a22dbe385e11d1f7af948f - GROUP BY 1, 2, 3 - ), - - decorated_protocol_fee AS ( - SELECT - d.day, - d.pool_id, - d.token_address, - t.symbol AS token_symbol, - SUM(d.protocol_fee_amount_raw) AS token_amount_raw, - SUM(d.protocol_fee_amount_raw / power(10, COALESCE(t.decimals,p1.decimals, p3.decimals))) AS token_amount, - SUM(COALESCE(p1.price, p2.price, p3.price) * protocol_fee_amount_raw / POWER(10, COALESCE(t.decimals,p1.decimals, p3.decimals))) AS protocol_fee_collected_usd - FROM daily_protocol_fee_collected d - LEFT JOIN prices p1 - ON p1.token = d.token_address - AND p1.day = d.day - LEFT JOIN dex_prices p2 - ON p2.token = d.token_address - AND p2.day = d.day - LEFT JOIN bpt_prices p3 - ON p3.token = d.token_address - AND p3.day <= d.day - AND d.day < p3.day_of_next_change - LEFT JOIN {{ source('tokens', 'erc20') }} t - ON t.contract_address = d.token_address - AND t.blockchain = 'fantom' - GROUP BY 1, 2, 3, 4 ) - - - SELECT - f.day, - f.pool_id, - BYTEARRAY_SUBSTRING(f.pool_id,1,20) as pool_address, - l.name AS pool_symbol, - 'fantom' as blockchain, - l.pool_type, - f.token_address, - f.token_symbol, - SUM(f.token_amount_raw) as token_amount_raw, - SUM(f.token_amount) as token_amount, - SUM(f.protocol_fee_collected_usd) as protocol_fee_collected_usd - FROM decorated_protocol_fee f - LEFT JOIN pool_labels l - ON BYTEARRAY_SUBSTRING(f.pool_id,1,20) = l.address - GROUP BY 1, 2, 3, 4, 5, 6, 7, 8 \ No newline at end of file +}} \ No newline at end of file diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_schema.yml b/models/beethoven_x/fantom/beethoven_x_fantom_schema.yml index a1263080140..73a6025c8b7 100644 --- a/models/beethoven_x/fantom/beethoven_x_fantom_schema.yml +++ b/models/beethoven_x/fantom/beethoven_x_fantom_schema.yml @@ -48,8 +48,11 @@ models: - 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' @@ -61,6 +64,10 @@ models: 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: beethoven_x_fantom_protocol_fee meta: @@ -83,6 +90,8 @@ models: - name: pool_address - name: pool_symbol - name: blockchain + - name: version + - name: pool_type - name: token_address - name: token_symbol - name: token_amount_raw @@ -91,6 +100,12 @@ models: 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: beethoven_x_fantom_bpt_supply meta: @@ -111,6 +126,7 @@ models: - name: day - name: pool_type - name: blockchain + - name: version - name: token_address - name: supply @@ -131,9 +147,11 @@ models: - contract_address columns: - name: blockchain + - name: version - name: day - name: decimals - name: contract_address + - name: pool_type - name: bpt_price - name: beethoven_x_fantom_transfers_bpt @@ -163,3 +181,150 @@ models: - name: from - name: to - name: value + + - name: beethoven_x_fantom_token_balance_changes + meta: + blockchain: fantom + project: beethoven_x + contributors: viniabussafi + config: + tags: ['fantom', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Beethoven X Pools. + 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: beethoven_x_fantom_token_balance_changes_daily + meta: + blockchain: fantom + project: beethoven_x + contributors: viniabussafi + config: + tags: ['fantom', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Beethoven X Pools, grouped by day. + 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: beethoven_x_fantom_bpt_supply_changes + meta: + blockchain: fantom + project: beethoven_x + contributors: viniabussafi + config: + tags: ['fantom', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events on Beethoven X. + 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: beethoven_x_fantom_bpt_supply_changes_daily + meta: + blockchain: fantom + project: beethoven_x + contributors: viniabussafi + config: + tags: ['fantom', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events on Beethoven X, grouped by day + 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" diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_token_balance_changes.sql b/models/beethoven_x/fantom/beethoven_x_fantom_token_balance_changes.sql new file mode 100644 index 00000000000..5c5b4b923e8 --- /dev/null +++ b/models/beethoven_x/fantom/beethoven_x_fantom_token_balance_changes.sql @@ -0,0 +1,17 @@ +{{ config( + schema = 'beethoven_x_fantom', + alias = 'token_balance_changes', + materialized = 'table', + file_format = 'delta' + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_macro( + blockchain = 'fantom', + version = '2', + project_decoded_as = 'beethoven_x', + base_spells_namespace = 'beethoven_x_fantom', + pool_labels_spell = ref('labels_beethoven_x_pools_fantom') + ) +}} \ No newline at end of file diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_token_balance_changes_daily.sql b/models/beethoven_x/fantom/beethoven_x_fantom_token_balance_changes_daily.sql new file mode 100644 index 00000000000..181974c2e7a --- /dev/null +++ b/models/beethoven_x/fantom/beethoven_x_fantom_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{{ + config( + schema = 'beethoven_x_fantom', + alias = 'token_balance_changes_daily', + materialized = 'table', + file_format = 'delta' + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = 'fantom', + version = '2', + project_decoded_as = 'beethoven_x', + base_spells_namespace = 'beethoven_x_fantom' + ) +}} \ No newline at end of file diff --git a/models/beethoven_x/fantom/beethoven_x_fantom_transfers_bpt.sql b/models/beethoven_x/fantom/beethoven_x_fantom_transfers_bpt.sql index 6d6e33b2ac5..1d287d4c9b1 100644 --- a/models/beethoven_x/fantom/beethoven_x_fantom_transfers_bpt.sql +++ b/models/beethoven_x/fantom/beethoven_x_fantom_transfers_bpt.sql @@ -11,31 +11,10 @@ ) }} - WITH registered_pools AS ( - SELECT - DISTINCT poolAddress AS pool_address - FROM - {{ source('beethoven_x_fantom', 'Vault_evt_PoolRegistered') }} +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = 'fantom', + version = '2', + project_decoded_as = 'beethoven_x' ) - - SELECT DISTINCT * FROM ( - SELECT - 'fantom' AS blockchain, - transfer.contract_address, - transfer.evt_tx_hash, - transfer.evt_index, - transfer.evt_block_time, - TRY_CAST(date_trunc('DAY', transfer.evt_block_time) AS date) AS block_date, - TRY_CAST(date_trunc('MONTH', transfer.evt_block_time) AS date) AS block_month, - transfer.evt_block_number, - transfer."from", - transfer.to, - transfer.value - FROM {{ source('erc20_fantom', 'evt_transfer') }} transfer - INNER JOIN registered_pools p ON p.pool_address = transfer.contract_address - {% if not is_incremental() %} - WHERE transfer.evt_block_time >= TIMESTAMP '2021-08-26' - {% endif %} - {% if is_incremental() %} - WHERE {{ incremental_predicate('evt_block_time') }} - {% endif %} ) transfers \ No newline at end of file +}} \ No newline at end of file