A smart contract that allows the owner to burn a specified token in exchange for ETH, using the V2 exchange. It also includes functions to set the V2 router contract and the target token to be burned, as well as a function to swap the burned tokens back for ETH and withdraw them. The contract also includes an Ownable contract, which allows the owner to transfer ownership or renounce ownership of the contract. The receive function allows the contract to receive ETH, and will automatically burn the target token in exchange for the received ETH if the target token is set. The swapTokensForEth function allows the contract to swap a specified amount of a given token for ETH, and the rescueTokens function allows the owner to retrieve any remaining tokens that have not been burned.
interface IUniswapV2Router {
function WETH() external pure returns (address);
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
interface IWETH {
function withdraw(uint) external;
}
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
}
Above are the Interface functions of the contract.
function setRouter(address router_) external onlyOwner {
require(router_ != address(router));
router = IUniswapV2Router(router_);
emit RouterSet(router_);
}
The setRouter function allows the owner of the contract to set the address of the V2 router contract that will be used to perform the token burn. The function includes a require statement that ensures the new router address is different from the current router address. This is to prevent the owner from inadvertently overwriting the current router address with the same address. The function also emits a RouterSet event with the new router address. This event can be used by external actors to track changes to the router address.
function setTargetToken(address targetToken_) external onlyOwner {
require(targetToken_ != targetToken);
targetToken = targetToken_;
emit TargetTokenSet(targetToken_);
}
The setTargetToken function allows the owner of the contract to set the address of the token that will be burned. The function includes a statement that ensures the new target token address is different from the current target token address. This is to prevent the owner from inadvertently overwriting the current target token address with the same address. The function also emits a event with the new target token address. This event can be used by external actors to track changes to the target token address.
