Skip to content

Commit

Permalink
tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Nov 22, 2024
1 parent 950b583 commit afd60e0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
18 changes: 16 additions & 2 deletions contracts/token/swaps/Uniswapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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<[email protected]>
Expand Down Expand Up @@ -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
Expand All @@ -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));
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]+sha512.beb9e2a803db336c10c9af682b58ad7181ca0fbd0d4119f2b33d5f2582e96d6c0d93c85b23869295b765170fbdaa92890c0da6ada457415039769edf3c959efe"
}
29 changes: 15 additions & 14 deletions test/unit/concrete/TestTokenPaymaster.Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

0 comments on commit afd60e0

Please sign in to comment.