ITradingCallbacksUtils

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

initializeCallbacks

function initializeCallbacks(uint8 _vaultClosingFeeP) external

Parameters

Name
Type
Description

_vaultClosingFeeP

uint8

the % of closing fee going to vault

initializeTreasuryAddress

function initializeTreasuryAddress(address _treasury) external

Initialize the treasury address

Parameters

Name
Type
Description

_treasury

address

the treasury address

updateVaultClosingFeeP

function updateVaultClosingFeeP(uint8 _valueP) external

Update the % of closing fee going to vault

Parameters

Name
Type
Description

_valueP

uint8

the % of closing fee going to vault

updateTreasuryAddress

function updateTreasuryAddress(address _treasury) external

Updates the treasury address

Parameters

Name
Type
Description

_treasury

address

the 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

Name
Type
Description

_a

the price aggregator answer (order id, price, etc.)

closeTradeMarketCallback

function closeTradeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external

Executes a pending close trade market order

Parameters

Name
Type
Description

_a

the 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

Name
Type
Description

_a

the 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

Name
Type
Description

_a

the price aggregator answer (order id, price, etc.)

updateLeverageCallback

function updateLeverageCallback(struct ITradingCallbacks.AggregatorAnswer _a) external

Executes a pending update leverage order

Parameters

Name
Type
Description

_a

the price aggregator answer (order id, price, etc.)

increasePositionSizeMarketCallback

function increasePositionSizeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external

Executes a pending increase position size market order

Parameters

Name
Type
Description

_a

the price aggregator answer (order id, price, etc.)

decreasePositionSizeMarketCallback

function decreasePositionSizeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external

Executes a pending decrease position size market order

Parameters

Name
Type
Description

_a

the 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

Name
Type
Description

_tradeId

the id of the trade

_orderType

enum ITradingStorage.PendingOrderType

the pending order type

_open

uint64

the open value from an aggregator answer

_high

uint64

the high value from an aggregator answer

_low

uint64

the 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

Name
Type
Description

_tradeId

the id of the trade

_orderType

enum ITradingStorage.PendingOrderType

the pending order type

_open

uint64

the open value from an aggregator answer

_high

uint64

the high value from an aggregator answer

_low

uint64

the low value from an aggregator answer

VaultClosingFeePUpdated

event VaultClosingFeePUpdated(uint8 valueP)

Emitted when vaultClosingFeeP is updated

Parameters

Name
Type
Description

valueP

uint8

the % of closing fee going to vault

PendingGovFeesClaimed

event PendingGovFeesClaimed(uint8 collateralIndex, uint256 amountCollateral)

Emitted when gov fees are claimed for a collateral

Parameters

Name
Type
Description

collateralIndex

uint8

the collateral index

amountCollateral

uint256

the 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

Name
Type
Description

orderId

struct ITradingStorage.Id

the id of the corresponding pending market order

user

address

trade user

index

uint32

trade index

t

struct ITradingStorage.Trade

the trade object

open

bool

true for a market open order, false for a market close order

oraclePrice

uint256

the oracle price without spread/impact (1e10 precision)

marketPrice

uint256

the price at which the trade was executed (1e10 precision)

liqPrice

uint256

trade liquidation price (1e10 precision)

priceImpactP

uint256

the price impact in percentage (1e10 precision)

percentProfit

int256

the profit in percentage (1e10 precision)

amountSentToTrader

uint256

the final amount of collateral sent to the trader

collateralPriceUsd

uint256

the 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

Name
Type
Description

orderId

struct ITradingStorage.Id

the id of the corresponding pending trigger order

user

address

trade user

index

uint32

trade index

limitIndex

uint32

limit index

t

struct ITradingStorage.Trade

the trade object

triggerCaller

address

the address that triggered the limit order

orderType

enum ITradingStorage.PendingOrderType

the type of the pending order

oraclePrice

uint256

the oracle price without spread/impact (1e10 precision)

marketPrice

uint256

the price at which the trade was executed (1e10 precision)

liqPrice

uint256

trade liquidation price (1e10 precision)

priceImpactP

uint256

the price impact in percentage (1e10 precision)

percentProfit

int256

the profit in percentage (1e10 precision)

amountSentToTrader

uint256

the final amount of collateral sent to the trader

collateralPriceUsd

uint256

the price of the collateral in USD (1e8 precision)

exactExecution

bool

true 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

Name
Type
Description

orderId

struct ITradingStorage.Id

order id of the pending market open order

trader

address

address of the trader

pairIndex

uint256

index of the trading pair

cancelReason

enum ITradingCallbacks.CancelReason

reason 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

Name
Type
Description

orderId

struct ITradingStorage.Id

order id of the pending market close order

trader

address

address of the trader

pairIndex

uint256

index of the trading pair

index

uint256

index of the trade for trader

cancelReason

enum ITradingCallbacks.CancelReason

reason 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

Name
Type
Description

orderId

struct ITradingStorage.Id

order id of the pending trigger order

triggerCaller

address

address of the trigger caller

orderType

enum ITradingStorage.PendingOrderType

type of the pending trigger order

cancelReason

enum ITradingCallbacks.CancelReason

reason for the cancellation

BorrowingFeeCharged

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

Parameters

Name
Type
Description

trader

address

address of the trader

index

uint32

index of the trade

collateralIndex

uint8

index of the collateral

amountCollateral

uint256

amount charged (collateral precision)

Last updated