CIP-38: Solver Computed Fees & Rank by Surplus

CIP: <to be assigned when moved to phase 2>
title: Solver Computed Fees & Rank by Surplus
author: Haris Angelidakis, Andrea Canidio, Felix Henneke
status: Draft
created:  2023-11-28
replaces: CIP-20

Simple summary

Currently, CoW Protocol collects fees from users and then uses these fees to reimburse solvers’ gas costs. We instead propose that solvers collect a “network fee” directly to cover their gas costs. This would mean eliminating our current fees and ranking solutions based on surplus alone.

With the proposed changes we also simplify the collection of protocol fees (as introduced in CIP-34). Such fees are collected by solvers on behalf of the protocol and paid to the CoW DAO in COW tokens.

Motivation

Today, CoW protocol reimburses solvers’ gas costs by collecting fees from users. Gas costs and fees are, however, not directly connected in the solver competition. This is inefficient for multiple reasons:

  • The benefit of batching orders (in terms of gas savings) is not always correctly passed on to users.
  • The protocol must monitor fees set by solvers, adding complexity.

This CIP proposes that we eliminate our current fee and stop reimbursing solvers for gas. In practice, we propose to stop reimbursing solvers for gas by ranking solutions based on “surplus” alone and rewarding the winning solver:

cap(surplus - second_highest_surplus)

paid in COW. Solvers would, therefore, no longer be guaranteed to receive a reward greater than their expenditure in gas costs, and will need to cover these costs by charging accurate fees. Competition between solvers guarantees that these fees equal gas costs, which is one of the main goals that motivated this proposed change.

Eliminating the current fees simplifies the protocol and how CoW DAO charges protocol fees (introduced in CIP-34). We propose that the protocol fee should be collected by solvers on behalf of CoW Protocol and then reimbursed weekly to the protocol in COW (the currency used for solver rewards).

The protocol fee therefore introduces a new utility for the COW token (and a new source of demand, as part of normal protocol operations) that should positively impact its price. Maintaining a healthy token is in the interest of CoW DAO, so this should be seen as a positive development for CoW DAO and COW token holders.

Finally, we want to clarify that the above proposal does not incur any change in the quotes the users will be receiving, and the only difference is that the users would be signing zero-fee orders while the limit prices (i.e., the guarantees provided by the protocol) would remain unchanged.

Specification

Solutions submitted by solvers contain orders together with their sell, buy, and fee amounts (specified in the sell token), and prices for all tokens traded by orders in the solution. The quality of a solution is now defined as the sum of surplus of the different orders, measured in ETH; the conversion to ETH will be done the same way it is done now, i.e., via the native prices vector provided in the auction instance sent to solvers. The solver whose solution has the largest quality wins the solver competition and executes their solution. Following a second-price mechanism (similar to CIP-20), a winning solver who successfully executes its solution on chain, is paid

cap(winning_quality - reference_quality)

in COW tokens, and own all fees they collected in the settlement. The reference_quality is the quality of the second best solution or set to zero if there is only one solution.

On the other hand, if the winning solver fails to execute their solution on chain, they pay a penalty equal to

cap(reference_quality).

The (asymmetric) capping of rewards and penalties is currently specified in CIP-36. As with CIP-20, the rewards will only apply to Ethereum Mainnet.

For a solution to be valid we require the following properties. Let a user send Y tokens of A and receive X tokens of B. The solver sets a fee f in the sell token A. The reported prices for A and B are p_A and p_B, respectively. Then uniform clearing prices need to hold:

(Y - f) / X = p_B / p_A. [Uniform Clearing Prices, UCP]

In addition, we require

Y / X = const [Uniform directional prices, UDP]

on all trades selling A and buying B.

The UCP rule is the same as the one we currently use. The rule on directional prices is new and means that all users trading on a token pair see the same effective exchange rate (i.e., exchange rate after fees).

Note that UDP only specifies how fees are distributed within a single directed token pair. However, it does not provide rules/guidelines on batches where there are multiple disjoint orders getting settled. For that, we will invoke the EBBO and social consensus rules to ensure that no order is treated unfairly, and this entails each order getting charged a reasonable fee that is proportional to the gas cost the order incurs within a batch. Moreover, the whole batch should pay a fee corresponding to the gas cost of executing the batch. In practice, we expect solvers to exercise common sense and charge reasonable fees to user orders, and the core team commits to proper monitoring of all settlements that take place so that such rules are checked on a per settlement basis. In case a solver intentionally misbehaves and violates some of the above rules, the DAO, via a vote, could slash a solver and its bond.

Ranking and network fees

With this proposal, solvers compute fees for all orders and the protocol stops accepting orders with a positive signed fee. Solvers have the knowledge of execution costs and determine the prices seen by users. This allows solvers to give all benefits from cost reductions to users. We note that solvers can already set fees for a subset of orders, namely the so-called limit orders. Within the previous ranking and payment mechanism, however, solvers were not explicitly incentivized to choose accurate fees. This changes with this proposal.

With this proposal, all user fees are determined and owned by solvers, and these fees are removed from the ranking and reward mechanism. This creates an incentive for solvers to choose fees to exactly cover execution costs of batches. On the one hand, charging larger fees reduces the rank in the competition. On the other hand, charging smaller fees results in unprofitable settlements for a solver since the fees do not cover execution costs and solver rewards are not guaranteed to compensate for this, due to the second price nature of the mechanism.

Example (toggle to show)

Suppose a solver found a solution that can generate up to 1.01 ETH of surplus and has an execution cost of 0.01 ETH. Then the solver should charge a total fee of 0.01 ETH, resulting in a total surplus of 1 ETH for users.

If the solver charges a smaller fee of e.g. 0.005 ETH and gives 1.005 ETH of surplus to users, it can happen that the solver makes a loss on winning the competition. For example, if the best competitor can provide 1.004 ETH of surplus, the solver is rewarded with only 1.005 ETH - 1.004 ETH = 0.001 ETH. Together with the fees of 0.005 ETH they collected they cannot cover the execution costs, 0.005 ETH + 0.001 ETH < 0.01ETH.

If the solver charges a larger fee of e.g. 0.015 ETH and thus gives 0.995 ETH of surplus to users, the solver might not win an auction even though they could have made a profit doing so. For example if the best competitor can provide a surplus of 0.999 ETH, they lose now. But had they charged a fee of 0.01 ETH they would have won, covered their costs, and gained a reward of 0.001 ETH.

The rule on directional uniform prices determines the distribution of fees across orders on the same token pair. It effectively means that fees are split proportional to volume. This rule thus provides additional guarantees for fairness on top of the current rules on uniform clearing prices.

Example (toggle to show)

Suppose a solution contains two orders, the first selling 1 ETH for at least 1800 USDC and the second selling 2 ETH for at least 3700 USDC. The orders can be settled with an AMMs trading 2.97 ETH to 5700 USDC with a total gas cost of the settlement of 0.03 ETH.

Then a solver should charge a total fee of 0.03 ETH and distribute it proportionally as 0.01 ETH to the smaller order and 0.02 ETH to the larger order. The returned amount from the AMM should also be split proportionally as 1900 USDC to the smaller order and 3800 to the larger order. This results in a uniform clearing price for USDC of 0.99/1900 ETH. The users see uniform exchange rates after fees of (1 ETH - 0.01 ETH) / 1900 USDC = 0.99 ETH / 1900 USDC = (2 ETH - 0.02 ETH) / 3800 USDC, and uniform exchange rates before fees of 1 ETH/1900 USDC = 2 ETH/3800 USDC.

The total fee on the batch as well as the distribution of fees of orders on different token pairs are not restricted by hard rules within the mechanism yet. The main protection for users in this case is through social consensus rules (e.g., EBBO). In particular it is not allowed to shift large fractions of fees of a batch to orders not responsible for correspondingly large parts of executions. This is a form of shifting surplus, forbidden by our current social consensus rules on provision of unfair prices (as specified in CIP-11).

Example (toggle to show)

Suppose a solution contains two orders, the first selling 1 ETH for at least 1800 USDC and the second selling 2 ETH for at least 3700 DAI. The order can be settled using two independent AMMs trading 0.99 ETH to 1900 USDC and 1.99 ETH to 3819 DAI. Both AMM interactions result in the same gas overhead and the total gas cost of the settlement is 0.02 ETH.

Then a solver should charge a fee of 0.02 ETH in total and the fee should be split equally among the two orders. This gives uniform clearing prices for USDC and DAI of 0.99/1900 ETH and 1.99/3819 ETH and users see exchange rates after fees of (1 ETH - 0.01 ETH) / 1900 USDC and (2 ETH - 1.99 ETH) / 3819 USDC, respectively.

We keep the second-price auction character of the competition from CIP-20, i.e., we reward solvers on how much their solutions improve upon those of the rest of the competition.

Solvers might choose to collect tokens from network fees in the settlement contract. We propose to treat those funds as slippage. This means that all buffer changes from a settlement are converted to ETH and paid to solvers in ETH once a week.

Regarding the quotes users will see, nothing changes other than the fact that orders will be signed as zero-fee orders while limit prices remain identical as before.

Example (toggle to show)

For example, a user selling 1 WETH for COW today will receive a quote that explicitly computes a gas fee, say 0.01 ETH, and then the remaining amount (i.e., 0.99 ETH) is converted to COW and the resulting COW amount is presented as the expected received amount from the user. In other words, we have the following breakdown:

  • Full amount provided by user = 1 WETH
  • Fee = 0.01 WETH
  • Tradable amount = 0.99 WETH
  • Full amount = Fee + Tradable amount
  • Expected received amount after converting the tradable WETH amount to COW, say 6k COW.

With the proposed change, there will be just a “full amount provided by user” equal to 1 WETH, and an expected received amount equal to 6k COW, and, assuming for simplicity a slippage tolerance of 0%, the breakdown of gas fee and tradable amount will be dynamically decided by the solver, while the 6k COW as minimum received amount will always be respected.

Extension to protocol fee

The mechanism described above can be extended to allow for a protocol fee (introduced in CIP-34) collected by solvers on behalf of the protocol. In that case, the quality of a solution is the sum of the surplus of the different orders and the protocol fees collected; the rationale being that solvers should still try to maximize the “size of the pie” and then distribute it accordingly to users and the protocol. In case of a successful settlement on chain, the winning solver is paid

cap(winning_quality - reference_quality)

For each order, in addition to the sell, buy, and network fee amount, there is a protocol fee of f_{p,sell} and f_{p,buy} denominated in the sell token A or buy token B, respectively.

The equation for uniform clearing prices then becomes

(Y - f - f_{p,sell}) / (X + f_{p,buy}) = p_B / p_A.

The equation for uniform directional prices becomes

(Y - f_{p,sell}) / (X + f_{p,buy}).

From the practical viewpoint, solvers collect the protocol fee (for example, by accumulating it in the settlement contract as positive slippage) and forward it to the protocol once a week, when solvers receive their rewards from the protocol (in COW tokens) and the value of their buffer (in ETH). We will later decide whether the protocol fee is paid back to the protocol in COW or in ETH (and hence is netted out from one of the two payments). If the protocol fee is collected in ETH, it will be converted automatically into COW.

Timeline

Assuming that this proposal passes, we propose to move to the new ranking and fee model as follows:

  • Before the start of the new ranking, fixed-fee in-market orders from CoW Swap and third-party integrators will be continuously phased out in favor of zero-fee orders.
  • Starting on 19.3.2024 the new ranking by surplus is used in the competition.
  • The first payout based on surplus is on 26.3.2024.
  • Starting on 19.3.2024 orders with a non-zero fee are rejected by the protocol.
  • After 4 weeks of running the new ranking, we will analyze the caps for rewards. The caps will be reduced in case of overspending (with respect to the budget defined in CIP-36) and increased in case of underspending, as an amendment to CIP-36. At this time we will also start with automatic conversion of protocol fees to COW tokens.

[Update on 2024-02-19: A timeline was added. Also, the text was adapted to account for the introduction of protocol fees (CIP-34), to the fact that solvers do now set fees for most orders, and to the new reward caps from CIP-36.]
[Update on 2024-02-22: Minor changes to the timeline and testing period.]

5 Likes

I fully support the proposal

1 Like

Now that the rewards mechanism will be adjusted, it would be great if you would also consider the following post:

1 Like

I fully support this proposal, great idea

1 Like

In general I support the proposal however I have a few points:

1/ The implementation of the way the protocol fees are paid back to cowswap are crucial, and some solutions are much more risky than others, considering the timescale of 1 week. If solvers were required to pay back protocol fee in COW token, they are exposed to really high leverage, which is capable of easily imploding their entire operation. If every auction the solvers are liable to repay COW denominated at the time of the transaction the solvers might be liable to repay orders of magnitude more in case COW price goes up. The risk of solvers having to repay in COW does not help the protocol because the solvers would have to commit a lot of resources into trying to create systems that mitigate the said risk, which involves live monitoring of PNL (which is very difficult at the moment) and then auto buying COW. Requirement of solvers paying back in COW tokens is counterproductive as solvers will commit significant resources to risk management instead of building algorithms that capitalize on the benefits of batch auctions and thus making the protocol competitive and positive sum.
The best and simplest way to mitigate the risk is to make cow protocol receive the protocol fee in ETH the most liquid and much more stable token.
To still achieve the desired outcomes for the COW token cow protocol should TWAP the received ETH into COW.

2/ I second Filius’s point on the penalty incurred by solvers. Before this CIP can be implemented the appropriate penalty implementation should be introduced, penalty should be paid on the first simulating solution.

3/ For solvers to be able to get more involved in the auction mechanism by self configuring fees, solvers need to have high data availability live for the auctions that are happening. I propose that the auctions are immediately available in the API not 64 blocks later when they are finalized. This can be easily solved on cow protocol side by maintaining an unfinalized auction api which also returns the unfinalized auctions.

Hi @Filius , I replied in the original thread.

Hi @copiumnicus ,

Thanks for your comments! Some thoughts:

1/If and when the DAO introduces the protocol fee, it will also specify its currency. For example, if the fee is a fraction of surplus, then it is in ETH. Similarly, the fee could be a fixed amount per order (in ETH or any other currency). The proposal is that, independently of the currency in which the fee is computed, the payment occurs in COW. This is similar to what currently happens with solvers’ rewards: they are in ETH but are converted and paid in COW once a week. And of course, in the implementation of the CIP (which will be discussed at a later stage), we will try to minimize or eliminate the risk of currency mismatch. A useful benchmark is a situation in which a solver accumulates the fee in their buffer with each trade: our goal is to have an accounting system that, in this case, completely eliminates currency risks.

/2 See my reply in the original thread

/3 This is a good point that will be relevant when discussing the implementation of the proposal. Let me however mention that, already now, solvers should have the auction ID as part of the instance. Auctions can be looked up immediately by auction id using this endpoint

Can you help me understand how you think about this as token utility? Is it because solvers must pay the protocol fee in COW?

Hi @trebor ,
You are correct. Cowswap has two sets of users: traders and solvers. Now some of our users (solvers) will need some COW to participate in the protocol.

1 Like

Work tokens: tokens grant access to the network and provide cash flow potential conditional on the provisioning of work.

The term was coined several years ago but is still relevant today

I adapted the text of the CIP-Draft in the following way:

  • A timeline was added.
  • The text was adapted to account for the introduction of protocol fees (CIP-34), to the fact that solvers do now set fees for most orders, and to the new reward caps from CIP-36.
1 Like