ETH-flow refund costs

ETH flow: potential refund cost approval

Proposal summary:

The CowSwap development team has collected feedback over the past couple of months from the community, investors, and partners and has realized that one major pain point for users is that the protocol is currently not facilitating native ETH trading. Therefore, the team is eager to develop a new user experience for ETH trading. While trading any ERC20 token to ETH works perfectly normally with CowSwap, the opposite trade is not as smooth compared to Uniswap and other DEX aggregators. The reason is that Cow Protocol requires approval of tokens to transfer the user’s token. Since users can’t set an approval for ETH, CowSwap currently requires all users to wrap their ETH to WETH before they can start trading.

On a high level, the ETH-flow UX project will improve the UX by allowing users to place an on-chain order and wrap ETH with one transaction. This would significantly improve the UX, as it would only require 1 wallet interaction instead of two.

This new ETH flow has a disadvantage though: If the user order is for some reason not settled, then the ETH needs to be sent back to the user’s wallet from the contract enabling this new ETH flow. The Cow Protocol development team would thus only start the development of the new UX flow under the premise that Cow DAO offers to cover the gas costs for those failed ETH trades. The gas costs for refunding are expected to be very low - as described below - though bugs could temporarily increase the costs.

Proposal - ETH-Flow

Why the ETH flow is an issue:

According to a Discord survey: 27/50 of traders do sometimes switch to other exchanges because of the current Cow Swap ETH UX-flow. When asked to describe the issue of the additional wrapping of ETH on a scale of 1 to 10, 1 being not an issue and 10 being a severe issue, the result was on average 5.5 with many users claiming that it’s a severe issue, while others state this is not an issue at all. Additionally, the missing ETH flow has been mentioned by potential partner projects as a reason against integrating Cow Protocol (note that also Balancer is despite its native integration of Cow Protocol not settling its ETH sell orders via Cow Protocol).

The ETH flow project:

Goal:
  • Enable new UX with only 1 user wallet interaction
  • Making a user’s first ETH trade a smooth experience
Specification:
  • Users will place an on-chain transaction to the so-called new “ETH-flow” contract and thereby send the ETH needed to place an order

  • The ETH-flow contract will wrap the ETH for the users and place an order using the EIP-1271 order placement method

  • During the settlement, the Cow Protocol will settle the previously placed EIP-1271 order as a normal order and send the received funds to the user

  • Initially user orders’ will not be updatable without on-chain transactions. However, this feature will likely be added in a future project cycle. For a more detailed write-up on this idea, read here.

The exact specification for the implementation can be read here: Smart contract specification.

The UX:
  • In most cases, the UX will feel like a normal Uniswap experience.
  • The users only need to sign 1 on-chain transaction.
  • Prototypes are currently in development. An early version can be found here.

There are small drawbacks compared to the normal WETH flow:

  • Slippage can not be set very tightly, as the orders should be settled with a high likelihood of execution - otherwise there is an additional cost to refund the ETH from the ETH-flow contract back to the user
  • Orders can only be canceled with on-chain transactions.
  • ETH will leave the wallet before the received token is credited.
  • Gas costs are slightly higher (20k gas) for regular users compared to the wrapping of ETH + offline signature order placement.

Comparison to WETH trading:

WETH trading ETH-flow
UX Wrapping tx + off-chain signed order 1 onchain transaction
ERC-Approval Required Not needed
Cancelling orders Possible Not possible
Updating orders Possible w/o costs Possible with small costs
Expiring orders No issue Refunding needed
Slippage Freely set by user Must be set relatively high > 0.5%, as non-settled orders need extra on-chain transaction to settle
Gas efficiency Cheaper for users who have already approved WETH Only cheaper for first-time users (due to WETH token approval)
ETH-transactions 1 settlement tx 1 order placement + 1 settlement tx

The request of this CIP:

The CowSwap development team thinks that it would be a bad UX for the users if an ETH-order was not filled and then the user would have to trigger the ETH-flow contract in order to receive back their funds. Instead, the project team thinks that it’s better if the front-end requires users to set slippage such that ETH orders are filled with a very high likelihood. Only in the unlikely event that the orders are not filled, then a service - run by Cow DAO - will trigger the ETH-flow contract to send back the ETH to the users.

In the following table, one can see the estimated likelihoods for ETH refunds from the ETH-flow contract back to the users given some slippage parameters. They were calculated using the following dune script: The script investigates the price changes for tokens that were used on CowSwap in WETH trades. It compares for each of these tokens the price at time t and t + 5 minutes and checks how often the price has fallen below the slippage point within these 5 minutes. Given that CowSwap’s settlements can take up to 5 minutes, these numbers should give an upper ceiling under normal conditions. However, we would expect even fewer reverts than calculated in the query, since many orders are settled more quickly than in 5 minutes and the price could also improve after 5 minutes and hence the order could be settled again.

The real risk is merely coming from the chance that our price estimations for the users are not correct and then the orders have a much higher likelihood of not being settled at all. The CowSwap team would do their best to reduce these costs - e.g. by aggregating different prices and filtering for outliers, though they could potentially still happen.

Allowed slippage Expected success rate Expected ETH refunds due to failure Expected gas amounts per month *
0.5% 0.971 Every 34th tx 6M
1% 0.9937 Every 160th tx 1.1M
2% 0.9989 Every 937th tx 0.018M

The CowSwap development team is asking the DAO whether it’s willing to take the cost of these ETH-Flow refunds - at the slippage rate > 0.5% that is decided later internally by the team - given that the new ETH-flow should improve the product and attract more users.

  • Footnote: Assuming 100 ETH sell orders per day (Refund tx gas costs: 60k): E(0.5%) =100*30 / 34th * 60K gas
3 Likes

if i am not mistaken this is very similar to uni v3’s approach, no? where the router wraps the eth received, and does a callback of some sorts in case there is a surplus left at the end of the trade?

1 Like

I don’t know uni v3 in detail, so please take the following with a grain of salt.

I think there are similarities: You are right that in both scenarios there are routers that wrap ETH. The difference in the two setups is that for uni v3 the owner of the ETH is at the same time the sender of the transaction doing a swap. For cowswap, the sender of the transaction is the particular solver trying to settle an order. This is the main difference and hence, we can not strictly implement a normal wrapping ETH router, but have to go with this a little bit more nuanced approach. But in the end, it’s all for the same reasons: Wrapping ETH under the hood with minimal UX hurdles.

Trying to understand if the core problem here is to return ETH to the user rather than wETH?

If that is the case, a way to approach it could be with a prompt
“You are exchanging ETH, if the order does not execute you will receive wETH back, minus gas fees.”

Feel free to disregard it if I misunderstood :stuck_out_tongue:

Yeah, the core problem is receiving ETH from the user rather than WETH. THe core issue is that one can not approve ETH, but our settlement contract requires this