> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gains.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# PriceAggregatorUtils

*GNSPriceAggregator facet external library*

## initializePriceAggregator

```solidity theme={null}
function initializePriceAggregator(address _linkErc677, contract IChainlinkFeed _linkUsdPriceFeed, uint24 _twapInterval, uint8 _minAnswers, address[] _oracles, bytes32[2] _jobIds, uint8[] _collateralIndices, struct IPriceAggregator.LiquidityPoolInput[] _gnsCollateralLiquidityPools, contract IChainlinkFeed[] _collateralUsdPriceFeeds) external
```

*Check IPriceAggregatorUtils interface for documentation*

## updateLinkUsdPriceFeed

```solidity theme={null}
function updateLinkUsdPriceFeed(contract IChainlinkFeed _value) public
```

*Check IPriceAggregatorUtils interface for documentation*

## updateCollateralUsdPriceFeed

```solidity theme={null}
function updateCollateralUsdPriceFeed(uint8 _collateralIndex, contract IChainlinkFeed _value) public
```

*Check IPriceAggregatorUtils interface for documentation*

## updateCollateralGnsLiquidityPool

```solidity theme={null}
function updateCollateralGnsLiquidityPool(uint8 _collateralIndex, struct IPriceAggregator.LiquidityPoolInput _liquidityPoolInput) public
```

*Check IPriceAggregatorUtils interface for documentation*

## updateTwapInterval

```solidity theme={null}
function updateTwapInterval(uint24 _twapInterval) public
```

*Check IPriceAggregatorUtils interface for documentation*

## updateMinAnswers

```solidity theme={null}
function updateMinAnswers(uint8 _value) public
```

*Check IPriceAggregatorUtils interface for documentation*

## addOracle

```solidity theme={null}
function addOracle(address _a) public
```

*Check IPriceAggregatorUtils interface for documentation*

## replaceOracle

```solidity theme={null}
function replaceOracle(uint256 _index, address _a) external
```

*Check IPriceAggregatorUtils interface for documentation*

## removeOracle

```solidity theme={null}
function removeOracle(uint256 _index) external
```

*Check IPriceAggregatorUtils interface for documentation*

## setMarketJobId

```solidity theme={null}
function setMarketJobId(bytes32 _jobId) public
```

*Check IPriceAggregatorUtils interface for documentation*

## setLimitJobId

```solidity theme={null}
function setLimitJobId(bytes32 _jobId) public
```

*Check IPriceAggregatorUtils interface for documentation*

## getPrice

```solidity theme={null}
function getPrice(uint8 _collateralIndex, uint16 _pairIndex, struct ITradingStorage.Id _tradeId, struct ITradingStorage.Id _orderId, enum ITradingStorage.PendingOrderType _orderType, uint256 _positionSizeCollateral, uint256 _fromBlock) external
```

*Check IPriceAggregatorUtils interface for documentation*

## fulfill

```solidity theme={null}
function fulfill(bytes32 _requestId, uint256 _priceData) external
```

*Check IPriceAggregatorUtils interface for documentation*

## claimBackLink

```solidity theme={null}
function claimBackLink() external
```

*Check IPriceAggregatorUtils interface for documentation*

## getLinkFee

```solidity theme={null}
function getLinkFee(uint8 _collateralIndex, address _trader, uint16 _pairIndex, uint256 _positionSizeCollateral) public view returns (uint256)
```

*Check IPriceAggregatorUtils interface for documentation*

## getCollateralPriceUsd

```solidity theme={null}
function getCollateralPriceUsd(uint8 _collateralIndex) public view returns (uint256)
```

*Check IPriceAggregatorUtils interface for documentation*

## getUsdNormalizedValue

```solidity theme={null}
function getUsdNormalizedValue(uint8 _collateralIndex, uint256 _collateralValue) public view returns (uint256)
```

*Check IPriceAggregatorUtils interface for documentation*

## getCollateralFromUsdNormalizedValue

```solidity theme={null}
function getCollateralFromUsdNormalizedValue(uint8 _collateralIndex, uint256 _normalizedValue) external view returns (uint256)
```

*Check IPriceAggregatorUtils interface for documentation*

## getGnsPriceUsd

```solidity theme={null}
function getGnsPriceUsd(uint8 _collateralIndex) external view returns (uint256)
```

*Check IPriceAggregatorUtils interface for documentation*

## getGnsPriceUsd

```solidity theme={null}
function getGnsPriceUsd(uint8 _collateralIndex, uint256 _gnsPriceCollateral) public view returns (uint256)
```

*Check IPriceAggregatorUtils interface for documentation*

## getGnsPriceCollateralAddress

```solidity theme={null}
function getGnsPriceCollateralAddress(address _collateral) external view returns (uint256 _price)
```

*Check IPriceAggregatorUtils interface for documentation*

## getGnsPriceCollateralIndex

```solidity theme={null}
function getGnsPriceCollateralIndex(uint8 _collateralIndex) public view returns (uint256 _price)
```

*Check IPriceAggregatorUtils interface for documentation*

## getLinkUsdPriceFeed

```solidity theme={null}
function getLinkUsdPriceFeed() external view returns (contract IChainlinkFeed)
```

*Check IPriceAggregatorUtils interface for documentation*

## getTwapInterval

```solidity theme={null}
function getTwapInterval() external view returns (uint24)
```

*Check IPriceAggregatorUtils interface for documentation*

## getMinAnswers

```solidity theme={null}
function getMinAnswers() external view returns (uint8)
```

*Check IPriceAggregatorUtils interface for documentation*

## getMarketJobId

```solidity theme={null}
function getMarketJobId() external view returns (bytes32)
```

*Check IPriceAggregatorUtils interface for documentation*

## getLimitJobId

```solidity theme={null}
function getLimitJobId() external view returns (bytes32)
```

*Check IPriceAggregatorUtils interface for documentation*

## getOracle

```solidity theme={null}
function getOracle(uint256 _index) external view returns (address)
```

*Check IPriceAggregatorUtils interface for documentation*

## getOracles

```solidity theme={null}
function getOracles() external view returns (address[])
```

*Check IPriceAggregatorUtils interface for documentation*

## getCollateralGnsLiquidityPool

```solidity theme={null}
function getCollateralGnsLiquidityPool(uint8 _collateralIndex) external view returns (struct IPriceAggregator.LiquidityPoolInfo)
```

*Check IPriceAggregatorUtils interface for documentation*

## getCollateralUsdPriceFeed

```solidity theme={null}
function getCollateralUsdPriceFeed(uint8 _collateralIndex) external view returns (contract IChainlinkFeed)
```

*Check IPriceAggregatorUtils interface for documentation*

## getPriceAggregatorOrder

```solidity theme={null}
function getPriceAggregatorOrder(bytes32 _requestId) external view returns (struct IPriceAggregator.Order)
```

*Check IPriceAggregatorUtils interface for documentation*

## getPriceAggregatorOrderAnswers

```solidity theme={null}
function getPriceAggregatorOrderAnswers(struct ITradingStorage.Id _orderId) external view returns (struct IPriceAggregator.OrderAnswer[])
```

*Check IPriceAggregatorUtils interface for documentation*

## getChainlinkToken

```solidity theme={null}
function getChainlinkToken() public view returns (address)
```

*Check IPriceAggregatorUtils interface for documentation*

## getRequestCount

```solidity theme={null}
function getRequestCount() external view returns (uint256)
```

*Check IPriceAggregatorUtils interface for documentation*

## getPendingRequest

```solidity theme={null}
function getPendingRequest(bytes32 _id) external view returns (address)
```

*Check IPriceAggregatorUtils interface for documentation*

## \_getSlot

```solidity theme={null}
function _getSlot() internal pure returns (uint256)
```

*Returns storage slot to use when fetching storage relevant to library*

## \_getStorage

```solidity theme={null}
function _getStorage() internal pure returns (struct IPriceAggregator.PriceAggregatorStorage s)
```

*Returns storage pointer for storage struct in diamond contract, at defined slot*

## \_getMultiCollatDiamond

```solidity theme={null}
function _getMultiCollatDiamond() internal view returns (contract IGNSMultiCollatDiamond)
```

*Returns current address as multi-collateral diamond interface to call other facets functions.*

## validCollateralIndex

```solidity theme={null}
modifier validCollateralIndex(uint8 _collateralIndex)
```

*Reverts if collateral index is not valid*

## \_median

```solidity theme={null}
function _median(struct IPriceAggregator.OrderAnswer[] _array) internal pure returns (uint64)
```

*returns median price of array (1 price only)*

### Parameters

| Name    | Type                                                                                                                       | Description     |
| ------- | -------------------------------------------------------------------------------------------------------------------------- | --------------- |
| \_array | [IPriceAggregator.OrderAnswer\[\]](/developer/technical-reference/contracts/interfaces/types/ipriceaggregator#orderanswer) | array of values |

## \_medianLookbacks

```solidity theme={null}
function _medianLookbacks(struct IPriceAggregator.OrderAnswer[] _array) internal pure returns (uint64 open, uint64 high, uint64 low)
```

*returns median prices of array (open, high, low)*

### Parameters

| Name    | Type                                                                                                                       | Description     |
| ------- | -------------------------------------------------------------------------------------------------------------------------- | --------------- |
| \_array | [IPriceAggregator.OrderAnswer\[\]](/developer/technical-reference/contracts/interfaces/types/ipriceaggregator#orderanswer) | array of values |

## \_swap

```solidity theme={null}
function _swap(uint256[] _array, uint256 _i, uint256 _j) internal pure
```

*swaps two elements in array*

### Parameters

| Name    | Type       | Description             |
| ------- | ---------- | ----------------------- |
| \_array | uint256\[] | array of values         |
| \_i     | uint256    | index of first element  |
| \_j     | uint256    | index of second element |

## \_sort

```solidity theme={null}
function _sort(uint256[] _array, uint256 begin, uint256 end) internal pure
```

*sorts array of uint256 values*

### Parameters

| Name    | Type       | Description     |
| ------- | ---------- | --------------- |
| \_array | uint256\[] | array of values |
| begin   | uint256    | start index     |
| end     | uint256    | end index       |

## \_getCollateralPrecisionDelta

```solidity theme={null}
function _getCollateralPrecisionDelta(uint8 _collateralIndex) internal view returns (uint256)
```

*Returns precision delta of collateral as uint256*

### Parameters

| Name              | Type  | Description         |
| ----------------- | ----- | ------------------- |
| \_collateralIndex | uint8 | index of collateral |
