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
  • tradingActivated
  • tradingActivatedOrCloseOnly
  • notDelegatedAction
  • initializeTrading
  • updateMarketOrdersTimeoutBlocks
  • updateByPassTriggerLink
  • setTradingDelegate
  • removeTradingDelegate
  • delegatedTradingAction
  • openTrade
  • openTradeNative
  • updateMaxClosingSlippageP
  • closeTradeMarket
  • updateOpenOrder
  • cancelOpenOrder
  • updateTp
  • updateSl
  • updateLeverage
  • increasePositionSize
  • decreasePositionSize
  • triggerOrder
  • cancelOrderAfterTimeout
  • getWrappedNativeToken
  • isWrappedNativeToken
  • getTradingDelegate
  • getMarketOrdersTimeoutBlocks
  • getByPassTriggerLink
  • _getSlot
  • _getStorage
  • _getMultiCollatDiamond
  • _openTrade
  • Parameters
  • _checkNoPendingTrigger
  • Parameters
  • _getPriceTriggerOrder
  • Parameters
  • _wrapNativeToken
  • Parameters
  • _msgSender

Was this helpful?

  1. Developer
  2. Technical Reference
  3. Contracts
  4. Libraries

TradingInteractionsUtils

GNSTradingInteractions facet internal library

tradingActivated

modifier tradingActivated()

Modifier to only allow trading action when trading is activated (= revert if not activated)

tradingActivatedOrCloseOnly

modifier tradingActivatedOrCloseOnly()

Modifier to only allow trading action when trading is activated or close only (= revert if paused)

notDelegatedAction

modifier notDelegatedAction()

Modifier to prevent calling function from delegated action

initializeTrading

function initializeTrading(uint16 _marketOrdersTimeoutBlocks, address[] _usersByPassTriggerLink) internal

Check ITradingInteractionsUtils interface for documentation

updateMarketOrdersTimeoutBlocks

function updateMarketOrdersTimeoutBlocks(uint16 _valueBlocks) internal

Check ITradingInteractionsUtils interface for documentation

updateByPassTriggerLink

function updateByPassTriggerLink(address[] _users, bool[] _shouldByPass) internal

Check ITradingInteractionsUtils interface for documentation

setTradingDelegate

function setTradingDelegate(address _delegate) internal

Check ITradingInteractionsUtils interface for documentation

removeTradingDelegate

function removeTradingDelegate() internal

Check ITradingInteractionsUtils interface for documentation

delegatedTradingAction

function delegatedTradingAction(address _trader, bytes _callData) internal returns (bytes)

Check ITradingInteractionsUtils interface for documentation

openTrade

function openTrade(struct ITradingStorage.Trade _trade, uint16 _maxSlippageP, address _referrer) internal

Check ITradingInteractionsUtils interface for documentation

openTradeNative

function openTradeNative(struct ITradingStorage.Trade _trade, uint16 _maxSlippageP, address _referrer) internal

Check ITradingInteractionsUtils interface for documentation

updateMaxClosingSlippageP

function updateMaxClosingSlippageP(uint32 _index, uint16 _maxClosingSlippageP) internal

Check ITradingInteractionsUtils interface for documentation

closeTradeMarket

function closeTradeMarket(uint32 _index, uint64 _expectedPrice) internal

Check ITradingInteractionsUtils interface for documentation

updateOpenOrder

function updateOpenOrder(uint32 _index, uint64 _openPrice, uint64 _tp, uint64 _sl, uint16 _maxSlippageP) internal

Check ITradingInteractionsUtils interface for documentation

cancelOpenOrder

function cancelOpenOrder(uint32 _index) internal

Check ITradingInteractionsUtils interface for documentation

updateTp

function updateTp(uint32 _index, uint64 _newTp) internal

Check ITradingInteractionsUtils interface for documentation

updateSl

function updateSl(uint32 _index, uint64 _newSl) internal

Check ITradingInteractionsUtils interface for documentation

updateLeverage

function updateLeverage(uint32 _index, uint24 _newLeverage) internal

Check ITradingInteractionsUtils interface for documentation

increasePositionSize

function increasePositionSize(uint32 _index, uint120 _collateralDelta, uint24 _leverageDelta, uint64 _expectedPrice, uint16 _maxSlippageP) internal

Check ITradingInteractionsUtils interface for documentation

decreasePositionSize

function decreasePositionSize(uint32 _index, uint120 _collateralDelta, uint24 _leverageDelta, uint64 _expectedPrice) internal

Check ITradingInteractionsUtils interface for documentation

triggerOrder

function triggerOrder(uint256 _packed) internal

Check ITradingInteractionsUtils interface for documentation

cancelOrderAfterTimeout

function cancelOrderAfterTimeout(uint32 _orderIndex) internal

Check ITradingInteractionsUtils interface for documentation

getWrappedNativeToken

function getWrappedNativeToken() internal view returns (address)

Check ITradingInteractionsUtils interface for documentation

isWrappedNativeToken

function isWrappedNativeToken(address _token) internal view returns (bool)

Check ITradingInteractionsUtils interface for documentation

getTradingDelegate

function getTradingDelegate(address _trader) internal view returns (address)

Check ITradingInteractionsUtils interface for documentation

getMarketOrdersTimeoutBlocks

function getMarketOrdersTimeoutBlocks() internal view returns (uint16)

Check ITradingInteractionsUtils interface for documentation

getByPassTriggerLink

function getByPassTriggerLink(address _user) internal view returns (bool)

Check ITradingInteractionsUtils interface for documentation

_getSlot

function _getSlot() internal pure returns (uint256)

Returns storage slot to use when fetching storage relevant to library

_getStorage

function _getStorage() internal pure returns (struct ITradingInteractions.TradingInteractionsStorage s)

Returns storage pointer for storage struct in diamond contract, at defined slot

_getMultiCollatDiamond

function _getMultiCollatDiamond() internal view returns (contract IGNSMultiCollatDiamond)

Returns current address as multi-collateral diamond interface to call other facets functions.

_openTrade

function _openTrade(struct ITradingStorage.Trade _trade, uint16 _maxSlippageP, address _referrer, bool _isNative) internal

Internal function for openTrade and openTradeNative

Parameters

Name
Type
Description

_trade

trade data

_maxSlippageP

uint16

max slippage percentage (1e3 precision)

_referrer

address

referrer address

_isNative

bool

if true we skip the collateral transfer from user to contract

_checkNoPendingTrigger

function _checkNoPendingTrigger(struct ITradingStorage.Id _tradeId, enum ITradingStorage.PendingOrderType _orderType) internal view

Revert if there is an active pending order for the trade

Parameters

Name
Type
Description

_tradeId

trade id

_orderType

enum ITradingStorage.PendingOrderType

order type

_getPriceTriggerOrder

function _getPriceTriggerOrder(struct ITradingStorage.Trade _trade, struct ITradingStorage.Id _orderId, enum ITradingStorage.PendingOrderType _orderType, uint256 _positionSizeCollateral) internal

Initiate price aggregator request for trigger order

Parameters

Name
Type
Description

_trade

trade

_orderId

order id

_orderType

enum ITradingStorage.PendingOrderType

order type

_positionSizeCollateral

uint256

position size in collateral tokens (collateral precision)

_wrapNativeToken

function _wrapNativeToken(uint8 _collateralIndex) internal returns (uint120)

Receives native token and sends back wrapped token to user

Parameters

Name
Type
Description

_collateralIndex

uint8

index of the collateral

_msgSender

function _msgSender() internal view returns (address)

Returns the caller of the transaction (overriden by trader address if delegatedAction is called)

PreviousTradingStorageUtilsNextMisc

Last updated 7 months ago

Was this helpful?

ITradingStorage.Trade
ITradingStorage.Id
ITradingStorage.Trade
ITradingStorage.Id