Skip to content

Commit

Permalink
[Easy] Fix usage of daily prices (#88)
Browse files Browse the repository at this point in the history
* Fix usage of daily prices

* filter on blockchain where adequate
  • Loading branch information
fleupold authored Dec 10, 2024
1 parent e26240b commit 9c28103
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cowamm/kpi/tvl_by_chain_4096107.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ tvl as (
pool,
token,
balance,
(balance * p.price_close) / pow(10, decimals) as tvl
(balance * p.price) / pow(10, decimals) as tvl
from reserves_by_day as r
inner join prices.day as p
on
r.day = p.timestamp
and p.contract_address = token
and blockchain = '{{blockchain}}'
where latest = 1
)

Expand Down
2 changes: 1 addition & 1 deletion cowamm/profitability/10k_growth/balancer_4106553.sql
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ lp_total_supply as (
tvl as (
select
l.day,
sum(token_balance * price_close) as tvl
sum(token_balance * price) as tvl
from balancer.liquidity as l
inner join pool
on
Expand Down
2 changes: 1 addition & 1 deletion cowamm/profitability/10k_growth/cow_4047078.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ tvl_by_tx as (
tvl as (
select
tvl_complete.day,
balance1 * p1.price_close + balance2 * p2.price_close as tvl
balance1 * p1.price + balance2 * p2.price as tvl
from (
-- join full date range with potentially incomplete data. This results in many rows per day (all pool balances on or before that day)
-- rank() is then used to order join candidates by recency (rank = 1 is the latest pool balances)
Expand Down
4 changes: 2 additions & 2 deletions cowamm/profitability/10k_growth/daily_rebalancing_4055484.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ with date_series as (
daily_price_change as (
select
ds.day,
p1.price_close / previous_p1.price_close as p1,
p2.price_close / previous_p2.price_close as p2
p1.price / previous_p1.price as p1,
p2.price / previous_p2.price as p2
from date_series as ds
inner join prices.day as p1
on
Expand Down
6 changes: 3 additions & 3 deletions cowamm/profitability/10k_growth/hodl_4086902.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ with date_series as (

starting_balance as (
select
5000 / p1.price_close as token_a_start,
5000 / p2.price_close as token_b_start
5000 / p1.price as token_a_start,
5000 / p2.price as token_b_start
from prices.day as p1
inner join prices.day as p2
on
Expand All @@ -29,7 +29,7 @@ starting_balance as (

select
ds.day,
token_a_start * p1.price_close + token_b_start * p2.price_close as current_value_of_investment
token_a_start * p1.price + token_b_start * p2.price as current_value_of_investment
from starting_balance
cross join date_series as ds
inner join prices.day as p1
Expand Down
3 changes: 2 additions & 1 deletion cowamm/profitability/10k_growth/uni_v2_4047194.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-- {{token_a}} - either token of the desired uni pool
-- {{token_b}} - other token of the desired uni pool
-- {{start}} - date as of which the analysis should run
-- {{blockchain}} - the blockchain to evaluate this for

-- Given that we might not have records every day in the source data (e.g. not every day the lp supply may change),
-- but still want to visualize development on a per day basis, we create an auxiliary table with one record per
Expand Down Expand Up @@ -116,7 +117,7 @@ tvl as (
select
balances.day,
balances.contract_address,
sum(balance * price_close / pow(10, decimals)) as tvl
sum(balance * price / pow(10, decimals)) as tvl
from (
-- turns (date, balance0, balance1) into (date, balance0) + (date, balance1)
select
Expand Down
2 changes: 1 addition & 1 deletion cowamm/profitability/invariant_growth/balancer_4106329.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tvl as (
l.day,
l.pool_address,
l.blockchain,
sum(token_balance * price_close) as tvl
sum(token_balance * price) as tvl
from balancer.liquidity as l
inner join pool
on
Expand Down

0 comments on commit 9c28103

Please sign in to comment.