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

initializeCallbacks

function initializeCallbacks(uint8 _vaultClosingFeeP) external

Parameters

NameTypeDescription
_vaultClosingFeePuint8the % of closing fee going to vault

initializeTreasuryAddress

function initializeTreasuryAddress(address _treasury) external
Initialize the treasury address

Parameters

NameTypeDescription
_treasuryaddressthe treasury address

updateVaultClosingFeeP

function updateVaultClosingFeeP(uint8 _valueP) external
Update the % of closing fee going to vault

Parameters

NameTypeDescription
_valuePuint8the % of closing fee going to vault

updateTreasuryAddress

function updateTreasuryAddress(address _treasury) external
Updates the treasury address

Parameters

NameTypeDescription
_treasuryaddressthe new treasury address

claimPendingGovFees

function claimPendingGovFees() external
Claim the pending gov fees for all collaterals

openTradeMarketCallback

function openTradeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external
Executes a pending open trade market order

Parameters

NameTypeDescription
_aITradingCallbacks.AggregatorAnswerthe price aggregator answer (order id, price, etc.)

closeTradeMarketCallback

function closeTradeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external
Executes a pending close trade market order

Parameters

NameTypeDescription
_aITradingCallbacks.AggregatorAnswerthe price aggregator answer (order id, price, etc.)

executeTriggerOpenOrderCallback

function executeTriggerOpenOrderCallback(struct ITradingCallbacks.AggregatorAnswer _a) external
Executes a pending open trigger order (for limit/stop orders)

Parameters

NameTypeDescription
_aITradingCallbacks.AggregatorAnswerthe price aggregator answer (order id, price, etc.)

executeTriggerCloseOrderCallback

function executeTriggerCloseOrderCallback(struct ITradingCallbacks.AggregatorAnswer _a) external
Executes a pending close trigger order (for tp/sl/liq orders)

Parameters

NameTypeDescription
_aITradingCallbacks.AggregatorAnswerthe price aggregator answer (order id, price, etc.)

updateLeverageCallback

function updateLeverageCallback(struct ITradingCallbacks.AggregatorAnswer _a) external
Executes a pending update leverage order

Parameters

NameTypeDescription
_aITradingCallbacks.AggregatorAnswerthe price aggregator answer (order id, price, etc.)

increasePositionSizeMarketCallback

function increasePositionSizeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external
Executes a pending increase position size market order

Parameters

NameTypeDescription
_aITradingCallbacks.AggregatorAnswerthe price aggregator answer (order id, price, etc.)

decreasePositionSizeMarketCallback

function decreasePositionSizeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external
Executes a pending decrease position size market order

Parameters

NameTypeDescription
_aITradingCallbacks.AggregatorAnswerthe price aggregator answer (order id, price, etc.)

getVaultClosingFeeP

function getVaultClosingFeeP() external view returns (uint8)
Returns the current vaultClosingFeeP value (%)

getPendingGovFeesCollateral

function getPendingGovFeesCollateral(uint8 _collateralIndex) external view returns (uint256)
Returns the current pending gov fees for a collateral index (collateral precision)

validateTriggerOpenOrderCallback

function validateTriggerOpenOrderCallback(struct ITradingStorage.Id _tradeId, enum ITradingStorage.PendingOrderType _orderType, uint64 _open, uint64 _high, uint64 _low) external view returns (struct ITradingStorage.Trade t, enum ITradingCallbacks.CancelReason cancelReason, struct ITradingCallbacks.Values v)
Makes open trigger (STOP/LIMIT) checks like slippage, price impact, missed targets and returns cancellation reason if any

Parameters

NameTypeDescription
_tradeIdITradingStorage.Idthe id of the trade
_orderTypeenum ITradingStorage.PendingOrderTypethe pending order type
_openuint64the open value from an aggregator answer
_highuint64the high value from an aggregator answer
_lowuint64the low value from an aggregator answer

validateTriggerCloseOrderCallback

function validateTriggerCloseOrderCallback(struct ITradingStorage.Id _tradeId, enum ITradingStorage.PendingOrderType _orderType, uint64 _open, uint64 _high, uint64 _low) external view returns (struct ITradingStorage.Trade t, enum ITradingCallbacks.CancelReason cancelReason, struct ITradingCallbacks.Values v)
Makes close trigger (SL/TP/LIQ) checks like slippage and price impact and returns cancellation reason if any

Parameters

NameTypeDescription
_tradeIdITradingStorage.Idthe id of the trade
_orderTypeenum ITradingStorage.PendingOrderTypethe pending order type
_openuint64the open value from an aggregator answer
_highuint64the high value from an aggregator answer
_lowuint64the low value from an aggregator answer

VaultClosingFeePUpdated

event VaultClosingFeePUpdated(uint8 valueP)
Emitted when vaultClosingFeeP is updated

Parameters

NameTypeDescription
valuePuint8the % of closing fee going to vault

PendingGovFeesClaimed

event PendingGovFeesClaimed(uint8 collateralIndex, uint256 amountCollateral)
Emitted when gov fees are claimed for a collateral

Parameters

NameTypeDescription
collateralIndexuint8the collateral index
amountCollateraluint256the amount of fees claimed (collateral precision)

MarketExecuted

event MarketExecuted(struct ITradingStorage.Id orderId, address user, uint32 index, struct ITradingStorage.Trade t, bool open, uint256 oraclePrice, uint256 marketPrice, uint256 liqPrice, uint256 priceImpactP, int256 percentProfit, uint256 amountSentToTrader, uint256 collateralPriceUsd)
Emitted when a market order is executed (open/close)

Parameters

NameTypeDescription
orderIdstruct ITradingStorage.Idthe id of the corresponding pending market order
useraddresstrade user
indexuint32trade index
tstruct ITradingStorage.Tradethe trade object
openbooltrue for a market open order, false for a market close order
oraclePriceuint256the oracle price without spread/impact (1e10 precision)
marketPriceuint256the price at which the trade was executed (1e10 precision)
liqPriceuint256trade liquidation price (1e10 precision)
priceImpactPuint256the price impact in percentage (1e10 precision)
percentProfitint256the profit in percentage (1e10 precision)
amountSentToTraderuint256the final amount of collateral sent to the trader
collateralPriceUsduint256the price of the collateral in USD (1e8 precision)

LimitExecuted

event LimitExecuted(struct ITradingStorage.Id orderId, address user, uint32 index, uint32 limitIndex, struct ITradingStorage.Trade t, address triggerCaller, enum ITradingStorage.PendingOrderType orderType, uint256 oraclePrice, uint256 marketPrice, uint256 liqPrice, uint256 priceImpactP, int256 percentProfit, uint256 amountSentToTrader, uint256 collateralPriceUsd, bool exactExecution)
Emitted when a limit/stop order is executed

Parameters

NameTypeDescription
orderIdstruct ITradingStorage.Idthe id of the corresponding pending trigger order
useraddresstrade user
indexuint32trade index
limitIndexuint32limit index
tstruct ITradingStorage.Tradethe trade object
triggerCalleraddressthe address that triggered the limit order
orderTypeenum ITradingStorage.PendingOrderTypethe type of the pending order
oraclePriceuint256the oracle price without spread/impact (1e10 precision)
marketPriceuint256the price at which the trade was executed (1e10 precision)
liqPriceuint256trade liquidation price (1e10 precision)
priceImpactPuint256the price impact in percentage (1e10 precision)
percentProfitint256the profit in percentage (1e10 precision)
amountSentToTraderuint256the final amount of collateral sent to the trader
collateralPriceUsduint256the price of the collateral in USD (1e8 precision)
exactExecutionbooltrue if guaranteed execution was used

MarketOpenCanceled

event MarketOpenCanceled(struct ITradingStorage.Id orderId, address trader, uint256 pairIndex, enum ITradingCallbacks.CancelReason cancelReason)
Emitted when a pending market open order is canceled

Parameters

NameTypeDescription
orderIdstruct ITradingStorage.Idorder id of the pending market open order
traderaddressaddress of the trader
pairIndexuint256index of the trading pair
cancelReasonenum ITradingCallbacks.CancelReasonreason for the cancellation

MarketCloseCanceled

event MarketCloseCanceled(struct ITradingStorage.Id orderId, address trader, uint256 pairIndex, uint256 index, enum ITradingCallbacks.CancelReason cancelReason)
Emitted when a pending market close order is canceled

Parameters

NameTypeDescription
orderIdstruct ITradingStorage.Idorder id of the pending market close order
traderaddressaddress of the trader
pairIndexuint256index of the trading pair
indexuint256index of the trade for trader
cancelReasonenum ITradingCallbacks.CancelReasonreason for the cancellation

TriggerOrderCanceled

event TriggerOrderCanceled(struct ITradingStorage.Id orderId, address triggerCaller, enum ITradingStorage.PendingOrderType orderType, enum ITradingCallbacks.CancelReason cancelReason)
Emitted when a pending trigger order is canceled

Parameters

NameTypeDescription
orderIdstruct ITradingStorage.Idorder id of the pending trigger order
triggerCalleraddressaddress of the trigger caller
orderTypeenum ITradingStorage.PendingOrderTypetype of the pending trigger order
cancelReasonenum ITradingCallbacks.CancelReasonreason for the cancellation

BorrowingFeeCharged

event BorrowingFeeCharged(address trader, uint32 index, uint8 collateralIndex, uint256 amountCollateral)

Parameters

NameTypeDescription
traderaddressaddress of the trader
indexuint32index of the trade
collateralIndexuint8index of the collateral
amountCollateraluint256amount charged (collateral precision)