// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import…
- User
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 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-core/contracts/interfaces/IUniswapV3Factory.sol"; import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract DynamicSwap is ReentrancyGuard {
address private _swapRouterAddressV3 = 0xE592427A0AEce92De3Edee1F18E0157C05861564; event FeeSwapped(address tokenIn, address tokenOut, uint256 amount); function swapOnV3(uint256 amount, uint24 _poolFee, address _tokenIn, address _tokenOut) public nonReentrant returns (bool) { IERC20(_tokenIn).approve(_swapRouterAddressV3, amount); ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({ tokenIn: _tokenIn, tokenOut: _tokenOut, fee: _poolFee, recipient: address(this), deadline: block.timestamp + 600, amountIn: amount, amountOutMinimum: 0, sqrtPriceLimitX96: 0 }); ISwapRouter(_swapRouterAddressV3).exactInputSingle(params); emit FeeSwapped(_tokenIn, _tokenOut, amount); return true; } // Additional function to retrieve the contract's token balance function getTokenBalance(address tokenAddress) public view returns (uint256) { return IERC20(tokenAddress).balanceOf(address(this)); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.