0xProject / ZEIPs

0x Improvement Proposals
Apache License 2.0
91 stars 24 forks source link

Optimized Uniswap V3 settlement #88

Closed dekz closed 2 years ago

dekz commented 3 years ago

Summary

This ZEIP proposes to optimize the the integration of Uniswap V3 during settlement, lowering the cost for a significant number of trades.

As Uniswap V3 is gaining significant volume, it is optimal for our users to access this liquidity source for the lowest cost possible.

The proposal also includes removing a deprecated feature known as the allowance target failover in FixinTokenSpender.

Type:

CORE

Motivation

This ZEIP integrates a number of features around Uniswap V3 to reduce the overall cost of using this source within 0x contracts.

In the 0x architecture, trades can either be executed inside or outside of a sandbox. When new liquidity sources are added they are added in a manner in which they execute inside of the sandbox. During settlement, the sandbox is transferred the tokens and has no access to any allowances, so no user funds can ever be at risk. This comes at the cost of additional gas cost overhead.

In order to optimize specific liquidity sources we implement a Feature which executes in an environment which may have access to user allowances. As such we take the utmost care when implementing a new Feature into the 0x protocol.

We propose to optimize the cost of Uniswap V3 settlement, lowering the costs for a large number of trades. There are two changes proposed in this ZEIP, firstly adding UniswapV3Feature to the ExchangeProxy as well as adding support for Uniswap v3 on MultiplexFeature.

The UniswapV3Feature is a gas-optimized contract allowing more efficient settlement of Uniswap V3 trades. The settlement cost when using the UniswapV3Feature is expected to be cheaper than using Uniswap V3 directly. This allows us to offer better prices through the 0x API using 0x contracts. This feature is used when the trade is entirely Uniswap V3.

Adding Uniswap V3 support in the MultiPlexFeature allows for Uniswap V3 execution to be mixed with other supported sources. For example, this allows cheap execution of a split between Uniswap V3 and 0x Request for Quote.

The proposal also includes removing a deprecated feature known as the allowance target failover in FixinTokenSpender.

Implementation

UniswapV3Feature: https://github.com/0xProject/protocol/pull/237 MultiPlex Changes: https://github.com/0xProject/protocol/pull/237

Costs

path gas cost (new) gas cost (old)
ETH->USDC 136615 272556
USDC->ETH 106248 239026
WETH->USDC 99272 243708
USDC->WETH 89648 239115

Designated team: 0x Labs

Notes

The change will be spot-checked by Consensys Diligence

mintcloud commented 2 years ago

voted on https://0x.org/zrx/vote/zeip-88 and deployed