From e82cd3e425968f3374467b6ae57d1bc9c5860d39 Mon Sep 17 00:00:00 2001 From: JaredBorders Date: Fri, 7 Apr 2023 14:45:34 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=F0=9F=8F=BB=E2=80=8D=E2=99=82?= =?UTF-8?q?=EF=B8=8F=20Handle=20paused=20markets=20edge=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Account.sol | 23 ++++++++++++++++++++--- src/interfaces/IAccount.sol | 4 ++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Account.sol b/src/Account.sol index 80d40280..d3eb9c5c 100644 --- a/src/Account.sol +++ b/src/Account.sol @@ -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 @@ -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"; @@ -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; @@ -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" + ) + ); } /*////////////////////////////////////////////////////////////// @@ -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)); diff --git a/src/interfaces/IAccount.sol b/src/interfaces/IAccount.sol index edc6ee4f..85425ece 100644 --- a/src/interfaces/IAccount.sol +++ b/src/interfaces/IAccount.sol @@ -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) @@ -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);