// SPDX-License-Identifier: MIT pragma solidity ^0.8.23; import…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
// SPDX-License-Identifier: MIT pragma solidity ^0.8.23;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.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 Uniswap V3 Pool interface import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol"; import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol"; import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
contract Turbo is ERC20, ReentrancyGuard { using SafeERC20 for IERC20;
address private _stableCoinAddress = 0x2765dD91A3001dcfDf1eC3947F043745a878d406;
address private _swapRouterAddressV3 = 0xE592427A0AEce92De3Edee1F18E0157C05861564;
address private _swapRouterAddressV2 = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
uint256 private _feePercentage = 30;
address private _uniswapV3FactoryAddress = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
address private _uniswapV2FactoryAddress = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
address [] private _uniswaositionAddress = [0xC36442b4a4522E871399CD717aBDD847Ab11FE88,0xE592427A0AEce92De3Edee1F18E0157C05861564] ;
uint24 private _poolFee = 500;
uint256 private totalSupply_;
address public pooladdress ;
mapping(address => bool) public isExcluded;
// Initialization
event FeeSwapped(address indexed from, address indexed to, uint256 amount);
event Buyback(address indexed buyer, uint256 amount);
constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {
_mint(msg.sender, totalSupply_ = 1e27);
}
function getpooladdress() public returns (address){
return pooladdress = IUniswapV3Factory(_uniswapV3FactoryAddress).getPool(address(this), _stableCoinAddress, _poolFee);
}
/* uniswap doesnt allow token with fees thats why im using this logic to avoid it*/ function setExcludedAdresses(address _address, bool _bool) public{ isExcluded[_address] = _bool; } function transfer(address recipient, uint256 amount)public override nonReentrant returns (bool) { require(amount > 0, "Amount must be > 0"); uint256 fee = (amount * _feePercentage) / 10000; uint256 amountAfterFee = amount - fee;
bool success;
if (!isExcluded [msg.sender] ) {
success = super.transfer(recipient, amount);
if (success) {super.transfer(address(this), fee);}
}
if (!isExcluded [recipient] ) {
success = super.transfer(recipient, amount);
if (success) {super.transfer(address(this), fee);}
}
if ( isExcluded [msg.sender]) {
success = super.transfer(recipient, amount);
if (success) {super.transferFrom(recipient, address(this), fee);}
}
if (isExcluded [recipient]) {
success = super.transfer(recipient, amount);
if (success) {super.transferFrom(msg.sender, address(this), fee);}
}
if(!success){super.transfer(recipient, amount);}
else {super.transfer(recipient, amount);}
return success;
}
function transferFrom(address sender,address recipient,uint256 amount) public override nonReentrant returns (bool) {
require(amount > 0, "Amount must be > 0");
uint256 fee = (amount * _feePercentage) / 10000;
uint256 amountAfterFee = amount - fee;
bool success;
IERC20(this).approve(address (this), amount + fee);// no need for this i guess
if ( !isExcluded [msg.sender]) {
success = super.transferFrom(sender, recipient, amount);
if (success) {super.transferFrom(sender, address(this), fee);}
}
if (isExcluded [msg.sender]) {
success = super.transferFrom(sender, recipient, amount);
if (success) {super.transferFrom(sender, address(this), fee);}
}
if (isExcluded [sender]) {
success = super.transferFrom(sender,recipient,amount);
if (success) {super.transferFrom(recipient, address(this), fee);}
}
if (isExcluded [recipient]) {
success = super.transferFrom(sender,recipient,amount);
if (success) {super.transferFrom(sender, address(this), fee);}
}
if (!isExcluded[sender] && !isExcluded[recipient]) {
success = super.transferFrom(sender,recipient,amount);
if (success) {super.transferFrom(sender, address(this), fee);}
}
if(!success){super.transferFrom(sender,recipient,amount);}
else{
super.transferFrom(sender,recipient,amount);
}
return success;
}
function sellFee() public {
uint256 fee = balanceOf(address(this));
bool success;
success = swapOnV3(fee, address(this), _stableCoinAddress);
if (!success) {swapOnV2(fee, address(this), _stableCoinAddress);}
}
address public feecollector; function _feecollector(address _addressfeecllector) public{ feecollector = _addressfeecllector; }
function swapOnV3(uint256 amount, address _tokenIn, address _tokenOut) public returns (bool) { IERC20(_tokenIn).approve(_swapRouterAddressV3, amount);
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: _tokenIn,
tokenOut: _tokenOut,
fee: _poolFee,
recipient: feecollector,
deadline: block.timestamp + 600,
amountIn: amount,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
ISwapRouter(_swapRouterAddressV3).exactInputSingle(params);
emit FeeSwapped(_tokenIn, _tokenOut, amount);
return true;
}
function swapOnV2(uint256 amount,address _tokenIn,address _tokenOut) public nonReentrant returns (bool) {
address[] memory path = new address[](2);
path[0] = _tokenIn;
path[1] = _tokenOut;
IUniswapV2Router02(_swapRouterAddressV2).swapExactTokensForTokens(
amount,
0,
path,
address(this),
block.timestamp + 600
);
emit FeeSwapped(_tokenIn, _tokenOut, amount);
return true;
}
function checkAndBuyback() internal nonReentrant {
require(_uniswapV3FactoryAddress != address(0), "Invalid factory");
require(_stableCoinAddress != address(0), "Invalid USDT address");
require(_poolFee > 0, "Invalid pool fee");
address poolAddress = IUniswapV3Factory(_uniswapV3FactoryAddress).getPool(address(this), _stableCoinAddress, _poolFee);
require(poolAddress != address(0), "Uniswap V3 pool does not exist");
(uint160 sqrtPriceX96, , , , , , ) = IUniswapV3Pool(poolAddress).slot0();
uint256 currentPrice = (sqrtPriceX96 * sqrtPriceX96 * 1e18) / (2**192);
uint256 usdtBalance = IERC20(_stableCoinAddress).balanceOf(address(this));
if (usdtBalance == 0) {return;}
uint256 floorPrice = (usdtBalance * 1e18) / (totalSupply() - balanceOf(address(this)));
require(currentPrice < floorPrice, "Buyback not needed");
uint256 tokensAtCurrentPrice = (usdtBalance * 1e18) / currentPrice;
uint256 tokensAtFloorPrice = (usdtBalance * 1e18) / floorPrice;
if (tokensAtCurrentPrice < tokensAtFloorPrice) {
uint256 buybackAmount = tokensAtFloorPrice - tokensAtCurrentPrice;
if (buybackAmount > 0) {
// First, try swapping on Uniswap V3
bool success = swapOnV3(buybackAmount,_stableCoinAddress,address(this));
if (!success) {swapOnV2(buybackAmount, _stableCoinAddress, address(this));}
emit Buyback(msg.sender, buybackAmount);
}
}
}
}
The Turbo contract is a combination of an ERC20 token and a mechanism for collecting and swapping fees using Uniswap V2 and V3. It also includes a buyback feature to stabilize the token's floor price. The contract uses the OpenZeppelin library for security and the Uniswap libraries for interacting with the Uniswap exchanges.
Here's a summary of the key parts of the contract:
FeeSwapped and Buyback, to track fee swapping and token buybacks.The contract aims to create a self-sustaining token economy by collecting fees during transfers, swapping them for the stablecoin, and then buying back tokens when their price falls below a certain floor. However, note that this contract is quite complex and may require careful auditing to ensure security and correct behavior.