GNSTradingStorage

Facet #5: Trading storage

Methods

addCollateral

function addCollateral(address _collateral, address _gToken) external nonpayable

Adds a new supported collateral

Parameters

NameTypeDescription

_collateral

address

the address of the collateral

_gToken

address

the gToken contract of the collateral

closePendingOrder

function closePendingOrder(ITradingStorage.Id _orderId) external nonpayable

Parameters

NameTypeDescription

_orderId

closeTrade

function closeTrade(ITradingStorage.Id _tradeId) external nonpayable

Parameters

NameTypeDescription

_tradeId

getAllPendingOrders

function getAllPendingOrders(uint256 _offset, uint256 _limit) external view returns (struct ITradingStorage.PendingOrder[])

Returns all pending orders using a pagination system

Parameters

NameTypeDescription

_offset

uint256

index of first pendingOrder to return

_limit

uint256

index of last pendingOrder to return

Returns

NameTypeDescription

_0

getAllTradeInfos

function getAllTradeInfos(uint256 _offset, uint256 _limit) external view returns (struct ITradingStorage.TradeInfo[])

Returns all trade infos of open trade/limit/stop orders using a pagination system

Parameters

NameTypeDescription

_offset

uint256

index of first tradeInfo to return

_limit

uint256

index of last tradeInfo to return

Returns

NameTypeDescription

_0

getAllTrades

function getAllTrades(uint256 _offset, uint256 _limit) external view returns (struct ITradingStorage.Trade[])

Returns all trade/limit/stop orders using a pagination system

Parameters

NameTypeDescription

_offset

uint256

index of first trade to return

_limit

uint256

index of last trade to return

Returns

NameTypeDescription

_0

getCollateral

function getCollateral(uint8 _index) external view returns (struct ITradingStorage.Collateral)

Returns collateral data by index

Parameters

NameTypeDescription

_index

uint8

the index of the supported collateral

Returns

NameTypeDescription

_0

getCollateralIndex

function getCollateralIndex(address _collateral) external view returns (uint8)

Returns the index of a supported collateral

Parameters

NameTypeDescription

_collateral

address

the address of the collateral

Returns

NameTypeDescription

_0

uint8

getCollaterals

function getCollaterals() external view returns (struct ITradingStorage.Collateral[])

Returns the supported collaterals

Returns

NameTypeDescription

_0

getCollateralsCount

function getCollateralsCount() external view returns (uint8)

Returns the number of supported collaterals

Returns

NameTypeDescription

_0

uint8

getCounters

function getCounters(address _trader, enum ITradingStorage.CounterType _type) external view returns (struct ITradingStorage.Counter)

Returns the counters of a trader (currentIndex / open count for trades/tradeInfos and pendingOrders mappings)

Parameters

NameTypeDescription

_trader

address

address of the trader

_type

the counter type (trade/pending order)

Returns

NameTypeDescription

_0

getGToken

function getGToken(uint8 _collateralIndex) external view returns (address)

Returns the address of the gToken for a collateral stack

Parameters

NameTypeDescription

_collateralIndex

uint8

the index of the supported collateral

Returns

NameTypeDescription

_0

address

getPendingOpenOrderType

function getPendingOpenOrderType(enum ITradingStorage.TradeType _tradeType) external pure returns (enum ITradingStorage.PendingOrderType)

Pure function that returns the pending order type (market open/limit open/stop open) for a trade type (trade/limit/stop)

Parameters

NameTypeDescription

_tradeType

the trade type

Returns

NameTypeDescription

_0

getPendingOrder

function getPendingOrder(ITradingStorage.Id _orderId) external view returns (struct ITradingStorage.PendingOrder)

Parameters

NameTypeDescription

_orderId

Returns

NameTypeDescription

_0

getPendingOrders

function getPendingOrders(address _user) external view returns (struct ITradingStorage.PendingOrder[])

Returns all pending orders for a trader

Parameters

NameTypeDescription

_user

address

address of the trader

Returns

NameTypeDescription

_0

getPnlPercent

function getPnlPercent(uint64 _openPrice, uint64 _currentPrice, bool _long, uint24 _leverage) external pure returns (int256)

Returns the current percent profit of a trade (1e10 precision)

Parameters

NameTypeDescription

_openPrice

uint64

trade open price (1e10 precision)

_currentPrice

uint64

trade current price (1e10 precision)

_long

bool

true for long, false for short

_leverage

uint24

trade leverage (1e3 precision)

Returns

NameTypeDescription

_0

int256

getTrade

function getTrade(address _trader, uint32 _index) external view returns (struct ITradingStorage.Trade)

Returns open trade/limit/stop order

Parameters

NameTypeDescription

_trader

address

address of the trader

_index

uint32

index of the trade for trader

Returns

NameTypeDescription

_0

getTradeInfo

function getTradeInfo(address _trader, uint32 _index) external view returns (struct ITradingStorage.TradeInfo)

Returns trade info of an open trade/limit/stop order

Parameters

NameTypeDescription

_trader

address

address of the trader

_index

uint32

index of the trade for trader

Returns

NameTypeDescription

_0

getTradeInfos

function getTradeInfos(address _trader) external view returns (struct ITradingStorage.TradeInfo[])

Returns all trade infos of open trade/limit/stop orders for a trader

Parameters

NameTypeDescription

_trader

address

address of the trader

Returns

NameTypeDescription

_0

getTradePendingOrderBlock

function getTradePendingOrderBlock(ITradingStorage.Id _tradeId, enum ITradingStorage.PendingOrderType _orderType) external view returns (uint256)

Parameters

NameTypeDescription

_tradeId

_orderType

Returns

NameTypeDescription

_0

uint256

getTraderStored

function getTraderStored(address _trader) external view returns (bool)

Returns whether a trader is stored in the traders array

Parameters

NameTypeDescription

_trader

address

trader to check

Returns

NameTypeDescription

_0

bool

getTraders

function getTraders(uint32 _offset, uint32 _limit) external view returns (address[])

Returns all traders that have open trades using a pagination system

Parameters

NameTypeDescription

_offset

uint32

start index in the traders array

_limit

uint32

end index in the traders array

Returns

NameTypeDescription

_0

address[]

getTrades

function getTrades(address _trader) external view returns (struct ITradingStorage.Trade[])

Returns all open trades/limit/stop orders for a trader

Parameters

NameTypeDescription

_trader

address

address of the trader

Returns

NameTypeDescription

_0

getTradingActivated

function getTradingActivated() external view returns (enum ITradingStorage.TradingActivated)

Returns the trading activated state

Returns

NameTypeDescription

_0

initializeTradingStorage

function initializeTradingStorage(address _gns, address _gnsStaking, address[] _collaterals, address[] _gTokens) external nonpayable

Initializes the trading storage facet

Parameters

NameTypeDescription

_gns

address

address of the gns token

_gnsStaking

address

address of the gns staking contract

_collaterals

address[]

_gTokens

address[]

isCollateralActive

function isCollateralActive(uint8 _index) external view returns (bool)

Returns whether can open new trades with a collateral

Parameters

NameTypeDescription

_index

uint8

the index of the collateral to check

Returns

NameTypeDescription

_0

bool

isCollateralListed

function isCollateralListed(uint8 _index) external view returns (bool)

Returns whether a collateral has been listed

Parameters

NameTypeDescription

_index

uint8

the index of the collateral to check

Returns

NameTypeDescription

_0

bool

storePendingOrder

function storePendingOrder(ITradingStorage.PendingOrder _pendingOrder) external nonpayable returns (struct ITradingStorage.PendingOrder)

Parameters

NameTypeDescription

_pendingOrder

Returns

NameTypeDescription

_0

storeTrade

function storeTrade(ITradingStorage.Trade _trade, ITradingStorage.TradeInfo _tradeInfo) external nonpayable returns (struct ITradingStorage.Trade)

Parameters

NameTypeDescription

_trade

_tradeInfo

Returns

NameTypeDescription

_0

toggleCollateralActiveState

function toggleCollateralActiveState(uint8 _collateralIndex) external nonpayable

Toggles the active state of a supported collateral

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

updateGToken

function updateGToken(address _collateral, address _gToken) external nonpayable

Updates the contracts of a supported collateral trading stack

Parameters

NameTypeDescription

_collateral

address

address of the collateral

_gToken

address

the gToken contract of the collateral

updateOpenOrderDetails

function updateOpenOrderDetails(ITradingStorage.Id _tradeId, uint64 _openPrice, uint64 _tp, uint64 _sl, uint16 _maxSlippageP) external nonpayable

Parameters

NameTypeDescription

_tradeId

_openPrice

uint64

_tp

uint64

_sl

uint64

_maxSlippageP

uint16

updateTradeCollateralAmount

function updateTradeCollateralAmount(ITradingStorage.Id _tradeId, uint120 _collateralAmount) external nonpayable

Parameters

NameTypeDescription

_tradeId

_collateralAmount

uint120

updateTradeSl

function updateTradeSl(ITradingStorage.Id _tradeId, uint64 _newSl) external nonpayable

Parameters

NameTypeDescription

_tradeId

_newSl

uint64

updateTradeTp

function updateTradeTp(ITradingStorage.Id _tradeId, uint64 _newTp) external nonpayable

Parameters

NameTypeDescription

_tradeId

ITradingStorage.Id

_newTp

uint64

updateTradingActivated

function updateTradingActivated(enum ITradingStorage.TradingActivated _activated) external nonpayable

Updates the trading activated state

Parameters

NameTypeDescription

_activated

the new trading activated state

Events

CollateralAdded

event CollateralAdded(address collateral, uint8 index, address gToken)

Emitted when a new supported collateral is added

Parameters

NameTypeDescription

collateral

address

the address of the collateral

index

uint8

the index of the supported collateral

gToken

address

the gToken contract of the collateral

CollateralDisabled

event CollateralDisabled(uint8 index)

Emitted when an existing supported collateral is disabled (can still close trades but not open new ones)

Parameters

NameTypeDescription

index

uint8

the index of the supported collateral

CollateralUpdated

event CollateralUpdated(uint8 indexed index, bool isActive)

Emitted when an existing supported collateral active state is updated

Parameters

NameTypeDescription

index indexed

uint8

the index of the supported collateral

isActive

bool

the new active state

GTokenUpdated

event GTokenUpdated(address collateral, uint8 index, address gToken)

Emitted when the contracts of a supported collateral trading stack are updated

Parameters

NameTypeDescription

collateral

address

the address of the collateral

index

uint8

the index of the supported collateral

gToken

address

the gToken contract of the collateral

OpenOrderDetailsUpdated

event OpenOrderDetailsUpdated(ITradingStorage.Id tradeId, uint64 openPrice, uint64 tp, uint64 sl, uint16 maxSlippageP)

Emitted when an existing trade/limit order/stop order is updated

Parameters

NameTypeDescription

tradeId

id of the updated trade

openPrice

uint64

new open price value (1e10)

tp

uint64

new take profit value (1e10)

sl

uint64

new stop loss value (1e10)

maxSlippageP

uint16

new max slippage % value (1e3)

PendingOrderClosed

event PendingOrderClosed(ITradingStorage.Id orderId)

Emitted when a pending order is closed

Parameters

NameTypeDescription

orderId

the id of the pending order closed

PendingOrderStored

event PendingOrderStored(ITradingStorage.PendingOrder pendingOrder)

Emitted when a new pending order is stored

Parameters

NameTypeDescription

pendingOrder

ITradingStorage.PendingOrder

the pending order stored

TradeClosed

event TradeClosed(ITradingStorage.Id tradeId)

Emitted when an open trade is closed

Parameters

NameTypeDescription

tradeId

the trade id

TradeCollateralUpdated

event TradeCollateralUpdated(ITradingStorage.Id tradeId, uint120 collateralAmount)

Emitted when an open trade collateral is updated

Parameters

NameTypeDescription

tradeId

id of the updated trade

collateralAmount

uint120

new collateral value (collateral precision)

TradeSlUpdated

event TradeSlUpdated(ITradingStorage.Id tradeId, uint64 newSl)

Emitted when the stop loss of an open trade is updated

Parameters

NameTypeDescription

tradeId

the trade id

newSl

uint64

the new sl (1e10 precision)

TradeStored

event TradeStored(ITradingStorage.Trade trade, ITradingStorage.TradeInfo tradeInfo)

Emitted when a new trade is stored

Parameters

NameTypeDescription

trade

the trade stored

tradeInfo

the trade info stored

TradeTpUpdated

event TradeTpUpdated(ITradingStorage.Id tradeId, uint64 newTp)

Emitted when the take profit of an open trade is updated

Parameters

NameTypeDescription

tradeId

the trade id

newTp

uint64

the new take profit (1e10 precision)

TradingActivatedUpdated

event TradingActivatedUpdated(enum ITradingStorage.TradingActivated activated)

Emitted when the trading activated state is updated

Parameters

NameTypeDescription

activated

the new trading activated state

Errors

AboveMax

error AboveMax()

AlreadyExists

error AlreadyExists()

BelowMin

error BelowMin()

BlockOrder

error BlockOrder()

CollateralAlreadyActive

error CollateralAlreadyActive()

CollateralAlreadyDisabled

error CollateralAlreadyDisabled()

DoesntExist

error DoesntExist()

InitError

error InitError()

InvalidAddresses

error InvalidAddresses()

InvalidCollateralIndex

error InvalidCollateralIndex()

InvalidInputLength

error InvalidInputLength()

MaxSlippageZero

error MaxSlippageZero()

MissingCollaterals

error MissingCollaterals()

NoSl

error NoSl()

NoTp

error NoTp()

NotAllowed

error NotAllowed()

NotAuthorized

error NotAuthorized()

Overflow

error Overflow()

Paused

error Paused()

TradeInfoCollateralPriceUsdZero

error TradeInfoCollateralPriceUsdZero()

TradeOpenPriceZero

error TradeOpenPriceZero()

TradePairNotListed

error TradePairNotListed()

TradePositionSizeZero

error TradePositionSizeZero()

TradeSlInvalid

error TradeSlInvalid()

TradeTpInvalid

error TradeTpInvalid()

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