Skip to content

Commit

Permalink
⚡ Optimize WETH
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Feb 15, 2024
1 parent 1e938d5 commit 69ec788
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ IETest:testCommandSendETH() (gas: 69457)
IETest:testCommandSendUSDC() (gas: 135705)
IETest:testCommandSwapDAI() (gas: 102148)
IETest:testCommandSwapETH() (gas: 113640)
IETest:testCommandSwapForETH() (gas: 123602)
IETest:testCommandSwapUSDC() (gas: 157143)
IETest:testCommandSwapForETH() (gas: 123456)
IETest:testCommandSwapUSDC() (gas: 157129)
IETest:testCommandSwapUSDCForWBTC() (gas: 165096)
IETest:testDeploy() (gas: 2674498)
IETest:testDeploy() (gas: 2660863)
IETest:testENSNameOwnership() (gas: 84066)
IETest:testIENameSetting() (gas: 8142)
IETest:testPreviewCommandSendDecimals() (gas: 91972)
Expand Down
15 changes: 9 additions & 6 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ contract IE {
);
if (ETHOut) {
uint256 amount = uint256(-(zeroForOne ? amount1Delta : amount0Delta));
IWETH(WETH).withdraw(amount);
_withdrawWETH(amount);
payer.safeTransferETH(amount);
}
}
Expand Down Expand Up @@ -395,6 +395,14 @@ contract IE {
}
}

function _withdrawWETH(uint256 amount) internal virtual {
assembly ("memory-safe") {
mstore(0x00, 0x2e1a7d4d) // `withdraw(uint256)`.
mstore(0x20, amount) // Store the `amount` argument.
pop(call(gas(), WETH, 0, 0x1c, 0x24, 0x20, 0x20))
}
}

/// ================== BALANCE & SUPPLY HELPERS ================== ///

/// @dev Returns the balance of a named account in a named token.
Expand Down Expand Up @@ -666,11 +674,6 @@ interface IToken {
function transfer(address, uint256) external returns (bool);
}

/// @dev Simple wrapped ether (WETH) token interface.
interface IWETH {
function withdraw(uint256) external;
}

/// @notice Simple calldata executor interface.
interface IExecutor {
function execute(address, uint256, bytes calldata) external payable returns (bytes memory);
Expand Down

0 comments on commit 69ec788

Please sign in to comment.