gnosis / cowswap

🐮 CowSwap: First Gnosis Protocol v2 UI
https://gnosis.io
GNU General Public License v3.0
113 stars 55 forks source link

Limit Orders #1297

Closed anxolin closed 2 years ago

anxolin commented 3 years ago

Description CowSwap is great swap interface, it protect us from MEV and allow us to exchange ERC20 at best available prices.

But, what if we don't like the available prices? what if we want to trade at better ones. Sure we don't want to be checking every few hours if the market price is now right for us, specially because this can happen at inconvenient times such as while we sleep.

Limit orders is a feature that makes a lot of sense for CowSwap / Gnosis Protocol, and one that has been asked many times in Twitter, Discord, Feedback form, and testing sessions.

One interesting fact is, technically all orders are limit orders at protocol level. This is, right now, when you sign an order you reveal the maximum price you are willing to pay for the asset you are buying.

So, if all orders are already limit orders, why CowSwap doesn't allow limit orders yet?

First reason is because, market orders UX is simpler. You trade at current market prices. Just exchange this token for this other token. Basically, the main Uniswap UX.

Limit orders, in the other hand, are for slightly more advanced users and would probably need to introduce more elements, like historic prices, volumes, some sense of the current order book, and last executed trades. So it felt not a natural first step in the proof of concept of this Coincidence Of Wants protocol (GPv2).

Another reason is that, limit orders might have additional complexities for the solvers (bigger number of open trades), but also there's another challenge to solve, the economical incentive of the execution of the order.

I don't want to extend too much in this forum about this economical incentive, because https://forum.gnosis.io or Discord would be more suitable, but I want just to mention what is this problem about:

One possible solution would be, to let the solvers execute the orders only when price drops enough so they can pay the fee with the generated surplus. This solves the problem! Although, this also mean that the orders won't execute at exactly the price in your limit, but would wait until the price is even better (note this could become a UX problem if we don't manage expectations).

There could be other more advanced solutions, each with their pros/cons, for example implementing some fair system to get the current fee that could be enforced by a contract, so no-one overpays. These family of solutions, would be very interesting, but also more complex in the protocol and UX. It would allow for example, to set some WETH10 or other permitable tokens aside to pay fees.

It looks then, the solution of paying the fee using the surplus would be a good solution as a first step for adding limit orders. To implement this, it would be interesting to research about it's UX and any restrictions, for example:

Proposal This Issue would be to explore further the topics explain above, maybe to define a minimal PoC or define what would an ideal limit order UI would contain.

This issue is also open for comments from anyone, so please let us know your thoughts!

alfetopito commented 2 years ago

Overall reasoning. Closing in favour of the epic https://github.com/gnosis/cowswap/issues/2458