> For the complete documentation index, see [llms.txt](https://hertzflow.gitbook.io/hertzflow-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hertzflow.gitbook.io/hertzflow-docs/tech-docs/smart-contract/exchangerouter.md).

# ExchangeRouter

### Overview

ExchangeRouter handles:

* Creating deposits and withdrawals
* Creating and managing orders
* Creating and managing shifts
* Claiming fees and collateral
* Token transfers
* External calls for integrations

### Functions

#### Deposits

**cancelDeposit**

Cancel a pending deposit.

```solidity
function cancelDeposit(bytes32 key) external payable;
```

**createDeposit**

Create a deposit request to add liquidity.

```solidity
function createDeposit(IDepositUtils.CreateDepositParams params) external payable returns (bytes32);
```

**simulateExecuteDeposit**

Simulate a deposit execution.

```solidity
function simulateExecuteDeposit(
    bytes32 key,
    OracleUtils.SimulatePricesParams simulatedOracleParams
) external payable;
```

**simulateExecuteLatestDeposit**

Simulate execution of the latest deposit.

```solidity
function simulateExecuteLatestDeposit(OracleUtils.SimulatePricesParams simulatedOracleParams) external payable;
```

#### Withdrawals

**cancelWithdrawal**

Cancel a pending withdrawal.

```solidity
function cancelWithdrawal(bytes32 key) external payable;
```

**createWithdrawal**

Create a withdrawal request to remove liquidity.

```solidity
function createWithdrawal(IWithdrawalUtils.CreateWithdrawalParams params) external payable returns (bytes32);
```

**executeAtomicWithdrawal**

Execute a withdrawal atomically (without keeper).

```solidity
function executeAtomicWithdrawal(
    IWithdrawalUtils.CreateWithdrawalParams params,
    OracleUtils.SetPricesParams oracleParams
) external payable;
```

**simulateExecuteLatestWithdrawal**

Simulate execution of the latest withdrawal.

```solidity
function simulateExecuteLatestWithdrawal(
    OracleUtils.SimulatePricesParams simulatedOracleParams,
    ISwapPricingUtils.SwapPricingType swapPricingType
) external payable;
```

**simulateExecuteWithdrawal**

Simulate a withdrawal execution.

```solidity
function simulateExecuteWithdrawal(
    bytes32 key,
    OracleUtils.SimulatePricesParams simulatedOracleParams,
    ISwapPricingUtils.SwapPricingType swapPricingType
) external payable;
```

#### Shifts

**cancelShift**

Cancel a pending shift.

```solidity
function cancelShift(bytes32 key) external payable;
```

**createShift**

Create a shift request to move liquidity between markets.

```solidity
function createShift(IShiftUtils.CreateShiftParams params) external payable returns (bytes32);
```

**simulateExecuteLatestShift**

Simulate execution of the latest shift.

```solidity
function simulateExecuteLatestShift(OracleUtils.SimulatePricesParams simulatedOracleParams) external payable;
```

**simulateExecuteShift**

Simulate a shift execution.

```solidity
function simulateExecuteShift(
    bytes32 key,
    OracleUtils.SimulatePricesParams simulatedOracleParams
) external payable;
```

#### Orders

**cancelOrder**

Cancel a pending order.

```solidity
function cancelOrder(bytes32 key) external payable;
```

**createOrder**

Create a new order (swap, increase, or decrease position).

```solidity
function createOrder(IBaseOrderUtils.CreateOrderParams params) external payable returns (bytes32);
```

**simulateExecuteLatestOrder**

Simulate execution of the latest order.

```solidity
function simulateExecuteLatestOrder(OracleUtils.SimulatePricesParams simulatedOracleParams) external payable;
```

**simulateExecuteOrder**

Simulate an order execution.

```solidity
function simulateExecuteOrder(
    bytes32 key,
    OracleUtils.SimulatePricesParams simulatedOracleParams
) external payable;
```

**updateOrder**

Update a pending order.

```solidity
function updateOrder(
    bytes32 key,
    uint256 sizeDeltaUsd,
    uint256 acceptablePrice,
    uint256 triggerPrice,
    uint256 minOutputAmount,
    uint256 validFromTime,
    bool autoCancel
) external payable;
```

#### Token Transfers

**sendNativeToken**

Transfer native tokens to a receiver.

```solidity
function sendNativeToken(
    address receiver,
    uint256 amount
) external payable;
```

**sendTokens**

Transfer ERC20 tokens from the caller to a receiver.

```solidity
function sendTokens(
    address token,
    address receiver,
    uint256 amount
) external payable;
```

**sendWnt**

Transfer wrapped native tokens (WNT) to a receiver.

```solidity
function sendWnt(
    address receiver,
    uint256 amount
) external payable;
```

#### Claims

**claimAffiliateRewards**

Claim affiliate rewards.

```solidity
function claimAffiliateRewards(
    address[] markets,
    address[] tokens,
    address receiver
) external payable returns (uint256[]);
```

**claimCollateral**

Claim collateral from capped price impact.

```solidity
function claimCollateral(
    address[] markets,
    address[] tokens,
    uint256[] timeKeys,
    address receiver
) external payable returns (uint256[]);
```

**claimFundingFees**

Claim accumulated funding fees.

```solidity
function claimFundingFees(
    address[] markets,
    address[] tokens,
    address receiver
) external payable returns (uint256[]);
```

**claimUiFees**

Claim UI fees.

```solidity
function claimUiFees(
    address[] markets,
    address[] tokens,
    address receiver
) external payable returns (uint256[]);
```

#### External Calls

**makeExternalCalls**

Perform external calls (e.g., swaps via aggregators) before protocol actions.

```solidity
function makeExternalCalls(
    address[] externalCallTargets,
    bytes[] externalCallDataList,
    address[] refundTokens,
    address[] refundReceivers
) external payable;
```

#### Settings

**setSavedCallbackContract**

Set a saved callback contract for liquidations and ADLs.

```solidity
function setSavedCallbackContract(
    address market,
    address callbackContract
) external payable;
```

**setUiFeeFactor**

Set the UI fee factor for the caller.

```solidity
function setUiFeeFactor(uint256 uiFeeFactor) external payable;
```

#### Multicall

**multicall**

Execute multiple calls in a single transaction (inherited from PayableMulticall).

```solidity
function multicall(bytes[] data) external payable returns (bytes[]);
```

#### View Functions

**dataStore**

Get the DataStore contract address.

```solidity
function dataStore() external view returns (DataStore);
```

**depositHandler**

Get the DepositHandler contract address.

```solidity
function depositHandler() external view returns (IDepositHandler);
```

**eventEmitter**

Get the EventEmitter contract address.

```solidity
function eventEmitter() external view returns (EventEmitter);
```

**externalHandler**

Get the ExternalHandler contract address.

```solidity
function externalHandler() external view returns (IExternalHandler);
```

**orderHandler**

Get the OrderHandler contract address.

```solidity
function orderHandler() external view returns (IOrderHandler);
```

**roleStore**

Get the RoleStore contract address.

```solidity
function roleStore() external view returns (RoleStore);
```

**router**

Get the Router contract address.

```solidity
function router() external view returns (Router);
```

**shiftHandler**

Get the ShiftHandler contract address.

```solidity
function shiftHandler() external view returns (IShiftHandler);
```

**withdrawalHandler**

Get the WithdrawalHandler contract address.

```solidity
function withdrawalHandler() external view returns (IWithdrawalHandler);
```

***

### Notes

{% hint style="info" %}
This documentation was auto-generated from the contract ABI.
{% endhint %}


---

# 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, and the optional `goal` query parameter:

```
GET https://hertzflow.gitbook.io/hertzflow-docs/tech-docs/smart-contract/exchangerouter.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
