cowprotocol / research

CoW Protocol Research
GNU Lesser General Public License v3.0
0 stars 0 forks source link

research(Contracts): express mutually exclusive orders (per batch or globally) #16

Open acanidio-econ opened 6 months ago

acanidio-econ commented 6 months ago

Problem

Currently, there is no way to express mutually exclusive orders; that is, that solvers should execute only one among several orders placed by the same user. But these mutually exclusive orders could be valuable in several situations:

However, checking whether an order is "canonical" requires checking a price oracle, and costs gas. This cost is limited if the AMM has only two tokens but becomes very expensive if the AMM has multiple tokens. As a consequence, it is not possible right nor to have CoWAMM with more than 2 tokens.

Acceptance criteria

Details

With respect to "sell for any stablecoin" and "sell for any major token" order-type, when an user places such orders, there are multiple orders places on the users' behalf, all grouped under a specific label, and only one of them is executable.

With respect to multi-tokens CoWAMM: Assuming we won't support basket orders (at least, not in the near future), then the AMM will need to trade a single token pair at the time. In practice, the AMM is divided into several "buckets" (say 20). At deployment, a user can specify a token for each bucket. The same token can be specified for multiple buckets. Then, the watchtower creates an order for the AMM by figuring out which "bucket" has the largest difference in value and creating a rebalancing trade for those buckets. The AMM is fully rebalanced throughout a few auctions. The main difficulty is that to check that the "canonical order" created by the watchtower is valid, the smart contract needs to pull several price oracles, which cost gas. But if we have a way to prevent solvers from placing multiple orders per AMM, then this step is not required.

Possible Solutions

Research track

smart contract, solvers, CoWAMM

fleupold commented 4 months ago

Related to https://github.com/cowprotocol/research/issues/3#issuecomment-1784559087 as a nullifier would allow to specify multiple orders with the same nullifier of which only one could be chosen.

If we implement #13 those types of markets could be added at will later on (but may still be good to include in the default market).