# JavPriceImpact

## General Description

The **JavPriceImpact** contract used for manage various settings related to price impact, such as open interest windows, depth factors, protection close factors, and cumulative factors. The contract is divided into management setters for configuring the system, interaction functions for updating open interest dynamically, and getters for retrieving various price impact-related data.

## Core Functionalities

### **`initializePriceImpact`**

* Initializes price impact settings, including the duration and count of open interest windows.
* **Parameters**:
  * `_windowsDuration`: Duration of each open interest window in seconds.
  * `_windowsCount`: Number of open interest windows.
* **Access Control**: `reinitializer(3)`.

### **`setPriceImpactWindowsCount`**

* Updates the number of open interest windows.
* **Parameters**:
  * `_newWindowsCount`: New count of open interest windows.
* **Access Control**: `onlyRole(Role.GOV)`.

### **`setPriceImpactWindowsDuration`**

* Updates the duration of open interest windows.
* **Parameters**:
  * `_newWindowsDuration`: New duration of open interest windows in seconds.
* **Access Control**: `onlyRole(Role.GOV)`.

### **`setPairDepths`**

* Sets the depth parameters for trading pairs.
* **Parameters**:
  * `_indices`: Array of trading pair indices.
  * `_depthsAboveUsd`: Array of depth values above the current USD price.
  * `_depthsBelowUsd`: Array of depth values below the current USD price.
* **Access Control**: `onlyRole(Role.MANAGER)`.

### **`setProtectionCloseFactors`**

* Configures protection close factors for trading pairs.
* **Parameters**:
  * `_pairIndices`: Array of trading pair indices.
  * `_protectionCloseFactors`: Array of close factor values for protection.
* **Access Control**: `onlyRole(Role.GOV)`.

### **`setProtectionCloseFactorBlocks`**

* Sets the block duration for protection close factors.
* **Parameters**:
  * `_pairIndices`: Array of trading pair indices.
  * `_protectionCloseFactorBlocks`: Array of block duration values.
* **Access Control**: `onlyRole(Role.GOV)`.

### **`setCumulativeFactors`**

* Configures cumulative factors for trading pairs.
* **Parameters**:
  * `_pairIndices`: Array of trading pair indices.
  * `_cumulativeFactors`: Array of cumulative factor values.
* **Access Control**: `onlyRole(Role.GOV)`.

### **`addPriceImpactOpenInterest`**

* Updates the open interest impact for a trader based on their activity.
* **Parameters**:
  * `_trader`: Address of the trader.
  * `_index`: Trading pair index.
  * `_oiDeltaCollateral`: Change in open interest collateral.
  * `_open`: Indicates if the position is being opened or closed.
* **Access Control**: `onlySelf`.

### **`getPriceImpactOi`**

* Retrieves the open interest price impact for a given pair.
* **Parameters**:
  * `_pairIndex`: Index of the trading pair.
  * `_long`: Indicates if the position is long.
* **Returns**: The active open interest.

### **`getTradePriceImpact`**

* Calculates the price impact for a trade.
* **Parameters**:
  * `_marketPrice`: Current market price.
  * `_pairIndex`: Trading pair index.
  * `_long`: Indicates if the position is long.
  * `_tradeOpenInterestUsd`: Open interest in USD.
  * `_isPnlPositive`: Indicates if profit and loss is positive.
  * `_open`: Indicates if the trade is opening or closing.
  * `_lastPosIncreaseBlock`: Block number of the last position increase.
* **Returns**:
  * `priceImpactP`: Price impact percentage.
  * `priceAfterImpact`: Price after applying impact.

### **`getPairDepth`**

* Retrieves the depth details for a trading pair.
* **Parameters**:
  * `_pairIndex`: Index of the trading pair.
* **Returns**: `PairDepth` structure containing depth details.

### **`getPairFactor`**

* Retrieves factors affecting a trading pair.
* **Parameters**:
  * `_pairIndex`: Index of the trading pair.
* **Returns**: `PairFactors` structure containing factor details.

### **`getOiWindowsSettings`**

* Retrieves settings related to open interest windows.
* **Returns**: `OiWindowsSettings` structure.

### **`getOiWindow`**

* Retrieves a specific open interest window's data.
* **Parameters**:
  * `_windowsDuration`: Duration of the window.
  * `_pairIndex`: Trading pair index.
  * `_windowId`: ID of the window.
* **Returns**: `PairOi` structure for the specified window.

### **`getOiWindows`**

* Retrieves data for multiple open interest windows.
* **Parameters**:
  * `_windowsDuration`: Duration of the windows.
  * `_pairIndex`: Trading pair index.
  * `_windowIds`: Array of window IDs.
* **Returns**: Array of `PairOi` structures.

### **`getPairDepths`**

* Retrieves depth details for multiple trading pairs.
* **Parameters**:
  * `_indices`: Array of trading pair indices.
* **Returns**: Array of `PairDepth` structures.

### **`getPairFactors`**

* Retrieves factors for multiple trading pairs.
* **Parameters**:
  * `_indices`: Array of trading pair indices.
* **Returns**: Array of `PairFactors` structures.


---

# Agent Instructions: 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:

```
GET https://docs.javsphere.com/engineering/smart-contracts/leveragex/javpriceimpact.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
