Here is my current code. In the past I have used ISwapRouter with v2 liqudity. In this case I am trying to execute a swap on base chain with v3 liqudity but base chain does not have a swap router contract so swaps go through the universal router. Every time I send 10 brett tokens to this contract and then try and call the execute function (in remix) I get my transaction reverted.
// SPDX-License-Identifier: MIT
//Solidity version
pragma solidity =0.8.25;
import"@uniswap/universal-router/contracts/interfaces/IUniversalRouter.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract SwapExecutor
{
address private immutable projectWallet=0x6d9265EC3e99E653Ae77c30AA9753BbcCafB45e9;
address private immutable brett=0x532f27101965dd16442E59d40670FaF5eBB142E4;
address private immutable weth= 0x4200000000000000000000000000000000000006;
uint24 private immutable fee=10000;
uint256 private immutable tokensIn=10 ether;
uint256 private immutable tokensOut=0 ether;
bytes1 private immutable V3_SWAP_EXACT_IN = 0x00;
bool private immutable fromMsgSender=true;
address private immutable _routerAddress=0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD ;
IUniversalRouter public router;
bytes private path;
constructor()
{
router = IUniversalRouter(_routerAddress);
path=abi.encodePacked(brett,fee,weth);
}
function executeSwap() external payable
{
IERC20(brett).approve(address(router), tokensIn);
uint256 deadLine=block.timestamp + 300;
bytes memory commands = new bytes(1);
commands[0] = V3_SWAP_EXACT_IN;
bytes[] memory inputs = new bytes[](1);
inputs[0] = abi.encode(
projectWallet,
tokensIn,
tokensOut,
path,
fromMsgSender
);
router.execute{value: msg.value}(commands, inputs, deadLine);
}
}