-
Notifications
You must be signed in to change notification settings - Fork 90
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
Convert executed_fee_amount to surplus token #3224
base: main
Are you sure you want to change the base?
Conversation
Reminder: Please consider backward compatibility when modifying the API specification.
Caused by: |
The change looks trivial, but I don't have a full picture of these fee migrations and PRs ordering, so I can't think of any implications atm. I need to go over other PRs again. |
// convert to buy token using executed amounts which are a very good | ||
// approximation of UCP prices conversion rate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be false for multiple reasons:
- I know of at least 1 integration that created their orders with
buy_amount: 1
out of convenience since cow protocol's competition would still protect this order by giving it a good price - applying a generous slippage to your price would introduce an error
I think in order to make this change correct we'd have to use the actual settlement's UCP to convert this price. For orders with partial fills even multiple prices of the respective settlements.
I believe this might not even be a huge change. Our big order SQL query already has to join all the relevant trades while computing sum_fee
. If this logic would be moved into the SQL query we should get actually accurate prices while still not having to change how the underlying gets stored in the DB.
Is that correct / reasonable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, you are right. So effectively we'd be using an average of the actual UCPs of each fill for converting the fees. That makes sense to me and should indeed be accurate. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question regarding Note 2: why we are not using executed_fee_amount
anymore?
This was how we used to model gas fees before, which was less accurate because the fee was determined at the order creation time, and kept fixed regardless if the order was settled right away or 10 minutes after, for example. Today, solvers define the amount of fee they want to take for each order at the solving time, and if order is not settled, next auction they can define a different fee for the same order if the gas price increased, for example. Solvers also have freedom to take more/less of a fee then what are the gas costs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments above added more context.
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
Description
As part of the initiative to show all executed order fees in surplus tokens, we have to convert the
executed_fee_amount
from sell token to surplus token. This is needed by frontend and other integrators, so that ALL fees are in surplus token and easily summarized.As a reminder,
executed_fee_amount
represents executed version of a fixedfee_amount
fee that is part of the signed order and it's always assumed that it is expressed in sell token. But we can easily convert the EXECUTED REPRESENTATION of this fee into surplus token by following this math:This math is 100% equal to using uniform clearing prices to convert between fee in sell and buy tokens, as already used in the existing code:
https://github.com/cowprotocol/services/blob/main/crates/autopilot/src/domain/settlement/trade/math.rs#L126-L129 :
Note 1: This PR only changes how the executed version of this fee is represented over the API. It does not change anything in the database, so it also does not change our assumption of how the
fee_amount
is saved internally.Note 2: Only > ~2 year old orders are affected by this. All newer orders have
executed_fee_amount = 0
.Note 3: These old orders will have a bad total fee shown when this PR is merged. We need #3184 merged as well (and all consequent data migrations) so that all fees are finally shown in surplus tokens.
Changes
fee_amount
is now shown in surplus tokenHow to test
Confirmed on several examples of orders that have fee_amount > 0.