cowprotocol / research

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

research(contracts): intent market abstractions #13

Open mfw78 opened 5 months ago

mfw78 commented 5 months ago

Problem

The current message signing enforces that an intent's delivery / metadata is unnecessarily bound to the type of market in which the intent is placed. In this case, the type of intent is an "ERC-20 to ERC-20" swap intent. This also enforces a single-type marketplace and limits CoW Protocol's diversity / growth opportunities.

Acceptance criteria

Details

The current swap marketplace does not support use cases such as where there is no out token (in the event of bridging), basket trades (e.g. trading m:n tokens), or more exotic markets such as "ERC-20 to ERC-721/ERC-1155" and vice-versa.

Possible Solutions

  1. The top-level EIP-712 type becomes Intent, with metadata / hooks / non-market-specific / validity parameters being moved to this type.
  2. "ERC-20 to ERC-20" type market parameters are moved to an "ERC20Swap" EIP-712 type, include sellToken, sellAmount, buyToken, buyAmount, partiallyFillable, and kind.

Research track

fleupold commented 2 months ago

I think a crucial component of the market parameters are a trade processing contract that allows for custom settlement logic. Instead of having one contract that processes all trade executions the same way (or knows up front all different ways market parameters are supposed to be handled), we could delegate this aspect to multiple different implementations (extensible later on)

The most basic logic is the one we support today (limit orders):

  1. Verify signature
  2. Transfer in some amount of exactly one ERC20 token ...
  3. Transfer out funds of exactly one ERC20 token

If any of the steps fails, revert.

For bridging markets for instance, step 3 might be changed for a call to some bridge registry where we want to make sure a claim has been recorded (meaning the user now has a claim on another chain) instead of particular transfer call.

It's important to note that orders of different markets should all be inter-operable. I'm not sure if the DAO should gate-keep the different trade processing contracts or solely rely on solvers/users deciding for themselves what markets they are willing to take part in (by signing orders/including orders in their solution).