PriceImpactUtils
_GNSPriceImpact facet internal library
This is a library to help manage a price impact decay algorithm .
When a trade is placed, OI is added to the window corresponding to time of open. When a trade is removed, OI is removed from the window corresponding to time of open.
When calculating price impact, only the most recent X windows are taken into account._
validWindowsDuration
Validates new windowsDuration value
initializePriceImpact
Check IPriceImpactUtils interface for documentation
initializeNegPnlCumulVolMultiplier
Check IPriceImpactUtils interface for documentation
initializePairFactors
Check IPriceImpactUtils interface for documentation
setPriceImpactWindowsCount
Check IPriceImpactUtils interface for documentation
setPriceImpactWindowsDuration
Check IPriceImpactUtils interface for documentation
setNegPnlCumulVolMultiplier
Check IPriceImpactUtils interface for documentation
setProtectionCloseFactorWhitelist
Check IPriceImpactUtils interface for documentation
setPairDepths
Check IPriceImpactUtils interface for documentation
setProtectionCloseFactors
Check IPriceImpactUtils interface for documentation
setProtectionCloseFactorBlocks
Check IPriceImpactUtils interface for documentation
setCumulativeFactors
Check IPriceImpactUtils interface for documentation
setExemptOnOpen
Check IPriceImpactUtils interface for documentation
setExemptAfterProtectionCloseFactor
Check IPriceImpactUtils interface for documentation
addPriceImpactOpenInterest
Check IPriceImpactUtils interface for documentation
getPriceImpactOi
Check IPriceImpactUtils interface for documentation
getTradePriceImpact
Check IPriceImpactUtils interface for documentation
getPairDepth
Check IPriceImpactUtils interface for documentation
getOiWindowsSettings
Check IPriceImpactUtils interface for documentation
getOiWindow
Check IPriceImpactUtils interface for documentation
getOiWindows
Check IPriceImpactUtils interface for documentation
getPairDepths
Check IPriceImpactUtils interface for documentation
getPairFactors
Check IPriceImpactUtils interface for documentation
getNegPnlCumulVolMultiplier
Check IPriceImpactUtils interface for documentation
getProtectionCloseFactorWhitelist
Check IPriceImpactUtils interface for documentation
_getSlot
Returns storage slot to use when fetching storage relevant to library
_getStorage
Returns storage pointer for storage struct in diamond contract, at defined slot
_getMultiCollatDiamond
Returns current address as multi-collateral diamond interface to call other facets functions.
_transferPriceImpactOiForPairs
_Transfers total long / short OI from last '_settings.windowsCount' windows of _prevPairOiWindows
to current window of _newPairOiWindows
for _pairsCount
pairs.
Emits a {PriceImpactOiTransferredPairs} event._
Parameters
_pairsCount
uint256
number of pairs
_prevPairOiWindows
mapping(uint256 => mapping(uint256 => struct IPriceImpact.PairOi))
previous pair OI windows (previous windowsDuration mapping)
_newPairOiWindows
mapping(uint256 => mapping(uint256 => struct IPriceImpact.PairOi))
new pair OI windows (new windowsDuration mapping)
_settings
current OI windows settings
_newWindowsDuration
uint48
new windows duration
_transferPriceImpactOiForPair
_Transfers total long / short OI from prevEarliestWindowId
to prevCurrentWindowId
windows of _prevPairOiWindows
to _newPairOiWindow
window.
Emits a {PriceImpactOiTransferredPair} event._
Parameters
_pairIndex
uint256
index of the pair
_prevCurrentWindowId
uint256
previous current window ID
_prevEarliestWindowId
uint256
previous earliest active window ID
_prevPairOiWindows
mapping(uint256 => struct IPriceImpact.PairOi)
previous pair OI windows (previous windowsDuration mapping)
_newPairOiWindow
new pair OI window (new windowsDuration mapping)
_getWindowId
Returns window id at _timestamp
given _settings
.
Parameters
_timestamp
uint48
timestamp
_settings
OI windows settings
_getCurrentWindowId
Returns window id at current timestamp given _settings
.
Parameters
_settings
OI windows settings
_getEarliestActiveWindowId
Returns earliest active window id given _currentWindowId
and _windowsCount
.
Parameters
_currentWindowId
uint256
current window id
_windowsCount
uint48
active windows count
_isWindowPotentiallyActive
_Returns whether 'windowId' can be potentially active id given _currentWindowId
Parameters
_windowId
uint256
window id
_currentWindowId
uint256
current window id
_getTradePriceImpact
Returns trade price impact % and opening price after impact.
Parameters
_marketPrice
uint256
market price (1e10 precision)
_long
bool
true for long, false for short
_startOpenInterestUsd
uint256
existing open interest of pair on trade side in USD (1e18 precision)
_tradeOpenInterestUsd
uint256
open interest of trade in USD (1e18 precision)
_onePercentDepthUsd
uint256
one percent depth of pair in USD on trade side
_open
bool
true for open, false for close
_protectionCloseFactor
uint256
protection close factor (1e10 precision)
_cumulativeFactor
uint256
cumulative factor (1e10 precision)
_contractsVersion
enum ITradingStorage.ContractsVersion
trade contracts version
Last updated