Skip to content

Callbacks Contract 📜

An extension of the TradingContract and handles the state management on chain for opening and closing trades.

State Variables

oracleModule

solidity
SlinkyOraclePrecompile immutable oracleModule = SlinkyOraclePrecompile(0x9202Af6Ce925b26AE6B25aDfff0B2705147e195F);
SlinkyOraclePrecompile immutable oracleModule = SlinkyOraclePrecompile(0x9202Af6Ce925b26AE6B25aDfff0B2705147e195F);

storageT

solidity
StorageInterfaceV5 public storageT;
StorageInterfaceV5 public storageT;

pairInfos

solidity
PairInfosInterfaceV6 public pairInfos;
PairInfosInterfaceV6 public pairInfos;

vault

solidity
IGToken public vault;
IGToken public vault;

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;

MAX_GAIN_P

solidity
uint256 constant MAX_GAIN_P = 900;
uint256 constant MAX_GAIN_P = 900;

MAX_EXECUTE_TIMEOUT

solidity
uint256 constant MAX_EXECUTE_TIMEOUT = 5;
uint256 constant MAX_EXECUTE_TIMEOUT = 5;

USDC

solidity
string constant USDC = "USDC/USDT";
string constant USDC = "USDC/USDT";

sssFeeP

solidity
uint256 public sssFeeP;
uint256 public sssFeeP;

isPaused

solidity
bool public isPaused;
bool public isPaused;

isDone

solidity
bool public isDone;
bool public isDone;

canExecuteTimeout

solidity
uint256 public canExecuteTimeout;
uint256 public canExecuteTimeout;

_tradeLastUpdated

solidity
mapping(address => mapping(uint256 => mapping(uint256 => mapping(TradeType => LastUpdated)))) private _tradeLastUpdated;
mapping(address => mapping(uint256 => mapping(uint256 => mapping(TradeType => LastUpdated)))) private _tradeLastUpdated;

borrowingFees

solidity
BorrowingFeesInterfaceV6_3_2 public borrowingFees;
BorrowingFeesInterfaceV6_3_2 public borrowingFees;

pairMaxLeverage

solidity
mapping(uint256 => uint256) public pairMaxLeverage;
mapping(uint256 => uint256) public pairMaxLeverage;

Functions

initializeV2

solidity
function initializeV2(BorrowingFeesInterfaceV6_3_2 _borrowingFees) external reinitializer(2);
function initializeV2(BorrowingFeesInterfaceV6_3_2 _borrowingFees) external reinitializer(2);

onlyGov

solidity
modifier onlyGov();
modifier onlyGov();

notDone

solidity
modifier notDone();
modifier notDone();

onlyTrading

solidity
modifier onlyTrading();
modifier onlyTrading();

onlyManager

solidity
modifier onlyManager();
modifier onlyManager();

isGov

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

isNotDone

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

isTrading

solidity
function isTrading() private view;
function isTrading() private view;

isManager

solidity
function isManager() private view;
function isManager() private view;

setPairMaxLeverage

solidity
function setPairMaxLeverage(uint256 pairIndex, uint256 maxLeverage) external onlyManager;
function setPairMaxLeverage(uint256 pairIndex, uint256 maxLeverage) external onlyManager;

setPairMaxLeverageArray

solidity
function setPairMaxLeverageArray(uint256[] calldata indices, uint256[] calldata values) external onlyManager;
function setPairMaxLeverageArray(uint256[] calldata indices, uint256[] calldata values) external onlyManager;

_setPairMaxLeverage

solidity
function _setPairMaxLeverage(uint256 pairIndex, uint256 maxLeverage) private;
function _setPairMaxLeverage(uint256 pairIndex, uint256 maxLeverage) private;

setCanExecuteTimeout

solidity
function setCanExecuteTimeout(uint256 _canExecuteTimeout) external onlyGov;
function setCanExecuteTimeout(uint256 _canExecuteTimeout) external onlyGov;

pause

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

done

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

openTradeMarketCallback

solidity
function openTradeMarketCallback(AggregatorAnswer memory a, StorageInterfaceV5.PendingMarketOrder memory o)
    external
    onlyTrading
    notDone;
function openTradeMarketCallback(AggregatorAnswer memory a, StorageInterfaceV5.PendingMarketOrder memory o)
    external
    onlyTrading
    notDone;

closeTradeMarketCallback

solidity
function closeTradeMarketCallback(AggregatorAnswer memory a, StorageInterfaceV5.PendingMarketOrder memory o)
    external
    onlyTrading
    notDone;
function closeTradeMarketCallback(AggregatorAnswer memory a, StorageInterfaceV5.PendingMarketOrder memory o)
    external
    onlyTrading
    notDone;

executeNftOpenOrderCallback

solidity
function executeNftOpenOrderCallback(AggregatorAnswer memory a, StorageInterfaceV5.PendingNftOrder memory n)
    external
    onlyTrading
    notDone;
function executeNftOpenOrderCallback(AggregatorAnswer memory a, StorageInterfaceV5.PendingNftOrder memory n)
    external
    onlyTrading
    notDone;

executeNftCloseOrderCallback

solidity
function executeNftCloseOrderCallback(AggregatorAnswer memory a, StorageInterfaceV5.PendingNftOrder memory o)
    external
    onlyTrading
    notDone;
function executeNftCloseOrderCallback(AggregatorAnswer memory a, StorageInterfaceV5.PendingNftOrder memory o)
    external
    onlyTrading
    notDone;

updateSlCallback

solidity
function updateSlCallback(AggregatorAnswer memory a, PendingSl memory o) external onlyTrading notDone;
function updateSlCallback(AggregatorAnswer memory a, PendingSl memory o) external onlyTrading notDone;

setTradeLastUpdated

solidity
function setTradeLastUpdated(SimplifiedTradeId memory _id, LastUpdated memory _lastUpdated) external onlyTrading;
function setTradeLastUpdated(SimplifiedTradeId memory _id, LastUpdated memory _lastUpdated) external onlyTrading;

withinMaxLeverage

solidity
function withinMaxLeverage(uint256 pairIndex, uint256 leverage) private view returns (bool);
function withinMaxLeverage(uint256 pairIndex, uint256 leverage) private view returns (bool);

currentPercentProfit

solidity
function currentPercentProfit(uint256 openPrice, uint256 currentPrice, bool buy, uint256 leverage)
    private
    pure
    returns (int256 p);
function currentPercentProfit(uint256 openPrice, uint256 currentPrice, bool buy, uint256 leverage)
    private
    pure
    returns (int256 p);

correctTp

solidity
function correctTp(uint256 openPrice, uint256 leverage, uint256 tp, bool buy) private pure returns (uint256);
function correctTp(uint256 openPrice, uint256 leverage, uint256 tp, bool buy) private pure returns (uint256);

correctSl

solidity
function correctSl(uint256 openPrice, uint256 leverage, uint256 sl, bool buy) private pure returns (uint256);
function correctSl(uint256 openPrice, uint256 leverage, uint256 sl, bool buy) private pure returns (uint256);

marketExecutionPrice

solidity
function marketExecutionPrice(uint256 price, uint256 spreadP, uint256 spreadReductionP, bool long)
    private
    pure
    returns (uint256);
function marketExecutionPrice(uint256 price, uint256 spreadP, uint256 spreadReductionP, bool long)
    private
    pure
    returns (uint256);

getPairsStorage

solidity
function getPairsStorage() private view returns (PairsStorageInterfaceV6);
function getPairsStorage() private view returns (PairsStorageInterfaceV6);

getOpenTrade

solidity
function getOpenTrade(address trader, uint256 pairIndex, uint256 index)
    private
    view
    returns (StorageInterfaceV5.Trade memory);
function getOpenTrade(address trader, uint256 pairIndex, uint256 index)
    private
    view
    returns (StorageInterfaceV5.Trade memory);

getOpenTradeInfo

solidity
function getOpenTradeInfo(address trader, uint256 pairIndex, uint256 index)
    private
    view
    returns (StorageInterfaceV5.TradeInfo memory);
function getOpenTradeInfo(address trader, uint256 pairIndex, uint256 index)
    private
    view
    returns (StorageInterfaceV5.TradeInfo memory);

getAllPairsMaxLeverage

solidity
function getAllPairsMaxLeverage() external view returns (uint256[] memory);
function getAllPairsMaxLeverage() external view returns (uint256[] memory);

tradeLastUpdated

solidity
function tradeLastUpdated(address trader, uint256 pairIndex, uint256 index, TradeType tradeType)
    external
    view
    returns (LastUpdated memory);
function tradeLastUpdated(address trader, uint256 pairIndex, uint256 index, TradeType tradeType)
    external
    view
    returns (LastUpdated memory);

tokenPriceHoney

solidity
function tokenPriceHoney() private view returns (uint256);
function tokenPriceHoney() private view returns (uint256);

Events

MarketOpenCanceled

solidity
event MarketOpenCanceled(address indexed trader, uint256 indexed pairIndex, CancelReason cancelReason);
event MarketOpenCanceled(address indexed trader, uint256 indexed pairIndex, CancelReason cancelReason);

MarketCloseCanceled

solidity
event MarketCloseCanceled(address indexed trader, uint256 indexed pairIndex, uint256 index, CancelReason cancelReason);
event MarketCloseCanceled(address indexed trader, uint256 indexed pairIndex, uint256 index, CancelReason cancelReason);

NftOrderCanceled

solidity
event NftOrderCanceled(
    StorageInterfaceV5.LimitOrder orderType,
    CancelReason cancelReason,
    uint256 currPrice,
    uint256 minExecPrice,
    uint256 maxExecPrice,
    uint256 tp,
    uint256 sl
);
event NftOrderCanceled(
    StorageInterfaceV5.LimitOrder orderType,
    CancelReason cancelReason,
    uint256 currPrice,
    uint256 minExecPrice,
    uint256 maxExecPrice,
    uint256 tp,
    uint256 sl
);

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);

SlCanceled

solidity
event SlCanceled(address indexed trader, uint256 indexed pairIndex, uint256 index, CancelReason cancelReason);
event SlCanceled(address indexed trader, uint256 indexed pairIndex, uint256 index, CancelReason cancelReason);

CanExecuteTimeoutUpdated

solidity
event CanExecuteTimeoutUpdated(uint256 newValue);
event CanExecuteTimeoutUpdated(uint256 newValue);

Pause

solidity
event Pause(bool paused);
event Pause(bool paused);

Done

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

PairMaxLeverageUpdated

solidity
event PairMaxLeverageUpdated(uint256 indexed pairIndex, uint256 maxLeverage);
event PairMaxLeverageUpdated(uint256 indexed pairIndex, uint256 maxLeverage);

Errors

WrongParams

solidity
error WrongParams();
error WrongParams();

Forbidden

solidity
error Forbidden();
error Forbidden();

Enums

CancelReason

solidity
enum CancelReason {
    NONE,
    PAUSED,
    MARKET_CLOSED,
    SLIPPAGE,
    TP_REACHED,
    SL_REACHED,
    EXPOSURE_LIMITS,
    PRICE_IMPACT,
    MAX_LEVERAGE,
    NO_TRADE,
    WRONG_TRADE,
    NOT_HIT
}
enum CancelReason {
    NONE,
    PAUSED,
    MARKET_CLOSED,
    SLIPPAGE,
    TP_REACHED,
    SL_REACHED,
    EXPOSURE_LIMITS,
    PRICE_IMPACT,
    MAX_LEVERAGE,
    NO_TRADE,
    WRONG_TRADE,
    NOT_HIT
}