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

Fix CoW AMM CoW surplus query #60

Merged
merged 3 commits into from
Nov 5, 2024
Merged

Fix CoW AMM CoW surplus query #60

merged 3 commits into from
Nov 5, 2024

Conversation

fhenneke
Copy link
Contributor

@fhenneke fhenneke commented Nov 5, 2024

This PR updates the query for computing CoW surplus of CoW AMMs for the onboing bounty.

The old query was broken due to 80/20-pools since it used a formula for surplus which worked directly with reserves and product invariant ("non-linear surplus"). The resulted in the potential of negative surplus, messing up bounty rewards:

image

The new query uses surplus as defined in the competition ("linear suplus"). This generalizes to all kinds of CoW AMMs. It also reduces the dependency on a large table which indexes reserves of all CoW AMMs. The results with the updated query (test query) change to this:

image

One change in behavior is that we now do not reward solvers in cases where the limit price set by the solver does not lie on the curve. This is, however, in line with how we treat rewards in general and should not have a major impact.

The old query was broken due to wrong handling of 80/20-pools.
The updated query uses surplus as defined in the auction instead of
relying on computing non-linear surplus using reserves.
where trades.trader in (select address from query_3959044 where blockchain = 'gnosis')
),

cow_surplus_per_batch as (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not including arbitrum AMMs here? I think they also qualify for the bounty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is easy to add that if it qualifies. Let me double check with @harisang.

I mostly tried to stick to what the previous query did. Note, that the query previously used was not the same as the one under version control. It explicitly used tables for ethereum and gnosis, but not arbitrum.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a table for arbitrum. Interestingly, there is no difference in total surplus. I briefly checked the intermediate tables and they seem to work. So I think it is fine to merge this.

the where clause used a column which was not present in the debug table
@fhenneke fhenneke merged commit 5e3d398 into main Nov 5, 2024
1 check passed
@fhenneke fhenneke deleted the fix_cow_amm_cow_surplus branch November 5, 2024 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants