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

TurbineLiquidityRouter

Git Source

Inherits: IUnlockCallback, ITurbineLiquidityRouter

State Variables

PERMIT2_CONTRACT

IPermit2 public constant PERMIT2_CONTRACT = IPermit2(0x000000000022D473030F116dDEE9F6B43aC78BA3)

POOL_MANAGER

IPoolManager public immutable POOL_MANAGER = IPoolManager(UNIV4_POOL_MANAGER)

turbineSettler

address public immutable turbineSettler

MIN_INTENT_EXPIRY

uint256 public constant MIN_INTENT_EXPIRY = 36 seconds

SPEEDBUMP_DURATION

uint256 public constant SPEEDBUMP_DURATION = 12 seconds

MAX_INTENT_EXPIRY

_TOKEN_PERMISSIONS_TYPEHASH

_PERMIT_TRANSFER_FROM_TYPEHASH

hook

removeLiquidityIntents

removeLiquidityPermits

removeLiquidityCreatedAt

Functions

constructor

ensure

_ensure

turbineSettlerOnly

Only Turbine OrderSettler may call this function

_turbineSettlerOnly

poolManagerOnly

Only PoolManager may call this function

_poolManagerOnly

settlerOrPoolManagerOnly

Only TurbineSettler or the PoolManager may call this function

Some functions are marked as external to allow calling them via delegatecall, but they are not intended to be called externally. They can only be called by the PoolManager, or by this contract itself in the context of a call from the TurbineSettler (msg.sender is therefore TurbineSettler).

_settlerOrPoolManagerOnly

getTurbineSettler

Returns the address of the TurbineSettler

Returns

Name
Type
Description

<none>

address

The address of the TurbineSettler

getTurbineHook

Returns the address of the TurbineHook

Return type is address to avoid unnecessary imports

Returns

Name
Type
Description

<none>

address

The address of the TurbineHook

submitRemoveLiquidityIntent

Submits a new remove-liquidity intent for later execution.

The caller must be intent.owner. The provided Permit2 authorization must match the LP token and cover at least intent.lpTokenAmount.

Parameters

Name
Type
Description

intent

RemoveLiquidityIntent

The remove-liquidity instruction containing pool and LP token amount details.

signatureTransferParams

SignatureTransferParams

Permit2 SignatureTransfer parameters and signature authorizing LP token transfer.

Returns

Name
Type
Description

intentHash

RemoveLiquidityIntentHash

The intent hash used to reference this submission.

executePendingIntents

Executes the provided intent hashes and deletes the executed intents.

Parameters

Name
Type
Description

hashes

RemoveLiquidityIntentHash[]

Array of intent hashes to execute.

getRemoveLiquidityIntents

Returns remove-liquidity intent data for the given hashes. Skips deleted/unknown intents (owner == address(0)).

Parameters

Name
Type
Description

hashes

RemoveLiquidityIntentHash[]

Array of intent hashes to query.

Returns

Name
Type
Description

result

RemoveLiquidityData[]

Array of RemoveLiquidityData for valid intents only.

_buildRemoveLiquidityData

_executePendingIntent

unlockCallback

Callback function invoked by the poolManager when unlock is called.

  • Only the poolManager can call this function (require(msg.sender == address(poolManager))).

  • Reverts if the delegatecall fails.

Parameters

Name
Type
Description

encodedData

bytes

Encoded data passed from the poolManager. The first parameter is the command (uint256), and the second is the raw data (bytes).

Returns

Name
Type
Description

<none>

bytes

The return data from the invoked callback function.

_maybeUnlockPoolManager

Wrapper function around poolManager.unlock that checks if the manager is already unlocked (because we are taking loans from the pool manager)

If the manager is already unlocked, it will delegatecall directly. Otherwise, it will unlock and pass the calldata.

Parameters

Name
Type
Description

data

bytes

The data to pass to the unlock callback

Returns

Name
Type
Description

result

bytes

The result from the unlock callback

swapExactTokens

Swaps an exact amount of a token for an exact amount of another token.

  • This function assumes that amountIn is already transferred to this contract.

  • This function transfers tokens to the poolManager via poolManager.unlock(...).

  • The poolManager will perform the swap and return the output amount via the callback (unlockCallback).

Parameters

Name
Type
Description

amountIn

uint256

The exact amount of input tokens to be sent for the swap.

amountOut

uint256

The exact amount of tokens expected to be received from the swap.

poolToken0

address

The address of the first token in the pool.

poolToken1

address

The address of the second token in the pool.

poolFee

uint24

The fee of the pool.

zeroForOne

bool

The direction of the swap.

deadline

uint256

A timestamp by which the call be finished to be valid.

_swapCallback

Callback function invoked by the poolManager during the swap execution.

  • Only the poolManager (or this contract if the pool manager is already unlocked) can call this function.

  • Performs a swap via poolManager.swap(...), and ensures the output is exactly amountOut.

  • Handles token transfers: input tokens are transferred from turbineAddress to poolManager, then output tokens are taken from the poolManager and sent to turbineAddress.

Parameters

Name
Type
Description

amountIn

uint256

The exact amount of input tokens to be sent for the swap.

amountOut

uint256

The exact amount of tokens to be received from the swap.

key

PoolKey

The pool key containing the token addresses and fee.

zeroForOne

bool

The direction of the swap.

Returns

Name
Type
Description

<none>

bytes

Empty bytes.

addLiquidity

Adds liquidity to the pair represented by the given hook.

Parameters

Name
Type
Description

to

address

The address receiving the minted liquidity.

amount0

uint256

The amount of token0 to add as liquidity.

amount1

uint256

The amount of token1 to add as liquidity.

poolToken0

address

The address of the first token in the pool.

poolToken1

address

The address of the second token in the pool.

poolFee

uint24

The fee of the pool.

liquidity

uint256

The liquidity amount to mint for the caller.

batchSignatureTransferParams

BatchSignatureTransferParams

The Permit2 batch SignatureTransfer permit and signature for token0 and token1.

Returns

Name
Type
Description

<none>

uint256

liquidity The minted liquidity amount for the caller.

_addLiquidityCallback

Callback function invoked by the PoolManager when adding liquidity.

  • Only the PoolManager should call this function.

  • Uses a single batch permitTransferFrom to transfer both tokens to this router.

  • Then settles each token individually with the PoolManager via sync -> transfer -> settle.

  • Mints the corresponding amounts to the hook contract via poolManager.mint(...).

Parameters

Name
Type
Description

caller

address

The address that initiated the liquidity addition.

amount0

uint256

The amount of token0 to add as liquidity.

amount1

uint256

The amount of token1 to add as liquidity.

key

PoolKey

The pool key containing the token addresses and fee.

batchSignatureTransferParams

BatchSignatureTransferParams

The Permit2 batch SignatureTransfer permit and signature for token0 and token1.

Returns

Name
Type
Description

<none>

bytes

Encoded data containing the hook reference (abi.encode(hook)).

removeLiquidity

Burns liquidity to the pair represented by the given hook.

Parameters

Name
Type
Description

to

address

The address receiving the burnt liquidity.

liquidity

uint256

The burnt liquidity amount from the caller.

poolToken0

address

The address of the first token in the pool.

poolToken1

address

The address of the second token in the pool.

poolFee

uint24

The fee of the pool.

signatureTransferParams

SignatureTransferParams

The Permit2 SignatureTransfer permit and signature for the LP token.

Returns

Name
Type
Description

<none>

uint256

amount0 The amount of token0 received from burning liquidity.

<none>

uint256

amount1 The amount of token1 received from burning liquidity.

_removeLiquidity

calculateWithdrawnAmounts

_removeLiquidityCallback

Callback function invoked by the PoolManager when removing liquidity.

  • Only the PoolManager should call this function.

  • Takes both token0 and token1 from the PoolManager to the caller.

  • Burns the corresponding amount from the hook contract via poolManager.burn(...).

Parameters

Name
Type
Description

caller

address

The address that initiated the liquidity removal.

liquidity

uint256

The amount of liquidity to remove.

key

PoolKey

The pool key containing the token addresses and fee.

amount0

uint256

The amount of token0 to receive from burning liquidity.

amount1

uint256

The amount of token1 to receive from burning liquidity.

signatureTransferParams

SignatureTransferParams

The Permit2 SignatureTransfer permit and signature for the LP token.

Returns

Name
Type
Description

<none>

bytes

Encoded data containing the amounts of tokens from burning liquidity.

_settleFromRouter

Settle a currency with the PoolManager when tokens are already held by the router

Used after batch permitTransferFrom has transferred tokens to this contract.

Parameters

Name
Type
Description

currency

Currency

Currency to settle

amount

uint256

Amount to send

isNonceUsed

Check if a SignatureTransfer nonce has already been used

Parameters

Name
Type
Description

owner

address

The owner of the nonce

nonce

uint256

The nonce to check

Returns

Name
Type
Description

<none>

bool

True if the nonce has been used, false otherwise

_hashRemoveLiquidityIntent

_isTooYoung

_isExpired

_deleteIntentData

Deletes intent mapping data for the given hash.

hash

Hash a PermitTransferFrom struct to create a unique identifier for the permit.

Adapted from https://github.com/Uniswap/permit2/blob/cc56ad0f3439c502c246fc5cfcc3db92bb8b7219/src/libraries/PermitHash.sol#L59 replacing the spender address with this router contract (address(this)), instead of msg.sender.

Parameters

Name
Type
Description

permit

ISignatureTransfer.PermitTransferFrom

The PermitTransferFrom struct to hash.

Returns

Name
Type
Description

<none>

bytes32

The hash of the PermitTransferFrom struct.

Last updated

Was this helpful?