From fb567590ac13ad8139c19aed5440c2530ba9df74 Mon Sep 17 00:00:00 2001 From: JChiaramonte7 Date: Tue, 1 Oct 2024 11:14:07 -0400 Subject: [PATCH] add try/catch return to margin pulling call --- src/Account.sol | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Account.sol b/src/Account.sol index ca860d80..d1ca6ef0 100644 --- a/src/Account.sol +++ b/src/Account.sol @@ -617,6 +617,20 @@ contract Account is IAccount, Auth, OpsReady { IPerpsV2MarketConsolidated(_market).transferMargin(_amount); } + /// @notice deposit/withdraw margin to/from a Synthetix PerpsV2 Market + /// @param _market: address of market + /// @param _amount: amount of margin to deposit/withdraw + function _perpsV2ModifyMarginNoExternalRevert(address _market, int256 _amount) internal returns (bool) { + if (_amount > 0) { + _sufficientMargin(_amount); + } + try IPerpsV2MarketConsolidated(_market).transferMargin(_amount) { + return true; + } catch { + return false; + } + } + /// @notice withdraw margin from market back to this account /// @dev this will *not* fail if market has zero margin function _perpsV2WithdrawAllMargin(address _market) internal { @@ -657,7 +671,9 @@ contract Account is IAccount, Auth, OpsReady { /// @dev this will revert if market does not /// have sufficient available margin - _perpsV2ModifyMargin(_market, -int256(difference)); + bool success = _perpsV2ModifyMarginNoExternalRevert(_market, -int256(difference)); + /// @dev breakout of fee impose if market reverts (max leverage scenario) + if (!success) return; } // impose fee on account from account margin