# GlvReader

> The `GlvReader` contract provides read-only functions for querying GMX Liquidity Vault (GLV) data from on-chain storage.

# GlvReader

The `GlvReader` contract provides read-only functions for querying GMX Liquidity Vault (GLV) data from on-chain storage.

For GM market reader functions, see [Reader](./reader.md).

This page focuses on the most commonly used GLV read helpers. For the full public surface, see [`GlvReader.sol`](https://github.com/gmx-io/gmx-synthetics/blob/updates/contracts/reader/GlvReader.sol).

Examples below assume you already have contract instances such as `glvReader` and `dataStore`, plus any required price structs.

## Getting a list of GLVs

Use `getGlvs` to retrieve all registered GLV vaults.

### GlvReader.getGlvs

```solidity
function getGlvs(DataStore dataStore, uint256 start, uint256 end)
    external view returns (Glv.Props[] memory)
```

**Example (TypeScript / ethers):**

```typescript
const glvs = await glvReader.getGlvs(dataStore.address, 0, 20);
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `start`     | `uint256` | Start index for pagination        |
| `end`       | `uint256` | End index for pagination          |

**Returns:** Array of `Glv.Props`.

### Glv.Props

| Field        | Type      | Description                |
| ------------ | --------- | -------------------------- |
| `glvToken`   | `address` | Address of the GLV token   |
| `longToken`  | `address` | Address of the long token  |
| `shortToken` | `address` | Address of the short token |

## Getting GLV info with market list

Use `getGlvInfoList` to retrieve GLV vaults together with the markets each vault is exposed to.

### GlvReader.getGlvInfoList

```solidity
function getGlvInfoList(DataStore dataStore, uint256 start, uint256 end)
    external view returns (GlvInfo[] memory)
```

**Example (TypeScript / ethers):**

```typescript
const glvInfoList = await glvReader.getGlvInfoList(dataStore.address, 0, 20);
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `start`     | `uint256` | Start index for pagination        |
| `end`       | `uint256` | End index for pagination          |

**Returns:** Array of `GlvInfo` elements, each containing a `Glv.Props` and a list of market addresses.

## Getting GLV value

Use `getGlvValue` to retrieve the total GLV vault value before converting it into a token price.

### GlvReader.getGlvValue

```solidity
function getGlvValue(
    DataStore dataStore,
    address[] memory marketAddresses,
    Price.Props[] memory indexTokenPrices,
    Price.Props memory longTokenPrice,
    Price.Props memory shortTokenPrice,
    address glv,
    bool maximize
) external view returns (uint256)
```

**Example (TypeScript / ethers):**

```typescript
const glvValue = await glvReader.getGlvValue(
  dataStore.address,
  marketAddresses,
  indexTokenPrices,
  longTokenPrice,
  shortTokenPrice,
  glvAddress,
  true
);
```

**Parameters:**

| Parameter          | Type            | Description                                                                             |
| ------------------ | --------------- | --------------------------------------------------------------------------------------- |
| `dataStore`        | `address`       | Address of the DataStore contract                                                       |
| `marketAddresses`  | `address[]`     | Addresses of the markets inside the GLV                                                 |
| `indexTokenPrices` | `Price.Props[]` | Prices for the index tokens of each GLV market. The order must match `marketAddresses`. |
| `longTokenPrice`   | `Price.Props`   | Price of the long token                                                                 |
| `shortTokenPrice`  | `Price.Props`   | Price of the short token                                                                |
| `glv`              | `address`       | Address of the GLV vault                                                                |
| `maximize`         | `bool`          | When `true`, uses maximum token prices. When `false`, uses minimum prices.              |

**Returns:** Total GLV vault value in 30-decimal USD precision.

## Getting GLV token price

Use `getGlvTokenPrice` to retrieve a GLV token price for the supplied market list, token prices, and min/max direction. The call also returns total vault value and total supply.

Use this method when you need direct GMX Reader valuation for a specific block and supplied price context, or when a Chainlink Data Feed is not available. For external protocol integrations that only need a standard oracle interface, prefer Chainlink Data Feeds where available. For the integration decision tree, see [Getting GM and GLV token prices](../gm-glv-prices.md).

### GlvReader.getGlvTokenPrice

```solidity
function getGlvTokenPrice(
    DataStore dataStore,
    address[] memory marketAddresses,
    Price.Props[] memory indexTokenPrices,
    Price.Props memory longTokenPrice,
    Price.Props memory shortTokenPrice,
    address glv,
    bool maximize
) external view returns (uint256, uint256, uint256)
```

**Example (TypeScript / ethers):**

```typescript
const [glvPrice, glvValue, totalSupply] = await glvReader.getGlvTokenPrice(
  dataStore.address,
  marketAddresses,
  indexTokenPrices,
  longTokenPrice,
  shortTokenPrice,
  glvAddress,
  true
);
```

**Parameters:**

| Parameter          | Type            | Description                                                                             |
| ------------------ | --------------- | --------------------------------------------------------------------------------------- |
| `dataStore`        | `address`       | Address of the DataStore contract                                                       |
| `marketAddresses`  | `address[]`     | Addresses of the markets inside the GLV                                                 |
| `indexTokenPrices` | `Price.Props[]` | Prices for the index tokens of each GLV market. The order must match `marketAddresses`. |
| `longTokenPrice`   | `Price.Props`   | Price of the long token                                                                 |
| `shortTokenPrice`  | `Price.Props`   | Price of the short token                                                                |
| `glv`              | `address`       | Address of the GLV vault                                                                |
| `maximize`         | `bool`          | When `true`, uses maximum token prices. When `false`, uses minimum prices.              |

**Returns:** A tuple of `(uint256 price, uint256 glvValue, uint256 totalSupply)`.

## Direct GLV lookups

Use these methods when you already have a GLV address or deployment salt and want the raw stored object.

### GlvReader.getGlv

```solidity
function getGlv(DataStore dataStore, address glv)
    external view returns (Glv.Props memory)
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `glv`       | `address` | GLV token address                 |

**Returns:** `Glv.Props` for the requested GLV.

### GlvReader.getGlvInfo

```solidity
function getGlvInfo(DataStore dataStore, address glv)
    public view returns (GlvInfo memory)
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `glv`       | `address` | GLV token address                 |

**Returns:** `GlvInfo`, containing the GLV props plus its supported market list.

### GlvReader.getGlvBySalt

```solidity
function getGlvBySalt(DataStore dataStore, bytes32 salt)
    external view returns (Glv.Props memory)
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `salt`      | `bytes32` | Deterministic GLV deployment salt |

**Returns:** `Glv.Props` for the requested GLV.

## GLV deposit requests

Use these methods to inspect GLV deposit requests by key, globally, or for one account.

### GlvReader.getGlvDeposit

```solidity
function getGlvDeposit(DataStore dataStore, bytes32 key)
    external view returns (GlvDeposit.Props memory)
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `key`       | `bytes32` | GLV deposit request key           |

**Returns:** Raw `GlvDeposit.Props` for the request.

### GlvReader.getGlvDeposits

```solidity
function getGlvDeposits(
    DataStore dataStore,
    uint256 start,
    uint256 end
) external view returns (GlvDeposit.Props[] memory)
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `start`     | `uint256` | Start index for pagination        |
| `end`       | `uint256` | End index for pagination          |

**Returns:** Array of `GlvDeposit.Props` values.

### GlvReader.getAccountGlvDeposits

```solidity
function getAccountGlvDeposits(
    DataStore dataStore,
    address account,
    uint256 start,
    uint256 end
) external view returns (GlvDeposit.Props[] memory)
```

**Parameters:**

| Parameter   | Type      | Description                          |
| ----------- | --------- | ------------------------------------ |
| `dataStore` | `address` | Address of the DataStore contract    |
| `account`   | `address` | Account to retrieve GLV deposits for |
| `start`     | `uint256` | Start index for pagination           |
| `end`       | `uint256` | End index for pagination             |

**Returns:** Array of `GlvDeposit.Props` values for the account.

## GLV withdrawal requests

Use these methods to inspect GLV withdrawal requests by key, globally, or for one account.

### GlvReader.getGlvWithdrawal

```solidity
function getGlvWithdrawal(DataStore dataStore, bytes32 key)
    external view returns (GlvWithdrawal.Props memory)
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `key`       | `bytes32` | GLV withdrawal request key        |

**Returns:** Raw `GlvWithdrawal.Props` for the request.

### GlvReader.getGlvWithdrawals

```solidity
function getGlvWithdrawals(
    DataStore dataStore,
    uint256 start,
    uint256 end
) external view returns (GlvWithdrawal.Props[] memory)
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `start`     | `uint256` | Start index for pagination        |
| `end`       | `uint256` | End index for pagination          |

**Returns:** Array of `GlvWithdrawal.Props` values.

### GlvReader.getAccountGlvWithdrawals

```solidity
function getAccountGlvWithdrawals(
    DataStore dataStore,
    address account,
    uint256 start,
    uint256 end
) external view returns (GlvWithdrawal.Props[] memory)
```

**Parameters:**

| Parameter   | Type      | Description                             |
| ----------- | --------- | --------------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract       |
| `account`   | `address` | Account to retrieve GLV withdrawals for |
| `start`     | `uint256` | Start index for pagination              |
| `end`       | `uint256` | End index for pagination                |

**Returns:** Array of `GlvWithdrawal.Props` values for the account.

## GLV shift requests

Use these methods to inspect GLV shift requests by key or through paginated lists.

### GlvReader.getGlvShift

```solidity
function getGlvShift(DataStore dataStore, bytes32 key)
    external view returns (GlvShift.Props memory)
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `key`       | `bytes32` | GLV shift request key             |

**Returns:** Raw `GlvShift.Props` for the request.

### GlvReader.getGlvShifts

```solidity
function getGlvShifts(
    DataStore dataStore,
    uint256 start,
    uint256 end
) external view returns (GlvShift.Props[] memory)
```

**Parameters:**

| Parameter   | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `dataStore` | `address` | Address of the DataStore contract |
| `start`     | `uint256` | Start index for pagination        |
| `end`       | `uint256` | End index for pagination          |

**Returns:** Array of `GlvShift.Props` values.
