diff --git a/dbt_subprojects/dex/models/_projects/balancer/labels/_schema.yml b/dbt_subprojects/dex/models/_projects/balancer/labels/_schema.yml index c9b3bc91415..9ee6011a6dc 100644 --- a/dbt_subprojects/dex/models/_projects/balancer/labels/_schema.yml +++ b/dbt_subprojects/dex/models/_projects/balancer/labels/_schema.yml @@ -338,7 +338,7 @@ models: project: balancer_v3 contributors: balancerlabs, viniabussafi config: - tags: ['labels', 'zkevm', 'balancer', 'pools'] + tags: ['labels', 'gnosis', 'balancer', 'pools'] description: 'Balancer V3 liquidity pools created on Gnosis.' data_tests: - dbt_utils.unique_combination_of_columns: @@ -356,6 +356,55 @@ models: - *model_name - *label_type + - name: labels_balancer_v3_pools_arbitrum + meta: + blockchain: arbitrum + sector: labels + project: balancer_v3 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'arbitrum', 'balancer', 'pools'] + description: 'Balancer V3 liquidity pools created on Arbitrum.' + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - address + columns: + - *blockchain + - *address + - *name + - *category + - *contributor + - *source + - *created_at + - *updated_at + - *model_name + - *label_type + + - name: labels_balancer_v3_pools_base + meta: + blockchain: base + sector: labels + project: balancer_v3 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'base', 'balancer', 'pools'] + description: 'Balancer V3 liquidity pools created on Base.' + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - address + columns: + - *blockchain + - *address + - *name + - *category + - *contributor + - *source + - *created_at + - *updated_at + - *model_name + - *label_type - name: labels_balancer_v3_pools meta: diff --git a/dbt_subprojects/dex/models/_projects/balancer/labels/arbitrum/labels_balancer_v3_pools_arbitrum.sql b/dbt_subprojects/dex/models/_projects/balancer/labels/arbitrum/labels_balancer_v3_pools_arbitrum.sql new file mode 100644 index 00000000000..78594dc8bb6 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/balancer/labels/arbitrum/labels_balancer_v3_pools_arbitrum.sql @@ -0,0 +1,100 @@ +{{config( + schema = 'labels', + alias = 'balancer_v3_pools_arbitrum', + post_hook = '{{ expose_spells(\'["arbitrum"]\', + "sector", + "labels", + \'["viniabussafi"]\') }}' +)}} + +WITH token_data AS ( + SELECT + pool, + ARRAY_AGG(FROM_HEX(json_extract_scalar(token, '$.token')) ORDER BY token_index) AS tokens + FROM ( + SELECT + pool, + tokenConfig, + SEQUENCE(1, CARDINALITY(tokenConfig)) AS token_index_array + FROM {{ source('balancer_v3_arbitrum', 'Vault_evt_PoolRegistered') }} + ) AS pool_data + CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index) + GROUP BY 1 + ), + + pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / POWER(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.pool AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_arbitrum', 'WeightedPoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'stable' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_arbitrum', 'StablePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + ) zip + ), + + settings AS ( + SELECT + pool_id, + coalesce(t.symbol, '?') AS token_symbol, + normalized_weight, + p.symbol AS pool_symbol, + p.pool_type + FROM pools p + LEFT JOIN {{ source('tokens', 'erc20') }} t ON p.token_address = t.contract_address + AND t.blockchain = 'arbitrum' + ) + +SELECT + 'arbitrum' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable') + THEN lower(pool_symbol) + ELSE lower(concat(array_join(array_agg(token_symbol ORDER BY token_symbol), '/'), ' ', + array_join(array_agg(cast(norm_weight AS varchar) ORDER BY token_symbol), '/'))) + END AS name, + pool_type, + 'balancer_v3_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP'2024-12-01 00:00' AS created_at, + now() AS updated_at, + 'balancer_v3_pools_arbitrum' AS model_name, + 'identifier' AS label_type +FROM ( + SELECT + s1.pool_id, + token_symbol, + pool_symbol, + cast(100 * normalized_weight AS integer) AS norm_weight, + pool_type + FROM settings s1 + GROUP BY s1.pool_id, token_symbol, pool_symbol, normalized_weight, pool_type +) s +GROUP BY pool_id, pool_symbol, pool_type +ORDER BY 1 \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/balancer/labels/base/labels_balancer_v3_pools_base.sql b/dbt_subprojects/dex/models/_projects/balancer/labels/base/labels_balancer_v3_pools_base.sql new file mode 100644 index 00000000000..55a9624bfe3 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/balancer/labels/base/labels_balancer_v3_pools_base.sql @@ -0,0 +1,100 @@ +{{config( + schema = 'labels', + alias = 'balancer_v3_pools_ethereum', + post_hook = '{{ expose_spells(\'["ethereum"]\', + "sector", + "labels", + \'["viniabussafi"]\') }}' +)}} + +WITH token_data AS ( + SELECT + pool, + ARRAY_AGG(FROM_HEX(json_extract_scalar(token, '$.token')) ORDER BY token_index) AS tokens + FROM ( + SELECT + pool, + tokenConfig, + SEQUENCE(1, CARDINALITY(tokenConfig)) AS token_index_array + FROM {{ source('balancer_v3_ethereum', 'Vault_evt_PoolRegistered') }} + ) AS pool_data + CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index) + GROUP BY 1 + ), + + pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / POWER(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.pool AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_ethereum', 'WeightedPoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'stable' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_ethereum', 'StablePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + ) zip + ), + + settings AS ( + SELECT + pool_id, + coalesce(t.symbol, '?') AS token_symbol, + normalized_weight, + p.symbol AS pool_symbol, + p.pool_type + FROM pools p + LEFT JOIN {{ source('tokens', 'erc20') }} t ON p.token_address = t.contract_address + AND t.blockchain = 'ethereum' + ) + +SELECT + 'ethereum' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable') + THEN lower(pool_symbol) + ELSE lower(concat(array_join(array_agg(token_symbol ORDER BY token_symbol), '/'), ' ', + array_join(array_agg(cast(norm_weight AS varchar) ORDER BY token_symbol), '/'))) + END AS name, + pool_type, + 'balancer_v3_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP'2024-12-01 00:00' AS created_at, + now() AS updated_at, + 'balancer_v3_pools_ethereum' AS model_name, + 'identifier' AS label_type +FROM ( + SELECT + s1.pool_id, + token_symbol, + pool_symbol, + cast(100 * normalized_weight AS integer) AS norm_weight, + pool_type + FROM settings s1 + GROUP BY s1.pool_id, token_symbol, pool_symbol, normalized_weight, pool_type +) s +GROUP BY pool_id, pool_symbol, pool_type +ORDER BY 1 \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/balancer/labels/labels_balancer_v3_pools.sql b/dbt_subprojects/dex/models/_projects/balancer/labels/labels_balancer_v3_pools.sql index 1e9e933869d..bf4fb27ae11 100644 --- a/dbt_subprojects/dex/models/_projects/balancer/labels/labels_balancer_v3_pools.sql +++ b/dbt_subprojects/dex/models/_projects/balancer/labels/labels_balancer_v3_pools.sql @@ -1,7 +1,7 @@ {{config( schema = 'labels', alias = 'balancer_v3_pools', - post_hook='{{ expose_spells(\'["ethereum", "gnosis"]\', + post_hook='{{ expose_spells(\'["arbitrum", "base", "ethereum", "gnosis"]\', "sector", "labels", \'["balancerlabs", "viniabussafi"]\') }}')}} @@ -9,3 +9,7 @@ SELECT * FROM {{ ref('labels_balancer_v3_pools_ethereum') }} UNION SELECT * FROM {{ ref('labels_balancer_v3_pools_gnosis') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v3_pools_arbitrum') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v3_pools_base') }} diff --git a/sources/balancer/arbitrum/balancer_arbitrum_sources.yml b/sources/balancer/arbitrum/balancer_arbitrum_sources.yml index dd45a15e521..bee53f663cf 100644 --- a/sources/balancer/arbitrum/balancer_arbitrum_sources.yml +++ b/sources/balancer/arbitrum/balancer_arbitrum_sources.yml @@ -186,4 +186,36 @@ sources: - name: assetManager description: 'Address of the contract which managed the asset from the vault' + - name: balancer_v3_arbitrum + description: > + Decoded tables related to Balancer V3, an automated portfolio manager and trading platform, on Arbitrum. + tables: + - name: Vault_evt_PoolRegistered + + - name: WeightedPoolFactory_evt_PoolCreated + + - name: WeightedPoolFactory_call_create + + - name: Vault_evt_LiquidityAdded + + - name: Vault_evt_LiquidityRemoved + + - name: StablePoolFactory_evt_PoolCreated + + - name: StablePoolFactory_call_create + + - name: Vault_evt_Swap + + - name: ProtocolFeeController_evt_ProtocolSwapFeeCollected + + - name: ProtocolFeeController_evt_ProtocolYieldFeeCollected + + - name: Vault_evt_Wrap + + - name: Vault_evt_Unwrap + + - name: Vault_evt_LiquidityAddedToBuffer + + - name: Vault_evt_LiquidityRemovedFromBuffer + - name: Vault_evt_SwapFeePercentageChanged diff --git a/sources/balancer/base/balancer_base_sources.yml b/sources/balancer/base/balancer_base_sources.yml index d4d39149ac0..8df66c66ab3 100644 --- a/sources/balancer/base/balancer_base_sources.yml +++ b/sources/balancer/base/balancer_base_sources.yml @@ -145,3 +145,36 @@ sources: - name: assetManager description: 'Address of the contract which managed the asset from the vault' + - name: balancer_v3_base + description: > + Decoded tables related to Balancer V3, an automated portfolio manager and trading platform, on Base. + tables: + - name: Vault_evt_PoolRegistered + + - name: WeightedPoolFactory_evt_PoolCreated + + - name: WeightedPoolFactory_call_create + + - name: Vault_evt_LiquidityAdded + + - name: Vault_evt_LiquidityRemoved + + - name: StablePoolFactory_evt_PoolCreated + + - name: StablePoolFactory_call_create + + - name: Vault_evt_Swap + + - name: ProtocolFeeController_evt_ProtocolSwapFeeCollected + + - name: ProtocolFeeController_evt_ProtocolYieldFeeCollected + + - name: Vault_evt_Wrap + + - name: Vault_evt_Unwrap + + - name: Vault_evt_LiquidityAddedToBuffer + + - name: Vault_evt_LiquidityRemovedFromBuffer + + - name: Vault_evt_SwapFeePercentageChanged