How We Built StableSwap Hooks for Revert Finance on Uniswap v4

Revert Finance came to us with a clear problem. Stablecoins and liquid staking tokens like USDC/USDT or wstETH/WETH trade near 1:1, but generic AMM pricing still charges unnecessary slippage on these swaps. Curve Finance solved this years ago with StableSwap, a pricing algorithm built for correlated assets. But that math only existed inside Curve's ecosystem. If you wanted it, you had to leave Uniswap.
Uniswap v4 changed the equation. Its new hooks architecture lets developers attach custom logic to core AMM operations without forking the protocol. Revert brought us in to take advantage of that: build a production-ready hook that brings Curve-style StableSwap math into the Uniswap ecosystem.
What We Built
Optimized stable asset trading. Pools designed for assets that trade near 1:1, like USDC/USDT or wstETH/WETH. The StableSwap pricing algorithm keeps slippage minimal even on large trades. In the high-volume, thin-margin world of stablecoins, that difference matters.
Multi-asset pools. A single pool can hold two, three, or four assets at once. This avoids splitting liquidity across multiple pair pools, which typically means worse prices and more complexity for integrators.
Three-tier fee system. LP fees, hook fees, and protocol fees, each tunable independently. Protocol teams get precise control over how value flows between liquidity providers, the hook operator, and the treasury.
Rate oracle support. Assets like wstETH don't hold a fixed ratio to ETH. The exchange rate shifts as staking rewards accumulate. Our hook consumes real-time rate data and feeds it into the pricing math, so the invariant stays accurate as rates drift.
Fungible LP tokens. Liquidity positions are standard ERC-20 tokens, not NFTs. That makes LP shares transferable, composable with other DeFi protocols, and familiar to teams that have worked with earlier-generation AMMs.
Native ETH support. Pools accept ETH directly. No wrapping to WETH before depositing or swapping, which cuts transaction steps and simplifies the experience.
Engineering Challenges
Porting StableSwap math to Solidity. The StableSwap invariant has no closed-form solution. Finding the correct output for a given input requires the Newton-Raphson method, applied iteratively until convergence. Solidity has no floating-point arithmetic, so every calculation runs in fixed-point integers where rounding errors compound across iterations. Getting this right meant careful precision management at every step while keeping gas costs practical for mainnet.
Handling assets that drift from 1:1. Standard StableSwap assumes all pool assets are equal in value. Liquid staking tokens break that: wstETH is worth more than ETH, and the ratio grows continuously. We built a rate oracle system that injects the current exchange rate into the invariant calculation before every operation. The math always works on value-normalized quantities, not raw token amounts.
Deploying hooks to deterministic addresses. Uniswap v4 has an unusual constraint: a hook's contract address must encode which hook functions it implements. The address itself acts as a capability bitmap. Generating a valid address requires CREATE2 with a specific salt, and finding that salt means iterating through candidates off-chain until the resulting address matches the required bit pattern. We built tooling to mine valid salts and deploy reliably.
Scaling across pool sizes. Supporting two, three, and four assets in a single codebase means every core operation (swap routing, fee calculation, slippage checks, invariant evaluation) must generalize across a variable number of tokens. The math scales non-linearly: adding a third or fourth asset doesn't just add a term, it changes the shape of the problem. Each operation was designed and tested across all supported pool sizes.
Safe amplification coefficient ramping. The amplification coefficient ("A") controls how tightly the pool prices assets near parity. Higher values mean less slippage at equilibrium but worse pricing at extremes. Changing A abruptly opens arbitrage windows. We implemented time-based ramping: the coefficient moves gradually from its current value to a new target over a configurable window, with safety bounds that prevent destabilizing an active pool.
Tech Stack
- Built on: Solidity 0.8.30, Uniswap v4 Core and Periphery, OpenZeppelin
- Tooling: Foundry (Forge)
- Testing: 290 tests across 16 suites, all passing
- Codebase: roughly 1,400 lines of modular Solidity
The Result
Revert Finance now has a production-ready StableSwap implementation running inside Uniswap v4. No separate protocol, no fragmented liquidity. Protocols and users trading stable pairs get Curve-quality pricing without leaving the Uniswap ecosystem.
The source code is open on GitHub: revert-finance/stableswap-hooks.
If you need custom AMM infrastructure, DeFi protocol development, or deep Solidity engineering, let's talk.
BootNode
BootNode is a high-output engineering and product shop specializing in DeFi, staking, infrastructure, and interoperability. We help protocols and builders ship faster and scale with confidence. Explore other projects and get in touch here.
Revert Finance
Revert Finance provides actionable analytics for liquidity providers in AMM protocols. Their tools help LPs understand and optimize their positions, making it easier to manage liquidity across decentralized exchanges.
Uniswap v4
Uniswap v4 is the latest version of the Uniswap Protocol. Its hooks architecture allows developers to attach custom logic to AMM pools, enabling new categories of on-chain trading infrastructure without forking the protocol.