Skip to content

Commit

Permalink
import interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Nov 25, 2024
1 parent 9717851 commit f721e4f
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 31 deletions.
10 changes: 2 additions & 8 deletions contracts/token/BiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down
20 changes: 4 additions & 16 deletions contracts/token/swaps/Uniswapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Check failure on line 19 in contracts/token/swaps/Uniswapper.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Function order is incorrect, state variable declaration can not go after event definition (line 17)

/// @notice The ERC-20 token that wraps the native asset for current chain
address public immutable wrappedNative;
Expand All @@ -41,7 +29,7 @@ abstract contract Uniswapper {
error TokensAndPoolsLengthMismatch();

constructor(
ISwapRouter uniswapRouterArg,
IV3SwapRouter uniswapRouterArg,
address wrappedNativeArg,
address[] memory tokens,
uint24[] memory tokenPoolFeeTiers
Expand All @@ -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],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion test/base/TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions test/unit/concrete/TestTokenPaymaster.Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/unit/concrete/TestTokenPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
1 change: 0 additions & 1 deletion test/unit/concrete/TestTokenPaymasterParserLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion test/unit/fuzz/TestFuzz_TestSponsorshipPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f721e4f

Please sign in to comment.