Skip to content

Commit

Permalink
add try/catch return to margin pulling call
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmonte committed Oct 1, 2024
1 parent 64a5db5 commit fb56759
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Account.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb56759

Please sign in to comment.