the interface you need to use is IUniswapV2Router01 (im not familiar at all with v3 ngl, so if you were looking to use uniswap v3 im afraid i cant help you without doing an amount of research im definitely too lazy to do lol), not IUniswapV2Callee. Look at the swapExactTokensForETH
function, and from there it should be pretty self explanatory. If you need more hints (or some example code) ill be glad to help :)
EDIT : this should work (i didnt test it and wrote it 100% out of memory, it might contain syntax errors)
// Needs IUniswapV2Router01 and IERC20 to work
IERC20 UniToken = IERC20(UniTokenAddress)
IUniswapV2Router01 router = IUniswapV2Router01(UniswapRouterAddress) // Actually both UniswapRouter01 and 02 will work, but including only UniswapRouter01 will be cheaper to deploy
function TransferAndSwap(uint256 amount) public {
// gets the tokens from msg.sender's wallet
UniToken.transferFrom(msg.sender, address(this), amount) // requires allowance from msg.sender to this contract
//generates the path to make the swap
address[] memory path = new address[](2);
path[0] = address(UniToken);
path[1] = //WETH address;
//lets the contract trade 'amount' of UNI using the UniswapV2Router01
UniToken.approve(address(router), amount)
// Makes the swap
router.swapExactTokensForETH(
amount,
0, // accepts any slippage, might be an issue if you're planning to make big transactions (allowing malicious actors to frontrun you), there is a workaround for that including UniswapV2Pair's getReserves functions, you should be able to figure it out ;)
path,
address(this), // or any address you want, if you want to send the output ETH to another address.
block.timestamp
);
}
// The fallback function, to recieve ether from the uniswapV2Router
fallback() external payable {}