From 240a8233dedd20c9aaef151fe8cfd5cafe72758c Mon Sep 17 00:00:00 2001 From: Filipp Makarov Date: Tue, 26 Nov 2024 14:02:15 +0400 Subject: [PATCH] gas opt --- contracts/token/swaps/Uniswapper.sol | 6 ++++-- test/unit/concrete/TestTokenPaymaster.Base.t.sol | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/contracts/token/swaps/Uniswapper.sol b/contracts/token/swaps/Uniswapper.sol index 3fd7c08..b00aa67 100644 --- a/contracts/token/swaps/Uniswapper.sol +++ b/contracts/token/swaps/Uniswapper.sol @@ -15,6 +15,8 @@ import { IV3SwapRouter } from "@uniswap/swap-router-contracts/contracts/interfac abstract contract Uniswapper { event SwappingReverted(address tokenIn, uint256 amountIn, bytes reason); + error UnwrappingReverted(uint256 amount); + /// @notice The Uniswap V3 SwapRouter contract IV3SwapRouter public immutable uniswapRouter; @@ -75,7 +77,7 @@ abstract contract Uniswapper { function _unwrapWeth(uint256 amount) internal { if(amount == 0) return; - IERC20(wrappedNative).transfer(address(uniswapRouter), amount); - IPeripheryPayments(address(uniswapRouter)).unwrapWETH9(amount, address(this)); + (bool success, ) = address(wrappedNative).call(abi.encodeWithSignature("withdraw(uint256)", amount)); + if (!success) revert UnwrappingReverted(amount); } } diff --git a/test/unit/concrete/TestTokenPaymaster.Base.t.sol b/test/unit/concrete/TestTokenPaymaster.Base.t.sol index 7d8ca2e..4582794 100644 --- a/test/unit/concrete/TestTokenPaymaster.Base.t.sol +++ b/test/unit/concrete/TestTokenPaymaster.Base.t.sol @@ -137,8 +137,7 @@ contract TestTokenPaymasterBase is TestBase { // IF THIS CASE FAILS ON 2% TOLERANCE => PUT THE FRESH PRICE FROM ORACLE HERE // https://basescan.org/address/0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70#readContract#F8 // and remove two last digits from the price - //3344583445, - 3478381850, + 3358580000, _PRICE_MARKUP_DENOMINATOR, this.getMaxPenalty(ops[0]), this.getRealPenalty(ops[0], gasValue, customGasPrice));