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
reserves0andreserves1) 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
IUnlockCallbackinterface, which is used by the Uniswap V4PoolManagerduring certain operations.Allows for a simplified user interface, controlling the flow of tokens during swaps and liquidity changes.
Swap flow
TurbineSettlercallsLiquidityRouter.LiquidityRouterunlocksPoolManagerto begin an operation.PoolManagerinvokesLiquidityRouter.unlockCallback(...).LiquidityRoutercallsPoolManager.swap(...)to perform the swap.PoolManagerdelegates the accounting toTurbineHookviabeforeSwap(...)andafterSwap(...)functions.LiquidityRoutertransfers tokens to and fromPoolManagerandTurbineSettler.
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?