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

Include Full Fee Amount For Limit Orders #792

Merged
merged 4 commits into from
Nov 17, 2022

Conversation

nlordell
Copy link
Contributor

Fixes #770

This PR makes sure limit orders also set their full_fee_amount. Specifically, CoW Protocol orders have 2 different fee fields:

  • fee_amount: This is the actual fee amount that we charge the user. In order to make trading more attractive on CoW Swap, we have a few "knobs" for configuring subsidies on orders used to compute this amount. For limit orders, this is the analogous to surplus_fee which is the actual fee we change the user (but instead of it being a pro-rated fee, it is taken from the order's surplus).
  • full_fee_amount: This is the actual expected "cost" of executing the order. We store this for a couple of reasons:
    1. Primary reason is that we want to use this value in the objective function and not the actual fee amount. The reason for this is we want competition to be done without taking subsidies into account.
    2. Secondary reason (and much less important) is to help in debugging and make sure our fee estimation is working as expected and somewhat accurate (we should compare these values with the actual on-chain gas costs of settlement executions).

These fields should be accurate for limit orders now 🎉.

Test Plan

Unit test to check that this field is being set. It gets read in the same way that it gets read for regular orders during auction building.

@nlordell nlordell requested a review from a team as a code owner November 16, 2022 15:31
crates/autopilot/src/database/orders.rs Outdated Show resolved Hide resolved
crates/shared/src/order_quoting.rs Outdated Show resolved Hide resolved
Comment on lines +185 to +187
/// the order on chain. This is the fee in full without any subsidies. The
/// fee is denoted in the sell token.
pub full_fee_amount: U256,
Copy link
Contributor

Choose a reason for hiding this comment

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

Types are awesome. The fact that this is in the sell token should be reflected by the type IMO. That'd be really nice. But obviously outside the scope of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fact that this is in the sell token should be reflected by the type IMO.

That would be the holy grail! We used to have a graph-based price fining algorithm for the first version of this project (Gnosis Protocol it was called) - and mixing up amounts for different tokens was one of the primary causes of logic bugs.

@nlordell nlordell force-pushed the include-full-fee-amount-for-limit-orders branch from 8dce72d to 11ae6af Compare November 17, 2022 12:18
@nlordell nlordell enabled auto-merge (squash) November 17, 2022 12:19
@nlordell nlordell merged commit 5e887e6 into main Nov 17, 2022
@nlordell nlordell deleted the include-full-fee-amount-for-limit-orders branch November 17, 2022 12:23
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2022
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.

Full fee amount not being populated for limit orders.
4 participants