Skip to content

Commit

Permalink
Change prices.usd to prices.minute
Browse files Browse the repository at this point in the history
  • Loading branch information
fleupold committed Nov 29, 2024
1 parent 4046e60 commit 9d4b5a7
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .github/nitpicks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- markdown: |
Are you _sure_ you want to use the legacy `prices.minute` table? Consider using `prices.minute` (https://docs.dune.com/data-catalog/curated/prices/overview)
pathFilter:
- "**/*.sql"
contentFilter:
- '(prices\.usd)'
10 changes: 10 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ jobs:
run: pip install sqlfluff
- name: Run SQLFluff
run: sqlfluff lint .
nitpicker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: ethanis/nitpicker@v1
with:
nitpicks: ".github/nitpicks.yml"
token: "${{ secrets.GITHUB_TOKEN }}"
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ recent_tvl as (
latest_per_pool,
(reserve0 * p0.price / pow(10, p0.decimals)) + (reserve1 * p1.price / pow(10, p1.decimals)) as tvl
from reserves as r
inner join prices.usd as p0
inner join prices.minute as p0
on
date_trunc('minute', block_time) = p0.minute
and token0 = p0.contract_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ tvl_volume_per_swap as (
and syncs.evt_index + 1 = swaps.evt_index
inner join pool
on syncs.contract_address = pool.contract_address
inner join prices.usd as p0
inner join prices.minute as p0
on
date_trunc('minute', syncs.evt_block_time) = p0.minute
and syncs.token0 = p0.contract_address
inner join prices.usd as p1
inner join prices.minute as p1
on
date_trunc('minute', syncs.evt_block_time) = p1.minute
and syncs.token1 = p1.contract_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ select distinct
evt_block_time,
reserve0 * p0.price * power(10, -p0.decimals) + reserve1 * p1.price * power(10, -p1.decimals) as tvl
from syncs as s
inner join prices.usd as p0
inner join prices.minute as p0
on
token0 = p0.contract_address
and p0.minute = evt_block_time
inner join prices.usd as p1
inner join prices.minute as p1
on
token1 = p1.contract_address
and p1.minute = evt_block_time
Expand Down
2 changes: 1 addition & 1 deletion cowamm/kpi/tvl_by_chain_4096107.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tvl as (
balance,
(balance * p.price_close) / pow(10, decimals) as tvl
from reserves_by_day as r
inner join prices.usd_daily as p
inner join prices.minute_daily as p
on
r.day = p.day
and p.contract_address = token
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 @@ -102,7 +102,7 @@ tvl as (
on
l.pool_address = pool.pool_address
and l.blockchain = pool.blockchain
left join prices.usd_daily as p1
left join prices.minute_daily as p1
on
l.blockchain = p1.blockchain
and l.token_address = p1.contract_address
Expand Down
4 changes: 2 additions & 2 deletions cowamm/profitability/10k_growth/cow_4047078.sql
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ tvl as (
-- performance optimisation: only look at the last update of the day
and tvl.latest = 1
) as tvl_complete
inner join prices.usd_daily as p1
inner join prices.minute_daily as p1
on
tvl_complete.day = p1.day
and p1.contract_address = token1
and p1.blockchain = '{{blockchain}}'
inner join prices.usd_daily as p2
inner join prices.minute_daily as p2
on
tvl_complete.day = p2.day
and p2.contract_address = token2
Expand Down
8 changes: 4 additions & 4 deletions cowamm/profitability/10k_growth/daily_rebalancing_4055484.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ daily_price_change as (
p1.price_close / previous_p1.price_close as p1,
p2.price_close / previous_p2.price_close as p2
from date_series as ds
inner join prices.usd_daily as p1
inner join prices.minute_daily as p1
on
p1.day = ds.day
and p1.contract_address = {{token_a}}
left join prices.usd_daily as previous_p1
left join prices.minute_daily as previous_p1
on
previous_p1.day = ds.day - interval '1' day
-- avoid computing price change on first day
and previous_p1.day >= date(timestamp '{{start}}')
and previous_p1.contract_address = {{token_a}}
inner join prices.usd_daily as p2
inner join prices.minute_daily as p2
on
p2.day = ds.day
and p2.contract_address = {{token_b}}
left join prices.usd_daily as previous_p2
left join prices.minute_daily as previous_p2
on
previous_p2.day = ds.day - interval '1' day
-- avoid computing price change on first day
Expand Down
8 changes: 4 additions & 4 deletions cowamm/profitability/10k_growth/hodl_4086902.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ starting_balance as (
select
5000 / p1.price_close as token_a_start,
5000 / p2.price_close as token_b_start
from prices.usd_daily as p1
inner join prices.usd_daily as p2
from prices.minute_daily as p1
inner join prices.minute_daily as p2
on
p1.day = p2.day
and p1.day = date(timestamp '{{start}}')
Expand All @@ -32,11 +32,11 @@ select
token_a_start * p1.price_close + token_b_start * p2.price_close as current_value_of_investment
from starting_balance
cross join date_series as ds
inner join prices.usd_daily as p1
inner join prices.minute_daily as p1
on
ds.day = p1.day
and p1.contract_address = {{token_a}}
inner join prices.usd_daily as p2
inner join prices.minute_daily as p2
on
ds.day = p2.day
and p2.contract_address = {{token_b}}
Expand Down
2 changes: 1 addition & 1 deletion cowamm/profitability/10k_growth/uni_v2_4047194.sql
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ tvl as (
token1 as token
from reserve_balances
) as balances
left join prices.usd_daily as prices
left join prices.minute_daily as prices
on
blockchain = '{{blockchain}}'
and balances.token = prices.contract_address
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 @@ -55,7 +55,7 @@ tvl as (
on
l.pool_address = pool.pool_address
and l.blockchain = pool.blockchain
left join prices.usd_daily as p1
left join prices.minute_daily as p1
on
l.blockchain = p1.blockchain
and l.token_address = p1.contract_address
Expand Down
4 changes: 2 additions & 2 deletions cowamm/profitability/invariant_growth/uni_v2_4060136.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ tvl_volume_per_swap as (
and syncs.evt_index + 1 = swaps.evt_index
inner join pool
on syncs.contract_address = pool.contract_address
inner join prices.usd as p0
inner join prices.minute as p0
on
date_trunc('minute', syncs.evt_block_time) = p0.minute
and syncs.token0 = p0.contract_address
inner join prices.usd as p1
inner join prices.minute as p1
on
date_trunc('minute', syncs.evt_block_time) = p1.minute
and syncs.token1 = p1.contract_address
Expand Down
2 changes: 1 addition & 1 deletion cowamm/tvl_by_tx_4059700.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tvl as (
price,
balance * price / POW(10, decimals) as tvl
from balances_by_tx as b
inner join prices.usd as p
inner join prices.minute as p
on
p.minute = DATE_TRUNC('minute', evt_block_time)
and b.token = p.contract_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ outgoing_cow as (
conversion_prices as (
select
(
select avg(price) from prices.usd
select avg(price) from prices.minute
where
blockchain = 'ethereum'
and contract_address = 0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab
and date(minute) = cast('{{end_time}}' as timestamp) - interval '1' day
) as cow_price,
(
select avg(price) from prices.usd
select avg(price) from prices.minute
where
blockchain = 'ethereum'
and contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ imported_prices_per_minute_with_usd_prices as (
ippm.price_unit_eth * p.price as price_unit,
ippm.price_unit_eth * p.price / pow(10, ippm.decimals) as price_atom,
source
from imported_prices_per_minute as ippm inner join prices.usd as p on ippm.minute = p.minute
from imported_prices_per_minute as ippm inner join prices.minute as p on ippm.minute = p.minute
where p.contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 and blockchain = 'ethereum'
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ fees_and_costs as (
conversion_prices as (
select
(
select avg(price) from prices.usd
select avg(price) from prices.minute
where
blockchain = 'ethereum'
and contract_address = 0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab
and date(minute) = cast('{{end_time}}' as timestamp) - interval '1' day
) as cow_price,
(
select avg(price) from prices.usd
select avg(price) from prices.minute
where
blockchain = 'ethereum'
and contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Expand Down
4 changes: 2 additions & 2 deletions cowprotocol/accounting/slippage/slippage_prices_4064601.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ precise_prices as (
avg(price) as price_unit,
avg(price) / pow(10, decimals) as price_atom
from
prices.usd
prices.minute
inner join token_times
on
date_trunc('hour', minute) = hour
Expand Down Expand Up @@ -126,7 +126,7 @@ native_token_prices as (
18 as decimals,
avg(price) as price_unit,
avg(price) / pow(10, 18) as price_atom
from prices.usd
from prices.minute
where
blockchain = '{{blockchain}}'
and contract_address = (select native_token_address from wrapped_native_token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ failed_settlements as (
name as solver_name
from
ethereum.transactions
inner join prices.usd as p on p.minute = date_trunc('minute', block_time) --noqa: LT02
inner join prices.minute as p on p.minute = date_trunc('minute', block_time) --noqa: LT02
and blockchain = 'ethereum'
and contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
inner join cow_protocol_ethereum.solvers on "from" = address --noqa: LT02
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ failed_settlements as (
environment as solver_env,
name as solver_name
from ethereum.transactions
inner join prices.usd as p on p.minute = date_trunc('minute', block_time) --noqa: LT02
inner join prices.minute as p on p.minute = date_trunc('minute', block_time) --noqa: LT02
and blockchain = 'ethereum'
and contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
inner join cow_protocol_ethereum.solvers on "from" = address --noqa: LT02
Expand Down
4 changes: 2 additions & 2 deletions cowprotocol/solver_dashboard/cow_rewards_totals_1372979.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- This query computes the total amount of COW distributed as rewards
-- it uses all of the outgoing transactions from the rewards safe
-- and the price is converted to USD using the latest price from the prices.usd_latest table
-- and the price is converted to USD using the latest price from the prices.minute_latest table
-- the inception date is defined as 2022-03-01

-- finally the query calculates the daily payout and the project budget for the year
Expand All @@ -26,7 +26,7 @@ addresses as (
),

latest_cow_price as (
select price from prices.usd_latest
select price from prices.minute_latest
where
blockchain = '{{blockchain}}'
and contract_address = (select token from addresses where blockchain = '{{blockchain}}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ select
*,
total_cow_rewarded * (
select price
from prices.usd_latest
from prices.minute_latest
where
contract_address = 0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab
and blockchain = 'ethereum'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ conversion_prices as (
(
select avg(price)
from
prices.usd
prices.minute
where
blockchain = 'ethereum'
and contract_address = 0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab
Expand All @@ -116,7 +116,7 @@ conversion_prices as (
(
select avg(price)
from
prices.usd
prices.minute
where
blockchain = 'ethereum'
and contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Expand Down

0 comments on commit 9d4b5a7

Please sign in to comment.