Skip to content

Commit

Permalink
👷 use withdrawTo for withdrawCollateralETH
Browse files Browse the repository at this point in the history
  • Loading branch information
Flocqst committed Oct 1, 2024
1 parent 85ee168 commit 90d9cc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Engine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -480,27 +480,26 @@ contract Engine is
int256 _amount,
uint256 _tolerance
) external override {
if (_amount >= 0) revert InvalidWithdrawalAmount();
if (_amount <= 0) revert InvalidWithdrawalAmount();
if (!isAccountOwner(_accountId, msg.sender)) revert Unauthorized();

PERPS_MARKET_PROXY.modifyCollateral(
_accountId, WETH_SYNTH_MARKET_ID, _amount
_accountId, WETH_SYNTH_MARKET_ID, -_amount
);

IERC20 synth = IERC20(SPOT_MARKET_PROXY.getSynth(WETH_SYNTH_MARKET_ID));
synth.approve(address(zap), _amount.abs256());
synth.approve(address(zap), uint256(_amount));

uint256 unwrappedWETH = zap.unwrap(
address(WETH),
WETH_SYNTH_MARKET_ID,
_amount.abs256(),
uint256(_amount),
_tolerance,
address(this)
);

// Convert WETH to ETH and send to user
WETH.withdraw(unwrappedWETH);
payable(msg.sender).transfer(unwrappedWETH);
WETH.withdrawTo(msg.sender, unwrappedWETH);
}

function _depositCollateral(
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/tokens/IWETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.20;
interface IWETH {
function deposit() external payable;
function withdraw(uint256) external;
function withdrawTo(address recipient, uint256 amount) external;
function approve(address guy, uint256 wad) external returns (bool);
function transfer(address dst, uint256 wad) external returns (bool);
function transferFrom(address src, address dst, uint256 wad)
Expand Down

0 comments on commit 90d9cc5

Please sign in to comment.