Skip to content

Commit

Permalink
improvements for erc4626_token_prices
Browse files Browse the repository at this point in the history
  • Loading branch information
viniabussafi committed Dec 9, 2024
1 parent 83d8a99 commit cf6ad26
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dbt_macros/shared/balancer/balancer_bpt_prices_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,10 @@ WITH pool_labels AS (
wrapped_token AS token,
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
next_change
DATE_TRUNC ('day', next_change) AS next_change
FROM {{ ref('balancer_v3_erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
),

swaps_changes AS (
Expand Down
3 changes: 2 additions & 1 deletion dbt_macros/shared/balancer/balancer_liquidity_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,10 @@ WITH pool_labels AS (
wrapped_token AS token,
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
next_change
DATE_TRUNC ('day', next_change) AS next_change
FROM {{ ref('balancer_v3_erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
),

swaps_changes AS (
Expand Down
3 changes: 2 additions & 1 deletion dbt_macros/shared/balancer/balancer_protocol_fee_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ WITH pool_labels AS (
wrapped_token AS token,
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
next_change
DATE_TRUNC ('day', next_change) AS next_change
FROM {{ ref('balancer_v3_erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
),

daily_protocol_fee_collected AS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ WITH
wrapped_token AS token,
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
next_change
DATE_TRUNC ('day', next_change) AS next_change
FROM {{ ref('balancer_v3_erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
),

daily_balance AS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
WITH wrap_unwrap AS(
SELECT
evt_block_time,
underlyingToken,
wrappedToken,
CAST(mintedShares AS DOUBLE) / CAST(depositedUnderlying AS DOUBLE) AS ratio
FROM {{ source('balancer_v3_ethereum', 'Vault_evt_Wrap') }}
Expand All @@ -24,7 +23,6 @@ WITH wrap_unwrap AS(

SELECT
evt_block_time,
underlyingToken,
wrappedToken,
CAST(burnedShares AS DOUBLE) / CAST(withdrawnUnderlying AS DOUBLE) AS ratio
FROM {{ source('balancer_v3_ethereum', 'Vault_evt_Unwrap') }}
Expand All @@ -37,12 +35,13 @@ WITH wrap_unwrap AS(
price_join AS(
SELECT
w.evt_block_time,
w.underlyingToken,
m.underlying_token,
w.wrappedToken,
p.decimals,
ratio * price AS adjusted_price
FROM wrap_unwrap w
JOIN {{ source('prices', 'usd') }} p ON w.underlyingToken = p.contract_address
JOIN {{ref('balancer_v3_ethereum_erc4626_token_mapping')}} m ON m.erc4626_token = w.wrappedToken
JOIN {{ source('prices', 'usd') }} p ON w.underlying_token = p.contract_address
AND p.blockchain = 'ethereum'
AND DATE_TRUNC('minute', w.evt_block_time) = DATE_TRUNC('minute', p.minute)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ WITH wrap_unwrap AS(
price_join AS(
SELECT
w.evt_block_time,
w.underlyingToken,
m.underlying_token,
w.wrappedToken,
p.decimals,
ratio * price AS adjusted_price
FROM wrap_unwrap w
JOIN {{ source('prices', 'usd') }} p ON w.underlyingToken = p.contract_address
JOIN {{ref('balancer_v3_ethereum_erc4626_token_mapping')}} m ON m.erc4626_token = w.wrappedToken
JOIN {{ source('prices', 'usd') }} p ON w.underlying_token = p.contract_address
AND p.blockchain = 'gnosis'
AND DATE_TRUNC('minute', w.evt_block_time) = DATE_TRUNC('minute', p.minute)
)
Expand Down

0 comments on commit cf6ad26

Please sign in to comment.