For the complete documentation index, see llms.txt. This page is also available as Markdown.

Solidity Documentation

Turbine protocol consists of an offchain backend and a set of smart contracts.

There are two main groups of contracts:

  • Order Settlement (settler): The main contract - TurbineSettler - is responsible for settling orders. Turbine backend submits transactions directly to this contract.

  • Liquidity Provision (univ4-hook): Liquidity provision is implemented by a Uniswap V4 Hook - TurbineHook - and a Router - TurbineLiquidityRouter.

Overview

TurbineHook

  • Implements a Uniswap V4 Hook interface to intercept and customize pool actions (e.g., swaps, liquidity additions).

  • Uses an internal ERC20 token to represent liquidity shares (similar to Uniswap V2 LP tokens).

  • Tracks the reserves internally (like Uniswap V2’s reserves0 and reserves1) to issue or burn liquidity tokens accordingly.

  • Restricts direct pool operations so that only the designated router can invoke critical functions like minting, burning, or swapping.

Router

  • Orchestrates liquidity addition (addLiquidity), removal (removeLiquidity), and swaps (swapExactTokens) by interacting with both TurbineHook and the Uniswap V4 PoolManager.

  • Implements the IUnlockCallback interface, which is used by the Uniswap V4 PoolManager during certain operations.

  • Allows for a simplified user interface, controlling the flow of tokens during swaps and liquidity changes.

Swap flow

  1. TurbineSettler calls LiquidityRouter.

  2. LiquidityRouter unlocks PoolManager to begin an operation. PoolManager invokes LiquidityRouter.unlockCallback(...).

  3. LiquidityRouter calls PoolManager.swap(...) to perform the swap.

  4. PoolManager delegates the accounting to TurbineHook via beforeSwap(...) and afterSwap(...) functions.

  5. LiquidityRouter transfers tokens to and from PoolManager and TurbineSettler.

Development with Foundry

Installation

Build

or to also include dev contracts used by Rust, use the makefile:

Test

Fuzz & Invariant Tests

Fuzz and invariant tests live in test/fuzz/ and run in CI with default settings (256 fuzz runs, 64 invariant runs). To run locally with more iterations:

Format

Deploy

See the specific page in the documentation for more information on how to deploy the contracts.

Last updated

Was this helpful?