Skip to content

Commit

Permalink
add labels for balancer v3 pools on arbitrum and base
Browse files Browse the repository at this point in the history
  • Loading branch information
viniabussafi committed Jan 28, 2025
1 parent 9fbf0df commit 5e9a0fb
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 2 deletions.
51 changes: 50 additions & 1 deletion dbt_subprojects/dex/models/_projects/balancer/labels/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{{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"]\') }}')}}

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') }}
32 changes: 32 additions & 0 deletions sources/balancer/arbitrum/balancer_arbitrum_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 33 additions & 0 deletions sources/balancer/base/balancer_base_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5e9a0fb

Please sign in to comment.