diff --git a/cowamm/kpi/competitors/all_competitors_4335231.sql b/cowamm/kpi/competitors/all_competitors_4335231.sql index d8dd4a11..a79ecae4 100644 --- a/cowamm/kpi/competitors/all_competitors_4335231.sql +++ b/cowamm/kpi/competitors/all_competitors_4335231.sql @@ -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 diff --git a/cowamm/kpi/competitors/cow_amm/cow_amm_kpi_4340428.sql b/cowamm/kpi/competitors/cow_amm/cow_amm_kpi_4340428.sql index 699d1bf8..d569a9b1 100644 --- a/cowamm/kpi/competitors/cow_amm/cow_amm_kpi_4340428.sql +++ b/cowamm/kpi/competitors/cow_amm/cow_amm_kpi_4340428.sql @@ -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 diff --git a/cowamm/kpi/competitors/curve/curve_kpis_4232873.sql b/cowamm/kpi/competitors/curve/curve_kpis_4232873.sql index 50b1f81d..e463db40 100644 --- a/cowamm/kpi/competitors/curve/curve_kpis_4232873.sql +++ b/cowamm/kpi/competitors/curve/curve_kpis_4232873.sql @@ -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