Skip to main content
Interface for GNSPriceImpact facet (inherits types and also contains functions, events, and custom errors)

initializePriceImpact

function initializePriceImpact(uint48 _windowsDuration, uint48 _windowsCount) external
Initializes price impact facet

Parameters

NameTypeDescription
_windowsDurationuint48windows duration (seconds)
_windowsCountuint48windows count

initializeNegPnlCumulVolMultiplier

function initializeNegPnlCumulVolMultiplier(uint40 _negPnlCumulVolMultiplier) external
Initializes negative pnl cumulative volume multiplier

Parameters

NameTypeDescription
_negPnlCumulVolMultiplieruint40new value (1e10)

initializePairFactors

function initializePairFactors(uint16[] _pairIndices, uint40[] _protectionCloseFactors, uint32[] _protectionCloseFactorBlocks, uint40[] _cumulativeFactors) external
Initializes pair factors

Parameters

NameTypeDescription
_pairIndicesuint16[]pair indices to initialize
_protectionCloseFactorsuint40[]protection close factors (1e10)
_protectionCloseFactorBlocksuint32[]protection close factor blocks
_cumulativeFactorsuint40[]cumulative factors (1e10)

setPriceImpactWindowsCount

function setPriceImpactWindowsCount(uint48 _newWindowsCount) external
Updates price impact windows count

Parameters

NameTypeDescription
_newWindowsCountuint48new windows count

setPriceImpactWindowsDuration

function setPriceImpactWindowsDuration(uint48 _newWindowsDuration) external
Updates price impact windows duration

Parameters

NameTypeDescription
_newWindowsDurationuint48new windows duration (seconds)

setNegPnlCumulVolMultiplier

function setNegPnlCumulVolMultiplier(uint40 _negPnlCumulVolMultiplier) external
Updates negative pnl cumulative volume multiplier

Parameters

NameTypeDescription
_negPnlCumulVolMultiplieruint40new value (1e10)

setProtectionCloseFactorWhitelist

function setProtectionCloseFactorWhitelist(address[] _traders, bool[] _whitelisted) external
Whitelists/unwhitelists traders from protection close factor

Parameters

NameTypeDescription
_tradersaddress[]traders addresses
_whitelistedbool[]values

setPairDepths

function setPairDepths(uint256[] _indices, uint128[] _depthsAboveUsd, uint128[] _depthsBelowUsd) external
Updates pairs 1% depths above and below

Parameters

NameTypeDescription
_indicesuint256[]indices of pairs
_depthsAboveUsduint128[]depths above the price in USD
_depthsBelowUsduint128[]depths below the price in USD

setProtectionCloseFactors

function setProtectionCloseFactors(uint16[] _pairIndices, uint40[] _protectionCloseFactors) external
Sets protection close factors for pairs

Parameters

NameTypeDescription
_pairIndicesuint16[]pair indices to update
_protectionCloseFactorsuint40[]new protection close factors (1e10)

setProtectionCloseFactorBlocks

function setProtectionCloseFactorBlocks(uint16[] _pairIndices, uint32[] _protectionCloseFactorBlocks) external
Sets protection close factor blocks duration for pairs

Parameters

NameTypeDescription
_pairIndicesuint16[]pair indices to update
_protectionCloseFactorBlocksuint32[]new protection close factor blocks

setCumulativeFactors

function setCumulativeFactors(uint16[] _pairIndices, uint40[] _cumulativeFactors) external
Sets cumulative factors for pairs

Parameters

NameTypeDescription
_pairIndicesuint16[]pair indices to update
_cumulativeFactorsuint40[]new cumulative factors (1e10)

setExemptOnOpen

function setExemptOnOpen(uint16[] _pairIndices, bool[] _exemptOnOpen) external
Sets whether pairs are exempt from price impact on open

Parameters

NameTypeDescription
_pairIndicesuint16[]pair indices to update
_exemptOnOpenbool[]new values

setExemptAfterProtectionCloseFactor

function setExemptAfterProtectionCloseFactor(uint16[] _pairIndices, bool[] _exemptAfterProtectionCloseFactor) external
Sets whether pairs are exempt from price impact on close once protection close factor has expired

Parameters

NameTypeDescription
_pairIndicesuint16[]pair indices to update
_exemptAfterProtectionCloseFactorbool[]new values

addPriceImpactOpenInterest

function addPriceImpactOpenInterest(address _trader, uint32 _index, uint256 _oiDeltaCollateral, bool _open, bool _isPnlPositive) external
Adds open interest to current window

Parameters

NameTypeDescription
_traderaddresstrader address
_indexuint32trade index
_oiDeltaCollateraluint256open interest to add (collateral precision)
_openboolwhether it corresponds to opening or closing a trade
_isPnlPositiveboolwhether it corresponds to a positive pnl trade (only relevant when _open = false)

getPriceImpactOi

function getPriceImpactOi(uint256 _pairIndex, bool _long) external view returns (uint256 activeOi)
Returns active open interest used in price impact calculation for a pair and side (long/short)

Parameters

NameTypeDescription
_pairIndexuint256index of pair
_longbooltrue for long, false for short

getTradePriceImpact

function getTradePriceImpact(address _trader, uint256 _marketPrice, uint256 _pairIndex, bool _long, uint256 _tradeOpenInterestUsd, bool _isPnlPositive, bool _open, uint256 _lastPosIncreaseBlock, enum ITradingStorage.ContractsVersion _contractsVersion) external view returns (uint256 priceImpactP, uint256 priceAfterImpact)
Returns price impact % (1e10 precision) and price after impact (1e10 precision) for a trade

Parameters

NameTypeDescription
_traderaddresstrader address (to check if whitelisted from protection close factor)
_marketPriceuint256market price (1e10 precision)
_pairIndexuint256index of pair
_longbooltrue for long, false for short
_tradeOpenInterestUsduint256open interest of trade in USD (1e18 precision)
_isPnlPositivebooltrue if positive pnl, false if negative pnl (only relevant when _open = false)
_openbooltrue on open, false on close
_lastPosIncreaseBlockuint256block when trade position size was last increased (only relevant when _open = false)
_contractsVersionenum ITradingStorage.ContractsVersiontrade contracts version

getPairDepth

function getPairDepth(uint256 _pairIndex) external view returns (struct IPriceImpact.PairDepth)
Returns a pair’s depths above and below the price

Parameters

NameTypeDescription
_pairIndexuint256index of pair

getOiWindowsSettings

function getOiWindowsSettings() external view returns (struct IPriceImpact.OiWindowsSettings)
Returns current price impact windows settings

getOiWindow

function getOiWindow(uint48 _windowsDuration, uint256 _pairIndex, uint256 _windowId) external view returns (struct IPriceImpact.PairOi)
Returns OI window details (long/short OI)

Parameters

NameTypeDescription
_windowsDurationuint48windows duration (seconds)
_pairIndexuint256index of pair
_windowIduint256id of window

getOiWindows

function getOiWindows(uint48 _windowsDuration, uint256 _pairIndex, uint256[] _windowIds) external view returns (struct IPriceImpact.PairOi[])
Returns multiple OI windows details (long/short OI)

Parameters

NameTypeDescription
_windowsDurationuint48windows duration (seconds)
_pairIndexuint256index of pair
_windowIdsuint256[]ids of windows

getPairDepths

function getPairDepths(uint256[] _indices) external view returns (struct IPriceImpact.PairDepth[])
Returns depths above and below the price for multiple pairs

Parameters

NameTypeDescription
_indicesuint256[]indices of pairs

getPairFactors

function getPairFactors(uint256[] _indices) external view returns (struct IPriceImpact.PairFactors[])
Returns factors for a set of pairs (1e10)

Parameters

NameTypeDescription
_indicesuint256[]indices of pairs

getNegPnlCumulVolMultiplier

function getNegPnlCumulVolMultiplier() external view returns (uint48)
Returns negative pnl cumulative volume multiplier

getProtectionCloseFactorWhitelist

function getProtectionCloseFactorWhitelist(address _trader) external view returns (bool)
Returns whether a trader is whitelisted from protection close factor

OiWindowsSettingsInitialized

event OiWindowsSettingsInitialized(uint48 windowsDuration, uint48 windowsCount)
Triggered when OiWindowsSettings is initialized (once)

Parameters

NameTypeDescription
windowsDurationuint48duration of each window (seconds)
windowsCountuint48number of windows

PriceImpactWindowsCountUpdated

event PriceImpactWindowsCountUpdated(uint48 windowsCount)
Triggered when OiWindowsSettings.windowsCount is updated

Parameters

NameTypeDescription
windowsCountuint48new number of windows

PriceImpactWindowsDurationUpdated

event PriceImpactWindowsDurationUpdated(uint48 windowsDuration)
Triggered when OiWindowsSettings.windowsDuration is updated

Parameters

NameTypeDescription
windowsDurationuint48new duration of each window (seconds)

NegPnlCumulVolMultiplierUpdated

event NegPnlCumulVolMultiplierUpdated(uint40 negPnlCumulVolMultiplier)
Triggered when negPnlCumulVolMultiplier is updated

Parameters

NameTypeDescription
negPnlCumulVolMultiplieruint40new value (1e10)

ProtectionCloseFactorWhitelistUpdated

event ProtectionCloseFactorWhitelistUpdated(address trader, bool whitelisted)
Triggered when a trader is whitelisted/unwhitelisted from protection close factor

Parameters

NameTypeDescription
traderaddresstrader address
whitelistedbooltrue if whitelisted, false if unwhitelisted

ProtectionCloseFactorUpdated

event ProtectionCloseFactorUpdated(uint256 pairIndex, uint40 protectionCloseFactor)
Triggered when a pair’s protection close factor is updated

Parameters

NameTypeDescription
pairIndexuint256index of the pair
protectionCloseFactoruint40new protection close factor (1e10)

ProtectionCloseFactorBlocksUpdated

event ProtectionCloseFactorBlocksUpdated(uint256 pairIndex, uint32 protectionCloseFactorBlocks)
Triggered when a pair’s protection close factor duration is updated

Parameters

NameTypeDescription
pairIndexuint256index of the pair
protectionCloseFactorBlocksuint32new protection close factor blocks

CumulativeFactorUpdated

event CumulativeFactorUpdated(uint256 pairIndex, uint40 cumulativeFactor)
Triggered when a pair’s cumulative factor is updated

Parameters

NameTypeDescription
pairIndexuint256index of the pair
cumulativeFactoruint40new cumulative factor (1e10)

ExemptOnOpenUpdated

event ExemptOnOpenUpdated(uint256 pairIndex, bool exemptOnOpen)
Triggered when a pair’s exemptOnOpen value is updated

Parameters

NameTypeDescription
pairIndexuint256index of the pair
exemptOnOpenboolwhether the pair is exempt of price impact on open

ExemptAfterProtectionCloseFactorUpdated

event ExemptAfterProtectionCloseFactorUpdated(uint256 pairIndex, bool exemptAfterProtectionCloseFactor)
Triggered when a pair’s exemptAfterProtectionCloseFactor value is updated

Parameters

NameTypeDescription
pairIndexuint256index of the pair
exemptAfterProtectionCloseFactorboolwhether the pair is exempt of price impact on close once protection close factor has expired

PriceImpactOpenInterestAdded

event PriceImpactOpenInterestAdded(struct IPriceImpact.OiWindowUpdate oiWindowUpdate)
Triggered when OI is added to a window.

Parameters

NameTypeDescription
oiWindowUpdatestruct IPriceImpact.OiWindowUpdateOI window update details (windowsDuration, pairIndex, windowId, etc.)

PriceImpactOiTransferredPairs

event PriceImpactOiTransferredPairs(uint256 pairsCount, uint256 prevCurrentWindowId, uint256 prevEarliestWindowId, uint256 newCurrentWindowId)
Triggered when multiple pairs’ OI are transferred to a new window (when updating windows duration).

Parameters

NameTypeDescription
pairsCountuint256number of pairs
prevCurrentWindowIduint256previous current window ID corresponding to previous window duration
prevEarliestWindowIduint256previous earliest window ID corresponding to previous window duration
newCurrentWindowIduint256new current window ID corresponding to new window duration

PriceImpactOiTransferredPair

event PriceImpactOiTransferredPair(uint256 pairIndex, struct IPriceImpact.PairOi totalPairOi)
Triggered when a pair’s OI is transferred to a new window.

Parameters

NameTypeDescription
pairIndexuint256index of the pair
totalPairOistruct IPriceImpact.PairOitotal USD long/short OI of the pair (1e18 precision)

OnePercentDepthUpdated

event OnePercentDepthUpdated(uint256 pairIndex, uint128 valueAboveUsd, uint128 valueBelowUsd)
Triggered when a pair’s depth is updated.

Parameters

NameTypeDescription
pairIndexuint256index of the pair
valueAboveUsduint128new USD depth above the price
valueBelowUsduint128new USD depth below the price

WrongWindowsDuration

error WrongWindowsDuration()

WrongWindowsCount

error WrongWindowsCount()