Skip to content

Commit

Permalink
✨ Prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders committed Oct 11, 2023
1 parent 1b864bb commit 2ae27e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
21 changes: 15 additions & 6 deletions src/Engine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract Engine is IEngine, Multicallable, EIP712, EIP7412, ERC2771Context {
public nonceBitmap;

/// @notice mapping of account id to ETH balance
/// @dev ETH can be deposited/withdrawn from the
/// @dev ETH can be deposited/withdrawn from the
/// Engine contract to pay for fee(s) (conditional order execution, etc.)
mapping(uint128 accountId => uint256 ethBalance) public ethBalances;

Expand Down Expand Up @@ -171,8 +171,11 @@ contract Engine is IEngine, Multicallable, EIP712, EIP7412, ERC2771Context {
emit EthDeposit(_accountId, msg.value);
}

/// @inheritdoc IEngine
function withdrawEth(uint128 _accountId, uint256 _amount) external override {
/// @inheritdoc IEngine
function withdrawEth(uint128 _accountId, uint256 _amount)
external
override
{
address payable caller = payable(_msgSender());

if (!isAccountOwner(_accountId, caller)) revert Unauthorized();
Expand All @@ -186,7 +189,9 @@ contract Engine is IEngine, Multicallable, EIP712, EIP7412, ERC2771Context {
/// @dev UNSAFE to call directly; use `withdrawEth` instead
/// @param _caller the caller of the function
/// @param _accountId the account id to debit ETH from
function _withdrawEth(address _caller, uint128 _accountId, uint256 _amount) internal {
function _withdrawEth(address _caller, uint128 _accountId, uint256 _amount)
internal
{
if (_amount > ethBalances[_accountId]) revert InsufficientEthBalance();

ethBalances[_accountId] -= _amount;
Expand Down Expand Up @@ -435,15 +440,19 @@ contract Engine is IEngine, Multicallable, EIP712, EIP7412, ERC2771Context {
//////////////////////////////////////////////////////////////*/

/// @inheritdoc IEngine
function execute(ConditionalOrder calldata _co, bytes calldata _signature, uint256 _fee)
function execute(
ConditionalOrder calldata _co,
bytes calldata _signature,
uint256 _fee
)
external
override
returns (
IPerpsMarketProxy.Data memory retOrder,
uint256 fees,
uint256 conditionalOrderFee
)
{
{
/// @dev check: (1) fee does not exceed the max fee set by the conditional order
/// @dev check: (2) fee does not exceed balance credited to the account
/// @dev check: (3) nonce has not been executed before
Expand Down
16 changes: 10 additions & 6 deletions src/interfaces/IEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface IEngine {

/// @notice thrown when attempting to verify a condition identified by an invalid selector
error InvalidConditionSelector(bytes4 selector);

/// @notice thrown when attempting to debit an account with insufficient balance
error InsufficientEthBalance();

Expand All @@ -88,7 +88,7 @@ interface IEngine {
event UnorderedNonceInvalidation(
uint128 indexed accountId, uint256 word, uint256 mask
);

/// @notice emitted when eth is deposited into the engine and credited to an account
/// @param accountId the id of the account that was credited
/// @param amount the amount of eth deposited
Expand Down Expand Up @@ -124,7 +124,7 @@ interface IEngine {
external
view
returns (bool);

/*//////////////////////////////////////////////////////////////
ETH MANAGEMENT
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -205,7 +205,7 @@ interface IEngine {
CONDITIONAL ORDER MANAGEMENT
//////////////////////////////////////////////////////////////*/

/// @custom:docs for in-depth documentation of conditional order mechanism,
/// @custom:docs for in-depth documentation of conditional order mechanism,
/// please refer to https://github.com/Kwenta/smart-margin-v3/wiki/Conditional-Orders

/// @notice execute a conditional order
Expand All @@ -215,7 +215,11 @@ interface IEngine {
/// @return retOrder the order committed
/// @return fees the fees paid for the order to Synthetix
/// @return conditionalOrderFee the fee paid to executor for the conditional order
function execute(ConditionalOrder calldata _co, bytes calldata _signature, uint256 _fee)
function execute(
ConditionalOrder calldata _co,
bytes calldata _signature,
uint256 _fee
)
external
returns (
IPerpsMarketProxy.Data memory retOrder,
Expand All @@ -227,7 +231,7 @@ interface IEngine {
/// @param _co the conditional order which details the order to be executed and the conditions to be met
/// @param _signature the signature of the conditional order
/// @param _fee the executor specified fee for the executing the conditional order
/// @dev if the fee is greater than the maxExecutorFee defined in the conditional order,
/// @dev if the fee is greater than the maxExecutorFee defined in the conditional order,
/// or if the account lacks sufficient ETH credit to pay the fee, canExecute will return false
/// @return true if the order can be executed, false otherwise
function canExecute(
Expand Down

0 comments on commit 2ae27e6

Please sign in to comment.