Skip to content

Commit

Permalink
🦴 Prepare PERMIT2 modification for _modifyAccountMargin
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders committed Jul 3, 2023
1 parent a51ba83 commit 1d9c938
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Account.sol
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ contract Account is IAccount, Auth, OpsReady {
/// @param _amount: amount to withdraw
function _withdrawEth(uint256 _amount) internal {
if (_amount > 0) {
(bool success,) = payable(owner).call{value: _amount}("");
(bool success,) = payable(msg.sender).call{value: _amount}("");
if (!success) revert EthWithdrawalFailed();

EVENTS.emitEthWithdraw({user: msg.sender, amount: _amount});
Expand All @@ -527,15 +527,24 @@ contract Account is IAccount, Auth, OpsReady {
// if amount is positive, deposit
if (_amount > 0) {
/// @dev failed Synthetix asset transfer will revert and not return false if unsuccessful
MARGIN_ASSET.transferFrom(owner, address(this), _abs(_amount));
MARGIN_ASSET.transferFrom(msg.sender, address(this), _abs(_amount));

/// @custom:todo implement PERMIT2 transfer here
/// @dev msg.sender must have approved Permit2 to spend at least the amountIn
// PERMIT2.transferFrom({
// from: msg.sender,
// to: address(this),
// amount: _abs(_amount).toUint160(),
// token: address(MARGIN_ASSET)
// });

EVENTS.emitDeposit({user: msg.sender, amount: _abs(_amount)});
} else if (_amount < 0) {
// if amount is negative, withdraw
_sufficientMargin(_amount);

/// @dev failed Synthetix asset transfer will revert and not return false if unsuccessful
MARGIN_ASSET.transfer(owner, _abs(_amount));
MARGIN_ASSET.transfer(msg.sender, _abs(_amount));

EVENTS.emitWithdraw({user: msg.sender, amount: _abs(_amount)});
}
Expand Down

0 comments on commit 1d9c938

Please sign in to comment.