From f721e4f0fb2601194b9917a4782fb5132728840b Mon Sep 17 00:00:00 2001 From: Filipp Makarov Date: Mon, 25 Nov 2024 16:15:23 +0400 Subject: [PATCH] import interface --- contracts/token/BiconomyTokenPaymaster.sol | 10 ++-------- contracts/token/swaps/Uniswapper.sol | 20 ++++--------------- package.json | 1 + remappings.txt | 1 + test/base/TestBase.sol | 2 +- .../concrete/TestTokenPaymaster.Base.t.sol | 4 ++-- test/unit/concrete/TestTokenPaymaster.t.sol | 4 ++-- .../TestTokenPaymasterParserLib.t.sol | 1 - .../TestFuzz_TestSponsorshipPaymaster.t.sol | 1 - 9 files changed, 13 insertions(+), 31 deletions(-) diff --git a/contracts/token/BiconomyTokenPaymaster.sol b/contracts/token/BiconomyTokenPaymaster.sol index 90b0d2a..ee0f498 100644 --- a/contracts/token/BiconomyTokenPaymaster.sol +++ b/contracts/token/BiconomyTokenPaymaster.sol @@ -16,9 +16,7 @@ import { TokenPaymasterParserLib } from "../libraries/TokenPaymasterParserLib.so import { SignatureCheckerLib } from "solady/utils/SignatureCheckerLib.sol"; import { ECDSA as ECDSA_solady } from "solady/utils/ECDSA.sol"; import "account-abstraction/core/Helpers.sol"; -import "./swaps/Uniswapper.sol"; -// Todo: marked for removal -import "forge-std/console2.sol"; +import { Uniswapper, IV3SwapRouter } from "./swaps/Uniswapper.sol"; /** * @title BiconomyTokenPaymaster @@ -72,7 +70,7 @@ contract BiconomyTokenPaymaster is uint256 priceExpiryDurationArg, uint256 nativeAssetDecimalsArg, IOracle nativeAssetToUsdOracleArg, - ISwapRouter uniswapRouterArg, + IV3SwapRouter uniswapRouterArg, address wrappedNativeArg, address[] memory independentTokensArg, // Array of token addresses supported by the paymaster in independent // mode @@ -553,8 +551,6 @@ contract BiconomyTokenPaymaster is address tokenAddress = modeSpecificData.parseIndependentModeSpecificData(); uint256 tokenPrice = _getPrice(tokenAddress); - console2.log("tokenPrice in validation phase", tokenPrice); - if(tokenPrice == 0) { revert TokenNotSupported(); } @@ -609,8 +605,6 @@ contract BiconomyTokenPaymaster is bytes32 userOpHash ) = abi.decode(context, (address, address, uint256, uint256, uint32, bytes32)); - console2.log("unaccountedGas", unaccountedGas); - // Calculate the actual cost in tokens based on the actual gas cost and the token price uint256 actualTokenAmount = ( (actualGasCost + (unaccountedGas * actualUserOpFeePerGas)) * appliedPriceMarkup * tokenPrice diff --git a/contracts/token/swaps/Uniswapper.sol b/contracts/token/swaps/Uniswapper.sol index e36922e..3fd7c08 100644 --- a/contracts/token/swaps/Uniswapper.sol +++ b/contracts/token/swaps/Uniswapper.sol @@ -4,19 +4,7 @@ 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/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); -} +import { IV3SwapRouter } from "@uniswap/swap-router-contracts/contracts/interfaces/IV3SwapRouter.sol"; /** * @title Uniswapper @@ -28,7 +16,7 @@ abstract contract Uniswapper { event SwappingReverted(address tokenIn, uint256 amountIn, bytes reason); /// @notice The Uniswap V3 SwapRouter contract - ISwapRouter public immutable uniswapRouter; + IV3SwapRouter public immutable uniswapRouter; /// @notice The ERC-20 token that wraps the native asset for current chain address public immutable wrappedNative; @@ -41,7 +29,7 @@ abstract contract Uniswapper { error TokensAndPoolsLengthMismatch(); constructor( - ISwapRouter uniswapRouterArg, + IV3SwapRouter uniswapRouterArg, address wrappedNativeArg, address[] memory tokens, uint24[] memory tokenPoolFeeTiers @@ -66,7 +54,7 @@ abstract contract Uniswapper { } function _swapTokenToWeth(address tokenIn, uint256 amountIn, uint256 minAmountOut) internal returns (uint256 amountOut) { - ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({ + IV3SwapRouter.ExactInputSingleParams memory params = IV3SwapRouter.ExactInputSingleParams({ tokenIn: tokenIn, tokenOut: wrappedNative, fee: tokenToPools[tokenIn], diff --git a/package.json b/package.json index 401bb10..219fdc4 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "solady": "github:vectorized/solady", "@uniswap/v3-core": "https://github.com/Uniswap/v3-core#0.8", "@uniswap/v3-periphery": "https://github.com/Uniswap/v3-periphery#0.8", + "@uniswap/swap-router-contracts": "https://github.com/Uniswap/swap-router-contracts", "@prb/test": "^0.6.4" }, "devDependencies": { diff --git a/remappings.txt b/remappings.txt index 56163b6..069b979 100644 --- a/remappings.txt +++ b/remappings.txt @@ -9,6 +9,7 @@ sentinellist/=node_modules/sentinellist/src/ solady/=node_modules/solady/src/ @uniswap/v3-periphery/contracts/=node_modules/@uniswap/v3-periphery/contracts @uniswap/v3-core/contracts/=node_modules/@uniswap/v3-core/contracts/ +@uniswap/swap-router-contracts/contracts/=node_modules/@uniswap/swap-router-contracts/contracts/ solady/src/=node_modules/solady/src/ excessively-safe-call/=node_modules/excessively-safe-call/src/ modulekit/=node_modules/@rhinestone/modulekit/src/ diff --git a/test/base/TestBase.sol b/test/base/TestBase.sol index 23a4fb1..2569eed 100644 --- a/test/base/TestBase.sol +++ b/test/base/TestBase.sol @@ -32,7 +32,7 @@ abstract contract TestBase is CheatCodes, TestHelper, BaseEventsAndErrors { using UserOperationLib for PackedUserOperation; address constant ENTRYPOINT_ADDRESS = address(0x0000000071727De22E5E9d8BAf0edAc6f37da032); - // Note: review addresses if testing on other chains + // Note: addresses valid for Base, can be different for other chains address constant WRAPPED_NATIVE_ADDRESS = address(0x4200000000000000000000000000000000000006); address constant SWAP_ROUTER_ADDRESS = address(0x2626664c2603336E57B271c5C0b26F421741e481); diff --git a/test/unit/concrete/TestTokenPaymaster.Base.t.sol b/test/unit/concrete/TestTokenPaymaster.Base.t.sol index 708af19..7d8ca2e 100644 --- a/test/unit/concrete/TestTokenPaymaster.Base.t.sol +++ b/test/unit/concrete/TestTokenPaymaster.Base.t.sol @@ -15,7 +15,7 @@ import "../../../contracts/token/swaps/Uniswapper.sol"; contract TestTokenPaymasterBase is TestBase { BiconomyTokenPaymaster public tokenPaymaster; - ISwapRouter public swapRouter; + IV3SwapRouter public swapRouter; // base addresses IOracle public nativeOracle = IOracle(0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70); // base ETH/USD chainlink feed IOracle public tokenOracle = IOracle(0x7e860098F58bBFC8648a4311b374B1D669a2bc6B); // base USDC/USD chainlink feed @@ -33,7 +33,7 @@ contract TestTokenPaymasterBase is TestBase { console2.log("current block timestamp ", block.timestamp); - swapRouter = ISwapRouter(SWAP_ROUTER_ADDRESS); // uniswap swap router v2 on base + swapRouter = IV3SwapRouter(SWAP_ROUTER_ADDRESS); // uniswap swap router v2 on base // Deploy the token paymaster tokenPaymaster = new BiconomyTokenPaymaster( PAYMASTER_OWNER.addr, diff --git a/test/unit/concrete/TestTokenPaymaster.t.sol b/test/unit/concrete/TestTokenPaymaster.t.sol index ed14622..c787c03 100644 --- a/test/unit/concrete/TestTokenPaymaster.t.sol +++ b/test/unit/concrete/TestTokenPaymaster.t.sol @@ -15,7 +15,7 @@ import "../../../contracts/token/swaps/Uniswapper.sol"; contract TestTokenPaymaster is TestBase { BiconomyTokenPaymaster public tokenPaymaster; - ISwapRouter swapRouter; + IV3SwapRouter swapRouter; MockOracle public nativeAssetToUsdOracle; MockToken public testToken; MockToken public testToken2; @@ -29,7 +29,7 @@ contract TestTokenPaymaster is TestBase { vm.txGasPrice(customGasPrice); // Deploy mock oracles and tokens - swapRouter = ISwapRouter(address(SWAP_ROUTER_ADDRESS)); + swapRouter = IV3SwapRouter(address(SWAP_ROUTER_ADDRESS)); nativeAssetToUsdOracle = new MockOracle(100_000_000, 8); // Oracle with 8 decimals for ETH // ETH/USD tokenOracle = new MockOracle(100_000_000, 8); // Oracle with 8 decimals for ERC20 token // TKN/USD testToken = new MockToken("Test Token", "TKN"); diff --git a/test/unit/concrete/TestTokenPaymasterParserLib.t.sol b/test/unit/concrete/TestTokenPaymasterParserLib.t.sol index 326acfa..97aa904 100644 --- a/test/unit/concrete/TestTokenPaymasterParserLib.t.sol +++ b/test/unit/concrete/TestTokenPaymasterParserLib.t.sol @@ -65,7 +65,6 @@ contract TestTokenPaymasterParserLib is Test { assertEq(parsedModeSpecificData, modeSpecificData, "Mode specific data should match"); } - // TODO: review prices added inline with MockOracle function test_ParseExternalModeSpecificData() public view { // Simulate valid external mode specific data uint48 expectedValidUntil = uint48(block.timestamp + 1 days); diff --git a/test/unit/fuzz/TestFuzz_TestSponsorshipPaymaster.t.sol b/test/unit/fuzz/TestFuzz_TestSponsorshipPaymaster.t.sol index 39b1263..c9f35ab 100644 --- a/test/unit/fuzz/TestFuzz_TestSponsorshipPaymaster.t.sol +++ b/test/unit/fuzz/TestFuzz_TestSponsorshipPaymaster.t.sol @@ -106,7 +106,6 @@ contract TestFuzz_SponsorshipPaymasterWithPriceMarkup is TestBase { assertEq(token.balanceOf(ALICE_ADDRESS), mintAmount); } - // Review: fuzz with high markeup and current set values. function testFuzz_ValidatePaymasterAndPostOpWithPriceMarkup(uint32 priceMarkup) external { vm.assume(priceMarkup <= 2e6 && priceMarkup > 1e6); bicoPaymaster.depositFor{ value: 10 ether }(DAPP_ACCOUNT.addr);