Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change prices.usd to prices.minute #76

Merged
merged 7 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.usd` table? Consider using `prices.minute` (https://docs.dune.com/data-catalog/curated/prices/overview)
pathFilter:
- "**/*.sql"
contentFilter: # \+ filters for added lines only
- '(\+.*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 @@ -47,7 +47,7 @@ transfers as (
),

-- rebuilds the reserves from the transfers
-- ETH transfers are not considered
-- ETH transfers are not considered
reserves as (
select
contract_address,
Expand Down Expand Up @@ -77,13 +77,13 @@ 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
date_trunc('minute', block_time) = p0.timestamp
and token0 = p0.contract_address
inner join prices.usd as p1
inner join prices.minute as p1
on
date_trunc('minute', block_time) = p1.minute
date_trunc('minute', block_time) = p1.timestamp
and token1 = p1.contract_address
where latest_per_tx = 1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ 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
date_trunc('minute', syncs.evt_block_time) = p0.timestamp
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
date_trunc('minute', syncs.evt_block_time) = p1.timestamp
and syncs.token1 = p1.contract_address
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ 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
and p0.timestamp = evt_block_time
inner join prices.minute as p1
on
token1 = p1.contract_address
and p1.minute = evt_block_time
and p1.timestamp = evt_block_time
where latest = 1
order by tvl desc
limit {{number_of_pools}}
4 changes: 2 additions & 2 deletions cowamm/kpi/tvl_by_chain_4096107.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ 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.day as p
on
r.day = p.day
r.day = p.timestamp
and p.contract_address = token
where latest = 1
)
Expand Down
4 changes: 2 additions & 2 deletions cowamm/profitability/10k_growth/balancer_4106553.sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ tvl as (
on
l.pool_address = pool.pool_address
and l.blockchain = pool.blockchain
left join prices.usd_daily as p1
left join prices.day as p1
on
l.blockchain = p1.blockchain
and l.token_address = p1.contract_address
and l.day = p1.day
and l.day = p1.timestamp
group by 1
),

Expand Down
8 changes: 4 additions & 4 deletions cowamm/profitability/10k_growth/cow_4047078.sql
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ 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.day as p1
on
tvl_complete.day = p1.day
tvl_complete.day = p1.timestamp
and p1.contract_address = token1
and p1.blockchain = '{{blockchain}}'
inner join prices.usd_daily as p2
inner join prices.day as p2
on
tvl_complete.day = p2.day
tvl_complete.day = p2.timestamp
and p2.contract_address = token2
and p2.blockchain = '{{blockchain}}'
where latest = 1
Expand Down
20 changes: 10 additions & 10 deletions cowamm/profitability/10k_growth/daily_rebalancing_4055484.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ 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.day as p1
on
p1.day = ds.day
p1.timestamp = ds.day
and p1.contract_address = {{token_a}}
left join prices.usd_daily as previous_p1
left join prices.day as previous_p1
on
previous_p1.day = ds.day - interval '1' day
previous_p1.timestamp = ds.day - interval '1' day
-- avoid computing price change on first day
and previous_p1.day >= date(timestamp '{{start}}')
and previous_p1.timestamp >= date(timestamp '{{start}}')
and previous_p1.contract_address = {{token_a}}
inner join prices.usd_daily as p2
inner join prices.day as p2
on
p2.day = ds.day
p2.timestamp = ds.day
and p2.contract_address = {{token_b}}
left join prices.usd_daily as previous_p2
left join prices.day as previous_p2
on
previous_p2.day = ds.day - interval '1' day
previous_p2.timestamp = ds.day - interval '1' day
-- avoid computing price change on first day
and previous_p2.day >= date(timestamp '{{start}}')
and previous_p2.timestamp >= date(timestamp '{{start}}')
and previous_p2.contract_address = {{token_b}}
)

Expand Down
16 changes: 8 additions & 8 deletions cowamm/profitability/10k_growth/hodl_4086902.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ 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.day as p1
inner join prices.day as p2
on
p1.day = p2.day
and p1.day = date(timestamp '{{start}}')
p1.timestamp = p2.timestamp
and p1.timestamp = date(timestamp '{{start}}')
and p1.contract_address = {{token_a}}
and p2.contract_address = {{token_b}}
)
Expand All @@ -32,12 +32,12 @@ 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.day as p1
on
ds.day = p1.day
ds.day = p1.timestamp
and p1.contract_address = {{token_a}}
inner join prices.usd_daily as p2
inner join prices.day as p2
on
ds.day = p2.day
ds.day = p2.timestamp
and p2.contract_address = {{token_b}}
order by 1 desc
4 changes: 2 additions & 2 deletions cowamm/profitability/10k_growth/uni_v2_4047194.sql
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ tvl as (
token1 as token
from reserve_balances
) as balances
left join prices.usd_daily as prices
left join prices.day as prices
on
blockchain = '{{blockchain}}'
and balances.token = prices.contract_address
and balances.day = prices.day
and balances.day = prices.timestamp
group by balances.day, balances.contract_address
),

Expand Down
4 changes: 2 additions & 2 deletions cowamm/profitability/invariant_growth/balancer_4106329.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ tvl as (
on
l.pool_address = pool.pool_address
and l.blockchain = pool.blockchain
left join prices.usd_daily as p1
left join prices.day as p1
on
l.blockchain = p1.blockchain
and l.token_address = p1.contract_address
and l.day = p1.day
and l.day = p1.timestamp
group by l.day, l.pool_address, l.blockchain
)

Expand Down
8 changes: 4 additions & 4 deletions cowamm/profitability/invariant_growth/uni_v2_4060136.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ 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
date_trunc('minute', syncs.evt_block_time) = p0.timestamp
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
date_trunc('minute', syncs.evt_block_time) = p1.timestamp
and syncs.token1 = p1.contract_address
where syncs.evt_block_time >= date(timestamp '{{start}}')
)
Expand Down
4 changes: 2 additions & 2 deletions cowamm/tvl_by_tx_4059700.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ 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)
p.timestamp = 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,18 +76,18 @@ 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
and date(timestamp) = 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
and date(minute) = cast('{{end_time}}' as timestamp) - interval '1' day
and date(timestamp) = cast('{{end_time}}' as timestamp) - interval '1' day
) as eth_price
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ with imported_prices as (
imported_prices_per_minute as (
select -- noqa: ST06
token_address,
date_trunc('minute', time) as minute, --noqa: RF04
date_trunc('minute', time) as timestamp, --noqa: RF04
decimals,
source,
avg(price_unit_eth) as price_unit_eth
Expand All @@ -42,13 +42,13 @@ 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.timestamp = p.timestamp
where p.contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 and blockchain = 'ethereum'
)

select -- noqa: ST06
token_address,
date_trunc('hour', minute) as hour, --noqa: RF04
date_trunc('hour', timestamp) as hour, --noqa: RF04
decimals,
source,
avg(price_unit) as price_unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ 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
and date(timestamp) = 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
and date(minute) = cast('{{end_time}}' as timestamp) - interval '1' day
and date(timestamp) = cast('{{end_time}}' as timestamp) - interval '1' day
) as eth_price
),

Expand Down
12 changes: 6 additions & 6 deletions cowprotocol/accounting/slippage/slippage_prices_4064601.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ with token_times as (
-- Precise prices are prices from the Dune price feed.
precise_prices as (
select -- noqa: ST06
date_trunc('hour', minute) as hour, --noqa: RF04
date_trunc('hour', timestamp) as hour, --noqa: RF04
token_address,
decimals,
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
date_trunc('hour', timestamp) = hour
and contract_address = token_address
and blockchain = '{{blockchain}}'
group by 1, 2, 3
Expand Down Expand Up @@ -121,16 +121,16 @@ wrapped_native_token as (
-- The price of the native token is reconstructed from it chain-dependent wrapped version.
native_token_prices as (
select -- noqa: ST06
date_trunc('hour', minute) as hour, --noqa: RF04
date_trunc('hour', timestamp) as hour, --noqa: RF04
0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee as token_address,
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)
and minute >= cast('{{start_time}}' as timestamp) and minute < cast('{{end_time}}' as timestamp)
and timestamp >= cast('{{start_time}}' as timestamp) and timestamp < cast('{{end_time}}' as timestamp)
group by 1, 2, 3
)

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.timestamp = 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.timestamp = 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
Loading