Gains Network
  • 📚Home
  • Gains Network
    • 🔎Overview
    • 🍏GNS Token
    • 📔Contract Addresses
      • Apechain Mainnet
      • Arbitrum Mainnet
      • Base Mainnet
      • Polygon Mainnet
  • gTrade (Leveraged Trading)
    • 🔎Overview
    • 🎛️Setting up to trade
      • 🟣Polygon Network Setup
      • 🔵Arbitrum Network Setup
    • 🏦Opening / Closing trades
    • 💲Trade Collaterals
      • Spotlight: WETH
    • 📖Asset classes
      • 🪙Cryptocurrencies
      • 💵Forex
      • 🛢️Commodities
    • 🎫Fees & Spread
    • 📰Pair List
    • 🧒How to use Practice Mode
    • ⚡One-Click Trading (1CT)
    • 🌌gTrade Solana
    • 📺Video tutorials
  • Loyalty Programs
    • Prime Trader
    • gTrade Credits
  • Community
    • gTrade Guardians
    • Governance forum
  • Reward Pools
    • 💚GNS Staking
    • 👛gToken Vaults
      • 👷Staker Functions
      • ❔Staker FAQ
      • ⏳Upgrades, updates, and timelocks
    • 🔼Active Pools & Incentives
  • Help
    • ❓FAQ
    • ⏳Chain congestion
  • Bridges
    • 🪐Arbitrum <-> Polygon Bridge
    • 🪐ERC20 Bridge (Polygon)
    • 🪐NFT Bridge (Polygon)
  • Developer
    • Integrators
      • Trading Contracts
      • Backend
      • Price Feed
      • Guides
        • v9 migration
        • Calculating borrowing fees
        • Calculating liquidation price
    • Technical Reference
      • Contracts
        • Changelogs
          • v9.2.1 Update
          • v9.1 Update
          • v9.1.1 Update
          • v9 Update
        • Core
          • Abstract
            • GNSAddressStore
            • GNSDiamondCut
            • GNSDiamondLoupe
            • GNSDiamondStorage
          • Facets
            • GNSBorrowingFees
            • GNSOtc
            • GNSPriceAggregator
            • GNSTradingInteractions
            • GNSTriggerRewards
            • GNSFeeTiers
            • GNSPairsStorage
            • GNSPriceImpact
            • GNSReferrals
            • GNSTradingCallbacks
            • GNSTradingStorage
          • GNSMultiCollatDiamond
          • GNSStaking
          • GToken
          • GTokenOpenPnlFeed
        • Interfaces
          • Libraries
            • IBorrowingFeesUtils
            • IOtcUtils
            • IPriceAggregatorUtils
            • ITriggerRewardsUtils
            • IFeeTiersUtils
            • IPairsStorageUtils
            • IPriceImpactUtils
            • IReferralsUtils
            • ITradingCallbacksUtils
            • ITradingCommonUtils
            • ITradingInteractionsUtils
            • ITradingStorageUtils
            • IUpdateLeverageUtils
            • IUpdatePositionSizeUtils
          • Types
            • IAddressStore
            • IBorrowingFees
            • IDiamondStorage
            • IOtc
            • IPriceAggregator
            • ITradingStorage
            • ITradingInteractions
            • ITriggerRewards
            • ITypes
            • IUpdateLeverage
            • IPairsStorage
            • IFeeTiers
            • IPriceImpact
            • IReferrals
            • ITradingCallbacks
            • IUpdatePositionSize
          • IChainlinkFeed
          • IArbSys
          • IChainlinkOracle
          • IERC20
          • IERC721
          • IERC721Design
          • IGeneralErrors
          • IGNSAddressStore
          • IGNSDiamond
          • IGNSDiamondCut
          • IGNSMultiCollatDiamond
          • IGNSDiamondLoupe
          • IGNSStaking
          • IGToken
          • IGTokenLockedDepositNft
          • IGTokenOpenPnlFeed
          • IGTokenLockedDepositNftDesign
          • ILiquidityPool
          • IRateProvider
          • IOwnable
        • Libraries
          • updateLeverage
            • UpdateLeverageLifecycles
          • updatePositionSize
            • IncreasePositionSizeUtils
            • DecreasePositionSizeUtils
            • UpdatePositionSizeLifecycles
          • AddressStoreUtils
          • ChainlinkClientUtils
          • ChainUtils
          • ConstantsUtils
          • CollateralUtils
          • DiamondUtils
          • LiquidityPoolUtils
          • OtcUtils
          • PackingUtils
          • StorageUtils
          • TriggerRewardsUtils
          • ArrayGetters
          • BorrowingFeesUtils
          • FeeTiersUtils
          • PriceAggregatorUtils
          • PriceImpactUtils
          • ReferralsUtils
          • TradingCallbacksUtils
          • PairsStorageUtils
          • TradingCommonUtils
          • TradingStorageUtils
          • TradingInteractionsUtils
        • Misc
          • EpochBasedTokenClaim
          • GNSCompensationHandler
          • GTokenRateProvider
          • GTokenLockedDepositNftDesign
          • ManagerTimelock
          • OwnerTimelock
          • VotingDelegator
        • Tokens
          • GainsNetworkToken
          • GTokenLockedDepositNft
      • Backend
        • Backend Types
      • SDK
        • Client Types
  • Archived
    • 🖼️gFARM2 NFTs
Powered by GitBook
On this page
  • constructor
  • initializePriceImpact
  • Parameters
  • initializeNegPnlCumulVolMultiplier
  • Parameters
  • initializePairFactors
  • Parameters
  • setPriceImpactWindowsCount
  • Parameters
  • setPriceImpactWindowsDuration
  • Parameters
  • setNegPnlCumulVolMultiplier
  • Parameters
  • setProtectionCloseFactorWhitelist
  • Parameters
  • setPairDepths
  • Parameters
  • setProtectionCloseFactors
  • Parameters
  • setProtectionCloseFactorBlocks
  • Parameters
  • setCumulativeFactors
  • Parameters
  • setExemptOnOpen
  • Parameters
  • setExemptAfterProtectionCloseFactor
  • Parameters
  • addPriceImpactOpenInterest
  • Parameters
  • getPriceImpactOi
  • Parameters
  • getTradePriceImpact
  • Parameters
  • getPairDepth
  • Parameters
  • getOiWindowsSettings
  • getOiWindow
  • Parameters
  • getOiWindows
  • Parameters
  • getPairDepths
  • Parameters
  • getPairFactors
  • Parameters
  • getNegPnlCumulVolMultiplier
  • getProtectionCloseFactorWhitelist

Was this helpful?

  1. Developer
  2. Technical Reference
  3. Contracts
  4. Core
  5. Facets

GNSPriceImpact

Facet #4: Price impact OI windows

constructor

constructor() public

initializePriceImpact

function initializePriceImpact(uint48 _windowsDuration, uint48 _windowsCount) external

Initializes price impact facet

Parameters

Name
Type
Description

_windowsDuration

uint48

windows duration (seconds)

_windowsCount

uint48

windows count

initializeNegPnlCumulVolMultiplier

function initializeNegPnlCumulVolMultiplier(uint40 _negPnlCumulVolMultiplier) external

Initializes negative pnl cumulative volume multiplier

Parameters

Name
Type
Description

_negPnlCumulVolMultiplier

uint40

new value (1e10)

initializePairFactors

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

Initializes pair factors

Parameters

Name
Type
Description

_pairIndices

uint16[]

pair indices to initialize

_protectionCloseFactors

uint40[]

protection close factors (1e10)

_protectionCloseFactorBlocks

uint32[]

protection close factor blocks

_cumulativeFactors

uint40[]

cumulative factors (1e10)

setPriceImpactWindowsCount

function setPriceImpactWindowsCount(uint48 _newWindowsCount) external

Updates price impact windows count

Parameters

Name
Type
Description

_newWindowsCount

uint48

new windows count

setPriceImpactWindowsDuration

function setPriceImpactWindowsDuration(uint48 _newWindowsDuration) external

Updates price impact windows duration

Parameters

Name
Type
Description

_newWindowsDuration

uint48

new windows duration (seconds)

setNegPnlCumulVolMultiplier

function setNegPnlCumulVolMultiplier(uint40 _negPnlCumulVolMultiplier) external

Updates negative pnl cumulative volume multiplier

Parameters

Name
Type
Description

_negPnlCumulVolMultiplier

uint40

new value (1e10)

setProtectionCloseFactorWhitelist

function setProtectionCloseFactorWhitelist(address[] _traders, bool[] _whitelisted) external

Whitelists/unwhitelists traders from protection close factor

Parameters

Name
Type
Description

_traders

address[]

traders addresses

_whitelisted

bool[]

values

setPairDepths

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

Updates pairs 1% depths above and below

Parameters

Name
Type
Description

_indices

uint256[]

indices of pairs

_depthsAboveUsd

uint128[]

depths above the price in USD

_depthsBelowUsd

uint128[]

depths below the price in USD

setProtectionCloseFactors

function setProtectionCloseFactors(uint16[] _pairIndices, uint40[] _protectionCloseFactors) external

Sets protection close factors for pairs

Parameters

Name
Type
Description

_pairIndices

uint16[]

pair indices to update

_protectionCloseFactors

uint40[]

new protection close factors (1e10)

setProtectionCloseFactorBlocks

function setProtectionCloseFactorBlocks(uint16[] _pairIndices, uint32[] _protectionCloseFactorBlocks) external

Sets protection close factor blocks duration for pairs

Parameters

Name
Type
Description

_pairIndices

uint16[]

pair indices to update

_protectionCloseFactorBlocks

uint32[]

new protection close factor blocks

setCumulativeFactors

function setCumulativeFactors(uint16[] _pairIndices, uint40[] _cumulativeFactors) external

Sets cumulative factors for pairs

Parameters

Name
Type
Description

_pairIndices

uint16[]

pair indices to update

_cumulativeFactors

uint40[]

new cumulative factors (1e10)

setExemptOnOpen

function setExemptOnOpen(uint16[] _pairIndices, bool[] _exemptOnOpen) external

Sets whether pairs are exempt from price impact on open

Parameters

Name
Type
Description

_pairIndices

uint16[]

pair indices to update

_exemptOnOpen

bool[]

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

Name
Type
Description

_pairIndices

uint16[]

pair indices to update

_exemptAfterProtectionCloseFactor

bool[]

new values

addPriceImpactOpenInterest

function addPriceImpactOpenInterest(address _trader, uint32 _index, uint256 _oiDeltaCollateral, bool _open, bool _isPnlPositive) external virtual

Adds open interest to current window

Parameters

Name
Type
Description

_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

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

Name
Type
Description

_pairIndex

uint256

index of pair

_long

bool

true 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

Name
Type
Description

_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

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

Returns a pair's depths above and below the price

Parameters

Name
Type
Description

_pairIndex

uint256

index 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

Name
Type
Description

_windowsDuration

uint48

windows duration (seconds)

_pairIndex

uint256

index of pair

_windowId

uint256

id 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

Name
Type
Description

_windowsDuration

uint48

windows duration (seconds)

_pairIndex

uint256

index of pair

_windowIds

uint256[]

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

Name
Type
Description

_indices

uint256[]

indices of pairs

getPairFactors

function getPairFactors(uint256[] _indices) external view returns (struct IPriceImpact.PairFactors[])

Returns factors for a set of pairs (1e10)

Parameters

Name
Type
Description

_indices

uint256[]

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

PreviousGNSPairsStorageNextGNSReferrals

Was this helpful?