diff --git a/.cursor/skills/dune-dbt-integration/SKILL.md b/.cursor/skills/dune-dbt-integration/SKILL.md new file mode 100644 index 0000000..0bbef2d --- /dev/null +++ b/.cursor/skills/dune-dbt-integration/SKILL.md @@ -0,0 +1,149 @@ +--- +name: dune-dbt-integration +description: Troubleshoot and configure Dune + dbt integration. Use when setting up profiles.yml, fixing 401/access denied errors, running dbt against Dune, or querying dbt models in the Dune UI. +alwaysApply: false +--- + +# Dune dbt Integration + +Key learnings for integrating dbt with Dune's Trino connector. + +## profiles.yml — Authentication + +**Dune uses LDAP, not JWT.** The official template differs from some docs: + +```yaml +# ✅ Correct (from dune-dbt-template) +method: ldap +user: dune # Fixed — do not change +password: "{{ env_var('DUNE_API_KEY') }}" +catalog: dune # Fixed — do not change +host: trino.api.dune.com +port: 443 +http_scheme: https +cert: true +session_properties: + transformations: true +``` + +**Do not use:** `method: jwt`, `jwt_token`, or `user: "{{ env_var('DUNE_TEAM_NAME') }}"`. + +## Environment Variables + +- **dbt does not auto-load `.env`** — run `source .env` before `uv run dbt run`. +- Required: `DUNE_API_KEY`, `DUNE_TEAM_NAME`. +- Optional: `DEV_SCHEMA_SUFFIX` for personal dev schemas. +- Optional: `DUNE_SKIP_VIEW_PROPERTIES=true` — skips `hide_spells()` and `expose_spells()` post-hooks in prod when API key lacks `alter_view_properties` permission. + +## Model Config — Dune Restrictions + +- **Remove `file_format = 'delta'`** — Dune catalog does not support this property. Causes: `table property 'format' does not exist`. +- **Never set `format` or `file_format`** in model configs. + +## incremental_predicate Macro + +Models using `incremental_predicate()` require these vars in `dbt_project.yml`: + +```yaml +vars: + DBT_ENV_INCREMENTAL_TIME_UNIT: 'day' + DBT_ENV_INCREMENTAL_TIME: '1' +``` + +Otherwise: `Required var 'DBT_ENV_INCREMENTAL_TIME_UNIT' not found`. + +## Schema Naming + +| Target | Schema pattern | Example | +|--------|----------------|---------| +| dev | `{team}__tmp___{custom}` | `balancer__tmp___balancer_v2_ethereum` | +| prod | `{team}__{custom}` or `{team}` | `balancer__balancer_v2_ethereum` | + +Note: dev uses **three underscores** between `tmp` and the custom schema. + +## Querying in Dune UI + +Always use the `dune.` catalog prefix: + +```sql +-- Dev +select * from dune.balancer__tmp___balancer_v2_ethereum.bpt_supply limit 100; + +-- Prod +select * from dune.balancer.bpt_supply limit 100; +``` + +## Common Errors + +| Error | Cause | Fix | +|-------|-------|-----| +| 401 Invalid authentication | Wrong auth method or API key | Use LDAP, `user: dune`, `password: DUNE_API_KEY` | +| Env var not provided | .env not loaded | Run `source .env` before dbt | +| table property 'format' does not exist | file_format in model | Remove `file_format = 'delta'` | +| DBT_ENV_INCREMENTAL_TIME_UNIT not found | incremental_predicate macro | Add vars to dbt_project.yml | +| access denied (prod) | See "Access Denied (Prod)" section below | | +| Cannot execute procedure dune._internal.alter_view_properties | API key lacks permission for view metadata | Set `DUNE_SKIP_VIEW_PROPERTIES=true` in .env | + +## Access Denied (Prod) — Support Recommendation + +When support says: *"make sure in your profiles.yml your api key has permissions in your prod target"*, they refer to: + +### 1. API key context + +- **API key must be from the team account**, not personal. +- If dev works, the key is team-level — this is not the issue. +- Prod writes to `{team_name}`; personal keys only have access to `{user}__tmp_*`. + +### 2. DUNE_TEAM_NAME exact match + +- Prod schema (`{{ env_var('DUNE_TEAM_NAME') }}`) must be **exactly** the team handle on Dune. +- Docs: *"Verify you're using the correct team namespace"* (Supported SQL Operations). +- Case-sensitive; no spaces or extra characters. + +**Check:** In the Dune UI, what is the exact team handle? Compare with `DUNE_TEAM_NAME` in `.env`. + +### 3. Data Transformations enabled + +- Docs: *"Dune Enterprise account with Data Transformations enabled"* (prerequisite). +- *"Verify you're using the correct team namespace and have Data Transformations enabled."* (troubleshooting). + +**Check:** Does the team's Enterprise plan have Data Transformations enabled? + +### 4. profiles.yml — same key for dev and prod + +- Dev and prod use the same `DUNE_API_KEY` (correct). +- Only difference is schema: dev → `{team}__tmp_*`, prod → `{team}`. +- `transformations: true` in both (required for writes). + +### Checklist for access denied in prod + +1. [ ] API key created under **team** context (if dev works, this is done) +2. [ ] `DUNE_TEAM_NAME` = exact team handle on Dune +3. [ ] Data Transformations enabled on team's Enterprise plan +4. [ ] `transformations: true` in session_properties (dev and prod) +5. [ ] Contact Dune support if all above pass — prod schema may require explicit provisioning + +## Deploy Targets + +```bash +# Dev (default) +uv run dbt run + +# Prod +uv run dbt run --target prod +``` + +Prod may require additional permissions; dev typically works with a valid org API key. + +## Verify API Key + +```bash +curl -X POST -H "X-DUNE-API-KEY: $DUNE_API_KEY" "https://api.dune.com/api/v1/usage" +``` + +Success = JSON with `credits_used`, `billing_periods`. Use **POST**, not GET. + +## Prerequisites + +- Dune Enterprise account with **Data Transformations** enabled. +- API key from the **team/org** (not personal) for team schemas. diff --git a/.env.example b/.env.example index b29707e..1f53315 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,5 @@ DUNE_TEAM_NAME=balancer -DUNE_API_KEY="" \ No newline at end of file +DUNE_API_KEY="" + +# Set to 'true' to skip alter_view_properties in prod (workaround when API key lacks permission) +# DUNE_SKIP_VIEW_PROPERTIES=true \ No newline at end of file diff --git a/dbt_project.yml b/dbt_project.yml index 84148e7..f832b17 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -17,7 +17,7 @@ flags: # These configurations specify where dbt should look for different types of files. # The `model-paths` config, for example, states that models in this project can be # found in the "models/" directory. You probably won't need to change these! -model-paths: ["models"] +model-paths: ["models", "sources"] analysis-paths: ["analyses"] test-paths: ["tests"] seed-paths: ["seeds"] @@ -28,8 +28,13 @@ clean-targets: # directories to be removed by `dbt clean` - "target" - "dbt_packages" +# Required by incremental_predicate macro (used in transfers_bpt models) +vars: + DBT_ENV_INCREMENTAL_TIME_UNIT: 'day' + DBT_ENV_INCREMENTAL_TIME: '1' + models: - dbt_template: + balancer: # Config indicated by + and applies to all files under models/templates/ +materialized: view # fallback default, materialized should be overriden in model specific configs +view_security: invoker # required security setting for views diff --git a/macros/dune/config_trino_properties.sql b/macros/dune/config_trino_properties.sql new file mode 100644 index 0000000..09fbc45 --- /dev/null +++ b/macros/dune/config_trino_properties.sql @@ -0,0 +1,52 @@ +{%- macro trino_properties(properties) -%} + map_from_entries(ARRAY[ + {%- for key, value in properties.items() %} + ROW('{{ key }}', '{{ value }}') + {%- if not loop.last -%},{%- endif -%} + {%- endfor %} + ]) +{%- endmacro -%} + +{% macro expose_spells(blockchains, spell_type, spell_name, contributors) %} + {%- set validated_contributors = tojson(fromjson(contributors | as_text)) -%} + {%- if ("%s" % validated_contributors) == "null" -%} + {%- do exceptions.raise_compiler_error("Invalid contributors '%s'. The list of contributors must be valid JSON." % contributors) -%} + {%- endif -%} + {%- if target.name == 'prod' and env_var('DUNE_SKIP_VIEW_PROPERTIES', 'false') != 'true' -%} + {%- set properties = { + 'dune.public': 'true', + 'dune.data_explorer.blockchains': blockchains | as_text, + 'dune.data_explorer.category': 'abstraction', + 'dune.data_explorer.abstraction.type': spell_type, + 'dune.data_explorer.abstraction.name': spell_name, + 'dune.data_explorer.contributors': validated_contributors, + 'dune.vacuum': '{"enabled":true}' + } -%} + {%- if model.config.materialized == "view" -%} + CALL {{ model.database }}._internal.alter_view_properties('{{ model.schema }}', '{{ model.alias }}', + {{ trino_properties(properties) }} + ) + {%- else -%} + ALTER TABLE {{ this }} + SET PROPERTIES extra_properties = {{ trino_properties(properties) }} + {%- endif -%} + {%- endif -%} +{%- endmacro -%} + +{% macro hide_spells() %} + {%- if target.name == 'prod' and env_var('DUNE_SKIP_VIEW_PROPERTIES', 'false') != 'true' -%} + {%- set properties = { + 'dune.public': 'false', + 'dune.data_explorer.category': 'abstraction', + 'dune.vacuum': '{"enabled":true}' + } -%} + {%- if model.config.materialized == "view" -%} + CALL {{ model.database }}._internal.alter_view_properties('{{ model.schema }}', '{{ model.alias }}', + {{ trino_properties(properties) }} + ) + {%- else -%} + ALTER TABLE {{ this }} + SET PROPERTIES extra_properties = {{ trino_properties(properties) }} + {%- endif -%} + {%- endif -%} +{%- endmacro -%} \ No newline at end of file diff --git a/macros/dune/incremental_predicate.sql b/macros/dune/incremental_predicate.sql new file mode 100644 index 0000000..ad34e73 --- /dev/null +++ b/macros/dune/incremental_predicate.sql @@ -0,0 +1,3 @@ +{% macro incremental_predicate(column) -%} +{{column}} >= date_trunc('{{var("DBT_ENV_INCREMENTAL_TIME_UNIT")}}', now() - interval '{{var('DBT_ENV_INCREMENTAL_TIME')}}' {{var('DBT_ENV_INCREMENTAL_TIME_UNIT')}}) +{%- endmacro -%} diff --git a/macros/dune_dbt_overrides/get_custom_schema.sql b/macros/dune_dbt_overrides/get_custom_schema.sql index 0cb8a50..da9c181 100644 --- a/macros/dune_dbt_overrides/get_custom_schema.sql +++ b/macros/dune_dbt_overrides/get_custom_schema.sql @@ -8,17 +8,14 @@ {% macro generate_schema_name(custom_schema_name, node) -%} - {%- set dev_suffix = env_var('DEV_SCHEMA_SUFFIX', '') -%} + {# Base schema is set in profiles.yml per Dune docs (team or team__tmp_*) #} + {%- set base_schema = target.schema -%} - {%- if target.name == 'prod' -%} - {# prod environment, writes to target schema #} - {{ target.schema }} - {%- elif target.name != 'prod' and dev_suffix != '' -%} - {# dev environments, writes to target schema with dev suffix #} - {{ target.schema }}__tmp_{{ dev_suffix | trim }} + {# If a model supplies a custom schema, append it to avoid collisions #} + {%- if custom_schema_name is not none -%} + {{ base_schema }}__{{ custom_schema_name | trim }} {%- else -%} - {# default to dev environment, no dev suffix #} - {{ target.schema }}__tmp_ + {{ base_schema }} {%- endif -%} {%- endmacro %} diff --git a/macros/shared/balancer/balancer_bpt_prices_macro.sql b/macros/shared/balancer/balancer_bpt_prices_macro.sql new file mode 100644 index 0000000..f0b6914 --- /dev/null +++ b/macros/shared/balancer/balancer_bpt_prices_macro.sql @@ -0,0 +1,650 @@ +{% macro + balancer_v2_compatible_bpt_prices_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_model + ) +%} + +WITH pool_labels AS ( + SELECT + address AS pool_id, + name AS pool_symbol, + pool_type + FROM {{ source('labels', pool_labels_model) }} + WHERE blockchain = '{{blockchain}}' + AND source = 'query' + AND model_name = '{{pool_labels_model}}' + ), + +-- 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 = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + gyro_prices AS ( + SELECT + token_address, + decimals, + price + FROM {{ source('gyroscope','gyro_tokens') }} + WHERE blockchain = '{{blockchain}}' + ), + + 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(project_decoded_as + '_' + blockchain, '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(project_decoded_as + '_' + blockchain, '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(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) + 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(project_decoded_as + '_' + blockchain, '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, + '{{blockchain}}' as blockchain, + b.pool_id, + b.token, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals, p4.decimals)) * COALESCE(p1.price, p4.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 = '{{blockchain}}' + LEFT JOIN prices p1 ON p1.day = b.day + AND p1.token = b.token + LEFT JOIN gyro_prices p4 ON p4.token_address = 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(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 {{ source('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 = '{{blockchain}}' + AND w.version = '{{version}}' + 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, + '{{version}}' AS version, + '{{blockchain}}' 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(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 + LEFT JOIN pool_labels p ON p.pool_id = BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) + GROUP BY 1, 2, 3, 4 + ), + +-- trade based formulation, for Linear Pools (former BPT prices spell) + + bpt_trades AS ( + SELECT * + 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) + ), + + 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.decimals, 18) AS token_in_decimals, + p2.price AS token_out_p, + COALESCE(p2.decimals, 18) AS token_out_decimals + FROM bpt_trades a + LEFT JOIN prices p1 ON p1.token = a.tokenIn + AND p1.day = date_trunc('day', a.evt_block_time) + LEFT JOIN prices p2 ON p2.token = a.tokenOut + AND p2.day = date_trunc('day', a.evt_block_time) + 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 + ), + + backfill_pricing 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 all_trades_calc_2 + ), + + 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 b2 WHERE b2.contract_address = b2.token_in + UNION + SELECT block_time, contract_address, token_out_price AS price + FROM backfill_pricing b2 WHERE b2.contract_address = b2.token_out + ) + GROUP BY 1, 2 + ), + + trade_price_formulation_2 AS( + SELECT + day, + contract_address, + approx_percentile(median_price, 0.5) OVER( + PARTITION BY contract_address ORDER BY day + ROWS BETWEEN 10 PRECEDING AND 10 FOLLOWING + ) 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 + ) + + SELECT + l.day, + l.blockchain, + l.version, + 18 AS decimals, + l.pool_address AS contract_address, + pl.pool_type, + CASE WHEN median_price IS NOT NULL + THEN p.median_price + ELSE l.liquidity / s.supply + END AS bpt_price + FROM tvl l + 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 + 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 > 0 + + {% endmacro %} + + {# ######################################################################### #} + + {% macro + balancer_v3_compatible_bpt_prices_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_model + ) +%} + +WITH pool_labels AS ( + SELECT + address AS pool_id, + name AS pool_symbol, + pool_type + FROM {{ source('labels', pool_labels_model) }} + WHERE blockchain = '{{blockchain}}' + AND source = 'query' + AND model_name = '{{pool_labels_model}}' + ), + + 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(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolRegistered') }} + ) AS pool_data + CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index) + GROUP BY 1 + ), + +-- 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 = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + erc4626_prices AS ( + SELECT + DATE_TRUNC('day', minute) AS day, + wrapped_token AS token, + decimals, + APPROX_PERCENTILE(median_price, 0.5) AS price, + LEAD(DATE_TRUNC('day', minute), 1, CURRENT_DATE + INTERVAL '1' day) OVER (PARTITION BY wrapped_token ORDER BY date_trunc('day', minute)) AS next_change + FROM {{ source('balancer_v3' , 'erc4626_token_prices') }} + WHERE blockchain = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + global_fees AS ( + SELECT + evt_block_time, + swapFeePercentage / 1e18 AS global_swap_fee, + ROW_NUMBER() OVER (ORDER BY evt_block_time DESC) AS rn + FROM {{ source(project_decoded_as + '_' + blockchain, 'ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged') }} + ), + + pool_creator_fees AS ( + SELECT + evt_block_time, + pool, + poolCreatorSwapFeePercentage / 1e18 AS pool_creator_swap_fee, + ROW_NUMBER() OVER (PARTITION BY pool ORDER BY evt_block_time DESC) AS rn + FROM {{ source(project_decoded_as + '_' + blockchain, 'ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged') }} + ), + + swaps_changes AS ( + SELECT + day, + pool_id, + token, + SUM(COALESCE(delta, INT256 '0')) AS delta + FROM + ( + SELECT + date_trunc('day', swap.evt_block_time) AS day, + swap.pool AS pool_id, + swap.tokenIn AS token, + CAST(swap.amountIn AS INT256) - (CAST(swap.swapFeeAmount AS INT256) * (g.global_swap_fee + COALESCE(pc.pool_creator_swap_fee, 0))) AS delta + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} swap + CROSS JOIN global_fees g + LEFT JOIN pool_creator_fees pc ON swap.pool = pc.pool AND pc.rn = 1 + WHERE g.rn = 1 + + UNION ALL + + SELECT + date_trunc('day', evt_block_time) AS day, + pool AS pool_id, + tokenOut AS token, + -CAST(amountOut AS INT256) AS delta + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} + ) swaps + GROUP BY 1, 2, 3 + ), + + balance_changes AS( + SELECT + evt_block_time, + pool_id, + category, + deltas, + swapFeeAmountsRaw + FROM + ( + SELECT + evt_block_time, + pool AS pool_id, + 'add' AS category, + amountsAddedRaw AS deltas, + swapFeeAmountsRaw + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_LiquidityAdded') }} + + UNION ALL + + SELECT + evt_block_time, + pool AS pool_id, + 'remove' AS category, + amountsRemovedRaw AS deltas, + swapFeeAmountsRaw + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_LiquidityRemoved') }} + ) adds_and_removes + ), + + zipped_balance_changes AS ( + SELECT + date_trunc('day', evt_block_time) AS day, + pool_id, + t.tokens, + CASE WHEN b.category = 'add' + THEN d.deltas + WHEN b.category = 'remove' + THEN -d.deltas + END AS deltas, + p.swapFeeAmountsRaw + FROM balance_changes b + JOIN token_data td ON b.pool_id = td.pool + CROSS JOIN UNNEST (td.tokens) WITH ORDINALITY as t(tokens,i) + CROSS JOIN UNNEST (b.deltas) WITH ORDINALITY as d(deltas,i) + CROSS JOIN UNNEST (b.swapFeeAmountsRaw) WITH ORDINALITY as p(swapFeeAmountsRaw,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(swapFeeAmountsRaw as int256) AS delta + FROM zipped_balance_changes + ORDER BY 1, 2, 3 + ), + + 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 + ) 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('2024-12-01'), date(now()), interval '1' day)) as t(date_sequence) + ), + + cumulative_usd_balance AS ( + SELECT + c.day, + '{{blockchain}}' as blockchain, + b.pool_id, + b.token, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals, p4.decimals)) * COALESCE(p1.price, p4.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 = '{{blockchain}}' + LEFT JOIN prices p1 ON p1.day = b.day + AND p1.token = b.token + LEFT JOIN erc4626_prices p4 ON p4.day <= c.day + AND c.day < p4.next_change + AND p4.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(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 {{ source('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 = '{{blockchain}}' + AND w.version = '{{version}}' + 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, + '{{version}}' AS version, + '{{blockchain}}' 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(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 + LEFT JOIN pool_labels p ON p.pool_id = BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) + GROUP BY 1, 2, 3, 4 + ) + + SELECT + l.day, + l.blockchain, + l.version, + 18 AS decimals, + l.pool_address AS contract_address, + pl.pool_type, + l.liquidity / s.supply AS bpt_price + FROM tvl l + 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 + LEFT JOIN pool_labels pl ON pl.pool_id = l.pool_address + WHERE supply > 0 + + {% endmacro %} diff --git a/macros/shared/balancer/balancer_bpt_supply_macro.sql b/macros/shared/balancer/balancer_bpt_supply_macro.sql new file mode 100644 index 0000000..8698635 --- /dev/null +++ b/macros/shared/balancer/balancer_bpt_supply_macro.sql @@ -0,0 +1,244 @@ +{% macro + balancer_v2_compatible_bpt_supply_macro( + blockchain, version, project_decoded_as, pool_labels_model, transfers_spell + ) +%} + +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 {{ source('labels', pool_labels_model) }} + WHERE blockchain = '{{blockchain}}' + and source = 'query' + and model_name = '{{pool_labels_model}}' + 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 {{ transfers_spell }} t + WHERE blockchain = '{{blockchain}}' + AND version = '{{version}}' + 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(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 + 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(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 + ), + + 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(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 + ), + + 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) + ) + + SELECT + c.day, + l.pool_type, + '{{version}}' as version, + '{{blockchain}}' 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, 5 + HAVING SUM(b.supply - COALESCE(preminted_bpts, 0) + COALESCE(adelta, 0)) >= 0 --simple filter to remove outliers + +{% endmacro %} + +{# ######################################################################### #} + +{% macro + balancer_v3_compatible_bpt_supply_macro( + blockchain, version, project_decoded_as, pool_labels_model, transfers_spell + ) +%} + + 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 {{ source('labels', pool_labels_model) }} + WHERE blockchain = '{{blockchain}}' + and source = 'query' + and model_name = '{{pool_labels_model}}' + 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 {{ transfers_spell }} t + WHERE blockchain = '{{blockchain}}' + AND version = '{{version}}' + 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 + ), + + -- Calculating Joins(mint) and Exits(burn) via Swap + joins AS ( + SELECT + DATE_TRUNC('day', evt_block_time) AS block_date, + tokenOut, + pool_type, + SUM(amountOut / POWER(10, 18)) AS ajoins + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} + LEFT JOIN pool_labels ON pool = address + WHERE tokenOut = pool + GROUP BY 1, 2, 3 + ), + + exits AS ( + SELECT + DATE_TRUNC('day', evt_block_time) AS block_date, + tokenIn, + pool_type, + SUM(amountIn / POWER(10, 18)) AS aexits + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} + LEFT JOIN pool_labels ON pool = address + WHERE tokenIn = pool + 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('2024-12-01'), date(now()), interval '1' day)) as t(date_sequence) + ) + + SELECT + c.day, + l.pool_type, + '{{version}}' as version, + '{{blockchain}}' as blockchain, + b.token AS token_address, + COALESCE(SUM(b.supply + 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 pool_labels l ON b.token = l.address + GROUP BY 1, 2, 3, 4, 5 + HAVING SUM(b.supply + COALESCE(adelta, 0)) >= 0 --simple filter to remove outliers + +{% endmacro %} \ No newline at end of file diff --git a/macros/shared/balancer/balancer_liquidity_macro.sql b/macros/shared/balancer/balancer_liquidity_macro.sql new file mode 100644 index 0000000..b2fb572 --- /dev/null +++ b/macros/shared/balancer/balancer_liquidity_macro.sql @@ -0,0 +1,638 @@ +{% macro + balancer_v2_compatible_liquidity_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_model + ) +%} + +WITH pool_labels AS ( + SELECT + address AS pool_id, + name AS pool_symbol, + pool_type + FROM {{ source('labels', pool_labels_model) }} + WHERE blockchain = '{{blockchain}}' + AND source = 'query' + AND model_name = '{{pool_labels_model}}' + ), + + prices AS ( + SELECT + date_trunc('day', minute) AS day, + contract_address AS token, + decimals, + APPROX_PERCENTILE(price, 0.5) AS price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + 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') }} + WHERE blockchain = '{{blockchain}}' + AND contract_address NOT IN (0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757) + 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 AS( + SELECT DISTINCT + day, + contract_address AS token, + decimals, + bpt_price + FROM {{ ref(base_spells_namespace + '_bpt_prices') }} + WHERE blockchain = '{{blockchain}}' + AND version = '{{version}}' + ), + + eth_prices AS ( + SELECT + DATE_TRUNC('day', minute) as day, + AVG(price) as eth_price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = 'ethereum' + AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + GROUP BY 1 + ), + + gyro_prices AS ( + SELECT + token_address, + decimals, + price + FROM {{ source('gyroscope', 'gyro_tokens') }} + WHERE blockchain = '{{blockchain}}' + ), + + 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(project_decoded_as + '_' + blockchain, '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(project_decoded_as + '_' + blockchain, '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(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) + 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(project_decoded_as + '_' + blockchain, '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, + '{{blockchain}}' as blockchain, + b.pool_id, + b.token, + symbol AS token_symbol, + cumulative_amount as token_balance_raw, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals, p3.decimals, p4.decimals)) AS token_balance, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals, p3.decimals, p4.decimals)) * COALESCE(p1.price, p2.price, p4.price, 0) AS protocol_liquidity_usd, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals, p3.decimals, p4.decimals)) * COALESCE(p1.price, p2.price, p3.bpt_price, p4.price, 0) AS pool_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 = '{{blockchain}}' + LEFT JOIN prices p1 ON p1.day = b.day + AND p1.token = b.token + LEFT JOIN dex_prices p2 ON p2.day <= c.day + AND c.day < p2.day_of_next_change + AND p2.token = b.token + LEFT JOIN bpt_prices p3 ON p3.day = b.day + AND p3.token = b.token + LEFT JOIN gyro_prices p4 ON p4.token_address = 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.pool_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, + SUM(b.pool_liquidity_usd) / COALESCE(SUM(w.normalized_weight), 1) AS pool_liquidity + FROM cumulative_usd_balance b + 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 {{ source('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 = '{{blockchain}}' + AND w.version = '{{version}}' + GROUP BY 1, 2, 3, 4 + ), + + weighted_pool_liquidity_estimates_2 AS( + SELECT e.day, + e.pool_id, + SUM(e.pool_liquidity) / MAX(e.pricing_count) AS pool_liquidity, + SUM(e.protocol_liquidity) / MAX(e.pricing_count) AS protocol_liquidity + FROM weighted_pool_liquidity_estimates e + GROUP BY 1,2 + ) + + SELECT + c.day, + c.pool_id, + BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) AS pool_address, + p.pool_symbol, + '{{version}}' AS version, + '{{blockchain}}' 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.pool_liquidity * w.normalized_weight, c.pool_liquidity_usd) AS pool_liquidity_usd, + COALESCE(b.pool_liquidity * w.normalized_weight, c.pool_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 + 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 + 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) + {% endmacro %} + +{# ######################################################################### #} + +{% macro + balancer_v3_compatible_liquidity_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_model + ) +%} + +WITH pool_labels AS ( + SELECT + address AS pool_id, + name AS pool_symbol, + pool_type + FROM {{ source('labels', pool_labels_model) }} + WHERE blockchain = '{{blockchain}}' + AND source = 'query' + AND model_name = '{{pool_labels_model}}' + ), + + 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(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolRegistered') }} + ) AS pool_data + CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index) + GROUP BY 1 + ), + + prices AS ( + SELECT + date_trunc('day', minute) AS day, + contract_address AS token, + decimals, + APPROX_PERCENTILE(price, 0.5) AS price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + dex_prices_1 AS ( + SELECT + date_trunc('day', timestamp) AS DAY, + contract_address AS token, + approx_percentile(price, 0.5) AS price + FROM {{ source('prices', 'hour') }} + WHERE blockchain = '{{blockchain}}' + GROUP BY 1, 2 + ), + + 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 AS( + SELECT DISTINCT + day, + contract_address AS token, + decimals, + bpt_price + FROM {{ ref(base_spells_namespace + '_bpt_prices') }} + WHERE blockchain = '{{blockchain}}' + AND version = '{{version}}' + ), + + eth_prices AS ( + SELECT + DATE_TRUNC('day', minute) as day, + AVG(price) as eth_price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = 'ethereum' + AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + GROUP BY 1 + ), + + erc4626_prices AS ( + SELECT + DATE_TRUNC('day', minute) AS day, + wrapped_token AS token, + decimals, + APPROX_PERCENTILE(median_price, 0.5) AS price, + LEAD(DATE_TRUNC('day', minute), 1, CURRENT_DATE + INTERVAL '1' day) OVER (PARTITION BY wrapped_token ORDER BY date_trunc('day', minute)) AS next_change + FROM {{ source('balancer_v3', 'erc4626_token_prices') }} + WHERE blockchain = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + global_fees AS ( + SELECT + evt_block_time, + swapFeePercentage / 1e18 AS global_swap_fee, + ROW_NUMBER() OVER (ORDER BY evt_block_time DESC) AS rn + FROM {{ source(project_decoded_as + '_' + blockchain, 'ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged') }} + ), + + pool_creator_fees AS ( + SELECT + evt_block_time, + pool, + poolCreatorSwapFeePercentage / 1e18 AS pool_creator_swap_fee, + ROW_NUMBER() OVER (PARTITION BY pool ORDER BY evt_block_time DESC) AS rn + FROM {{ source(project_decoded_as + '_' + blockchain, 'ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged') }} + ), + + swaps_changes AS ( + SELECT + day, + pool_id, + token, + SUM(COALESCE(delta, INT256 '0')) AS delta + FROM + ( + SELECT + date_trunc('day', swap.evt_block_time) AS day, + swap.pool AS pool_id, + swap.tokenIn AS token, + CAST(swap.amountIn AS INT256) - (CAST(swap.swapFeeAmount AS INT256) * (g.global_swap_fee + COALESCE(pc.pool_creator_swap_fee, 0))) AS delta + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} swap + CROSS JOIN global_fees g + LEFT JOIN pool_creator_fees pc ON swap.pool = pc.pool AND pc.rn = 1 + WHERE g.rn = 1 + + + UNION ALL + + SELECT + date_trunc('day', evt_block_time) AS day, + pool AS pool_id, + tokenOut AS token, + -CAST(amountOut AS INT256) AS delta + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} + ) swaps + GROUP BY 1, 2, 3 + ), + + balance_changes AS( + SELECT + evt_block_time, + pool_id, + category, + deltas, + swapFeeAmountsRaw + FROM + ( + SELECT + evt_block_time, + pool AS pool_id, + 'add' AS category, + amountsAddedRaw AS deltas, + swapFeeAmountsRaw + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_LiquidityAdded') }} + + UNION ALL + + SELECT + evt_block_time, + pool AS pool_id, + 'remove' AS category, + amountsRemovedRaw AS deltas, + swapFeeAmountsRaw + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_LiquidityRemoved') }} + ) adds_and_removes + ), + + zipped_balance_changes AS ( + SELECT + date_trunc('day', evt_block_time) AS day, + pool_id, + t.tokens, + CASE WHEN b.category = 'add' + THEN d.deltas + WHEN b.category = 'remove' + THEN -d.deltas + END AS deltas, + p.swapFeeAmountsRaw + FROM balance_changes b + JOIN token_data td ON b.pool_id = td.pool + CROSS JOIN UNNEST (td.tokens) WITH ORDINALITY as t(tokens,i) + CROSS JOIN UNNEST (b.deltas) WITH ORDINALITY as d(deltas,i) + CROSS JOIN UNNEST (b.swapFeeAmountsRaw) WITH ORDINALITY as p(swapFeeAmountsRaw,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(swapFeeAmountsRaw as int256) AS delta + FROM zipped_balance_changes + ORDER BY 1, 2, 3 + ), + + 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 + ) 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('2024-12-01'), date(now()), interval '1' day)) as t(date_sequence) + ), + + cumulative_usd_balance AS ( + SELECT + c.day, + '{{blockchain}}' as blockchain, + b.pool_id, + b.token, + symbol AS token_symbol, + cumulative_amount as token_balance_raw, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals, p3.decimals, p4.decimals)) AS token_balance, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals, p3.decimals, p4.decimals)) * COALESCE(p1.price, p2.price, p4.price, 0) AS protocol_liquidity_usd, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals, p3.decimals, p4.decimals)) * COALESCE(p1.price, p2.price, p3.bpt_price, p4.price, 0) AS pool_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 = '{{blockchain}}' + LEFT JOIN prices p1 ON p1.day = b.day + AND p1.token = b.token + LEFT JOIN dex_prices p2 ON p2.day <= c.day + AND c.day < p2.day_of_next_change + AND p2.token = b.token + LEFT JOIN bpt_prices p3 ON p3.day = b.day + AND p3.token = b.token + LEFT JOIN erc4626_prices p4 ON p4.day <= c.day + AND c.day < p4.next_change + AND p4.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.pool_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, + SUM(b.pool_liquidity_usd) / COALESCE(SUM(w.normalized_weight), 1) AS pool_liquidity + FROM cumulative_usd_balance b + 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 {{ source('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 = '{{blockchain}}' + AND w.version = '{{version}}' + GROUP BY 1, 2, 3, 4 + ), + + weighted_pool_liquidity_estimates_2 AS( + SELECT e.day, + e.pool_id, + SUM(e.pool_liquidity) / MAX(e.pricing_count) AS pool_liquidity, + SUM(e.protocol_liquidity) / MAX(e.pricing_count) AS protocol_liquidity + FROM weighted_pool_liquidity_estimates e + GROUP BY 1,2 + ) + + SELECT + c.day, + c.pool_id, + BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) AS pool_address, + p.pool_symbol, + '{{version}}' AS version, + '{{blockchain}}' 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.pool_liquidity * w.normalized_weight, c.pool_liquidity_usd) AS pool_liquidity_usd, + COALESCE(b.pool_liquidity * w.normalized_weight, c.pool_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 + 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 + 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) + + {% endmacro %} \ No newline at end of file diff --git a/macros/shared/balancer/balancer_token_balance_changes_daily_agg_macro.sql b/macros/shared/balancer/balancer_token_balance_changes_daily_agg_macro.sql new file mode 100644 index 0000000..55cced8 --- /dev/null +++ b/macros/shared/balancer/balancer_token_balance_changes_daily_agg_macro.sql @@ -0,0 +1,384 @@ +{% macro + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain, version, project_decoded_as, base_spells_namespace + ) +%} +WITH + prices AS ( + SELECT + date_trunc('day', minute) AS day, + contract_address AS token, + decimals, + AVG(price) AS price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + {% if is_incremental() %} + WHERE {{ incremental_predicate('minute') }} + {% endif %} + 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') }} + WHERE blockchain = '{{blockchain}}' + AND contract_address NOT IN (0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757) + {% if is_incremental() %} + AND {{ incremental_predicate('hour') }} + {% endif %} + 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 AS( + SELECT DISTINCT + day, + contract_address AS token, + decimals, + bpt_price + FROM {{ ref(base_spells_namespace + '_bpt_prices') }} + WHERE blockchain = '{{blockchain}}' + {% if is_incremental() %} + AND {{ incremental_predicate('day') }} + {% endif %} + AND version = '{{version}}' + ), + + eth_prices AS ( + SELECT + DATE_TRUNC('day', minute) as day, + AVG(price) as eth_price + FROM {{ source('prices', 'usd') }} + WHERE symbol = 'ETH' + {% if is_incremental() %} + WHERE {{ incremental_predicate('minute') }} + {% endif %} + GROUP BY 1 + ), + + gyro_prices AS ( + SELECT + token_address, + decimals, + price + FROM {{ source('gyroscope','gyro_tokens') }} + WHERE blockchain = '{{blockchain}}' + ), + + daily_balance AS ( + SELECT + block_date, + pool_id, + pool_symbol, + pool_type, + token_address, + 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(base_spells_namespace + '_token_balance_changes') }} + WHERE blockchain = '{{blockchain}}' + AND version = '{{version}}' + GROUP BY 1, 2, 3, 4, 5, 6 + ), + + calendar AS ( + SELECT date_sequence AS day + FROM unnest(sequence(date('2021-04-21'), date(now()), interval '1' day)) as t(date_sequence) + ), + + daily_usd_balance AS ( + SELECT + c.day AS block_date, + '{{blockchain}}"' as blockchain, + b.pool_id, + b.pool_symbol, + b.pool_type, + b.token_address, + b.token_symbol, + daily_amount, + daily_amount * COALESCE(p1.price, p2.price, p3.bpt_price, p4.price, 0) AS daily_amount_usd + FROM calendar c + LEFT JOIN daily_balance b ON b.block_date <= c.day + AND c.day < b.day_of_next_change + LEFT JOIN prices p1 ON p1.day = b.block_date + AND p1.token = b.token_address + LEFT JOIN dex_prices p2 ON p2.day <= c.day + AND c.day < p2.day_of_next_change + AND p2.token = b.token_address + LEFT JOIN bpt_prices p3 ON p3.day = b.block_date + AND p3.token = b.token_address + LEFT JOIN gyro_prices p4 ON p4.token_address = b.token_address + WHERE b.token_address != BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) + ), + + weighted_pool_amount_estimates AS ( + SELECT + b.block_date, + b.pool_id, + q.name, + pool_type, + 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(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 {{ source('balancer','token_whitelist') }} q ON b.token_address = q.address + AND b.blockchain = q.chain + WHERE q.name IS NOT NULL + AND b.pool_type = 'weighted' -- filters for weighted pools with pricing assets + AND w.blockchain = '{{blockchain}}' + AND w.version = '2' + GROUP BY 1, 2, 3, 4 + ), + + weighted_pool_amount_estimates_2 AS( + SELECT e.block_date, + e.pool_id, + SUM(e.weighted_daily_amount_usd) / MAX(e.pricing_count) AS weighted_daily_amount_usd + FROM weighted_pool_amount_estimates e + GROUP BY 1,2 + ) + + SELECT DISTINCT + c.block_date, + c.pool_id, + BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) AS pool_address, + c.pool_symbol, + '2' AS version, + '{{blockchain}}' AS blockchain, + c.pool_type, + c.token_address, + c.token_symbol, + c.daily_amount AS daily_delta, + COALESCE(b.weighted_daily_amount_usd * w.normalized_weight, c.daily_amount_usd) AS daily_delta_usd, + COALESCE(b.weighted_daily_amount_usd * w.normalized_weight, c.daily_amount_usd)/e.eth_price AS daily_delta_eth + 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(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 + {% endmacro %} + +{# ######################################################################### #} + +{% macro + balancer_v3_compatible_token_balance_changes_daily_agg_macro( + blockchain, version, project_decoded_as, base_spells_namespace + ) +%} +WITH + prices AS ( + SELECT + date_trunc('day', minute) AS day, + contract_address AS token, + decimals, + AVG(price) AS price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + {% if is_incremental() %} + WHERE {{ incremental_predicate('minute') }} + {% endif %} + 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') }} + WHERE blockchain = '{{blockchain}}' + AND contract_address NOT IN (0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757) + {% if is_incremental() %} + AND {{ incremental_predicate('hour') }} + {% endif %} + 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 AS( + SELECT DISTINCT + day, + contract_address AS token, + decimals, + bpt_price + FROM {{ ref(base_spells_namespace + '_bpt_prices') }} + WHERE blockchain = '{{blockchain}}' + {% if is_incremental() %} + AND {{ incremental_predicate('day') }} + {% endif %} + AND version = '{{version}}' + ), + + eth_prices AS ( + SELECT + DATE_TRUNC('day', minute) as day, + AVG(price) as eth_price + FROM {{ source('prices', 'usd') }} + WHERE symbol = 'ETH' + {% if is_incremental() %} + WHERE {{ incremental_predicate('minute') }} + {% endif %} + GROUP BY 1 + ), + + erc4626_prices AS ( + SELECT + DATE_TRUNC('day', minute) AS day, + wrapped_token AS token, + decimals, + APPROX_PERCENTILE(median_price, 0.5) AS price, + LEAD(DATE_TRUNC('day', minute), 1, CURRENT_DATE + INTERVAL '1' day) OVER (PARTITION BY wrapped_token ORDER BY date_trunc('day', minute)) AS next_change + FROM {{ source('balancer_v3' , 'erc4626_token_prices') }} + WHERE blockchain = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + daily_balance AS ( + SELECT + block_date, + pool_id, + pool_symbol, + pool_type, + token_address, + 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(base_spells_namespace + '_token_balance_changes') }} + WHERE blockchain = '{{blockchain}}' + AND version = '{{version}}' + GROUP BY 1, 2, 3, 4, 5, 6 + ), + + calendar AS ( + SELECT date_sequence AS day + FROM unnest(sequence(date('2024-12-01'), date(now()), interval '1' day)) as t(date_sequence) + ), + + daily_usd_balance AS ( + SELECT + c.day AS block_date, + '{{blockchain}}"' as blockchain, + b.pool_id, + b.pool_symbol, + b.pool_type, + b.token_address, + b.token_symbol, + daily_amount, + daily_amount * COALESCE(p1.price, p2.price, p3.bpt_price, p4.price, 0) AS daily_amount_usd + FROM calendar c + LEFT JOIN daily_balance b ON b.block_date <= c.day + AND c.day < b.day_of_next_change + LEFT JOIN prices p1 ON p1.day = b.block_date + AND p1.token = b.token_address + LEFT JOIN dex_prices p2 ON p2.day <= c.day + AND c.day < p2.day_of_next_change + AND p2.token = b.token_address + LEFT JOIN bpt_prices p3 ON p3.day = b.block_date + AND p3.token = b.token_address + LEFT JOIN erc4626_prices p4 ON p4.day <= c.day + AND c.day < p4.next_change + AND p4.token = b.token_address + WHERE b.token_address != BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) + ), + + weighted_pool_amount_estimates AS ( + SELECT + b.block_date, + b.pool_id, + q.name, + pool_type, + 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(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 {{ source('balancer','token_whitelist') }} q ON b.token_address = q.address + AND b.blockchain = q.chain + WHERE q.name IS NOT NULL + AND b.pool_type = 'weighted' -- filters for weighted pools with pricing assets + AND w.blockchain = '{{blockchain}}' + AND w.version = '2' + GROUP BY 1, 2, 3, 4 + ), + + weighted_pool_amount_estimates_2 AS( + SELECT e.block_date, + e.pool_id, + SUM(e.weighted_daily_amount_usd) / MAX(e.pricing_count) AS weighted_daily_amount_usd + FROM weighted_pool_amount_estimates e + GROUP BY 1,2 + ) + + SELECT DISTINCT + c.block_date, + c.pool_id, + BYTEARRAY_SUBSTRING(c.pool_id, 1, 20) AS pool_address, + c.pool_symbol, + '2' AS version, + '{{blockchain}}' AS blockchain, + c.pool_type, + c.token_address, + c.token_symbol, + c.daily_amount AS daily_delta, + COALESCE(b.weighted_daily_amount_usd * w.normalized_weight, c.daily_amount_usd) AS daily_delta_usd, + COALESCE(b.weighted_daily_amount_usd * w.normalized_weight, c.daily_amount_usd)/e.eth_price AS daily_delta_eth + 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(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 + {% endmacro %} + +{# ######################################################################### #} diff --git a/macros/shared/balancer/balancer_token_balance_changes_macro.sql b/macros/shared/balancer/balancer_token_balance_changes_macro.sql new file mode 100644 index 0000000..473b966 --- /dev/null +++ b/macros/shared/balancer/balancer_token_balance_changes_macro.sql @@ -0,0 +1,389 @@ +{% macro + balancer_v2_compatible_token_balance_changes_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_model + ) +%} +WITH pool_labels AS ( + SELECT + address AS pool_id, + name AS pool_symbol, + pool_type + FROM {{ source('labels', pool_labels_model) }} + WHERE blockchain = '{{blockchain}}' + AND source = 'query' + AND model_name = '{{pool_labels_model}}' + ), + + swaps_changes AS ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + token, + SUM(COALESCE(delta, INT256 '0')) AS delta + FROM + ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + poolId AS pool_id, + tokenIn AS token, + CAST(amountIn as int256) AS delta + FROM {{ source(project_decoded_as ~ '_' ~ blockchain, 'Vault_evt_Swap') }} + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + + UNION ALL + + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + poolId AS pool_id, + tokenOut AS token, + -CAST(amountOut AS int256) AS delta + FROM {{ source(project_decoded_as ~ '_' ~ blockchain, 'Vault_evt_Swap') }} + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + ) swaps + GROUP BY 1, 2, 3, 4, 5, 6 + ), + + zipped_balance_changes AS ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + poolId AS pool_id, + t.tokens, + d.deltas, + p.protocolFeeAmounts + 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) + WHERE t.i = d.i + AND d.i = p.i + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} + ), + + balances_changes AS ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + tokens AS token, + deltas - CAST(protocolFeeAmounts as int256) AS delta + FROM zipped_balance_changes + ), + + managed_changes AS ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + poolId AS pool_id, + token, + cashDelta + managedDelta AS delta + FROM {{ source(project_decoded_as ~ '_' ~ blockchain, 'Vault_evt_PoolBalanceManaged') }} + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + ) + + + SELECT + date_trunc('day', b.evt_block_time) AS block_date, + b.evt_block_time, + b.evt_block_number, + '{{blockchain}}' AS blockchain, + b.evt_tx_hash, + b.evt_index, + b.pool_id, + BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) AS pool_address, + p.pool_symbol, + p.pool_type, + '{{version}}' AS version, + b.token AS token_address, + t.symbol AS token_symbol, + b.amount AS delta_amount_raw, + CASE WHEN BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) = b.token + THEN amount / POWER (10, 18) --for Balancer Pool Tokens + ELSE amount / POWER (10, COALESCE(t.decimals, 0)) + END AS delta_amount + FROM + ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + token, + COALESCE(delta, INT256 '0') AS amount + FROM balances_changes + + UNION ALL + + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + token, + delta AS amount + FROM + swaps_changes + + UNION ALL + + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + token, + CAST(delta AS int256) AS amount + FROM managed_changes + ) b + LEFT JOIN {{ source('tokens', 'erc20') }} t ON t.contract_address = b.token + AND blockchain = '{{blockchain}}' + LEFT JOIN pool_labels p ON p.pool_id = BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + + {% endmacro %} + +{# ######################################################################### #} + +{% macro + balancer_v3_compatible_token_balance_changes_macro( + blockchain, version, project_decoded_as, base_spells_namespace, pool_labels_model + ) +%} +WITH pool_labels AS ( + SELECT + address AS pool_id, + name AS pool_symbol, + pool_type + FROM {{ source('labels', pool_labels_model) }} + WHERE blockchain = '{{blockchain}}' + AND source = 'query' + AND model_name = '{{pool_labels_model}}' + ), + + 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(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolRegistered') }} + ) AS pool_data + CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index) + GROUP BY 1 + ), + + global_fees AS ( + SELECT + evt_block_time, + swapFeePercentage / 1e18 AS global_swap_fee, + ROW_NUMBER() OVER (ORDER BY evt_block_time DESC) AS rn + FROM {{ source(project_decoded_as + '_' + blockchain, 'ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged') }} + ), + + pool_creator_fees AS ( + SELECT + evt_block_time, + pool, + poolCreatorSwapFeePercentage / 1e18 AS pool_creator_swap_fee, + ROW_NUMBER() OVER (PARTITION BY pool ORDER BY evt_block_time DESC) AS rn + FROM {{ source(project_decoded_as + '_' + blockchain, 'ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged') }} + ), + + swaps_changes AS ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + token, + SUM(COALESCE(delta, INT256 '0')) AS delta + FROM + ( + SELECT + swap.evt_block_time, + swap.evt_block_number, + swap.evt_tx_hash, + swap.evt_index, + swap.pool AS pool_id, + swap.tokenIn AS token, + CAST(swap.amountIn AS INT256) - (CAST(swap.swapFeeAmount AS INT256) * (g.global_swap_fee + COALESCE(pc.pool_creator_swap_fee, 0))) AS delta + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} swap + CROSS JOIN global_fees g + LEFT JOIN pool_creator_fees pc ON swap.pool = pc.pool AND pc.rn = 1 + WHERE g.rn = 1 + + UNION ALL + + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool AS pool_id, + tokenOut AS token, + -CAST(amountOut AS int256) AS delta + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_Swap') }} + ) swaps + GROUP BY 1, 2, 3, 4, 5, 6 + ), + + balance_changes AS( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + category, + deltas, + swapFeeAmountsRaw + FROM + ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool AS pool_id, + 'add' AS category, + amountsAddedRaw AS deltas, + swapFeeAmountsRaw + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_LiquidityAdded') }} + + UNION ALL + + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool AS pool_id, + 'remove' AS category, + amountsRemovedRaw AS deltas, + swapFeeAmountsRaw + FROM {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_LiquidityRemoved') }} + ) adds_and_removes + ), + + zipped_balance_changes AS ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + t.tokens, + CASE WHEN b.category = 'add' + THEN d.deltas + WHEN b.category = 'remove' + THEN -d.deltas + END AS deltas, + p.swapFeeAmountsRaw + FROM balance_changes b + JOIN token_data td ON b.pool_id = td.pool + CROSS JOIN UNNEST (td.tokens) WITH ORDINALITY as t(tokens,i) + CROSS JOIN UNNEST (b.deltas) WITH ORDINALITY as d(deltas,i) + CROSS JOIN UNNEST (b.swapFeeAmountsRaw) WITH ORDINALITY as p(swapFeeAmountsRaw,i) + WHERE t.i = d.i + AND d.i = p.i + ORDER BY 1,2,3 + ), + + balances_changes AS ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + tokens AS token, + deltas - CAST(swapFeeAmountsRaw as int256) AS delta + FROM zipped_balance_changes + ORDER BY 1, 2, 3 + ) + + + SELECT + date_trunc('day', b.evt_block_time) AS block_date, + b.evt_block_time, + b.evt_block_number, + '{{blockchain}}' AS blockchain, + b.evt_tx_hash, + b.evt_index, + b.pool_id, + BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) AS pool_address, + p.pool_symbol, + p.pool_type, + '{{version}}' AS version, + b.token AS token_address, + t.symbol AS token_symbol, + b.amount AS delta_amount_raw, + CASE WHEN BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) = b.token + THEN amount / POWER (10, 18) --for Balancer Pool Tokens + ELSE amount / POWER (10, COALESCE(t.decimals, 0)) + END AS delta_amount + FROM + ( + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + token, + COALESCE(delta, INT256 '0') AS amount + FROM balances_changes + + UNION ALL + + SELECT + evt_block_time, + evt_block_number, + evt_tx_hash, + evt_index, + pool_id, + token, + delta AS amount + FROM + swaps_changes + ) b + LEFT JOIN {{ source('tokens', 'erc20') }} t ON t.contract_address = b.token + AND blockchain = '{{blockchain}}' + LEFT JOIN pool_labels p ON p.pool_id = BYTEARRAY_SUBSTRING(b.pool_id, 1, 20) + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + + {% endmacro %} \ No newline at end of file diff --git a/macros/shared/balancer/balancer_transfers_bpt_macro.sql b/macros/shared/balancer/balancer_transfers_bpt_macro.sql new file mode 100644 index 0000000..12cee1a --- /dev/null +++ b/macros/shared/balancer/balancer_transfers_bpt_macro.sql @@ -0,0 +1,76 @@ +{% macro + balancer_v2_compatible_transfers_bpt_macro( + blockchain, version, project_decoded_as + ) +%} + + WITH registered_pools AS ( + SELECT + DISTINCT poolAddress AS pool_address + FROM + {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolRegistered') }} + ) + + SELECT DISTINCT * FROM ( + SELECT + '{{blockchain}}' AS blockchain, + '{{version}}' AS version, + 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_' + blockchain, '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-01-01' + {% endif %} + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} ) transfers + {% endmacro %} + + {# ######################################################################### #} + + {% macro + balancer_v3_compatible_transfers_bpt_macro( + blockchain, version, project_decoded_as + ) +%} + + WITH registered_pools AS ( + SELECT + DISTINCT pool AS pool_address + FROM + {{ source(project_decoded_as + '_' + blockchain, 'Vault_evt_PoolRegistered') }} + ) + + SELECT DISTINCT * FROM ( + SELECT + '{{blockchain}}' AS blockchain, + '{{version}}' AS version, + 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_' + blockchain, '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 '2024-12-01' + {% endif %} + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} ) transfers + + {% endmacro %} diff --git a/models/_project/balancer/balances/_schema.yml b/models/_project/balancer/balances/_schema.yml new file mode 100644 index 0000000..c281af4 --- /dev/null +++ b/models/_project/balancer/balances/_schema.yml @@ -0,0 +1,98 @@ +version: 2 + +models: + - name: balancer_token_balance_changes + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + contributors: viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &blockchain + name: blockchain + description: "Blockchain" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + - &evt_index + name: evt_index + description: 'Event index' + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: balancer_token_balance_changes_daily + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + contributors: viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *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" \ No newline at end of file diff --git a/models/_project/balancer/balances/arbitrum/_schema.yml b/models/_project/balancer/balances/arbitrum/_schema.yml new file mode 100644 index 0000000..b6c40d4 --- /dev/null +++ b/models/_project/balancer/balances/arbitrum/_schema.yml @@ -0,0 +1,162 @@ +version: 2 + +models: + - name: balancer_v2_arbitrum_token_balance_changes + meta: + blockchain: arbitrum + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &blockchain + name: blockchain + description: "Blockchain" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + - &evt_index + name: evt_index + description: 'Event index' + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: balancer_v2_arbitrum_token_balance_changes_daily + meta: + blockchain: arbitrum + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *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: balancer_v3_arbitrum_token_balance_changes + meta: + blockchain: arbitrum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_id + - *pool_address + - *pool_symbol + - *pool_type + - *version + - *token_address + - *token_symbol + - *delta_amount_raw + - *delta_amount + + - name: balancer_v3_arbitrum_token_balance_changes_daily + meta: + blockchain: arbitrum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *token_symbol + - *daily_delta + - *daily_delta_usd + - *daily_delta_eth \ No newline at end of file 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 new file mode 100644 index 0000000..a61b06f --- /dev/null +++ b/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'arbitrum' %} + +{{ config( + alias = 'balancer_v2_arbitrum_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_arbitrum' + ) +}} \ 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 new file mode 100644 index 0000000..4fc8746 --- /dev/null +++ b/models/_project/balancer/balances/arbitrum/balancer_v2_arbitrum_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_v2_arbitrum_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/arbitrum/balancer_v3_arbitrum_token_balance_changes.sql b/models/_project/balancer/balances/arbitrum/balancer_v3_arbitrum_token_balance_changes.sql new file mode 100644 index 0000000..ac84568 --- /dev/null +++ b/models/_project/balancer/balances/arbitrum/balancer_v3_arbitrum_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'arbitrum' %} + +{{ config( + alias = 'balancer_v3_arbitrum_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v3_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_arbitrum' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/arbitrum/balancer_v3_arbitrum_token_balance_changes_daily.sql b/models/_project/balancer/balances/arbitrum/balancer_v3_arbitrum_token_balance_changes_daily.sql new file mode 100644 index 0000000..a5760e4 --- /dev/null +++ b/models/_project/balancer/balances/arbitrum/balancer_v3_arbitrum_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_v3_arbitrum_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v3_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/avalanche_c/_schema.yml b/models/_project/balancer/balances/avalanche_c/_schema.yml new file mode 100644 index 0000000..f26d2aa --- /dev/null +++ b/models/_project/balancer/balances/avalanche_c/_schema.yml @@ -0,0 +1,100 @@ +version: 2 + +models: + - name: balancer_v2_avalanche_c_token_balance_changes + meta: + blockchain: avalanche_c + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['avalanche_c', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &blockchain + name: blockchain + description: "Blockchain" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + - &evt_index + name: evt_index + description: 'Event index' + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: balancer_v2_avalanche_c_token_balance_changes_daily + meta: + blockchain: avalanche_c + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['avalanche_c', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *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" \ 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 new file mode 100644 index 0000000..9c27538 --- /dev/null +++ b/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'avalanche_c' %} + +{{ config( + alias = 'balancer_v2_avalanche_c_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_avalanche_c' + ) +}} \ 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 new file mode 100644 index 0000000..87b4c6f --- /dev/null +++ b/models/_project/balancer/balances/avalanche_c/balancer_v2_avalanche_c_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'avalanche_c' %} + +{{ + config( + alias = 'balancer_v2_avalanche_c_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/balancer_token_balance_changes.sql b/models/_project/balancer/balances/balancer_token_balance_changes.sql new file mode 100644 index 0000000..f8f363d --- /dev/null +++ b/models/_project/balancer/balances/balancer_token_balance_changes.sql @@ -0,0 +1,46 @@ +{{ config( + alias = 'balancer_token_balance_changes' + , post_hook='{{ hide_spells() }}' + ) +}} + +{% set balancer_models = [ + ref('balancer_v2_arbitrum_token_balance_changes'), + ref('balancer_v2_avalanche_c_token_balance_changes'), + ref('balancer_v2_base_token_balance_changes'), + ref('balancer_v2_ethereum_token_balance_changes'), + ref('balancer_v2_gnosis_token_balance_changes'), + ref('balancer_v2_optimism_token_balance_changes'), + ref('balancer_v2_polygon_token_balance_changes'), + ref('balancer_v2_zkevm_token_balance_changes'), + ref('balancer_v3_ethereum_token_balance_changes'), + ref('balancer_v3_gnosis_token_balance_changes'), + ref('balancer_v3_arbitrum_token_balance_changes'), + ref('balancer_v3_base_token_balance_changes') +] %} + +SELECT * +FROM ( + {% for model in balancer_models %} + SELECT + block_date + , evt_block_time + , evt_block_number + , blockchain + , evt_tx_hash + , evt_index + , pool_id + , pool_address + , pool_symbol + , pool_type + , version + , token_address + , token_symbol + , delta_amount_raw + , delta_amount + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) \ No newline at end of file diff --git a/models/_project/balancer/balances/balancer_token_balance_changes_daily.sql b/models/_project/balancer/balances/balancer_token_balance_changes_daily.sql new file mode 100644 index 0000000..5765189 --- /dev/null +++ b/models/_project/balancer/balances/balancer_token_balance_changes_daily.sql @@ -0,0 +1,43 @@ +{{ config( + alias = 'balancer_token_balance_changes_daily' + , post_hook='{{ hide_spells() }}' + ) +}} + +{% set balancer_models = [ + ref('balancer_v2_arbitrum_token_balance_changes_daily'), + ref('balancer_v2_avalanche_c_token_balance_changes_daily'), + ref('balancer_v2_base_token_balance_changes_daily'), + ref('balancer_v2_ethereum_token_balance_changes_daily'), + ref('balancer_v2_gnosis_token_balance_changes_daily'), + ref('balancer_v2_optimism_token_balance_changes_daily'), + ref('balancer_v2_polygon_token_balance_changes_daily'), + ref('balancer_v2_zkevm_token_balance_changes_daily'), + ref('balancer_v3_ethereum_token_balance_changes_daily'), + ref('balancer_v3_gnosis_token_balance_changes_daily'), + ref('balancer_v3_arbitrum_token_balance_changes_daily'), + ref('balancer_v3_base_token_balance_changes_daily') +] %} + +SELECT * +FROM ( + {% for model in balancer_models %} + SELECT + block_date + , pool_id + , pool_address + , pool_symbol + , version + , blockchain + , pool_type + , token_address + , token_symbol + , daily_delta + , daily_delta_usd + , daily_delta_eth + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) \ No newline at end of file diff --git a/models/_project/balancer/balances/base/_schema.yml b/models/_project/balancer/balances/base/_schema.yml new file mode 100644 index 0000000..b3ffc16 --- /dev/null +++ b/models/_project/balancer/balances/base/_schema.yml @@ -0,0 +1,162 @@ +version: 2 + +models: + - name: balancer_v2_base_token_balance_changes + meta: + blockchain: base + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &blockchain + name: blockchain + description: "Blockchain" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + - &evt_index + name: evt_index + description: 'Event index' + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: balancer_v2_base_token_balance_changes_daily + meta: + blockchain: base + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *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: balancer_v3_base_token_balance_changes + meta: + blockchain: base + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_id + - *pool_address + - *pool_symbol + - *pool_type + - *version + - *token_address + - *token_symbol + - *delta_amount_raw + - *delta_amount + + - name: balancer_v3_base_token_balance_changes_daily + meta: + blockchain: base + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *token_symbol + - *daily_delta + - *daily_delta_usd + - *daily_delta_eth \ 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 new file mode 100644 index 0000000..e1978c1 --- /dev/null +++ b/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'base' %} + +{{ config( + alias = 'balancer_v2_base_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_base' + ) +}} \ 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 new file mode 100644 index 0000000..51d3193 --- /dev/null +++ b/models/_project/balancer/balances/base/balancer_v2_base_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v2_base_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + 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_v3_base_token_balance_changes.sql b/models/_project/balancer/balances/base/balancer_v3_base_token_balance_changes.sql new file mode 100644 index 0000000..4dda42d --- /dev/null +++ b/models/_project/balancer/balances/base/balancer_v3_base_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'base' %} + +{{ config( + alias = 'balancer_v3_base_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v3_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_base' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/base/balancer_v3_base_token_balance_changes_daily.sql b/models/_project/balancer/balances/base/balancer_v3_base_token_balance_changes_daily.sql new file mode 100644 index 0000000..39e9ea3 --- /dev/null +++ b/models/_project/balancer/balances/base/balancer_v3_base_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v3_base_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v3_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/ethereum/_schema.yml b/models/_project/balancer/balances/ethereum/_schema.yml new file mode 100644 index 0000000..9fe9fe5 --- /dev/null +++ b/models/_project/balancer/balances/ethereum/_schema.yml @@ -0,0 +1,193 @@ +version: 2 + +models: + - name: balancer_ethereum_balances + meta: + blockchain: ethereum + project: balancer + contributors: jacektrocinski, metacrypto, viniabussafi + config: + tags: ['ethereum', 'balancer', 'balances'] + description: > + ERC20 token rolling sum balances on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool + - token + columns: + - &day + name: day + description: "UTC event block time truncated to the day mark" + data_tests: + - not_null + - &pool + name: pool + description: "Balancer pool contract address" + - &token + name: token + description: "Token contract address" + - &cumulative_amount + name: cumulative_amount + description: "Balance of a token" + + - name: balancer_v2_ethereum_token_balance_changes + meta: + blockchain: ethereum + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &evt_block_time + name: evt_block_time + description: "Block time of transfer event" + - &evt_block_number + name: evt_block_number + description: "Block number of transfer event" + - &blockchain + name: blockchain + description: "Blockchain" + - &evt_tx_hash + name: evt_tx_hash + description: "Transaction hash of transfer event" + - &evt_index + name: evt_index + description: "Event index" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: balancer_v2_ethereum_token_balance_changes_daily + meta: + blockchain: ethereum + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *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: balancer_v3_ethereum_token_balance_changes + meta: + blockchain: ethereum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_id + - *pool_address + - *pool_symbol + - *pool_type + - *version + - *token_address + - *token_symbol + - *delta_amount_raw + - *delta_amount + + - name: balancer_v3_ethereum_token_balance_changes_daily + meta: + blockchain: ethereum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *token_symbol + - *daily_delta + - *daily_delta_usd + - *daily_delta_eth \ No newline at end of file diff --git a/models/_project/balancer/balances/ethereum/balancer_ethereum_balances.sql b/models/_project/balancer/balances/ethereum/balancer_ethereum_balances.sql new file mode 100644 index 0000000..cb6f222 --- /dev/null +++ b/models/_project/balancer/balances/ethereum/balancer_ethereum_balances.sql @@ -0,0 +1,71 @@ +{{ + config( + alias = 'balancer_ethereum_balances' + , post_hook='{{ hide_spells() }}' + ) +}} + +{% set balancer_contract = '0xba12222222228d8ba445958a75a0704d566bf2c8' %} + +WITH pools AS ( + SELECT pool as pools + FROM {{ source('balancer_v1_ethereum', 'BFactory_evt_LOG_NEW_POOL') }} +), + +joins AS ( + SELECT p.pools as pool, date_trunc('day', e.evt_block_time) AS day, e.contract_address AS token, SUM(CAST(value AS int256)) AS amount + FROM {{ source('erc20_ethereum', 'evt_Transfer') }} e + INNER JOIN pools p ON e."to" = p.pools + GROUP BY 1, 2, 3 + UNION ALL + SELECT e."to" as pool, date_trunc('day', e.evt_block_time) AS day, e.contract_address AS token, SUM(CAST(value as int256)) AS amount + FROM {{ source('erc20_ethereum', 'evt_Transfer') }} e + WHERE e."to" = {{balancer_contract}} + GROUP BY 1, 2, 3 +), + +exits AS ( + SELECT p.pools as pool, date_trunc('day', e.evt_block_time) AS day, e.contract_address AS token, -SUM(CAST(value as int256)) AS amount + FROM {{ source('erc20_ethereum', 'evt_Transfer') }} e + INNER JOIN pools p ON e."from" = p.pools + GROUP BY 1, 2, 3 + UNION ALL + SELECT e."from" as pool, date_trunc('day', e.evt_block_time) AS day, e.contract_address AS token, -SUM(CAST(value as int256)) AS amount + FROM {{ source('erc20_ethereum', 'evt_Transfer') }} e + WHERE e."from" = {{balancer_contract}} + GROUP BY 1, 2, 3 +), + +daily_delta_balance_by_token AS ( + SELECT pool, day, token, SUM(COALESCE(amount, CAST(0 as int256))) AS amount FROM + (SELECT * + FROM joins j + UNION ALL + SELECT * + FROM exits e) foo + GROUP BY 1, 2, 3 +), + +cumulative_balance_by_token AS ( + SELECT + pool, + token, + day, + LEAD(day, 1, now()) OVER (PARTITION BY pool, token ORDER BY day) AS day_of_next_change, + SUM(amount) OVER (PARTITION BY pool, token ORDER BY day ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_amount + FROM daily_delta_balance_by_token +), + + calendar AS ( + SELECT date_sequence AS day + FROM unnest(sequence(date('2020-01-01'), date(now()), interval '1' day)) as t(date_sequence) + ), + + +running_cumulative_balance_by_token AS ( + SELECT c.day, pool, token, cumulative_amount + FROM calendar c + LEFT JOIN cumulative_balance_by_token b ON b.day <= c.day AND c.day < b.day_of_next_change +) + +SELECT * FROM running_cumulative_balance_by_token \ 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 new file mode 100644 index 0000000..b7c9dbf --- /dev/null +++ b/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'ethereum' %} + +{{ config( + alias = 'balancer_v2_ethereum_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_ethereum' + ) +}} \ 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 new file mode 100644 index 0000000..9f5d818 --- /dev/null +++ b/models/_project/balancer/balances/ethereum/balancer_v2_ethereum_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v2_ethereum_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + 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_v3_ethereum_token_balance_changes.sql b/models/_project/balancer/balances/ethereum/balancer_v3_ethereum_token_balance_changes.sql new file mode 100644 index 0000000..4974b6c --- /dev/null +++ b/models/_project/balancer/balances/ethereum/balancer_v3_ethereum_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'ethereum' %} + +{{ config( + alias = 'balancer_v3_ethereum_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v3_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_ethereum' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/ethereum/balancer_v3_ethereum_token_balance_changes_daily.sql b/models/_project/balancer/balances/ethereum/balancer_v3_ethereum_token_balance_changes_daily.sql new file mode 100644 index 0000000..1b73c31 --- /dev/null +++ b/models/_project/balancer/balances/ethereum/balancer_v3_ethereum_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v3_ethereum_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v3_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/gnosis/_schema.yml b/models/_project/balancer/balances/gnosis/_schema.yml new file mode 100644 index 0000000..790b9fa --- /dev/null +++ b/models/_project/balancer/balances/gnosis/_schema.yml @@ -0,0 +1,162 @@ +version: 2 + +models: + - name: balancer_v2_gnosis_token_balance_changes + meta: + blockchain: gnosis + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &blockchain + name: blockchain + description: "Blockchain" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + - &evt_index + name: evt_index + description: 'Event index' + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: balancer_v2_gnosis_token_balance_changes_daily + meta: + blockchain: gnosis + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *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: balancer_v3_gnosis_token_balance_changes + meta: + blockchain: gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_id + - *pool_address + - *pool_symbol + - *pool_type + - *version + - *token_address + - *token_symbol + - *delta_amount_raw + - *delta_amount + + - name: balancer_v3_gnosis_token_balance_changes_daily + meta: + blockchain: gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *token_symbol + - *daily_delta + - *daily_delta_usd + - *daily_delta_eth \ 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 new file mode 100644 index 0000000..4c5e45b --- /dev/null +++ b/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'gnosis' %} + +{{ config( + alias = 'balancer_v2_gnosis_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_gnosis' + ) +}} \ 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 new file mode 100644 index 0000000..734fe8f --- /dev/null +++ b/models/_project/balancer/balances/gnosis/balancer_v2_gnosis_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v2_gnosis_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + 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_v3_gnosis_token_balance_changes.sql b/models/_project/balancer/balances/gnosis/balancer_v3_gnosis_token_balance_changes.sql new file mode 100644 index 0000000..11e492f --- /dev/null +++ b/models/_project/balancer/balances/gnosis/balancer_v3_gnosis_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'gnosis' %} + +{{ config( + alias = 'balancer_v3_gnosis_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v3_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_gnosis' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/gnosis/balancer_v3_gnosis_token_balance_changes_daily.sql b/models/_project/balancer/balances/gnosis/balancer_v3_gnosis_token_balance_changes_daily.sql new file mode 100644 index 0000000..cfb0834 --- /dev/null +++ b/models/_project/balancer/balances/gnosis/balancer_v3_gnosis_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v3_gnosis_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v3_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/balances/optimism/_schema.yml b/models/_project/balancer/balances/optimism/_schema.yml new file mode 100644 index 0000000..458444d --- /dev/null +++ b/models/_project/balancer/balances/optimism/_schema.yml @@ -0,0 +1,100 @@ +version: 2 + +models: + - name: balancer_v2_optimism_token_balance_changes + meta: + blockchain: optimism + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['optimism', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &blockchain + name: blockchain + description: "Blockchain" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + - &evt_index + name: evt_index + description: 'Event index' + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: balancer_v2_optimism_token_balance_changes_daily + meta: + blockchain: optimism + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['optimism', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *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" \ 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 new file mode 100644 index 0000000..c8db6ad --- /dev/null +++ b/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'optimism' %} + +{{ config( + alias = 'balancer_v2_optimism_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_optimism' + ) +}} \ 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 new file mode 100644 index 0000000..726b978 --- /dev/null +++ b/models/_project/balancer/balances/optimism/balancer_v2_optimism_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'optimism' %} + +{{ + config( + alias = 'balancer_v2_optimism_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + 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/_schema.yml b/models/_project/balancer/balances/polygon/_schema.yml new file mode 100644 index 0000000..a55b1ec --- /dev/null +++ b/models/_project/balancer/balances/polygon/_schema.yml @@ -0,0 +1,100 @@ +version: 2 + +models: + - name: balancer_v2_polygon_token_balance_changes + meta: + blockchain: polygon + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['polygon', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &blockchain + name: blockchain + description: "Blockchain" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + - &evt_index + name: evt_index + description: 'Event index' + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: balancer_v2_polygon_token_balance_changes_daily + meta: + blockchain: polygon + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['polygon', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *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" \ 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 new file mode 100644 index 0000000..a068d47 --- /dev/null +++ b/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'polygon' %} + +{{ config( + alias = 'balancer_v2_polygon_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_polygon' + ) +}} \ 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 new file mode 100644 index 0000000..217b529 --- /dev/null +++ b/models/_project/balancer/balances/polygon/balancer_v2_polygon_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'polygon' %} + +{{ + config( + alias = 'balancer_v2_polygon_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + 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/_schema.yml b/models/_project/balancer/balances/zkevm/_schema.yml new file mode 100644 index 0000000..56ef4d3 --- /dev/null +++ b/models/_project/balancer/balances/zkevm/_schema.yml @@ -0,0 +1,100 @@ +version: 2 + +models: + - name: balancer_v2_zkevm_token_balance_changes + meta: + blockchain: zkevm + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['zkevm', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - token_address + columns: + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &blockchain + name: blockchain + description: "Blockchain" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + - &evt_index + name: evt_index + description: 'Event index' + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &delta_amount_raw + name: delta_amount_raw + description: "Raw value of the transaction at the time of execution in the original currency" + - &delta_amount + name: delta_amount + description: "Normalized value of the transaction at the time of execution in the original currency" + + - name: balancer_v2_zkevm_token_balance_changes_daily + meta: + blockchain: zkevm + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['zkevm', 'bpt', 'supply', 'changes'] + description: > + Token Balance Changes on Balancer Pools, grouped by day. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_address + columns: + - *block_date + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *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" \ 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 new file mode 100644 index 0000000..68279e8 --- /dev/null +++ b/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'zkevm' %} + +{{ config( + alias = 'balancer_v2_zkevm_token_balance_changes', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_zkevm' + ) +}} \ 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 new file mode 100644 index 0000000..423a671 --- /dev/null +++ b/models/_project/balancer/balances/zkevm/balancer_v2_zkevm_token_balance_changes_daily.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'zkevm' %} + +{{ + config( + alias = 'balancer_v2_zkevm_token_balance_changes_daily', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_token_balance_changes_daily_agg_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/_schema.yml b/models/_project/balancer/bpt/_schema.yml new file mode 100644 index 0000000..eb4c1db --- /dev/null +++ b/models/_project/balancer/bpt/_schema.yml @@ -0,0 +1,176 @@ +version: 2 + +models: + - name: balancer_transfers_bpt + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevmn + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &contract_address + name: contract_address + description: 'zkevm address for the liquidity pool used in transaction' + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + - &evt_index + name: evt_index + description: 'Event index' + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &from + name: from + description: 'Address of BPT provider of transfer event' + - &to + name: to + description: 'Address of BPT receiver of transfer event' + - &value + name: value + description: 'Amount of BPT transferred in transfer event' + + - name: balancer_bpt_prices + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + sector: dex + contributors: thetroyharris, victorstefenon, viniabussafi + config: + tags: ['balancer', 'amm', 'dex', 'bpt', 'prices', 'ethereum', 'arbitrum', 'optimism', 'polygon', 'gnosis', 'avalanche_c', 'base', 'zkevm'] + description: > + Balancer Pool Token (BPT) hourly median price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - &day + name: day + description: "Block date in UTC" + - *version + - &decimals + name: decimals + description: "Token decimals. 18, by default, on BPTs" + - *contract_address + - &bpt_price + name: bpt_price + description: "Price of the BPT" + + + - name: balancer_bpt_supply + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + contributors: thetroyharris, viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'bpt'] + description: > + The Balancer Pool Token (BPT) supply over time of ComposableStablePools versions 4+ + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - *version + - *blockchain + - &token_address + name: token_address + description: "Contract address of the BPT" + - &supply + name: supply + description: "Supply of the BPT, discounted of premints" + + - name: balancer_bpt_supply_changes + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + contributors: viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - *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: balancer_bpt_supply_changes_daily + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + contributors: viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - &daily_delta + name: daily_delta + description: "Daily total impact on BPT supply" \ No newline at end of file diff --git a/models/_project/balancer/bpt/arbitrum/_schema.yml b/models/_project/balancer/bpt/arbitrum/_schema.yml new file mode 100644 index 0000000..1cf07fe --- /dev/null +++ b/models/_project/balancer/bpt/arbitrum/_schema.yml @@ -0,0 +1,314 @@ +version: 2 + +models: + - name: balancer_v2_arbitrum_transfers_bpt + meta: + blockchain: arbitrum + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['arbitrum', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on Arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &contract_address + name: contract_address + description: 'Arbitrum address for the liquidity pool used in transaction' + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + tests: + - not_null + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + tests: + - not_null + - &evt_index + name: evt_index + description: 'Event index' + tests: + - not_null + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &from + name: from + description: 'Address of BPT provider of transfer event' + - &to + name: to + description: 'Address of BPT receiver of transfer event' + - &value + name: value + description: 'Amount of BPT transferred in transfer event' + + - name: balancer_v2_arbitrum_bpt_prices + meta: + blockchain: arbitrum + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['arbitrum', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - &day + name: day + description: "Block date in UTC" + - *version + - &decimals + name: decimals + description: "Token decimals. 18, by default, on BPTs" + - *contract_address + - &bpt_price + name: bpt_price + description: "Price of the BPT" + + - name: balancer_v2_arbitrum_bpt_supply + meta: + blockchain: arbitrum + project: balancer_v2 + contributors: thetroyharris, viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - *version + - *blockchain + - &token_address + name: token_address + description: "Contract address of the BPT" + - &supply + name: supply + description: "Supply of the BPT, discounted of premints" + + - name: balancer_v2_arbitrum_bpt_supply_changes + meta: + blockchain: arbitrum + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - *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: balancer_v2_arbitrum_bpt_supply_changes_daily + meta: + blockchain: arbitrum + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - &daily_delta + name: daily_delta + description: "Daily total impact on BPT supply" + + - name: balancer_v3_arbitrum_transfers_bpt + meta: + blockchain: arbitrum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - *blockchain + - *version + - *contract_address + - *block_date + - *block_month + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - *from + - *to + - *value + + - name: balancer_v3_arbitrum_bpt_prices + meta: + blockchain: arbitrum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - *day + - *version + - *decimals + - *contract_address + - *bpt_price + + - name: balancer_v3_arbitrum_bpt_supply + meta: + blockchain: arbitrum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - *pool_type + - *version + - *blockchain + - *token_address + - *supply + + - name: balancer_v3_arbitrum_bpt_supply_changes + meta: + blockchain: arbitrum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - *pool_symbol + - *version + - *label + - *token_address + - *delta_amount_raw + - *delta_amount + + - name: balancer_v3_arbitrum_bpt_supply_changes_daily + meta: + blockchain: arbitrum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - *daily_delta \ 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 new file mode 100644 index 0000000..018bf8c --- /dev/null +++ b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_v2_arbitrum_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v2_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_arbitrum' + ) +}} 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 new file mode 100644 index 0000000..c31bdb6 --- /dev/null +++ b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_bpt_supply.sql @@ -0,0 +1,17 @@ +{% set blockchain = 'arbitrum' %} + +{{ config( + alias = 'balancer_v2_arbitrum_bpt_supply', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + pool_labels_model = 'balancer_v2_pools_arbitrum', + transfers_spell = ref('balancer_v2_arbitrum_transfers_bpt') + ) +}} \ 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 new file mode 100644 index 0000000..742fc91 --- /dev/null +++ b/models/_project/balancer/bpt/arbitrum/balancer_v2_arbitrum_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_v2_arbitrum_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/arbitrum/balancer_v3_arbitrum_bpt_prices.sql b/models/_project/balancer/bpt/arbitrum/balancer_v3_arbitrum_bpt_prices.sql new file mode 100644 index 0000000..16389a3 --- /dev/null +++ b/models/_project/balancer/bpt/arbitrum/balancer_v3_arbitrum_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_v3_arbitrum_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v3_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_arbitrum' + ) +}} diff --git a/models/_project/balancer/bpt/arbitrum/balancer_v3_arbitrum_bpt_supply.sql b/models/_project/balancer/bpt/arbitrum/balancer_v3_arbitrum_bpt_supply.sql new file mode 100644 index 0000000..bc5a797 --- /dev/null +++ b/models/_project/balancer/bpt/arbitrum/balancer_v3_arbitrum_bpt_supply.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_v3_arbitrum_bpt_supply', + materialized = 'table', + + ) +}} + +{{ + balancer_v3_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + pool_labels_model = 'balancer_v3_pools_arbitrum', + transfers_spell = ref('balancer_v3_arbitrum_transfers_bpt') + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/arbitrum/balancer_v3_arbitrum_transfers_bpt.sql b/models/_project/balancer/bpt/arbitrum/balancer_v3_arbitrum_transfers_bpt.sql new file mode 100644 index 0000000..471acbf --- /dev/null +++ b/models/_project/balancer/bpt/arbitrum/balancer_v3_arbitrum_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_v3_arbitrum_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v3_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/avalanche_c/_schema.yml b/models/_project/balancer/bpt/avalanche_c/_schema.yml new file mode 100644 index 0000000..170b830 --- /dev/null +++ b/models/_project/balancer/bpt/avalanche_c/_schema.yml @@ -0,0 +1,184 @@ +version: 2 + +models: + - name: balancer_v2_avalanche_c_transfers_bpt + meta: + blockchain: avalanche_c + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['avalanche_c', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on avalanche_c. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &contract_address + name: contract_address + description: 'avalanche_c address for the liquidity pool used in transaction' + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + tests: + - not_null + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + tests: + - not_null + - &evt_index + name: evt_index + description: 'Event index' + tests: + - not_null + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &from + name: from + description: 'Address of BPT provider of transfer event' + - &to + name: to + description: 'Address of BPT receiver of transfer event' + - &value + name: value + description: 'Amount of BPT transferred in transfer event' + + - name: balancer_v2_avalanche_c_bpt_prices + meta: + blockchain: avalanche_c + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['avalanche_c', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - &day + name: day + description: "Block date in UTC" + - *version + - &decimals + name: decimals + description: "Token decimals. 18, by default, on BPTs" + - *contract_address + - &bpt_price + name: bpt_price + description: "Price of the BPT" + + - name: balancer_v2_avalanche_c_bpt_supply + meta: + blockchain: avalanche_c + project: balancer_v2 + contributors: thetroyharris, viniabussafi + config: + tags: ['avalanche_c', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - *version + - *blockchain + - &token_address + name: token_address + description: "Contract address of the BPT" + - &supply + name: supply + description: "Supply of the BPT, discounted of premints" + + - name: balancer_v2_avalanche_c_bpt_supply_changes + meta: + blockchain: avalanche_c + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['avalanche_c', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - *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: balancer_v2_avalanche_c_bpt_supply_changes_daily + meta: + blockchain: avalanche_c + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['avalanche_c', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - &daily_delta + name: daily_delta + description: "Daily total impact on BPT supply" \ 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 new file mode 100644 index 0000000..700799c --- /dev/null +++ b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'avalanche_c' %} + +{{ + config( + alias = 'balancer_v2_avalanche_c_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v2_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_avalanche_c' + ) +}} 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 new file mode 100644 index 0000000..425deeb --- /dev/null +++ b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_bpt_supply.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'avalanche_c' %} + +{{ + config( + alias = 'balancer_v2_avalanche_c_bpt_supply', + materialized = 'table', + + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + pool_labels_model = 'balancer_v2_pools_avalanche_c', + transfers_spell = ref('balancer_v2_avalanche_c_transfers_bpt') + ) +}} \ 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 new file mode 100644 index 0000000..5739f36 --- /dev/null +++ b/models/_project/balancer/bpt/avalanche_c/balancer_v2_avalanche_c_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'avalanche_c' %} + +{{ + config( + alias = 'balancer_v2_avalanche_c_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/balancer_bpt_prices.sql b/models/_project/balancer/bpt/balancer_bpt_prices.sql new file mode 100644 index 0000000..ca6fdff --- /dev/null +++ b/models/_project/balancer/bpt/balancer_bpt_prices.sql @@ -0,0 +1,39 @@ +{{ config( + alias = 'balancer_bpt_prices' + , post_hook='{{ hide_spells() }}' + ) +}} + +{% set balancer_models = [ + ref('balancer_v2_ethereum_bpt_prices'), + ref('balancer_v2_arbitrum_bpt_prices'), + ref('balancer_v2_polygon_bpt_prices'), + ref('balancer_v2_gnosis_bpt_prices'), + ref('balancer_v2_optimism_bpt_prices'), + ref('balancer_v2_avalanche_c_bpt_prices'), + ref('balancer_v2_base_bpt_prices'), + ref('balancer_v2_zkevm_bpt_prices'), + ref('balancer_v3_ethereum_bpt_prices'), + ref('balancer_v3_gnosis_bpt_prices'), + ref('balancer_v3_arbitrum_bpt_prices'), + ref('balancer_v3_base_bpt_prices') +] %} + +SELECT * +FROM ( + {% for bpt_prices in balancer_models %} + SELECT + day, + blockchain, + version, + decimals, + contract_address, + pool_type, + bpt_price + FROM {{ bpt_prices }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) +; diff --git a/models/_project/balancer/bpt/balancer_bpt_supply.sql b/models/_project/balancer/bpt/balancer_bpt_supply.sql new file mode 100644 index 0000000..394bcd9 --- /dev/null +++ b/models/_project/balancer/bpt/balancer_bpt_supply.sql @@ -0,0 +1,37 @@ +{{ config( + alias = 'balancer_bpt_supply' + , post_hook='{{ hide_spells() }}' + ) +}} + +{% set bpt_supply_models = [ + ref('balancer_v2_ethereum_bpt_supply'), + ref('balancer_v2_arbitrum_bpt_supply'), + ref('balancer_v2_polygon_bpt_supply'), + ref('balancer_v2_gnosis_bpt_supply'), + ref('balancer_v2_optimism_bpt_supply'), + ref('balancer_v2_avalanche_c_bpt_supply'), + ref('balancer_v2_base_bpt_supply'), + ref('balancer_v2_zkevm_bpt_supply'), + ref('balancer_v3_gnosis_bpt_supply'), + ref('balancer_v3_ethereum_bpt_supply'), + ref('balancer_v3_arbitrum_bpt_supply'), + ref('balancer_v3_base_bpt_supply') +] %} + +SELECT * +FROM ( + {% for bpt_supply_model in bpt_supply_models %} + SELECT + day, + token_address, + pool_type, + version, + blockchain, + supply + FROM {{ bpt_supply_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +); diff --git a/models/_project/balancer/bpt/balancer_transfers_bpt.sql b/models/_project/balancer/bpt/balancer_transfers_bpt.sql new file mode 100644 index 0000000..f7010d5 --- /dev/null +++ b/models/_project/balancer/bpt/balancer_transfers_bpt.sql @@ -0,0 +1,42 @@ +{{ config( + alias = 'balancer_transfers_bpt' + , post_hook='{{ hide_spells() }}' + ) +}} + +{% set balancer_models = [ + ref('balancer_v2_arbitrum_transfers_bpt'), + ref('balancer_v2_avalanche_c_transfers_bpt'), + ref('balancer_v2_base_transfers_bpt'), + ref('balancer_v2_ethereum_transfers_bpt'), + ref('balancer_v2_gnosis_transfers_bpt'), + ref('balancer_v2_optimism_transfers_bpt'), + ref('balancer_v2_polygon_transfers_bpt'), + ref('balancer_v2_zkevm_transfers_bpt'), + ref('balancer_v3_ethereum_transfers_bpt'), + ref('balancer_v3_gnosis_transfers_bpt'), + ref('balancer_v3_arbitrum_transfers_bpt'), + ref('balancer_v3_base_transfers_bpt') +] %} + +SELECT * +FROM ( + {% for model in balancer_models %} + SELECT + blockchain + , version + , contract_address + , block_date + , evt_tx_hash + , evt_index + , evt_block_time + , evt_block_number + , "from" + , to + , value + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) \ No newline at end of file diff --git a/models/_project/balancer/bpt/base/_schema.yml b/models/_project/balancer/bpt/base/_schema.yml new file mode 100644 index 0000000..54e716b --- /dev/null +++ b/models/_project/balancer/bpt/base/_schema.yml @@ -0,0 +1,314 @@ +version: 2 + +models: + - name: balancer_v2_base_transfers_bpt + meta: + blockchain: base + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['base', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on base. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &contract_address + name: contract_address + description: 'base address for the liquidity pool used in transaction' + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + tests: + - not_null + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + tests: + - not_null + - &evt_index + name: evt_index + description: 'Event index' + tests: + - not_null + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &from + name: from + description: 'Address of BPT provider of transfer event' + - &to + name: to + description: 'Address of BPT receiver of transfer event' + - &value + name: value + description: 'Amount of BPT transferred in transfer event' + + - name: balancer_v2_base_bpt_prices + meta: + blockchain: base + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['base', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - &day + name: day + description: "Block date in UTC" + - *version + - &decimals + name: decimals + description: "Token decimals. 18, by default, on BPTs" + - *contract_address + - &bpt_price + name: bpt_price + description: "Price of the BPT" + + - name: balancer_v2_base_bpt_supply + meta: + blockchain: base + project: balancer_v2 + contributors: thetroyharris, viniabussafi + config: + tags: ['base', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - *version + - *blockchain + - &token_address + name: token_address + description: "Contract address of the BPT" + - &supply + name: supply + description: "Supply of the BPT, discounted of premints" + + - name: balancer_v2_base_bpt_supply_changes + meta: + blockchain: base + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - *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: balancer_v2_base_bpt_supply_changes_daily + meta: + blockchain: base + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - &daily_delta + name: daily_delta + description: "Daily total impact on BPT supply" + + - name: balancer_v3_base_transfers_bpt + meta: + blockchain: base + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on base. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - *blockchain + - *version + - *contract_address + - *block_date + - *block_month + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - *from + - *to + - *value + + - name: balancer_v3_base_bpt_prices + meta: + blockchain: base + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - *day + - *version + - *decimals + - *contract_address + - *bpt_price + + - name: balancer_v3_base_bpt_supply + meta: + blockchain: base + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - *pool_type + - *version + - *blockchain + - *token_address + - *supply + + - name: balancer_v3_base_bpt_supply_changes + meta: + blockchain: base + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - *pool_symbol + - *version + - *label + - *token_address + - *delta_amount_raw + - *delta_amount + + - name: balancer_v3_base_bpt_supply_changes_daily + meta: + blockchain: base + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['base', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - *daily_delta \ 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 new file mode 100644 index 0000000..6205eb4 --- /dev/null +++ b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v2_base_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v2_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_base' + ) +}} 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 new file mode 100644 index 0000000..ef9467a --- /dev/null +++ b/models/_project/balancer/bpt/base/balancer_v2_base_bpt_supply.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v2_base_bpt_supply', + materialized = 'table', + + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + pool_labels_model = 'balancer_v2_pools_base', + transfers_spell = ref('balancer_v2_base_transfers_bpt') + ) +}} \ 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 new file mode 100644 index 0000000..94d228e --- /dev/null +++ b/models/_project/balancer/bpt/base/balancer_v2_base_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v2_base_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/base/balancer_v3_base_bpt_prices.sql b/models/_project/balancer/bpt/base/balancer_v3_base_bpt_prices.sql new file mode 100644 index 0000000..20a3eb7 --- /dev/null +++ b/models/_project/balancer/bpt/base/balancer_v3_base_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v3_base_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v3_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_base' + ) +}} diff --git a/models/_project/balancer/bpt/base/balancer_v3_base_bpt_supply.sql b/models/_project/balancer/bpt/base/balancer_v3_base_bpt_supply.sql new file mode 100644 index 0000000..e4351b7 --- /dev/null +++ b/models/_project/balancer/bpt/base/balancer_v3_base_bpt_supply.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v3_base_bpt_supply', + materialized = 'table', + + ) +}} + +{{ + balancer_v3_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + pool_labels_model = 'balancer_v3_pools_base', + transfers_spell = ref('balancer_v3_base_transfers_bpt') + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/base/balancer_v3_base_transfers_bpt.sql b/models/_project/balancer/bpt/base/balancer_v3_base_transfers_bpt.sql new file mode 100644 index 0000000..4c3134e --- /dev/null +++ b/models/_project/balancer/bpt/base/balancer_v3_base_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v3_base_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v3_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/ethereum/_schema.yml b/models/_project/balancer/bpt/ethereum/_schema.yml new file mode 100644 index 0000000..1538c2e --- /dev/null +++ b/models/_project/balancer/bpt/ethereum/_schema.yml @@ -0,0 +1,314 @@ +version: 2 + +models: + - name: balancer_v2_ethereum_transfers_bpt + meta: + blockchain: ethereum + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['ethereum', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on ethereum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &contract_address + name: contract_address + description: 'ethereum address for the liquidity pool used in transaction' + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + tests: + - not_null + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + tests: + - not_null + - &evt_index + name: evt_index + description: 'Event index' + tests: + - not_null + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &from + name: from + description: 'Address of BPT provider of transfer event' + - &to + name: to + description: 'Address of BPT receiver of transfer event' + - &value + name: value + description: 'Amount of BPT transferred in transfer event' + + - name: balancer_v2_ethereum_bpt_prices + meta: + blockchain: ethereum + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['ethereum', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - &day + name: day + description: "Block date in UTC" + - *version + - &decimals + name: decimals + description: "Token decimals. 18, by default, on BPTs" + - *contract_address + - &bpt_price + name: bpt_price + description: "Price of the BPT" + + - name: balancer_v2_ethereum_bpt_supply + meta: + blockchain: ethereum + project: balancer_v2 + contributors: thetroyharris, viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - *version + - *blockchain + - &token_address + name: token_address + description: "Contract address of the BPT" + - &supply + name: supply + description: "Supply of the BPT, discounted of premints" + + - name: balancer_v2_ethereum_bpt_supply_changes + meta: + blockchain: ethereum + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - *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: balancer_v2_ethereum_bpt_supply_changes_daily + meta: + blockchain: ethereum + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - &daily_delta + name: daily_delta + description: "Daily total impact on BPT supply" + + - name: balancer_v3_ethereum_transfers_bpt + meta: + blockchain: ethereum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on ethereum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - *blockchain + - *version + - *contract_address + - *block_date + - *block_month + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - *from + - *to + - *value + + - name: balancer_v3_ethereum_bpt_prices + meta: + blockchain: ethereum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - *day + - *version + - *decimals + - *contract_address + - *bpt_price + + - name: balancer_v3_ethereum_bpt_supply + meta: + blockchain: ethereum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - *pool_type + - *version + - *blockchain + - *token_address + - *supply + + - name: balancer_v3_ethereum_bpt_supply_changes + meta: + blockchain: ethereum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - *pool_symbol + - *version + - *label + - *token_address + - *delta_amount_raw + - *delta_amount + + - name: balancer_v3_ethereum_bpt_supply_changes_daily + meta: + blockchain: ethereum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['ethereum', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - *daily_delta \ 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 new file mode 100644 index 0000000..c61b06f --- /dev/null +++ b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v2_ethereum_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v2_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_ethereum' + ) +}} 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 new file mode 100644 index 0000000..e9fe5b3 --- /dev/null +++ b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_bpt_supply.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v2_ethereum_bpt_supply', + materialized = 'table', + + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + pool_labels_model = 'balancer_v2_pools_ethereum', + transfers_spell = ref('balancer_v2_ethereum_transfers_bpt') + ) +}} \ 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 new file mode 100644 index 0000000..59a7ab6 --- /dev/null +++ b/models/_project/balancer/bpt/ethereum/balancer_v2_ethereum_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v2_ethereum_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/ethereum/balancer_v3_ethereum_bpt_prices.sql b/models/_project/balancer/bpt/ethereum/balancer_v3_ethereum_bpt_prices.sql new file mode 100644 index 0000000..186b787 --- /dev/null +++ b/models/_project/balancer/bpt/ethereum/balancer_v3_ethereum_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v3_ethereum_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v3_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_ethereum' + ) +}} diff --git a/models/_project/balancer/bpt/ethereum/balancer_v3_ethereum_bpt_supply.sql b/models/_project/balancer/bpt/ethereum/balancer_v3_ethereum_bpt_supply.sql new file mode 100644 index 0000000..4d0dc77 --- /dev/null +++ b/models/_project/balancer/bpt/ethereum/balancer_v3_ethereum_bpt_supply.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v3_ethereum_bpt_supply', + materialized = 'table', + + ) +}} + +{{ + balancer_v3_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + pool_labels_model = 'balancer_v3_pools_ethereum', + transfers_spell = ref('balancer_v3_ethereum_transfers_bpt') + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/ethereum/balancer_v3_ethereum_transfers_bpt.sql b/models/_project/balancer/bpt/ethereum/balancer_v3_ethereum_transfers_bpt.sql new file mode 100644 index 0000000..1338f05 --- /dev/null +++ b/models/_project/balancer/bpt/ethereum/balancer_v3_ethereum_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v3_ethereum_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v3_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/gnosis/_schema.yml b/models/_project/balancer/bpt/gnosis/_schema.yml new file mode 100644 index 0000000..ee90702 --- /dev/null +++ b/models/_project/balancer/bpt/gnosis/_schema.yml @@ -0,0 +1,314 @@ +version: 2 + +models: + - name: balancer_v2_gnosis_transfers_bpt + meta: + blockchain: gnosis + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['gnosis', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on gnosis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &contract_address + name: contract_address + description: 'gnosis address for the liquidity pool used in transaction' + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + tests: + - not_null + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + tests: + - not_null + - &evt_index + name: evt_index + description: 'Event index' + tests: + - not_null + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &from + name: from + description: 'Address of BPT provider of transfer event' + - &to + name: to + description: 'Address of BPT receiver of transfer event' + - &value + name: value + description: 'Amount of BPT transferred in transfer event' + + - name: balancer_v2_gnosis_bpt_prices + meta: + blockchain: gnosis + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['gnosis', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - &day + name: day + description: "Block date in UTC" + - *version + - &decimals + name: decimals + description: "Token decimals. 18, by default, on BPTs" + - *contract_address + - &bpt_price + name: bpt_price + description: "Price of the BPT" + + - name: balancer_v2_gnosis_bpt_supply + meta: + blockchain: gnosis + project: balancer_v2 + contributors: thetroyharris, viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - *version + - *blockchain + - &token_address + name: token_address + description: "Contract address of the BPT" + - &supply + name: supply + description: "Supply of the BPT, discounted of premints" + + - name: balancer_v2_gnosis_bpt_supply_changes + meta: + blockchain: gnosis + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - *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: balancer_v2_gnosis_bpt_supply_changes_daily + meta: + blockchain: gnosis + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - &daily_delta + name: daily_delta + description: "Daily total impact on BPT supply" + + - name: balancer_v3_gnosis_transfers_bpt + meta: + blockchain: gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on gnosis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - *blockchain + - *version + - *contract_address + - *block_date + - *block_month + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - *from + - *to + - *value + + - name: balancer_v3_gnosis_bpt_prices + meta: + blockchain: gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - *day + - *version + - *decimals + - *contract_address + - *bpt_price + + - name: balancer_v3_gnosis_bpt_supply + meta: + blockchain: gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - *pool_type + - *version + - *blockchain + - *token_address + - *supply + + - name: balancer_v3_gnosis_bpt_supply_changes + meta: + blockchain: gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - *pool_symbol + - *version + - *label + - *token_address + - *delta_amount_raw + - *delta_amount + + - name: balancer_v3_gnosis_bpt_supply_changes_daily + meta: + blockchain: gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['gnosis', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - *daily_delta \ 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 new file mode 100644 index 0000000..3e03982 --- /dev/null +++ b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v2_gnosis_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v2_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_gnosis' + ) +}} 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 new file mode 100644 index 0000000..f48fe98 --- /dev/null +++ b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_bpt_supply.sql @@ -0,0 +1,18 @@ +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v2_gnosis_bpt_supply', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + pool_labels_model = 'balancer_v2_pools_gnosis', + transfers_spell = ref('balancer_v2_gnosis_transfers_bpt') + ) +}} \ 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 new file mode 100644 index 0000000..c7bd53a --- /dev/null +++ b/models/_project/balancer/bpt/gnosis/balancer_v2_gnosis_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v2_gnosis_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/gnosis/balancer_v3_gnosis_bpt_prices.sql b/models/_project/balancer/bpt/gnosis/balancer_v3_gnosis_bpt_prices.sql new file mode 100644 index 0000000..66f147b --- /dev/null +++ b/models/_project/balancer/bpt/gnosis/balancer_v3_gnosis_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v3_gnosis_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v3_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_gnosis' + ) +}} diff --git a/models/_project/balancer/bpt/gnosis/balancer_v3_gnosis_bpt_supply.sql b/models/_project/balancer/bpt/gnosis/balancer_v3_gnosis_bpt_supply.sql new file mode 100644 index 0000000..795a8be --- /dev/null +++ b/models/_project/balancer/bpt/gnosis/balancer_v3_gnosis_bpt_supply.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v3_gnosis_bpt_supply', + materialized = 'table', + + ) +}} + +{{ + balancer_v3_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + pool_labels_model = 'balancer_v3_pools_gnosis', + transfers_spell = ref('balancer_v3_gnosis_transfers_bpt') + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/gnosis/balancer_v3_gnosis_transfers_bpt.sql b/models/_project/balancer/bpt/gnosis/balancer_v3_gnosis_transfers_bpt.sql new file mode 100644 index 0000000..240df13 --- /dev/null +++ b/models/_project/balancer/bpt/gnosis/balancer_v3_gnosis_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v3_gnosis_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v3_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/optimism/_schema.yml b/models/_project/balancer/bpt/optimism/_schema.yml new file mode 100644 index 0000000..4e9ba9c --- /dev/null +++ b/models/_project/balancer/bpt/optimism/_schema.yml @@ -0,0 +1,184 @@ +version: 2 + +models: + - name: balancer_v2_optimism_transfers_bpt + meta: + blockchain: optimism + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['optimism', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on optimism. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &contract_address + name: contract_address + description: 'optimism address for the liquidity pool used in transaction' + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + tests: + - not_null + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + tests: + - not_null + - &evt_index + name: evt_index + description: 'Event index' + tests: + - not_null + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &from + name: from + description: 'Address of BPT provider of transfer event' + - &to + name: to + description: 'Address of BPT receiver of transfer event' + - &value + name: value + description: 'Amount of BPT transferred in transfer event' + + - name: balancer_v2_optimism_bpt_prices + meta: + blockchain: optimism + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['optimism', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - &day + name: day + description: "Block date in UTC" + - *version + - &decimals + name: decimals + description: "Token decimals. 18, by default, on BPTs" + - *contract_address + - &bpt_price + name: bpt_price + description: "Price of the BPT" + + - name: balancer_v2_optimism_bpt_supply + meta: + blockchain: optimism + project: balancer_v2 + contributors: thetroyharris, viniabussafi + config: + tags: ['optimism', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - *version + - *blockchain + - &token_address + name: token_address + description: "Contract address of the BPT" + - &supply + name: supply + description: "Supply of the BPT, discounted of premints" + + - name: balancer_v2_optimism_bpt_supply_changes + meta: + blockchain: optimism + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['optimism', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - *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: balancer_v2_optimism_bpt_supply_changes_daily + meta: + blockchain: optimism + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['optimism', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - &daily_delta + name: daily_delta + description: "Daily total impact on BPT supply" \ 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 new file mode 100644 index 0000000..c58e69b --- /dev/null +++ b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'optimism' %} + +{{ + config( + alias = 'balancer_v2_optimism_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v2_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_optimism' + ) +}} 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 new file mode 100644 index 0000000..e1049df --- /dev/null +++ b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_bpt_supply.sql @@ -0,0 +1,18 @@ +{% set blockchain = 'optimism' %} + +{{ + config( + alias = 'balancer_v2_optimism_bpt_supply', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + pool_labels_model = 'balancer_v2_pools_optimism', + transfers_spell = ref('balancer_v2_optimism_transfers_bpt') + ) +}} \ 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 new file mode 100644 index 0000000..619e747 --- /dev/null +++ b/models/_project/balancer/bpt/optimism/balancer_v2_optimism_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'optimism' %} + +{{ + config( + alias = 'balancer_v2_optimism_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/polygon/_schema.yml b/models/_project/balancer/bpt/polygon/_schema.yml new file mode 100644 index 0000000..b7a9693 --- /dev/null +++ b/models/_project/balancer/bpt/polygon/_schema.yml @@ -0,0 +1,184 @@ +version: 2 + +models: + - name: balancer_v2_polygon_transfers_bpt + meta: + blockchain: polygon + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['polygon', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on polygon. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &contract_address + name: contract_address + description: 'polygon address for the liquidity pool used in transaction' + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + tests: + - not_null + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + tests: + - not_null + - &evt_index + name: evt_index + description: 'Event index' + tests: + - not_null + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &from + name: from + description: 'Address of BPT provider of transfer event' + - &to + name: to + description: 'Address of BPT receiver of transfer event' + - &value + name: value + description: 'Amount of BPT transferred in transfer event' + + - name: balancer_v2_polygon_bpt_prices + meta: + blockchain: polygon + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['polygon', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - &day + name: day + description: "Block date in UTC" + - *version + - &decimals + name: decimals + description: "Token decimals. 18, by default, on BPTs" + - *contract_address + - &bpt_price + name: bpt_price + description: "Price of the BPT" + + - name: balancer_v2_polygon_bpt_supply + meta: + blockchain: polygon + project: balancer_v2 + contributors: thetroyharris, viniabussafi + config: + tags: ['polygon', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - *version + - *blockchain + - &token_address + name: token_address + description: "Contract address of the BPT" + - &supply + name: supply + description: "Supply of the BPT, discounted of premints" + + - name: balancer_v2_polygon_bpt_supply_changes + meta: + blockchain: polygon + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['polygon', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - *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: balancer_v2_polygon_bpt_supply_changes_daily + meta: + blockchain: polygon + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['polygon', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - &daily_delta + name: daily_delta + description: "Daily total impact on BPT supply" \ 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 new file mode 100644 index 0000000..a445a3b --- /dev/null +++ b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'polygon' %} + +{{ + config( + alias = 'balancer_v2_polygon_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v2_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_polygon' + ) +}} 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 new file mode 100644 index 0000000..e25d5c3 --- /dev/null +++ b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_bpt_supply.sql @@ -0,0 +1,18 @@ +{% set blockchain = 'polygon' %} + +{{ + config( + alias = 'balancer_v2_polygon_bpt_supply', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + pool_labels_model = 'balancer_v2_pools_polygon', + transfers_spell = ref('balancer_v2_polygon_transfers_bpt') + ) +}} \ 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 new file mode 100644 index 0000000..c4a9448 --- /dev/null +++ b/models/_project/balancer/bpt/polygon/balancer_v2_polygon_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'polygon' %} + +{{ + config( + alias = 'balancer_v2_polygon_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/bpt/zkevm/_schema.yml b/models/_project/balancer/bpt/zkevm/_schema.yml new file mode 100644 index 0000000..1ea89c9 --- /dev/null +++ b/models/_project/balancer/bpt/zkevm/_schema.yml @@ -0,0 +1,184 @@ +version: 2 + +models: + - name: balancer_v2_zkevm_transfers_bpt + meta: + blockchain: zkevm + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['zkevm', 'bpt', 'transfers'] + description: > + Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on zkevm. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - evt_tx_hash + - evt_index + - block_date + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &contract_address + name: contract_address + description: 'zkevm address for the liquidity pool used in transaction' + - &block_date + name: block_date + description: "UTC event block date of each DEX trade" + tests: + - not_null + - &block_month + name: block_month + description: "UTC event block month of each DEX trade" + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash of transfer event' + tests: + - not_null + - &evt_index + name: evt_index + description: 'Event index' + tests: + - not_null + - &evt_block_time + name: evt_block_time + description: 'Block time of transfer event' + - &evt_block_number + name: evt_block_number + description: 'Block number of transfer event' + - &from + name: from + description: 'Address of BPT provider of transfer event' + - &to + name: to + description: 'Address of BPT receiver of transfer event' + - &value + name: value + description: 'Amount of BPT transferred in transfer event' + + - name: balancer_v2_zkevm_bpt_prices + meta: + blockchain: zkevm + project: balancer_v2 + contributors: victorstefenon, thetroyharris, viniabussafi + config: + tags: ['zkevm', 'bpt', 'prices'] + description: > + Balancer Pool Token (BPT) daily price by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - day + - contract_address + columns: + - *blockchain + - &day + name: day + description: "Block date in UTC" + - *version + - &decimals + name: decimals + description: "Token decimals. 18, by default, on BPTs" + - *contract_address + - &bpt_price + name: bpt_price + description: "Price of the BPT" + + - name: balancer_v2_zkevm_bpt_supply + meta: + blockchain: zkevm + project: balancer_v2 + contributors: thetroyharris, viniabussafi + config: + tags: ['zkevm', 'bpt', 'supply'] + description: > + Balancer Pool Token (BPT) supply by pool on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - blockchain + - token_address + columns: + - *day + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - *version + - *blockchain + - &token_address + name: token_address + description: "Contract address of the BPT" + - &supply + name: supply + description: "Supply of the BPT, discounted of premints" + + - name: balancer_v2_zkevm_bpt_supply_changes + meta: + blockchain: zkevm + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['zkevm', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - evt_tx_hash + - evt_index + - label + columns: + - *block_date + - *evt_block_time + - *evt_block_number + - *blockchain + - *evt_tx_hash + - *evt_index + - *pool_type + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - *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: balancer_v2_zkevm_bpt_supply_changes_daily + meta: + blockchain: zkevm + project: balancer_v2 + contributors: viniabussafi + config: + tags: ['zkevm', 'bpt', 'supply', 'changes'] + description: > + Balancer Pool Token (BPT) supply change events. grouped by day + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - token_address + columns: + - *block_date + - *blockchain + - *pool_type + - *pool_symbol + - *version + - *token_address + - &daily_delta + name: daily_delta + description: "Daily total impact on BPT supply" \ 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 new file mode 100644 index 0000000..9984a8f --- /dev/null +++ b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_prices.sql @@ -0,0 +1,19 @@ +{% set blockchain = 'zkevm' %} + +{{ + config( + alias = 'balancer_v2_zkevm_bpt_prices', + materialized = 'table', + ) +}} + + +{{ + balancer_v2_compatible_bpt_prices_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_zkevm' + ) +}} 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 new file mode 100644 index 0000000..735a5ea --- /dev/null +++ b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_bpt_supply.sql @@ -0,0 +1,18 @@ +{% set blockchain = 'zkevm' %} + +{{ + config( + alias = 'balancer_v2_zkevm_bpt_supply', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_bpt_supply_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + pool_labels_model = 'balancer_v2_pools_zkevm', + transfers_spell = ref('balancer_v2_zkevm_transfers_bpt') + ) +}} \ 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 new file mode 100644 index 0000000..34c5317 --- /dev/null +++ b/models/_project/balancer/bpt/zkevm/balancer_v2_zkevm_transfers_bpt.sql @@ -0,0 +1,20 @@ +{% set blockchain = 'zkevm' %} + +{{ + config( + alias = 'balancer_v2_zkevm_transfers_bpt', + partition_by = ['block_month'], + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['block_date', 'evt_tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] + ) +}} + +{{ + balancer_v2_compatible_transfers_bpt_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/liquidity/_schema.yml b/models/_project/balancer/liquidity/_schema.yml new file mode 100644 index 0000000..30dcf72 --- /dev/null +++ b/models/_project/balancer/liquidity/_schema.yml @@ -0,0 +1,60 @@ +version: 2 + +models: + - name: balancer_liquidity + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + project: balancer + contributors: viniabussafi + config: + tags: ['balancer', 'amm', 'dex', 'liquidity', 'ethereum', 'arbitrum', 'optimism', 'polygon', 'avalanche_c', 'base', 'zkevm'] + description: > + Liquidity by token on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - blockchain + - token_address + - token_symbol + columns: + - &day + name: day + description: "Block date in UTC" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &version + name: version + description: "Version of the project" + - &blockchain + name: blockchain + description: "Blockchain" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - name: token_balance_raw + description: 'Raw balance of the token in the pool in the original currency' + - name: token_balance + description: 'Scaled balance of the token in the pool in the original currency' + - name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' \ No newline at end of file diff --git a/models/_project/balancer/liquidity/arbitrum/_schema.yml b/models/_project/balancer/liquidity/arbitrum/_schema.yml new file mode 100644 index 0000000..0653af7 --- /dev/null +++ b/models/_project/balancer/liquidity/arbitrum/_schema.yml @@ -0,0 +1,96 @@ +version: 2 + +models: + - name: balancer_v2_arbitrum_liquidity + meta: + blockchain: arbitrum + project: balancer_v2 + contributors: victorstefenon, viniabussafi, thetroyharris + config: + tags: ['arbitrum', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v2 pools liquidity by token in Arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - &day + name: day + description: "Block date in UTC" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &version + name: version + description: "Version of the project" + - &blockchain + name: blockchain + description: "Blockchain" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &token_balance_raw + name: token_balance_raw + description: 'Raw balance of the token in the pool in the original currency' + - &token_balance + name: token_balance + description: 'Scaled balance of the token in the pool in the original currency' + - &protocol_liquidity_usd + name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - &protocol_liquidity_eth + name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - &pool_liquidity_usd + name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - &pool_liquidity_eth + name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' + + - name: balancer_v3_arbitrum_liquidity + meta: + blockchain: arbitrum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v3 pools liquidity by token in arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - *day + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *token_symbol + - *token_balance_raw + - *token_balance + - *protocol_liquidity_usd + - *protocol_liquidity_eth + - *pool_liquidity_usd + - *pool_liquidity_eth \ 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 new file mode 100644 index 0000000..c70318d --- /dev/null +++ b/models/_project/balancer/liquidity/arbitrum/balancer_v2_arbitrum_liquidity.sql @@ -0,0 +1,19 @@ + +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_v2_arbitrum_liquidity', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_liquidity_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_arbitrum' + ) +}} diff --git a/models/_project/balancer/liquidity/arbitrum/balancer_v3_arbitrum_liquidity.sql b/models/_project/balancer/liquidity/arbitrum/balancer_v3_arbitrum_liquidity.sql new file mode 100644 index 0000000..23bb686 --- /dev/null +++ b/models/_project/balancer/liquidity/arbitrum/balancer_v3_arbitrum_liquidity.sql @@ -0,0 +1,20 @@ + +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_v3_arbitrum_liquidity', + materialized = 'table', + ) +}} + + +{{ + balancer_v3_compatible_liquidity_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_arbitrum' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/liquidity/avalanche_c/_schema.yml b/models/_project/balancer/liquidity/avalanche_c/_schema.yml new file mode 100644 index 0000000..d0c6674 --- /dev/null +++ b/models/_project/balancer/liquidity/avalanche_c/_schema.yml @@ -0,0 +1,58 @@ +version: 2 + +models: + - name: balancer_v2_avalanche_c_liquidity + meta: + blockchain: avalanche_c + project: balancer_v2 + contributors: victorstefenon, viniabussafi, thetroyharris + config: + tags: ['avalanche_c', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v2 pools liquidity by token in Arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - &day + name: day + description: "Block date in UTC" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &version + name: version + description: "Version of the project" + - &blockchain + name: blockchain + description: "Blockchain" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - name: token_balance_raw + description: 'Raw balance of the token in the pool in the original currency' + - name: token_balance + description: 'Scaled balance of the token in the pool in the original currency' + - name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' \ No newline at end of file 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 new file mode 100644 index 0000000..bca9a2d --- /dev/null +++ b/models/_project/balancer/liquidity/avalanche_c/balancer_v2_avalanche_c_liquidity.sql @@ -0,0 +1,19 @@ + +{% set blockchain = 'avalanche_c' %} + +{{ + config( + alias = 'balancer_v2_avalanche_c_liquidity', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_liquidity_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_avalanche_c' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/liquidity/balancer_liquidity.sql b/models/_project/balancer/liquidity/balancer_liquidity.sql new file mode 100644 index 0000000..3cc736a --- /dev/null +++ b/models/_project/balancer/liquidity/balancer_liquidity.sql @@ -0,0 +1,50 @@ +{{ config( + alias = 'balancer_liquidity' + , post_hook='{{ hide_spells() }}' + ) +}} + +{% set balancer_models = [ +ref('balancer_v1_ethereum_liquidity') +, ref('balancer_v2_ethereum_liquidity') +, ref('balancer_v2_optimism_liquidity') +, ref('balancer_v2_arbitrum_liquidity') +, ref('balancer_v2_polygon_liquidity') +, ref('balancer_v2_gnosis_liquidity') +, ref('balancer_v2_avalanche_c_liquidity') +, ref('balancer_v2_base_liquidity') +, ref('balancer_v2_zkevm_liquidity') +, ref('balancer_cowswap_amm_liquidity') +, ref('balancer_v3_ethereum_liquidity') +, ref('balancer_v3_gnosis_liquidity') +, ref('balancer_v3_arbitrum_liquidity') +, ref('balancer_v3_base_liquidity') +] %} + + +SELECT * +FROM ( + {% for liquidity_model in balancer_models %} + SELECT + day, + pool_id, + pool_address, + pool_symbol, + version, + blockchain, + pool_type, + token_address, + token_symbol, + token_balance_raw, + token_balance, + protocol_liquidity_usd, + protocol_liquidity_eth, + pool_liquidity_usd, + pool_liquidity_eth + FROM {{ liquidity_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) +; \ No newline at end of file diff --git a/models/_project/balancer/liquidity/base/_schema.yml b/models/_project/balancer/liquidity/base/_schema.yml new file mode 100644 index 0000000..3f5b93d --- /dev/null +++ b/models/_project/balancer/liquidity/base/_schema.yml @@ -0,0 +1,96 @@ +version: 2 + +models: + - name: balancer_v2_base_liquidity + meta: + blockchain: base + project: balancer_v2 + contributors: victorstefenon, viniabussafi, thetroyharris + config: + tags: ['base', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v2 pools liquidity by token in Arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - &day + name: day + description: "Block date in UTC" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &version + name: version + description: "Version of the project" + - &blockchain + name: blockchain + description: "Blockchain" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &token_balance_raw + name: token_balance_raw + description: 'Raw balance of the token in the pool in the original currency' + - &token_balance + name: token_balance + description: 'Scaled balance of the token in the pool in the original currency' + - &protocol_liquidity_usd + name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - &protocol_liquidity_eth + name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - &pool_liquidity_usd + name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - &pool_liquidity_eth + name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' + + - name: balancer_v3_base_liquidity + meta: + blockchain: base + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['base', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v3 pools liquidity by token in base. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - *day + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *token_symbol + - *token_balance_raw + - *token_balance + - *protocol_liquidity_usd + - *protocol_liquidity_eth + - *pool_liquidity_usd + - *pool_liquidity_eth \ No newline at end of file diff --git a/models/_project/balancer/liquidity/base/balancer_v2_base_liquidity.sql b/models/_project/balancer/liquidity/base/balancer_v2_base_liquidity.sql new file mode 100644 index 0000000..9a9d7a7 --- /dev/null +++ b/models/_project/balancer/liquidity/base/balancer_v2_base_liquidity.sql @@ -0,0 +1,19 @@ + +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v2_base_liquidity', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_liquidity_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_base' + ) +}} diff --git a/models/_project/balancer/liquidity/base/balancer_v3_base_liquidity.sql b/models/_project/balancer/liquidity/base/balancer_v3_base_liquidity.sql new file mode 100644 index 0000000..5d00cae --- /dev/null +++ b/models/_project/balancer/liquidity/base/balancer_v3_base_liquidity.sql @@ -0,0 +1,20 @@ + +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_v3_base_liquidity', + materialized = 'table', + ) +}} + + +{{ + balancer_v3_compatible_liquidity_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_base' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/liquidity/ethereum/_schema.yml b/models/_project/balancer/liquidity/ethereum/_schema.yml new file mode 100644 index 0000000..0279d42 --- /dev/null +++ b/models/_project/balancer/liquidity/ethereum/_schema.yml @@ -0,0 +1,128 @@ +version: 2 + +models: + - name: balancer_v2_ethereum_liquidity + meta: + blockchain: ethereum + project: balancer_v2 + contributors: victorstefenon, viniabussafi, thetroyharris + config: + tags: ['ethereum', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v2 pools liquidity by token in Ethereum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - &day + name: day + description: "Block date in UTC" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &version + name: version + description: "Version of the project" + - &blockchain + name: blockchain + description: "Blockchain" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &token_balance_raw + name: token_balance_raw + description: 'Raw balance of the token in the pool in the original currency' + - &token_balance + name: token_balance + description: 'Scaled balance of the token in the pool in the original currency' + - &protocol_liquidity_usd + name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - &protocol_liquidity_eth + name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - &pool_liquidity_usd + name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - &pool_liquidity_eth + name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' + + - name: balancer_v1_ethereum_liquidity + meta: + blockchain: ethereum + project: balancer_v1 + contributors: markusbkoch, mendesfabio, victorstefenon, viniabussafi, thetroyharris + config: + tags: ['ethereum', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v1 pools liquidity by token in Ethereum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - *day + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *token_symbol + - *token_balance_raw + - *token_balance + - *protocol_liquidity_usd + - *protocol_liquidity_eth + - *pool_liquidity_usd + - *pool_liquidity_eth + + - name: balancer_v3_ethereum_liquidity + meta: + blockchain: ethereum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['ethereum', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v3 pools liquidity by token in Ethereum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - *day + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *token_symbol + - *token_balance_raw + - *token_balance + - *protocol_liquidity_usd + - *protocol_liquidity_eth + - *pool_liquidity_usd + - *pool_liquidity_eth \ No newline at end of file diff --git a/models/_project/balancer/liquidity/ethereum/balancer_v1_ethereum_liquidity.sql b/models/_project/balancer/liquidity/ethereum/balancer_v1_ethereum_liquidity.sql new file mode 100644 index 0000000..3d3fcac --- /dev/null +++ b/models/_project/balancer/liquidity/ethereum/balancer_v1_ethereum_liquidity.sql @@ -0,0 +1,97 @@ +{{ + config( + alias = 'balancer_v1_ethereum_liquidity', + materialized = 'table', + ) +}} + +WITH pool_labels AS ( + SELECT + address, + name + FROM {{ source('labels', 'balancer_v1_pools_ethereum') }} + ), + + prices AS ( + SELECT + date_trunc('day', minute) AS day, + contract_address AS token, + decimals, + AVG(price) AS price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = 'ethereum' + GROUP BY 1, 2, 3 + ), + + eth_prices AS( + SELECT + date_trunc('day', minute) AS day, + APPROX_PERCENTILE(price, 0.5) AS eth_price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = 'ethereum' + AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + GROUP BY 1 + ), + + cumulative_balance AS ( + SELECT + day, + pool, + token, + cumulative_amount + FROM {{ ref('balancer_ethereum_balances') }} b + ), + + cumulative_usd_balance AS ( + SELECT + b.day, + b.pool, + b.token, + t.symbol, + cumulative_amount as token_balance_raw, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals)) AS token_balance, + cumulative_amount / POWER(10, COALESCE(t.decimals, p1.decimals)) * COALESCE(p1.price, 0) AS protocol_liquidity_usd + FROM cumulative_balance b + LEFT JOIN {{ source('tokens_ethereum', 'erc20') }} t ON t.contract_address = b.token + LEFT JOIN prices p1 ON p1.day = b.day + AND p1.token = b.token + ), + + pool_liquidity_estimates AS ( + SELECT + b.day, + b.pool, + SUM(b.protocol_liquidity_usd) / SUM(w.normalized_weight) AS liquidity + FROM cumulative_usd_balance b + INNER JOIN {{ ref('balancer_v1_ethereum_pools_tokens_weights') }} w ON b.pool = w.pool_id + AND b.token = w.token_address + AND CAST (b.protocol_liquidity_usd as DOUBLE) > CAST (0 as DOUBLE) + AND CAST (w.normalized_weight as DOUBLE) > CAST (0 as DOUBLE) + GROUP BY 1, 2 + ) + + SELECT + b.day, + w.pool_id, + w.pool_id AS pool_address, + p.name AS pool_symbol, + '1' AS version, + 'ethereum' AS blockchain, + 'V1' AS pool_type, + w.token_address, + t.symbol AS token_symbol, + token_balance_raw, + token_balance, + liquidity * normalized_weight AS protocol_liquidity_usd, + (liquidity * normalized_weight) / e.eth_price AS protocol_liquidity_eth, + liquidity * normalized_weight AS pool_liquidity_usd, + (liquidity * normalized_weight) / e.eth_price AS pool_liquidity_eth + FROM pool_liquidity_estimates b + LEFT JOIN cumulative_usd_balance c ON c.day = b.day + AND c.pool = b.pool + INNER JOIN {{ ref('balancer_v1_ethereum_pools_tokens_weights') }} w ON b.pool = w.pool_id + AND w.token_address = c.token + AND CAST (w.normalized_weight as DOUBLE) > CAST (0 as DOUBLE) + LEFT JOIN {{ source('tokens_ethereum', 'erc20') }} t ON t.contract_address = w.token_address + LEFT JOIN pool_labels p ON p.address = w.pool_id + LEFT JOIN eth_prices e ON e.day = b.day diff --git a/models/_project/balancer/liquidity/ethereum/balancer_v2_ethereum_liquidity.sql b/models/_project/balancer/liquidity/ethereum/balancer_v2_ethereum_liquidity.sql new file mode 100644 index 0000000..050f95d --- /dev/null +++ b/models/_project/balancer/liquidity/ethereum/balancer_v2_ethereum_liquidity.sql @@ -0,0 +1,20 @@ + +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v2_ethereum_liquidity', + materialized = 'table', + ) +}} + + +{{ + balancer_v2_compatible_liquidity_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_ethereum' + ) +}} \ No newline at end of file diff --git a/models/_project/balancer/liquidity/ethereum/balancer_v3_ethereum_liquidity.sql b/models/_project/balancer/liquidity/ethereum/balancer_v3_ethereum_liquidity.sql new file mode 100644 index 0000000..27f0179 --- /dev/null +++ b/models/_project/balancer/liquidity/ethereum/balancer_v3_ethereum_liquidity.sql @@ -0,0 +1,20 @@ + +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_v3_ethereum_liquidity', + materialized = 'table', + ) +}} + + +{{ + balancer_v3_compatible_liquidity_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_ethereum' + ) +}} diff --git a/models/_project/balancer/liquidity/gnosis/_schema.yml b/models/_project/balancer/liquidity/gnosis/_schema.yml new file mode 100644 index 0000000..2441ab2 --- /dev/null +++ b/models/_project/balancer/liquidity/gnosis/_schema.yml @@ -0,0 +1,96 @@ +version: 2 + +models: + - name: balancer_v2_gnosis_liquidity + meta: + blockchain: gnosis + project: balancer_v2 + contributors: victorstefenon, viniabussafi, thetroyharris + config: + tags: ['gnosis', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v2 pools liquidity by token in Gnosis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - &day + name: day + description: "Block date in UTC" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &version + name: version + description: "Version of the project" + - &blockchain + name: blockchain + description: "Blockchain" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - &token_balance_raw + name: token_balance_raw + description: 'Raw balance of the token in the pool in the original currency' + - &token_balance + name: token_balance + description: 'Scaled balance of the token in the pool in the original currency' + - &protocol_liquidity_usd + name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - &protocol_liquidity_eth + name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - &pool_liquidity_usd + name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - &pool_liquidity_eth + name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' + + - name: balancer_v3_gnosis_liquidity + meta: + blockchain: gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['gnosis', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v3 pools liquidity by token in Gnosis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - *day + - *pool_id + - *pool_address + - *pool_symbol + - *version + - *blockchain + - *pool_type + - *token_address + - *token_symbol + - *token_balance_raw + - *token_balance + - *protocol_liquidity_usd + - *protocol_liquidity_eth + - *pool_liquidity_usd + - *pool_liquidity_eth \ 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 new file mode 100644 index 0000000..b302dc1 --- /dev/null +++ b/models/_project/balancer/liquidity/gnosis/balancer_v2_gnosis_liquidity.sql @@ -0,0 +1,19 @@ + +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v2_gnosis_liquidity', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_liquidity_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_gnosis' + ) +}} diff --git a/models/_project/balancer/liquidity/gnosis/balancer_v3_gnosis_liquidity.sql b/models/_project/balancer/liquidity/gnosis/balancer_v3_gnosis_liquidity.sql new file mode 100644 index 0000000..26f3925 --- /dev/null +++ b/models/_project/balancer/liquidity/gnosis/balancer_v3_gnosis_liquidity.sql @@ -0,0 +1,19 @@ + +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_v3_gnosis_liquidity', + materialized = 'table', + ) +}} + +{{ + balancer_v3_compatible_liquidity_macro( + blockchain = blockchain, + version = '3', + project_decoded_as = 'balancer_v3', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v3_pools_gnosis' + ) +}} diff --git a/models/_project/balancer/liquidity/optimism/_schema.yml b/models/_project/balancer/liquidity/optimism/_schema.yml new file mode 100644 index 0000000..05b582f --- /dev/null +++ b/models/_project/balancer/liquidity/optimism/_schema.yml @@ -0,0 +1,58 @@ +version: 2 + +models: + - name: balancer_v2_optimism_liquidity + meta: + blockchain: optimism + project: balancer_v2 + contributors: victorstefenon, viniabussafi, thetroyharris + config: + tags: ['optimism', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v2 pools liquidity by token in Arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - &day + name: day + description: "Block date in UTC" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &version + name: version + description: "Version of the project" + - &blockchain + name: blockchain + description: "Blockchain" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - name: token_balance_raw + description: 'Raw balance of the token in the pool in the original currency' + - name: token_balance + description: 'Scaled balance of the token in the pool in the original currency' + - name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' \ No newline at end of file diff --git a/models/_project/balancer/liquidity/optimism/balancer_v2_optimism_liquidity.sql b/models/_project/balancer/liquidity/optimism/balancer_v2_optimism_liquidity.sql new file mode 100644 index 0000000..57dfcc0 --- /dev/null +++ b/models/_project/balancer/liquidity/optimism/balancer_v2_optimism_liquidity.sql @@ -0,0 +1,19 @@ + +{% set blockchain = 'optimism' %} + +{{ + config( + alias = 'balancer_v2_optimism_liquidity', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_liquidity_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_optimism' + ) +}} diff --git a/models/_project/balancer/liquidity/polygon/_schema.yml b/models/_project/balancer/liquidity/polygon/_schema.yml new file mode 100644 index 0000000..dd896b9 --- /dev/null +++ b/models/_project/balancer/liquidity/polygon/_schema.yml @@ -0,0 +1,58 @@ +version: 2 + +models: + - name: balancer_v2_polygon_liquidity + meta: + blockchain: polygon + project: balancer_v2 + contributors: victorstefenon, viniabussafi, thetroyharris + config: + tags: ['polygon', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v2 pools liquidity by token in Arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - &day + name: day + description: "Block date in UTC" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &version + name: version + description: "Version of the project" + - &blockchain + name: blockchain + description: "Blockchain" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - name: token_balance_raw + description: 'Raw balance of the token in the pool in the original currency' + - name: token_balance + description: 'Scaled balance of the token in the pool in the original currency' + - name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' \ No newline at end of file diff --git a/models/_project/balancer/liquidity/polygon/balancer_v2_polygon_liquidity.sql b/models/_project/balancer/liquidity/polygon/balancer_v2_polygon_liquidity.sql new file mode 100644 index 0000000..d57ef8b --- /dev/null +++ b/models/_project/balancer/liquidity/polygon/balancer_v2_polygon_liquidity.sql @@ -0,0 +1,19 @@ + +{% set blockchain = 'polygon' %} + +{{ + config( + alias = 'balancer_v2_polygon_liquidity', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_liquidity_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_polygon' + ) +}} diff --git a/models/_project/balancer/liquidity/zkevm/_schema.yml b/models/_project/balancer/liquidity/zkevm/_schema.yml new file mode 100644 index 0000000..2dc4742 --- /dev/null +++ b/models/_project/balancer/liquidity/zkevm/_schema.yml @@ -0,0 +1,58 @@ +version: 2 + +models: + - name: balancer_v2_zkevm_liquidity + meta: + blockchain: zkevm + project: balancer_v2 + contributors: victorstefenon, viniabussafi, thetroyharris + config: + tags: ['zkevm', 'balancer', 'pools', 'liquidity'] + description: > + Balancer v2 pools liquidity by token in Arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - &day + name: day + description: "Block date in UTC" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &pool_address + name: pool_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &version + name: version + description: "Version of the project" + - &blockchain + name: blockchain + description: "Blockchain" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &token_address + name: token_address + description: "Contract address of the token" + - &token_symbol + name: token_symbol + description: "Token symbol" + - name: token_balance_raw + description: 'Raw balance of the token in the pool in the original currency' + - name: token_balance + description: 'Scaled balance of the token in the pool in the original currency' + - name: protocol_liquidity_usd + description: 'Liquidity of the token in the pool in USD, except BPTs' + - name: protocol_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, except BPTs' + - name: pool_liquidity_usd + description: 'Liquidity of the token in the pool in USD, including BPTs' + - name: pool_liquidity_eth + description: 'Liquidity of the token in the pool in ETH, including BPTs' \ No newline at end of file diff --git a/models/_project/balancer/liquidity/zkevm/balancer_v2_zkevm_liquidity.sql b/models/_project/balancer/liquidity/zkevm/balancer_v2_zkevm_liquidity.sql new file mode 100644 index 0000000..850dec3 --- /dev/null +++ b/models/_project/balancer/liquidity/zkevm/balancer_v2_zkevm_liquidity.sql @@ -0,0 +1,19 @@ + +{% set blockchain = 'zkevm' %} + +{{ + config( + alias = 'balancer_v2_zkevm_liquidity', + materialized = 'table', + ) +}} + +{{ + balancer_v2_compatible_liquidity_macro( + blockchain = blockchain, + version = '2', + project_decoded_as = 'balancer_v2', + base_spells_namespace = 'balancer', + pool_labels_model = 'balancer_v2_pools_zkevm' + ) +}} diff --git a/models/_project/balancer/pools/_schema.yml b/models/_project/balancer/pools/_schema.yml new file mode 100644 index 0000000..2094f08 --- /dev/null +++ b/models/_project/balancer/pools/_schema.yml @@ -0,0 +1,194 @@ +version: 2 + +models: + - name: balancer_pools_tokens_weights + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, 'zkevm' + contributors: jacektrocinski, viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'bpt', 'transfers'] + description: > + Token weights in Balancer pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - pool_id + - token_address + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + + - name: balancer_pools_metrics_daily + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + contributors: viniabussafi, metacrypto + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'balancer', 'pool', 'stats', 'volume', 'tvl', 'fee'] + description: > + This spell aggregates data from the trades, liquidity and protocol fees spells, by day and pool, while also displaying some basic information about the pool. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - project + - version + - project_contract_address + columns: + - *blockchain + - &project + name: project + description: "Project name (balancer)" + - *version + - &block_date + name: block_date + description: "Block date in UTC" + - &project_contract_address + name: project_contract_address + description: "Pool address" + - &pool_symbol + name: pool_symbol + description: "Token symbols, followed by their respective weights, if applicable" + - &pool_type + name: pool_type + description: "Pool attributes, determined by the pool's factory" + - &swap_amount_usd + name: swap_amount_usd + description: "Daily swap volume on a pool, in USD" + - &tvl_usd + name: tvl_usd + description: "Total Value Locked on a pool, in USD" + - &tvl_eth + name: tvl_eth + description: "Total Value Locked on a pool, in ETH" + - &fee_amount_usd + name: fee_amount_usd + description: "Daily fees collected on a pool, in USD" + + - name: balancer_gauge_mappings + meta: + blockchain: optimism + sector: dex + contributors: msilb7 + config: + tags: ['balancer', 'amm', 'trades', 'dex', 'incentives'] + description: > + Gauge to Pool mappings for balancer on all chains. + columns: + - *blockchain + - *version + - &pool_contract + name: pool_contract + description: "Address of the liquidity pool contract" + - *pool_id + - &incentives_contract + name: incentives_contract + description: "Address of the contract where incentives are stored and emitted." + - &incentives_type + name: incentives_type + description: "Description of the incentives address type." + - &evt_block_time + name: evt_block_time + description: "Block time in UTC" + - &evt_block_number + name: evt_block_number + description: 'Event Block Number' + - &contract_address + name: contract_address + description: 'zkevm address for the liquidity pool used in transaction' + data_tests: + - not_null + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash' + - &evt_index + name: evt_index + description: 'Event Index' + + - name: balancer_view_pools_latest + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + contributors: viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'balancer', 'pool', 'stats', 'volume', 'tvl', 'fee'] + description: > + This spell aggregates data from the trades, liquidity, and protocol fees spells, by pool, while also displaying information about the pool creation. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - pool_id + columns: + - *blockchain + - name: pool_id + - name: pool_address + - name: pool_symbol + - name: pool_type + - name: factory_version + - name: factory_address + - name: creation_date + - name: tvl_usd + - name: tvl_eth + - name: swap_volume + - name: swap_volume_1y + - name: swap_volume_30d + - name: swap_volume_7d + - name: swap_volume_1d + - name: fees_collected + - name: fees_collected_1y + - name: fees_collected_30d + - name: fees_collected_7d + - name: fees_collected_1d + + - name: balancer_v3_lbps + meta: + blockchain: arbitrum, base, ethereum, gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'base', 'ethereum', 'gnosis', 'balancer', 'lbp'] + description: > + Record of the Liquidity Boostrapping Pools (LBP) of Balancer, an automated portfolio manager and trading platform, across supported chains. + columns: + - *blockchain + - name: pool_symbol + description: "Name of the LBP" + - name: pool_address + description: "ID of the LBP" + - name: start_time + description: "LBP start time" + - name: end_time + description: "LBP end time" + - name: project_token + description: "Contract address of the token sold by the LBP" + - name: reserve_token + description: "Contract address of the token bought by the LBP" + - name: project_token_symbol + description: "Symbol of the token sold by the LBP" + - name: reserve_token_symbol + description: "Symbol of the token bought by the LBP" + - name: project_token_start_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_start_weight + description: "Start Weight of the token bought by the LBP" + - name: project_token_end_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_end_weight + description: "End Weight of the token bought by the LBP" diff --git a/models/_project/balancer/pools/arbitrum/_schema.yml b/models/_project/balancer/pools/arbitrum/_schema.yml new file mode 100644 index 0000000..360ef1c --- /dev/null +++ b/models/_project/balancer/pools/arbitrum/_schema.yml @@ -0,0 +1,110 @@ +version: 2 + +models: + - name: balancer_arbitrum_pools_tokens_weights + meta: + blockchain: arbitrum + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['arbitrum', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer pools. + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + tests: + - not_null + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + - name: balancer_v2_arbitrum_pools_tokens_weights + meta: + blockchain: arbitrum + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['arbitrum', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v2 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v3_arbitrum_pools_tokens_weights + meta: + blockchain: arbitrum + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['arbitrum', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v3 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v3_arbitrum_lbps + meta: + blockchain: arbitrum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['arbitrum', 'balancer', 'lbp'] + description: > + Record of the Liquidity Boostrapping Pools (LBP) of Balancer, an automated portfolio manager and trading platform, on arbitrum. + columns: + - *blockchain + - name: pool_symbol + description: "Name of the LBP" + - name: pool_address + description: "ID of the LBP" + - name: start_time + description: "LBP start time" + - name: end_time + description: "LBP end time" + - name: project_token + description: "Contract address of the token sold by the LBP" + - name: reserve_token + description: "Contract address of the token bought by the LBP" + - name: project_token_symbol + description: "Symbol of the token sold by the LBP" + - name: reserve_token_symbol + description: "Symbol of the token bought by the LBP" + - name: project_token_start_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_start_weight + description: "Start Weight of the token bought by the LBP" + - name: project_token_end_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_end_weight + description: "End Weight of the token bought by the LBP" \ No newline at end of file diff --git a/models/_project/balancer/pools/arbitrum/balancer_arbitrum_pools_tokens_weights.sql b/models/_project/balancer/pools/arbitrum/balancer_arbitrum_pools_tokens_weights.sql new file mode 100644 index 0000000..de6a1d8 --- /dev/null +++ b/models/_project/balancer/pools/arbitrum/balancer_arbitrum_pools_tokens_weights.sql @@ -0,0 +1,27 @@ +{{ config( + alias = 'balancer_arbitrum_pools_tokens_weights', + + ) +}} + +{% set balancer_models = [ + ref('balancer_v2_arbitrum_pools_tokens_weights'), + ref('balancer_v3_arbitrum_pools_tokens_weights') +] %} + +SELECT * +FROM ( + {% for model in balancer_models %} + SELECT + blockchain, + version, + pool_id, + token_address, + normalized_weight + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) +; diff --git a/models/_project/balancer/pools/arbitrum/balancer_v2_arbitrum_pools_tokens_weights.sql b/models/_project/balancer/pools/arbitrum/balancer_v2_arbitrum_pools_tokens_weights.sql new file mode 100644 index 0000000..56ee09e --- /dev/null +++ b/models/_project/balancer/pools/arbitrum/balancer_v2_arbitrum_pools_tokens_weights.sql @@ -0,0 +1,107 @@ +{{ + config( + alias = 'balancer_v2_arbitrum_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v2 Pools Tokens Weights +-- +WITH registered AS ( + SELECT + poolID AS pool_id, + evt_block_time + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_arbitrum', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.weights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + + UNION ALL + + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_arbitrum', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_2tokens_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_arbitrum', 'WeightedPool2TokensFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.weights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_v2_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_arbitrum', 'WeightedPoolV2Factory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory + UNION ALL + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_2tokens_factory + UNION ALL + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_v2_factory +) + +SELECT + 'arbitrum' AS blockchain, + '2' AS version, + r.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +LEFT JOIN registered r ON BYTEARRAY_SUBSTRING(r.pool_id,1,20) = w.pool_id +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/arbitrum/balancer_v3_arbitrum_pools_tokens_weights.sql b/models/_project/balancer/pools/arbitrum/balancer_v3_arbitrum_pools_tokens_weights.sql new file mode 100644 index 0000000..72e95ee --- /dev/null +++ b/models/_project/balancer/pools/arbitrum/balancer_v3_arbitrum_pools_tokens_weights.sql @@ -0,0 +1,59 @@ +{{ + config( + alias = 'balancer_v3_arbitrum_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v3 Pools Tokens Weights +-- +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 + ), + +weighted_pool_factory AS ( + SELECT + call_create.output_pool AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v3_arbitrum', 'WeightedPoolFactory_call_create') }} AS call_create + JOIN token_data td ON td.pool = call_create.output_pool + CROSS JOIN UNNEST(td.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), + +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory +) + +SELECT + 'arbitrum' AS blockchain, + '3' AS version, + w.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/avalanche_c/_schema.yml b/models/_project/balancer/pools/avalanche_c/_schema.yml new file mode 100644 index 0000000..8a14389 --- /dev/null +++ b/models/_project/balancer/pools/avalanche_c/_schema.yml @@ -0,0 +1,53 @@ +version: 2 + +models: + - name: balancer_avalanche_c_pools_tokens_weights + meta: + blockchain: avalanche_c + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['avalanche_c', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer pools. + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + tests: + - not_null + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + - name: balancer_v2_avalanche_c_pools_tokens_weights + meta: + blockchain: avalanche_c + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['avalanche_c', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v2 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight \ No newline at end of file diff --git a/models/_project/balancer/pools/avalanche_c/balancer_avalanche_c_pools_tokens_weights.sql b/models/_project/balancer/pools/avalanche_c/balancer_avalanche_c_pools_tokens_weights.sql new file mode 100644 index 0000000..80985e9 --- /dev/null +++ b/models/_project/balancer/pools/avalanche_c/balancer_avalanche_c_pools_tokens_weights.sql @@ -0,0 +1,16 @@ +{{ config( + alias = 'balancer_avalanche_c_pools_tokens_weights', + ) +}} + +SELECT * +FROM +( + SELECT + blockchain, + version, + pool_id, + token_address, + normalized_weight + FROM {{ ref('balancer_v2_avalanche_c_pools_tokens_weights') }} +) \ No newline at end of file diff --git a/models/_project/balancer/pools/avalanche_c/balancer_v2_avalanche_c_pools_tokens_weights.sql b/models/_project/balancer/pools/avalanche_c/balancer_v2_avalanche_c_pools_tokens_weights.sql new file mode 100644 index 0000000..2c0240a --- /dev/null +++ b/models/_project/balancer/pools/avalanche_c/balancer_v2_avalanche_c_pools_tokens_weights.sql @@ -0,0 +1,53 @@ +{{ + config( + alias = 'balancer_v2_avalanche_c_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v2 Pools Tokens Weights +-- +WITH registered AS ( + SELECT + poolID AS pool_id, + evt_block_time + FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_avalanche_c', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), + +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory +) + +SELECT + 'avalanche_c' AS blockchain, + '2' AS version, + r.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +LEFT JOIN registered r ON BYTEARRAY_SUBSTRING(r.pool_id,1,20) = w.pool_id +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/balancer_pools_tokens_weights.sql b/models/_project/balancer/pools/balancer_pools_tokens_weights.sql new file mode 100644 index 0000000..5b0af6c --- /dev/null +++ b/models/_project/balancer/pools/balancer_pools_tokens_weights.sql @@ -0,0 +1,33 @@ +{{ config( + alias = 'balancer_pools_tokens_weights' + , post_hook='{{ hide_spells() }}' + ) +}} + +{% set balancer_models = [ + ref('balancer_arbitrum_pools_tokens_weights'), + ref('balancer_avalanche_c_pools_tokens_weights'), + ref('balancer_base_pools_tokens_weights'), + ref('balancer_ethereum_pools_tokens_weights'), + ref('balancer_gnosis_pools_tokens_weights'), + ref('balancer_optimism_pools_tokens_weights'), + ref('balancer_polygon_pools_tokens_weights'), + ref('balancer_zkevm_pools_tokens_weights') +] %} + + +SELECT * +FROM ( + {% for model in balancer_models %} + SELECT + blockchain, + version, + pool_id, + token_address, + normalized_weight + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) diff --git a/models/_project/balancer/pools/base/_schema.yml b/models/_project/balancer/pools/base/_schema.yml new file mode 100644 index 0000000..ce452f9 --- /dev/null +++ b/models/_project/balancer/pools/base/_schema.yml @@ -0,0 +1,110 @@ +version: 2 + +models: + - name: balancer_base_pools_tokens_weights + meta: + blockchain: base + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['base', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer pools. + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + tests: + - not_null + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + - name: balancer_v2_base_pools_tokens_weights + meta: + blockchain: base + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['base', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v2 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v3_base_pools_tokens_weights + meta: + blockchain: base + project: balancer + contributors: viniabussafi + config: + tags: ['base', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v3 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v3_base_lbps + meta: + blockchain: base + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['base', 'balancer', 'lbp'] + description: > + Record of the Liquidity Boostrapping Pools (LBP) of Balancer, an automated portfolio manager and trading platform, on base. + columns: + - *blockchain + - name: pool_symbol + description: "Name of the LBP" + - name: pool_address + description: "ID of the LBP" + - name: start_time + description: "LBP start time" + - name: end_time + description: "LBP end time" + - name: project_token + description: "Contract address of the token sold by the LBP" + - name: reserve_token + description: "Contract address of the token bought by the LBP" + - name: project_token_symbol + description: "Symbol of the token sold by the LBP" + - name: reserve_token_symbol + description: "Symbol of the token bought by the LBP" + - name: project_token_start_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_start_weight + description: "Start Weight of the token bought by the LBP" + - name: project_token_end_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_end_weight + description: "End Weight of the token bought by the LBP" \ No newline at end of file diff --git a/models/_project/balancer/pools/base/balancer_base_pools_tokens_weights.sql b/models/_project/balancer/pools/base/balancer_base_pools_tokens_weights.sql new file mode 100644 index 0000000..c286d6a --- /dev/null +++ b/models/_project/balancer/pools/base/balancer_base_pools_tokens_weights.sql @@ -0,0 +1,27 @@ +{{ config( + alias = 'balancer_base_pools_tokens_weights', + + ) +}} + +{% set balancer_models = [ + ref('balancer_v2_base_pools_tokens_weights'), + ref('balancer_v3_base_pools_tokens_weights') +] %} + +SELECT * +FROM ( + {% for model in balancer_models %} + SELECT + blockchain, + version, + pool_id, + token_address, + normalized_weight + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) +; diff --git a/models/_project/balancer/pools/base/balancer_v2_base_pools_tokens_weights.sql b/models/_project/balancer/pools/base/balancer_v2_base_pools_tokens_weights.sql new file mode 100644 index 0000000..63f88f8 --- /dev/null +++ b/models/_project/balancer/pools/base/balancer_v2_base_pools_tokens_weights.sql @@ -0,0 +1,53 @@ +{{ + config( + alias = 'balancer_v2_base_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v2 Pools Tokens Weights +-- +WITH registered AS ( + SELECT + poolID AS pool_id, + evt_block_time + FROM {{ source('balancer_v2_base', 'Vault_evt_PoolRegistered') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_base', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), + +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory +) + +SELECT + 'base' AS blockchain, + '2' AS version, + r.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +LEFT JOIN registered r ON BYTEARRAY_SUBSTRING(r.pool_id,1,20) = w.pool_id +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/base/balancer_v3_base_pools_tokens_weights.sql b/models/_project/balancer/pools/base/balancer_v3_base_pools_tokens_weights.sql new file mode 100644 index 0000000..9291fb2 --- /dev/null +++ b/models/_project/balancer/pools/base/balancer_v3_base_pools_tokens_weights.sql @@ -0,0 +1,59 @@ +{{ + config( + alias = 'balancer_v3_base_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v3 Pools Tokens Weights +-- +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_base', 'Vault_evt_PoolRegistered') }} + ) AS pool_data + CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index) + GROUP BY 1 + ), + +weighted_pool_factory AS ( + SELECT + call_create.output_pool AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v3_base', 'WeightedPoolFactory_call_create') }} AS call_create + JOIN token_data td ON td.pool = call_create.output_pool + CROSS JOIN UNNEST(td.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), + +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory +) + +SELECT + 'base' AS blockchain, + '3' AS version, + w.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/ethereum/_schema.yml b/models/_project/balancer/pools/ethereum/_schema.yml new file mode 100644 index 0000000..30d025e --- /dev/null +++ b/models/_project/balancer/pools/ethereum/_schema.yml @@ -0,0 +1,154 @@ +version: 2 + +models: + - name: balancer_ethereum_pools_tokens_weights + meta: + blockchain: ethereum + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['ethereum', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer pools. + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + tests: + - not_null + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + - name: balancer_v1_ethereum_pools_tokens_weights + meta: + blockchain: ethereum + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['ethereum', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v1 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v2_ethereum_pools_tokens_weights + meta: + blockchain: ethereum + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['ethereum', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v2 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v2_ethereum_lbps + meta: + blockchain: ethereum + project: balancer_v2 + contributors: stefenon + config: + tags: ['ethereum', 'balancer', 'lbp'] + description: > + Record of the Liquidity Boostrapping Pools (LBP) of Balancer, an automated portfolio manager and trading platform, on Ethereum. + columns: + - name: name + description: "Name of the LBP" + - name: pool_id + description: "ID of the LBP" + - name: token_sold + description: "Contract address of the token sold by the LBP" + - name: token_symbol + description: "Symbol of the token sold by the LBP" + - name: start_time + description: "LBP start time" + - name: end_time + description: "LBP end time" + + - name: balancer_v3_ethereum_pools_tokens_weights + meta: + blockchain: ethereum + project: balancer + contributors: viniabussafi + config: + tags: ['ethereum', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v3 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v3_ethereum_lbps + meta: + blockchain: ethereum + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['ethereum', 'balancer', 'lbp'] + description: > + Record of the Liquidity Boostrapping Pools (LBP) of Balancer, an automated portfolio manager and trading platform, on Ethereum. + columns: + - *blockchain + - name: pool_symbol + description: "Name of the LBP" + - name: pool_address + description: "ID of the LBP" + - name: start_time + description: "LBP start time" + - name: end_time + description: "LBP end time" + - name: project_token + description: "Contract address of the token sold by the LBP" + - name: reserve_token + description: "Contract address of the token bought by the LBP" + - name: project_token_symbol + description: "Symbol of the token sold by the LBP" + - name: reserve_token_symbol + description: "Symbol of the token bought by the LBP" + - name: project_token_start_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_start_weight + description: "Start Weight of the token bought by the LBP" + - name: project_token_end_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_end_weight + description: "End Weight of the token bought by the LBP" diff --git a/models/_project/balancer/pools/ethereum/balancer_ethereum_pools_tokens_weights.sql b/models/_project/balancer/pools/ethereum/balancer_ethereum_pools_tokens_weights.sql new file mode 100644 index 0000000..0d66c89 --- /dev/null +++ b/models/_project/balancer/pools/ethereum/balancer_ethereum_pools_tokens_weights.sql @@ -0,0 +1,28 @@ +{{ config( + alias = 'balancer_ethereum_pools_tokens_weights', + + ) +}} + +{% set balancer_models = [ + ref('balancer_v1_ethereum_pools_tokens_weights'), + ref('balancer_v2_ethereum_pools_tokens_weights'), + ref('balancer_v3_ethereum_pools_tokens_weights') +] %} + +SELECT * +FROM ( + {% for model in balancer_models %} + SELECT + blockchain, + version, + pool_id, + token_address, + normalized_weight + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) +; diff --git a/models/_project/balancer/pools/ethereum/balancer_v1_ethereum_pools_tokens_weights.sql b/models/_project/balancer/pools/ethereum/balancer_v1_ethereum_pools_tokens_weights.sql new file mode 100644 index 0000000..7808aad --- /dev/null +++ b/models/_project/balancer/pools/ethereum/balancer_v1_ethereum_pools_tokens_weights.sql @@ -0,0 +1,128 @@ +{{ + config( + alias = 'balancer_v1_ethereum_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +{% set bind_start_date = '2020-02-28' %} +{% set rebind_start_date = '2020-04-01' %} +{% set unbind_start_date = '2020-04-05' %} + +WITH events AS ( + -- Binds + SELECT + bind.call_block_number AS block_number, + tx.index, + bind.call_trace_address, + bind.contract_address AS pool, + bind.token, + CAST(bind.denorm as int256) as denorm + FROM {{ source('balancer_v1_ethereum', 'BPool_call_bind') }} bind + INNER JOIN {{ source('ethereum', 'transactions') }} tx ON tx.hash = bind.call_tx_hash + WHERE bind.call_success = TRUE + {% if not is_incremental() %} + AND bind.call_block_time >= TIMESTAMP '{{bind_start_date}}' + AND tx.block_time >= TIMESTAMP '{{bind_start_date}}' + {% endif %} + {% if is_incremental() %} + AND bind.call_block_time >= date_trunc('day', now() - interval '7' day) + AND tx.block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + + UNION ALL + + -- Rebinds + SELECT + rebind.call_block_number AS block_number, + tx.index, + rebind.call_trace_address, + rebind.contract_address AS pool, + rebind.token, + CAST(rebind.denorm as int256) as denorm + FROM {{ source('balancer_v1_ethereum', 'BPool_call_rebind') }} rebind + INNER JOIN {{ source('ethereum', 'transactions') }} tx ON tx.hash = rebind.call_tx_hash + WHERE rebind.call_success = TRUE + {% if not is_incremental() %} + AND rebind.call_block_time >= TIMESTAMP '{{bind_start_date}}' + AND tx.block_time >= TIMESTAMP '{{bind_start_date}}' + {% endif %} + {% if is_incremental() %} + AND rebind.call_block_time >= date_trunc('day', now() - interval '7' day) + AND tx.block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + + UNION ALL + + -- Unbinds + SELECT + unbind.call_block_number AS block_number, + tx.index, + unbind.call_trace_address, + unbind.contract_address AS pool, + unbind.token, + CAST('0' as int256) AS denorm + FROM {{ source('balancer_v1_ethereum', 'BPool_call_unbind') }} unbind + INNER JOIN {{ source('ethereum', 'transactions') }} tx ON tx.hash = unbind.call_tx_hash + WHERE unbind.call_success = TRUE + {% if not is_incremental() %} + AND unbind.call_block_time >= TIMESTAMP '{{bind_start_date}}' + AND tx.block_time >= TIMESTAMP '{{bind_start_date}}' + {% endif %} + {% if is_incremental() %} + AND unbind.call_block_time >= date_trunc('day', now() - interval '7' day) + AND tx.block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +state_with_gaps AS ( + SELECT + events.block_number, + events.pool, + events.token, + events.denorm, + LEAD(events.block_number, 1) OVER ( + PARTITION BY events.pool, events.token + ORDER BY events.block_number, index, call_trace_address + ) AS next_block_number + FROM events +), +settings AS ( + SELECT + pool, + token, + denorm + FROM state_with_gaps + WHERE + next_block_number IS NULL + AND denorm <> CAST('0' as int256) +), +sum_denorm AS ( + SELECT + pool, + SUM(denorm) AS sum_denorm + FROM state_with_gaps + WHERE + next_block_number IS NULL + AND denorm <> CAST('0' as int256) + GROUP BY pool +), +norm_weights AS ( + SELECT + settings.pool AS pool_address, + token AS token_address, + CAST(denorm as DOUBLE) / CAST(sum_denorm AS DOUBLE) AS normalized_weight + FROM settings + INNER JOIN sum_denorm ON settings.pool = sum_denorm.pool +) +-- +-- Balancer v1 Pools Tokens Weights +-- +SELECT + 'ethereum' AS blockchain, + '1' AS version, + pool_address AS pool_id, + token_address, + normalized_weight +FROM norm_weights \ No newline at end of file diff --git a/models/_project/balancer/pools/ethereum/balancer_v2_ethereum_pools_tokens_weights.sql b/models/_project/balancer/pools/ethereum/balancer_v2_ethereum_pools_tokens_weights.sql new file mode 100644 index 0000000..c0ecb86 --- /dev/null +++ b/models/_project/balancer/pools/ethereum/balancer_v2_ethereum_pools_tokens_weights.sql @@ -0,0 +1,107 @@ +{{ + config( + alias = 'balancer_v2_ethereum_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v2 Pools Tokens Weights +-- +WITH registered AS ( + SELECT + poolID AS pool_id, + evt_block_time + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_ethereum', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.weights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + + UNION ALL + + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_ethereum', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_2tokens_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_ethereum', 'WeightedPool2TokensFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.weights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_v2_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_ethereum', 'WeightedPoolV2Factory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory + UNION ALL + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_2tokens_factory + UNION ALL + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_v2_factory +) + +SELECT + 'ethereum' AS blockchain, + '2' AS version, + r.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +LEFT JOIN registered r ON BYTEARRAY_SUBSTRING(r.pool_id,1,20) = w.pool_id +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/ethereum/balancer_v3_ethereum_pools_tokens_weights.sql b/models/_project/balancer/pools/ethereum/balancer_v3_ethereum_pools_tokens_weights.sql new file mode 100644 index 0000000..b32b3e5 --- /dev/null +++ b/models/_project/balancer/pools/ethereum/balancer_v3_ethereum_pools_tokens_weights.sql @@ -0,0 +1,59 @@ +{{ + config( + alias = 'balancer_v3_ethereum_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v3 Pools Tokens Weights +-- +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 + ), + +weighted_pool_factory AS ( + SELECT + call_create.output_pool AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v3_ethereum', 'WeightedPoolFactory_call_create') }} AS call_create + JOIN token_data td ON td.pool = call_create.output_pool + CROSS JOIN UNNEST(td.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), + +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory +) + +SELECT + 'ethereum' AS blockchain, + '3' AS version, + w.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/gnosis/_schema.yml b/models/_project/balancer/pools/gnosis/_schema.yml new file mode 100644 index 0000000..7e7b172 --- /dev/null +++ b/models/_project/balancer/pools/gnosis/_schema.yml @@ -0,0 +1,110 @@ +version: 2 + +models: + - name: balancer_gnosis_pools_tokens_weights + meta: + blockchain: gnosis + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['gnosis', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer pools. + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + tests: + - not_null + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + - name: balancer_v2_gnosis_pools_tokens_weights + meta: + blockchain: gnosis + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['gnosis', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v2 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v3_gnosis_pools_tokens_weights + meta: + blockchain: gnosis + project: balancer + contributors: viniabussafi + config: + tags: ['gnosis', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v3 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v3_gnosis_lbps + meta: + blockchain: gnosis + project: balancer_v3 + contributors: viniabussafi + config: + tags: ['gnosis', 'balancer', 'lbp'] + description: > + Record of the Liquidity Boostrapping Pools (LBP) of Balancer, an automated portfolio manager and trading platform, on gnosis. + columns: + - *blockchain + - name: pool_symbol + description: "Name of the LBP" + - name: pool_address + description: "ID of the LBP" + - name: start_time + description: "LBP start time" + - name: end_time + description: "LBP end time" + - name: project_token + description: "Contract address of the token sold by the LBP" + - name: reserve_token + description: "Contract address of the token bought by the LBP" + - name: project_token_symbol + description: "Symbol of the token sold by the LBP" + - name: reserve_token_symbol + description: "Symbol of the token bought by the LBP" + - name: project_token_start_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_start_weight + description: "Start Weight of the token bought by the LBP" + - name: project_token_end_weight + description: "Start Weight of the token sold by the LBP" + - name: reserve_token_end_weight + description: "End Weight of the token bought by the LBP" \ No newline at end of file diff --git a/models/_project/balancer/pools/gnosis/balancer_gnosis_pools_tokens_weights.sql b/models/_project/balancer/pools/gnosis/balancer_gnosis_pools_tokens_weights.sql new file mode 100644 index 0000000..d5ab07e --- /dev/null +++ b/models/_project/balancer/pools/gnosis/balancer_gnosis_pools_tokens_weights.sql @@ -0,0 +1,28 @@ +{{ config( + alias = 'balancer_gnosis_pools_tokens_weights', + + ) +}} + +{% set balancer_models = [ + ref('balancer_v2_gnosis_pools_tokens_weights'), + ref('balancer_v3_gnosis_pools_tokens_weights') +] %} + +SELECT * +FROM ( + {% for model in balancer_models %} + SELECT + blockchain, + version, + pool_id, + token_address, + normalized_weight + FROM {{ model }} + WHERE pool_id IS NOT NULL + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) +; diff --git a/models/_project/balancer/pools/gnosis/balancer_v2_gnosis_pools_tokens_weights.sql b/models/_project/balancer/pools/gnosis/balancer_v2_gnosis_pools_tokens_weights.sql new file mode 100644 index 0000000..584ac4b --- /dev/null +++ b/models/_project/balancer/pools/gnosis/balancer_v2_gnosis_pools_tokens_weights.sql @@ -0,0 +1,72 @@ +{{ + config( + alias = 'balancer_v2_gnosis_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v2 Pools Tokens Weights +-- +WITH registered AS ( + SELECT + poolID AS pool_id, + evt_block_time + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_v4_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_gnosis', 'WeightedPoolV4Factory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_v2_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_gnosis', 'WeightedPoolV2Factory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_v4_factory + UNION ALL + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_v2_factory +) + +SELECT + 'gnosis' AS blockchain, + '2' AS version, + r.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +LEFT JOIN registered r ON BYTEARRAY_SUBSTRING(r.pool_id,1,20) = w.pool_id +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/gnosis/balancer_v3_gnosis_pools_tokens_weights.sql b/models/_project/balancer/pools/gnosis/balancer_v3_gnosis_pools_tokens_weights.sql new file mode 100644 index 0000000..aa989a5 --- /dev/null +++ b/models/_project/balancer/pools/gnosis/balancer_v3_gnosis_pools_tokens_weights.sql @@ -0,0 +1,59 @@ +{{ + config( + alias = 'balancer_v3_gnosis_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v3 Pools Tokens Weights +-- +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_gnosis', 'Vault_evt_PoolRegistered') }} + ) AS pool_data + CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index) + GROUP BY 1 + ), + +weighted_pool_factory AS ( + SELECT + call_create.output_pool AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v3_gnosis', 'WeightedPoolFactory_call_create') }} AS call_create + JOIN token_data td ON td.pool = call_create.output_pool + CROSS JOIN UNNEST(td.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), + +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory +) + +SELECT + 'gnosis' AS blockchain, + '3' AS version, + w.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/optimism/_schema.yml b/models/_project/balancer/pools/optimism/_schema.yml new file mode 100644 index 0000000..7bcf374 --- /dev/null +++ b/models/_project/balancer/pools/optimism/_schema.yml @@ -0,0 +1,95 @@ +version: 2 + +models: + - name: balancer_optimism_pools_tokens_weights + meta: + blockchain: optimism + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['optimism', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer pools. + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + tests: + - not_null + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + - name: balancer_v2_optimism_pools_tokens_weights + meta: + blockchain: optimism + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['optimism', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v2 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_optimism_gauge_mappings + meta: + blockchain: optimism + project: balancer + contributors: msilb7 + config: + tags: ['optimism', 'balancer', 'gauges', 'incentives'] + description: > + Balancer gauge to pool mappings on Optimism. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_contract + - incentives_contract + columns: + - *blockchain + - *version + - &pool_contract + name: pool_contract + description: "Address of the liquidity pool contract" + - *pool_id + - &incentives_contract + name: incentives_contract + description: "Address of the contract where incentives are stored and emitted." + - &incentives_type + name: incentives_type + description: "Description of the incentives address type." + - &evt_block_time + name: evt_block_time + description: "Block time in UTC" + - &evt_block_number + name: evt_block_number + description: 'Event Block Number' + - &contract_address + name: contract_address + - &evt_tx_hash + name: evt_tx_hash + description: 'Transaction hash' + - &evt_index + name: evT_index + description: 'Event Index' \ No newline at end of file diff --git a/models/_project/balancer/pools/optimism/balancer_optimism_pools_tokens_weights.sql b/models/_project/balancer/pools/optimism/balancer_optimism_pools_tokens_weights.sql new file mode 100644 index 0000000..9316ad8 --- /dev/null +++ b/models/_project/balancer/pools/optimism/balancer_optimism_pools_tokens_weights.sql @@ -0,0 +1,16 @@ +{{ config( + alias = 'balancer_optimism_pools_tokens_weights' + ) +}} + +SELECT * +FROM +( + SELECT + blockchain, + version, + pool_id, + token_address, + normalized_weight + FROM {{ ref('balancer_v2_optimism_pools_tokens_weights') }} +) \ No newline at end of file diff --git a/models/_project/balancer/pools/optimism/balancer_v2_optimism_pools_tokens_weights.sql b/models/_project/balancer/pools/optimism/balancer_v2_optimism_pools_tokens_weights.sql new file mode 100644 index 0000000..8782735 --- /dev/null +++ b/models/_project/balancer/pools/optimism/balancer_v2_optimism_pools_tokens_weights.sql @@ -0,0 +1,107 @@ +{{ + config( + alias = 'balancer_v2_optimism_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v2 Pools Tokens Weights +-- +WITH registered AS ( + SELECT + poolID AS pool_id, + evt_block_time + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_optimism', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.weights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + + UNION ALL + + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_optimism', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_2tokens_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_optimism', 'WeightedPool2TokensFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.weights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_v2_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_optimism', 'WeightedPoolV2Factory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory + UNION ALL + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_2tokens_factory + UNION ALL + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_v2_factory +) + +SELECT + 'optimism' AS blockchain, + '2' AS version, + r.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +LEFT JOIN registered r ON BYTEARRAY_SUBSTRING(r.pool_id,1,20) = w.pool_id +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/polygon/_schema.yml b/models/_project/balancer/pools/polygon/_schema.yml new file mode 100644 index 0000000..e16e6d9 --- /dev/null +++ b/models/_project/balancer/pools/polygon/_schema.yml @@ -0,0 +1,76 @@ +version: 2 + +models: + - name: balancer_polygon_pools_tokens_weights + meta: + blockchain: polygon + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['polygon', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer pools. + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + tests: + - not_null + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + - name: balancer_v2_polygon_pools_tokens_weights + meta: + blockchain: polygon + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['polygon', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v2 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight + + - name: balancer_v2_polygon_lbps + meta: + blockchain: polygon + project: balancer_v2 + contributors: stefenon + config: + tags: ['polygon', 'balancer', 'lbp'] + description: > + Record of the Liquidity Boostrapping Pools (LBP) of Balancer, an automated portfolio manager and trading platform, on polygon. + columns: + - name: name + description: "Name of the LBP" + - name: pool_id + description: "ID of the LBP" + - name: token_sold + description: "Contract address of the token sold by the LBP" + - name: token_symbol + description: "Symbol of the token sold by the LBP" + - name: start_time + description: "LBP start time" + - name: end_time + description: "LBP end time" \ No newline at end of file diff --git a/models/_project/balancer/pools/polygon/balancer_polygon_pools_tokens_weights.sql b/models/_project/balancer/pools/polygon/balancer_polygon_pools_tokens_weights.sql new file mode 100644 index 0000000..79f8cf2 --- /dev/null +++ b/models/_project/balancer/pools/polygon/balancer_polygon_pools_tokens_weights.sql @@ -0,0 +1,16 @@ +{{ config( + alias = 'balancer_polygon_pools_tokens_weights', + ) +}} + +SELECT * +FROM +( + SELECT + blockchain, + version, + pool_id, + token_address, + normalized_weight + FROM {{ ref('balancer_v2_polygon_pools_tokens_weights') }} +) \ No newline at end of file diff --git a/models/_project/balancer/pools/polygon/balancer_v2_polygon_pools_tokens_weights.sql b/models/_project/balancer/pools/polygon/balancer_v2_polygon_pools_tokens_weights.sql new file mode 100644 index 0000000..a42fc7c --- /dev/null +++ b/models/_project/balancer/pools/polygon/balancer_v2_polygon_pools_tokens_weights.sql @@ -0,0 +1,107 @@ +{{ + config( + alias = 'balancer_v2_polygon_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v2 Pools Tokens Weights +-- +WITH registered AS ( + SELECT + poolID AS pool_id, + evt_block_time + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_polygon', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.weights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + + UNION ALL + + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_polygon', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_2tokens_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_polygon', 'WeightedPool2TokensFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.weights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_v2_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_polygon', 'WeightedPoolV2Factory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory + UNION ALL + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_2tokens_factory + UNION ALL + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_v2_factory +) + +SELECT + 'polygon' AS blockchain, + '2' AS version, + r.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +LEFT JOIN registered r ON BYTEARRAY_SUBSTRING(r.pool_id,1,20) = w.pool_id +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/zkevm/_schema.yml b/models/_project/balancer/pools/zkevm/_schema.yml new file mode 100644 index 0000000..ac666bf --- /dev/null +++ b/models/_project/balancer/pools/zkevm/_schema.yml @@ -0,0 +1,53 @@ +version: 2 + +models: + - name: balancer_zkevm_pools_tokens_weights + meta: + blockchain: zkevm + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['zkevm', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer pools. + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &version + name: version + description: "Version of Balancer where the liquidity pool used in transaction is deployed" + - &pool_id + name: pool_id + description: 'Unique encoded identifier that refers to each pool' + data_tests: + - not_null + - &token_address + name: token_address + description: 'Contract address for the token' + tests: + - not_null + - &normalized_weight + name: normalized_weight + description: 'Weight of the token in the pool.' + + - name: balancer_v2_zkevm_pools_tokens_weights + meta: + blockchain: zkevm + project: balancer + contributors: jacektrocinski, viniabussafi + config: + tags: ['zkevm', 'balancer', 'pools', 'tokens', 'weights'] + description: > + Token weights in Balancer v2 pools. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - token_address + columns: + - *blockchain + - *version + - *pool_id + - *token_address + - *normalized_weight \ No newline at end of file diff --git a/models/_project/balancer/pools/zkevm/balancer_v2_zkevm_pools_tokens_weights.sql b/models/_project/balancer/pools/zkevm/balancer_v2_zkevm_pools_tokens_weights.sql new file mode 100644 index 0000000..ee9f2cc --- /dev/null +++ b/models/_project/balancer/pools/zkevm/balancer_v2_zkevm_pools_tokens_weights.sql @@ -0,0 +1,53 @@ +{{ + config( + alias = 'balancer_v2_zkevm_pools_tokens_weights', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['pool_id', 'token_address'] + ) +}} + +-- +-- Balancer v2 Pools Tokens Weights +-- +WITH registered AS ( + SELECT + poolID AS pool_id, + evt_block_time + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} + {% if is_incremental() %} + WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), +weighted_pool_factory AS ( + SELECT + call_create.output_0 AS pool_id, + t.pos AS pos, + t.token_address AS token_address, + t2.normalized_weight AS normalized_weight + FROM {{ source('balancer_v2_zkevm', 'WeightedPoolFactory_call_create') }} AS call_create + CROSS JOIN UNNEST(call_create.tokens) WITH ORDINALITY t(token_address, pos) + CROSS JOIN UNNEST(call_create.normalizedWeights) WITH ORDINALITY t2(normalized_weight, pos) + WHERE t.pos = t2.pos + {% if is_incremental() %} + AND call_create.call_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} +), + +normalized_weights AS ( + SELECT + pool_id, + token_address, + normalized_weight / POWER(10, 18) AS normalized_weight + FROM weighted_pool_factory +) + +SELECT + 'zkevm' AS blockchain, + '2' AS version, + r.pool_id, + w.token_address, + w.normalized_weight +FROM normalized_weights w +LEFT JOIN registered r ON BYTEARRAY_SUBSTRING(r.pool_id,1,20) = w.pool_id +WHERE w.pool_id IS NOT NULL diff --git a/models/_project/balancer/pools/zkevm/balancer_zkevm_pools_tokens_weights.sql b/models/_project/balancer/pools/zkevm/balancer_zkevm_pools_tokens_weights.sql new file mode 100644 index 0000000..cdc274e --- /dev/null +++ b/models/_project/balancer/pools/zkevm/balancer_zkevm_pools_tokens_weights.sql @@ -0,0 +1,16 @@ +{{ config( + alias = 'balancer_zkevm_pools_tokens_weights', + ) +}} + +SELECT * +FROM +( + SELECT + blockchain, + version, + pool_id, + token_address, + normalized_weight + FROM {{ ref('balancer_v2_zkevm_pools_tokens_weights') }} +) \ No newline at end of file diff --git a/models/_project/balancer/support/_schema.yml b/models/_project/balancer/support/_schema.yml new file mode 100644 index 0000000..07ad1ae --- /dev/null +++ b/models/_project/balancer/support/_schema.yml @@ -0,0 +1,56 @@ +version: 2 + +models: + - name: balancer_token_whitelist + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, 'zkevm' + contributors: viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm'] + description: > + These tokens are whitelisted to be used as pricing assets on liquidity calculations for weighted pools, due to the trustability of their data. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - address + - name + - chain + columns: + - &address + name: address + description: "Token address" + - &name + name: name + description: "Token symbol" + - &chain + name: chain + description: "Token blockchain" + + - name: balancer_single_recipient_gauges + meta: + blockchain: ethereum + contributors: viniabussafi + config: + tags: ['ethereum', 'gauges'] + description: > + These gauges are deployed by the SingleRecipientGauge contract and this mapping manually links each gauge to it's correspondent pool and project + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - gauge_address + - pool_id + - project + - blockchain + columns: + - &gauge_address + name: gauge_address + descripton: "Gauge address" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool to which each gauge directs incentives" + - &project + name: project + description: "ve8020 project for each gauge" + - &blockchain + name: blockchain + description: "Blockchain" \ No newline at end of file diff --git a/models/_project/balancer/support/balancer_token_whitelist.sql b/models/_project/balancer/support/balancer_token_whitelist.sql new file mode 100644 index 0000000..8104e2e --- /dev/null +++ b/models/_project/balancer/support/balancer_token_whitelist.sql @@ -0,0 +1,58 @@ +{{ config( + alias = 'token_whitelist' + ) +}} + + --These tokens are whitelisted to be used as pricing assets on liquidity calculations for weighted pools, due to the trustability of their data. + +WITH whitelist_token as ( + SELECT * FROM (values + (0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8, 'USDC', 'arbitrum'), + (0xaf88d065e77c8cc2239327c5edb3a432268e5831, 'USDC', 'arbitrum'), + (0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1, 'DAI', 'arbitrum'), + (0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9, 'USDT', 'arbitrum'), + (0x82aF49447D8a07e3bd95BD0d56f35241523fBab1, 'WETH', 'arbitrum'), + (0x0fBcbaEA96Ce0cF7Ee00A8c19c3ab6f5Dc8E1921, 'WSTETH', 'arbitrum'), + (0x5979d7b546e38e414f7e9822514be443a4800529, 'WSTETH', 'arbitrum'), + (0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E, 'USDC', 'avalanche_c'), + (0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7, 'USDT', 'avalanche_c'), + (0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB, 'WETH', 'avalanche_c'), + (0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7, 'wAVAX', 'avalanche_c'), + (0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA, 'USDC', 'base'), + (0x833589fcd6edb6e08f4c7c32d4f71b54bda02913, 'USDC', 'base'), + (0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb, 'DAI', 'base'), + (0x4200000000000000000000000000000000000006, 'WETH', 'base'), + (0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83, 'WFTM', 'fantom'), + (0xddafbb505ad214d7b80b1f830fccc89b60fb7a83, 'USDC', 'gnosis'), + (0x4ecaba5870353805a9f068101a40e0f32ed605c6, 'USDT', 'gnosis'), + (0xe91d153e0b41518a2ce8dd3d7944fa863463a97d, 'WXDAI', 'gnosis'), + (0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1, 'WETH', 'gnosis'), + (0x6c76971f98945ae98dd7d4dfca8711ebea946ea6, 'WSTETH', 'gnosis'), + (0xaf204776c7245bf4147c2612bf6e5972ee483701, 'SDAI', 'gnosis'), + (0x9c58bacc331c9aa871afd802db6379a98e80cedb, 'GNO', 'gnosis'), + (0xdAC17F958D2ee523a2206206994597C13D831ec7, 'USDT', 'ethereum'), + (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, 'USDC', 'ethereum'), + (0x6B175474E89094C44Da98b954EedeAC495271d0F, 'DAI', 'ethereum'), + (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, 'WETH', 'ethereum'), + (0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0, 'WSTETH', 'ethereum'), + (0x7F5c764cBc14f9669B88837ca1490cCa17c31607, 'USDC', 'optimism'), + (0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1, 'USDT', 'optimism'), + (0x94b008aA00579c1307B0EF2c499aD98a8ce58e58, 'DAI', 'optimism'), + (0x4200000000000000000000000000000000000006, 'WETH', 'optimism'), + (0x1F32b1c2345538c0c6f582fCB022739c4A194Ebb, 'WSTETH', 'optimism'), + (0x2791bca1f2de4661ed88a30c99a7a9449aa84174, 'USDC', 'polygon'), + (0x8f3cf7ad23cd3cadbd9735aff958023239c6a063, 'DAI', 'polygon'), + (0xc2132d05d31c914a87c6611c10748aeb04b58e8f, 'USDT', 'polygon'), + (0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38, 'wS', 'sonic'), + (0xe5da20f15420ad15de0fa650600afc998bbe3955, 'stS', 'sonic'), + (0x1e5fe95fb90ac0530f581c617272cd0864626795, 'BEETS', 'sonic'), + (0xd3DCe716f3eF535C5Ff8d041c1A41C3bd89b97aE, 'scUSD', 'sonic'), + (0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270, 'WMATIC', 'polygon'), + (0x7ceb23fd6bc0add59e62ac25578270cff1b9f619, 'WETH', 'polygon'), + (0x37eaa0ef3549a5bb7d431be78a3d99bd360d19e5, 'USDC', 'zkevm'), + (0x744c5860ba161b5316f7e80d9ec415e2727e5bd5, 'DAI', 'zkevm'), + (0x4f9a0e7fd2bf6067db6994cf12e4495df938e6e9, 'WETH', 'zkevm') + ) + as t (address, name, chain)) + +SELECT * FROM whitelist_token diff --git a/models/_project/balancer_cowswap_amm/_schema.yml b/models/_project/balancer_cowswap_amm/_schema.yml new file mode 100644 index 0000000..122bf01 --- /dev/null +++ b/models/_project/balancer_cowswap_amm/_schema.yml @@ -0,0 +1,68 @@ +version: 2 + +models: + - name: balancer_cowswap_amm_balances + meta: + blockchain: arbitrum, base, ethereum, gnosis + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['arbitrum', 'base', 'ethereum', 'gnosis', 'balancer', 'balances'] + description: > + ERC20 token rolling sum balances on Balancer, an automated portfolio manager and trading platform. + columns: + - &day + name: day + description: "UTC event block time truncated to the day mark" + data_tests: + - not_null + - &blockchain + name: blockchain + description: "" + - &pool_address + name: pool_address + description: "Balancer CoWSwap AMM pool contract address" + - &token_address + name: token_address + description: "Token contract address" + - &token_balance_raw + name: token_balance_raw + description: "Balance of a token" + + - name: balancer_cowswap_amm_liquidity + meta: + blockchain: arbitrum, base, ethereum, gnosis + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['arbitrum', 'base', 'ethereum', 'gnosis', 'balancer', 'pools', 'liquidity'] + description: > + Balancer CoWSwap AMM pools liquidity by token in Ethereum. + columns: + - *day + - name: pool_id + - *pool_address + - name: pool_symbol + - name: version + - *blockchain + - name: pool_type + - *token_address + - &token_symbol + name: token_symbol + description: "Token symbol" + - *token_balance_raw + - &token_balance + name: token_balance + description: "Balance of the token in the pool" + - &protocol_liquidity_usd + name: protocol_liquidity_usd + description: "Protocol liquidity in USD" + - &protocol_liquidity_eth + name: protocol_liquidity_eth + description: "Protocol liquidity in ETH" + - &pool_liquidity_usd + name: pool_liquidity_usd + description: "Pool liquidity in USD" + - &pool_liquidity_eth + name: pool_liquidity_eth + description: "Pool liquidity in ETH" \ No newline at end of file diff --git a/models/_project/balancer_cowswap_amm/arbitrum/_schema.yml b/models/_project/balancer_cowswap_amm/arbitrum/_schema.yml new file mode 100644 index 0000000..ee5ebc5 --- /dev/null +++ b/models/_project/balancer_cowswap_amm/arbitrum/_schema.yml @@ -0,0 +1,80 @@ +version: 2 + +models: + - name: balancer_cowswap_amm_arbitrum_balances + meta: + blockchain: arbitrum + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['arbitrum', 'balancer', 'balances'] + description: > + ERC20 token rolling sum balances on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_address + - token_address + columns: + - &day + name: day + description: "UTC event block time truncated to the day mark" + data_tests: + - not_null + - &blockchain + name: blockchain + description: "" + - &pool_address + name: pool_address + description: "Balancer CoWSwap AMM pool contract address" + - &token_address + name: token_address + description: "Token contract address" + - &token_balance_raw + name: token_balance_raw + description: "Balance of a token" + + - name: balancer_cowswap_amm_arbitrum_liquidity + meta: + blockchain: arbitrum + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['arbitrum', 'balancer', 'pools', 'liquidity'] + description: > + Balancer CoWSwap AMM pools liquidity by token in arbitrum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - *day + - name: pool_id + - *pool_address + - name: pool_symbol + - name: version + - *blockchain + - name: pool_type + - *token_address + - &token_symbol + name: token_symbol + description: "Token symbol" + - *token_balance_raw + - &token_balance + name: token_balance + description: "Balance of the token in the pool" + - &protocol_liquidity_usd + name: protocol_liquidity_usd + description: "Protocol liquidity in USD" + - &protocol_liquidity_eth + name: protocol_liquidity_eth + description: "Protocol liquidity in ETH" + - &pool_liquidity_usd + name: pool_liquidity_usd + description: "Pool liquidity in USD" + - &pool_liquidity_eth + name: pool_liquidity_eth + description: "Pool liquidity in ETH" \ No newline at end of file diff --git a/models/_project/balancer_cowswap_amm/arbitrum/balancer_cowswap_amm_arbitrum_balances.sql b/models/_project/balancer_cowswap_amm/arbitrum/balancer_cowswap_amm_arbitrum_balances.sql new file mode 100644 index 0000000..768993c --- /dev/null +++ b/models/_project/balancer_cowswap_amm/arbitrum/balancer_cowswap_amm_arbitrum_balances.sql @@ -0,0 +1,75 @@ +{{ + config( + alias = 'balancer_cowswap_amm_arbitrum_balances', + materialized = 'table', + ) +}} + +WITH pools AS ( + SELECT + bPool AS pools + FROM {{ source('b_cow_amm_arbitrum', 'BCoWFactory_evt_LOG_NEW_POOL') }} +), + +joins AS ( + SELECT + p.pools AS pool, + DATE_TRUNC('day', e.evt_block_time) AS day, + e.contract_address AS token, + SUM(CAST(value AS int256)) AS amount + FROM {{ source('erc20_arbitrum', 'evt_Transfer') }} e + INNER JOIN pools p ON e."to" = p.pools + GROUP BY 1, 2, 3 +), + +exits AS ( + SELECT + p.pools AS pool, + DATE_TRUNC('day', e.evt_block_time) AS day, + e.contract_address AS token, + - SUM(CAST(value AS int256)) AS amount + FROM {{ source('erc20_arbitrum', 'evt_Transfer') }} e + INNER JOIN pools p ON e."from" = p.pools + GROUP BY 1, 2, 3 +), + +daily_delta_balance_by_token AS ( + SELECT + pool, + day, + token, + SUM(COALESCE(amount, CAST(0 AS int256))) AS amount + FROM + (SELECT * + FROM joins j + UNION ALL + SELECT * + FROM exits e) foo + GROUP BY 1, 2, 3 +), + +cumulative_balance_by_token AS ( + SELECT + pool, + token, + day, + LEAD(day, 1, now()) OVER (PARTITION BY pool, token ORDER BY day) AS day_of_next_change, + SUM(amount) OVER (PARTITION BY pool, token ORDER BY day ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_amount + FROM daily_delta_balance_by_token +), + +calendar AS ( + SELECT + date_sequence AS day + FROM unnest(sequence(date('2024-07-01'), date(now()), interval '1' day)) AS t(date_sequence) +) + +SELECT + c.day, + 'arbitrum' AS blockchain, + b.pool AS pool_address, + b.token AS token_address, + b.cumulative_amount AS token_balance_raw +FROM calendar c +LEFT JOIN cumulative_balance_by_token b ON b.day <= c.day AND c.day < b.day_of_next_change +WHERE b.pool IS NOT NULL diff --git a/models/_project/balancer_cowswap_amm/arbitrum/balancer_cowswap_amm_arbitrum_liquidity.sql b/models/_project/balancer_cowswap_amm/arbitrum/balancer_cowswap_amm_arbitrum_liquidity.sql new file mode 100644 index 0000000..abe8d95 --- /dev/null +++ b/models/_project/balancer_cowswap_amm/arbitrum/balancer_cowswap_amm_arbitrum_liquidity.sql @@ -0,0 +1,83 @@ +{% set blockchain = 'arbitrum' %} + +{{ + config( + alias = 'balancer_cowswap_amm_arbitrum_liquidity', + materialized = 'table', + ) +}} + +WITH pool_labels AS ( + SELECT + address, + name + FROM {{ source('labels', 'balancer_cowswap_amm_pools') }} + WHERE blockchain = '{{blockchain}}' + ), + + prices AS ( + SELECT + date_trunc('day', minute) AS day, + contract_address AS token, + decimals, + AVG(price) AS price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + eth_prices AS( + SELECT + date_trunc('day', minute) AS day, + AVG(price) AS eth_price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = 'ethereum' + AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + GROUP BY 1 + ), + + cumulative_balance AS ( + SELECT + day, + pool_address, + token_address, + token_balance_raw + FROM {{ ref('balancer_cowswap_amm_arbitrum_balances') }} b + ), + + cumulative_usd_balance AS ( + SELECT + b.day, + b.pool_address, + b.token_address, + t.symbol, + token_balance_raw, + token_balance_raw / POWER(10, COALESCE(t.decimals, p1.decimals)) AS token_balance, + token_balance_raw / POWER(10, COALESCE(t.decimals, p1.decimals)) * COALESCE(p1.price, 0) AS protocol_liquidity_usd + FROM cumulative_balance b + LEFT JOIN {{ source('tokens', 'erc20') }} t ON t.contract_address = b.token_address + AND t.blockchain = '{{blockchain}}' + LEFT JOIN prices p1 ON p1.day = b.day + AND p1.token = b.token_address + ) + +SELECT + c.day, + c.pool_address AS pool_id, + c.pool_address, + p.name AS pool_symbol, + '1' AS version, + '{{blockchain}}' AS blockchain, + 'balancer_cowswap_amm' AS pool_type, + c.token_address, + c.symbol AS token_symbol, + c.token_balance_raw, + c.token_balance, + c.protocol_liquidity_usd, + (c.protocol_liquidity_usd) / e.eth_price AS protocol_liquidity_eth, + c.protocol_liquidity_usd AS pool_liquidity_usd, + (c.protocol_liquidity_usd) / e.eth_price AS pool_liquidity_eth +FROM cumulative_usd_balance c +LEFT JOIN pool_labels p ON p.address = c.pool_address +LEFT JOIN eth_prices e ON e.day = c.day +WHERE c.pool_address IS NOT NULL \ No newline at end of file diff --git a/models/_project/balancer_cowswap_amm/balancer_cowswap_amm_balances.sql b/models/_project/balancer_cowswap_amm/balancer_cowswap_amm_balances.sql new file mode 100644 index 0000000..66c783b --- /dev/null +++ b/models/_project/balancer_cowswap_amm/balancer_cowswap_amm_balances.sql @@ -0,0 +1,30 @@ +{{ + config( + alias = 'balancer_cowswap_amm_balances', + materialized = 'view' + ) +}} + + +{% set b_cow_amm_models = [ + ref('balancer_cowswap_amm_arbitrum_balances'), + ref('balancer_cowswap_amm_base_balances'), + ref('balancer_cowswap_amm_ethereum_balances'), + ref('balancer_cowswap_amm_gnosis_balances') +] %} + +SELECT * +FROM ( + {% for model in b_cow_amm_models %} + SELECT + day, + blockchain, + pool_address, + token_address, + token_balance_raw + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) \ No newline at end of file diff --git a/models/_project/balancer_cowswap_amm/balancer_cowswap_amm_liquidity.sql b/models/_project/balancer_cowswap_amm/balancer_cowswap_amm_liquidity.sql new file mode 100644 index 0000000..e9f764b --- /dev/null +++ b/models/_project/balancer_cowswap_amm/balancer_cowswap_amm_liquidity.sql @@ -0,0 +1,39 @@ +{{ + config( + alias = 'balancer_cowswap_amm_liquidity', + materialized = 'view' + ) +}} + +{% set b_cow_amm_models = [ + ref('balancer_cowswap_amm_arbitrum_liquidity'), + ref('balancer_cowswap_amm_base_liquidity'), + ref('balancer_cowswap_amm_ethereum_liquidity'), + ref('balancer_cowswap_amm_gnosis_liquidity') +] %} + +SELECT * +FROM ( + {% for model in b_cow_amm_models %} + SELECT + day, + pool_id, + pool_address, + pool_symbol, + version, + blockchain, + pool_type, + token_address, + token_symbol, + token_balance_raw, + token_balance, + protocol_liquidity_usd, + protocol_liquidity_eth, + pool_liquidity_usd, + pool_liquidity_eth + FROM {{ model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} +) \ No newline at end of file diff --git a/models/_project/balancer_cowswap_amm/base/_schema.yml b/models/_project/balancer_cowswap_amm/base/_schema.yml new file mode 100644 index 0000000..41ad149 --- /dev/null +++ b/models/_project/balancer_cowswap_amm/base/_schema.yml @@ -0,0 +1,80 @@ +version: 2 + +models: + - name: balancer_cowswap_amm_base_balances + meta: + blockchain: base + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['base', 'balancer', 'balances'] + description: > + ERC20 token rolling sum balances on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_address + - token_address + columns: + - &day + name: day + description: "UTC event block time truncated to the day mark" + data_tests: + - not_null + - &blockchain + name: blockchain + description: "" + - &pool_address + name: pool_address + description: "Balancer CoWSwap AMM pool contract address" + - &token_address + name: token_address + description: "Token contract address" + - &token_balance_raw + name: token_balance_raw + description: "Balance of a token" + + - name: balancer_cowswap_amm_base_liquidity + meta: + blockchain: base + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['base', 'balancer', 'pools', 'liquidity'] + description: > + Balancer CoWSwap AMM pools liquidity by token in base. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - *day + - name: pool_id + - *pool_address + - name: pool_symbol + - name: version + - *blockchain + - name: pool_type + - *token_address + - &token_symbol + name: token_symbol + description: "Token symbol" + - *token_balance_raw + - &token_balance + name: token_balance + description: "Balance of the token in the pool" + - &protocol_liquidity_usd + name: protocol_liquidity_usd + description: "Protocol liquidity in USD" + - &protocol_liquidity_eth + name: protocol_liquidity_eth + description: "Protocol liquidity in ETH" + - &pool_liquidity_usd + name: pool_liquidity_usd + description: "Pool liquidity in USD" + - &pool_liquidity_eth + name: pool_liquidity_eth + description: "Pool liquidity in ETH" \ No newline at end of file diff --git a/models/_project/balancer_cowswap_amm/base/balancer_cowswap_amm_base_balances.sql b/models/_project/balancer_cowswap_amm/base/balancer_cowswap_amm_base_balances.sql new file mode 100644 index 0000000..fc21cbb --- /dev/null +++ b/models/_project/balancer_cowswap_amm/base/balancer_cowswap_amm_base_balances.sql @@ -0,0 +1,75 @@ +{{ + config( + alias = 'balancer_cowswap_amm_base_balances', + materialized = 'table', + ) +}} + +WITH pools AS ( + SELECT + bPool AS pools + FROM {{ source('b_cow_amm_base', 'BCoWFactory_evt_LOG_NEW_POOL') }} +), + +joins AS ( + SELECT + p.pools AS pool, + DATE_TRUNC('day', e.evt_block_time) AS day, + e.contract_address AS token, + SUM(CAST(value AS int256)) AS amount + FROM {{ source('erc20_base', 'evt_Transfer') }} e + INNER JOIN pools p ON e."to" = p.pools + GROUP BY 1, 2, 3 +), + +exits AS ( + SELECT + p.pools AS pool, + DATE_TRUNC('day', e.evt_block_time) AS day, + e.contract_address AS token, + - SUM(CAST(value AS int256)) AS amount + FROM {{ source('erc20_base', 'evt_Transfer') }} e + INNER JOIN pools p ON e."from" = p.pools + GROUP BY 1, 2, 3 +), + +daily_delta_balance_by_token AS ( + SELECT + pool, + day, + token, + SUM(COALESCE(amount, CAST(0 AS int256))) AS amount + FROM + (SELECT * + FROM joins j + UNION ALL + SELECT * + FROM exits e) foo + GROUP BY 1, 2, 3 +), + +cumulative_balance_by_token AS ( + SELECT + pool, + token, + day, + LEAD(day, 1, now()) OVER (PARTITION BY pool, token ORDER BY day) AS day_of_next_change, + SUM(amount) OVER (PARTITION BY pool, token ORDER BY day ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_amount + FROM daily_delta_balance_by_token +), + +calendar AS ( + SELECT + date_sequence AS day + FROM unnest(sequence(date('2024-12-01'), date(now()), interval '1' day)) AS t(date_sequence) +) + +SELECT + c.day, + 'base' AS blockchain, + b.pool AS pool_address, + b.token AS token_address, + b.cumulative_amount AS token_balance_raw +FROM calendar c +LEFT JOIN cumulative_balance_by_token b ON b.day <= c.day AND c.day < b.day_of_next_change +WHERE b.pool IS NOT NULL diff --git a/models/_project/balancer_cowswap_amm/base/balancer_cowswap_amm_base_liquidity.sql b/models/_project/balancer_cowswap_amm/base/balancer_cowswap_amm_base_liquidity.sql new file mode 100644 index 0000000..b75dd2a --- /dev/null +++ b/models/_project/balancer_cowswap_amm/base/balancer_cowswap_amm_base_liquidity.sql @@ -0,0 +1,83 @@ +{% set blockchain = 'base' %} + +{{ + config( + alias = 'balancer_cowswap_amm_base_liquidity', + materialized = 'table', + ) +}} + +WITH pool_labels AS ( + SELECT + address, + name + FROM {{ source('labels', 'balancer_cowswap_amm_pools') }} + WHERE blockchain = '{{blockchain}}' + ), + + prices AS ( + SELECT + date_trunc('day', minute) AS day, + contract_address AS token, + decimals, + AVG(price) AS price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + eth_prices AS( + SELECT + date_trunc('day', minute) AS day, + APPROX_PERCENTILE(price, 0.5) AS eth_price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + GROUP BY 1 + ), + + cumulative_balance AS ( + SELECT + day, + pool_address, + token_address, + token_balance_raw + FROM {{ ref('balancer_cowswap_amm_base_balances') }} b + ), + + cumulative_usd_balance AS ( + SELECT + b.day, + b.pool_address, + b.token_address, + t.symbol, + token_balance_raw, + token_balance_raw / POWER(10, COALESCE(t.decimals, p1.decimals)) AS token_balance, + token_balance_raw / POWER(10, COALESCE(t.decimals, p1.decimals)) * COALESCE(p1.price, 0) AS protocol_liquidity_usd + FROM cumulative_balance b + LEFT JOIN {{ source('tokens', 'erc20') }} t ON t.contract_address = b.token_address + AND t.blockchain = '{{blockchain}}' + LEFT JOIN prices p1 ON p1.day = b.day + AND p1.token = b.token_address + ) + +SELECT + c.day, + c.pool_address AS pool_id, + c.pool_address, + p.name AS pool_symbol, + '1' AS version, + '{{blockchain}}' AS blockchain, + 'balancer_cowswap_amm' AS pool_type, + c.token_address, + c.symbol AS token_symbol, + c.token_balance_raw, + c.token_balance, + c.protocol_liquidity_usd, + (c.protocol_liquidity_usd) / e.eth_price AS protocol_liquidity_eth, + c.protocol_liquidity_usd AS pool_liquidity_usd, + (c.protocol_liquidity_usd) / e.eth_price AS pool_liquidity_eth +FROM cumulative_usd_balance c +LEFT JOIN pool_labels p ON p.address = c.pool_address +LEFT JOIN eth_prices e ON e.day = c.day +WHERE c.pool_address IS NOT NULL diff --git a/models/_project/balancer_cowswap_amm/ethereum/_schema.yml b/models/_project/balancer_cowswap_amm/ethereum/_schema.yml new file mode 100644 index 0000000..e6038d9 --- /dev/null +++ b/models/_project/balancer_cowswap_amm/ethereum/_schema.yml @@ -0,0 +1,80 @@ +version: 2 + +models: + - name: balancer_cowswap_amm_ethereum_balances + meta: + blockchain: ethereum + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['ethereum', 'balancer', 'balances'] + description: > + ERC20 token rolling sum balances on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_address + - token_address + columns: + - &day + name: day + description: "UTC event block time truncated to the day mark" + data_tests: + - not_null + - &blockchain + name: blockchain + description: "" + - &pool_address + name: pool_address + description: "Balancer CoWSwap AMM pool contract address" + - &token_address + name: token_address + description: "Token contract address" + - &token_balance_raw + name: token_balance_raw + description: "Balance of a token" + + - name: balancer_cowswap_amm_ethereum_liquidity + meta: + blockchain: ethereum + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['ethereum', 'balancer', 'pools', 'liquidity'] + description: > + Balancer CoWSwap AMM pools liquidity by token in ethereum. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - *day + - name: pool_id + - *pool_address + - name: pool_symbol + - name: version + - *blockchain + - name: pool_type + - *token_address + - &token_symbol + name: token_symbol + description: "Token symbol" + - *token_balance_raw + - &token_balance + name: token_balance + description: "Balance of the token in the pool" + - &protocol_liquidity_usd + name: protocol_liquidity_usd + description: "Protocol liquidity in USD" + - &protocol_liquidity_eth + name: protocol_liquidity_eth + description: "Protocol liquidity in ETH" + - &pool_liquidity_usd + name: pool_liquidity_usd + description: "Pool liquidity in USD" + - &pool_liquidity_eth + name: pool_liquidity_eth + description: "Pool liquidity in ETH" \ No newline at end of file diff --git a/models/_project/balancer_cowswap_amm/ethereum/balancer_cowswap_amm_ethereum_balances.sql b/models/_project/balancer_cowswap_amm/ethereum/balancer_cowswap_amm_ethereum_balances.sql new file mode 100644 index 0000000..97d9025 --- /dev/null +++ b/models/_project/balancer_cowswap_amm/ethereum/balancer_cowswap_amm_ethereum_balances.sql @@ -0,0 +1,75 @@ +{{ + config( + alias = 'balancer_cowswap_amm_ethereum_balances', + materialized = 'table', + ) +}} + +WITH pools AS ( + SELECT + bPool AS pools + FROM {{ source('b_cow_amm_ethereum', 'BCoWFactory_evt_LOG_NEW_POOL') }} +), + +joins AS ( + SELECT + p.pools AS pool, + DATE_TRUNC('day', e.evt_block_time) AS day, + e.contract_address AS token, + SUM(CAST(value AS int256)) AS amount + FROM {{ source('erc20_ethereum', 'evt_Transfer') }} e + INNER JOIN pools p ON e."to" = p.pools + GROUP BY 1, 2, 3 +), + +exits AS ( + SELECT + p.pools AS pool, + DATE_TRUNC('day', e.evt_block_time) AS day, + e.contract_address AS token, + - SUM(CAST(value AS int256)) AS amount + FROM {{ source('erc20_ethereum', 'evt_Transfer') }} e + INNER JOIN pools p ON e."from" = p.pools + GROUP BY 1, 2, 3 +), + +daily_delta_balance_by_token AS ( + SELECT + pool, + day, + token, + SUM(COALESCE(amount, CAST(0 AS int256))) AS amount + FROM + (SELECT * + FROM joins j + UNION ALL + SELECT * + FROM exits e) foo + GROUP BY 1, 2, 3 +), + +cumulative_balance_by_token AS ( + SELECT + pool, + token, + day, + LEAD(day, 1, now()) OVER (PARTITION BY pool, token ORDER BY day) AS day_of_next_change, + SUM(amount) OVER (PARTITION BY pool, token ORDER BY day ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_amount + FROM daily_delta_balance_by_token +), + +calendar AS ( + SELECT + date_sequence AS day + FROM unnest(sequence(date('2024-07-01'), date(now()), interval '1' day)) AS t(date_sequence) +) + +SELECT + c.day, + 'ethereum' AS blockchain, + b.pool AS pool_address, + b.token AS token_address, + b.cumulative_amount AS token_balance_raw +FROM calendar c +LEFT JOIN cumulative_balance_by_token b ON b.day <= c.day AND c.day < b.day_of_next_change +WHERE b.pool IS NOT NULL diff --git a/models/_project/balancer_cowswap_amm/ethereum/balancer_cowswap_amm_ethereum_liquidity.sql b/models/_project/balancer_cowswap_amm/ethereum/balancer_cowswap_amm_ethereum_liquidity.sql new file mode 100644 index 0000000..499abd6 --- /dev/null +++ b/models/_project/balancer_cowswap_amm/ethereum/balancer_cowswap_amm_ethereum_liquidity.sql @@ -0,0 +1,83 @@ +{% set blockchain = 'ethereum' %} + +{{ + config( + alias = 'balancer_cowswap_amm_ethereum_liquidity', + materialized = 'table', + ) +}} + +WITH pool_labels AS ( + SELECT + address, + name + FROM {{ source('labels', 'balancer_cowswap_amm_pools') }} + WHERE blockchain = '{{blockchain}}' + ), + + prices AS ( + SELECT + date_trunc('day', minute) AS day, + contract_address AS token, + decimals, + AVG(price) AS price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + eth_prices AS( + SELECT + date_trunc('day', minute) AS day, + APPROX_PERCENTILE(price, 0.5) AS eth_price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + GROUP BY 1 + ), + + cumulative_balance AS ( + SELECT + day, + pool_address, + token_address, + token_balance_raw + FROM {{ ref('balancer_cowswap_amm_ethereum_balances') }} b + ), + + cumulative_usd_balance AS ( + SELECT + b.day, + b.pool_address, + b.token_address, + t.symbol, + token_balance_raw, + token_balance_raw / POWER(10, COALESCE(t.decimals, p1.decimals)) AS token_balance, + token_balance_raw / POWER(10, COALESCE(t.decimals, p1.decimals)) * COALESCE(p1.price, 0) AS protocol_liquidity_usd + FROM cumulative_balance b + LEFT JOIN {{ source('tokens', 'erc20') }} t ON t.contract_address = b.token_address + AND t.blockchain = '{{blockchain}}' + LEFT JOIN prices p1 ON p1.day = b.day + AND p1.token = b.token_address + ) + +SELECT + c.day, + c.pool_address AS pool_id, + c.pool_address, + p.name AS pool_symbol, + '1' AS version, + '{{blockchain}}' AS blockchain, + 'balancer_cowswap_amm' AS pool_type, + c.token_address, + c.symbol AS token_symbol, + c.token_balance_raw, + c.token_balance, + c.protocol_liquidity_usd, + (c.protocol_liquidity_usd) / e.eth_price AS protocol_liquidity_eth, + c.protocol_liquidity_usd AS pool_liquidity_usd, + (c.protocol_liquidity_usd) / e.eth_price AS pool_liquidity_eth +FROM cumulative_usd_balance c +LEFT JOIN pool_labels p ON p.address = c.pool_address +LEFT JOIN eth_prices e ON e.day = c.day +WHERE c.pool_address IS NOT NULL diff --git a/models/_project/balancer_cowswap_amm/gnosis/_schema.yml b/models/_project/balancer_cowswap_amm/gnosis/_schema.yml new file mode 100644 index 0000000..733a07d --- /dev/null +++ b/models/_project/balancer_cowswap_amm/gnosis/_schema.yml @@ -0,0 +1,80 @@ +version: 2 + +models: + - name: balancer_cowswap_amm_gnosis_balances + meta: + blockchain: gnosis + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['gnosis', 'balancer', 'balances'] + description: > + ERC20 token rolling sum balances on Balancer, an automated portfolio manager and trading platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_address + - token_address + columns: + - &day + name: day + description: "UTC event block time truncated to the day mark" + data_tests: + - not_null + - &blockchain + name: blockchain + description: "" + - &pool_address + name: pool_address + description: "Balancer CoWSwap AMM pool contract address" + - &token_address + name: token_address + description: "Token contract address" + - &token_balance_raw + name: token_balance_raw + description: "Balance of a token" + + - name: balancer_cowswap_amm_gnosis_liquidity + meta: + blockchain: gnosis + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['gnosis', 'balancer', 'pools', 'liquidity'] + description: > + Balancer CoWSwap AMM pools liquidity by token in gnosis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool_id + - token_address + columns: + - *day + - name: pool_id + - *pool_address + - name: pool_symbol + - name: version + - *blockchain + - name: pool_type + - *token_address + - &token_symbol + name: token_symbol + description: "Token symbol" + - *token_balance_raw + - &token_balance + name: token_balance + description: "Balance of the token in the pool" + - &protocol_liquidity_usd + name: protocol_liquidity_usd + description: "Protocol liquidity in USD" + - &protocol_liquidity_eth + name: protocol_liquidity_eth + description: "Protocol liquidity in ETH" + - &pool_liquidity_usd + name: pool_liquidity_usd + description: "Pool liquidity in USD" + - &pool_liquidity_eth + name: pool_liquidity_eth + description: "Pool liquidity in ETH" \ No newline at end of file diff --git a/models/_project/balancer_cowswap_amm/gnosis/balancer_cowswap_amm_gnosis_balances.sql b/models/_project/balancer_cowswap_amm/gnosis/balancer_cowswap_amm_gnosis_balances.sql new file mode 100644 index 0000000..b88a1de --- /dev/null +++ b/models/_project/balancer_cowswap_amm/gnosis/balancer_cowswap_amm_gnosis_balances.sql @@ -0,0 +1,75 @@ +{{ + config( + alias = 'balancer_cowswap_amm_gnosis_balances', + materialized = 'table', + ) +}} + +WITH pools AS ( + SELECT + bPool AS pools + FROM {{ source('b_cow_amm_gnosis', 'BCoWFactory_evt_LOG_NEW_POOL') }} +), + +joins AS ( + SELECT + p.pools AS pool, + DATE_TRUNC('day', e.evt_block_time) AS day, + e.contract_address AS token, + SUM(CAST(value AS int256)) AS amount + FROM {{ source('erc20_gnosis', 'evt_Transfer') }} e + INNER JOIN pools p ON e."to" = p.pools + GROUP BY 1, 2, 3 +), + +exits AS ( + SELECT + p.pools AS pool, + DATE_TRUNC('day', e.evt_block_time) AS day, + e.contract_address AS token, + - SUM(CAST(value AS int256)) AS amount + FROM {{ source('erc20_gnosis', 'evt_Transfer') }} e + INNER JOIN pools p ON e."from" = p.pools + GROUP BY 1, 2, 3 +), + +daily_delta_balance_by_token AS ( + SELECT + pool, + day, + token, + SUM(COALESCE(amount, CAST(0 AS int256))) AS amount + FROM + (SELECT * + FROM joins j + UNION ALL + SELECT * + FROM exits e) foo + GROUP BY 1, 2, 3 +), + +cumulative_balance_by_token AS ( + SELECT + pool, + token, + day, + LEAD(day, 1, now()) OVER (PARTITION BY pool, token ORDER BY day) AS day_of_next_change, + SUM(amount) OVER (PARTITION BY pool, token ORDER BY day ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_amount + FROM daily_delta_balance_by_token +), + +calendar AS ( + SELECT + date_sequence AS day + FROM unnest(sequence(date('2024-07-01'), date(now()), interval '1' day)) AS t(date_sequence) +) + +SELECT + c.day, + 'gnosis' AS blockchain, + b.pool AS pool_address, + b.token AS token_address, + b.cumulative_amount AS token_balance_raw +FROM calendar c +LEFT JOIN cumulative_balance_by_token b ON b.day <= c.day AND c.day < b.day_of_next_change +WHERE b.pool IS NOT NULL diff --git a/models/_project/balancer_cowswap_amm/gnosis/balancer_cowswap_amm_gnosis_liquidity.sql b/models/_project/balancer_cowswap_amm/gnosis/balancer_cowswap_amm_gnosis_liquidity.sql new file mode 100644 index 0000000..a8ae129 --- /dev/null +++ b/models/_project/balancer_cowswap_amm/gnosis/balancer_cowswap_amm_gnosis_liquidity.sql @@ -0,0 +1,83 @@ +{% set blockchain = 'gnosis' %} + +{{ + config( + alias = 'balancer_cowswap_amm_gnosis_liquidity', + materialized = 'table', + ) +}} + +WITH pool_labels AS ( + SELECT + address, + name + FROM {{ source('labels', 'balancer_cowswap_amm_pools') }} + WHERE blockchain = '{{blockchain}}' + ), + + prices AS ( + SELECT + date_trunc('day', minute) AS day, + contract_address AS token, + decimals, + AVG(price) AS price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = '{{blockchain}}' + GROUP BY 1, 2, 3 + ), + + eth_prices AS( + SELECT + date_trunc('day', minute) AS day, + APPROX_PERCENTILE(price, 0.5) AS eth_price + FROM {{ source('prices', 'usd') }} + WHERE blockchain = 'ethereum' + AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + GROUP BY 1 + ), + + cumulative_balance AS ( + SELECT + day, + pool_address, + token_address, + token_balance_raw + FROM {{ ref('balancer_cowswap_amm_gnosis_balances') }} b + ), + + cumulative_usd_balance AS ( + SELECT + b.day, + b.pool_address, + b.token_address, + t.symbol, + token_balance_raw, + token_balance_raw / POWER(10, COALESCE(t.decimals, p1.decimals)) AS token_balance, + token_balance_raw / POWER(10, COALESCE(t.decimals, p1.decimals)) * COALESCE(p1.price, 0) AS protocol_liquidity_usd + FROM cumulative_balance b + LEFT JOIN {{ source('tokens', 'erc20') }} t ON t.contract_address = b.token_address + AND t.blockchain = '{{blockchain}}' + LEFT JOIN prices p1 ON p1.day = b.day + AND p1.token = b.token_address + ) + +SELECT + c.day, + c.pool_address AS pool_id, + c.pool_address, + p.name AS pool_symbol, + '1' AS version, + '{{blockchain}}' AS blockchain, + 'balancer_cowswap_amm' AS pool_type, + c.token_address, + c.symbol AS token_symbol, + c.token_balance_raw, + c.token_balance, + c.protocol_liquidity_usd, + (c.protocol_liquidity_usd) / e.eth_price AS protocol_liquidity_eth, + c.protocol_liquidity_usd AS pool_liquidity_usd, + (c.protocol_liquidity_usd) / e.eth_price AS pool_liquidity_eth +FROM cumulative_usd_balance c +LEFT JOIN pool_labels p ON p.address = c.pool_address +LEFT JOIN eth_prices e ON e.day = c.day +WHERE c.pool_address IS NOT NULL diff --git a/models/_projects/balancer/labels/_schema.yml b/models/_projects/balancer/labels/_schema.yml new file mode 100644 index 0000000..3366fe1 --- /dev/null +++ b/models/_projects/balancer/labels/_schema.yml @@ -0,0 +1,455 @@ +version: 2 + +models: + - name: labels_balancer_v1_pools_ethereum + meta: + blockchain: ethereum + sector: labels + project: balancer_v1 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'ethereum', 'balancer', 'pools'] + description: "Balancer V1 liquidity pools created on Ethereum. " + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - address + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &address + name: address + description: "Address of liquidity pool" + tests: + - not_null + - &name + name: name + description: "Label name of pool containg the token symbols and their respective weights (if applicable)" + - &category + name: category + description: "Label category" + - &contributor + name: contributor + description: "Wizard(s) contributing to labels" + - &source + name: source + description: "How were labels generated (could be static or query)" + - &created_at + name: created_at + description: "When were labels created" + - &updated_at + name: updated_at + description: "When were labels updated for the last time" + - &model_name + name: model_name + description: "Name of the label model sourced from" + - &label_type + name: label_type + description: "Type of label (see labels overall readme)" + + - name: labels_balancer_v1_pools + meta: + blockchain: ethereum + sector: labels + project: balancer_v1 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'ethereum', 'balancer', 'pools'] + description: "Balancer V1 liquidity pools created across blockchains." + columns: + - *blockchain + - *address + - *name + - *category + - *contributor + - *source + - *created_at + - *updated_at + - *model_name + - *label_type + + - name: labels_balancer_v2_pools_ethereum + meta: + blockchain: ethereum + sector: labels + project: balancer_v2 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'ethereum', 'balancer', 'pools'] + description: 'Balancer V2 liquidity pools created on Ethereum. ' + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - address + - name + - category + - model_name + - blockchain + columns: + - *blockchain + - *address + - *name + - *category + - *contributor + - *source + - *created_at + - *updated_at + - *model_name + - *label_type + + - name: labels_balancer_v2_pools_polygon + meta: + blockchain: polygon + sector: labels + project: balancer_v2 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'polygon', 'balancer', 'pools'] + description: 'Balancer V2 liquidity pools created on Polygon.' + 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_v2_pools_gnosis + meta: + blockchain: gnosis + sector: labels + project: balancer_v2 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'gnosis', 'balancer', 'pools'] + description: 'Balancer V2 liquidity pools created on Gnosis.' + 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_v2_pools_avalanche_c + meta: + blockchain: avalanche_c + sector: labels + project: balancer_v2 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'avalanche_c', 'balancer', 'pools'] + description: 'Balancer V2 liquidity pools created on Avalanche Chain.' + 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_v2_pools_base + meta: + blockchain: base + sector: labels + project: balancer_v2 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'base', 'balancer', 'pools'] + description: 'Balancer V2 liquidity pools created on Base Chain.' + 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_v2_pools_arbitrum + meta: + blockchain: arbitrum + sector: labels + project: balancer_v2 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'arbitrum', 'balancer', 'pools'] + description: 'Balancer V2 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_v2_pools_optimism + meta: + blockchain: optimism + sector: labels + project: balancer_v2 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'optimism', 'balancer', 'pools'] + description: 'Balancer V2 liquidity pools created on Optimism.' + 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_v2_pools_zkevm + meta: + blockchain: zkevm + sector: labels + project: balancer_v2 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'zkevm', 'balancer', 'pools'] + description: 'Balancer V2 liquidity pools created on Polygon zkevm.' + 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_v2_pools + meta: + blockchain: ethereum, polygon, arbitrum, optimism, gnosis, base, avalanche_c, zkevm + sector: labels + project: balancer_v2 + contributors: balancerlabs, viniabussafi + config: + tags: + [ + 'labels', + 'ethereum', + 'polygon', + 'arbitrum', + 'optimism', + 'avalanche_c', + 'base', + 'gnosis', + 'zkevm', + 'balancer', + 'pools', + ] + description: 'Balancer V2 liquidity pools created across blockchains.' + columns: + - *blockchain + - *address + - *name + - *category + - *contributor + - *source + - *created_at + - *updated_at + - *model_name + - *label_type + + - name: labels_balancer_v3_pools_ethereum + meta: + blockchain: ethereum + sector: labels + project: balancer_v3 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'ethereum', 'balancer', 'pools'] + description: 'Balancer V3 liquidity pools created on Ethereum.' + 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_gnosis + meta: + blockchain: gnosis + sector: labels + project: balancer_v3 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'gnosis', 'balancer', 'pools'] + description: 'Balancer V3 liquidity pools created on Gnosis.' + 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_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_plasma + meta: + blockchain: plasma + sector: labels + project: balancer_v3 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'plasma', 'balancer', 'pools'] + description: 'Balancer V3 liquidity pools created on Plasma.' + 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: + blockchain: arbitrum, base, ethereum, gnosis, plasma + sector: labels + project: balancer_v3 + contributors: balancerlabs, viniabussafi + config: + tags: ['labels', 'arbitrum', 'base', 'ethereum', 'gnosis', 'plasma', 'balancer', 'pools'] + description: 'Balancer V3 liquidity pools created across blockchains.' + columns: + - *blockchain + - *address + - *name + - *category + - *contributor + - *source + - *created_at + - *updated_at + - *model_name + - *label_type diff --git a/models/_projects/balancer/labels/arbitrum/labels_balancer_v2_pools_arbitrum.sql b/models/_projects/balancer/labels/arbitrum/labels_balancer_v2_pools_arbitrum.sql new file mode 100644 index 0000000..0df9784 --- /dev/null +++ b/models/_projects/balancer/labels/arbitrum/labels_balancer_v2_pools_arbitrum.sql @@ -0,0 +1,304 @@ +{{config( + alias = 'balancer_v2_pools_arbitrum' + , post_hook='{{ hide_spells() }}' +)}} + +WITH pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'WeightedPoolV2Factory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'investment' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'InvestmentPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'WeightedPool2TokensFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'StablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'MetaStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'LiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'ComposableStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'AaveLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_arbitrum', 'ERC4626LinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_arbitrum', 'GyroECLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) +/* + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_arbitrum', 'Gyro2CLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) +*/ + UNION ALL + + SELECT + cc.output_balancerPoolId AS pool_id, + _baseToken AS token_address, + 0 AS normalized_weight, + COALESCE(CONCAT('LP-', t.symbol), '?') AS name, + 'FX' AS pool_type + FROM {{ source('xavefinance_arbitrum', 'FXPoolDeployer_call_newFXPool') }} cc + LEFT JOIN {{ source('tokens', 'erc20') }} t ON cc._baseToken = t.contract_address + AND blockchain = 'arbitrum' + WHERE call_success +), + +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', 'linear', 'LBP', 'ECLP', 'FX') + 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_v2_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP'2022-12-23 00:00' AS created_at, + now() AS updated_at, + 'balancer_v2_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 diff --git a/models/_projects/balancer/labels/arbitrum/labels_balancer_v3_pools_arbitrum.sql b/models/_projects/balancer/labels/arbitrum/labels_balancer_v3_pools_arbitrum.sql new file mode 100644 index 0000000..11a2176 --- /dev/null +++ b/models/_projects/balancer/labels/arbitrum/labels_balancer_v3_pools_arbitrum.sql @@ -0,0 +1,135 @@ +{{config( + alias = 'balancer_v3_pools_arbitrum' + , post_hook='{{ hide_spells() }}' +)}} + +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) + + 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', 'StableSurgePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'LBP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_arbitrum', 'LBPoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_arbitrum', 'GyroECLPPoolFactory_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', 'LBP', 'ECLP') + 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/models/_projects/balancer/labels/avalanche_c/labels_balancer_v2_pools_avalanche_c.sql b/models/_projects/balancer/labels/avalanche_c/labels_balancer_v2_pools_avalanche_c.sql new file mode 100644 index 0000000..15e92e1 --- /dev/null +++ b/models/_projects/balancer/labels/avalanche_c/labels_balancer_v2_pools_avalanche_c.sql @@ -0,0 +1,180 @@ +{{config( + alias = 'balancer_v2_pools_avalanche_c' + , post_hook='{{ hide_spells() }}' +)}} + +WITH pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_avalanche_c', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_avalanche_c', 'NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_avalanche_c', 'ComposableStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_avalanche_c', 'AaveLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_avalanche_c', 'ERC4626LinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + cc.output_0 AS pool_id, + token AS token_address, + 0 AS normalized_weight, + cc._name, + 'FX' AS pool_type + FROM {{ source('xavefinance_avalanche_c', 'FXPoolFactory_call_newFXPool') }} cc + CROSS JOIN UNNEST(_assetsToRegister) AS t (token) + WHERE call_success + + UNION ALL + + SELECT + cc.output_balancerPoolId AS pool_id, + _baseToken AS token_address, + 0 AS normalized_weight, + COALESCE(CONCAT('LP-', t.symbol), '?') AS name, + 'FX' AS pool_type + FROM {{ source('xavefinance_avalanche_c', 'FXPoolDeployer_call_newFXPool') }} cc + LEFT JOIN {{ source('tokens', 'erc20') }} t ON cc._baseToken = t.contract_address + AND blockchain = 'avalanche_c' + WHERE call_success + + UNION ALL + + SELECT + c.poolId AS pool_id, + from_hex(t.tokens) AS token_address, + 0 AS normalized_weight, + json_extract_scalar(params, '$.symbol') AS symbol, + 'managed' AS pool_type + FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_avalanche_c', 'ManagedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_pool + CROSS JOIN UNNEST( + CAST(json_extract(settingsParams, '$.tokens') AS ARRAY(VARCHAR)) + ) AS t (tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_avalanche_c', 'GyroECLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = coalesce(cc.output_0, 0x) + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) +), + +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 = 'avalanche_c' +) + +SELECT + 'avalanche_c' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'FX', 'managed', 'ECLP') + 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_v2_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP'2022-12-23 00:00' AS created_at, + now() AS updated_at, + 'balancer_v2_pools_avalanche_c' 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 diff --git a/models/_projects/balancer/labels/base/labels_balancer_v2_pools_base.sql b/models/_projects/balancer/labels/base/labels_balancer_v2_pools_base.sql new file mode 100644 index 0000000..571ed65 --- /dev/null +++ b/models/_projects/balancer/labels/base/labels_balancer_v2_pools_base.sql @@ -0,0 +1,155 @@ +{{config( + alias = 'balancer_v2_pools_base' + , post_hook='{{ hide_spells() }}' +)}} + +WITH pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_base', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_base', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_base', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_base', 'NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_base', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_base', 'ComposableStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_base', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_base', 'AaveLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_base', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_base', 'ERC4626LinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + from_hex(t.tokens) AS token_address, + 0 AS normalized_weight, + json_extract_scalar(params, '$.symbol') AS symbol, + 'managed' AS pool_type + FROM {{ source('balancer_v2_base', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_base', 'ManagedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_pool + CROSS JOIN UNNEST( + CAST(json_extract(settingsParams, '$.tokens') AS ARRAY(VARCHAR)) + ) AS t (tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_base', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_base', 'GyroECLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) +), + +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 = 'base' +) + +SELECT + 'base' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'managed', 'ECLP') + 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_v2_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP '2023-08-17' AS created_at, + now() AS updated_at, + 'balancer_v2_pools_base' 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 diff --git a/models/_projects/balancer/labels/base/labels_balancer_v3_pools_base.sql b/models/_projects/balancer/labels/base/labels_balancer_v3_pools_base.sql new file mode 100644 index 0000000..04441f6 --- /dev/null +++ b/models/_projects/balancer/labels/base/labels_balancer_v3_pools_base.sql @@ -0,0 +1,135 @@ +{{config( + alias = 'balancer_v3_pools_base' + , post_hook='{{ hide_spells() }}' +)}} + +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_base', '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_base', '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_base', 'StablePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + 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_base', 'StableSurgePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'LBP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_base', 'LBPoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_base', 'GyroECLPPoolFactory_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 = 'base' + ) + +SELECT + 'base' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable', 'LBP', 'ECLP') + 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_base' 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/models/_projects/balancer/labels/ethereum/labels_balancer_v1_pools_ethereum.sql b/models/_projects/balancer/labels/ethereum/labels_balancer_v1_pools_ethereum.sql new file mode 100644 index 0000000..7ff1c1c --- /dev/null +++ b/models/_projects/balancer/labels/ethereum/labels_balancer_v1_pools_ethereum.sql @@ -0,0 +1,92 @@ +{{config( + alias = 'balancer_v1_pools_ethereum', + materialized = 'incremental', + incremental_strategy = 'merge', + unique_key = ['address'] + , post_hook='{{ hide_spells() }}' + ) +}} + +WITH events AS ( + -- binds + SELECT call_block_number AS block_number, + contract_address AS pool, + token, + denorm + FROM {{ source('balancer_v1_ethereum', 'BPool_call_bind') }} + WHERE call_success + {% if is_incremental() %} + AND {{incremental_predicate('call_block_time')}} + {% endif %} + + UNION all + + -- rebinds + SELECT call_block_number AS block_number, + contract_address AS pool, + token, + denorm + FROM {{ source('balancer_v1_ethereum', 'BPool_call_rebind') }} + WHERE call_success + {% if is_incremental() %} + AND {{incremental_predicate('call_block_time')}} + {% endif %} + + UNION all + + -- unbinds + SELECT call_block_number AS block_number, + contract_address AS pool, + token, + uint256 '0' AS denorm + FROM {{ source('balancer_v1_ethereum', 'BPool_call_unbind') }} + WHERE call_success + {% if is_incremental() %} + AND {{incremental_predicate('call_block_time')}} + {% endif %} +), + +state_with_gaps AS ( + SELECT events.block_number + , events.pool + , events.token + , CAST(events.denorm AS uint256) AS denorm, + LEAD(events.block_number, 1, 99999999) OVER (PARTITION BY events.pool, events.token ORDER BY events.block_number) AS next_block_number + FROM events +), + +settings AS ( + SELECT pool, + coalesce(t.symbol,'?') AS symbol, + denorm, + next_block_number + FROM state_with_gaps s + LEFT JOIN {{ source('tokens_ethereum', 'erc20') }} t ON s.token = t.contract_address + WHERE next_block_number = 99999999 + AND denorm > uint256 '0' +), + +final AS ( + SELECT + 'ethereum' AS blockchain, + pool AS address, + lower(concat(array_join(array_agg(symbol), '/'), ' ', array_join(array_agg(cast(norm_weight AS varchar)), '/'))) AS name, + 'balancer_v1_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + timestamp '2023-02-02' AS created_at, + now() AS updated_at, + 'balancer_v1_pools_ethereum' AS model_name, + 'identifier' as label_type + FROM ( + SELECT s1.pool, symbol, cast(100*denorm/total_denorm AS integer) AS norm_weight FROM settings s1 + INNER JOIN (SELECT pool, sum(denorm) AS total_denorm FROM settings GROUP BY pool) s2 + ON s1.pool = s2.pool + ORDER BY 1 ASC , 3 DESC, 2 ASC + ) s + + GROUP BY 1, 2 +) +SELECT * +FROM final +WHERE length(name) < 35 \ No newline at end of file diff --git a/models/_projects/balancer/labels/ethereum/labels_balancer_v2_pools_ethereum.sql b/models/_projects/balancer/labels/ethereum/labels_balancer_v2_pools_ethereum.sql new file mode 100644 index 0000000..1d00619 --- /dev/null +++ b/models/_projects/balancer/labels/ethereum/labels_balancer_v2_pools_ethereum.sql @@ -0,0 +1,304 @@ +{{config( + alias = 'balancer_v2_pools_ethereum' + , post_hook='{{ hide_spells() }}' +)}} + +WITH pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'WeightedPoolV2Factory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'WeightedPool2TokensFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'investment' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'InvestmentPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'StablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'MetaStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'LiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'StablePhantomPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'ComposableStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_ethereum', 'AaveLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_ethereum', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_ethereum', 'GyroECLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + cc.output_0 AS pool_id, + token AS token_address, + 0 AS normalized_weight, + cc._name, + 'FX' AS pool_type + FROM {{ source('xavefinance_ethereum', 'FXPoolFactory_call_newFXPool') }} cc + CROSS JOIN UNNEST(_assetsToRegister) AS t (token) + WHERE call_success + + UNION ALL + + SELECT + cc.output_balancerPoolId AS pool_id, + _baseToken AS token_address, + 0 AS normalized_weight, + COALESCE(CONCAT('LP-', t.symbol), '?') AS name, + 'FX' AS pool_type + FROM {{ source('xavefinance_ethereum', 'FXPoolDeployer_call_newFXPool') }} cc + LEFT JOIN {{ source('tokens', 'erc20') }} t ON cc._baseToken = t.contract_address + AND blockchain = 'ethereum' + WHERE call_success +), + +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', 'linear', 'LBP', 'ECLP', 'FX') + 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_v2_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP'2022-12-23 00:00' AS created_at, + now() AS updated_at, + 'balancer_v2_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 diff --git a/models/_projects/balancer/labels/ethereum/labels_balancer_v3_pools_ethereum.sql b/models/_projects/balancer/labels/ethereum/labels_balancer_v3_pools_ethereum.sql new file mode 100644 index 0000000..203c0ef --- /dev/null +++ b/models/_projects/balancer/labels/ethereum/labels_balancer_v3_pools_ethereum.sql @@ -0,0 +1,135 @@ +{{config( + alias = 'balancer_v3_pools_ethereum' + , post_hook='{{ hide_spells() }}' +)}} + +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) + + 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', 'StableSurgePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'LBP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_ethereum', 'LBPoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_ethereum', 'GyroECLPPoolFactory_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', 'LBP', 'ECLP') + 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/models/_projects/balancer/labels/gnosis/labels_balancer_v2_pools_gnosis.sql b/models/_projects/balancer/labels/gnosis/labels_balancer_v2_pools_gnosis.sql new file mode 100644 index 0000000..977a40d --- /dev/null +++ b/models/_projects/balancer/labels/gnosis/labels_balancer_v2_pools_gnosis.sql @@ -0,0 +1,221 @@ +{{config( + alias = 'balancer_v2_pools_gnosis' + , post_hook='{{ hide_spells() }}' +)}} + +WITH pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'WeightedPoolV2Factory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'WeightedPoolV4Factory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'StablePoolV2Factory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'ComposableStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'AaveLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'AaveLinearPoolV3Factory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'AaveLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'ComposableStablePoolV2Factory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + from_hex(t.tokens) AS token_address, + 0 AS normalized_weight, + json_extract_scalar(params, '$.symbol') AS symbol, + 'managed' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_gnosis', 'ManagedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_pool + CROSS JOIN UNNEST( + CAST(json_extract(settingsParams, '$.tokens') AS ARRAY(VARCHAR)) + ) AS t (tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_gnosis', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_gnosis', 'GyroECLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) +), + +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 = 'gnosis' +) + +SELECT + 'gnosis' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'ECLP', 'FX', 'managed') + 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_v2_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP'2022-12-23 00:00' AS created_at, + now() AS updated_at, + 'balancer_v2_pools_gnosis' 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 diff --git a/models/_projects/balancer/labels/gnosis/labels_balancer_v3_pools_gnosis.sql b/models/_projects/balancer/labels/gnosis/labels_balancer_v3_pools_gnosis.sql new file mode 100644 index 0000000..20f76e9 --- /dev/null +++ b/models/_projects/balancer/labels/gnosis/labels_balancer_v3_pools_gnosis.sql @@ -0,0 +1,135 @@ +{{config( + alias = 'balancer_v3_pools_gnosis' + , post_hook='{{ hide_spells() }}' +)}} + +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_gnosis', '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_gnosis', '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_gnosis', 'StablePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + 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_gnosis', 'StableSurgePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'LBP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_gnosis', 'LBPoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_gnosis', 'GyroECLPPoolFactory_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 = 'gnosis' + ) + +SELECT + 'gnosis' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable', 'LBP', 'ECLP') + 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_gnosis' 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 diff --git a/models/_projects/balancer/labels/labels_balancer_v1_pools.sql b/models/_projects/balancer/labels/labels_balancer_v1_pools.sql new file mode 100644 index 0000000..271e9e0 --- /dev/null +++ b/models/_projects/balancer/labels/labels_balancer_v1_pools.sql @@ -0,0 +1,7 @@ +{{config( + alias = 'labels_balancer_v1_pools' + , post_hook='{{ hide_spells() }}' + ) +}} + +SELECT * FROM {{ ref('labels_balancer_v1_pools_ethereum') }} \ No newline at end of file diff --git a/models/_projects/balancer/labels/labels_balancer_v2_pools.sql b/models/_projects/balancer/labels/labels_balancer_v2_pools.sql new file mode 100644 index 0000000..39ed23a --- /dev/null +++ b/models/_projects/balancer/labels/labels_balancer_v2_pools.sql @@ -0,0 +1,21 @@ +{{config( + alias = 'balancer_v2_pools' + , post_hook='{{ hide_spells() }}' + ) +}} + +SELECT * FROM {{ ref('labels_balancer_v2_pools_ethereum') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v2_pools_arbitrum') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v2_pools_optimism') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v2_pools_polygon') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v2_pools_gnosis') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v2_pools_avalanche_c') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v2_pools_base') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v2_pools_zkevm') }} \ No newline at end of file diff --git a/models/_projects/balancer/labels/labels_balancer_v3_pools.sql b/models/_projects/balancer/labels/labels_balancer_v3_pools.sql new file mode 100644 index 0000000..b4da0c9 --- /dev/null +++ b/models/_projects/balancer/labels/labels_balancer_v3_pools.sql @@ -0,0 +1,15 @@ +{{config( + alias = 'balancer_v3_pools' + , post_hook='{{ hide_spells() }}' + ) +}} + +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') }} +UNION +SELECT * FROM {{ ref('labels_balancer_v3_pools_plasma') }} diff --git a/models/_projects/balancer/labels/optimism/labels_balancer_v2_pools_optimism.sql b/models/_projects/balancer/labels/optimism/labels_balancer_v2_pools_optimism.sql new file mode 100644 index 0000000..5f548ac --- /dev/null +++ b/models/_projects/balancer/labels/optimism/labels_balancer_v2_pools_optimism.sql @@ -0,0 +1,225 @@ +{{config( + alias = 'balancer_v2_pools_optimism' + , post_hook='{{ hide_spells() }}' +)}} + +WITH pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_optimism', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_optimism', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_optimism', 'WeightedPoolV2Factory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_optimism', 'WeightedPool2TokensFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_optimism', 'StablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_optimism', 'MetaStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_optimism', 'NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_optimism', 'ComposableStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_optimism', 'AaveLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_optimism', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_optimism', 'GyroECLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens_array_binary) AS t(tokens) +), + +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 = 'optimism' +) + +SELECT + 'optimism' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'ECLP') + 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_v2_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP'2022-12-23 00:00' AS created_at, + now() AS updated_at, + 'balancer_v2_pools_optimism' 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 diff --git a/models/_projects/balancer/labels/plasma/labels_balancer_v3_pools_plasma.sql b/models/_projects/balancer/labels/plasma/labels_balancer_v3_pools_plasma.sql new file mode 100644 index 0000000..4013ce1 --- /dev/null +++ b/models/_projects/balancer/labels/plasma/labels_balancer_v3_pools_plasma.sql @@ -0,0 +1,148 @@ +{{config( + alias = 'balancer_v3_pools_plasma' + , post_hook='{{ hide_spells() }}' +)}} + +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_plasma', '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_plasma', '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, + 'reclamm' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_plasma', 'ReclammPoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + 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_plasma', 'StablePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + 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_plasma', 'StableSurgePoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'LBP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_plasma', 'LBPoolFactory_call_create') }} cc + ON c.pool = cc.output_pool + CROSS JOIN UNNEST(c.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.pool AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM token_data c + INNER JOIN {{ source('balancer_v3_plasma', 'GyroECLPPoolFactory_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 = 'plasma' + ) + +SELECT + 'plasma' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable', 'LBP', 'ECLP') + 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_plasma' 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/models/_projects/balancer/labels/polygon/labels_balancer_v2_pools_polygon.sql b/models/_projects/balancer/labels/polygon/labels_balancer_v2_pools_polygon.sql new file mode 100644 index 0000000..57f97dd --- /dev/null +++ b/models/_projects/balancer/labels/polygon/labels_balancer_v2_pools_polygon.sql @@ -0,0 +1,302 @@ +{{config( + alias = 'balancer_v2_pools_polygon' + , post_hook='{{ hide_spells() }}' +)}} + +WITH pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'WeightedPoolV2Factory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'WeightedPool2TokensFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'investment' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'InvestmentPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.weights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens, + 0 AS weights, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'StablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'MetaStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'LiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'ComposableStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'StablePhantomPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_polygon', 'AaveLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_polygon', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_polygon', 'GyroECLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + cc.output_0 AS pool_id, + token AS token_address, + 0 AS normalized_weight, + cc._name, + 'FX' AS pool_type + FROM {{ source('xavefinance_polygon', 'FXPoolFactory_call_newFXPool') }} cc + CROSS JOIN UNNEST(_assetsToRegister) AS t (token) + WHERE call_success + + UNION ALL + + SELECT + cc.output_balancerPoolId AS pool_id, + _baseToken AS token_address, + 0 AS normalized_weight, + COALESCE(CONCAT('LP-', t.symbol), '?') AS name, + 'FX' AS pool_type + FROM {{ source('xavefinance_avalanche_c', 'FXPoolDeployer_call_newFXPool') }} cc + LEFT JOIN {{ source('tokens', 'erc20') }} t ON cc._baseToken = t.contract_address + AND blockchain = 'avalanche_c' + WHERE call_success +), + +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 = 'polygon' +) + +SELECT + 'polygon' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'ECLP', 'FX') + 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_v2_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP'2022-12-23 00:00' AS created_at, + now() AS updated_at, + 'balancer_v2_pools_polygon' 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 diff --git a/models/_projects/balancer/labels/zkevm/labels_balancer_v2_pools_zkevm.sql b/models/_projects/balancer/labels/zkevm/labels_balancer_v2_pools_zkevm.sql new file mode 100644 index 0000000..fc078bc --- /dev/null +++ b/models/_projects/balancer/labels/zkevm/labels_balancer_v2_pools_zkevm.sql @@ -0,0 +1,183 @@ +{{config( + alias = 'balancer_v2_pools_zkevm' + , post_hook='{{ hide_spells() }}' +)}} + +WITH pools AS ( + SELECT + pool_id, + zip.tokens AS token_address, + zip.weights / pow(10, 18) AS normalized_weight, + symbol, + pool_type + FROM ( + SELECT + c.poolId AS pool_id, + t.tokens, + w.weights, + cc.symbol, + 'weighted' AS pool_type + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_zkevm', 'WeightedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) WITH ORDINALITY t(tokens, pos) + CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) + WHERE t.pos = w.pos + ) zip + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'LBP' AS pool_type + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_zkevm', 'NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'stable' AS pool_type + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_zkevm', 'ComposableStablePoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_zkevm', 'AaveLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_zkevm', 'YearnLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_zkevm', 'GearboxLinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + element AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'linear' AS pool_type + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_zkevm', 'ERC4626LinearPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(ARRAY[cc.mainToken, cc.wrappedToken]) AS t (element) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_zkevm', 'GyroECLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + from_hex(t.tokens) AS token_address, + 0 AS normalized_weight, + json_extract_scalar(params, '$.symbol') AS symbol, + 'managed' AS pool_type + FROM {{ source('balancer_v2_zkevm', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('balancer_v2_zkevm', 'ManagedPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_pool + CROSS JOIN UNNEST( + CAST(json_extract(settingsParams, '$.tokens') AS ARRAY(VARCHAR)) + ) AS t (tokens) +), + +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 = 'zkevm' +) + +SELECT + 'zkevm' AS blockchain, + bytearray_substring(pool_id, 1, 20) AS address, + CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'ECLP', 'FX', 'managed') + 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_v2_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + TIMESTAMP'2022-12-23 00:00' AS created_at, + now() AS updated_at, + 'balancer_v2_pools_zkevm' 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 diff --git a/profiles.yml b/profiles.yml index 8cdb520..0995ff3 100644 --- a/profiles.yml +++ b/profiles.yml @@ -1,18 +1,18 @@ # dbt profile for Dune API connection +# See: https://github.com/duneanalytics/dune-dbt-template +# Dune uses LDAP auth (not JWT): user is always 'dune', API key goes in password balancer: target: dev outputs: dev: type: trino + method: ldap user: dune # do not change: user is always 'dune' password: "{{ env_var('DUNE_API_KEY') }}" host: trino.api.dune.com port: 443 - method: ldap catalog: dune # do not change: catalog is always 'dune' - # schema: REQUIRED - Set DUNE_TEAM_NAME in .env to your team name - # Default is 'dune' if not set. To hardcode, replace: env_var('DUNE_TEAM_NAME', 'your_team') - schema: "{{ env_var('DUNE_TEAM_NAME', 'dune') }}" + schema: "{{ env_var('DUNE_TEAM_NAME') }}__tmp_{{ env_var('DEV_SCHEMA_SUFFIX', '') }}" threads: 4 http_scheme: https cert: true @@ -21,15 +21,13 @@ balancer: timezone: UTC prod: type: trino + method: ldap user: dune # do not change: user is always 'dune' password: "{{ env_var('DUNE_API_KEY') }}" host: trino.api.dune.com port: 443 - method: ldap catalog: dune # do not change: catalog is always 'dune' - # schema: REQUIRED - Set DUNE_TEAM_NAME in .env to your team name - # Default is 'dune' if not set. To hardcode, replace: env_var('DUNE_TEAM_NAME', 'your_team') - schema: "{{ env_var('DUNE_TEAM_NAME', 'dune') }}" + schema: "{{ env_var('DUNE_TEAM_NAME') }}" threads: 4 http_scheme: https cert: true diff --git a/sources/balancer/arbitrum/balancer_arbitrum_sources.yml b/sources/balancer/arbitrum/balancer_arbitrum_sources.yml new file mode 100644 index 0000000..311a790 --- /dev/null +++ b/sources/balancer/arbitrum/balancer_arbitrum_sources.yml @@ -0,0 +1,235 @@ +version: 2 + +sources: + - name: balancer_v2_arbitrum + description: > + Decoded tables related to Balancer V2, an automated portfolio manager and trading platform, on Arbitrum. + tables: + - name: Vault_evt_PoolRegistered + description: > + Decoded table of registered pools on the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - &evt_tx_hash + name: evt_tx_hash + description: 'Primary key of the transaction' + - &evt_index + name: evt_index + description: 'Index value of the transaction' + - &evt_block_time + name: evt_block_time + description: 'Timestamp for block event time in UTC' + - &evt_block_number + name: evt_block_number + description: 'Block number which processed the unique transaction hash' + - name: poolAddress + description: 'Arbitrum address for the liquidity pool used in transaction' + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - name: specialization + description: 'Pool specialization' + + - name: WeightedPoolFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPoolFactory contract. + columns: + - &call_block_number + name: call_block_number + description: 'Block number which processed the unique transaction hash' + - &call_block_time + name: call_block_time + description: 'Timestamp for block time in which the call occurred in UTC' + - &call_success + name: call_success + description: 'Boolean indicating if call was successfully processed' + - &call_trace_address + name: call_trace_address + description: '' + - &call_tx_hash + name: call_tx_hash + description: 'Primary key of the transaction' + - name: contract_address + description: 'Address of the WeightedPoolFactory contract' + - name: name + description: 'Name of the created pool' + - &output_0 + name: output_0 + description: 'Contract address of the created pool' + - &owner + name: owner + description: 'Contract of the pool owner' + - &swapFeePercentage + name: swapFeePercentage + description: 'Pool swap fee in percentage' + - &symbol + name: symbol + description: 'Symbol of the created pool' + - &tokens + name: tokens + description: 'Array with the address of the created pool tokens' + - &weights + name: weights + description: 'Array with the weight of each token in the created pool' + + - name: WeightedPool2TokensFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPool2TokensFactory contract' + - name: name + description: 'Name of the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + - *weights + + - name: WeightedPoolV2Factory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPoolV2Factory contract' + - name: name + description: 'Name of the created pool' + - name: normalizedWeights + description: 'Array with the normalized weight of each token in the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + + - name: Vault_evt_PoolBalanceChanged + description: > + Decoded table of pool balances changes record on the Balancer Vault contract on Arbitrum. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: tokens + description: 'Contract address of each token of the pool' + - name: deltas + description: 'Balance changes of each token of the pool' + - name: liquidityProvider + description: 'Address of the wallet which provided or removed liquidity from the pool' + - name: protocolFeeAmounts + description: 'Amount of fee paid of each token of the pool during the transaction' + + - name: Vault_evt_PoolBalanceManaged + description: > + Decoded table of transactions performed by asset managers on the Balancer Vault contract on Arbitrum. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: token + description: 'Contract address of token managed' + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + - name: managedDelta + description: 'Change in the amount of token managed by the asset manager' + - name: cashDelta + description: 'Change in the amount of token cashed the vault' + + - name: Vault_evt_FlashLoan + + - name: ComposableStablePoolFactory_evt_PoolCreated + description: > + Decoded table of Composable Stable Pools created by the Composable Stable Pool Factory contract. + columns: + - name: contract_address + description: 'Balancer v2 Composable Stable Pool Factory contract address.' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: pool + description: 'Ethereum address for the Composable Stable Pool created in the transaction.' + + - name: Vault_evt_TokensRegistered + description: > + Decoded table of tokens registered by pool with the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - *tokens + - 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: StableSurgePoolFactory_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 + + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + + - name: LBPoolFactory_call_create + + - name: LBPoolFactory_evt_LBPoolCreated + + - name: LBPool_evt_GradualWeightUpdateScheduled + + - name: GyroECLPPoolFactory_call_create diff --git a/sources/balancer/avalanche_c/balancer_avalanche_c_sources.yml b/sources/balancer/avalanche_c/balancer_avalanche_c_sources.yml new file mode 100644 index 0000000..2c92bd4 --- /dev/null +++ b/sources/balancer/avalanche_c/balancer_avalanche_c_sources.yml @@ -0,0 +1,146 @@ +version: 2 + +sources: + - name: balancer_v2_avalanche_c + description: > + Decoded tables related to Balancer V2, an automated portfolio manager and trading platform, on avalanche_c. + tables: + - name: Vault_evt_PoolRegistered + description: > + Decoded table of registered pools on the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - &evt_tx_hash + name: evt_tx_hash + description: 'Primary key of the transaction' + - &evt_index + name: evt_index + description: 'Index value of the transaction' + - &evt_block_time + name: evt_block_time + description: 'Timestamp for block event time in UTC' + - &evt_block_number + name: evt_block_number + description: 'Block number which processed the unique transaction hash' + - name: poolAddress + description: 'avalanche_c address for the liquidity pool used in transaction' + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - name: specialization + description: 'Pool specialization' + + - name: WeightedPoolFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPoolFactory contract. + columns: + - &call_block_number + name: call_block_number + description: 'Block number which processed the unique transaction hash' + - &call_block_time + name: call_block_time + description: 'Timestamp for block time in which the call occurred in UTC' + - &call_success + name: call_success + description: 'Boolean indicating if call was successfully processed' + - &call_trace_address + name: call_trace_address + description: '' + - &call_tx_hash + name: call_tx_hash + description: 'Primary key of the transaction' + - name: contract_address + description: 'Address of the WeightedPoolFactory contract' + - name: name + description: 'Name of the created pool' + - &output_0 + name: output_0 + description: 'Contract address of the created pool' + - &owner + name: owner + description: 'Contract of the pool owner' + - &swapFeePercentage + name: swapFeePercentage + description: 'Pool swap fee in percentage' + - &symbol + name: symbol + description: 'Symbol of the created pool' + - &tokens + name: tokens + description: 'Array with the address of the created pool tokens' + - &weights + name: weights + description: 'Array with the weight of each token in the created pool' + + - name: Vault_evt_PoolBalanceChanged + description: > + Decoded table of pool balances changes record on the Balancer Vault contract on avalanche_c. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: tokens + description: 'Contract address of each token of the pool' + - name: deltas + description: 'Balance changes of each token of the pool' + - name: liquidityProvider + description: 'Address of the wallet which provided or removed liquidity from the pool' + - name: protocolFeeAmounts + description: 'Amount of fee paid of each token of the pool during the transaction' + + - name: Vault_evt_PoolBalanceManaged + description: > + Decoded table of transactions performed by asset managers on the Balancer Vault contract on avalanche_c. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: token + description: 'Contract address of token managed' + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + - name: managedDelta + description: 'Change in the amount of token managed by the asset manager' + - name: cashDelta + description: 'Change in the amount of token cashed the vault' + + - name: Vault_evt_FlashLoan + + - name: ComposableStablePoolFactory_evt_PoolCreated + description: > + Decoded table of Composable Stable Pools created by the Composable Stable Pool Factory contract. + columns: + - name: contract_address + description: 'Balancer v2 Composable Stable Pool Factory contract address.' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: pool + description: 'Ethereum address for the Composable Stable Pool created in the transaction.' + + - name: Vault_evt_TokensRegistered + description: > + Decoded table of tokens registered by pool with the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - *tokens + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' diff --git a/sources/balancer/base/balancer_base_sources.yml b/sources/balancer/base/balancer_base_sources.yml new file mode 100644 index 0000000..2434c37 --- /dev/null +++ b/sources/balancer/base/balancer_base_sources.yml @@ -0,0 +1,194 @@ +version: 2 + +sources: + - name: balancer_v2_base + description: > + Decoded tables related to Balancer V2, an automated portfolio manager and trading platform, on base. + tables: + - name: Vault_evt_PoolRegistered + description: > + Decoded table of registered pools on the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - &evt_tx_hash + name: evt_tx_hash + description: 'Primary key of the transaction' + - &evt_index + name: evt_index + description: 'Index value of the transaction' + - &evt_block_time + name: evt_block_time + description: 'Timestamp for block event time in UTC' + - &evt_block_number + name: evt_block_number + description: 'Block number which processed the unique transaction hash' + - name: poolAddress + description: 'Base address for the liquidity pool used in transaction' + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - name: specialization + description: 'Pool specialization' + + - name: WeightedPoolFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPoolFactory contract. + columns: + - &call_block_number + name: call_block_number + description: 'Block number which processed the unique transaction hash' + - &call_block_time + name: call_block_time + description: 'Timestamp for block time in which the call occurred in UTC' + - &call_success + name: call_success + description: 'Boolean indicating if call was successfully processed' + - &call_trace_address + name: call_trace_address + description: '' + - &call_tx_hash + name: call_tx_hash + description: 'Primary key of the transaction' + - name: contract_address + description: 'Address of the WeightedPoolFactory contract' + - name: name + description: 'Name of the created pool' + - &output_0 + name: output_0 + description: 'Contract address of the created pool' + - &owner + name: owner + description: 'Contract of the pool owner' + - &swapFeePercentage + name: swapFeePercentage + description: 'Pool swap fee in percentage' + - &symbol + name: symbol + description: 'Symbol of the created pool' + - &tokens + name: tokens + description: 'Array with the address of the created pool tokens' + - &weights + name: weights + description: 'Array with the weight of each token in the created pool' + + - name: Vault_evt_PoolBalanceChanged + description: > + Decoded table of pool balances changes record on the Balancer Vault contract on base. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: tokens + description: 'Contract address of each token of the pool' + - name: deltas + description: 'Balance changes of each token of the pool' + - name: liquidityProvider + description: 'Address of the wallet which provided or removed liquidity from the pool' + - name: protocolFeeAmounts + description: 'Amount of fee paid of each token of the pool during the transaction' + + - name: Vault_evt_PoolBalanceManaged + description: > + Decoded table of transactions performed by asset managers on the Balancer Vault contract on base. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: token + description: 'Contract address of token managed' + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + - name: managedDelta + description: 'Change in the amount of token managed by the asset manager' + - name: cashDelta + description: 'Change in the amount of token cashed the vault' + + - name: Vault_evt_FlashLoan + + - name: ComposableStablePoolFactory_evt_PoolCreated + description: > + Decoded table of Composable Stable Pools created by the Composable Stable Pool Factory contract. + columns: + - name: contract_address + description: 'Balancer v2 Composable Stable Pool Factory contract address.' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: pool + description: 'Ethereum address for the Composable Stable Pool created in the transaction.' + + - name: Vault_evt_TokensRegistered + description: > + Decoded table of tokens registered by pool with the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - *tokens + - 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: StableSurgePoolFactory_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 + + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + + - name: LBPoolFactory_call_create + + - name: LBPoolFactory_evt_LBPoolCreated + + - name: LBPool_evt_GradualWeightUpdateScheduled + + - name: GyroECLPPoolFactory_call_create diff --git a/sources/balancer/ethereum/balancer_ethereum_sources.yml b/sources/balancer/ethereum/balancer_ethereum_sources.yml new file mode 100644 index 0000000..70c729f --- /dev/null +++ b/sources/balancer/ethereum/balancer_ethereum_sources.yml @@ -0,0 +1,402 @@ +version: 2 + +sources: + - name: balancer_v2_ethereum + description: > + Decoded tables related to Balancer v2, an automated portfolio manager and trading platform, on Ethereum. + tables: + - name: Vault_evt_PoolRegistered + description: > + Decoded table of registered pools on the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - &evt_tx_hash + name: evt_tx_hash + description: 'Primary key of the transaction' + - &evt_index + name: evt_index + description: 'Index value of the transaction' + - &evt_block_time + name: evt_block_time + description: 'Timestamp for block event time in UTC' + - &evt_block_number + name: evt_block_number + description: 'Block number which processed the unique transaction hash' + - name: poolAddress + description: 'Ethereum address for the liquidity pool used in transaction' + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - name: specialization + description: 'Pool specialization' + + - name: WeightedPoolFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPoolFactory contract. + columns: + - &call_block_number + name: call_block_number + description: 'Block number which processed the unique transaction hash' + - &call_block_time + name: call_block_time + description: 'Timestamp for block time in which the call occurred in UTC' + - &call_success + name: call_success + description: 'Boolean indicating if call was successfully processed' + - &call_trace_address + name: call_trace_address + description: '' + - &call_tx_hash + name: call_tx_hash + description: 'Primary key of the transaction' + - name: contract_address + description: 'Address of the WeightedPoolFactory contract' + - name: name + description: 'Name of the created pool' + - &output_0 + name: output_0 + description: 'Contract address of the created pool' + - &owner + name: owner + description: 'Contract of the pool owner' + - &swapFeePercentage + name: swapFeePercentage + description: 'Pool swap fee in percentage' + - &symbol + name: symbol + description: 'Symbol of the created pool' + - &tokens + name: tokens + description: 'Array with the address of the created pool tokens' + - &weights + name: weights + description: 'Array with the weight of each token in the created pool' + + - name: WeightedPool2TokensFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPool2TokensFactory contract' + - name: name + description: 'Name of the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + - *weights + + - name: WeightedPoolV2Factory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPoolV2Factory contract' + - name: name + description: 'Name of the created pool' + - name: normalizedWeights + description: 'Array with the normalized weight of each token in the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + + - name: Vault_evt_PoolBalanceChanged + description: > + Decoded table of pool balances changes record on the Balancer Vault contract on Ethereum. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: tokens + description: 'Contract address of each token of the pool' + - name: deltas + description: 'Balance changes of each token of the pool' + - name: liquidityProvider + description: 'Address of the wallet which provided or removed liquidity from the pool' + - name: protocolFeeAmounts + description: 'Amount of fee paid of each token of the pool during the transaction' + + - name: Vault_evt_PoolBalanceManaged + description: > + Decoded table of transactions performed by asset managers on the Balancer Vault contract on Ethereum. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: token + description: 'Contract address of token managed' + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + - name: managedDelta + description: 'Change in the amount of token managed by the asset manager' + - name: cashDelta + description: 'Change in the amount of token cashed the vault' + + - name: LiquidityBootstrappingPool_evt_GradualWeightUpdateScheduled + description: > + Decoded table related to scheduled gradual weight updates on the Balancer LiquidityBootstrappingPool contract. + columns: + - name: contract_address + description: 'LBP contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - &endTime + name: endTime + description: 'Unix timestamp of the LBP end time' + - &endWeights + name: endWeights + description: 'Array with the weights of the LBP tokens at the end of the LBP' + - &startTime + name: startTime + description: 'Unix timestamp of the LBP start time' + - &startWeights + name: startWeights + description: 'Array with the weights of the LBP tokens at the start of the LBP' + + - name: NoProtocolFeeLiquidityBootstrappingPool_evt_GradualWeightUpdateScheduled + description: > + Decoded table related to scheduled gradual weight updates on the Balancer NoProtocolFeeLiquidityBootstrappingPool contract. + columns: + - name: contract_address + description: 'LBP contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - *endTime + - *endWeights + - *startTime + - *startWeights + + - name: Vault_evt_FlashLoan + + - name: ComposableStablePoolFactory_evt_PoolCreated + description: > + Decoded table of Composable Stable Pools created by the Composable Stable Pool Factory contract. + columns: + - name: contract_address + description: 'Balancer v2 Composable Stable Pool Factory contract address.' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: pool + description: 'Ethereum address for the Composable Stable Pool created in the transaction.' + + - name: Vault_evt_TokensRegistered + description: > + Decoded table of tokens registered by pool with the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - *tokens + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + + - name: balancer_v1_ethereum + description: > + Decoded tables related to Balancer V1, an automated portfolio manager and trading platform, on Ethereum. + tables: + - name: BFactory_evt_LOG_NEW_POOL + description: > + Decoded table related to the Balancer BFactory contract. + columns: + - name: contract_address + description: 'Balancer v1 BFactory contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: caller + description: 'Caller address that created the Balancer pool' + - name: pool + description: 'Balancer pool contract address' + + - name: BPool_call_bind + description: > + Decoded table related to the Balancer BPool contract. + columns: + - &balance + name: balance + description: '' + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: '' + - &denorm + name: denorm + description: '' + - &token + name: token + description: '' + + - name: BPool_call_rebind + description: > + Decoded table related to the Balancer BPool contract. + columns: + - *balance + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: '' + - *denorm + - *token + + - name: BPool_call_unbind + description: > + Decoded table related to the Balancer BPool contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: '' + - *token + + - name: balancer_ethereum + description: > + Decoded tables related to Balancer, an automated portfolio manager and trading platform, on Ethereum. + tables: + - name: veBAL_call_create_lock + description: "Function to create a veBAL lock" + columns: + - name: _unlock_time + description: "Epoch time when tokens unlock; this is the user's request, but the actual unlock time will be rounded down to a Thursday" + - name: _value + description: "Amount to deposit" + + - name: veBAL_evt_Deposit + description: "Emitted when user deposits tokens in their lock or extends its unlock time" + columns: + - name: locktime + description: "Epoch time when tokens unlock" + - name: provider + description: "The wallet address of the lock's owner" + - name: ts + description: "Block timestamp" + - name: type + data_tests: + - accepted_values: + values: [0, 1, 2, 3] + description: > + DEPOSIT_FOR_TYPE: 0 + CREATE_LOCK_TYPE: 1 + INCREASE_LOCK_AMOUNT: 2 + INCREASE_UNLOCK_TIME: 3 + - name: value + description: "Amount of base tokens added to the lock" + + - name: veBAL_evt_Withdraw + description: "Emitted when user withdraws tokens from their lock" + columns: + - name: provider + description: "The wallet address of the lock's owner" + - name: value + description: "Amount of base tokens withdrawn from the lock" + - name: ts + description: "Block timestamp" + + - name: GaugeController_evt_VoteForGauge + description: "Emitted when veBAL holder votes for a gauge" + columns: + - name: contract_address + description: "Gauge controller address" + - *evt_block_number + - *evt_block_time + - *evt_index + - *evt_tx_hash + - name: gauge_addr + description: "Address of the gauge which user votes for" + - name: time + description: "Epoch timestamp at which the event occurred" + - name: user + description: "veBAL holder that voted for the gauge" + - name: weight + description: "Weight of the user for the gauge" + + - name: balancer_v3_ethereum + description: > + Decoded tables related to Balancer V3, an automated portfolio manager and trading platform, on Ethereum. + 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: StableSurgePoolFactory_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 + + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + + - name: LBPoolFactory_call_create + + - name: LBPoolFactory_evt_LBPoolCreated + + - name: LBPool_evt_GradualWeightUpdateScheduled + + - name: GyroECLPPoolFactory_call_create diff --git a/sources/balancer/gnosis/balancer_gnosis_sources.yml b/sources/balancer/gnosis/balancer_gnosis_sources.yml new file mode 100644 index 0000000..8db6a27 --- /dev/null +++ b/sources/balancer/gnosis/balancer_gnosis_sources.yml @@ -0,0 +1,294 @@ +version: 2 + +sources: + - name: balancer_v2_gnosis + description: > + Decoded tables related to Balancer V2, an automated portfolio manager and trading platform, on Gnosis. + tables: + - name: Vault_evt_PoolRegistered + description: > + Decoded table of registered pools on the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - &evt_tx_hash + name: evt_tx_hash + description: 'Primary key of the transaction' + - &evt_index + name: evt_index + description: 'Index value of the transaction' + - &evt_block_time + name: evt_block_time + description: 'Timestamp for block event time in UTC' + - &evt_block_number + name: evt_block_number + description: 'Block number which processed the unique transaction hash' + - name: poolAddress + description: 'gnosis address for the liquidity pool used in transaction' + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - name: specialization + description: 'Pool specialization' + + - name: WeightedPoolFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPoolFactory contract. + columns: + - &call_block_number + name: call_block_number + description: 'Block number which processed the unique transaction hash' + - &call_block_time + name: call_block_time + description: 'Timestamp for block time in which the call occurred in UTC' + - &call_success + name: call_success + description: 'Boolean indicating if call was successfully processed' + - &call_trace_address + name: call_trace_address + description: '' + - &call_tx_hash + name: call_tx_hash + description: 'Primary key of the transaction' + - name: contract_address + description: 'Address of the WeightedPoolFactory contract' + - name: name + description: 'Name of the created pool' + - &output_0 + name: output_0 + description: 'Contract address of the created pool' + - &owner + name: owner + description: 'Contract of the pool owner' + - &swapFeePercentage + name: swapFeePercentage + description: 'Pool swap fee in percentage' + - &symbol + name: symbol + description: 'Symbol of the created pool' + - &tokens + name: tokens + description: 'Array with the address of the created pool tokens' + - &weights + name: weights + description: 'Array with the weight of each token in the created pool' + + - name: WeightedPool2TokensFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPool2TokensFactory contract' + - name: name + description: 'Name of the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + - *weights + + - name: WeightedPoolV2Factory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPoolV2Factory contract' + - name: name + description: 'Name of the created pool' + - name: normalizedWeights + description: 'Array with the normalized weight of each token in the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + + - name: WeightedPoolV4Factory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPoolV2Factory contract' + - name: name + description: 'Name of the created pool' + - name: normalizedWeights + description: 'Array with the normalized weight of each token in the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + + - name: Vault_evt_PoolBalanceChanged + description: > + Decoded table of pool balances changes record on the Balancer Vault contract on gnosis. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: tokens + description: 'Contract address of each token of the pool' + - name: deltas + description: 'Balance changes of each token of the pool' + - name: liquidityProvider + description: 'Address of the wallet which provided or removed liquidity from the pool' + - name: protocolFeeAmounts + description: 'Amount of fee paid of each token of the pool during the transaction' + + - name: Vault_evt_PoolBalanceManaged + description: > + Decoded table of transactions performed by asset managers on the Balancer Vault contract on gnosis. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: token + description: 'Contract address of token managed' + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + - name: managedDelta + description: 'Change in the amount of token managed by the asset manager' + - name: cashDelta + description: 'Change in the amount of token cashed the vault' + + - name: LiquidityBootstrappingPool_evt_GradualWeightUpdateScheduled + description: > + Decoded table related to scheduled gradual weight updates on the Balancer LiquidityBootstrappingPool contract. + columns: + - name: contract_address + description: 'LBP contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - &endTime + name: endTime + description: 'Unix timestamp of the LBP end time' + - &endWeights + name: endWeights + description: 'Array with the weights of the LBP tokens at the end of the LBP' + - &startTime + name: startTime + description: 'Unix timestamp of the LBP start time' + - &startWeights + name: startWeights + description: 'Array with the weights of the LBP tokens at the start of the LBP' + + - name: NoProtocolFeeLiquidityBootstrappingPool_evt_GradualWeightUpdateScheduled + description: > + Decoded table related to scheduled gradual weight updates on the Balancer NoProtocolFeeLiquidityBootstrappingPool contract. + columns: + - name: contract_address + description: 'LBP contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - *endTime + - *endWeights + - *startTime + - *startWeights + + - name: Vault_evt_FlashLoan + + - name: ComposableStablePoolFactory_evt_PoolCreated + description: > + Decoded table of Composable Stable Pools created by the Composable Stable Pool Factory contract. + columns: + - name: contract_address + description: 'Balancer v2 Composable Stable Pool Factory contract address.' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: pool + description: 'Ethereum address for the Composable Stable Pool created in the transaction.' + + - name: Vault_evt_TokensRegistered + description: > + Decoded table of tokens registered by pool with the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - *tokens + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + + - name: balancer_v3_gnosis + description: > + Decoded tables related to Balancer V2, an automated portfolio manager and trading platform, on Gnosis. + 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: StableSurgePoolFactory_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 + + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + + - name: LBPoolFactory_call_create + + - name: LBPoolFactory_evt_LBPoolCreated + + - name: LBPool_evt_GradualWeightUpdateScheduled + + - name: GyroECLPPoolFactory_call_create diff --git a/sources/balancer/optimism/balancer_optimism_sources.yml b/sources/balancer/optimism/balancer_optimism_sources.yml new file mode 100644 index 0000000..3919cbf --- /dev/null +++ b/sources/balancer/optimism/balancer_optimism_sources.yml @@ -0,0 +1,199 @@ +version: 2 + +sources: + - name: balancer_v2_optimism + description: > + Decoded tables related to Balancer V2, an automated portfolio manager and trading platform, on Optimism. + tables: + - name: Vault_evt_PoolRegistered + description: > + Decoded table of registered pools on the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - &evt_tx_hash + name: evt_tx_hash + description: 'Primary key of the transaction' + - &evt_index + name: evt_index + description: 'Index value of the transaction' + - &evt_block_time + name: evt_block_time + description: 'Timestamp for block event time in UTC' + - &evt_block_number + name: evt_block_number + description: 'Block number which processed the unique transaction hash' + - name: poolAddress + description: 'Optimism address for the liquidity pool used in transaction' + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - name: specialization + description: 'Pool specialization' + + - name: WeightedPoolFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPoolFactory contract. + columns: + - &call_block_number + name: call_block_number + description: 'Block number which processed the unique transaction hash' + - &call_block_time + name: call_block_time + description: 'Timestamp for block time in which the call occurred in UTC' + - &call_success + name: call_success + description: 'Boolean indicating if call was successfully processed' + - &call_trace_address + name: call_trace_address + description: '' + - &call_tx_hash + name: call_tx_hash + description: 'Primary key of the transaction' + - name: contract_address + description: 'Address of the WeightedPoolFactory contract' + - name: name + description: 'Name of the created pool' + - &output_0 + name: output_0 + description: 'Contract address of the created pool' + - &owner + name: owner + description: 'Contract of the pool owner' + - &swapFeePercentage + name: swapFeePercentage + description: 'Pool swap fee in percentage' + - &symbol + name: symbol + description: 'Symbol of the created pool' + - &tokens + name: tokens + description: 'Array with the address of the created pool tokens' + - &weights + name: weights + description: 'Array with the weight of each token in the created pool' + + - name: WeightedPool2TokensFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPool2TokensFactory contract' + - name: name + description: 'Name of the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + - *weights + + - name: WeightedPoolV2Factory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPoolV2Factory contract' + - name: name + description: 'Name of the created pool' + - name: normalizedWeights + description: 'Array with the normalized weight of each token in the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + + - name: Vault_evt_PoolBalanceChanged + description: > + Decoded table of pool balances changes record on the Balancer Vault contract on Optimism. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: tokens + description: 'Contract address of each token of the pool' + - name: deltas + description: 'Balance changes of each token of the pool' + - name: liquidityProvider + description: 'Address of the wallet which provided or removed liquidity from the pool' + - name: protocolFeeAmounts + description: 'Amount of fee paid of each token of the pool during the transaction' + + - name: Vault_evt_PoolBalanceManaged + description: > + Decoded table of transactions performed by asset managers on the Balancer Vault contract on Optimism. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: token + description: 'Contract address of token managed' + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + - name: managedDelta + description: 'Change in the amount of token managed by the asset manager' + - name: cashDelta + description: 'Change in the amount of token cashed the vault' + - *tokens + + - name: ChildChainLiquidityGaugeFactory_evt_RewardsOnlyGaugeCreated + description: "Rewards gauges created on Balancer on Optimism" + + - name: Vault_evt_FlashLoan + + - name: ComposableStablePoolFactory_evt_PoolCreated + description: > + Decoded table of Composable Stable Pools created by the Composable Stable Pool Factory contract. + columns: + - name: contract_address + description: 'Balancer v2 Composable Stable Pool Factory contract address.' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: pool + description: 'Ethereum address for the Composable Stable Pool created in the transaction.' + + - name: Vault_evt_TokensRegistered + description: > + Decoded table of tokens registered by pool with the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - *tokens + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + + + - name: balancer_optimism + description: > + Decoded tables related to Balancer V2, an automated portfolio manager and trading platform, on Optimism. + tables: + - name: ChildChainLiquidityGaugeFactory_evt_RewardsOnlyGaugeCreated + description: "Rewards gauges created on Balancer on Optimism" diff --git a/sources/balancer/plasma/balancer_plasma_sources.yml b/sources/balancer/plasma/balancer_plasma_sources.yml new file mode 100644 index 0000000..3b96fcb --- /dev/null +++ b/sources/balancer/plasma/balancer_plasma_sources.yml @@ -0,0 +1,52 @@ +version: 2 + +sources: + - name: balancer_v3_plasma + description: > + Decoded tables related to Balancer V3, an automated portfolio manager and trading platform, on Plasma. + 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: StableSurgePoolFactory_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 + + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + + - name: LBPoolFactory_call_create + + - name: LBPoolFactory_evt_LBPoolCreated + + - name: LBPool_evt_GradualWeightUpdateScheduled + + - name: GyroECLPPoolFactory_call_create + + - name: ReclammPoolFactory_call_create diff --git a/sources/balancer/polygon/balancer_polygon_sources.yml b/sources/balancer/polygon/balancer_polygon_sources.yml new file mode 100644 index 0000000..82c3416 --- /dev/null +++ b/sources/balancer/polygon/balancer_polygon_sources.yml @@ -0,0 +1,226 @@ +version: 2 + +sources: + - name: balancer_v2_polygon + description: > + Decoded tables related to Balancer V2, an automated portfolio manager and trading platform, on Polygon. + tables: + - name: Vault_evt_PoolRegistered + description: > + Decoded table of registered pools on the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - &evt_tx_hash + name: evt_tx_hash + description: 'Primary key of the transaction' + - &evt_index + name: evt_index + description: 'Index value of the transaction' + - &evt_block_time + name: evt_block_time + description: 'Timestamp for block event time in UTC' + - &evt_block_number + name: evt_block_number + description: 'Block number which processed the unique transaction hash' + - name: poolAddress + description: 'Polygon address for the liquidity pool used in transaction' + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - name: specialization + description: 'Pool specialization' + + - name: WeightedPoolFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPoolFactory contract. + columns: + - &call_block_number + name: call_block_number + description: 'Block number which processed the unique transaction hash' + - &call_block_time + name: call_block_time + description: 'Timestamp for block time in which the call occurred in UTC' + - &call_success + name: call_success + description: 'Boolean indicating if call was successfully processed' + - &call_trace_address + name: call_trace_address + description: '' + - &call_tx_hash + name: call_tx_hash + description: 'Primary key of the transaction' + - name: contract_address + description: 'Address of the WeightedPoolFactory contract' + - name: name + description: 'Name of the created pool' + - &output_0 + name: output_0 + description: 'Contract address of the created pool' + - &owner + name: owner + description: 'Contract of the pool owner' + - &swapFeePercentage + name: swapFeePercentage + description: 'Pool swap fee in percentage' + - &symbol + name: symbol + description: 'Symbol of the created pool' + - &tokens + name: tokens + description: 'Array with the address of the created pool tokens' + - &weights + name: weights + description: 'Array with the weight of each token in the created pool' + + - name: WeightedPool2TokensFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPool2TokensFactory contract' + - name: name + description: 'Name of the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + - *weights + + - name: WeightedPoolV2Factory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPool2TokensFactory contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: contract_address + description: 'Address of the WeightedPoolV2Factory contract' + - name: name + description: 'Name of the created pool' + - name: normalizedWeights + description: 'Array with the normalized weight of each token in the created pool' + - *output_0 + - *owner + - *swapFeePercentage + - *symbol + - *tokens + + - name: Vault_evt_PoolBalanceChanged + description: > + Decoded table of pool balances changes record on the Balancer Vault contract on Polygon. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: tokens + description: 'Contract address of each token of the pool' + - name: deltas + description: 'Balance changes of each token of the pool' + - name: liquidityProvider + description: 'Address of the wallet which provided or removed liquidity from the pool' + - name: protocolFeeAmounts + description: 'Amount of fee paid of each token of the pool during the transaction' + + - name: Vault_evt_PoolBalanceManaged + description: > + Decoded table of transactions performed by asset managers on the Balancer Vault contract on Polygon. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: token + description: 'Contract address of token managed' + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + - name: managedDelta + description: 'Change in the amount of token managed by the asset manager' + - name: cashDelta + description: 'Change in the amount of token cashed the vault' + + - name: LiquidityBootstrappingPool_evt_GradualWeightUpdateScheduled + description: > + Decoded table related to scheduled gradual weight updates on the Balancer LiquidityBootstrappingPool contract. + columns: + - name: contract_address + description: 'LBP contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - &endTime + name: endTime + description: 'Unix timestamp of the LBP end time' + - &endWeights + name: endWeights + description: 'Array with the weights of the LBP tokens at the end of the LBP' + - &startTime + name: startTime + description: 'Unix timestamp of the LBP start time' + - &startWeights + name: startWeights + description: 'Array with the weights of the LBP tokens at the start of the LBP' + + - name: NoProtocolFeeLiquidityBootstrappingPool_evt_GradualWeightUpdateScheduled + description: > + Decoded table related to scheduled gradual weight updates on the Balancer NoProtocolFeeLiquidityBootstrappingPool contract. + columns: + - name: contract_address + description: 'LBP contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - *endTime + - *endWeights + - *startTime + - *startWeights + + - name: Vault_evt_FlashLoan + + - name: ComposableStablePoolFactory_evt_PoolCreated + description: > + Decoded table of Composable Stable Pools created by the Composable Stable Pool Factory contract. + columns: + - name: contract_address + description: 'Balancer v2 Composable Stable Pool Factory contract address.' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: pool + description: 'Ethereum address for the Composable Stable Pool created in the transaction.' + + - name: Vault_evt_TokensRegistered + description: > + Decoded table of tokens registered by pool with the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - *evt_tx_hash + - *evt_index + - *evt_block_time + - *evt_block_number + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - *tokens + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + diff --git a/sources/balancer/zkevm/balancer_zkevm_sources.yml b/sources/balancer/zkevm/balancer_zkevm_sources.yml new file mode 100644 index 0000000..bb44ac9 --- /dev/null +++ b/sources/balancer/zkevm/balancer_zkevm_sources.yml @@ -0,0 +1,179 @@ +version: 2 + +sources: + - name: balancer_v2_zkevm + description: > + Decoded tables related to Balancer V2, an automated portfolio manager and trading platform, on polygon zkevm. + tables: + - name: Vault_evt_PoolRegistered + description: > + Decoded table of registered pools on the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - &evt_tx_hash + name: evt_tx_hash + description: 'Primary key of the transaction' + - &evt_index + name: evt_index + description: 'Index value of the transaction' + - &evt_block_time + name: evt_block_time + description: 'Timestamp for block event time in UTC' + - &evt_block_number + name: evt_block_number + description: 'Block number which processed the unique transaction hash' + - name: poolAddress + description: 'zkevm address for the liquidity pool used in transaction' + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - name: specialization + description: 'Pool specialization' + + - name: WeightedPoolFactory_call_create + description: > + Decoded table of registered pools on the Balancer WeightedPoolFactory contract. + columns: + - &call_block_number + name: call_block_number + description: 'Block number which processed the unique transaction hash' + - &call_block_time + name: call_block_time + description: 'Timestamp for block time in which the call occurred in UTC' + - &call_success + name: call_success + description: 'Boolean indicating if call was successfully processed' + - &call_trace_address + name: call_trace_address + description: '' + - &call_tx_hash + name: call_tx_hash + description: 'Primary key of the transaction' + - name: contract_address + description: 'Address of the WeightedPoolFactory contract' + - name: name + description: 'Name of the created pool' + - &output_0 + name: output_0 + description: 'Contract address of the created pool' + - &owner + name: owner + description: 'Contract of the pool owner' + - &swapFeePercentage + name: swapFeePercentage + description: 'Pool swap fee in percentage' + - &symbol + name: symbol + description: 'Symbol of the created pool' + - &tokens + name: tokens + description: 'Array with the address of the created pool tokens' + - &weights + name: weights + description: 'Array with the weight of each token in the created pool' + + - name: Vault_evt_PoolBalanceChanged + description: > + Decoded table of pool balances changes record on the Balancer Vault contract on zkevm. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - name: evt_tx_hash + - name: evt_index + - name: evt_block_time + - name: evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: tokens + description: 'Contract address of each token of the pool' + - name: deltas + description: 'Balance changes of each token of the pool' + - name: liquidityProvider + description: 'Address of the wallet which provided or removed liquidity from the pool' + - name: protocolFeeAmounts + description: 'Amount of fee paid of each token of the pool during the transaction' + + - name: Vault_evt_PoolBalanceManaged + description: > + Decoded table of transactions performed by asset managers on the Balancer Vault contract on zkevm. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - name: evt_tx_hash + - name: evt_index + - name: evt_block_time + - name: evt_block_number + - name: poolId + description: 'Balancer pool contract address' + - name: token + description: 'Contract address of token managed' + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + - name: managedDelta + description: 'Change in the amount of token managed by the asset manager' + - name: cashDelta + description: 'Change in the amount of token cashed the vault' + + - name: NoProtocolFeeLiquidityBootstrappingPool_evt_GradualWeightUpdateScheduled + description: > + Decoded table related to scheduled gradual weight updates on the Balancer NoProtocolFeeLiquidityBootstrappingPool contract. + columns: + - name: contract_address + description: 'LBP contract address' + - name: evt_tx_hash + - name: evt_index + - name: evt_block_time + - name: evt_block_number + - name: endTime + - name: endWeights + - name: startTime + - name: startWeights + + - name: Vault_evt_FlashLoan + + - name: ComposableStablePoolFactory_evt_PoolCreated + description: > + Decoded table of Composable Stable Pools created by the Composable Stable Pool Factory contract. + columns: + - name: contract_address + description: 'Balancer v2 Composable Stable Pool Factory contract address.' + - name: evt_tx_hash + - name: evt_index + - name: evt_block_time + - name: evt_block_number + - name: pool + description: 'Ethereum address for the Composable Stable Pool created in the transaction.' + + - name: Vault_evt_TokensRegistered + description: > + Decoded table of tokens registered by pool with the Balancer Vault contract. + columns: + - name: contract_address + description: 'Balancer v2 Vault contract address' + - name: evt_tx_hash + - name: evt_index + - name: evt_block_time + - name: evt_block_number + - name: poolId + description: 'Unique encoded identifier that refers to each pool' + - name: tokens + - name: assetManager + description: 'Address of the contract which managed the asset from the vault' + + - name: Vault_evt_Swap + description: "" + columns: + - name: amountIn + - name: amountOut + - name: contract_address + - name: evt_block_number + description: "Block number which processed the unique transaction hash" + - name: evt_block_time + description: "Timestamp for block event time in UTC" + - name: evt_index + description: "Index value of the transaction" + - name: evt_tx_hash + description: "Primary key of the transaction" + - name: poolId + - name: tokenIn + - name: tokenOut \ No newline at end of file diff --git a/sources/balancer_cowswap_amm/arbitrum/_sources.yml b/sources/balancer_cowswap_amm/arbitrum/_sources.yml new file mode 100644 index 0000000..0c38eff --- /dev/null +++ b/sources/balancer_cowswap_amm/arbitrum/_sources.yml @@ -0,0 +1,9 @@ +version: 2 +sources: + - name: b_cow_amm_arbitrum + tables: + - name: BCoWFactory_evt_LOG_NEW_POOL + - name: BCoWFactory_evt_COWAMMPoolCreated + - name: BCoWFactory_call_logBCoWPool + - name: BCoWPool_call_bind + - name: BCoWPool_call_unbind \ No newline at end of file diff --git a/sources/balancer_cowswap_amm/base/_sources.yml b/sources/balancer_cowswap_amm/base/_sources.yml new file mode 100644 index 0000000..a122c59 --- /dev/null +++ b/sources/balancer_cowswap_amm/base/_sources.yml @@ -0,0 +1,9 @@ +version: 2 +sources: + - name: b_cow_amm_base + tables: + - name: BCoWFactory_evt_LOG_NEW_POOL + - name: BCoWFactory_evt_COWAMMPoolCreated + - name: BCoWFactory_call_logBCoWPool + - name: BCoWPool_call_bind + - name: BCoWPool_call_unbind \ No newline at end of file diff --git a/sources/balancer_cowswap_amm/ethereum/_sources.yml b/sources/balancer_cowswap_amm/ethereum/_sources.yml new file mode 100644 index 0000000..7282c11 --- /dev/null +++ b/sources/balancer_cowswap_amm/ethereum/_sources.yml @@ -0,0 +1,9 @@ +version: 2 +sources: + - name: b_cow_amm_ethereum + tables: + - name: BCoWFactory_evt_LOG_NEW_POOL + - name: BCoWFactory_evt_COWAMMPoolCreated + - name: BCoWFactory_call_logBCoWPool + - name: BCoWPool_call_bind + - name: BCoWPool_call_unbind \ No newline at end of file diff --git a/sources/balancer_cowswap_amm/gnosis/_sources.yml b/sources/balancer_cowswap_amm/gnosis/_sources.yml new file mode 100644 index 0000000..e92ca72 --- /dev/null +++ b/sources/balancer_cowswap_amm/gnosis/_sources.yml @@ -0,0 +1,9 @@ +version: 2 +sources: + - name: b_cow_amm_gnosis + tables: + - name: BCoWFactory_evt_LOG_NEW_POOL + - name: BCoWFactory_evt_COWAMMPoolCreated + - name: BCoWFactory_call_logBCoWPool + - name: BCoWPool_call_bind + - name: BCoWPool_call_unbind \ No newline at end of file diff --git a/sources/balancer_liquidity_extra_sources.yml b/sources/balancer_liquidity_extra_sources.yml new file mode 100644 index 0000000..6a16c17 --- /dev/null +++ b/sources/balancer_liquidity_extra_sources.yml @@ -0,0 +1,1936 @@ +version: 2 +sources: +- name: balancer + tables: + - name: token_whitelist +- name: balancer_v2_arbitrum + tables: + - name: AaveLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer AaveLinearPoolFactory + contract. + + ' + columns: + - &id001 + name: call_block_number + description: Block number which processed the unique transaction hash + - &id002 + name: call_block_time + description: Timestamp for block time in which the call occurred in UTC + - &id003 + name: call_success + description: Boolean indicating if call was successfully processed + - &id004 + name: call_trace_address + description: '' + - &id005 + name: call_tx_hash + description: Primary key of the transaction + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - &id010 + name: mainToken + description: Address of the main token of the created pool + - &id011 + name: wrappedToken + description: Address of the wrapped token of the created pool + - &id012 + name: upperTarget + description: Upper limit of the "no fee zone" of the created pool + - &id006 + name: output_0 + description: Contract address of the created pool + - &id007 + name: owner + description: Contract of the pool owner + - &id008 + name: swapFeePercentage + description: Pool swap fee in percentage + - &id009 + name: symbol + description: Symbol of the created pool + - name: ComposableStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - &id018 + name: tokenRateCacheDurations + description: Array with the duration of each tokens cached by RateProviders + - &id019 + name: exemptFromYieldProtocolFeeFlags + description: Array of booleans indicating if each token of the pool is exempt + from yield protocol fee + - *id006 + - *id007 + - *id008 + - &id017 + name: amplificationParameter + description: Amplification parameter of the created pool + - &id016 + name: rateProviders + description: Array with the contracts of the rate providers of the created pool + - *id009 + - &id013 + name: tokens + description: Array with the address of the created pool tokens + - name: ERC4626LinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ERC4626LinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id010 + - *id011 + - *id012 + - *id006 + - *id007 + - *id008 + - *id009 + - name: InvestmentPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer InvestmentPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the InvestmentPoolFactory contract + - name: name + description: Name of the created pool + - *id006 + - *id007 + - *id008 + - &id014 + name: swapEnabledOnStart + description: Boolean indicating if swap is enabled on start + - &id020 + name: managementSwapFeePercentage + description: Management swap fee in percentage + - *id009 + - *id013 + - &id015 + name: weights + description: Array with the weight of each token in the created pool + - name: LiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer LiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the LiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: MetaStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer MetaStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the MetaStablePoolFactory contract + - name: name + description: Name of the created pool + - &id021 + name: oracleEnabled + description: Boolean which indicates if the oracle functionality is enabled + in the created pool + - *id016 + - &id022 + name: priceRateCacheDuration + description: Array with the duration of the cached prices from RateProviders + for each token + - *id006 + - *id007 + - *id008 + - *id017 + - *id009 + - *id013 + - name: NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer NoProtocolFeeLiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the NoProtocolFeeLiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + - name: StablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer StablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the StablePoolFactory contract + - name: name + description: Name of the created pool + - *id017 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - name: Vault_evt_LiquidityAdded + - name: Vault_evt_LiquidityRemoved + - name: Vault_evt_Swap +- name: balancer_v2_avalanche_c + tables: + - name: AaveLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer AaveLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id010 + - *id011 + - *id012 + - *id006 + - *id007 + - *id008 + - *id009 + - name: ComposableStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: ERC4626LinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: ManagedPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ManagedPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ManagedPoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer NoProtocolFeeLiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the NoProtocolFeeLiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + - name: Vault_evt_LiquidityAdded + - name: Vault_evt_LiquidityRemoved + - name: Vault_evt_Swap +- name: balancer_v2_base + tables: + - name: AaveLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer AaveLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id010 + - *id011 + - *id012 + - *id006 + - *id007 + - *id008 + - *id009 + - name: ComposableStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: ERC4626LinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ERC4626LinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ERC4626LinearPoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: ManagedPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ManagedPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ManagedPoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer NoProtocolFeeLiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the NoProtocolFeeLiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + - name: Vault_evt_LiquidityAdded + - name: Vault_evt_LiquidityRemoved + - name: Vault_evt_Swap +- name: balancer_v2_ethereum + tables: + - name: AaveLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer AaveLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id010 + - *id011 + - *id012 + - *id006 + - *id007 + - *id008 + - *id009 + - name: ComposableStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: InvestmentPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer InvestmentPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - name: contract_address + description: Address of the InvestmentPoolFactory contract + - name: name + description: Name of the created pool + - *id006 + - *id007 + - *id008 + - *id014 + - *id020 + - *id009 + - *id013 + - *id015 + - name: LiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer LiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the LiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: MetaStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer MetaStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the MetaStablePoolFactory contract + - name: name + description: Name of the created pool + - *id021 + - *id016 + - *id022 + - *id006 + - *id007 + - *id008 + - *id017 + - *id009 + - *id013 + - name: NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer NoProtocolFeeLiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the NoProtocolFeeLiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + - name: StablePhantomPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer StablePhantomPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the StablePhantomPoolFactory contract + - name: name + description: Name of the created pool + - *id006 + - *id007 + - *id016 + - *id018 + - *id017 + - *id008 + - *id009 + - *id013 + - name: StablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer StablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the StablePoolFactory contract + - name: name + description: Name of the created pool + - *id017 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - name: Vault_evt_LiquidityAdded + - name: Vault_evt_LiquidityRemoved + - name: Vault_evt_Swap +- name: balancer_v2_gnosis + tables: + - name: AaveLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer AaveLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id010 + - *id011 + - *id012 + - *id006 + - *id007 + - *id008 + - *id009 + - name: AaveLinearPoolV3Factory_call_create + description: 'Decoded table of registered pools on the Balancer AaveLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id010 + - *id011 + - *id012 + - *id006 + - *id007 + - *id008 + - *id009 + - name: ComposableStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: ComposableStablePoolV2Factory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: ManagedPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ManagedPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ManagedPoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer NoProtocolFeeLiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the NoProtocolFeeLiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + - name: StablePoolV2Factory_call_create + description: 'Decoded table of registered pools on the Balancer StablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the StablePoolFactory contract + - name: name + description: Name of the created pool + - *id017 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - name: Vault_evt_LiquidityAdded + - name: Vault_evt_LiquidityRemoved + - name: Vault_evt_Swap +- name: balancer_v2_optimism + tables: + - name: AaveLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer AaveLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id010 + - *id011 + - *id012 + - *id006 + - *id007 + - *id008 + - *id009 + - name: ComposableStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id018 + - *id009 + - *id013 + - name: MetaStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer MetaStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the MetaStablePoolFactory contract + - name: name + description: Name of the created pool + - *id021 + - *id016 + - *id022 + - *id006 + - *id007 + - *id008 + - *id017 + - *id009 + - *id013 + - name: NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer NoProtocolFeeLiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the NoProtocolFeeLiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + - name: StablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer StablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the StablePoolFactory contract + - name: name + description: Name of the created pool + - *id017 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - name: Vault_evt_LiquidityAdded + - name: Vault_evt_LiquidityRemoved + - name: Vault_evt_Swap +- name: balancer_v2_polygon + tables: + - name: AaveLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer AaveLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id010 + - *id011 + - *id012 + - *id006 + - *id007 + - *id008 + - *id009 + - name: ComposableStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: InvestmentPoolFactory_call_create + description: 'Deco*ed table of registered pools on the Balancer InvestmentPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the InvestmentPoolFactory contract + - name: name + description: Name of the created pool + - *id006 + - *id007 + - *id008 + - *id014 + - *id020 + - *id009 + - *id013 + - *id015 + - name: LiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer LiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the LiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: MetaStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer MetaStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the MetaStablePoolFactory contract + - name: name + description: Name of the created pool + - *id021 + - *id016 + - *id022 + - *id006 + - *id007 + - *id008 + - *id017 + - *id009 + - *id013 + - name: NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer NoProtocolFeeLiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the NoProtocolFeeLiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + - name: StablePhantomPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer StablePhantomPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the StablePhantomPoolFactory contract + - name: name + description: Name of the created pool + - *id006 + - *id007 + - *id016 + - *id018 + - *id017 + - *id008 + - *id009 + - *id013 + - name: StablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer StablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the StablePoolFactory contract + - name: name + description: Name of the created pool + - *id017 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - name: Vault_evt_LiquidityAdded + - name: Vault_evt_LiquidityRemoved + - name: Vault_evt_Swap +- name: balancer_v2_zkevm + tables: + - name: AaveLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer AaveLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the AaveLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id010 + - *id011 + - *id012 + - *id006 + - *id007 + - *id008 + - *id009 + - name: ComposableStablePoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ComposableStablePoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: ERC4626LinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ERC4626LinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ERC4626LinearPoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: GearboxLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer GearboxLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the GearboxLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: ManagedPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer ManagedPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the ManagedPoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 + - name: NoProtocolFeeLiquidityBootstrappingPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer NoProtocolFeeLiquidityBootstrappingPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the NoProtocolFeeLiquidityBootstrappingPoolFactory contract + - name: name + description: Name of the created pool + - *id014 + - *id006 + - *id007 + - *id008 + - *id009 + - *id013 + - *id015 + - name: ProtocolFeeController_evt_GlobalProtocolSwapFeePercentageChanged + - name: ProtocolFeeController_evt_PoolCreatorSwapFeePercentageChanged + - name: Vault_evt_LiquidityAdded + - name: Vault_evt_LiquidityRemoved + - name: YearnLinearPoolFactory_call_create + description: 'Decoded table of registered pools on the Balancer YearnLinearPoolFactory + contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: contract_address + description: Address of the YearnLinearPoolFactory contract + - name: name + description: Name of the created pool + - *id018 + - *id019 + - *id006 + - *id007 + - *id008 + - *id017 + - *id016 + - *id009 + - *id013 +- name: balancer_v3 + tables: + - name: erc4626_token_prices +- name: balancer_v3_arbitrum + tables: + - name: Vault_evt_PoolBalanceChanged + - name: Vault_evt_PoolBalanceManaged +- name: balancer_v3_base + tables: + - name: Vault_evt_PoolBalanceChanged + - name: Vault_evt_PoolBalanceManaged +- name: balancer_v3_ethereum + tables: + - name: Vault_evt_PoolBalanceChanged + - name: Vault_evt_PoolBalanceManaged +- name: balancer_v3_gnosis + tables: + - name: Vault_evt_PoolBalanceChanged + - name: Vault_evt_PoolBalanceManaged +- name: dex + tables: + - name: prices +- name: erc20_arbitrum + description: Standard ERC20 Fungible Token event tables for arbitrum + tables: + - name: evt_Transfer + columns: + - name: contract_address + description: Address of the ERC20 token contract that emitted this event + - name: evt_tx_hash + description: Hash of the transaction containing this event + - name: evt_index + description: Index position of this event within the transaction + - name: evt_block_time + description: Timestamp of the block containing this event + - name: evt_block_number + description: The block number containing this event + - name: from + description: Sender of tokens + - name: to + description: Recipient of tokens + - name: value + description: Amount of ERC20 tokens transferred, in the token's native decimal + representation (raw value) +- name: erc20_avalanche_c + tables: + - name: evt_Transfer + columns: + - name: contract_address + description: Address of the ERC20 token contract that emitted this event + - name: evt_tx_hash + description: Hash of the transaction containing this event + - name: evt_index + description: Index position of this event within the transaction + - name: evt_block_time + description: Timestamp of the block containing this event + - name: evt_block_number + description: The block number containing this event + - name: from + description: Address of the account that initiated and signed this transaction + - name: to + description: Address of the recipient account or contract; null for contract + creation transactions + - name: value + description: Amount of ERC20 tokens transferred, in the token's native decimal + representation (raw value) +- name: erc20_base + tables: + - name: evt_Transfer + columns: + - name: contract_address + description: Address of the ERC20 token contract that emitted this event + - name: evt_tx_hash + description: Hash of the transaction containing this event + - name: evt_index + description: Index position of this event within the transaction + - name: evt_block_time + description: Timestamp of the block containing this event + - name: evt_block_number + description: The block number containing this event + - name: from + description: Address of the account that initiated and signed this transaction + - name: to + description: Address of the recipient account or contract; null for contract + creation transactions + - name: value + description: Amount of ERC20 tokens transferred, in the token's native decimal + representation (raw value) +- name: erc20_ethereum + tables: + - name: evt_Transfer + columns: + - name: contract_address + description: Address of the ERC20 token contract that emitted this event + - name: evt_tx_hash + description: Hash of the transaction containing this event + - name: evt_index + description: Index position of this event within the transaction + - name: evt_block_time + description: Timestamp of the block containing this event + - name: evt_block_number + description: The block number containing this event + - name: from + description: Address of the account that initiated and signed this transaction + - name: to + description: Address of the recipient account or contract; null for contract + creation transactions + - name: value + description: Amount of ERC20 tokens transferred, in the token's native decimal + representation (raw value) +- name: erc20_gnosis + tables: + - name: evt_Transfer + columns: + - name: contract_address + description: Address of the ERC20 token contract that emitted this event + - name: evt_tx_hash + description: Hash of the transaction containing this event + - name: evt_index + description: Index position of this event within the transaction + - name: evt_block_time + description: Timestamp of the block containing this event + - name: evt_block_number + description: The block number containing this event + - name: from + description: Address of the account that initiated and signed this transaction + - name: to + description: Address of the recipient account or contract; null for contract + creation transactions + - name: value + description: Amount of ERC20 tokens transferred, in the token's native decimal + representation (raw value) +- name: erc20_optimism + description: Standard ERC20 Fungible Token event tables for optimism + tables: + - name: evt_Transfer + columns: + - name: contract_address + description: Address of the ERC20 token contract that emitted this event + - name: evt_tx_hash + description: Hash of the transaction containing this event + - name: evt_index + description: Index position of this event within the transaction + - name: evt_block_time + description: Timestamp of the block containing this event + - name: evt_block_number + description: The block number containing this event + - name: from + description: Sender of tokens + - name: to + description: Recipient of tokens + - name: value + description: Amount of ERC20 tokens transferred, in the token's native decimal + representation (raw value) +- name: erc20_polygon + tables: + - name: evt_Transfer + columns: + - name: contract_address + description: Address of the ERC20 token contract that emitted this event + - name: evt_tx_hash + description: Hash of the transaction containing this event + - name: evt_index + description: Index position of this event within the transaction + - name: evt_block_time + description: Timestamp of the block containing this event + - name: evt_block_number + description: The block number containing this event + - name: from + description: Address of the account that initiated and signed this transaction + - name: to + description: Address of the recipient account or contract; null for contract + creation transactions + - name: value + description: Amount of ERC20 tokens transferred, in the token's native decimal + representation (raw value) +- name: erc20_zkevm + tables: + - name: evt_Transfer + columns: + - name: contract_address + description: Address of the ERC20 token contract that emitted this event + - name: evt_tx_hash + description: Hash of the transaction containing this event + - name: evt_index + description: Index position of this event within the transaction + - name: evt_block_time + description: Timestamp of the block containing this event + - name: evt_block_number + description: The block number containing this event + - name: from + description: Address of the account that initiated and signed this transaction + - name: to + description: Address of the recipient account or contract; null for contract + creation transactions + - name: value + description: Amount of ERC20 tokens transferred, in the token's native decimal + representation (raw value) +- name: gyroscope + tables: + - name: gyro_tokens +- name: gyroscope_arbitrum + tables: + - name: Gyro2CLPPoolFactory_call_create + description: 'Decoded table of registered pools on the Gyroscope ECLP contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: capManager + - name: capParams + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: derivedECLPParams + - name: eclpParams + - name: name + - *id006 + - *id007 + - name: pauseManager + - name: pauseParams + - *id008 + - *id016 + - *id009 + - *id013 + - name: GyroECLPPoolFactory_call_create + description: 'Decoded table of registered pools on the Gyroscope ECLP contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: capManager + - name: capParams + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: derivedECLPParams + - name: eclpParams + - name: name + - *id006 + - *id007 + - name: pauseManager + - name: pauseParams + - *id008 + - *id016 + - *id009 + - *id013 +- name: gyroscope_avalanche_c + tables: + - name: GyroECLPPoolFactory_call_create + description: 'Decoded table of registered pools on the Gyroscope ECLP contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: capManager + - name: capParams + - name: contract_address + description: Address of the ECLP Pool contract + - name: derivedECLPParams + - name: eclpParams + - name: name + - *id006 + - *id007 + - name: pauseManager + - name: pauseParams + - *id008 + - *id016 + - *id009 + - *id013 +- name: gyroscope_base + tables: + - name: GyroECLPPoolFactory_call_create + description: 'Decoded table of registered pools on the Gyroscope ECLP contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: capManager + - name: capParams + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: derivedECLPParams + - name: eclpParams + - name: name + - *id006 + - *id007 + - name: pauseManager + - name: pauseParams + - *id008 + - *id016 + - *id009 + - *id013 +- name: gyroscope_ethereum + tables: + - name: GyroECLPPoolFactory_call_create + description: 'Decoded table of registered pools on the Gyroscope ECLP contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: capManager + - name: capParams + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: derivedECLPParams + - name: eclpParams + - name: name + - *id006 + - *id007 + - name: pauseManager + - name: pauseParams + - *id008 + - *id016 + - *id009 + - *id013 +- name: gyroscope_gnosis + tables: + - name: GyroECLPPoolFactory_call_create + description: Decoded table of registered pools on the Gyroscope ECLP contract. + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: capManager + - name: capParams + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: derivedECLPParams + - name: eclpParams + - name: name + - *id006 + - *id007 + - name: pauseManager + - name: pauseParams + - *id008 + - *id016 + - *id009 + - *id013 +- name: gyroscope_optimism + tables: + - name: GyroECLPPoolFactory_call_create + description: 'Decoded table of registered pools on the Gyroscope ECLP contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: capManager + - name: capParams + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: derivedECLPParams + - name: eclpParams + - name: name + - *id006 + - *id007 + - name: pauseManager + - name: pauseParams + - *id008 + - *id016 + - *id009 + - *id013 +- name: gyroscope_polygon + tables: + - name: GyroECLPPoolFactory_call_create + description: 'Decoded table of registered pools on the Gyroscope ECLP contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: capManager + - name: capParams + - name: contract_address + description: Address of the ComposableStablePoolFactory contract + - name: derivedECLPParams + - name: eclpParams + - name: name + - *id006 + - *id007 + - name: pauseManager + - name: pauseParams + - *id008 + - *id016 + - *id009 + - *id013 +- name: gyroscope_zkevm + tables: + - name: GyroECLPPoolFactory_call_create + description: 'Decoded table of registered pools on the Gyroscope ECLP contract. + + ' + columns: + - *id001 + - *id002 + - *id003 + - *id004 + - *id005 + - name: capManager + - name: capParams + - name: contract_address + - name: derivedECLPParams + - name: eclpParams + - name: name + - *id006 + - *id007 + - name: pauseManager + - name: pauseParams + - *id008 + - *id016 + - *id009 + - *id013 +- name: labels + tables: + - name: balancer_v1_pools_ethereum + - name: balancer_cowswap_amm_pools + - name: balancer_v2_pools + - name: balancer_v2_pools_arbitrum + - name: balancer_v2_pools_avalanche_c + - name: balancer_v2_pools_base + - name: balancer_v2_pools_ethereum + - name: balancer_v2_pools_gnosis + - name: balancer_v2_pools_optimism + - name: balancer_v2_pools_polygon + - name: balancer_v2_pools_zkevm + - name: balancer_v3_pools + - name: balancer_v3_pools_arbitrum + - name: balancer_v3_pools_base + - name: balancer_v3_pools_ethereum + - name: balancer_v3_pools_gnosis + - name: balancer_v3_pools_plasma + - name: labels_balancer_v1_pools +- name: prices + tables: + - name: hour + description: Hourly token prices aggregated from various sources + columns: + - name: blockchain + description: Native blockchain of the token + type: varchar + - name: contract_address + description: Contract address of the token + type: varbinary + - name: symbol + description: Token symbol + type: varchar + - name: timestamp + description: UTC timestamp for the hour + type: timestamp(3) with time zone + - name: price + description: USD price of a token + type: double + - name: decimals + description: Number of decimals for the token contract + type: bigint + - name: volume + description: Trading volume in USD + type: double + - name: source + description: Source of the price data + type: varchar + - name: source_timestamp + description: Original timestamp from the source + type: timestamp(3) with time zone + - name: usd + description: USD prices across blockchains + meta: + docs_slug: /curated/asset-tracking/prices/prices + columns: + - name: minute + description: UTC event block time truncated to the minute mark + - name: blockchain + description: Native blockchain of the token + - name: contract_address + description: Contract address of the token + - name: symbol + description: Token symbol + - name: price + description: USD price of a token +- name: tokens + tables: + - name: erc20 + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: symbol + data_type: varchar + - name: decimals + data_type: integer +- name: tokens_ethereum + tables: + - name: erc20 + columns: + - name: contract_address + data_type: varbinary + - name: symbol + data_type: varchar + - name: decimals + data_type: integer +- name: xavefinance_arbitrum + tables: + - name: FXPoolDeployer_call_newFXPool + columns: + - name: contract_address + - name: call_tx_hash + - name: call_success + - name: call_trace_address + - name: call_block_time + - name: call_block_number + - name: _baseToken + - name: _baseOracle + - name: _initialDepositInNumeraire + - name: _params + - name: output_balancerPoolId + - name: output_fxpoolAddr +- name: xavefinance_avalanche_c + tables: + - name: FXPoolDeployer_call_newFXPool + columns: + - name: contract_address + - name: call_tx_hash + - name: call_success + - name: call_trace_address + - name: call_block_time + - name: call_block_number + - name: _baseToken + - name: _baseOracle + - name: _initialDepositInNumeraire + - name: _params + - name: output_balancerPoolId + - name: output_fxpoolAddr + - name: FXPoolFactory_call_newFXPool + columns: + - name: contract_address + - name: call_tx_hash + - name: call_success + - name: call_trace_address + - name: call_block_time + - name: call_block_number + - name: _assetsToRegister + - name: _name + - name: _percentFee + - name: _symbol + - name: output_0 + - name: vault +- name: xavefinance_ethereum + tables: + - name: FXPoolDeployer_call_newFXPool + columns: + - name: contract_address + - name: call_tx_hash + - name: call_success + - name: call_trace_address + - name: call_block_time + - name: call_block_number + - name: _baseToken + - name: _baseOracle + - name: _initialDepositInNumeraire + - name: _params + - name: output_balancerPoolId + - name: output_fxpoolAddr + - name: FXPoolFactory_call_newFXPool + columns: + - name: contract_address + - name: call_tx_hash + - name: call_success + - name: call_trace_address + - name: call_block_time + - name: call_block_number + - name: _assetsToRegister + - name: _name + - name: _percentFee + - name: _symbol + - name: output_0 + - name: vault +- name: xavefinance_polygon + tables: + - name: FXPoolFactory_call_newFXPool + columns: + - name: contract_address + - name: call_tx_hash + - name: call_success + - name: call_trace_address + - name: call_block_time + - name: call_block_number + - name: _assetsToRegister + - name: _name + - name: _percentFee + - name: _symbol + - name: output_0 + - name: vault