GNSPriceImpact

Facet #4: Price impact OI windows

Methods

addPriceImpactOpenInterest

function addPriceImpactOpenInterest(uint256 _openInterestUsd, uint256 _pairIndex, bool _long) external nonpayable

Adds open interest to a window

Parameters

NameTypeDescription

_openInterestUsd

uint256

open interest of trade in USD (1e18 precision)

_pairIndex

uint256

index of pair

_long

bool

true for long, false for short

getOiWindow

function getOiWindow(uint48 _windowsDuration, uint256 _pairIndex, uint256 _windowId) external view returns (struct IPriceImpact.PairOi)

Returns OI window details (long/short OI)

Parameters

NameTypeDescription

_windowsDuration

uint48

windows duration (seconds)

_pairIndex

uint256

index of pair

_windowId

uint256

id of window

Returns

NameTypeDescription

_0

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

_windowsDuration

uint48

windows duration (seconds)

_pairIndex

uint256

index of pair

_windowIds

uint256[]

ids of windows

Returns

NameTypeDescription

_0

getOiWindowsSettings

function getOiWindowsSettings() external view returns (struct IPriceImpact.OiWindowsSettings)

Returns current price impact windows settings

Returns

NameTypeDescription

_0

getPairDepth

function getPairDepth(uint256 _pairIndex) external view returns (struct IPriceImpact.PairDepth)

Returns a pair's depths above and below the price

Parameters

NameTypeDescription

_pairIndex

uint256

index of pair

Returns

NameTypeDescription

_0

getPairDepths

function getPairDepths(uint256[] _indices) external view returns (struct IPriceImpact.PairDepth[])

Returns depths above and below the price for multiple pairs

Parameters

NameTypeDescription

_indices

uint256[]

indices of pairs

Returns

NameTypeDescription

_0

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

_pairIndex

uint256

index of pair

_long

bool

true for long, false for short

Returns

NameTypeDescription

activeOi

uint256

getTradePriceImpact

function getTradePriceImpact(uint256 _openPrice, uint256 _pairIndex, bool _long, uint256 _tradeOpenInterestUsd) external view returns (uint256 priceImpactP, uint256 priceAfterImpact)

Returns price impact % (1e10 precision) and price after impact (1e10 precision) for a trade

Parameters

NameTypeDescription

_openPrice

uint256

open 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)

Returns

NameTypeDescription

priceImpactP

uint256

priceAfterImpact

uint256

initializePriceImpact

function initializePriceImpact(uint48 _windowsDuration, uint48 _windowsCount) external nonpayable

Initializes price impact facet

Parameters

NameTypeDescription

_windowsDuration

uint48

windows duration (seconds)

_windowsCount

uint48

windows count

removePriceImpactOpenInterest

function removePriceImpactOpenInterest(uint256 _openInterestUsd, uint256 _pairIndex, bool _long, uint48 _addTs) external nonpayable

Removes open interest from a window

Parameters

NameTypeDescription

_openInterestUsd

uint256

open interest of trade in USD (1e18 precision)

_pairIndex

uint256

index of pair

_long

bool

true for long, false for short

_addTs

uint48

timestamp of when the trade open interest was added (to remove from same window)

setPairDepths

function setPairDepths(uint256[] _indices, uint128[] _depthsAboveUsd, uint128[] _depthsBelowUsd) external nonpayable

Updates pairs 1% depths above and below

Parameters

NameTypeDescription

_indices

uint256[]

indices of pairs

_depthsAboveUsd

uint128[]

depths above the price in USD

_depthsBelowUsd

uint128[]

depths below the price in USD

setPriceImpactWindowsCount

function setPriceImpactWindowsCount(uint48 _newWindowsCount) external nonpayable

Updates price impact windows count

Parameters

NameTypeDescription

_newWindowsCount

uint48

new windows count

setPriceImpactWindowsDuration

function setPriceImpactWindowsDuration(uint48 _newWindowsDuration) external nonpayable

Updates price impact windows duration

Parameters

NameTypeDescription

_newWindowsDuration

uint48

new windows duration (seconds)

Events

OiWindowsSettingsInitialized

event OiWindowsSettingsInitialized(uint48 indexed windowsDuration, uint48 indexed windowsCount)

Triggered when OiWindowsSettings is initialized (once)

Parameters

NameTypeDescription

windowsDuration indexed

uint48

duration of each window (seconds)

windowsCount indexed

uint48

number of windows

OnePercentDepthUpdated

event OnePercentDepthUpdated(uint256 indexed pairIndex, uint128 valueAboveUsd, uint128 valueBelowUsd)

Triggered when a pair's depth is updated.

Parameters

NameTypeDescription

pairIndex indexed

uint256

index of the pair

valueAboveUsd

uint128

new USD depth above the price

valueBelowUsd

uint128

new USD depth below the price

PriceImpactOiTransferredPair

event PriceImpactOiTransferredPair(uint256 indexed pairIndex, IPriceImpact.PairOi totalPairOi)

Triggered when a pair's OI is transferred to a new window.

Parameters

NameTypeDescription

pairIndex indexed

uint256

index of the pair

totalPairOi

total USD long/short OI of the pair (1e18 precision)

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

pairsCount

uint256

number of pairs

prevCurrentWindowId

uint256

previous current window ID corresponding to previous window duration

prevEarliestWindowId

uint256

previous earliest window ID corresponding to previous window duration

newCurrentWindowId

uint256

new current window ID corresponding to new window duration

PriceImpactOpenInterestAdded

event PriceImpactOpenInterestAdded(IPriceImpact.OiWindowUpdate oiWindowUpdate)

Triggered when OI is added to a window.

Parameters

NameTypeDescription

oiWindowUpdate

OI window update details (windowsDuration, pairIndex, windowId, etc.)

PriceImpactOpenInterestRemoved

event PriceImpactOpenInterestRemoved(IPriceImpact.OiWindowUpdate oiWindowUpdate, bool notOutdated)

Triggered when OI is (tentatively) removed from a window.

Parameters

NameTypeDescription

oiWindowUpdate

OI window update details (windowsDuration, pairIndex, windowId, etc.)

notOutdated

bool

true if the OI is not outdated

PriceImpactWindowsCountUpdated

event PriceImpactWindowsCountUpdated(uint48 indexed windowsCount)

Triggered when OiWindowsSettings.windowsCount is updated

Parameters

NameTypeDescription

windowsCount indexed

uint48

new number of windows

PriceImpactWindowsDurationUpdated

event PriceImpactWindowsDurationUpdated(uint48 indexed windowsDuration)

Triggered when OiWindowsSettings.windowsDuration is updated

Parameters

NameTypeDescription

windowsDuration indexed

uint48

new duration of each window (seconds)

Errors

AboveMax

error AboveMax()

AlreadyExists

error AlreadyExists()

BelowMin

error BelowMin()

BlockOrder

error BlockOrder()

DoesntExist

error DoesntExist()

InitError

error InitError()

InvalidAddresses

error InvalidAddresses()

InvalidCollateralIndex

error InvalidCollateralIndex()

InvalidInputLength

error InvalidInputLength()

NotAllowed

error NotAllowed()

NotAuthorized

error NotAuthorized()

Overflow

error Overflow()

Paused

error Paused()

WrongAccess

error WrongAccess()

WrongIndex

error WrongIndex()

WrongLength

error WrongLength()

WrongOrder

error WrongOrder()

WrongParams

error WrongParams()

WrongTradeType

error WrongTradeType()

WrongWindowsCount

error WrongWindowsCount()

WrongWindowsDuration

error WrongWindowsDuration()

ZeroAddress

error ZeroAddress()

ZeroValue

error ZeroValue()

Last updated