GNSTradingCallbacks

Facet #8: Callbacks (to execute actions after receiving median price from price aggregator)

Methods

claimPendingGovFees

function claimPendingGovFees() external nonpayable

Claim the pending gov fees for all collaterals

closeTradeMarketCallback

function closeTradeMarketCallback(ITradingCallbacks.AggregatorAnswer _a) external nonpayable

Parameters

decreasePositionSizeMarketCallback

function decreasePositionSizeMarketCallback(AggregatorAnswer memory _a) external;

Parameters

executeTriggerCloseOrderCallback

function executeTriggerCloseOrderCallback(ITradingCallbacks.AggregatorAnswer _a) external nonpayable

Parameters

executeTriggerOpenOrderCallback

function executeTriggerOpenOrderCallback(ITradingCallbacks.AggregatorAnswer _a) external nonpayable

Parameters

getPendingGovFeesCollateral

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

Returns the current pending gov fees for a collateral index (collateral precision)

Parameters

NameTypeDescription

_collateralIndex

uint8

Returns

NameTypeDescription

_0

uint256

getVaultClosingFeeP

function getVaultClosingFeeP() external view returns (uint8)

Returns the current vaultClosingFeeP value (%)

Returns

NameTypeDescription

_0

uint8

increasePositionSizeMarketCallback

function increasePositionSizeMarketCallback(AggregatorAnswer memory _a) external;

Parameters

initializeCallbacks

function initializeCallbacks(uint8 _vaultClosingFeeP) external nonpayable

Parameters

NameTypeDescription

_vaultClosingFeeP

uint8

the % of closing fee going to vault

openTradeMarketCallback

function openTradeMarketCallback(ITradingCallbacks.AggregatorAnswer _a) external nonpayable

Parameters

updateLeverageCallback

function updateLeverageCallback(AggregatorAnswer memory _a) external;

Parameters

updateVaultClosingFeeP

function updateVaultClosingFeeP(uint8 _valueP) external nonpayable

Update the % of closing fee going to vault

Parameters

NameTypeDescription

_valueP

uint8

the % of closing fee going to vault

Events

BorrowingFeeCharged

event BorrowingFeeCharged(address indexed trader, uint8 indexed collateralIndex, uint256 amountCollateral)

Parameters

NameTypeDescription

trader indexed

address

address of the trader

collateralIndex indexed

uint8

index of the collateral

amountCollateral

uint256

amount charged (collateral precision)

GTokenFeeCharged

event GTokenFeeCharged(address indexed trader, uint8 indexed collateralIndex, uint256 amountCollateral)

Parameters

NameTypeDescription

trader indexed

address

address of the trader

collateralIndex indexed

uint8

index of the collateral

amountCollateral

uint256

amount charged (collateral precision)

GnsStakingFeeCharged

event GnsStakingFeeCharged(address indexed trader, uint8 indexed collateralIndex, uint256 amountCollateral)

Parameters

NameTypeDescription

trader indexed

address

address of the trader

collateralIndex indexed

uint8

index of the collateral

amountCollateral

uint256

amount charged (collateral precision)

GovFeeCharged

event GovFeeCharged(address indexed trader, uint8 indexed collateralIndex, uint256 amountCollateral)

Parameters

NameTypeDescription

trader indexed

address

address of the trader

collateralIndex indexed

uint8

index of the collateral

amountCollateral

uint256

amount charged (collateral precision)

LeverageUpdateExecuted

event LeverageUpdateExecuted(ITradingStorage.Id orderId, bool isIncrease, ITradingCallbacks.CancelReason cancelReason, uint8 indexed collateralIndex, address indexed trader, uint256 indexed pairIndex, uint256 index, uint256 marketPrice, uint256 collateralDelta, IUpdateLeverage.UpdateLeverageValues values);

Emitted when a leverage update is executed

Parameters

NameTypeDescription

orderId

true if leverage increased, false if decreased

isIncrease

bool

cancel reason (executed if none)

cancelReason

cancel reason if canceled or none if executed

collateralIndex

uint8

collateral index

trader

address

address of trader

pairIndex

uint256

index of pair

index

uint256

index of trade

marketPrice

uint256

current market price (1e10)

collateralDelta

uint256

collateral delta (collateral precision)

values

values useful values (new collateral, new leverage, liq price, gov fee collateral)

LimitExecuted

event LimitExecuted(ITradingStorage.Id orderId, ITradingStorage.Trade t, address indexed triggerCaller, enum ITradingStorage.PendingOrderType orderType, uint256 price, uint256 priceImpactP, int256 percentProfit, uint256 amountSentToTrader, uint256 collateralPriceUsd, bool exactExecution)

Emitted when a limit/stop order is executed

Parameters

NameTypeDescription

orderId

the id of the corresponding pending trigger order

t

the trade object

triggerCaller indexed

address

the address that triggered the limit order

orderType

the type of the pending order

price

uint256

the price at which the trade was executed (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

MarketCloseCanceled

event MarketCloseCanceled(ITradingStorage.Id orderId, address indexed trader, uint256 indexed pairIndex, uint256 index, enum ITradingCallbacks.CancelReason cancelReason)

Emitted when a pending market close order is canceled

Parameters

NameTypeDescription

orderId

order id of the pending market close order

trader indexed

address

address of the trader

pairIndex indexed

uint256

index of the trading pair

index

uint256

index of the trade for trader

cancelReason

reason for the cancelation

MarketExecuted

event MarketExecuted(ITradingStorage.Id orderId, ITradingStorage.Trade t, bool open, uint64 price, uint256 priceImpactP, int256 percentProfit, uint256 amountSentToTrader, uint256 collateralPriceUsd)

Emitted when a market order is executed (open/close)

Parameters

NameTypeDescription

orderId

the id of the corrsponding pending market order

t

the trade object

open

bool

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

price

uint64

the price at which the trade was executed (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)

MarketOpenCanceled

event MarketOpenCanceled(ITradingStorage.Id orderId, address indexed trader, uint256 indexed pairIndex, enum ITradingCallbacks.CancelReason cancelReason)

Emitted when a pending market open order is canceled

Parameters

NameTypeDescription

orderId

order id of the pending market open order

trader indexed

address

address of the trader

pairIndex indexed

uint256

index of the trading pair

cancelReason

reason for the cancelation

PendingGovFeesClaimed

event PendingGovFeesClaimed(uint8 collateralIndex, uint256 amountCollateral)

Emitted when gov fees are claimed for a collateral

Parameters

NameTypeDescription

collateralIndex

uint8

the collateral index

amountCollateral

uint256

the amount of fees claimed (collateral precision)

PositionSizeDecreaseExecuted

event PositionSizeDecreaseExecuted(ITradingStorage.Id orderId, ITradingCallbacks.CancelReason cancelReason, uint8 indexed collateralIndex, address indexed trader, uint256 indexed pairIndex, uint256 index, uint256 marketPrice, uint256 collateralDelta, uint256 leverageDelta, IUpdatePositionSize.DecreasePositionSizeValues values);

Emitted when position size decrease is executed

Parameters

NameTypeDescription

orderId

true if leverage increased, false if decreased

cancelReason

cancel reason if canceled or none if executed

collateralIndex

uint8

collateral index

trader

address

address of trader

pairIndex

uint256

index of pair

index

uint256

index of trade

marketPrice

uint256

current market price (1e10)

collateralDelta

uint256

collateral delta (collateral precision)

leverageDelta

uint256

leverage delta (1e3)

values

values important values (pnl, new leverage, new collateral, etc.)

PositionSizeIncreaseExecuted

event PositionSizeIncreaseExecuted(ITradingStorage.Id orderId, ITradingCallbacks.CancelReason cancelReason, uint8 indexed collateralIndex, address indexed trader, uint256 indexed pairIndex, uint256 index, uint256 marketPrice, uint256 collateralDelta, uint256 leverageDelta, IUpdatePositionSize.DecreasePositionSizeValues values);

Emitted when position size increase is executed

Parameters

NameTypeDescription

orderId

true if leverage increased, false if decreased

cancelReason

cancel reason if canceled or none if executed

collateralIndex

uint8

collateral index

trader

address

address of trader

pairIndex

uint256

index of pair

index

uint256

index of trade

marketPrice

uint256

current market price (1e10)

collateralDelta

uint256

collateral delta (collateral precision)

leverageDelta

uint256

leverage delta (1e3)

values

important values (new open price, new leverage, new collateral, etc.)

ReferralFeeCharged

event ReferralFeeCharged(address indexed trader, uint8 indexed collateralIndex, uint256 amountCollateral)

Parameters

NameTypeDescription

trader indexed

address

address of the trader

collateralIndex indexed

uint8

index of the collateral

amountCollateral

uint256

amount charged (collateral precision)

TriggerFeeCharged

event TriggerFeeCharged(address indexed trader, uint8 indexed collateralIndex, uint256 amountCollateral)

Parameters

NameTypeDescription

trader indexed

address

address of the trader

collateralIndex indexed

uint8

index of the collateral

amountCollateral

uint256

amount charged (collateral precision)

TriggerOrderCanceled

event TriggerOrderCanceled(ITradingStorage.Id orderId, address indexed triggerCaller, enum ITradingStorage.PendingOrderType orderType, enum ITradingCallbacks.CancelReason cancelReason)

Emitted when a pending trigger order is canceled

Parameters

NameTypeDescription

orderId

order id of the pending trigger order

triggerCaller indexed

address

address of the trigger caller

orderType

type of the pending trigger order

cancelReason

reason for the cancelation

VaultClosingFeePUpdated

event VaultClosingFeePUpdated(uint8 valueP)

Emitted when vaultClosingFeeP is updated

Parameters

NameTypeDescription

valueP

uint8

the % of closing fee going to vault

Errors

AboveMax

error AboveMax()

AlreadyExists

error AlreadyExists()

BelowMin

error BelowMin()

BlockOrder

error BlockOrder()

DoesntExist

error DoesntExist()

InitError

error InitError()

InvalidAddresses

error InvalidAddresses()

InvalidCollateralIndex

error InvalidCollateralIndex()

InvalidInputLength

error InvalidInputLength()

NotAllowed

error NotAllowed()

NotAuthorized

error NotAuthorized()

Overflow

error Overflow()

Paused

error Paused()

WrongAccess

error WrongAccess()

WrongIndex

error WrongIndex()

WrongLength

error WrongLength()

WrongOrder

error WrongOrder()

WrongParams

error WrongParams()

WrongTradeType

error WrongTradeType()

ZeroAddress

error ZeroAddress()

ZeroValue

error ZeroValue()

Last updated