TradingCallbacksUtils

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

initializeCallbacks

function initializeCallbacks(uint8 _vaultClosingFeeP) internal

Check ITradingCallbacksUtils interface for documentation

updateVaultClosingFeeP

function updateVaultClosingFeeP(uint8 _valueP) internal

Check ITradingCallbacksUtils interface for documentation

updateTreasuryAddress

function updateTreasuryAddress(address _treasury) internal

Check ITradingCallbacksUtils interface for documentation

claimPendingGovFees

function claimPendingGovFees() internal

Check ITradingCallbacksUtils interface for documentation

openTradeMarketCallback

function openTradeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) internal

Check ITradingCallbacksUtils interface for documentation

closeTradeMarketCallback

function closeTradeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) internal

Check ITradingCallbacksUtils interface for documentation

executeTriggerOpenOrderCallback

function executeTriggerOpenOrderCallback(struct ITradingCallbacks.AggregatorAnswer _a) internal

Check ITradingCallbacksUtils interface for documentation

executeTriggerCloseOrderCallback

function executeTriggerCloseOrderCallback(struct ITradingCallbacks.AggregatorAnswer _a) internal

Check ITradingCallbacksUtils interface for documentation

updateLeverageCallback

function updateLeverageCallback(struct ITradingCallbacks.AggregatorAnswer _a) internal

Check ITradingCallbacksUtils interface for documentation

increasePositionSizeMarketCallback

function increasePositionSizeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) internal

Check ITradingCallbacksUtils interface for documentation

decreasePositionSizeMarketCallback

function decreasePositionSizeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) internal

Check ITradingCallbacksUtils interface for documentation

getVaultClosingFeeP

function getVaultClosingFeeP() internal view returns (uint8)

Check ITradingCallbacksUtils interface for documentation

getPendingGovFeesCollateral

function getPendingGovFeesCollateral(uint8 _collateralIndex) internal view returns (uint256)

Check ITradingCallbacksUtils interface for documentation

validateTriggerOpenOrderCallback

function validateTriggerOpenOrderCallback(struct ITradingStorage.Id _tradeId, enum ITradingStorage.PendingOrderType _orderType, uint64 _open, uint64 _high, uint64 _low) internal view returns (struct ITradingStorage.Trade t, enum ITradingCallbacks.CancelReason cancelReason, struct ITradingCallbacks.Values v)

Check ITradingCallbacksUtils interface for documentation

validateTriggerCloseOrderCallback

function validateTriggerCloseOrderCallback(struct ITradingStorage.Id _tradeId, enum ITradingStorage.PendingOrderType _orderType, uint64 _open, uint64 _high, uint64 _low) internal view returns (struct ITradingStorage.Trade t, enum ITradingCallbacks.CancelReason cancelReason, struct ITradingCallbacks.Values v)

Check ITradingCallbacksUtils 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 ITradingCallbacks.TradingCallbacksStorage 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.

_registerTrade

function _registerTrade(struct ITradingStorage.Trade _trade, struct ITradingStorage.PendingOrder _pendingOrder) internal returns (struct ITradingStorage.Trade)

Registers a trade in storage, and handles all fees and rewards

Parameters

NameTypeDescription

_trade

Trade to register

_pendingOrder

Corresponding pending order

Return Values

NameTypeDescription

[0]

Final registered trade

_unregisterTrade

function _unregisterTrade(struct ITradingStorage.Trade _trade, int256 _profitP, enum ITradingStorage.PendingOrderType _orderType, uint256 _oraclePrice, uint256 _liqPrice) internal returns (uint256 tradeValueCollateral)

Unregisters a trade from storage, and handles all fees and rewards

Parameters

NameTypeDescription

_trade

Trade to unregister

_profitP

int256

Profit percentage (1e10)

_orderType

enum ITradingStorage.PendingOrderType

pending order type

_oraclePrice

uint256

oracle price without closing spread/impact (1e10)

_liqPrice

uint256

trade liquidation price (1e10)

Return Values

NameTypeDescription

tradeValueCollateral

uint256

Amount of collateral sent to trader, collateral + pnl (collateral precision)

_openTradePrep

function _openTradePrep(struct ITradingStorage.Trade _trade, uint256 _executionPrice, uint256 _oraclePrice, uint256 _spreadP, uint256 _maxSlippageP) internal view returns (uint256 priceImpactP, uint256 priceAfterImpact, enum ITradingCallbacks.CancelReason cancelReason)

Makes pre-trade checks: price impact, if trade should be cancelled based on parameters like: PnL, leverage, slippage, etc.

Parameters

NameTypeDescription

_trade

trade input

_executionPrice

uint256

execution price (1e10 precision)

_oraclePrice

uint256

oracle price (1e10 precision)

_spreadP

uint256

spread % (1e10 precision)

_maxSlippageP

uint256

max slippage % (1e3 precision)

_getPendingOrder

function _getPendingOrder(struct ITradingStorage.Id _orderId) internal view returns (struct ITradingStorage.PendingOrder)

Returns pending order from storage

Parameters

NameTypeDescription

_orderId

Order ID

Return Values

NameTypeDescription

[0]

Pending order

_getCollateralPriceUsd

function _getCollateralPriceUsd(uint8 _collateralIndex) internal view returns (uint256)

Returns collateral price in USD

Parameters

NameTypeDescription

_collateralIndex

uint8

Collateral index

Return Values

NameTypeDescription

[0]

uint256

Collateral price in USD

_getTrade

function _getTrade(address _trader, uint32 _index) internal view returns (struct ITradingStorage.Trade)

Returns trade from storage

Parameters

NameTypeDescription

_trader

address

Trader address

_index

uint32

Trade index

Return Values

NameTypeDescription

[0]

Trade

_getTradeInfo

function _getTradeInfo(address _trader, uint32 _index) internal view returns (struct ITradingStorage.TradeInfo)

Returns trade info from storage

Parameters

NameTypeDescription

_trader

address

Trader address

_index

uint32

Trade index

Return Values

NameTypeDescription

[0]

TradeInfo

Last updated