> For the complete documentation index, see [llms.txt](https://docs.turbine.exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.turbine.exchange/reference/contracts/solidity-documentation/settler/contract.turbinesettler.md).

# TurbineSettler

[Git Source](https://github.com/propeller-heads/turbine/blob/90514973167f1eb25cb9eb7756354fb3de34824d/src/settler/TurbineSettler.sol)

**Inherits:** [ITurbineSettler](https://github.com/propeller-heads/turbine-docs/blob/master/src/settler/interfaces/ITurbineSettler.sol/interface.ITurbineSettler.md), AccessControl, Pausable, IUnlockCallback

## State Variables

### PERMIT2\_CONTRACT

```solidity
IPermit2 public constant PERMIT2_CONTRACT = IPermit2(PERMIT2)
```

### UNIV4\_POOL\_MANAGER\_CONTRACT

```solidity
IPoolManager public constant UNIV4_POOL_MANAGER_CONTRACT = IPoolManager(UNIV4_POOL_MANAGER)
```

### PAUSER\_ROLE

```solidity
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE")
```

### UNPAUSER\_ROLE

```solidity
bytes32 public constant UNPAUSER_ROLE = keccak256("UNPAUSER_ROLE")
```

### CALL\_DATA\_EXECUTION\_GAS\_LIMIT

```solidity
uint256 private constant CALL_DATA_EXECUTION_GAS_LIMIT = 200000
```

### turbineSigner

Address that signs the settlement solutions

```solidity
address public immutable turbineSigner
```

### feeWithdrawer

Address authorized to withdraw accumulated fees

```solidity
address public feeWithdrawer
```

### turbineLiquidityRouter

Contract that handles liquidity provisions and removals

```solidity
ITurbineLiquidityRouter public immutable turbineLiquidityRouter
```

### executedSellAmounts

Executed settled sell amounts of orders

```solidity
mapping(bytes32 orderHash => uint256 executedSellAmount) public executedSellAmounts
```

## Functions

### constructor

\---------------------------- 🛠️ CONSTRUCTOR ----------------------------- ///

```solidity
constructor(address _turbineSigner, address _maintainer, address _turbineLiquidityRouter) ;
```

### onlyTurbineSigner

Restricts function access to the turbine signer only

```solidity
modifier onlyTurbineSigner() ;
```

### \_onlyTurbineSigner

```solidity
function _onlyTurbineSigner() internal view;
```

### onlyFeeWithdrawer

Restricts function access to the fee withdrawer only

```solidity
modifier onlyFeeWithdrawer() ;
```

### \_onlyFeeWithdrawer

```solidity
function _onlyFeeWithdrawer() internal view;
```

### pause

\------------------------ 🌐 EXTERNAL METHODS ------------------------- ///

Pauses the contract

```solidity
function pause() external onlyRole(PAUSER_ROLE);
```

### unpause

Unpauses the contract

```solidity
function unpause() external onlyRole(UNPAUSER_ROLE);
```

### renounceAdmin

Renounces the caller's admin role

Can only be called by an admin. If multiple admins exist, other admins retain their roles.

```solidity
function renounceAdmin() external onlyRole(DEFAULT_ADMIN_ROLE);
```

### updateFeeWithdrawer

Updates the fee withdrawer address

Only callable by the admin

```solidity
function updateFeeWithdrawer(address newFeeWithdrawer) external onlyRole(DEFAULT_ADMIN_ROLE);
```

**Parameters**

| Name               | Type      | Description                    |
| ------------------ | --------- | ------------------------------ |
| `newFeeWithdrawer` | `address` | The new fee withdrawer address |

### sweepFees

Sweeps all available balance of specified tokens to a specified recipient

Only callable by the fee withdrawer

```solidity
function sweepFees(address[] calldata tokens, address to) external onlyFeeWithdrawer;
```

**Parameters**

| Name     | Type        | Description                           |
| -------- | ----------- | ------------------------------------- |
| `tokens` | `address[]` | The addresses of the tokens to sweep  |
| `to`     | `address`   | The address to send the swept fees to |

### executeLiquidityActionsAndSettlement

Executes liquidity actions and a batch settlement

```solidity
function executeLiquidityActionsAndSettlement(
    AddLiquidityAppliedAction[] calldata addLiquidityActions,
    RemoveLiquidityAppliedAction[] calldata removeLiquidityOffchainActions,
    RemoveLiquidityIntentHash[] calldata removeLiquidityOnchainActions,
    BatchSettlement calldata settlement,
    uint256 targetBlockNumber,
    uint256 batchId
) external onlyTurbineSigner whenNotPaused;
```

**Parameters**

| Name                             | Type                             | Description                                                |
| -------------------------------- | -------------------------------- | ---------------------------------------------------------- |
| `addLiquidityActions`            | `AddLiquidityAppliedAction[]`    | The liquidity actions to add liquidity                     |
| `removeLiquidityOffchainActions` | `RemoveLiquidityAppliedAction[]` | The offchain-applied liquidity actions to remove liquidity |
| `removeLiquidityOnchainActions`  | `RemoveLiquidityIntentHash[]`    | Intent hashes for onchain liquidity removals               |
| `settlement`                     | `BatchSettlement`                | The settlement to execute                                  |
| `targetBlockNumber`              | `uint256`                        | The block number at which the settlement is valid          |
| `batchId`                        | `uint256`                        | The unique identifier for this settlement batch            |

### unlockCallback

Take loans, fill orders, repay the loans

This function is called by the UniV4PoolManager contract.

```solidity
function unlockCallback(bytes calldata data) external override returns (bytes memory);
```

### batchExecutedSellAmounts

Returns the cumulative executed sell amount for a batch of orders over all settlements

```solidity
function batchExecutedSellAmounts(bytes32[] calldata orderHashes) external view returns (uint256[] memory);
```

**Parameters**

| Name          | Type        | Description              |
| ------------- | ----------- | ------------------------ |
| `orderHashes` | `bytes32[]` | The hashes of the orders |

**Returns**

| Name     | Type        | Description               |
| -------- | ----------- | ------------------------- |
| `<none>` | `uint256[]` | The executed sell amounts |

### getTurbineLiquidityRouter

Returns the address of the TurbineLiquidityRouter

Return type is address to avoid unnecessary imports

```solidity
function getTurbineLiquidityRouter() external view returns (address);
```

**Returns**

| Name     | Type      | Description                               |
| -------- | --------- | ----------------------------------------- |
| `<none>` | `address` | The address of the TurbineLiquidityRouter |

### getTurbineHook

Returns the address of the TurbineHook (via the TurbineLiquidityRouter)

Return type is address to avoid unnecessary imports

```solidity
function getTurbineHook() external view returns (address);
```

**Returns**

| Name     | Type      | Description                    |
| -------- | --------- | ------------------------------ |
| `<none>` | `address` | The address of the TurbineHook |

### \_executeBatchSettlement

\------------------------- 🛠️ INTERNAL METHODS ------------------------- ///

Execute a settlement, potentially taking flashloans

```solidity
function _executeBatchSettlement(BatchSettlement calldata settlement) internal;
```

### \_executeSmartOrderSwaps

Executes smart orders

```solidity
function _executeSmartOrderSwaps(SmartOrderExecution[] memory swaps) internal;
```

### \_executeDEXSwaps

Executes DEX pool swaps

```solidity
function _executeDEXSwaps(DEXSwap[] memory swaps) internal;
```

### \_executeTurbinePoolExecutions

Execute Turbine pool executions

```solidity
function _executeTurbinePoolExecutions(TurbinePoolExecution[] memory executions) internal;
```

### \_receiveSellTokens

```solidity
function _receiveSellTokens(LimitOrderExecution[] memory swaps) internal;
```

### \_sendBuyTokens

```solidity
function _sendBuyTokens(LimitOrderExecution[] memory swaps, ReceivedTokenAmount[] memory tokenAmounts) internal;
```

### \_computeReceivedTokenAmounts

```solidity
function _computeReceivedTokenAmounts(
    BatchSettlement memory settlement,
    uint256[] memory initialBalances
) internal view returns (ReceivedTokenAmount[] memory);
```

### \_executeSmartOrderSwap

Execute swaps on external contracts

This is used both to execute smart orders and to execute swaps on liquidity pools. These two cases are almost identical, but they might diverge in the future. We may decide later to merge them.

```solidity
function _executeSmartOrderSwap(SmartOrderExecution memory swap) internal returns (uint256);
```

**Parameters**

| Name   | Type                  | Description          |
| ------ | --------------------- | -------------------- |
| `swap` | `SmartOrderExecution` | The swap to execute. |

**Returns**

| Name     | Type      | Description                                                       |
| -------- | --------- | ----------------------------------------------------------------- |
| `<none>` | `uint256` | Returns the received sell amount from this smart order execution. |

### \_executeDEXSwap

Execute a swap on a DEX pool

We don't check for amounts transferred because we do these checks at a token level

```solidity
function _executeDEXSwap(DEXSwap memory swap) internal returns (uint256);
```

**Parameters**

| Name   | Type      | Description          |
| ------ | --------- | -------------------- |
| `swap` | `DEXSwap` | The swap to execute. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.turbine.exchange/reference/contracts/solidity-documentation/settler/contract.turbinesettler.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
