From afd60e06bdbffe824942eba28d527bc661f960a3 Mon Sep 17 00:00:00 2001 From: Filipp Makarov Date: Fri, 22 Nov 2024 18:48:42 +0300 Subject: [PATCH] tests pass --- contracts/token/swaps/Uniswapper.sol | 18 ++++++++++-- package.json | 3 +- .../concrete/TestTokenPaymaster.Base.t.sol | 29 ++++++++++--------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/contracts/token/swaps/Uniswapper.sol b/contracts/token/swaps/Uniswapper.sol index 205eb03..ed1889e 100644 --- a/contracts/token/swaps/Uniswapper.sol +++ b/contracts/token/swaps/Uniswapper.sol @@ -3,9 +3,22 @@ pragma solidity ^0.8.27; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; +//import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; import "@uniswap/v3-periphery/contracts/interfaces/IPeripheryPayments.sol"; +interface ISwapRouter { + struct ExactInputSingleParams { + address tokenIn; + address tokenOut; + uint24 fee; + address recipient; + uint256 amountIn; + uint256 amountOutMinimum; + uint160 sqrtPriceLimitX96; + } + function exactInputSingle(ExactInputSingleParams memory params) external payable returns (uint256 amountOut); +} + /** * @title Uniswapper * @author ShivaanshK @@ -59,7 +72,7 @@ abstract contract Uniswapper { tokenOut: wrappedNative, fee: tokenToPools[tokenIn], recipient: address(this), - deadline: block.timestamp, + //deadline: block.timestamp, amountIn: amountIn, amountOutMinimum: minAmountOut, sqrtPriceLimitX96: 0 @@ -75,6 +88,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)); } } diff --git a/package.json b/package.json index 96bcd82..52bb896 100644 --- a/package.json +++ b/package.json @@ -71,5 +71,6 @@ "lint:ts-fix": "pnpm prettier --write 'test/**/*.ts' 'scripts/**/*.ts'", "lint:sol-fix": "pnpm prettier --write 'contracts/**/*.sol' && pnpm solhint 'contracts/**/*.sol' --fix --noPrompt && forge fmt", "lint:fix": "pnpm run lint:sol-fix && pnpm run lint:ts-fix" - } + }, + "packageManager": "pnpm@9.13.0+sha512.beb9e2a803db336c10c9af682b58ad7181ca0fbd0d4119f2b33d5f2582e96d6c0d93c85b23869295b765170fbdaa92890c0da6ada457415039769edf3c959efe" } diff --git a/test/unit/concrete/TestTokenPaymaster.Base.t.sol b/test/unit/concrete/TestTokenPaymaster.Base.t.sol index d02ffbf..2647b3e 100644 --- a/test/unit/concrete/TestTokenPaymaster.Base.t.sol +++ b/test/unit/concrete/TestTokenPaymaster.Base.t.sol @@ -33,7 +33,7 @@ contract TestTokenPaymasterBase is TestBase { console2.log("current block timestamp ", block.timestamp); - swapRouter = ISwapRouter(0x2626664c2603336E57B271c5C0b26F421741e481); // uniswap swap router v2 on base + swapRouter = ISwapRouter(SWAP_ROUTER_ADDRESS); // uniswap swap router v2 on base // Deploy the token paymaster tokenPaymaster = new BiconomyTokenPaymaster( PAYMASTER_OWNER.addr, @@ -143,25 +143,26 @@ contract TestTokenPaymasterBase is TestBase { // test to make a swap. function test_BaseFork_Success_TokenPaymaster_SwapToNativeAndDeposit() external { - deal(address(usdc), address(tokenPaymaster), 100e6); - uint256 initialTokenBalance = usdc.balanceOf(address(tokenPaymaster)); - console2.log("initialTokenBalance", initialTokenBalance); - uint256 initialDepositOnEntryPoint = tokenPaymaster.getDeposit(); + // deposit 100 USDC to the paymaster + deal(address(usdc), address(tokenPaymaster), 100e6); + uint256 initialTokenBalance = usdc.balanceOf(address(tokenPaymaster)); + console2.log("initialTokenBalance", initialTokenBalance); + uint256 initialDepositOnEntryPoint = tokenPaymaster.getDeposit(); vm.startPrank(address(tokenPaymaster)); - //usdc.approve(address(SWAP_ROUTER_ADDRESS), usdc.balanceOf(address(tokenPaymaster))); + usdc.approve(address(swapRouter), usdc.balanceOf(address(tokenPaymaster))); vm.stopPrank(); - // Review reason for failure - startPrank(PAYMASTER_OWNER.addr); - tokenPaymaster.swapTokenAndDeposit(address(usdc), 99e6, 0); - stopPrank(); + uint256 amountToSwap = 99e6; + startPrank(PAYMASTER_OWNER.addr); + tokenPaymaster.swapTokenAndDeposit(address(usdc), amountToSwap, 0); + stopPrank(); - uint256 newTokenBalance = usdc.balanceOf(address(tokenPaymaster)); - assertEq(newTokenBalance, 0); + uint256 newTokenBalance = usdc.balanceOf(address(tokenPaymaster)); + assertEq(newTokenBalance, initialTokenBalance - amountToSwap); - // uint256 newDepositOnEntryPoint = tokenPaymaster.getDeposit(); - // assertGt(newDepositOnEntryPoint, initialDepositOnEntryPoint); + uint256 newDepositOnEntryPoint = tokenPaymaster.getDeposit(); + assertGt(newDepositOnEntryPoint, initialDepositOnEntryPoint); } }