> 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/reader-contract.md).

# Reader Contract

### Overview

Reader is used for:

* Querying market information
* Getting position details
* Calculating prices and fees
* Retrieving account data
* Simulating deposits and withdrawals

### Functions

#### Market Data

**getMarket**

Get market configuration.

```solidity
function getMarket(
    DataStore dataStore,
    address key
) external view returns (Market.Props);
```

**getMarketBySalt**

Get market by salt.

```solidity
function getMarketBySalt(
    DataStore dataStore,
    bytes32 salt
) external view returns (Market.Props);
```

**getMarketInfo**

Get detailed market information.

```solidity
function getMarketInfo(
    DataStore dataStore,
    MarketUtils.MarketPrices prices,
    address marketKey
) external view returns (ReaderUtils.MarketInfo);
```

**getMarketInfoList**

Get market information for multiple markets.

```solidity
function getMarketInfoList(
    DataStore dataStore,
    MarketUtils.MarketPrices[] marketPricesList,
    uint256 start,
    uint256 end
) external view returns (ReaderUtils.MarketInfo[]);
```

**getMarkets**

Get all markets.

```solidity
function getMarkets(
    DataStore dataStore,
    uint256 start,
    uint256 end
) external view returns (Market.Props[]);
```

**getMarketTokenPrice**

Get current HM token price.

```solidity
function getMarketTokenPrice(
    DataStore dataStore,
    Market.Props market,
    Price.Props indexTokenPrice,
    Price.Props longTokenPrice,
    Price.Props shortTokenPrice,
    bytes32 pnlFactorType,
    bool maximize
) external view returns ((int256, MarketPoolValueInfo.Props));
```

#### Position Data

**getAccountPositionInfoList**

Get position information for all positions of an account.

```solidity
function getAccountPositionInfoList(
    DataStore dataStore,
    IReferralStorage referralStorage,
    address account,
    address[] markets,
    MarketUtils.MarketPrices[] marketPrices,
    address uiFeeReceiver,
    uint256 start,
    uint256 end
) external view returns (ReaderPositionUtils.PositionInfo[]);
```

**getAccountPositions**

Get all positions for an account.

```solidity
function getAccountPositions(
    DataStore dataStore,
    address account,
    uint256 start,
    uint256 end
) external view returns (Position.Props[]);
```

**getPosition**

Get position details.

```solidity
function getPosition(
    DataStore dataStore,
    bytes32 key
) external view returns (Position.Props);
```

**getPositionInfo**

Get detailed position information including fees.

```solidity
function getPositionInfo(
    DataStore dataStore,
    IReferralStorage referralStorage,
    bytes32 positionKey,
    MarketUtils.MarketPrices prices,
    uint256 sizeDeltaUsd,
    address uiFeeReceiver,
    bool usePositionSizeAsSizeDeltaUsd
) external view returns (ReaderPositionUtils.PositionInfo);
```

**getPositionInfoList**

Get position information for multiple positions.

```solidity
function getPositionInfoList(
    DataStore dataStore,
    IReferralStorage referralStorage,
    bytes32[] positionKeys,
    MarketUtils.MarketPrices[] prices,
    address uiFeeReceiver
) external view returns (ReaderPositionUtils.PositionInfo[]);
```

**getPositionPnlUsd**

Get position PnL in USD.

```solidity
function getPositionPnlUsd(
    DataStore dataStore,
    Market.Props market,
    MarketUtils.MarketPrices prices,
    bytes32 positionKey,
    uint256 sizeDeltaUsd
) external view returns ((int256, int256, uint256));
```

**isPositionLiquidatable**

Check if a position can be liquidated.

```solidity
function isPositionLiquidatable(
    DataStore dataStore,
    IReferralStorage referralStorage,
    bytes32 positionKey,
    Market.Props market,
    MarketUtils.MarketPrices prices,
    bool shouldValidateMinCollateralUsd,
    bool forLiquidation
) external view returns ((bool, string, PositionUtils.IsPositionLiquidatableInfo));
```

#### Order Data

**getAccountOrders**

Get all orders for an account.

```solidity
function getAccountOrders(
    DataStore dataStore,
    address account,
    uint256 start,
    uint256 end
) external view returns (ReaderUtils.OrderInfo[]);
```

**getOrder**

Get order details.

```solidity
function getOrder(
    DataStore dataStore,
    bytes32 key
) external view returns (Order.Props);
```

#### Deposit & Withdrawal Data

**getDeposit**

Get deposit details.

```solidity
function getDeposit(
    DataStore dataStore,
    bytes32 key
) external view returns (Deposit.Props);
```

**getShift**

Get shift details.

```solidity
function getShift(
    DataStore dataStore,
    bytes32 key
) external view returns (Shift.Props);
```

**getWithdrawal**

Get withdrawal details.

```solidity
function getWithdrawal(
    DataStore dataStore,
    bytes32 key
) external view returns (Withdrawal.Props);
```

#### Simulation Functions

**getDepositAmountOut**

Simulate deposit and get expected HM tokens out.

```solidity
function getDepositAmountOut(
    DataStore dataStore,
    Market.Props market,
    MarketUtils.MarketPrices prices,
    uint256 longTokenAmount,
    uint256 shortTokenAmount,
    address uiFeeReceiver,
    ISwapPricingUtils.SwapPricingType swapPricingType,
    bool includeVirtualInventoryImpact
) external view returns (uint256);
```

**getExecutionPrice**

Get execution price for a position change.

```solidity
function getExecutionPrice(
    DataStore dataStore,
    address marketKey,
    MarketUtils.MarketPrices prices,
    uint256 positionSizeInUsd,
    uint256 positionSizeInTokens,
    int256 sizeDeltaUsd,
    int256 pendingImpactAmount,
    bool isLong
) external view returns (ReaderPricingUtils.ExecutionPriceResult);
```

**getSwapAmountOut**

Simulate swap and get expected output.

```solidity
function getSwapAmountOut(
    DataStore dataStore,
    Market.Props market,
    MarketUtils.MarketPrices prices,
    address tokenIn,
    uint256 amountIn,
    address uiFeeReceiver
) external view returns ((uint256, int256, SwapPricingUtils.SwapFees fees));
```

**getWithdrawalAmountOut**

Simulate withdrawal and get expected tokens out.

```solidity
function getWithdrawalAmountOut(
    DataStore dataStore,
    Market.Props market,
    MarketUtils.MarketPrices prices,
    uint256 marketTokenAmount,
    address uiFeeReceiver,
    ISwapPricingUtils.SwapPricingType swapPricingType
) external view returns ((uint256, uint256));
```

#### PnL & Analytics

**getNetPnl**

Get net PnL for a market.

```solidity
function getNetPnl(
    DataStore dataStore,
    Market.Props market,
    Price.Props indexTokenPrice,
    bool maximize
) external view returns (int256);
```

**getOpenInterestWithPnl**

Get open interest with PnL.

```solidity
function getOpenInterestWithPnl(
    DataStore dataStore,
    Market.Props market,
    Price.Props indexTokenPrice,
    bool isLong,
    bool maximize
) external view returns (int256);
```

**getPnl**

Get PnL for a specific side.

```solidity
function getPnl(
    DataStore dataStore,
    Market.Props market,
    Price.Props indexTokenPrice,
    bool isLong,
    bool maximize
) external view returns (int256);
```

**getPnlToPoolFactor**

Get PnL to pool factor.

```solidity
function getPnlToPoolFactor(
    DataStore dataStore,
    address marketAddress,
    MarketUtils.MarketPrices prices,
    bool isLong,
    bool maximize
) external view returns (int256);
```

#### Price Impact

**getSwapPriceImpact**

Calculate swap price impact.

```solidity
function getSwapPriceImpact(
    DataStore dataStore,
    address marketKey,
    address tokenIn,
    address tokenOut,
    uint256 amountIn,
    Price.Props tokenInPrice,
    Price.Props tokenOutPrice
) external view returns ((int256, int256, int256));
```

#### ADL State

**getAdlState**

Get ADL (Auto-Deleveraging) state.

```solidity
function getAdlState(
    DataStore dataStore,
    address market,
    bool isLong,
    MarketUtils.MarketPrices prices
) external view returns ((uint256, bool, int256, uint256));
```

#### Utility

**getPendingPositionImpactPoolDistributionAmount**

Get pending position impact pool distribution.

```solidity
function getPendingPositionImpactPoolDistributionAmount(
    DataStore dataStore,
    address market
) external view returns ((uint256, uint256));
```

***

### 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/reader-contract.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.
