Skip to content

Trading Contract 📜

Git Source

Main public facing contract and entrypoint for all users to place, update, or cancel trades and for liquidation/limit orders to be filled.

State Variables

storageT

solidity
StorageInterfaceV5 public immutable storageT;
StorageInterfaceV5 public immutable storageT;

pairInfos

solidity
GNSPairInfosInterfaceV6 public immutable pairInfos;
GNSPairInfosInterfaceV6 public immutable pairInfos;

borrowingFees

solidity
GNSBorrowingFeesInterfaceV6_3_2 public immutable borrowingFees;
GNSBorrowingFeesInterfaceV6_3_2 public immutable borrowingFees;

PRECISION

solidity
uint256 constant PRECISION = 1e10;
uint256 constant PRECISION = 1e10;

MAX_SL_P

solidity
uint256 constant MAX_SL_P = 75;
uint256 constant MAX_SL_P = 75;

marketOrdersTimeout

solidity
uint256 public marketOrdersTimeout;
uint256 public marketOrdersTimeout;

isPaused

solidity
bool public isPaused;
bool public isPaused;

isDone

solidity
bool public isDone;
bool public isDone;

openLimitOrderTypes

solidity
mapping(address => mapping(uint256 => mapping(uint256 => OpenLimitOrderType))) public openLimitOrderTypes;
mapping(address => mapping(uint256 => mapping(uint256 => OpenLimitOrderType))) public openLimitOrderTypes;

Functions

onlyGov

solidity
modifier onlyGov();
modifier onlyGov();

notContract

solidity
modifier notContract();
modifier notContract();

notDone

solidity
modifier notDone();
modifier notDone();

isGov

solidity
function isGov() private view;
function isGov() private view;

isNotContract

solidity
function isNotContract() private view;
function isNotContract() private view;

isNotDone

solidity
function isNotDone() private view;
function isNotDone() private view;

setMarketOrdersTimeout

solidity
function setMarketOrdersTimeout(uint256 value) external onlyGov;
function setMarketOrdersTimeout(uint256 value) external onlyGov;

pause

solidity
function pause() external onlyGov;
function pause() external onlyGov;

done

solidity
function done() external onlyGov;
function done() external onlyGov;

openTrade

solidity
function openTrade(StorageInterfaceV5.Trade memory t, OpenLimitOrderType orderType, uint256 slippageP)
    external
    notContract
    notDone;
function openTrade(StorageInterfaceV5.Trade memory t, OpenLimitOrderType orderType, uint256 slippageP)
    external
    notContract
    notDone;

closeTradesMarket

solidity
function closeTradesMarket(TradeOrOrder[] memory trades) external notContract notDone;
function closeTradesMarket(TradeOrOrder[] memory trades) external notContract notDone;

closeTradeMarket

solidity
function closeTradeMarket(uint256 pairIndex, uint256 index) external notContract notDone;
function closeTradeMarket(uint256 pairIndex, uint256 index) external notContract notDone;

updateOpenLimitOrder

solidity
function updateOpenLimitOrder(uint256 pairIndex, uint256 index, uint256 price, uint256 tp, uint256 sl)
    external
    notContract
    notDone;
function updateOpenLimitOrder(uint256 pairIndex, uint256 index, uint256 price, uint256 tp, uint256 sl)
    external
    notContract
    notDone;

cancelOpenLimitOrders

solidity
function cancelOpenLimitOrders(TradeOrOrder[] memory orders) external notContract notDone;
function cancelOpenLimitOrders(TradeOrOrder[] memory orders) external notContract notDone;

cancelOpenLimitOrder

solidity
function cancelOpenLimitOrder(uint256 pairIndex, uint256 index) external notContract notDone;
function cancelOpenLimitOrder(uint256 pairIndex, uint256 index) external notContract notDone;

updateTp

solidity
function updateTp(uint256 pairIndex, uint256 index, uint256 newTp) external notContract notDone;
function updateTp(uint256 pairIndex, uint256 index, uint256 newTp) external notContract notDone;

updateSl

solidity
function updateSl(uint256 pairIndex, uint256 index, uint256 newSl) external notContract notDone;
function updateSl(uint256 pairIndex, uint256 index, uint256 newSl) external notContract notDone;

executeNftOrder

solidity
function executeNftOrder(StorageInterfaceV5.LimitOrder orderType, address trader, uint256 pairIndex, uint256 index)
    external
    notDone;
function executeNftOrder(StorageInterfaceV5.LimitOrder orderType, address trader, uint256 pairIndex, uint256 index)
    external
    notDone;

getPrice

solidity
function getPrice(uint256 pairIndex) private view returns (TradingCallbacksV6_3_2.AggregatorAnswer memory);
function getPrice(uint256 pairIndex) private view returns (TradingCallbacksV6_3_2.AggregatorAnswer memory);

canExecute

solidity
function canExecute(StorageInterfaceV5.LimitOrder orderType, TradingCallbacksV6_3_2.SimplifiedTradeId memory id)
    private
    view
    returns (bool);
function canExecute(StorageInterfaceV5.LimitOrder orderType, TradingCallbacksV6_3_2.SimplifiedTradeId memory id)
    private
    view
    returns (bool);

pairMaxLeverage

solidity
function pairMaxLeverage(PairsStorageInterfaceV6 pairsStorage, uint256 pairIndex) private view returns (uint256);
function pairMaxLeverage(PairsStorageInterfaceV6 pairsStorage, uint256 pairIndex) private view returns (uint256);

Events

Done

solidity
event Done(bool done);
event Done(bool done);

Paused

solidity
event Paused(bool paused);
event Paused(bool paused);

NumberUpdated

solidity
event NumberUpdated(string name, uint256 value);
event NumberUpdated(string name, uint256 value);

OpenLimitPlaced

solidity
event OpenLimitPlaced(
    address indexed trader, uint256 indexed pairIndex, uint256 index, StorageInterfaceV5.OpenLimitOrder order
);
event OpenLimitPlaced(
    address indexed trader, uint256 indexed pairIndex, uint256 index, StorageInterfaceV5.OpenLimitOrder order
);

OpenLimitUpdated

solidity
event OpenLimitUpdated(
    address indexed trader,
    uint256 indexed pairIndex,
    uint256 index,
    uint256 newPrice,
    uint256 newTp,
    uint256 newSl,
    StorageInterfaceV5.OpenLimitOrder order
);
event OpenLimitUpdated(
    address indexed trader,
    uint256 indexed pairIndex,
    uint256 index,
    uint256 newPrice,
    uint256 newTp,
    uint256 newSl,
    StorageInterfaceV5.OpenLimitOrder order
);

OpenLimitCanceled

solidity
event OpenLimitCanceled(address indexed trader, uint256 indexed pairIndex, uint256 index, uint256 openTime);
event OpenLimitCanceled(address indexed trader, uint256 indexed pairIndex, uint256 index, uint256 openTime);

TpUpdated

solidity
event TpUpdated(address indexed trader, uint256 indexed pairIndex, uint256 index, uint256 newTp, uint256 openTime);
event TpUpdated(address indexed trader, uint256 indexed pairIndex, uint256 index, uint256 newTp, uint256 openTime);

SlUpdated

solidity
event SlUpdated(address indexed trader, uint256 indexed pairIndex, uint256 index, uint256 newSl, uint256 openTime);
event SlUpdated(address indexed trader, uint256 indexed pairIndex, uint256 index, uint256 newSl, uint256 openTime);

CouldNotCloseTrade

solidity
event CouldNotCloseTrade(address indexed trader, uint256 indexed pairIndex, uint256 index);
event CouldNotCloseTrade(address indexed trader, uint256 indexed pairIndex, uint256 index);

Structs

TradeOrOrder

solidity
struct TradeOrOrder {
    uint256 pairIndex;
    uint256 index;
}
struct TradeOrOrder {
    uint256 pairIndex;
    uint256 index;
}

Enums

OpenLimitOrderType

solidity
enum OpenLimitOrderType {
    LEGACY,
    REVERSAL,
    MOMENTUM
}
enum OpenLimitOrderType {
    LEGACY,
    REVERSAL,
    MOMENTUM
}