Skip to content

Commit

Permalink
πŸ‘·πŸ»β€β™‚οΈ Handle paused markets edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders committed Apr 7, 2023
1 parent 2f6ca22 commit e82cd3e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Account.sol
Expand Up @@ -5,11 +5,12 @@ import {Auth} from "./utils/Auth.sol";
import {
IAccount,
IAddressResolver,
IEvents,
IFactory,
IFuturesMarketManager,
IPerpsV2MarketConsolidated,
ISettings,
IEvents
ISystemStatus
} from "./interfaces/IAccount.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Initializable} from
Expand All @@ -33,6 +34,9 @@ contract Account is IAccount, OpsReady, Auth, Initializable {
/// @notice name for futures market manager
bytes32 private constant FUTURES_MARKET_MANAGER = "FuturesMarketManager";

/// @notice name for system status
bytes32 private constant SYSTEM_STATUS = "SystemStatus";

/// @notice constant for sUSD currency key
bytes32 private constant SUSD = "sUSD";

Expand All @@ -57,6 +61,9 @@ contract Account is IAccount, OpsReady, Auth, Initializable {
//// @inheritdoc IAccount
IFuturesMarketManager public futuresMarketManager;

/// @inheritdoc IAccount
ISystemStatus public systemStatus;

/// @inheritdoc IAccount
ISettings public settings;

Expand Down Expand Up @@ -134,6 +141,13 @@ contract Account is IAccount, OpsReady, Auth, Initializable {
"Account: Could not get Futures Market Manager"
)
);

// get address for system status
systemStatus = ISystemStatus(
ADDRESS_RESOLVER.requireAndGetAddress(
SYSTEM_STATUS, "Account: Could not get System Status"
)
);
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -895,8 +909,11 @@ contract Account is IAccount, OpsReady, Auth, Initializable {
ConditionalOrder memory conditionalOrder =
getConditionalOrder(_conditionalOrderId);

// return false is market is paused
/// @custom:todo check if market is paused
// return false if market is paused
try systemStatus.requireFuturesMarketActive(conditionalOrder.marketKey)
{} catch {
return false;
}

/// @dev if marketKey is invalid, this will revert
uint256 price = _sUSDRate(_getPerpsV2Market(conditionalOrder.marketKey));
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/IAccount.sol
Expand Up @@ -9,6 +9,7 @@ import {IFuturesMarketManager} from "@synthetix/IFuturesMarketManager.sol";
import {IPerpsV2MarketConsolidated} from
"@synthetix/IPerpsV2MarketConsolidated.sol";
import {ISettings} from "./ISettings.sol";
import {ISystemStatus} from "@synthetix/ISystemStatus.sol";

/// @title Kwenta Smart Margin Account Implementation Interface
/// @author JaredBorders (jaredborders@pm.me), JChiaramonte7 (jeremy@bytecode.llc)
Expand Down Expand Up @@ -132,6 +133,9 @@ interface IAccount {
view
returns (IFuturesMarketManager);

/// @return returns the address of the synthetix system status
function systemStatus() external view returns (ISystemStatus);

/// @return returns the address of the native settings for account
function settings() external view returns (ISettings);

Expand Down

0 comments on commit e82cd3e

Please sign in to comment.