cowprotocol / services

Off-chain services for CoW Protocol
https://cow.fi/
Other
171 stars 67 forks source link

bug: Don't count surplus of liquidity JIT orders in autopilot #2684

Closed MartinquaXD closed 4 months ago

MartinquaXD commented 4 months ago

Problem

Unless I'm misreading things the autopilot currently sums up surplus for all orders traded in an auction.

Impact

Since JIT orders can not be differentiated from regular cowswap orders they would currently count towards surplus in the autopilot which might skew further analytics or alerting based on that data.

Expected behaviour

Only orders that are eligible to count towards surplus actually do that in the autopilot score computation for settlements found on-chain. When adding this exception for liquidity JIT orders we might as well also add code to allow surplus from CoW AMM JIT orders. Another thing that might be tackled in a separate PR is not counting surplus for any regular cowswap order that was not part of the associated auction. My understanding is that if an order was not part of an auction it should not count towards surplus. This would mostly happen if the solver crawls the orderbook on its own to add any open orders that were not in the respective auction for some reason.

sunce86 commented 4 months ago

After some thinking, should we fix this by actually counting the surplus from JIT orders in the driver (and not fix it by NOT counting the surplus from JIT in the autopilot)? Do we have a strong reason to exclude JIT orders from surplus/score calculation?

JIT orders cant be recognized from the onchain settlement and in order to exclude them, we need to fetch some offchain data which is a step back from decentralization so we should have a strong reason for it?

cc @harisang or @fhenneke

fleupold commented 4 months ago

Counting jit orders for surplus would completely break the mechanism. A solver could just come up with a trade willing to sell 1 trillion dollars for 1c and settle it against itself (not losing any money). This would create amazing surplus and likely make them win the competition.

It is therefore crucial that all orders which can contribute to surplus have been available to all solvers (so there is fair game in settling them). The reason why CoW AMM orders can become surplus capturing JIT orders is that we will provide a list of eligible JIT order authors in the auction instance so all solvers can index their logic and settle them.

fhenneke commented 4 months ago

I do not have a strong opinion on this.

Having jit orders generate surplus without any oversight will cause problems. For example, it becomes easier to break social consensus rules on wash trading, as @fleupold pointed out.

If there is no way of distinguishing jit orders from other order (from the point of view of the autopilot), this might be a more general problem though in a world with colocated drivers. Then settling a jit order might be similar to just lying about surplus to the autopilot. I thought that detecting this was possible and that a rule of the form "only CoW AMM jit orders are allowed to have surplus" would be enforceable in the autopilot/post processing. Is it not?