# IPairsStorageUtils

*Interface for GNSPairsStorage facet (inherits types and also contains functions, events, and custom errors)*

## initializeGroupLiquidationParams

```solidity
function initializeGroupLiquidationParams(struct IPairsStorage.GroupLiquidationParams[] _groupLiquidationParams) external
```

*Initializes liquidation params for all existing groups*

### Parameters

| Name                     | Type                                                                                                                                                    | Description                                                          |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| \_groupLiquidationParams | [IPairsStorage.GroupLiquidationParams\[\]](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#groupliquidationparams) | liquidation params for each group (index corresponds to group index) |

## initializeNewFees

```solidity
function initializeNewFees(struct IPairsStorage.GlobalTradeFeeParams _tradeFeeParams) external
```

*Copies all existing fee groups to new mapping, multiplies existing groups min/max lev by 1e3, initializes new global trade fee params*

### Parameters

| Name             | Type                                                                                                                                            | Description             |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| \_tradeFeeParams | [IPairsStorage.GlobalTradeFeeParams](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#globaltradefeeparams) | global trade fee params |

## addPairs

```solidity
function addPairs(struct IPairsStorage.Pair[] _pairs) external
```

*Adds new trading pairs*

### Parameters

| Name    | Type                                                                                                                | Description  |
| ------- | ------------------------------------------------------------------------------------------------------------------- | ------------ |
| \_pairs | [IPairsStorage.Pair\[\]](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#pair) | pairs to add |

## updatePairs

```solidity
function updatePairs(uint256[] _pairIndices, struct IPairsStorage.Pair[] _pairs) external
```

*Updates trading pairs*

### Parameters

| Name          | Type                                                                                                                | Description      |
| ------------- | ------------------------------------------------------------------------------------------------------------------- | ---------------- |
| \_pairIndices | uint256\[]                                                                                                          | indices of pairs |
| \_pairs       | [IPairsStorage.Pair\[\]](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#pair) | new pairs values |

## addGroups

```solidity
function addGroups(struct IPairsStorage.Group[] _groups) external
```

*Adds new pair groups*

### Parameters

| Name     | Type                                                                                                                  | Description   |
| -------- | --------------------------------------------------------------------------------------------------------------------- | ------------- |
| \_groups | [IPairsStorage.Group\[\]](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#group) | groups to add |

## updateGroups

```solidity
function updateGroups(uint256[] _ids, struct IPairsStorage.Group[] _groups) external
```

*Updates pair groups*

### Parameters

| Name     | Type                                                                                                                  | Description       |
| -------- | --------------------------------------------------------------------------------------------------------------------- | ----------------- |
| \_ids    | uint256\[]                                                                                                            | indices of groups |
| \_groups | [IPairsStorage.Group\[\]](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#group) | new groups values |

## addFees

```solidity
function addFees(struct IPairsStorage.FeeGroup[] _fees) external
```

*Adds new pair fees groups*

### Parameters

| Name   | Type                                                                                                                        | Description |
| ------ | --------------------------------------------------------------------------------------------------------------------------- | ----------- |
| \_fees | [IPairsStorage.FeeGroup\[\]](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#feegroup) | fees to add |

## updateFees

```solidity
function updateFees(uint256[] _ids, struct IPairsStorage.FeeGroup[] _fees) external
```

*Updates pair fees groups*

### Parameters

| Name   | Type                                                                                                                        | Description     |
| ------ | --------------------------------------------------------------------------------------------------------------------------- | --------------- |
| \_ids  | uint256\[]                                                                                                                  | indices of fees |
| \_fees | [IPairsStorage.FeeGroup\[\]](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#feegroup) | new fees values |

## setPairCustomMaxLeverages

```solidity
function setPairCustomMaxLeverages(uint256[] _indices, uint256[] _values) external
```

*Updates pair custom max leverages (if unset group default is used); useful to delist a pair if new value is below the pair's group minLeverage*

### Parameters

| Name      | Type       | Description                              |
| --------- | ---------- | ---------------------------------------- |
| \_indices | uint256\[] | indices of pairs                         |
| \_values  | uint256\[] | new custom max leverages (1e3 precision) |

## setGroupLiquidationParams

```solidity
function setGroupLiquidationParams(uint256 _groupIndex, struct IPairsStorage.GroupLiquidationParams _params) external
```

*Updates group liquidation params (will only apply for trades opened after the change)*

### Parameters

| Name         | Type                                                                                                                                                | Description            |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
| \_groupIndex | uint256                                                                                                                                             | index of group         |
| \_params     | [IPairsStorage.GroupLiquidationParams](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#groupliquidationparams) | new liquidation params |

## setGlobalTradeFeeParams

```solidity
function setGlobalTradeFeeParams(struct IPairsStorage.GlobalTradeFeeParams _feeParams) external
```

*Updates global trade fee params*

### Parameters

| Name        | Type                                                                                                                                            | Description    |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
| \_feeParams | [IPairsStorage.GlobalTradeFeeParams](https://docs.gains.trade/developer/technical-reference/contracts/types/ipairsstorage#globaltradefeeparams) | new fee params |

## pairJob

```solidity
function pairJob(uint256 _pairIndex) external view returns (string from, string to)
```

*Returns data needed by price aggregator when doing a new price request*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

### Return Values

| Name | Type   | Description         |
| ---- | ------ | ------------------- |
| from | string | pair from (eg. BTC) |
| to   | string | pair to (eg. USD)   |

## isPairListed

```solidity
function isPairListed(string _from, string _to) external view returns (bool)
```

*Returns whether a pair is listed*

### Parameters

| Name   | Type   | Description         |
| ------ | ------ | ------------------- |
| \_from | string | pair from (eg. BTC) |
| \_to   | string | pair to (eg. USD)   |

## isPairIndexListed

```solidity
function isPairIndexListed(uint256 _pairIndex) external view returns (bool)
```

*Returns whether a pair index is listed*

### Parameters

| Name        | Type    | Description            |
| ----------- | ------- | ---------------------- |
| \_pairIndex | uint256 | index of pair to check |

## pairs

```solidity
function pairs(uint256 _index) external view returns (struct IPairsStorage.Pair)
```

*Returns a pair's details*

### Parameters

| Name    | Type    | Description   |
| ------- | ------- | ------------- |
| \_index | uint256 | index of pair |

## pairsCount

```solidity
function pairsCount() external view returns (uint256)
```

*Returns number of listed pairs*

## pairSpreadP

```solidity
function pairSpreadP(uint256 _pairIndex) external view returns (uint256)
```

*Returns a pair's spread % (1e10 precision)*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

## pairMinLeverage

```solidity
function pairMinLeverage(uint256 _pairIndex) external view returns (uint256)
```

*Returns a pair's min leverage (1e3 precision)*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

## pairTotalPositionSizeFeeP

```solidity
function pairTotalPositionSizeFeeP(uint256 _pairIndex) external view returns (uint256)
```

*Returns a pair's total position size fee % (1e10 precision)*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

## pairTotalLiqCollateralFeeP

```solidity
function pairTotalLiqCollateralFeeP(uint256 _pairIndex) external view returns (uint256)
```

*Returns a pair's total liquidation collateral fee % (1e10 precision)*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

## pairOraclePositionSizeFeeP

```solidity
function pairOraclePositionSizeFeeP(uint256 _pairIndex) external view returns (uint256)
```

*Returns a pair's oracle position size fee % (1e10 precision)*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

## pairMinPositionSizeUsd

```solidity
function pairMinPositionSizeUsd(uint256 _pairIndex) external view returns (uint256)
```

*Returns a pair's min position size in USD (1e18 precision)*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

## getGlobalTradeFeeParams

```solidity
function getGlobalTradeFeeParams() external view returns (struct IPairsStorage.GlobalTradeFeeParams)
```

*Returns global trade fee params*

## pairMinFeeUsd

```solidity
function pairMinFeeUsd(uint256 _pairIndex) external view returns (uint256)
```

*Returns a pair's minimum trading fee in USD (1e18 precision)*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

## groups

```solidity
function groups(uint256 _index) external view returns (struct IPairsStorage.Group)
```

*Returns a group details*

### Parameters

| Name    | Type    | Description    |
| ------- | ------- | -------------- |
| \_index | uint256 | index of group |

## groupsCount

```solidity
function groupsCount() external view returns (uint256)
```

*Returns number of listed groups*

## fees

```solidity
function fees(uint256 _index) external view returns (struct IPairsStorage.FeeGroup)
```

*Returns a fee group details*

### Parameters

| Name    | Type    | Description        |
| ------- | ------- | ------------------ |
| \_index | uint256 | index of fee group |

## feesCount

```solidity
function feesCount() external view returns (uint256)
```

*Returns number of listed fee groups*

## pairMaxLeverage

```solidity
function pairMaxLeverage(uint256 _pairIndex) external view returns (uint256)
```

*Returns a pair's active max leverage; custom if set, otherwise group default (1e3 precision)*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

## pairCustomMaxLeverage

```solidity
function pairCustomMaxLeverage(uint256 _pairIndex) external view returns (uint256)
```

*Returns a pair's custom max leverage; 0 if not set (1e3 precision)*

### Parameters

| Name        | Type    | Description   |
| ----------- | ------- | ------------- |
| \_pairIndex | uint256 | index of pair |

## getAllPairsRestrictedMaxLeverage

```solidity
function getAllPairsRestrictedMaxLeverage() external view returns (uint256[])
```

*Returns all listed pairs custom max leverages (1e3 precision)*

## getGroupLiquidationParams

```solidity
function getGroupLiquidationParams(uint256 _groupIndex) external view returns (struct IPairsStorage.GroupLiquidationParams)
```

*Returns a group's liquidation params*

## getPairLiquidationParams

```solidity
function getPairLiquidationParams(uint256 _pairIndex) external view returns (struct IPairsStorage.GroupLiquidationParams)
```

*Returns a pair's group liquidation params*

## PairAdded

```solidity
event PairAdded(uint256 index, string from, string to)
```

*Emitted when a new pair is listed*

### Parameters

| Name  | Type    | Description         |
| ----- | ------- | ------------------- |
| index | uint256 | index of pair       |
| from  | string  | pair from (eg. BTC) |
| to    | string  | pair to (eg. USD)   |

## PairUpdated

```solidity
event PairUpdated(uint256 index)
```

*Emitted when a pair is updated*

### Parameters

| Name  | Type    | Description   |
| ----- | ------- | ------------- |
| index | uint256 | index of pair |

## PairCustomMaxLeverageUpdated

```solidity
event PairCustomMaxLeverageUpdated(uint256 index, uint256 maxLeverage)
```

*Emitted when a pair's custom max leverage is updated*

### Parameters

| Name        | Type    | Description                      |
| ----------- | ------- | -------------------------------- |
| index       | uint256 | index of pair                    |
| maxLeverage | uint256 | new max leverage (1e3 precision) |

## GroupAdded

```solidity
event GroupAdded(uint256 index, string name)
```

*Emitted when a new group is added*

### Parameters

| Name  | Type    | Description    |
| ----- | ------- | -------------- |
| index | uint256 | index of group |
| name  | string  | name of group  |

## GroupUpdated

```solidity
event GroupUpdated(uint256 index)
```

*Emitted when a group is updated*

### Parameters

| Name  | Type    | Description    |
| ----- | ------- | -------------- |
| index | uint256 | index of group |

## FeeAdded

```solidity
event FeeAdded(uint256 index, struct IPairsStorage.FeeGroup feeGroup)
```

*Emitted when a new fee group is added*

### Parameters

| Name     | Type                          | Description        |
| -------- | ----------------------------- | ------------------ |
| index    | uint256                       | index of fee group |
| feeGroup | struct IPairsStorage.FeeGroup | fee group          |

## FeeUpdated

```solidity
event FeeUpdated(uint256 index, struct IPairsStorage.FeeGroup feeGroup)
```

*Emitted when a fee group is updated*

### Parameters

| Name     | Type                          | Description        |
| -------- | ----------------------------- | ------------------ |
| index    | uint256                       | index of fee group |
| feeGroup | struct IPairsStorage.FeeGroup | updated fee group  |

## GroupLiquidationParamsUpdated

```solidity
event GroupLiquidationParamsUpdated(uint256 index, struct IPairsStorage.GroupLiquidationParams params)
```

*Emitted when a group liquidation params are updated*

### Parameters

| Name   | Type                                        | Description                  |
| ------ | ------------------------------------------- | ---------------------------- |
| index  | uint256                                     | index of group               |
| params | struct IPairsStorage.GroupLiquidationParams | new group liquidation params |

## GlobalTradeFeeParamsUpdated

```solidity
event GlobalTradeFeeParamsUpdated(struct IPairsStorage.GlobalTradeFeeParams feeParams)
```

*Emitted when global trade fee params are updated*

### Parameters

| Name      | Type                                      | Description    |
| --------- | ----------------------------------------- | -------------- |
| feeParams | struct IPairsStorage.GlobalTradeFeeParams | new fee params |

## PairNotListed

```solidity
error PairNotListed()
```

## GroupNotListed

```solidity
error GroupNotListed()
```

## FeeNotListed

```solidity
error FeeNotListed()
```

## WrongLeverages

```solidity
error WrongLeverages()
```

## WrongFees

```solidity
error WrongFees()
```

## PairAlreadyListed

```solidity
error PairAlreadyListed()
```

## MaxLiqSpreadPTooHigh

```solidity
error MaxLiqSpreadPTooHigh()
```

## WrongLiqParamsThresholds

```solidity
error WrongLiqParamsThresholds()
```

## WrongLiqParamsLeverages

```solidity
error WrongLiqParamsLeverages()
```

## StartLiqThresholdTooHigh

```solidity
error StartLiqThresholdTooHigh()
```

## EndLiqThresholdTooLow

```solidity
error EndLiqThresholdTooLow()
```

## StartLeverageTooLow

```solidity
error StartLeverageTooLow()
```

## EndLeverageTooHigh

```solidity
error EndLeverageTooHigh()
```
