2022-06-30 23:43:20 +00:00
|
|
|
//SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.7.0;
|
2022-07-05 13:03:47 +00:00
|
|
|
import "./variables.sol";
|
2022-07-06 01:07:56 +00:00
|
|
|
import "./events.sol";
|
2022-06-30 23:43:20 +00:00
|
|
|
import { Basic } from "../../common/basic.sol";
|
|
|
|
|
2022-07-06 01:07:56 +00:00
|
|
|
contract Helpers is Basic, Variables, Events {
|
2022-07-06 13:40:38 +00:00
|
|
|
/**
|
2022-07-06 13:52:01 +00:00
|
|
|
* @dev Get Enetered markets for a user
|
2022-06-30 23:43:20 +00:00
|
|
|
*/
|
|
|
|
function getEnteredMarkets()
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (address[] memory enteredMarkets)
|
|
|
|
{
|
|
|
|
enteredMarkets = markets.getEnteredMarkets(address(this));
|
|
|
|
}
|
|
|
|
|
2022-07-06 13:52:01 +00:00
|
|
|
/**
|
|
|
|
* @dev Get sub account address
|
|
|
|
* @param primary address of user
|
|
|
|
* @param subAccountId subAccount ID
|
|
|
|
*/
|
2022-07-06 13:40:38 +00:00
|
|
|
function getSubAccount(address primary, uint256 subAccountId)
|
|
|
|
public
|
|
|
|
pure
|
|
|
|
returns (address)
|
|
|
|
{
|
|
|
|
require(subAccountId < 256, "sub-account-id-too-big");
|
|
|
|
return address(uint160(primary) ^ uint160(subAccountId));
|
|
|
|
}
|
2022-07-06 01:07:56 +00:00
|
|
|
|
2022-07-06 13:52:01 +00:00
|
|
|
/**
|
|
|
|
* @dev Check if the market is entered
|
|
|
|
* @param token token address
|
|
|
|
*/
|
2022-07-06 13:40:38 +00:00
|
|
|
function checkIfEnteredMarket(address token) public view returns (bool) {
|
2022-07-06 01:07:56 +00:00
|
|
|
address[] memory enteredMarkets = getEnteredMarkets();
|
|
|
|
uint256 length = enteredMarkets.length;
|
|
|
|
|
2022-07-06 13:40:38 +00:00
|
|
|
for (uint256 i = 0; i < length; i++) {
|
|
|
|
if (enteredMarkets[i] == token) {
|
2022-07-06 01:07:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-06-30 23:43:20 +00:00
|
|
|
}
|