CONVEXSWAP
ConvexSwap started as a hackathon project addressing a simple problem: big trades on decentralized exchange pools like Uniswap move the price against you. A pool prices every swap off its own reserves, so the larger the order, the higher the slippage. ConvexSwap streams the trade out over time instead, in smaller chunks, letting other participants arbitrage the market price back to its starting point, saving the trader a part of their slippage costs.
| invariant | x · y = k | 100 · 300,000 = 30,000,000 |
| you receive | Δy = y · Δx / (x + Δx) | 85,714 USDC |
| spot price | p₀ = y / x | 3,000 USDC/ETH |
| execution price | p = Δy / Δx = y / (x + Δx) | 2,143 USDC/ETH |
| slippage | 1 − p / p₀ = Δx / (x + Δx) | 28.6% |
| in 4 chunks | n · y · (Δx/n) / (x + Δx/n) | 109,091 USDC · 9.1% |
The interesting part is deciding how many chunks to use. Splitting a trade to many chunks cuts slippage costs but increases gas costs and exposure to volatility. This forms a convex optimization problem. The ConvexSwap algorithm finds the number of chunks executed at a set interval that minimize trade costs. Inputs are gas cost estimates, market liquidity depth, and recent volatility.
Illustrative numbers on a toy pool; the shape is the one the optimizer searches.