Skip to content

Commit

Permalink
Comptetitor aprs (#75)
Browse files Browse the repository at this point in the history
* New queries to measure the kpis from competitors

* new parameter added because of the previous queries

* Excludes possible negative tvls because of issues with ERC20/ETH transfers

* Formatting

* Added a missing blockchain parameter

* Simplified the querying of all tranactions from a curve pool

* Few comments and adapting to remarks for Curve

* Added filter by x largest pools

* Added/propagated through queries number_of_pools parameter and various comments

* Removed the union for inactive pools. THe left join does the work

* Fixed the sqlfluff

* Moved the folder to kpis/competitors

* New query to replace the uni style querying. they are now grouped in the same query

* Added the project value to classify the pools: uni/ pancake/sushi

* Comments

* Added parameter for time window, and removed avg(tvl), avg(fee)

* upadated default parameter

* Added syncs inline to kpis.

* Added flag uni/pancake/Sushi and parameter for time window

* New default value for day, few comments and renaming

* Changed deployer contract addres for uniswap

* Query to regroup all the different projects kpis together

* Typo for chain_id

Co-authored-by: Felix Leupold <[email protected]>

* fixed typo and added base

* updated kpis to filter before joining and improve performance

* increased number of pools to display

* Adding CoW AMMs to the list of AMMs to monitor

* typo in chain_id

* Adding parameter for time window

* wrong join leading to less pools visible

* Adapting the query to get the info for every chain

* wrong sum for volume/apr in curve and cow_amm kpis

* Renaming table temp + typo

---------

Co-authored-by: Felix Leupold <[email protected]>
  • Loading branch information
PoloX2021 and fleupold authored Nov 29, 2024
1 parent dc1c512 commit 3f95dbd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cowamm/kpi/competitors/all_competitors_4335231.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ select
end as chain_id
from "query_4232873(blockchain='ethereum', competitor_end_time='{{competitor_end_time}}')"
-- there are no significant curve pools on arbitrum/gnosis
where {{blockchain}} = 'ethereum'
where '{{blockchain}}' = 'ethereum'

union distinct

Expand Down
34 changes: 21 additions & 13 deletions cowamm/kpi/competitors/cow_amm/cow_amm_kpi_4340428.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@
select
contract_address,
tvl,
sum(usd_value) over (partition by contract_address order by latest_per_pool) as volume,
365 * sum(surplus_usd / tvl) over (partition by contract_address order by latest_per_pool) as apr
from "query_4340356(blockchain='{{blockchain}}')" as tvl
left join
( --noqa: ST05
select *
from cow_protocol_{{blockchain}}.trades
where
block_time >= date_add('day', -1, (case when '{{competitor_end_time}}' = '2100-01-01' then now() else timestamp '{{competitor_end_time}}' end))
) as t
on
t.tx_hash = tvl.tx_hash
and tvl.contract_address = trader
volume,
apr
from ( --noqa: ST05
select
contract_address,
tvl,
latest_per_pool,
sum(usd_value) over (partition by contract_address order by latest_per_pool desc) as volume,
365 * sum(surplus_usd / tvl) over (partition by contract_address order by latest_per_pool desc) as apr
from "query_4340356(blockchain='{{blockchain}}')" as tvl
left join
( --noqa: ST05
select *
from cow_protocol_{{blockchain}}.trades
where
block_time >= date_add('day', -1, (case when '{{competitor_end_time}}' = '2100-01-01' then now() else timestamp '{{competitor_end_time}}' end))
) as t
on
t.tx_hash = tvl.tx_hash
and tvl.contract_address = trader
)
where latest_per_pool = 1
47 changes: 28 additions & 19 deletions cowamm/kpi/competitors/curve/curve_kpis_4232873.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@
-- {{competitor_end_time}}: The end time of the time window (end_time - 1 day; end_time), defaults to now()
select
contract_address,
fee,
tvl,
sum(amount_usd) over (partition by contract_address order by latest_per_pool) as volume,
365 * sum(amount_usd * fee / tvl) over (partition by contract_address order by latest_per_pool) as apr
-- The first call to 4232976 gets the tvl after each tx to compute volume/tvl
from "query_4232976(blockchain='{{blockchain}}')" as r
left join
( --noqa: ST05
select *
from curve.trades
where
block_time >= date_add('day', -1, (case when '{{competitor_end_time}}' = '2100-01-01' then now() else timestamp '{{competitor_end_time}}' end))
) as t
on
r.contract_address = t.project_contract_address
and r.tx_hash = t.tx_hash
where
latest_per_pool = 1
-- This test avoids any possible issue with reconstructing the reserves of the pool
and tvl > 0
fee,
volume,
apr
from (
select
contract_address,
fee,
tvl,
latest_per_pool,
sum(amount_usd) over (partition by contract_address order by latest_per_pool) as volume,
365 * sum(amount_usd * fee / tvl) over (partition by contract_address order by latest_per_pool) as apr
-- The first call to 4232976 gets the tvl after each tx to compute volume/tvl
from "query_4232976(blockchain='{{blockchain}}')" as r
left join
( --noqa: ST05
select *
from curve.trades
where
block_time >= date_add('day', -1, (case when '{{competitor_end_time}}' = '2100-01-01' then now() else timestamp '{{competitor_end_time}}' end))
) as t
on
r.contract_address = t.project_contract_address
and r.tx_hash = t.tx_hash
where
-- This test avoids any possible issue with reconstructing the reserves of the pool
tvl > 0
)
where latest_per_pool = 1

0 comments on commit 3f95dbd

Please sign in to comment.