JavTradingStorage
General Description
The JavTradingStorage contract used for managing the trading system's storage and operations, including the handling of collateral, trades, and trade-related details. It allows for the initialization and configuration of the trading environment, such as setting up the supported collateral, adjusting trading activation status, and linking to a borrowing provider. The contract enables the storage, modification, and retrieval of trade data, including managing trade position parameters, stop loss, take profit, and slippage conditions. Additionally, it provides several functions to query and manipulate collateral data, such as activating/deactivating collaterals and adding new ones. The system also supports the management and retrieval of liquidation parameters and counters for individual traders.
Core Functionalities
initializeTradingStorage
initializeTradingStorage
Initializes the trading storage with essential configuration settings, such as rewards token, rewards distributor, borrowing provider, and supported collaterals.
Parameters:
_rewardsToken
: Address of the rewards token._rewardsDistributor
: Address of the rewards distributor contract._borrowingProvider
: Address of the borrowing provider._collaterals
: List of collateral addresses._collateralsIndexes
: List of corresponding indexes for each collateral.
Access Control: External.
updateTradingActivated
updateTradingActivated
Updates the trading activation state (whether trading is active or not).
Parameters:
_activated
: The new trading activation state.
Access Control: External.
addCollateral
addCollateral
Adds a new collateral to the supported list of collaterals.
Parameters:
_collateral
: Address of the new collateral._index
: Index of the collateral in the supported list.
Access Control: External.
toggleCollateralActiveState
toggleCollateralActiveState
Toggles the active state of an existing collateral (enables or disables it for trading).
Parameters:
_collateralIndex
: Index of the collateral to toggle.
Access Control: External.
updateBorrowingProvider
updateBorrowingProvider
Updates the address of the borrowing provider.
Parameters:
_borrowingProvider
: New borrowing provider address.
Access Control: External.
updateCollateralApprove
updateCollateralApprove
Updates the approval state for a specified collateral.
Parameters:
_collateralIndex
: Index of the collateral to update approval for.
Access Control: External.
storeTrade
storeTrade
Stores a new trade, including details for trade, limit, or stop orders.
Parameters:
_trade
: Trade data to be stored._tradeInfo
: Additional trade info to be stored.
Returns:
Trade
– The stored trade.Access Control: External.
updateTradeMaxClosingSlippageP
updateTradeMaxClosingSlippageP
Updates the maximum closing slippage for a specified trade.
Parameters:
_tradeId
: ID of the trade to update._maxSlippageP
: New maximum slippage percentage (1e3 precision).
Access Control: External.
updateTradeCollateralAmount
updateTradeCollateralAmount
Updates the collateral amount for an open trade.
Parameters:
_tradeId
: ID of the trade to update._collateralAmount
: New collateral amount (collateral precision).
Access Control: External.
updateTradePosition
updateTradePosition
Updates the position parameters of an open trade, including collateral, leverage, and open price.
Parameters:
_tradeId
: ID of the trade to update._collateralAmount
: New collateral amount._leverage
: New leverage._openPrice
: New open price._isPartialIncrease
: If true, refreshes liquidation parameters.
Access Control: External.
updateOpenOrderDetails
updateOpenOrderDetails
Updates the details of an open order, including price, take profit (tp), stop loss (sl), and slippage.
Parameters:
_tradeId
: ID of the trade to update._openPrice
: New open price (1e10 precision)._tp
: New take profit price (1e10 precision)._sl
: New stop loss price (1e10 precision)._maxSlippageP
: New maximum slippage percentage (1e3 precision).
Access Control: External.
updateTradeTp
updateTradeTp
Updates the take profit (tp) of an open trade.
Parameters:
_tradeId
: ID of the trade to update._newTp
: New take profit price (1e10 precision).
Access Control: External.
updateTradeSl
updateTradeSl
Updates the stop loss (sl) of an open trade.
Parameters:
_tradeId
: ID of the trade to update._newSl
: New stop loss price (1e10 precision).
Access Control: External.
closeTrade
closeTrade
Marks an open trade, limit, or stop order as closed.
Parameters:
_tradeId
: ID of the trade to close.
Access Control: External.
getCollateral
getCollateral
Returns collateral data for a specified index.
Parameters:
_index
: Index of the collateral to retrieve.
Returns:
Collateral
– The collateral data.Access Control: External.
isCollateralActive
isCollateralActive
Returns whether a specified collateral is active for trading.
Parameters:
_index
: Index of the collateral.
Returns:
bool
– Whether the collateral is active.Access Control: External.
isCollateralListed
isCollateralListed
Returns whether a specified collateral has been listed in the system.
Parameters:
_index
: Index of the collateral.
Returns:
bool
– Whether the collateral is listed.Access Control: External.
getCollateralsCount
getCollateralsCount
Returns the count of supported collaterals in the system.
Returns:
uint8
– Number of supported collaterals.Access Control: External.
getCollaterals
getCollaterals
Returns a list of all supported collaterals.
Returns:
Collateral[]
– List of collaterals.Access Control: External.
getCollateralIndex
getCollateralIndex
Returns the index of a specific collateral.
Parameters:
_collateral
: Address of the collateral.
Returns:
uint8
– Index of the collateral.Access Control: External.
Trader & Trade Information Retrieval
getTradingActivated
getTradingActivated
Returns the current trading activation state.
Returns:
TradingActivated
– The current state.Access Control: External.
getTraderStored
getTraderStored
Checks if a trader is stored in the traders array.
Parameters:
_trader
: Address of the trader to check.
Returns:
bool
– Whether the trader is stored.Access Control: External.
getTraders
getTraders
Retrieves a list of traders with open trades, using pagination.
Parameters:
_offset
: Start index._limit
: End index.
Returns:
address[]
– List of traders.Access Control: External.
getTrade
getTrade
Retrieves a specific trade for a trader.
Parameters:
_trader
: Address of the trader._index
: Index of the trade.
Returns:
Trade
– The trade data.Access Control: External.
getTrades
getTrades
Retrieves all trades for a specified trader.
Parameters:
_trader
: Address of the trader.
Returns:
Trade[]
– List of trades.Access Control: External.
getAllTrades
getAllTrades
Retrieves all trades in the system using pagination.
Parameters:
_offset
: Start index._limit
: End index.
Returns:
Trade[]
– List of trades.Access Control: External.
getTradeInfo
getTradeInfo
Retrieves trade info for a specified trader and trade index.
Parameters:
_trader
: Address of the trader._index
: Index of the trade.
Returns:
TradeInfo
– The trade info.Access Control: External.
getTradeInfos
getTradeInfos
Retrieves all trade info for a specified trader.
Parameters:
_trader
: Address of the trader.
Returns:
TradeInfo[]
– List of trade info.Access Control: External.
getAllTradeInfos
getAllTradeInfos
Retrieves all trade info using pagination.
Parameters:
_offset
: Start index._limit
: End index.
Returns:
TradeInfo[]
– List of trade info.Access Control: External.
getCounters
getCounters
Returns the counters for a specified trader (open trades, trade infos, pending orders).
Parameters:
_trader
: Address of the trader.
Returns:
Counter
– The trader's counters.Access Control: External.
getTradeLiquidationParams
getTradeLiquidationParams
Retrieves liquidation parameters for a specific trade.
Parameters:
_trader
: Address of the trader._index
: Index of the trade.
Returns:
GroupLiquidationParams
– The liquidation parameters.Access Control: External.
getTradesLiquidationParams
getTradesLiquidationParams
Retrieves liquidation parameters for all trades of a trader.
Parameters:
_trader
: Address of the trader.
Returns:
GroupLiquidationParams[]
– List of liquidation parameters.Access Control: External.
getAllTradesLiquidationParams
getAllTradesLiquidationParams
Retrieves all liquidation parameters using pagination.
Parameters:
_offset
: Start index._limit
: End index.
Returns:
GroupLiquidationParams[]
– List of liquidation parameters.Access Control: External.
getBorrowingProvider
getBorrowingProvider
Returns the address of the liquidity provider.
Returns:
address
– Address of the borrowing provider.Access Control: External.
Last updated