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

Remove restriction on quote rewards for limit orders #328

Merged
merged 9 commits into from
Jan 10, 2024

Conversation

fhenneke
Copy link
Collaborator

@fhenneke fhenneke commented Jan 4, 2024

When switching to all orders being limit orders we need to adapt how we compute quote rewards. At the moment, only market orders are eligible for quote rewards. With the current code this would mean that no quotes would receive rewards.

This PR removes testing the kind of an order when querying for quote solvers. This means that all quotes associated with executed orders are elibible for rewards.

The impact of rewarding more quotes is expected to be small.

This change has to be done merged toether with a PR on syncing quote solvers to dune.

before this change only market orders were eligible for quote rewards
and only in that case a quote_solver was fetched.
with this change, a quote_solver is always fetched (if it exists)
Copy link
Contributor

@harisang harisang left a comment

Choose a reason for hiding this comment

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

Looks good!

@@ -3,8 +3,7 @@ with winning_quotes as (SELECT concat('0x', encode(oq.solver, 'hex')) as solver,
FROM trades t
INNER JOIN orders o ON order_uid = uid
JOIN order_quotes oq ON t.order_uid = oq.order_uid
WHERE o.class = 'market'
AND block_number BETWEEN {{start_block}} AND {{end_block}}
WHERE block_number BETWEEN {{start_block}} AND {{end_block}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just be careful with between since it uses a closed interval block_number in [start, end] while in other places we have block_number in (start, end]. Probably wouldn't hurt to eliminate all uses of BETWEEN.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True. I created a draft PR handling that here: #329

@harisang
Copy link
Contributor

harisang commented Jan 7, 2024

I am now thinking whether we should implement this change so that there is no change in the rewards paid,in the sense of paying rewards only for "in-market" limit orders. Specifically, instead of dropping the condition about whether the order is market or limit, we could replace it with the following

((o.kind = 'sell' AND o.buy_amount <= oq.buy_amount) OR (o.kind='buy' AND o.sell_amount >= oq.sell_amount))

@fhenneke
Copy link
Collaborator Author

fhenneke commented Jan 8, 2024

Using the restriction ((o.kind = 'sell' AND o.buy_amount <= oq.buy_amount) OR (o.kind='buy' AND o.sell_amount >= oq.sell_amount)) seems fine. It is closer to the spirit of the quotes CIP.

It is not equivalent to the original result though in some experiments I did:

with winning_quotes as (SELECT concat('0x', encode(oq.solver, 'hex')) as solver,
                               oq.order_uid
                        FROM trades t
                               INNER JOIN orders o ON order_uid = uid
                               JOIN order_quotes oq ON t.order_uid = oq.order_uid
                        WHERE o.class = 'market'
                          AND block_number BETWEEN 18933106 - 10000 AND 18933106
                          AND oq.solver != '\x0000000000000000000000000000000000000000')
SELECT solver, count(*) AS num_quotes
FROM winning_quotes

gives different results compared to

with winning_quotes as (SELECT concat('0x', encode(oq.solver, 'hex')) as solver,
                               oq.order_uid
                        FROM trades t
                               INNER JOIN orders o ON order_uid = uid
                               JOIN order_quotes oq ON t.order_uid = oq.order_uid
                        WHERE ((o.kind = 'sell' AND o.buy_amount <= oq.buy_amount)
                            OR (o.kind='buy' AND o.sell_amount >= oq.sell_amount))
                          AND block_number BETWEEN 18933106 - 10000 AND 18933106
                          AND oq.solver != '\x0000000000000000000000000000000000000000')
SELECT solver, count(*) AS num_quotes
FROM winning_quotes

I did not drill into why that is though.

@harisang
Copy link
Contributor

harisang commented Jan 10, 2024

Using the restriction ((o.kind = 'sell' AND o.buy_amount <= oq.buy_amount) OR (o.kind='buy' AND o.sell_amount >= oq.sell_amount)) seems fine. It is closer to the spirit of the quotes CIP.

It is not equivalent to the original result though in some experiments I did:

with winning_quotes as (SELECT concat('0x', encode(oq.solver, 'hex')) as solver,
                               oq.order_uid
                        FROM trades t
                               INNER JOIN orders o ON order_uid = uid
                               JOIN order_quotes oq ON t.order_uid = oq.order_uid
                        WHERE o.class = 'market'
                          AND block_number BETWEEN 18933106 - 10000 AND 18933106
                          AND oq.solver != '\x0000000000000000000000000000000000000000')
SELECT solver, count(*) AS num_quotes
FROM winning_quotes

gives different results compared to

with winning_quotes as (SELECT concat('0x', encode(oq.solver, 'hex')) as solver,
                               oq.order_uid
                        FROM trades t
                               INNER JOIN orders o ON order_uid = uid
                               JOIN order_quotes oq ON t.order_uid = oq.order_uid
                        WHERE ((o.kind = 'sell' AND o.buy_amount <= oq.buy_amount)
                            OR (o.kind='buy' AND o.sell_amount >= oq.sell_amount))
                          AND block_number BETWEEN 18933106 - 10000 AND 18933106
                          AND oq.solver != '\x0000000000000000000000000000000000000000')
SELECT solver, count(*) AS num_quotes
FROM winning_quotes

I did not drill into why that is though.

If we want to push it a bit more, we could also exclude all partially fillable orders, so I would actually go with this.

with winning_quotes as (SELECT concat('0x', encode(oq.solver, 'hex')) as solver,
                               oq.order_uid
                        FROM trades t
                               INNER JOIN orders o ON order_uid = uid
                               JOIN order_quotes oq ON t.order_uid = oq.order_uid
                        WHERE ((o.kind = 'sell' AND o.buy_amount <= oq.buy_amount)
                            OR (o.kind='buy' AND o.sell_amount >= oq.sell_amount))
                          AND o.partially_fillable='f'
                          AND block_number BETWEEN 18933106 - 10000 AND 18933106
                          AND oq.solver != '\x0000000000000000000000000000000000000000')
SELECT count(*) AS num_quotes
FROM winning_quotes

- only orders where the amounts are below quoted amounts are eligible
- only orders which are not partially fillable are eligible
@fhenneke
Copy link
Collaborator Author

I added the restriction from your last comment.

Should we change the query in dyne sync too or change the dune query on period rewards?

fhenneke added a commit to cowprotocol/dune-sync that referenced this pull request Jan 10, 2024
- only orders where the amounts are below quoted amounts are eligible
- only orders which are not partially fillable are eligible

this makes it consistent with the new code in
cowprotocol/solver-rewards#328
@harisang
Copy link
Contributor

Oh good. We can first merge PR #330, then rebase this PR so that there is not all this noise here and finally fix the dune-sync. I suspect then that the only thing that might be needed is to manually run the payouts next week in order to pinpoint the block where the Dune data changed, so that we align our script with the Dune dashboard

@harisang harisang merged commit 2293623 into main Jan 10, 2024
6 checks passed
@harisang harisang deleted the zero_fee_quote_rewards branch January 10, 2024 22:07
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants