GNSPriceImpact
Facet #4: Price impact OI windows
constructor
initializePriceImpact
Initializes price impact facet
Parameters
_windowsDuration
uint48
windows duration (seconds)
_windowsCount
uint48
windows count
initializeNegPnlCumulVolMultiplier
Initializes negative pnl cumulative volume multiplier
Parameters
_negPnlCumulVolMultiplier
uint40
new value (1e10)
initializePairFactors
Initializes pair factors
Parameters
_pairIndices
uint16[]
pair indices to initialize
_protectionCloseFactors
uint40[]
protection close factors (1e10)
_protectionCloseFactorBlocks
uint32[]
protection close factor blocks
_cumulativeFactors
uint40[]
cumulative factors (1e10)
setPriceImpactWindowsCount
Updates price impact windows count
Parameters
_newWindowsCount
uint48
new windows count
setPriceImpactWindowsDuration
Updates price impact windows duration
Parameters
_newWindowsDuration
uint48
new windows duration (seconds)
setNegPnlCumulVolMultiplier
Updates negative pnl cumulative volume multiplier
Parameters
_negPnlCumulVolMultiplier
uint40
new value (1e10)
setProtectionCloseFactorWhitelist
Whitelists/unwhitelists traders from protection close factor
Parameters
_traders
address[]
traders addresses
_whitelisted
bool[]
values
setPairDepths
Updates pairs 1% depths above and below
Parameters
_indices
uint256[]
indices of pairs
_depthsAboveUsd
uint128[]
depths above the price in USD
_depthsBelowUsd
uint128[]
depths below the price in USD
setProtectionCloseFactors
Sets protection close factors for pairs
Parameters
_pairIndices
uint16[]
pair indices to update
_protectionCloseFactors
uint40[]
new protection close factors (1e10)
setProtectionCloseFactorBlocks
Sets protection close factor blocks duration for pairs
Parameters
_pairIndices
uint16[]
pair indices to update
_protectionCloseFactorBlocks
uint32[]
new protection close factor blocks
setCumulativeFactors
Sets cumulative factors for pairs
Parameters
_pairIndices
uint16[]
pair indices to update
_cumulativeFactors
uint40[]
new cumulative factors (1e10)
setExemptOnOpen
Sets whether pairs are exempt from price impact on open
Parameters
_pairIndices
uint16[]
pair indices to update
_exemptOnOpen
bool[]
new values
setExemptAfterProtectionCloseFactor
Sets whether pairs are exempt from price impact on close once protection close factor has expired
Parameters
_pairIndices
uint16[]
pair indices to update
_exemptAfterProtectionCloseFactor
bool[]
new values
addPriceImpactOpenInterest
Adds open interest to current window
Parameters
_trader
address
trader address
_index
uint32
trade index
_oiDeltaCollateral
uint256
open interest to add (collateral precision)
_open
bool
whether it corresponds to opening or closing a trade
_isPnlPositive
bool
whether it corresponds to a positive pnl trade (only relevant when _open = false)
getPriceImpactOi
Returns active open interest used in price impact calculation for a pair and side (long/short)
Parameters
_pairIndex
uint256
index of pair
_long
bool
true for long, false for short
getTradePriceImpact
Returns price impact % (1e10 precision) and price after impact (1e10 precision) for a trade
Parameters
_trader
address
trader address (to check if whitelisted from protection close factor)
_marketPrice
uint256
market price (1e10 precision)
_pairIndex
uint256
index of pair
_long
bool
true for long, false for short
_tradeOpenInterestUsd
uint256
open interest of trade in USD (1e18 precision)
_isPnlPositive
bool
true if positive pnl, false if negative pnl (only relevant when _open = false)
_open
bool
true on open, false on close
_lastPosIncreaseBlock
uint256
block when trade position size was last increased (only relevant when _open = false)
_contractsVersion
enum ITradingStorage.ContractsVersion
trade contracts version
getPairDepth
Returns a pair's depths above and below the price
Parameters
_pairIndex
uint256
index of pair
getOiWindowsSettings
Returns current price impact windows settings
getOiWindow
Returns OI window details (long/short OI)
Parameters
_windowsDuration
uint48
windows duration (seconds)
_pairIndex
uint256
index of pair
_windowId
uint256
id of window
getOiWindows
Returns multiple OI windows details (long/short OI)
Parameters
_windowsDuration
uint48
windows duration (seconds)
_pairIndex
uint256
index of pair
_windowIds
uint256[]
ids of windows
getPairDepths
Returns depths above and below the price for multiple pairs
Parameters
_indices
uint256[]
indices of pairs
getPairFactors
Returns factors for a set of pairs (1e10)
Parameters
_indices
uint256[]
indices of pairs
getNegPnlCumulVolMultiplier
Returns negative pnl cumulative volume multiplier
getProtectionCloseFactorWhitelist
Returns whether a trader is whitelisted from protection close factor