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

Restrict orders which receive quote rewards #61

Merged
merged 1 commit into from
Jan 10, 2024
Merged

Conversation

fhenneke
Copy link
Contributor

@fhenneke fhenneke commented Jan 10, 2024

We decided to restrict a bit more quotes which can receive rewards to be in line with the original spirit of CIP-27.

This PR would make the data synced to dune consistent with cowprotocol/solver-rewards#328

The additional restrictions are:

  • only orders where the amounts are below quoted amounts are eligible
  • only orders which are not partially fillable are eligible

Note that the convention for block ranges in this repo is different from the convention in the solver rewards repo. This inconsistency is maybe a bit confusing. But not a problem for any of the queries since this repo is only about syncing data.

This refines PR #59

- 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
@fhenneke fhenneke requested a review from harisang January 10, 2024 11:45
@harisang harisang merged commit 54d6464 into main Jan 10, 2024
4 of 6 checks passed
@harisang harisang deleted the restrict_quote_rewards branch January 10, 2024 18:15
harisang pushed a commit to cowprotocol/solver-rewards that referenced this pull request Feb 5, 2024
This PR implements the same change as this
PR(cowprotocol/dune-sync#73) for dune-sync.
Tests have been adapted to the new query. It should be live in
production before the payment on 2024-02-06.

Text from there:

We currently classify limit orders as in-market based on quoted amounts,
see [dune sync #61](cowprotocol/dune-sync#61).
As it turns out, those amounts do not take fees into account for limit
orders. Therefore we misclassify some orders whicch are out-of-market as
in-market.

This PR changes the classification of in-market orders to be in line
with how market orders are created in the frontend: If the quoted
amounts are `oq.sell_amount` and `oq.buy_amount` and the estimated fee
is `oq.gas_amount * oq.gas_price / oq.sell_price` then a market order
sell order would have charged a fee of `oq.gas_amount * oq.gas_price /
oq.sell_price` and exchanged the remaining abount `oq.sell_amount -
oq.gas_amount * oq.gas_price / oq.sell_price` at the quoted exchange
rate `oq.buy_amount / oq.sell_amount` to a buy amount of
`(oq.sell_amount - oq.gas_amount * oq.gas_price / oq.sell_price) /
oq.sell_amount * oq.buy_amount`. Thus an order would be in-market if
`o.buy_amount <= (oq.sell_amount - oq.gas_amount * oq.gas_price /
oq.sell_price) / oq.sell_amount * oq.buy_amount`, whoch is equivalent to
`(oq.sell_amount - oq.gas_amount * oq.gas_price / oq.sell_token_price) *
oq.buy_amount >= o.buy_amount * oq.sell_amount`.

For a buy order a reasonable market order would have traded
`oq.sell_amount + oq.gas_amount * oq.gas_price / oq.sell_token_price` to
`oq.buy_amount`. Thus an order is regarded as in-market if
`o.sell_amount >= oq.sell_amount + oq.gas_amount * oq.gas_price /
oq.sell_token_price`.

These rules are implemented in this PR.

Note that those rules are not really applicable to paartially-fillable
orders. It can happen that an execution for the full amount is not
possible (out-of-market) but smaller chunks can be executed. When that
usecase arises we need to revisit this code.
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